Unique extended existential shapes using the generalized AST type #42563
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.
I wrote out this whole analysis of why different existential types might have the same logical content, and then I turned around and immediately uniqued existential shapes purely by logical content rather than the (generalized) formal type. Oh well. At least it's not too late to make ABI changes like this.
We now store a reference to a mangling of the generalized formal type directly in the shape. This type alone is sufficient to unique the shape:
By the nature of the generalization algorithm, every type parameter in the generalization signature should be mentioned in the generalized formal type in a deterministic order.
By the nature of the generalization algorithm, every other requirement in the generalization signature should be implied by the positions in which generalization type parameters appear (e.g. because the formal type is C & P, where C constrains its type parameter for well-formedness).
The requirement signature and type expression are extracted from the existential type.
As a result, we no longer rely on computing a unique hash at compile time.
Storing this separately from the requirement signature potentially allows runtimes with general shape support to work with future extensions to existential types even if they cannot demangle the generalized formal type.
Storing the generalized formal type also allows us to easily and reliably extract the formal type of the existential. Otherwise, it's quite a heroic endeavor to match requirements back up with primary associated types. Doing so would also only allows us to extract some matching formal type, not necessarily the right formal type. So there's some good synergy here.