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,
widenconston aConstwhose value is aTypecan be quite slow - slow enough to show up noticeably in profiles. This attempts to address that by splitting theConstlattice element into two:ConstandConstType, the former being used for non-Typevalues and the latter being used forTypes, additionally tracking theType{T}for the constant typeT, thus saving the lookup on widenconst.Now, not every
Constactually passes through widenconst, which would cause a performance regression, but it turns out that mostConstTypes 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
ConstTypefield lazily computed on the firstwidenconst. However, because this would requires makingConstTypemutable, 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.