]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: enable generics syntax with -lang=go1.18
authorMatthew Dempsky <mdempsky@google.com>
Thu, 1 Jul 2021 19:47:58 +0000 (12:47 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 2 Jul 2021 14:55:39 +0000 (14:55 +0000)
We already use -lang=go1.18 to control the types2 type checker
behavior. This CL does the same for the parser.

Also, disable an assertion in the unified IR linker that depended on
the -G flag. This assertion was more useful during initial
bootstrapping of that code, but it's less critical now.

With these two changes, "GOEXPERIMENT=unified ./make.bash" is enough
to get a fully functional generics-enabled toolchain. There's no need
to continue specifying custom compiler flags later on.

Change-Id: I7766381926f3bb17eee2e5fcc182a38a39e937e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/332373
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/noder/linker.go
src/cmd/compile/internal/noder/noder.go

index ed47a355d816150df3353f39ee856b1dd7660953..eefb5083e50624ecf6136c5ccc42f4adf5442928 100644 (file)
@@ -149,9 +149,11 @@ func (l *linker) relocObj(pr *pkgReader, idx int) int {
                var ok bool
                obj, ok = sym.Def.(*ir.Name)
 
-               // Generic types and functions won't have definitions.
+               // Generic types and functions and declared constraint types won't
+               // have definitions.
                // For now, just generically copy their extension data.
-               if !ok && base.Flag.G == 0 {
+               // TODO(mdempsky): Restore assertion.
+               if !ok && false {
                        base.Fatalf("missing definition for %v", sym)
                }
        }
index 3d83129aea6ba7f06c4a045f8586bd49eb84b069..6a2aacd3fea71fa5d46d361834cefc60993829f7 100644 (file)
@@ -9,6 +9,7 @@ import (
        "fmt"
        "go/constant"
        "go/token"
+       "internal/buildcfg"
        "os"
        "path/filepath"
        "runtime"
@@ -30,8 +31,11 @@ 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 base.Flag.G != 0 {
+       if supportsGenerics && types.AllowsGoVersion(types.LocalPkg, 1, 18) {
                mode |= syntax.AllowGenerics
        }