go/loader: ignore (*build.Package).Goroot flag when handling "unsafe"

For the default build.Context, the Package.Goroot flag indicates when a
package was loaded from the standard library.  Until now, the loader
used it to enable the typechecker's intrinsics for the "unsafe" package.
This seemed like a good check, but it is troublesome for clients that
use a nonstandard build.Context.  For example, if a client defines
nonstandard Context hooks that load all packages, whether standard or
user-defined, from a flat sstable, there is no way for those hooks to
indicate which packages should have this flag set and which not.  As a
result the contents of the "unsafe" package directory are treated as Go
source code when they are merely documentation.

Change-Id: Iea0a7cc9877507d73606391293971a28279c4e4b
Reviewed-on: https://go-review.googlesource.com/19188
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Alan Donovan 2016-02-04 11:15:46 -05:00
parent 9a6ae37d4e
commit 02f1928320
2 changed files with 4 additions and 4 deletions

View File

@ -711,7 +711,7 @@ func (conf *Config) build() *build.Context {
// 'x': include external *_test.go source files. (XTestGoFiles) // 'x': include external *_test.go source files. (XTestGoFiles)
// //
func (conf *Config) parsePackageFiles(bp *build.Package, which rune) ([]*ast.File, []error) { func (conf *Config) parsePackageFiles(bp *build.Package, which rune) ([]*ast.File, []error) {
if bp.Goroot && bp.ImportPath == "unsafe" { if bp.ImportPath == "unsafe" {
return nil, nil return nil, nil
} }
var filenames []string var filenames []string
@ -767,7 +767,7 @@ func (imp *importer) doImport(from *PackageInfo, to string) (*types.Package, err
// The standard unsafe package is handled specially, // The standard unsafe package is handled specially,
// and has no PackageInfo. // and has no PackageInfo.
if bp.Goroot && bp.ImportPath == "unsafe" { if bp.ImportPath == "unsafe" {
return types.Unsafe, nil return types.Unsafe, nil
} }

View File

@ -714,7 +714,7 @@ func (conf *Config) build() *build.Context {
// 'x': include external *_test.go source files. (XTestGoFiles) // 'x': include external *_test.go source files. (XTestGoFiles)
// //
func (conf *Config) parsePackageFiles(bp *build.Package, which rune) ([]*ast.File, []error) { func (conf *Config) parsePackageFiles(bp *build.Package, which rune) ([]*ast.File, []error) {
if bp.Goroot && bp.ImportPath == "unsafe" { if bp.ImportPath == "unsafe" {
return nil, nil return nil, nil
} }
var filenames []string var filenames []string
@ -770,7 +770,7 @@ func (imp *importer) doImport(from *PackageInfo, to string) (*types.Package, err
// The standard unsafe package is handled specially, // The standard unsafe package is handled specially,
// and has no PackageInfo. // and has no PackageInfo.
if bp.Goroot && bp.ImportPath == "unsafe" { if bp.ImportPath == "unsafe" {
return types.Unsafe, nil return types.Unsafe, nil
} }