Add Expr::ErasedLoad

This commit is contained in:
Ayaz Hafiz 2023-07-02 11:48:21 -05:00
parent 2c838aa5c2
commit 283b9d53d6
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
11 changed files with 92 additions and 17 deletions

View file

@ -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 {