compiler: disambiguate function-local named types#5336
Open
jakebailey wants to merge 3 commits intotinygo-org:devfrom
Open
compiler: disambiguate function-local named types#5336jakebailey wants to merge 3 commits intotinygo-org:devfrom
jakebailey wants to merge 3 commits intotinygo-org:devfrom
Conversation
aykevl
reviewed
Apr 22, 2026
Member
aykevl
left a comment
There was a problem hiding this comment.
Didn't do a full review but here are some notes.
| pkg *types.Package | ||
| packageDir string // directory for this package | ||
| runtimePkg *types.Package | ||
| localTypeNames map[*types.TypeName]string |
Member
There was a problem hiding this comment.
Have you looked at typeutil.Map? It might do exactly what you want with much less complexity.
Member
Author
There was a problem hiding this comment.
Yeah, I just didn't think it really added much, because all it does is store the type, which we then just .Obj() on, so doesn't really do anything?
Comment on lines
+710
to
+711
| // Names depend only on intrinsic SSA properties (RelString and the | ||
| // raw token.Pos used as a sort key), so any package compiling the |
Member
There was a problem hiding this comment.
To clarify: token.Pos is not used to uniquely identify a type, it is only used for sorting?
Asking since some things (like CGo) might not produce unique locations.
Member
Author
There was a problem hiding this comment.
Correct, it is not, though I thought cgo was not supported in tinygo?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5180
This is an alternative to #5183 which handles more cases.
This is really tricky and I think only possible through the more complicated method in this PR, where we have to walk through more stuff to assign names where needed. As far as I can tell, this works even with build caching, but obviously comes at a cost.
I recommend looking just at the last commit, as that's the one that shows the change including how test golden files get updated.