Skip to content

Commit 6aadfcd

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent ec177e4 commit 6aadfcd

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

api/go1.15.txt

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ pkg debug/pe, const IMAGE_SUBSYSTEM_XBOX = 14
114114
pkg debug/pe, const IMAGE_SUBSYSTEM_XBOX ideal-int
115115
pkg go/printer, const StdFormat = 16
116116
pkg go/printer, const StdFormat Mode
117-
pkg go/types, type Config struct, UsesCgo bool
118117
pkg math/big, method (*Int) FillBytes([]uint8) []uint8
119118
pkg net, method (*Resolver) LookupIP(context.Context, string, string) ([]IP, error)
120119
pkg net/url, method (*URL) EscapedFragment() string

src/go/internal/srcimporter/srcimporter.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"path/filepath"
2121
"strings"
2222
"sync"
23+
_ "unsafe" // for go:linkname
2324
)
2425

2526
// 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
133134
// build.Context's VFS.
134135
conf.FakeImportC = true
135136
} else {
136-
conf.UsesCgo = true
137+
setUsesCgo(&conf)
137138
file, err := p.cgo(bp)
138139
if err != nil {
139140
return nil, err
@@ -260,3 +261,6 @@ func (p *Importer) joinPath(elem ...string) string {
260261
}
261262
return filepath.Join(elem...)
262263
}
264+
265+
//go:linkname setUsesCgo go/types.srcimporter_setUsesCgo
266+
func setUsesCgo(conf *types.Config)

src/go/types/api.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ type Config struct {
105105
// Do not use casually!
106106
FakeImportC bool
107107

108-
// If UsesCgo is set, the type checker expects the
108+
// If go115UsesCgo is set, the type checker expects the
109109
// _cgo_gotypes.go file generated by running cmd/cgo to be
110110
// provided as a package source file. Qualified identifiers
111111
// referring to package C will be resolved to cgo-provided
112112
// declarations within _cgo_gotypes.go.
113113
//
114-
// It is an error to set both FakeImportC and UsesCgo.
115-
UsesCgo bool
114+
// It is an error to set both FakeImportC and go115UsesCgo.
115+
go115UsesCgo bool
116116

117117
// If Error != nil, it is called with each error found
118118
// during type checking; err has dynamic type Error.
@@ -140,6 +140,10 @@ type Config struct {
140140
DisableUnusedImportCheck bool
141141
}
142142

143+
func srcimporter_setUsesCgo(conf *Config) {
144+
conf.go115UsesCgo = true
145+
}
146+
143147
// Info holds result type information for a type-checked package.
144148
// Only the information for which a map is provided is collected.
145149
// If the package has type errors, the collected information may

src/go/types/check.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ func (check *Checker) handleBailout(err *error) {
248248
// Files checks the provided files as part of the checker's package.
249249
func (check *Checker) Files(files []*ast.File) error { return check.checkFiles(files) }
250250

251-
var errBadCgo = errors.New("cannot use FakeImportC and UsesCgo together")
251+
var errBadCgo = errors.New("cannot use FakeImportC and go115UsesCgo together")
252252

253253
func (check *Checker) checkFiles(files []*ast.File) (err error) {
254-
if check.conf.FakeImportC && check.conf.UsesCgo {
254+
if check.conf.FakeImportC && check.conf.go115UsesCgo {
255255
return errBadCgo
256256
}
257257

src/go/types/resolver.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ func (check *Checker) importPackage(pos token.Pos, path, dir string) *Package {
141141
}
142142

143143
// no package yet => import it
144-
if path == "C" && (check.conf.FakeImportC || check.conf.UsesCgo) {
144+
if path == "C" && (check.conf.FakeImportC || check.conf.go115UsesCgo) {
145145
imp = NewPackage("C", "C")
146146
imp.fake = true // package scope is not populated
147-
imp.cgo = check.conf.UsesCgo
147+
imp.cgo = check.conf.go115UsesCgo
148148
} else {
149149
// ordinary import
150150
var err error

0 commit comments

Comments
 (0)