-
Notifications
You must be signed in to change notification settings - Fork 49
ssa: canonicalize basic aliases in generic symbols #2367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,6 +245,15 @@ func typeArgString(t types.Type) string { | |
| case *types.Alias: | ||
| return typeArgString(types.Unalias(t)) | ||
| case *types.Basic: | ||
| // byte and rune are aliases for uint8 and int32. go/types may cache a | ||
| // generic instance using either spelling, so ABI symbols must not | ||
| // depend on which spelling was instantiated first. | ||
| switch t.Kind() { | ||
| case types.Byte: | ||
| return types.Typ[types.Uint8].String() | ||
| case types.Rune: | ||
| return types.Typ[types.Int32].String() | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: this canonicalization now lives in four places in the package ( |
||
| return t.String() | ||
| case *types.Named: | ||
| return namedLikeTypeArgString(t.Obj(), t.TypeArgs()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the switch is keyed on
Kind(), andtypes.Byte/types.Runeare the same constants astypes.Uint8/types.Int32. So these cases also match plainuint8/int32arguments (harmless no-op here), and a futurecase types.Uint8:/case types.Int32:would be a duplicate-case compile error. A one-line note that the branch is keyed on kind (which can't distinguish the alias from the target) would prevent that foot-gun. Non-blocking.