]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove -G flag
authorMatthew Dempsky <mdempsky@google.com>
Mon, 28 Feb 2022 22:09:47 +0000 (14:09 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 1 Mar 2022 19:45:44 +0000 (19:45 +0000)
Post 1.18, we're committed to types2 as cmd/compile's type checker.

Change-Id: I30d2dd2b2ba62832fcdcaeb996fcbc8a4a05d591
Reviewed-on: https://go-review.googlesource.com/c/go/+/388535
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/base/flag.go
src/cmd/compile/internal/noder/irgen.go
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/reflectdata/reflect.go
src/cmd/compile/internal/typecheck/iexport.go
src/cmd/compile/internal/types/universe.go

index d78f93b343fa118670f5703cefddd2f700f1d94e..6377091ce0b20967eaf3e9ffc0a1676a1ef5c2ff 100644 (file)
@@ -55,7 +55,6 @@ type CmdFlags struct {
        C CountFlag    "help:\"disable printing of columns in error messages\""
        D string       "help:\"set relative `path` for local imports\""
        E CountFlag    "help:\"debug symbol export\""
-       G CountFlag    "help:\"accept generic code\""
        I func(string) "help:\"add `directory` to import search path\""
        K CountFlag    "help:\"debug missing line numbers\""
        L CountFlag    "help:\"show full file names in error messages\""
@@ -141,7 +140,6 @@ type CmdFlags struct {
 
 // ParseFlags parses the command-line flags into Flag.
 func ParseFlags() {
-       Flag.G = 3
        Flag.I = addImportDir
 
        Flag.LowerC = 1
index 52224c4046353b63195ee3d26f3ca5e6a8acaf63..993c2542183669ce36711c84cd8a2ca3671896c6 100644 (file)
@@ -6,7 +6,6 @@ package noder
 
 import (
        "fmt"
-       "os"
 
        "cmd/compile/internal/base"
        "cmd/compile/internal/dwarfgen"
@@ -77,10 +76,6 @@ func checkFiles(noders []*noder) (posMap, *types2.Package, *types2.Info) {
 func check2(noders []*noder) {
        m, pkg, info := checkFiles(noders)
 
-       if base.Flag.G < 2 {
-               os.Exit(0)
-       }
-
        g := irgen{
                target: typecheck.Target,
                self:   pkg,
@@ -90,10 +85,6 @@ func check2(noders []*noder) {
                typs:   make(map[types2.Type]*types.Type),
        }
        g.generate(noders)
-
-       if base.Flag.G < 3 {
-               os.Exit(0)
-       }
 }
 
 // Information about sub-dictionary entries in a dictionary
index b36db67a507a87f8cd6bd0a56791b4f34399cedc..2cd7218c55c6b97dd456bd9fc99e124526c9ebaf 100644 (file)
@@ -9,7 +9,6 @@ import (
        "fmt"
        "go/constant"
        "go/token"
-       "internal/buildcfg"
        "os"
        "path/filepath"
        "runtime"
@@ -31,13 +30,7 @@ import (
 func LoadPackage(filenames []string) {
        base.Timer.Start("fe", "parse")
 
-       // -G=3 and unified expect generics syntax, but -G=0 does not.
-       supportsGenerics := base.Flag.G != 0 || buildcfg.Experiment.Unified
-
-       mode := syntax.CheckBranches
-       if supportsGenerics {
-               mode |= syntax.AllowGenerics
-       }
+       mode := syntax.CheckBranches | syntax.AllowGenerics
 
        // Limit the number of simultaneously open files.
        sem := make(chan struct{}, runtime.GOMAXPROCS(0)+10)
@@ -85,104 +78,8 @@ func LoadPackage(filenames []string) {
                return
        }
 
-       if base.Flag.G != 0 {
-               // Use types2 to type-check and possibly generate IR.
-               check2(noders)
-               return
-       }
-
-       for _, p := range noders {
-               p.node()
-               p.file = nil // release memory
-       }
-
-       if base.SyntaxErrors() != 0 {
-               base.ErrorExit()
-       }
-       types.CheckDclstack()
-
-       for _, p := range noders {
-               p.processPragmas()
-       }
-
-       // Typecheck.
-       types.LocalPkg.Height = myheight
-       typecheck.DeclareUniverse()
-       typecheck.TypecheckAllowed = true
-
-       // Process top-level declarations in phases.
-
-       // Phase 1: const, type, and names and types of funcs.
-       //   This will gather all the information about types
-       //   and methods but doesn't depend on any of it.
-       //
-       //   We also defer type alias declarations until phase 2
-       //   to avoid cycles like #18640.
-       //   TODO(gri) Remove this again once we have a fix for #25838.
-       //
-       // Phase 2: Variable assignments.
-       //   To check interface assignments, depends on phase 1.
-
-       // Don't use range--typecheck can add closures to Target.Decls.
-       for phase, name := range []string{"top1", "top2"} {
-               base.Timer.Start("fe", "typecheck", name)
-               for i := 0; i < len(typecheck.Target.Decls); i++ {
-                       n := typecheck.Target.Decls[i]
-                       op := n.Op()
-
-                       // Closure function declarations are typechecked as part of the
-                       // closure expression.
-                       if fn, ok := n.(*ir.Func); ok && fn.OClosure != nil {
-                               continue
-                       }
-
-                       // We don't actually add ir.ODCL nodes to Target.Decls. Make sure of that.
-                       if op == ir.ODCL {
-                               base.FatalfAt(n.Pos(), "unexpected top declaration: %v", op)
-                       }
-
-                       // Identify declarations that should be deferred to the second
-                       // iteration.
-                       late := op == ir.OAS || op == ir.OAS2 || op == ir.ODCLTYPE && n.(*ir.Decl).X.Alias()
-
-                       if late == (phase == 1) {
-                               typecheck.Target.Decls[i] = typecheck.Stmt(n)
-                       }
-               }
-       }
-
-       // Phase 3: Type check function bodies.
-       // Don't use range--typecheck can add closures to Target.Decls.
-       base.Timer.Start("fe", "typecheck", "func")
-       for i := 0; i < len(typecheck.Target.Decls); i++ {
-               if fn, ok := typecheck.Target.Decls[i].(*ir.Func); ok {
-                       if base.Flag.W > 1 {
-                               s := fmt.Sprintf("\nbefore typecheck %v", fn)
-                               ir.Dump(s, fn)
-                       }
-                       typecheck.FuncBody(fn)
-                       if base.Flag.W > 1 {
-                               s := fmt.Sprintf("\nafter typecheck %v", fn)
-                               ir.Dump(s, fn)
-                       }
-               }
-       }
-
-       // Phase 4: Check external declarations.
-       // TODO(mdempsky): This should be handled when type checking their
-       // corresponding ODCL nodes.
-       base.Timer.Start("fe", "typecheck", "externdcls")
-       for i, n := range typecheck.Target.Externs {
-               if n.Op() == ir.ONAME {
-                       typecheck.Target.Externs[i] = typecheck.Expr(typecheck.Target.Externs[i])
-               }
-       }
-
-       // Phase 5: With all user code type-checked, it's now safe to verify map keys.
-       // With all user code typechecked, it's now safe to verify unused dot imports.
-       typecheck.CheckMapKeys()
-       CheckDotImports()
-       base.ExitIfErrors()
+       // Use types2 to type-check and generate IR.
+       check2(noders)
 }
 
 func (p *noder) errorAt(pos syntax.Pos, format string, args ...interface{}) {
index bd55c91c388f134f62e8d7d477fad0a32d84e42c..0402c2d82c8736e11bfffbeb86b5c6d910279748 100644 (file)
@@ -1397,9 +1397,7 @@ func WriteBasicTypes() {
                }
                writeType(types.NewPtr(types.Types[types.TSTRING]))
                writeType(types.NewPtr(types.Types[types.TUNSAFEPTR]))
-               if base.Flag.G > 0 {
-                       writeType(types.AnyType)
-               }
+               writeType(types.AnyType)
 
                // emit type structs for error and func(error) string.
                // The latter is the type of an auto-generated wrapper.
index 947d029ae2ceb557e63b1c5fef192d2051ce51ae..fe0c80ac58413e9c3d6a1c59a420522ddc6f2490 100644 (file)
@@ -607,7 +607,7 @@ func (p *iexporter) doDecl(n *ir.Name) {
                        // Do same for ComparableType as for ErrorType.
                        underlying = types.ComparableType
                }
-               if base.Flag.G > 0 && underlying == types.AnyType.Underlying() {
+               if underlying == types.AnyType.Underlying() {
                        // Do same for AnyType as for ErrorType.
                        underlying = types.AnyType
                }
@@ -949,7 +949,6 @@ func (w *exportWriter) startType(k itag) {
 func (w *exportWriter) doTyp(t *types.Type) {
        s := t.Sym()
        if s != nil && t.OrigSym() != nil {
-               assert(base.Flag.G > 0)
                // This is an instantiated type - could be a re-instantiation like
                // Value[T2] or a full instantiation like Value[int].
                if strings.Index(s.Name, "[") < 0 {
@@ -974,7 +973,6 @@ func (w *exportWriter) doTyp(t *types.Type) {
        // type, rather than a defined type with typeparam underlying type, like:
        // type orderedAbs[T any] T
        if t.IsTypeParam() && t.Underlying() == t {
-               assert(base.Flag.G > 0)
                if s.Pkg == types.BuiltinPkg || s.Pkg == types.UnsafePkg {
                        base.Fatalf("builtin type missing from typIndex: %v", t)
                }
@@ -1064,7 +1062,6 @@ func (w *exportWriter) doTyp(t *types.Type) {
                }
 
        case types.TUNION:
-               assert(base.Flag.G > 0)
                // TODO(danscales): possibly put out the tilde bools in more
                // compact form.
                w.startType(unionType)
index 55ed7bd6d0c7e0aaafbddb310aebe58b955d2fc6..4dff4548da7201c5c1968bc446e54e0f20a1d087 100644 (file)
@@ -115,10 +115,6 @@ func InitTypes(defTypeName func(sym *Sym, typ *Type) Object) {
        AnyType.SetUnderlying(NewInterface(BuiltinPkg, []*Field{}, false))
        ResumeCheckSize()
 
-       if base.Flag.G == 0 {
-               ComparableType.Sym().Def = nil
-       }
-
        Types[TUNSAFEPTR] = defBasic(TUNSAFEPTR, UnsafePkg, "Pointer")
 
        Types[TBLANK] = newType(TBLANK)