mirror of
https://github.com/golang/go
synced 2024-11-11 19:41:36 -07:00
go/types: rename UsesCgo to go115UsesCgo
This API and functionality was added late in the Go 1.15 release cycle, and use within gopls has revealed some shortcomings. It's possible (but not decided) that we'll want a different API long-term, so for now this CL renames UsesCgo to a non-exported name to avoid long-term commitment under the Go 1 compat guarantee. Updates #16623. Updates #39072. Change-Id: I04bc0c161a84adebe43e926df5df406bc794c3db Reviewed-on: https://go-review.googlesource.com/c/go/+/237417 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
ec177e4c83
commit
6aadfcdfad
@ -114,7 +114,6 @@ pkg debug/pe, const IMAGE_SUBSYSTEM_XBOX = 14
|
|||||||
pkg debug/pe, const IMAGE_SUBSYSTEM_XBOX ideal-int
|
pkg debug/pe, const IMAGE_SUBSYSTEM_XBOX ideal-int
|
||||||
pkg go/printer, const StdFormat = 16
|
pkg go/printer, const StdFormat = 16
|
||||||
pkg go/printer, const StdFormat Mode
|
pkg go/printer, const StdFormat Mode
|
||||||
pkg go/types, type Config struct, UsesCgo bool
|
|
||||||
pkg math/big, method (*Int) FillBytes([]uint8) []uint8
|
pkg math/big, method (*Int) FillBytes([]uint8) []uint8
|
||||||
pkg net, method (*Resolver) LookupIP(context.Context, string, string) ([]IP, error)
|
pkg net, method (*Resolver) LookupIP(context.Context, string, string) ([]IP, error)
|
||||||
pkg net/url, method (*URL) EscapedFragment() string
|
pkg net/url, method (*URL) EscapedFragment() string
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
_ "unsafe" // for go:linkname
|
||||||
)
|
)
|
||||||
|
|
||||||
// An Importer provides the context for importing packages from source code.
|
// 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.
|
// build.Context's VFS.
|
||||||
conf.FakeImportC = true
|
conf.FakeImportC = true
|
||||||
} else {
|
} else {
|
||||||
conf.UsesCgo = true
|
setUsesCgo(&conf)
|
||||||
file, err := p.cgo(bp)
|
file, err := p.cgo(bp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -260,3 +261,6 @@ func (p *Importer) joinPath(elem ...string) string {
|
|||||||
}
|
}
|
||||||
return filepath.Join(elem...)
|
return filepath.Join(elem...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:linkname setUsesCgo go/types.srcimporter_setUsesCgo
|
||||||
|
func setUsesCgo(conf *types.Config)
|
||||||
|
@ -105,14 +105,14 @@ type Config struct {
|
|||||||
// Do not use casually!
|
// Do not use casually!
|
||||||
FakeImportC bool
|
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
|
// _cgo_gotypes.go file generated by running cmd/cgo to be
|
||||||
// provided as a package source file. Qualified identifiers
|
// provided as a package source file. Qualified identifiers
|
||||||
// referring to package C will be resolved to cgo-provided
|
// referring to package C will be resolved to cgo-provided
|
||||||
// declarations within _cgo_gotypes.go.
|
// declarations within _cgo_gotypes.go.
|
||||||
//
|
//
|
||||||
// It is an error to set both FakeImportC and UsesCgo.
|
// It is an error to set both FakeImportC and go115UsesCgo.
|
||||||
UsesCgo bool
|
go115UsesCgo bool
|
||||||
|
|
||||||
// If Error != nil, it is called with each error found
|
// If Error != nil, it is called with each error found
|
||||||
// during type checking; err has dynamic type Error.
|
// during type checking; err has dynamic type Error.
|
||||||
@ -140,6 +140,10 @@ type Config struct {
|
|||||||
DisableUnusedImportCheck bool
|
DisableUnusedImportCheck bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func srcimporter_setUsesCgo(conf *Config) {
|
||||||
|
conf.go115UsesCgo = true
|
||||||
|
}
|
||||||
|
|
||||||
// Info holds result type information for a type-checked package.
|
// Info holds result type information for a type-checked package.
|
||||||
// Only the information for which a map is provided is collected.
|
// Only the information for which a map is provided is collected.
|
||||||
// If the package has type errors, the collected information may
|
// If the package has type errors, the collected information may
|
||||||
|
@ -248,10 +248,10 @@ func (check *Checker) handleBailout(err *error) {
|
|||||||
// Files checks the provided files as part of the checker's package.
|
// Files checks the provided files as part of the checker's package.
|
||||||
func (check *Checker) Files(files []*ast.File) error { return check.checkFiles(files) }
|
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) {
|
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
|
return errBadCgo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,10 +141,10 @@ func (check *Checker) importPackage(pos token.Pos, path, dir string) *Package {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no package yet => import it
|
// 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 = NewPackage("C", "C")
|
||||||
imp.fake = true // package scope is not populated
|
imp.fake = true // package scope is not populated
|
||||||
imp.cgo = check.conf.UsesCgo
|
imp.cgo = check.conf.go115UsesCgo
|
||||||
} else {
|
} else {
|
||||||
// ordinary import
|
// ordinary import
|
||||||
var err error
|
var err error
|
||||||
|
Loading…
Reference in New Issue
Block a user