Track const type information in a separate lattice element #44447
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.
As mentioned in #44402,
widenconst
on aConst
whose value is aType
can be quite slow - slow enough to show up noticeably in profiles. This attempts to address that by splitting theConst
lattice element into two:Const
andConstType
, the former being used for non-Type
values and the latter being used forType
s, additionally tracking theType{T}
for the constant typeT
, thus saving the lookup on widenconst.Now, not every
Const
actually passes through widenconst, which would cause a performance regression, but it turns out that mostConstType
s originate from global references. Thus, we can take advantage of the recently added binding type field to cache theType{T}
value for bindings and directly feed that into ConstType.As a second enhancement, when we don't already have a Type{T} value, we could make the corresponding
ConstType
field lazily computed on the firstwidenconst
. However, because this would requires makingConstType
mutable, this change is a bit of a wash performance wise. I included it in the anticipation that codegen for mutable types with const fields will improve in the future, but it's optional.