core: add TypeVarConstraint, and use in irdl_to_attr_constraint #3443
+403
−46
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.
We currently do not preserve type var information in the ParamDef, meaning that each time that we construct a constraint that specialises a TypeVar used in the definition of an attribute, we reconstruct the definition from scratch. Currently, this means re-parsing the type hints used when defining the attribute, but with a dictionary that maps the TypeVar used to the concrete constraint to use for the attribute's parameter. In order to move away from the type-based ParamDef pattern of defining parametrized attributes, we need to somehow store the information of TypeVars used in the attribute definition. This PR proposes a mechanism based on a new kind of attribute constraint, and uses it to split the existing mechanism into two phases: first constructing the constraint with TypeVars, and then swapping out the TypVars in the result. Upcoming PRs will remove the part where we remove the type parsing for each time that a new constraint for a ParametrizedAttribute is constructed.