Struct cairo_lang_semantic::expr::inference::Inference
source · pub struct Inference<'db> {
pub data: &'db mut InferenceData,
/* private fields */
}
Expand description
State of inference.
Fields§
§data: &'db mut InferenceData
Implementations§
source§impl<'db> Inference<'db>
impl<'db> Inference<'db>
sourcepub fn with_data(
db: &'db dyn SemanticGroup,
data: &'db mut InferenceData
) -> Self
pub fn with_data( db: &'db dyn SemanticGroup, data: &'db mut InferenceData ) -> Self
Creates a new Inference instance with the given InferenceData.
pub fn clone_data(&self) -> InferenceData
sourcepub fn new_type_var(&mut self, stable_ptr: SyntaxStablePtrId) -> TypeId
pub fn new_type_var(&mut self, stable_ptr: SyntaxStablePtrId) -> TypeId
Allocated a new TypeVar for an unknown type that needs to be inferred,
sourcepub fn new_impl_var(
&mut self,
concrete_trait_id: ConcreteTraitId,
stable_ptr: SyntaxStablePtrId,
lookup_context: ImplLookupContext
) -> InferenceResult<ImplId>
pub fn new_impl_var( &mut self, concrete_trait_id: ConcreteTraitId, stable_ptr: SyntaxStablePtrId, lookup_context: ImplLookupContext ) -> InferenceResult<ImplId>
Allocated a new ImplVar for an unknown type that needs to be inferred,
sourcepub fn get_candidates(&self, var: &ImplVar) -> Option<Vec<UninferredImpl>>
pub fn get_candidates(&self, var: &ImplVar) -> Option<Vec<UninferredImpl>>
Returns the candidates for the given ImplVar.
sourcepub fn finalize(&mut self) -> Option<(SyntaxStablePtrId, InferenceError)>
pub fn finalize(&mut self) -> Option<(SyntaxStablePtrId, InferenceError)>
Relaxes all the constraints until stable. Retrieves the first variable that is still not inferred, or None, if everything is inferred.
sourcepub fn n_variables(&self) -> usize
pub fn n_variables(&self) -> usize
Returns the number of variables allocated for current inference. Useful for deciding if new variables were introduced.
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_ty_ex(
&mut self,
ty0: TypeId,
ty1: TypeId,
ty0_is_self: bool
) -> Result<(TypeId, usize), InferenceError>
pub fn conform_ty_ex( &mut self, ty0: TypeId, ty1: TypeId, ty0_is_self: bool ) -> Result<(TypeId, usize), InferenceError>
Same as conform_ty but supports adding snapshots to ty0 if ty0_is_self
is true.
Returns the reduced type for ty0 and the number of snapshots that needs to be added
for the types to conform.
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 conform_impl(
&mut self,
impl0: ImplId,
impl1: ImplId
) -> InferenceResult<ImplId>
pub fn conform_impl( &mut self, impl0: ImplId, impl1: ImplId ) -> InferenceResult<ImplId>
Conforms an impl. See conform_ty()
.
sourcepub fn conform_traits(
&mut self,
trt0: ConcreteTraitId,
trt1: ConcreteTraitId
) -> Result<ConcreteTraitId, InferenceError>
pub fn conform_traits( &mut self, trt0: ConcreteTraitId, trt1: ConcreteTraitId ) -> Result<ConcreteTraitId, InferenceError>
Conforms generics traits. See conform_ty()
.
sourcepub fn ty_contains_var(
&mut self,
ty: TypeId,
var: InferenceVar
) -> InferenceResult<bool>
pub fn ty_contains_var( &mut self, ty: TypeId, var: InferenceVar ) -> InferenceResult<bool>
Checks if a type tree contains a certain InferenceVar somewhere. Used to avoid inference cycles.
sourcepub fn can_infer_generics(
&self,
generic_params: &[GenericParam],
generic_args: &[GenericArgumentId],
expected_generic_args: &[GenericArgumentId],
lookup_context: &ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> bool
pub fn can_infer_generics( &self, generic_params: &[GenericParam], generic_args: &[GenericArgumentId], expected_generic_args: &[GenericArgumentId], lookup_context: &ImplLookupContext, 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 can_infer_impl(
&self,
uninferred_impl: UninferredImpl,
concrete_trait_id: ConcreteTraitId,
lookup_context: &ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> Maybe<bool>
pub fn can_infer_impl( &self, uninferred_impl: UninferredImpl, concrete_trait_id: ConcreteTraitId, lookup_context: &ImplLookupContext, stable_ptr: SyntaxStablePtrId ) -> Maybe<bool>
Check if it possible to infer an impl to provide a concrete trait. See infer_impl.
sourcepub fn infer_impl_def(
&mut self,
impl_def_id: ImplDefId,
concrete_trait_id: ConcreteTraitId,
lookup_context: &ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> Result<ImplId, InferenceError>
pub fn infer_impl_def( &mut self, impl_def_id: ImplDefId, concrete_trait_id: ConcreteTraitId, lookup_context: &ImplLookupContext, stable_ptr: SyntaxStablePtrId ) -> Result<ImplId, InferenceError>
Infers all the variables required to make an impl (possibly with free generic params) provide a concrete trait.
sourcepub fn infer_impl_alias(
&mut self,
impl_alias_id: ImplAliasId,
concrete_trait_id: ConcreteTraitId,
lookup_context: &ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> Result<ImplId, InferenceError>
pub fn infer_impl_alias( &mut self, impl_alias_id: ImplAliasId, concrete_trait_id: ConcreteTraitId, lookup_context: &ImplLookupContext, stable_ptr: SyntaxStablePtrId ) -> Result<ImplId, InferenceError>
Infers all the variables required to make an impl alias (possibly with free generic params) provide a concrete trait.
sourcepub fn infer_generic_assignment(
&mut self,
generic_params: &[GenericParam],
generic_args: &[GenericArgumentId],
expected_generic_args: &[GenericArgumentId],
lookup_context: &ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> InferenceResult<Vec<GenericArgumentId>>
pub fn infer_generic_assignment( &mut self, generic_params: &[GenericParam], generic_args: &[GenericArgumentId], expected_generic_args: &[GenericArgumentId], lookup_context: &ImplLookupContext, stable_ptr: SyntaxStablePtrId ) -> InferenceResult<Vec<GenericArgumentId>>
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_generic_args(
&mut self,
generic_params: &[GenericParam],
lookup_context: &ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> InferenceResult<Vec<GenericArgumentId>>
pub fn infer_generic_args( &mut self, generic_params: &[GenericParam], lookup_context: &ImplLookupContext, stable_ptr: SyntaxStablePtrId ) -> InferenceResult<Vec<GenericArgumentId>>
Infers all generic_arguments given the parameters.
sourcepub fn infer_concrete_trait_by_self(
&mut self,
trait_function: TraitFunctionId,
self_ty: TypeId,
lookup_context: &ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> Option<(ConcreteTraitId, usize)>
pub fn infer_concrete_trait_by_self( &mut self, trait_function: TraitFunctionId, self_ty: TypeId, lookup_context: &ImplLookupContext, stable_ptr: SyntaxStablePtrId ) -> Option<(ConcreteTraitId, usize)>
Tries to infer a trait function as a method for self_ty
.
Supports snapshot snapshot coercions.
Returns the deduced type and the number of snapshots that need to be added to it.
sourcepub fn infer_generic_arg(
&mut self,
param: &GenericParam,
lookup_context: ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> InferenceResult<GenericArgumentId>
pub fn infer_generic_arg( &mut self, param: &GenericParam, lookup_context: ImplLookupContext, stable_ptr: SyntaxStablePtrId ) -> InferenceResult<GenericArgumentId>
Infers a generic argument to be passed as a generic paramter. Allocates a new inference variable of the correct kind, and wraps in a generic argument.
sourcepub fn infer_trait_function(
&mut self,
concrete_trait_function: ConcreteTraitGenericFunctionId,
lookup_context: &ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> InferenceResult<FunctionId>
pub fn infer_trait_function( &mut self, concrete_trait_function: ConcreteTraitGenericFunctionId, lookup_context: &ImplLookupContext, stable_ptr: SyntaxStablePtrId ) -> InferenceResult<FunctionId>
Infers the impl to be substituted instead of a trait for a given trait function, and the generic arguments to be passed to the function. Returns the resulting impl function.
sourcepub fn infer_generic_function(
&mut self,
generic_function: GenericFunctionId,
lookup_context: &ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> InferenceResult<FunctionId>
pub fn infer_generic_function( &mut self, generic_function: GenericFunctionId, lookup_context: &ImplLookupContext, stable_ptr: SyntaxStablePtrId ) -> InferenceResult<FunctionId>
Infers generic arguments to be passed to a generic function. Returns the resulting specialized function.
sourcepub fn infer_trait_generic_function(
&mut self,
trait_function: ConcreteTraitGenericFunctionId,
lookup_context: &ImplLookupContext,
stable_ptr: SyntaxStablePtrId
) -> InferenceResult<GenericFunctionId>
pub fn infer_trait_generic_function( &mut self, trait_function: ConcreteTraitGenericFunctionId, lookup_context: &ImplLookupContext, stable_ptr: SyntaxStablePtrId ) -> InferenceResult<GenericFunctionId>
Infers the impl to be substituted instead of a trait for a given trait function. Returns the resulting impl generic function.