@@ -29,6 +29,7 @@ import (
29
29
)
30
30
31
31
var MaxGoRoutines int
32
+ var typeParamParent map [* types.TypeParam ]types.Object = make (map [* types.TypeParam ]types.Object )
32
33
33
34
func init () {
34
35
// this sets the number of threads that the Go runtime will spawn; this is separate
@@ -365,13 +366,13 @@ func extractObjects(tw *trap.Writer, scope *types.Scope, scopeLabel trap.Label)
365
366
// do not appear as objects in any scope, so they have to be dealt
366
367
// with separately in extractMethods.
367
368
if funcObj , ok := obj .(* types.Func ); ok {
368
- populateTypeParamParents (tw , funcObj .Type ().(* types.Signature ).TypeParams (), lbl )
369
- populateTypeParamParents (tw , funcObj .Type ().(* types.Signature ).RecvTypeParams (), lbl )
369
+ populateTypeParamParents (tw , funcObj .Type ().(* types.Signature ).TypeParams (), obj )
370
+ populateTypeParamParents (tw , funcObj .Type ().(* types.Signature ).RecvTypeParams (), obj )
370
371
}
371
372
// Populate type parameter parents for named types.
372
373
if typeNameObj , ok := obj .(* types.TypeName ); ok {
373
374
if tp , ok := typeNameObj .Type ().(* types.Named ); ok {
374
- populateTypeParamParents (tw , tp .TypeParams (), lbl )
375
+ populateTypeParamParents (tw , tp .TypeParams (), obj )
375
376
}
376
377
}
377
378
extractObject (tw , obj , lbl )
@@ -397,8 +398,8 @@ func extractMethod(tw *trap.Writer, meth *types.Func) trap.Label {
397
398
if ! exists {
398
399
// Populate type parameter parents for methods. They do not appear as
399
400
// objects in any scope, so they have to be dealt with separately here.
400
- populateTypeParamParents (tw , meth .Type ().(* types.Signature ).TypeParams (), methlbl )
401
- populateTypeParamParents (tw , meth .Type ().(* types.Signature ).RecvTypeParams (), methlbl )
401
+ populateTypeParamParents (tw , meth .Type ().(* types.Signature ).TypeParams (), meth )
402
+ populateTypeParamParents (tw , meth .Type ().(* types.Signature ).RecvTypeParams (), meth )
402
403
extractObject (tw , meth , methlbl )
403
404
}
404
405
@@ -1099,6 +1100,7 @@ func extractExprs(tw *trap.Writer, exprs []ast.Expr, parent trap.Label, idx int,
1099
1100
func extractTypeOf (tw * trap.Writer , expr ast.Expr , lbl trap.Label ) {
1100
1101
tp := typeOf (tw , expr )
1101
1102
if tp != nil {
1103
+ // log.Printf("Extracting type of expr %v", expr)
1102
1104
tplbl := extractType (tw , tp )
1103
1105
dbscheme .TypeOfTable .Emit (tw , lbl , tplbl )
1104
1106
}
@@ -1574,10 +1576,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
1574
1576
}
1575
1577
case * types.TypeParam :
1576
1578
kind = dbscheme .TypeParamType .Index ()
1577
- parentlbl , exists := tw .TypeParamParent [tp ]
1578
- if ! exists {
1579
- log .Fatalf ("Parent of type parameter does not exist: %s" , tp .String ())
1580
- }
1579
+ parentlbl := getTypeParamParentLabel (tw , tp )
1581
1580
constraintLabel := extractType (tw , tp .Constraint ())
1582
1581
dbscheme .TypeParamTable .Emit (tw , lbl , tp .Obj ().Name (), constraintLabel , parentlbl , tp .Index ())
1583
1582
case * types.Union :
@@ -1718,7 +1717,7 @@ func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
1718
1717
}
1719
1718
lbl = tw .Labeler .GlobalID (fmt .Sprintf ("{%s};namedtype" , entitylbl ))
1720
1719
case * types.TypeParam :
1721
- parentlbl := tw . TypeParamParent [ tp ]
1720
+ parentlbl := getTypeParamParentLabel ( tw , tp )
1722
1721
lbl = tw .Labeler .GlobalID (fmt .Sprintf ("{%v},%s;typeparamtype" , parentlbl , tp .Obj ().Name ()))
1723
1722
case * types.Union :
1724
1723
var b strings.Builder
@@ -1903,11 +1902,11 @@ func extractTypeParamDecls(tw *trap.Writer, fields *ast.FieldList, parent trap.L
1903
1902
}
1904
1903
}
1905
1904
1906
- // populateTypeParamParents sets `parentlbl ` as the parent of the elements of `typeparams`
1907
- func populateTypeParamParents (tw * trap.Writer , typeparams * types.TypeParamList , parentlbl trap. Label ) {
1905
+ // populateTypeParamParents sets `parent ` as the parent of the elements of `typeparams`
1906
+ func populateTypeParamParents (tw * trap.Writer , typeparams * types.TypeParamList , parent types. Object ) {
1908
1907
if typeparams != nil {
1909
1908
for idx := 0 ; idx < typeparams .Len (); idx ++ {
1910
- tw . TypeParamParent [ typeparams .At (idx )] = parentlbl
1909
+ setTypeParamParent ( typeparams .At (idx ), parent )
1911
1910
}
1912
1911
}
1913
1912
}
@@ -1999,3 +1998,24 @@ func trackInstantiatedStructFields(tw *trap.Writer, tp, origintp *types.Named) {
1999
1998
}
2000
1999
}
2001
2000
}
2001
+
2002
+ func getTypeParamParentLabel (tw * trap.Writer , tp * types.TypeParam ) trap.Label {
2003
+ parent , exists := typeParamParent [tp ]
2004
+ if ! exists {
2005
+ log .Fatalf ("Parent of type parameter does not exist: %s %s" , tp .String (), tp .Constraint ().String ())
2006
+ }
2007
+ parentlbl , _ := tw .Labeler .ScopedObjectID (parent , func () trap.Label {
2008
+ log .Fatalf ("getTypeLabel() called for parent of type parameter %s" , tp .String ())
2009
+ return trap .InvalidLabel
2010
+ })
2011
+ return parentlbl
2012
+ }
2013
+
2014
+ func setTypeParamParent (tp * types.TypeParam , newobj types.Object ) {
2015
+ obj , exists := typeParamParent [tp ]
2016
+ if ! exists {
2017
+ typeParamParent [tp ] = newobj
2018
+ } else if newobj != obj {
2019
+ log .Fatalf ("Parent of type parameter '%s %s' being set to a different value: '%s' vs '%s'" , tp .String (), tp .Constraint ().String (), obj , newobj )
2020
+ }
2021
+ }
0 commit comments