Validate the type params of an entry once - #3143
Merged
Merged
Conversation
`DefinitionBuilder#validate_type_params` ran the variance calculator over every ancestor and every method type of every type being built, but without type params nothing can violate the variance: the ancestor validation iterates the (empty) params of the type, and the type params of the methods themselves are invariant, which `Result#compatible?` always accepts. Return early in that case. Most types have no type params, so this skips the whole calculation for most of the environment -- the validation was 12% of a whole-environment warmup of a large Rails application. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
`DefinitionBuilder#validate_type_name` absolutized the name before raising, while the variance calculation reported undefined names in method types as they are written. Skipping the variance calculation for types without type params moved their detection to `validate_type_name`, turning messages like `Could not find voida` into `Could not find ::voida`. Raise with the as-written name instead, which also matches the location the message points at -- `Could not find A` for `extend Bar[A]`, where `::A` was reported before. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
`ClassEntry#type_params` and `ModuleEntry#type_params` validated the consistency of the type params across the declarations on every call, renaming and comparing the param lists each time, and the definition builder reads `type_params` of the same entries over and over while resolving ancestors. Record a successful validation and skip it until `<<` adds another declaration; a failed validation is not recorded and raises again. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
DefinitionBuildervalidated the type params of a class or moduleevery time a definition referring to it was built: the variance
calculation ran over every method type even for types without type
params, and the
Environmententries validated their params on everycall.
The variance calculation is skipped for types without type params, and
an entry remembers that its params have been validated until a
declaration is added to it. Detecting an undefined type name then moved
from the variance calculation to
validate_type_name, which absolutizedthe name before raising, so it now raises with the name as written --
Could not find Aforextend Bar[A], matching the location themessage points at.
Building the definitions of all 1,806 types of Steep's environment goes
from 2.5s to 1.7s, and loading the signatures from 3.0s to 1.9s.