diff --git a/debugdir.go b/debugdir.go index 3e487ac..275d7ea 100644 --- a/debugdir.go +++ b/debugdir.go @@ -142,25 +142,25 @@ func debugDirNeedsRebuild() (bool, error) { return false, err } sawBuildInputs := false + missingArtifacts := false for _, lpkg := range sharedCache.ListedPackages { if len(lpkg.GarbleActionID) == 0 { continue } if len(lpkg.CompiledGoFiles) > 0 { sawBuildInputs = true - if debugArtifactsExistForPkg(fsCache, lpkg, debugCacheKindCompile) { - return false, nil + if !debugArtifactsExistForPkg(fsCache, lpkg, debugCacheKindCompile) { + missingArtifacts = true } } if len(lpkg.SFiles) > 0 { sawBuildInputs = true - if debugArtifactsExistForPkg(fsCache, lpkg, debugCacheKindAsm) { - return false, nil + if !debugArtifactsExistForPkg(fsCache, lpkg, debugCacheKindAsm) { + missingArtifacts = true } } } - // If no debug artifacts exist yet, force one full rebuild to warm cache. - // Once at least one cache entry exists, incremental builds can repopulate - // from cache + newly rebuilt packages without forcing -a. - return sawBuildInputs, nil + // For -debugdir to be complete, we either need artifacts in cache for every + // package input, or we need to force one full rebuild with -a. + return sawBuildInputs && missingArtifacts, nil } diff --git a/reverse.go b/reverse.go index 95136fd..69136eb 100644 --- a/reverse.go +++ b/reverse.go @@ -103,11 +103,15 @@ One can reverse a captured panic stack trace as follows: if obj == nil || !obj.IsField() { continue } - strct := fieldToStruct[obj] + originObj := obj.Origin() + strct := fieldToStruct[originObj] + if strct == nil { + strct = fieldToStruct[obj] + } if strct == nil { panic("could not find struct for field " + name.Name) } - replaces = append(replaces, hashWithStruct(strct, obj), name.Name) + replaces = append(replaces, hashWithStruct(strct, originObj), name.Name) } case *ast.CallExpr: diff --git a/testdata/script/typeparams.txtar b/testdata/script/typeparams.txtar index 7469959..3a41a0d 100644 --- a/testdata/script/typeparams.txtar +++ b/testdata/script/typeparams.txtar @@ -16,6 +16,11 @@ func main() { g2 := GenericGraph[*[]byte]{Content: new([]byte)} g2.Edges = make([]GenericGraph[*[]byte], 1) + + var ga genericAlias + ga.list = nil + var gan genericAliasNamed + gan.list = nil } func GenericFunc[GenericParamA, B any](x GenericParamA, y B) {} @@ -66,3 +71,10 @@ func (w *AsyncResult[oldT, newT]) AsResult() Result[newT] { } func (w *AsyncResult[oldT, newT]) Redirect(struct {ret newT}) {} + +type genericAlias = generic[int] +type generic[T any] struct { + list *T +} + +type genericAliasNamed genericAlias diff --git a/transformer.go b/transformer.go index 7f5d497..b45374b 100644 --- a/transformer.go +++ b/transformer.go @@ -166,10 +166,11 @@ func recordType(used, origin types.Type, done map[*types.Named]bool, fieldToStru origin := origin.(*types.Struct) for i := range used.NumFields() { field := used.Field(i) - fieldToStruct[field] = origin + fieldToStruct[field.Origin()] = origin if field.Embedded() { - recordType(field.Type(), origin.Field(i).Type(), done, fieldToStruct) + originField := origin.Field(i) + recordType(field.Type(), originField.Type(), done, fieldToStruct) } } } @@ -1237,11 +1238,12 @@ func (tf *transformer) transformGoFile(file *ast.File) *ast.File { // any field is unexported. If that is done, add a test // that ensures unexported fields from different // packages result in different obfuscated names. - strct := tf.fieldToStruct[obj] + originObj := obj.Origin() + strct := tf.fieldToStruct[originObj] if strct == nil { panic("could not find struct for field " + name) } - node.Name = hashWithStruct(strct, obj) + node.Name = hashWithStruct(strct, originObj) if flagDebug { // TODO(mvdan): remove once https://go.dev/issue/53465 if fixed log.Printf("%s %q hashed with struct fields to %q", debugName, name, node.Name) }