Skip to content

Validate the type params of an entry once - #3143

Merged
soutaro merged 3 commits into
masterfrom
type-params-validation
Sep 2, 2026
Merged

Validate the type params of an entry once#3143
soutaro merged 3 commits into
masterfrom
type-params-validation

Conversation

@soutaro

@soutaro soutaro commented Sep 2, 2026

Copy link
Copy Markdown
Member

DefinitionBuilder validated the type params of a class or module
every time a definition referring to it was built: the variance
calculation ran over every method type even for types without type
params, and the Environment entries validated their params on every
call.

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 absolutized
the name before raising, so it now raises with the name as written --
Could not find A for extend Bar[A], matching the location the
message 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.

`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>
@soutaro
soutaro added this pull request to the merge queue Sep 2, 2026
Merged via the queue into master with commit 52b9107 Sep 2, 2026
24 checks passed
@soutaro
soutaro deleted the type-params-validation branch September 2, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants