Skip to content

Commit d8fe4d2

Browse files
authored
Merge pull request github#18489 from owen-mc/go/rename-namedtype-definedtype
Go: Rename "named type" to "defined type"
2 parents 083c756 + 1a52398 commit d8fe4d2

File tree

34 files changed

+2319
-89
lines changed

34 files changed

+2319
-89
lines changed

go/downgrades/b3da71c3ac204b557c86e9d9c26012360bdbdccb/go.dbscheme

Lines changed: 552 additions & 0 deletions
Large diffs are not rendered by default.

go/downgrades/b3da71c3ac204b557c86e9d9c26012360bdbdccb/old.dbscheme

Lines changed: 552 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
description: Rename @definedtype to @namedtype
2+
compatibility: full

go/extractor/dbscheme/tables.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,13 @@ var BuiltinObjectType = NewUnionType("@builtinobject")
694694
// PkgObjectType is the type of imported packages
695695
var PkgObjectType = ObjectKind.NewBranch("@pkgobject")
696696

697-
// TypeObjectType is the type of declared or built-in named types
697+
// TypeObjectType is the type of named types (predeclared types, defined types, type parameters and aliases which refer to those things)
698698
var TypeObjectType = NewUnionType("@typeobject")
699699

700-
// DeclTypeObjectType is the type of declared named types
700+
// DeclTypeObjectType is the type of defined types, type parameters and aliases which refer to named types
701701
var DeclTypeObjectType = ObjectKind.NewBranch("@decltypeobject", TypeObjectType, DeclObjectType, TypeParamParentObjectType)
702702

703-
// BuiltinTypeObjectType is the type of built-in named types
703+
// BuiltinTypeObjectType is the type of built-in types (predeclared types)
704704
var BuiltinTypeObjectType = ObjectKind.NewBranch("@builtintypeobject", TypeObjectType, BuiltinObjectType)
705705

706706
// ValueObjectType is the type of declared or built-in variables or constants
@@ -855,8 +855,8 @@ var ChanTypes = map[gotypes.ChanDir]*BranchType{
855855
gotypes.SendRecv: TypeKind.NewBranch("@sendrcvchantype", ChanType),
856856
}
857857

858-
// NamedType is the type of named types
859-
var NamedType = TypeKind.NewBranch("@namedtype", CompositeType)
858+
// DefinedType is the type of defined types
859+
var DefinedType = TypeKind.NewBranch("@definedtype", CompositeType)
860860

861861
// TypeSetLiteral is the type of type set literals
862862
var TypeSetLiteral = TypeKind.NewBranch("@typesetliteraltype", CompositeType)
@@ -1080,10 +1080,10 @@ var FieldStructsTable = NewTable("fieldstructs",
10801080
EntityColumn(StructType, "struct"),
10811081
)
10821082

1083-
// MethodHostsTable maps interface methods to the named type they belong to
1083+
// MethodHostsTable maps interface methods to the defined type they belong to
10841084
var MethodHostsTable = NewTable("methodhosts",
10851085
EntityColumn(ObjectType, "method"),
1086-
EntityColumn(NamedType, "host"),
1086+
EntityColumn(DefinedType, "host"),
10871087
)
10881088

10891089
// DefsTable maps identifiers to the objects they define
@@ -1110,7 +1110,7 @@ var TypeOfTable = NewTable("type_of",
11101110
EntityColumn(TypeType, "tp"),
11111111
)
11121112

1113-
// TypeNameTable is the table associating named types with their names
1113+
// TypeNameTable is the table associating defined types with their names
11141114
var TypeNameTable = NewTable("typename",
11151115
EntityColumn(TypeType, "tp").Unique(),
11161116
StringColumn("name"),
@@ -1135,10 +1135,10 @@ var BaseTypeTable = NewTable("base_type",
11351135
EntityColumn(TypeType, "tp"),
11361136
)
11371137

1138-
// UnderlyingTypeTable is the table associating named types with their
1138+
// UnderlyingTypeTable is the table associating defined types with their
11391139
// underlying type
11401140
var UnderlyingTypeTable = NewTable("underlying_type",
1141-
EntityColumn(NamedType, "named").Unique(),
1141+
EntityColumn(DefinedType, "defined").Unique(),
11421142
EntityColumn(TypeType, "tp"),
11431143
)
11441144

go/extractor/extractor.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ func extractObjects(tw *trap.Writer, scope *types.Scope, scopeLabel trap.Label)
475475
populateTypeParamParents(funcObj.Type().(*types.Signature).TypeParams(), obj)
476476
populateTypeParamParents(funcObj.Type().(*types.Signature).RecvTypeParams(), obj)
477477
}
478-
// Populate type parameter parents for named types.
478+
// Populate type parameter parents for defined types and alias types.
479479
if typeNameObj, ok := obj.(*types.TypeName); ok {
480480
// `types.TypeName` represents a type with a name: a defined
481481
// type, an alias type, a type parameter, or a predeclared
@@ -574,7 +574,7 @@ func extractObject(tw *trap.Writer, obj types.Object, lbl trap.Label) {
574574
// For more information on objects, see:
575575
// https://github.com/golang/example/blob/master/gotypes/README.md#objects
576576
func extractObjectTypes(tw *trap.Writer) {
577-
// calling `extractType` on a named type will extract all methods defined
577+
// calling `extractType` on a defined type will extract all methods defined
578578
// on it, which will add new objects. Therefore we need to do this first
579579
// before we loop over all objects and emit them.
580580
changed := true
@@ -1695,7 +1695,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
16951695
extractElementType(tw, lbl, tp.Elem())
16961696
case *types.Named:
16971697
origintp := tp.Origin()
1698-
kind = dbscheme.NamedType.Index()
1698+
kind = dbscheme.DefinedType.Index()
16991699
dbscheme.TypeNameTable.Emit(tw, lbl, origintp.Obj().Name())
17001700
underlying := origintp.Underlying()
17011701
extractUnderlyingType(tw, lbl, underlying)
@@ -1767,9 +1767,9 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
17671767
// Type labels refer to global keys to ensure that if the same type is
17681768
// encountered during the extraction of different files it is still ultimately
17691769
// mapped to the same entity. In particular, this means that keys for compound
1770-
// types refer to the labels of their component types. For named types, the key
1770+
// types refer to the labels of their component types. For defined types, the key
17711771
// is constructed from their globally unique ID. This prevents cyclic type keys
1772-
// since type recursion in Go always goes through named types.
1772+
// since type recursion in Go always goes through defined types.
17731773
func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
17741774
tp = resolveTypeAlias(tp)
17751775
lbl, exists := tw.Labeler.TypeLabels[tp]
@@ -1874,12 +1874,12 @@ func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
18741874
origintp := tp.Origin()
18751875
entitylbl, exists := tw.Labeler.LookupObjectID(origintp.Obj(), lbl)
18761876
if entitylbl == trap.InvalidLabel {
1877-
panic(fmt.Sprintf("Cannot construct label for named type %v (underlying object is %v).\n", origintp, origintp.Obj()))
1877+
panic(fmt.Sprintf("Cannot construct label for defined type %v (underlying object is %v).\n", origintp, origintp.Obj()))
18781878
}
18791879
if !exists {
18801880
extractObject(tw, origintp.Obj(), entitylbl)
18811881
}
1882-
lbl = tw.Labeler.GlobalID(fmt.Sprintf("{%s};namedtype", entitylbl))
1882+
lbl = tw.Labeler.GlobalID(fmt.Sprintf("{%s};definedtype", entitylbl))
18831883
case *types.TypeParam:
18841884
parentlbl := getTypeParamParentLabel(tw, tp)
18851885
idx := tp.Index()
@@ -1921,9 +1921,9 @@ func extractBaseType(tw *trap.Writer, ptr trap.Label, base types.Type) {
19211921
}
19221922

19231923
// extractUnderlyingType extracts `underlying` as the underlying type of the
1924-
// named type `named`
1925-
func extractUnderlyingType(tw *trap.Writer, named trap.Label, underlying types.Type) {
1926-
dbscheme.UnderlyingTypeTable.Emit(tw, named, extractType(tw, underlying))
1924+
// defined type `defined`
1925+
func extractUnderlyingType(tw *trap.Writer, defined trap.Label, underlying types.Type) {
1926+
dbscheme.UnderlyingTypeTable.Emit(tw, defined, extractType(tw, underlying))
19271927
}
19281928

19291929
// extractComponentType extracts `component` as the `idx`th component type of `parent` with name `name`
@@ -2173,8 +2173,8 @@ func checkObjectNotSpecialized(obj types.Object) {
21732173
log.Fatalf("Encountered unexpected specialization %s of generic variable object %s", varObj.String(), varObj.Origin().String())
21742174
}
21752175
if typeNameObj, ok := obj.(*types.TypeName); ok {
2176-
if namedType, ok := typeNameObj.Type().(*types.Named); ok && namedType != namedType.Origin() {
2177-
log.Fatalf("Encountered type object for specialization %s of named type %s", namedType.String(), namedType.Origin().String())
2176+
if definedType, ok := typeNameObj.Type().(*types.Named); ok && definedType != definedType.Origin() {
2177+
log.Fatalf("Encountered type object for specialization %s of defined type %s", definedType.String(), definedType.Origin().String())
21782178
}
21792179
}
21802180
}

go/extractor/trap/labels.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ func findMethodWithGivenReceiver(object types.Object) *types.Func {
181181

182182
// findMethodWithGivenReceiver finds a method on type `tp` with `object` as its receiver, if one exists
183183
func findMethodOnTypeWithGivenReceiver(tp types.Type, object types.Object) *types.Func {
184-
if namedType, ok := tp.(*types.Named); ok {
185-
for i := 0; i < namedType.NumMethods(); i++ {
186-
meth := namedType.Method(i)
184+
if definedType, ok := tp.(*types.Named); ok {
185+
for i := 0; i < definedType.NumMethods(); i++ {
186+
meth := definedType.Method(i)
187187
if object == meth.Type().(*types.Signature).Recv() {
188188
return meth
189189
}

go/ql/examples/snippets/incompleteswitchoverenum.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import go
1111

12-
from ExpressionSwitchStmt ss, DeclaredConstant c, NamedType t
12+
from ExpressionSwitchStmt ss, DeclaredConstant c, DefinedType t
1313
where
1414
t.getUnderlyingType() instanceof IntegerType and
1515
t = ss.getExpr().getType() and
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: deprecated
3+
---
4+
* The class `NamedType` has been deprecated. Use the new class `DefinedType` instead. This better matches the terminology used in the Go language specification, which was changed in Go 1.9.
5+
* The member predicate `getNamedType` on `GoMicro::ServiceInterfaceType` has been deprecated. Use the new member predicate `getDefinedType` instead.
6+
* The member predicate `getNamedType` on `Twirp::ServiceInterfaceType` has been deprecated. Use the new member predicate `getDefinedType` instead.

go/ql/lib/go.dbscheme

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ methodreceivers(unique int method: @object ref, int receiver: @object ref);
184184

185185
fieldstructs(unique int field: @object ref, int struct: @structtype ref);
186186

187-
methodhosts(int method: @object ref, int host: @namedtype ref);
187+
methodhosts(int method: @object ref, int host: @definedtype ref);
188188

189189
defs(int ident: @ident ref, int object: @object ref);
190190

@@ -202,7 +202,7 @@ element_type(unique int container: @containertype ref, int tp: @type ref);
202202

203203
base_type(unique int ptr: @pointertype ref, int tp: @type ref);
204204

205-
underlying_type(unique int named: @namedtype ref, int tp: @type ref);
205+
underlying_type(unique int defined: @definedtype ref, int tp: @type ref);
206206

207207
#keyset[parent, index]
208208
component_types(int parent: @compositetype ref, int index: int ref, string name: string ref, int tp: @type ref);
@@ -506,7 +506,7 @@ case @type.kind of
506506
| 35 = @sendchantype
507507
| 36 = @recvchantype
508508
| 37 = @sendrcvchantype
509-
| 38 = @namedtype
509+
| 38 = @definedtype
510510
| 39 = @typesetliteraltype;
511511

512512
@basictype = @booltype | @numerictype | @stringtype | @literaltype | @invalidtype | @unsafepointertype;
@@ -531,7 +531,7 @@ case @type.kind of
531531
| @stringliteraltype | @nilliteraltype;
532532

533533
@compositetype = @typeparamtype | @containertype | @structtype | @pointertype | @interfacetype | @tupletype
534-
| @signaturetype | @namedtype | @typesetliteraltype;
534+
| @signaturetype | @definedtype | @typesetliteraltype;
535535

536536
@containertype = @arraytype | @slicetype | @maptype | @chantype;
537537

go/ql/lib/go.dbscheme.stats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@
681681
<v>101202</v>
682682
</e>
683683
<e>
684-
<k>@namedtype</k>
684+
<k>@definedtype</k>
685685
<v>12852686</v>
686686
</e>
687687
<e>

0 commit comments

Comments
 (0)