diff --git a/api/go1.15.txt b/api/go1.15.txt index f16faa07800b2..b51837cf3806c 100644 --- a/api/go1.15.txt +++ b/api/go1.15.txt @@ -114,7 +114,6 @@ pkg debug/pe, const IMAGE_SUBSYSTEM_XBOX = 14 pkg debug/pe, const IMAGE_SUBSYSTEM_XBOX ideal-int pkg go/printer, const StdFormat = 16 pkg go/printer, const StdFormat Mode -pkg go/types, type Config struct, UsesCgo bool pkg math/big, method (*Int) FillBytes([]uint8) []uint8 pkg net, method (*Resolver) LookupIP(context.Context, string, string) ([]IP, error) pkg net/url, method (*URL) EscapedFragment() string diff --git a/src/go/internal/srcimporter/srcimporter.go b/src/go/internal/srcimporter/srcimporter.go index daef27c8b9dc8..90bb3a9bc1155 100644 --- a/src/go/internal/srcimporter/srcimporter.go +++ b/src/go/internal/srcimporter/srcimporter.go @@ -20,6 +20,7 @@ import ( "path/filepath" "strings" "sync" + _ "unsafe" // for go:linkname ) // An Importer provides the context for importing packages from source code. @@ -133,7 +134,7 @@ func (p *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*type // build.Context's VFS. conf.FakeImportC = true } else { - conf.UsesCgo = true + setUsesCgo(&conf) file, err := p.cgo(bp) if err != nil { return nil, err @@ -260,3 +261,6 @@ func (p *Importer) joinPath(elem ...string) string { } return filepath.Join(elem...) } + +//go:linkname setUsesCgo go/types.srcimporter_setUsesCgo +func setUsesCgo(conf *types.Config) diff --git a/src/go/types/api.go b/src/go/types/api.go index 7787b88906e35..1abcd9d951227 100644 --- a/src/go/types/api.go +++ b/src/go/types/api.go @@ -105,14 +105,14 @@ type Config struct { // Do not use casually! FakeImportC bool - // If UsesCgo is set, the type checker expects the + // If go115UsesCgo is set, the type checker expects the // _cgo_gotypes.go file generated by running cmd/cgo to be // provided as a package source file. Qualified identifiers // referring to package C will be resolved to cgo-provided // declarations within _cgo_gotypes.go. // - // It is an error to set both FakeImportC and UsesCgo. - UsesCgo bool + // It is an error to set both FakeImportC and go115UsesCgo. + go115UsesCgo bool // If Error != nil, it is called with each error found // during type checking; err has dynamic type Error. @@ -140,6 +140,10 @@ type Config struct { DisableUnusedImportCheck bool } +func srcimporter_setUsesCgo(conf *Config) { + conf.go115UsesCgo = true +} + // Info holds result type information for a type-checked package. // Only the information for which a map is provided is collected. // If the package has type errors, the collected information may diff --git a/src/go/types/check.go b/src/go/types/check.go index a94770ffef3ed..007babdf9d67a 100644 --- a/src/go/types/check.go +++ b/src/go/types/check.go @@ -248,10 +248,10 @@ func (check *Checker) handleBailout(err *error) { // Files checks the provided files as part of the checker's package. func (check *Checker) Files(files []*ast.File) error { return check.checkFiles(files) } -var errBadCgo = errors.New("cannot use FakeImportC and UsesCgo together") +var errBadCgo = errors.New("cannot use FakeImportC and go115UsesCgo together") func (check *Checker) checkFiles(files []*ast.File) (err error) { - if check.conf.FakeImportC && check.conf.UsesCgo { + if check.conf.FakeImportC && check.conf.go115UsesCgo { return errBadCgo } diff --git a/src/go/types/resolver.go b/src/go/types/resolver.go index f80b4ec7841f1..078adc5ec7808 100644 --- a/src/go/types/resolver.go +++ b/src/go/types/resolver.go @@ -141,10 +141,10 @@ func (check *Checker) importPackage(pos token.Pos, path, dir string) *Package { } // no package yet => import it - if path == "C" && (check.conf.FakeImportC || check.conf.UsesCgo) { + if path == "C" && (check.conf.FakeImportC || check.conf.go115UsesCgo) { imp = NewPackage("C", "C") imp.fake = true // package scope is not populated - imp.cgo = check.conf.UsesCgo + imp.cgo = check.conf.go115UsesCgo } else { // ordinary import var err error