pub struct MonomorphizationVisitor<'a> {
pub state: &'a mut CompilerState,
pub program: Symbol,
pub function_map: IndexMap<Vec<Symbol>, Function>,
pub struct_map: IndexMap<Vec<Symbol>, Composite>,
pub reconstructed_functions: IndexMap<Vec<Symbol>, Function>,
pub monomorphized_functions: IndexSet<Vec<Symbol>>,
pub reconstructed_structs: IndexMap<Vec<Symbol>, Composite>,
pub monomorphized_structs: IndexSet<Vec<Symbol>>,
pub unresolved_calls: Vec<CallExpression>,
pub unresolved_struct_exprs: Vec<StructExpression>,
pub unresolved_struct_types: Vec<CompositeType>,
pub changed: bool,
}
Fields§
§state: &'a mut CompilerState
§program: Symbol
The main program.
function_map: IndexMap<Vec<Symbol>, Function>
A map to provide faster lookup of functions.
struct_map: IndexMap<Vec<Symbol>, Composite>
A map to provide faster lookup of structs.
reconstructed_functions: IndexMap<Vec<Symbol>, Function>
A map of reconstructed functions in the current program scope.
monomorphized_functions: IndexSet<Vec<Symbol>>
A set of all functions that have been monomorphized at least once. This keeps track of the original names of the functions not the names of the monomorphized versions.
reconstructed_structs: IndexMap<Vec<Symbol>, Composite>
A map of reconstructed functions in the current program scope.
monomorphized_structs: IndexSet<Vec<Symbol>>
A set of all functions that have been monomorphized at least once. This keeps track of the original names of the functions not the names of the monomorphized versions.
unresolved_calls: Vec<CallExpression>
A vector of all the calls to const generic functions that have not been resolved.
unresolved_struct_exprs: Vec<StructExpression>
A vector of all the struct expressions of const generic structs that have not been resolved.
unresolved_struct_types: Vec<CompositeType>
A vector of all the struct type instantiations of const generic structs that have not been resolved.
changed: bool
Have we actually modified the program at all?
Implementations§
Source§impl<'a> MonomorphizationVisitor<'a>
impl<'a> MonomorphizationVisitor<'a>
Sourcefn try_evaluate_const_args(
&mut self,
const_args: &[Expression],
) -> Option<Vec<Expression>>
fn try_evaluate_const_args( &mut self, const_args: &[Expression], ) -> Option<Vec<Expression>>
Evaluates the given constant arguments if possible.
Returns Some
with all evaluated expressions if all are constants, or None
if any argument is not constant.
Source§impl MonomorphizationVisitor<'_>
impl MonomorphizationVisitor<'_>
Sourcepub(crate) fn monomorphize_struct(
&mut self,
path: &Path,
const_arguments: &Vec<Expression>,
) -> Path
pub(crate) fn monomorphize_struct( &mut self, path: &Path, const_arguments: &Vec<Expression>, ) -> Path
Monomorphizes a generic struct by substituting const parameters with concrete arguments and caching result.
Generates a unique name like Foo::[1u32, 2u32]
based on the original name and the provided const arguments.
Replaces all const parameter references in the struct body with values, then resolves nested generics.
Assigns a new name and struct ID, clears const params, and stores the result to avoid reprocessing.
Panics if the original struct is not found in reconstructed_structs
(should already be reconstructed).
§Arguments
name
- Symbol of the original generic struct.const_arguments
- Const values to substitute into the struct.- Returns a
Symbol
for the newly monomorphized struct.
Note: this functions already assumes that all provided const arguments are literals.
Trait Implementations§
Source§impl AstReconstructor for MonomorphizationVisitor<'_>
impl AstReconstructor for MonomorphizationVisitor<'_>
type AdditionalInput = ()
type AdditionalOutput = ()
fn reconstruct_composite_type( &mut self, input: CompositeType, ) -> (Type, Self::AdditionalOutput)
fn reconstruct_expression( &mut self, input: Expression, _additional: &(), ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_call( &mut self, input_call: CallExpression, _additional: &(), ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_struct_init( &mut self, input: StructExpression, _additional: &(), ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_type(&mut self, input: Type) -> (Type, Self::AdditionalOutput)
fn reconstruct_array_type( &mut self, input: ArrayType, ) -> (Type, Self::AdditionalOutput)
fn reconstruct_future_type( &mut self, input: FutureType, ) -> (Type, Self::AdditionalOutput)
fn reconstruct_mapping_type( &mut self, input: MappingType, ) -> (Type, Self::AdditionalOutput)
fn reconstruct_optional_type( &mut self, input: OptionalType, ) -> (Type, Self::AdditionalOutput)
fn reconstruct_tuple_type( &mut self, input: TupleType, ) -> (Type, Self::AdditionalOutput)
fn reconstruct_array_access( &mut self, input: ArrayAccess, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_associated_constant( &mut self, input: AssociatedConstantExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_associated_function( &mut self, input: AssociatedFunctionExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_async( &mut self, input: AsyncExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_member_access( &mut self, input: MemberAccess, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_repeat( &mut self, input: RepeatExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_tuple_access( &mut self, input: TupleAccess, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_array( &mut self, input: ArrayExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_binary( &mut self, input: BinaryExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_cast( &mut self, input: CastExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_err( &mut self, _input: ErrExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_path( &mut self, input: Path, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_literal( &mut self, input: Literal, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_locator( &mut self, input: LocatorExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_ternary( &mut self, input: TernaryExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_tuple( &mut self, input: TupleExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_unary( &mut self, input: UnaryExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_unit( &mut self, input: UnitExpression, _additional: &Self::AdditionalInput, ) -> (Expression, Self::AdditionalOutput)
fn reconstruct_statement( &mut self, input: Statement, ) -> (Statement, Self::AdditionalOutput)
fn reconstruct_assert( &mut self, input: AssertStatement, ) -> (Statement, Self::AdditionalOutput)
fn reconstruct_assign( &mut self, input: AssignStatement, ) -> (Statement, Self::AdditionalOutput)
fn reconstruct_block(&mut self, input: Block) -> (Block, Self::AdditionalOutput)
fn reconstruct_conditional( &mut self, input: ConditionalStatement, ) -> (Statement, Self::AdditionalOutput)
fn reconstruct_const( &mut self, input: ConstDeclaration, ) -> (Statement, Self::AdditionalOutput)
fn reconstruct_definition( &mut self, input: DefinitionStatement, ) -> (Statement, Self::AdditionalOutput)
fn reconstruct_expression_statement( &mut self, input: ExpressionStatement, ) -> (Statement, Self::AdditionalOutput)
fn reconstruct_iteration( &mut self, input: IterationStatement, ) -> (Statement, Self::AdditionalOutput)
fn reconstruct_return( &mut self, input: ReturnStatement, ) -> (Statement, Self::AdditionalOutput)
Source§impl ProgramReconstructor for MonomorphizationVisitor<'_>
impl ProgramReconstructor for MonomorphizationVisitor<'_>
fn reconstruct_program_scope(&mut self, input: ProgramScope) -> ProgramScope
fn reconstruct_program(&mut self, input: Program) -> Program
fn reconstruct_module(&mut self, input: Module) -> Module
fn reconstruct_stub(&mut self, input: Stub) -> Stub
fn reconstruct_function(&mut self, input: Function) -> Function
fn reconstruct_constructor(&mut self, input: Constructor) -> Constructor
fn reconstruct_function_stub(&mut self, input: FunctionStub) -> FunctionStub
fn reconstruct_struct(&mut self, input: Composite) -> Composite
fn reconstruct_import(&mut self, input: Program) -> Program
fn reconstruct_mapping(&mut self, input: Mapping) -> Mapping
Auto Trait Implementations§
impl<'a> Freeze for MonomorphizationVisitor<'a>
impl<'a> !RefUnwindSafe for MonomorphizationVisitor<'a>
impl<'a> !Send for MonomorphizationVisitor<'a>
impl<'a> !Sync for MonomorphizationVisitor<'a>
impl<'a> Unpin for MonomorphizationVisitor<'a>
impl<'a> !UnwindSafe for MonomorphizationVisitor<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more