Struct cairo_lang_semantic::expr::inference::Inference
source · pub struct Inference<'db> {
pub enabled: bool,
/* private fields */
}
Expand description
State of inference.
Fields§
§enabled: bool
Whether inference is enabled.
Implementations§
source§impl<'db> Inference<'db>
impl<'db> Inference<'db>
sourcepub fn new(db: &'db dyn SemanticGroup) -> Self
pub fn new(db: &'db dyn SemanticGroup) -> Self
Creates a new Inference instance.
sourcepub fn disabled(db: &'db dyn SemanticGroup) -> Self
pub fn disabled(db: &'db dyn SemanticGroup) -> Self
Creates a disabled Inference instance, where no inference is being performed.
sourcepub fn new_var(&mut self, stable_ptr: SyntaxStablePtrId) -> TypeId
pub fn new_var(&mut self, stable_ptr: SyntaxStablePtrId) -> TypeId
Allocated a new TypeVar for an unknown type that needs to be inferred,
sourcepub fn first_undetermined_variable(&self) -> Option<SyntaxStablePtrId>
pub fn first_undetermined_variable(&self) -> Option<SyntaxStablePtrId>
Retrieves the first variable that is still not inferred, or None, if everything is inferred.
sourcepub fn reduce_ty(&mut self, ty: TypeId) -> TypeId
pub fn reduce_ty(&mut self, ty: TypeId) -> TypeId
Gets current canonical representation for a TypeId after all known substitutions.
sourcepub fn reduce_concrete_variant(&mut self, concrete_variant: &mut ConcreteVariant)
pub fn reduce_concrete_variant(&mut self, concrete_variant: &mut ConcreteVariant)
Gets current canonical representation for a ConcreteVariant after all known substitutions.
sourcepub fn reduce_concrete_enum(
&mut self,
concrete_enum_id: ConcreteEnumId
) -> ConcreteEnumId
pub fn reduce_concrete_enum(
&mut self,
concrete_enum_id: ConcreteEnumId
) -> ConcreteEnumId
Gets current canonical representation for a ConcreteEnumId after all known substitutions.
sourcepub fn reduce_var(&mut self, var: TypeVar) -> TypeId
pub fn reduce_var(&mut self, var: TypeVar) -> TypeId
Gets current canonical representation for a TypeVar after all known substitutions.
sourcepub fn reduce_generic_args(
&mut self,
generic_args: &[GenericArgumentId]
) -> Vec<GenericArgumentId> ⓘ
pub fn reduce_generic_args(
&mut self,
generic_args: &[GenericArgumentId]
) -> Vec<GenericArgumentId> ⓘ
Gets current canonical representation for a GenericArgumentId vector after all known substitutions.
sourcepub fn reduce_pattern(&mut self, pattern: &mut Pattern)
pub fn reduce_pattern(&mut self, pattern: &mut Pattern)
Gets current canonical representation for a Pattern after all known substitutions, and updates inplace.
sourcepub fn conform_ty(
&mut self,
ty0: TypeId,
ty1: TypeId
) -> Result<TypeId, InferenceError>
pub fn conform_ty(
&mut self,
ty0: TypeId,
ty1: TypeId
) -> Result<TypeId, InferenceError>
Conforms ty0 to ty1. Should be called when ty0 should be coerced to ty1. Not symmetric. Returns the reduced type for ty0, or an error if the type is no coercible.
sourcepub fn conform_generic_arg(
&mut self,
garg0: GenericArgumentId,
garg1: GenericArgumentId
) -> Result<GenericArgumentId, InferenceError>
pub fn conform_generic_arg(
&mut self,
garg0: GenericArgumentId,
garg1: GenericArgumentId
) -> Result<GenericArgumentId, InferenceError>
Conforms a generics arg. See conform_ty()
.
sourcepub fn contains_var(&mut self, ty: TypeId, var: TypeVar) -> bool
pub fn contains_var(&mut self, ty: TypeId, var: TypeVar) -> bool
Checks if the a type tree contains a certain TypeVar somewhere. Used to avoid inference cycles.
sourcepub fn can_infer_generics(
&self,
generic_params: &[GenericParamId],
generic_args: &[GenericArgumentId],
expected_generic_args: &[GenericArgumentId],
stable_ptr: SyntaxStablePtrId
) -> bool
pub fn can_infer_generics(
&self,
generic_params: &[GenericParamId],
generic_args: &[GenericArgumentId],
expected_generic_args: &[GenericArgumentId],
stable_ptr: SyntaxStablePtrId
) -> bool
Determines if an assignment to generic_params
can be chosen s.t. generic_args
will be
substituted to expected_generic_args
.
sourcepub fn infer_generics(
&mut self,
generic_params: &[GenericParamId],
generic_args: &[GenericArgumentId],
expected_generic_args: &[GenericArgumentId],
stable_ptr: SyntaxStablePtrId
) -> Result<Vec<GenericArgumentId>, InferenceError>
pub fn infer_generics(
&mut self,
generic_params: &[GenericParamId],
generic_args: &[GenericArgumentId],
expected_generic_args: &[GenericArgumentId],
stable_ptr: SyntaxStablePtrId
) -> Result<Vec<GenericArgumentId>, InferenceError>
Chooses and assignment to generic_params s.t. generic_args will be substituted to expected_generic_args. Returns the generic_params assignment.
sourcepub fn infer_concrete_trait_by_self(
&mut self,
trait_function: TraitFunctionId,
self_ty: TypeId,
stable_ptr: SyntaxStablePtrId
) -> Option<ConcreteTraitId>
pub fn infer_concrete_trait_by_self(
&mut self,
trait_function: TraitFunctionId,
self_ty: TypeId,
stable_ptr: SyntaxStablePtrId
) -> Option<ConcreteTraitId>
Tries to infer a trait function as a method for self_ty
.