Skip to content

Commit 7ab2296

Browse files
compiler: export the type "any" as a builtin
Otherwise we can't tell the difference between builtin type "any" and a locally defined type "any". This will require updates to the gccgo export data parsers in the main Go repo and the x/tools repo. These updates are https://go.dev/cl/537195 and https://go.dev/cl/537215. Change-Id: Ief043db22265d7e14b192fc4d3e1ef845b66c7fe Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/536715 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent ddf3758 commit 7ab2296

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

Diff for: go/export.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,7 @@ Export::register_builtin_types(Gogo* gogo)
16611661
this->register_builtin_type(gogo, "error", BUILTIN_ERROR);
16621662
this->register_builtin_type(gogo, "byte", BUILTIN_BYTE);
16631663
this->register_builtin_type(gogo, "rune", BUILTIN_RUNE);
1664+
this->register_builtin_type(gogo, "any", BUILTIN_ANY);
16641665
}
16651666

16661667
// Register one builtin type in the export table.

Diff for: go/export.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ enum Builtin_code
5151
BUILTIN_ERROR = -19,
5252
BUILTIN_BYTE = -20,
5353
BUILTIN_RUNE = -21,
54+
BUILTIN_ANY = -22,
5455

55-
SMALLEST_BUILTIN_CODE = -21
56+
SMALLEST_BUILTIN_CODE = -22
5657
};
5758

5859
// Export data version number. New export data is written with the

Diff for: go/import.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,7 @@ Import::register_builtin_types(Gogo* gogo)
14081408
this->register_builtin_type(gogo, "error", BUILTIN_ERROR);
14091409
this->register_builtin_type(gogo, "byte", BUILTIN_BYTE);
14101410
this->register_builtin_type(gogo, "rune", BUILTIN_RUNE);
1411+
this->register_builtin_type(gogo, "any", BUILTIN_ANY);
14111412
}
14121413

14131414
// Register a single builtin type.

Diff for: libgo/go/go/internal/gccgoimporter/parser.go

+16-14
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ func (p *parser) parseQualifiedNameStr(unquotedName string) (pkgpath, name strin
187187
// getPkg returns the package for a given path. If the package is
188188
// not found but we have a package name, create the package and
189189
// add it to the p.imports map.
190-
//
191190
func (p *parser) getPkg(pkgpath, name string) *types.Package {
192191
// package unsafe is not in the imports map - handle explicitly
193192
if pkgpath == "unsafe" {
@@ -904,6 +903,7 @@ const (
904903
gccgoBuiltinERROR = 19
905904
gccgoBuiltinBYTE = 20
906905
gccgoBuiltinRUNE = 21
906+
gccgoBuiltinANY = 22
907907
)
908908

909909
func lookupBuiltinType(typ int) types.Type {
@@ -928,13 +928,13 @@ func lookupBuiltinType(typ int) types.Type {
928928
gccgoBuiltinERROR: types.Universe.Lookup("error").Type(),
929929
gccgoBuiltinBYTE: types.Universe.Lookup("byte").Type(),
930930
gccgoBuiltinRUNE: types.Universe.Lookup("rune").Type(),
931+
gccgoBuiltinANY: types.Universe.Lookup("any").Type(),
931932
}[typ]
932933
}
933934

934935
// Type = "<" "type" ( "-" int | int [ TypeSpec ] ) ">" .
935936
//
936937
// parseType updates the type map to t for all type numbers n.
937-
//
938938
func (p *parser) parseType(pkg *types.Package, n ...any) types.Type {
939939
p.expect('<')
940940
t, _ := p.parseTypeAfterAngle(pkg, n...)
@@ -1117,9 +1117,10 @@ func (p *parser) maybeCreatePackage() {
11171117
}
11181118

11191119
// InitDataDirective = ( "v1" | "v2" | "v3" ) ";" |
1120-
// "priority" int ";" |
1121-
// "init" { PackageInit } ";" |
1122-
// "checksum" unquotedString ";" .
1120+
//
1121+
// "priority" int ";" |
1122+
// "init" { PackageInit } ";" |
1123+
// "checksum" unquotedString ";" .
11231124
func (p *parser) parseInitDataDirective() {
11241125
if p.tok != scanner.Ident {
11251126
// unexpected token kind; panic
@@ -1170,15 +1171,16 @@ func (p *parser) parseInitDataDirective() {
11701171
}
11711172

11721173
// Directive = InitDataDirective |
1173-
// "package" unquotedString [ unquotedString ] [ unquotedString ] ";" |
1174-
// "pkgpath" unquotedString ";" |
1175-
// "prefix" unquotedString ";" |
1176-
// "import" unquotedString unquotedString string ";" |
1177-
// "indirectimport" unquotedString unquotedstring ";" |
1178-
// "func" Func ";" |
1179-
// "type" Type ";" |
1180-
// "var" Var ";" |
1181-
// "const" Const ";" .
1174+
//
1175+
// "package" unquotedString [ unquotedString ] [ unquotedString ] ";" |
1176+
// "pkgpath" unquotedString ";" |
1177+
// "prefix" unquotedString ";" |
1178+
// "import" unquotedString unquotedString string ";" |
1179+
// "indirectimport" unquotedString unquotedstring ";" |
1180+
// "func" Func ";" |
1181+
// "type" Type ";" |
1182+
// "var" Var ";" |
1183+
// "const" Const ";" .
11821184
func (p *parser) parseDirective() {
11831185
if p.tok != scanner.Ident {
11841186
// unexpected token kind; panic

0 commit comments

Comments
 (0)