mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Add Expr::ErasedLoad
This commit is contained in:
parent
2c838aa5c2
commit
283b9d53d6
11 changed files with 92 additions and 17 deletions
|
@ -1841,6 +1841,12 @@ pub struct ReuseToken {
|
|||
pub update_mode: UpdateModeId,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum ErasedField {
|
||||
Value,
|
||||
Callee,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Expr<'a> {
|
||||
Literal(Literal<'a>),
|
||||
|
@ -1904,6 +1910,14 @@ pub enum Expr<'a> {
|
|||
callee: Symbol,
|
||||
},
|
||||
|
||||
/// Loads a field from a type-erased value.
|
||||
ErasedLoad {
|
||||
/// The erased symbol.
|
||||
symbol: Symbol,
|
||||
/// The field to load.
|
||||
field: ErasedField,
|
||||
},
|
||||
|
||||
/// Returns a pointer to the given function.
|
||||
FunctionPointer {
|
||||
lambda_name: LambdaName<'a>,
|
||||
|
@ -2112,6 +2126,19 @@ impl<'a> Expr<'a> {
|
|||
.append(" }")
|
||||
}
|
||||
|
||||
ErasedLoad { symbol, field } => {
|
||||
let field = match field {
|
||||
ErasedField::Value => ".Value",
|
||||
ErasedField::Callee => ".Callee",
|
||||
};
|
||||
|
||||
alloc
|
||||
.text("ErasedLoad ")
|
||||
.append(symbol_to_doc(alloc, *symbol, pretty))
|
||||
.append(alloc.text(" "))
|
||||
.append(field)
|
||||
}
|
||||
|
||||
FunctionPointer { lambda_name } => alloc
|
||||
.text("FunctionPointer ")
|
||||
.append(symbol_to_doc(alloc, lambda_name.name(), pretty)),
|
||||
|
@ -7837,6 +7864,11 @@ fn substitute_in_expr<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
ErasedLoad { symbol, field } => substitute(subs, *symbol).map(|new_symbol| ErasedLoad {
|
||||
symbol: new_symbol,
|
||||
field: *field,
|
||||
}),
|
||||
|
||||
FunctionPointer { .. } => None,
|
||||
|
||||
StructAtIndex {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue