Struct cairo_lang_semantic::expr::inference::Inference
source · pub struct Inference<'db> {
pub data: &'db mut InferenceData,
/* private fields */
}
Expand description
State of inference. A system of inference constraints.
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 impl_assignment(&self, var_id: LocalImplVarId) -> Option<ImplId>
pub fn impl_assignment(&self, var_id: LocalImplVarId) -> Option<ImplId>
Getter for an impl var assignment.
sourcepub fn new_type_var(&mut self, stable_ptr: Option<SyntaxStablePtrId>) -> TypeId
pub fn new_type_var(&mut self, stable_ptr: Option<SyntaxStablePtrId>) -> TypeId
Allocates a new TypeVar for an unknown type that needs to be inferred. Returns a wrapping TypeId.
sourcepub fn new_type_var_raw(
&mut self,
stable_ptr: Option<SyntaxStablePtrId>
) -> TypeVar
pub fn new_type_var_raw( &mut self, stable_ptr: Option<SyntaxStablePtrId> ) -> TypeVar
Allocates a new TypeVar for an unknown type that needs to be inferred. Returns the variable id.
sourcepub fn new_impl_var(
&mut self,
concrete_trait_id: ConcreteTraitId,
stable_ptr: Option<SyntaxStablePtrId>,
lookup_context: ImplLookupContext
) -> InferenceResult<ImplId>
pub fn new_impl_var( &mut self, concrete_trait_id: ConcreteTraitId, stable_ptr: Option<SyntaxStablePtrId>, lookup_context: ImplLookupContext ) -> InferenceResult<ImplId>
Allocates a new ImplVar for an unknown type that needs to be inferred. Returns a wrapping ImplId.
sourcepub fn solve(&mut self) -> InferenceResult<()>
pub fn solve(&mut self) -> InferenceResult<()>
Solves the inference system. After a successful solve, there are no more pending impl inferences.
sourcepub fn solution_set(&mut self) -> InferenceResult<SolutionSet<()>>
pub fn solution_set(&mut self) -> InferenceResult<SolutionSet<()>>
Returns the solution set status for the inference: Whether there is a unique solution, multiple solutions, no solutions or an error.
sourcepub fn finalize(
&mut self
) -> Option<(Option<SyntaxStablePtrId>, InferenceError)>
pub fn finalize( &mut self ) -> Option<(Option<SyntaxStablePtrId>, InferenceError)>
Finalizes an inference by inferring uninferred numeric literals as felt252.
sourcepub fn first_undetermined_variable(
&mut self
) -> Option<(InferenceVar, InferenceError)>
pub fn first_undetermined_variable( &mut self ) -> Option<(InferenceVar, InferenceError)>
Retrieves the first variable that is still not inferred, or None, if everything is inferred.
sourcepub fn trait_solution_set(
&mut self,
concrete_trait_id: ConcreteTraitId,
lookup_context: ImplLookupContext
) -> InferenceResult<SolutionSet<(CanonicalImpl, CanonicalMapping)>>
pub fn trait_solution_set( &mut self, concrete_trait_id: ConcreteTraitId, lookup_context: ImplLookupContext ) -> InferenceResult<SolutionSet<(CanonicalImpl, CanonicalMapping)>>
Computes the solution set for an trait with a recursive query.
Methods from Deref<Target = InferenceData>§
pub fn inference<'db, 'b: 'db>( &'db mut self, db: &'b dyn SemanticGroup ) -> Inference<'db>
Trait Implementations§
source§impl<'a> HasDb<&'a dyn SemanticGroup> for Inference<'a>
impl<'a> HasDb<&'a dyn SemanticGroup> for Inference<'a>
fn get_db(&self) -> &'a dyn SemanticGroup
source§impl<'db> InferenceConform for Inference<'db>
impl<'db> InferenceConform for Inference<'db>
source§fn conform_ty(
&mut self,
ty0: TypeId,
ty1: TypeId
) -> Result<TypeId, InferenceError>
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.
source§fn conform_ty_ex(
&mut self,
ty0: TypeId,
ty1: TypeId,
ty0_is_self: bool
) -> Result<(TypeId, usize), InferenceError>
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.
source§fn conform_generic_args(
&mut self,
gargs0: &[GenericArgumentId],
gargs1: &[GenericArgumentId]
) -> Result<Vec<GenericArgumentId>, InferenceError>
fn conform_generic_args( &mut self, gargs0: &[GenericArgumentId], gargs1: &[GenericArgumentId] ) -> Result<Vec<GenericArgumentId>, InferenceError>
Conforms generics args. See conform_ty()
.
source§fn conform_generic_arg(
&mut self,
garg0: GenericArgumentId,
garg1: GenericArgumentId
) -> Result<GenericArgumentId, InferenceError>
fn conform_generic_arg( &mut self, garg0: GenericArgumentId, garg1: GenericArgumentId ) -> Result<GenericArgumentId, InferenceError>
Conforms a generics arg. See conform_ty()
.
source§fn conform_impl(
&mut self,
impl0: ImplId,
impl1: ImplId
) -> InferenceResult<ImplId>
fn conform_impl( &mut self, impl0: ImplId, impl1: ImplId ) -> InferenceResult<ImplId>
Conforms an impl. See conform_ty()
.
source§fn conform_traits(
&mut self,
trt0: ConcreteTraitId,
trt1: ConcreteTraitId
) -> Result<ConcreteTraitId, InferenceError>
fn conform_traits( &mut self, trt0: ConcreteTraitId, trt1: ConcreteTraitId ) -> Result<ConcreteTraitId, InferenceError>
Conforms generics traits. See conform_ty()
.
source§fn ty_contains_var(
&mut self,
ty: TypeId,
var: InferenceVar
) -> InferenceResult<bool>
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.
source§fn generic_args_contain_var(
&mut self,
generic_args: &[GenericArgumentId],
var: InferenceVar
) -> InferenceResult<bool>
fn generic_args_contain_var( &mut self, generic_args: &[GenericArgumentId], var: InferenceVar ) -> InferenceResult<bool>
Checks if a slice of generics arguments contain a certain InferenceVar somewhere. Used to avoid inference cycles.
source§fn impl_contains_var(
&mut self,
impl_id: &ImplId,
var: InferenceVar
) -> Result<bool, InferenceError>
fn impl_contains_var( &mut self, impl_id: &ImplId, var: InferenceVar ) -> Result<bool, InferenceError>
Checks if an impl contains a certain InferenceVar somewhere. Used to avoid inference cycles.
fn maybe_peel_snapshots( &mut self, ty0_is_self: bool, ty1: TypeId ) -> (usize, TypeLongId)
source§impl<'db> InferenceEmbeddings for Inference<'db>
impl<'db> InferenceEmbeddings for Inference<'db>
source§fn infer_impl(
&mut self,
uninferred_impl: UninferredImpl,
concrete_trait_id: ConcreteTraitId,
lookup_context: &ImplLookupContext,
stable_ptr: Option<SyntaxStablePtrId>
) -> InferenceResult<ImplId>
fn infer_impl( &mut self, uninferred_impl: UninferredImpl, concrete_trait_id: ConcreteTraitId, lookup_context: &ImplLookupContext, stable_ptr: Option<SyntaxStablePtrId> ) -> InferenceResult<ImplId>
Infers all the variables required to make an uninferred impl provide a concrete trait.
source§fn infer_impl_def(
&mut self,
impl_def_id: ImplDefId,
concrete_trait_id: ConcreteTraitId,
lookup_context: &ImplLookupContext,
stable_ptr: Option<SyntaxStablePtrId>
) -> InferenceResult<ImplId>
fn infer_impl_def( &mut self, impl_def_id: ImplDefId, concrete_trait_id: ConcreteTraitId, lookup_context: &ImplLookupContext, stable_ptr: Option<SyntaxStablePtrId> ) -> InferenceResult<ImplId>
Infers all the variables required to make an impl (possibly with free generic params) provide a concrete trait.
source§fn infer_impl_alias(
&mut self,
impl_alias_id: ImplAliasId,
concrete_trait_id: ConcreteTraitId,
lookup_context: &ImplLookupContext,
stable_ptr: Option<SyntaxStablePtrId>
) -> InferenceResult<ImplId>
fn infer_impl_alias( &mut self, impl_alias_id: ImplAliasId, concrete_trait_id: ConcreteTraitId, lookup_context: &ImplLookupContext, stable_ptr: Option<SyntaxStablePtrId> ) -> InferenceResult<ImplId>
Infers all the variables required to make an impl alias (possibly with free generic params) provide a concrete trait.
source§fn infer_generic_assignment(
&mut self,
generic_params: &[GenericParam],
generic_args: &[GenericArgumentId],
expected_generic_args: &[GenericArgumentId],
lookup_context: &ImplLookupContext,
stable_ptr: Option<SyntaxStablePtrId>
) -> InferenceResult<Vec<GenericArgumentId>>
fn infer_generic_assignment( &mut self, generic_params: &[GenericParam], generic_args: &[GenericArgumentId], expected_generic_args: &[GenericArgumentId], lookup_context: &ImplLookupContext, stable_ptr: Option<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.
source§fn infer_generic_args(
&mut self,
generic_params: &[GenericParam],
lookup_context: &ImplLookupContext,
stable_ptr: Option<SyntaxStablePtrId>
) -> InferenceResult<Vec<GenericArgumentId>>
fn infer_generic_args( &mut self, generic_params: &[GenericParam], lookup_context: &ImplLookupContext, stable_ptr: Option<SyntaxStablePtrId> ) -> InferenceResult<Vec<GenericArgumentId>>
Infers all generic_arguments given the parameters.
source§fn infer_concrete_trait_by_self(
&mut self,
trait_function: TraitFunctionId,
self_ty: TypeId,
lookup_context: &ImplLookupContext,
stable_ptr: Option<SyntaxStablePtrId>
) -> Option<(ConcreteTraitId, usize)>
fn infer_concrete_trait_by_self( &mut self, trait_function: TraitFunctionId, self_ty: TypeId, lookup_context: &ImplLookupContext, stable_ptr: Option<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.
source§fn infer_generic_arg(
&mut self,
param: &GenericParam,
lookup_context: ImplLookupContext,
stable_ptr: Option<SyntaxStablePtrId>
) -> InferenceResult<GenericArgumentId>
fn infer_generic_arg( &mut self, param: &GenericParam, lookup_context: ImplLookupContext, stable_ptr: Option<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.
source§fn infer_trait_function(
&mut self,
concrete_trait_function: ConcreteTraitGenericFunctionId,
lookup_context: &ImplLookupContext,
stable_ptr: Option<SyntaxStablePtrId>
) -> InferenceResult<FunctionId>
fn infer_trait_function( &mut self, concrete_trait_function: ConcreteTraitGenericFunctionId, lookup_context: &ImplLookupContext, stable_ptr: Option<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.
source§fn infer_generic_function(
&mut self,
generic_function: GenericFunctionId,
lookup_context: &ImplLookupContext,
stable_ptr: Option<SyntaxStablePtrId>
) -> InferenceResult<FunctionId>
fn infer_generic_function( &mut self, generic_function: GenericFunctionId, lookup_context: &ImplLookupContext, stable_ptr: Option<SyntaxStablePtrId> ) -> InferenceResult<FunctionId>
Infers generic arguments to be passed to a generic function. Returns the resulting specialized function.
source§fn infer_trait_generic_function(
&mut self,
trait_function: ConcreteTraitGenericFunctionId,
lookup_context: &ImplLookupContext,
stable_ptr: Option<SyntaxStablePtrId>
) -> InferenceResult<GenericFunctionId>
fn infer_trait_generic_function( &mut self, trait_function: ConcreteTraitGenericFunctionId, lookup_context: &ImplLookupContext, stable_ptr: Option<SyntaxStablePtrId> ) -> InferenceResult<GenericFunctionId>
Infers the impl to be substituted instead of a trait for a given trait function. Returns the resulting impl generic function.