Solve
Type resolution for type inference.
This module contains the type resolution algorithm for type inference. A simple algorithm is used to resolve the types of the IR by comparing the input types with the output types.
ResolutionError dataclass
ResolutionError(
expr: types.TypeAttribute, value: types.TypeAttribute
)
ResolutionOk dataclass
ResolutionOk()
TypeResolution dataclass
TypeResolution(
vars: dict[types.TypeVar, types.TypeAttribute] = dict()
)
Type resolution algorithm for type inference.
solve
solve(
annot: types.TypeAttribute, value: types.TypeAttribute
) -> TypeResolutionResult
Solve the type resolution problem.
This method compares the expected type annot
with the actual type value
and returns a result indicating whether the types match or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annot | TypeAttribute | The expected type. | required |
value | TypeAttribute | The actual type. | required |
Returns:
Type | Description |
---|---|
TypeResolutionResult | A |
TypeResolutionResult | resolution. |
Source code in src/kirin/analysis/typeinfer/solve.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
substitute
substitute(typ: types.TypeAttribute) -> types.TypeAttribute
Substitute type variables in the type with their values.
This method substitutes type variables in the given type with their values. If the type is a generic type, the method recursively substitutes the type variables in the type arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
typ | TypeAttribute | The type to substitute. | required |
Returns:
Type | Description |
---|---|
TypeAttribute | The type with the type variables substituted. |
Source code in src/kirin/analysis/typeinfer/solve.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
TypeResolutionResult dataclass
TypeResolutionResult()
Base class for type resolution results.