]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: add a compiler param to SizesFor
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 2 Mar 2017 15:02:26 +0000 (07:02 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 2 Mar 2017 17:13:28 +0000 (17:13 +0000)
The current StdSizes most closely matches
the gc compiler, and the uses I know of that care
which compiler the sizes are for are all for
the gc compiler, so call the existing
implementation "gc".

Updates #17586
Fixes #19351

Change-Id: I2bdd694518fbe233473896321a1f9758b46ed79b
Reviewed-on: https://go-review.googlesource.com/37666
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/internal/srcimporter/srcimporter.go
src/go/types/api.go
src/go/types/gotype.go
src/go/types/sizes.go

index 26d9d09037f021034d3323c9ddab59a6a77d585f..45fddb9feeef2ca2d23cb78e6a18d95d743f2801 100644 (file)
@@ -35,7 +35,7 @@ func New(ctxt *build.Context, fset *token.FileSet, packages map[string]*types.Pa
        return &Importer{
                ctxt:     ctxt,
                fset:     fset,
-               sizes:    types.SizesFor(ctxt.GOARCH), // uses go/types default if GOARCH not found
+               sizes:    types.SizesFor(ctxt.Compiler, ctxt.GOARCH), // uses go/types default if GOARCH not found
                packages: packages,
        }
 }
index cd8b19f024e17e8be491f269ce22efc54d81c493..1e99f4fb13712a89fab3f89c22b8f48c3bed3963 100644 (file)
@@ -121,7 +121,7 @@ type Config struct {
        Importer Importer
 
        // If Sizes != nil, it provides the sizing functions for package unsafe.
-       // Otherwise SizesFor("amd64") is used instead.
+       // Otherwise SizesFor("gc", "amd64") is used instead.
        Sizes Sizes
 
        // If DisableUnusedImportCheck is set, packages are not checked
index b466fb9fb26f83a88f8fe11e5b43d555ba887c5b..157fd54042e1438103205ec66dedd4f33f030ba7 100644 (file)
@@ -247,7 +247,7 @@ func checkPkgFiles(files []*ast.File) {
                        report(err)
                },
                Importer: importer.For(*compiler, nil),
-               Sizes:    types.SizesFor(build.Default.GOARCH),
+               Sizes:    types.SizesFor(build.Default.Compiler, build.Default.GOARCH),
        }
 
        defer func() {
index 67df9180f9bdbacc8b0efd8beeb032cb3d6e6593..4fa71b4d5e01a50a3fa9ff1894f67dde72c9faf5 100644 (file)
@@ -154,7 +154,7 @@ func (s *StdSizes) Sizeof(T Type) int64 {
 }
 
 // common architecture word sizes and alignments
-var archSizes = map[string]*StdSizes{
+var gcArchSizes = map[string]*StdSizes{
        "386":      {4, 4},
        "arm":      {4, 4},
        "arm64":    {8, 8},
@@ -171,16 +171,21 @@ var archSizes = map[string]*StdSizes{
        // update the doc string of SizesFor below.
 }
 
-// SizesFor returns the Sizes for one of these architectures:
+// SizesFor returns the Sizes used by a compiler for an architecture.
+// The result is nil if a compiler/architecture pair is not known.
+//
+// Supported architectures for compiler "gc":
 // "386", "arm", "arm64", "amd64", "amd64p32", "mips", "mipsle",
 // "mips64", "mips64le", "ppc64", "ppc64le", "s390x".
-// The result is nil if an architecture is not known.
-func SizesFor(arch string) Sizes {
-       return archSizes[arch]
+func SizesFor(compiler, arch string) Sizes {
+       if compiler != "gc" {
+               return nil
+       }
+       return gcArchSizes[arch]
 }
 
 // stdSizes is used if Config.Sizes == nil.
-var stdSizes = SizesFor("amd64")
+var stdSizes = SizesFor("gc", "amd64")
 
 func (conf *Config) alignof(T Type) int64 {
        if s := conf.Sizes; s != nil {