add alloca as an expression

This commit is contained in:
Folkert 2023-07-29 20:10:52 +02:00
parent 750234f2de
commit cdd2aab217
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
15 changed files with 171 additions and 14 deletions

View file

@ -30,6 +30,7 @@ pub enum UseKind {
ErasedMake(ErasedField),
Erased,
FunctionPointer,
Alloca,
}
pub enum ProblemKind<'a> {
@ -524,6 +525,17 @@ impl<'a, 'r> Ctx<'a, 'r> {
self.check_sym_exists(symbol);
None
}
Expr::Alloca {
initializer,
element_layout,
} => {
if let Some(initializer) = initializer {
self.check_sym_exists(*initializer);
self.check_sym_layout(*initializer, *element_layout, UseKind::Alloca);
}
None
}
Expr::RuntimeErrorFunction(_) => None,
}
}

View file

@ -513,6 +513,7 @@ fn format_use_kind(use_kind: UseKind) -> &'static str {
},
UseKind::Erased => "erasure",
UseKind::FunctionPointer => "function pointer",
UseKind::Alloca => "alloca initializer",
}
}

View file

@ -247,6 +247,7 @@ fn specialize_drops_stmt<'a, 'i>(
RuntimeErrorFunction(_)
| FunctionPointer { .. }
| GetTagId { .. }
| Alloca { .. }
| EmptyArray
| NullPointer => { /* do nothing */ }
}
@ -1620,6 +1621,8 @@ fn low_level_no_rc(lowlevel: &LowLevel) -> RC {
| RefCountDecDataPtr | RefCountIsUnique => {
unreachable!("Only inserted *after* borrow checking: {:?}", lowlevel);
}
SetJmp | LongJmp | SetLongJmpBuffer => unreachable!("only inserted in dev backend codegen"),
}
}

View file

@ -1138,6 +1138,9 @@ fn insert_refcount_operations_binding<'a>(
Expr::Reset { .. } | Expr::ResetRef { .. } => {
unreachable!("Reset(ref) should not exist at this point")
}
Expr::Alloca { .. } => {
unreachable!("Alloca should not exist at this point")
}
}
}
@ -1366,6 +1369,10 @@ fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[Ownership] {
PtrCast => arena.alloc_slice_copy(&[owned]),
Alloca => arena.alloc_slice_copy(&[owned]),
SetJmp | LongJmp | SetLongJmpBuffer => {
unreachable!("only inserted in dev backend codegen")
}
PtrClearTagId | RefCountIncRcPtr | RefCountDecRcPtr | RefCountIncDataPtr
| RefCountDecDataPtr | RefCountIsUnique => {
unreachable!("Only inserted *after* borrow checking: {:?}", op);

View file

@ -329,7 +329,7 @@ pub enum HostExposedLayouts<'a> {
},
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SelfRecursive {
NotSelfRecursive,
SelfRecursive(JoinPointId),
@ -1924,6 +1924,11 @@ pub enum Expr<'a> {
lambda_name: LambdaName<'a>,
},
Alloca {
element_layout: InLayout<'a>,
initializer: Option<Symbol>,
},
Reset {
symbol: Symbol,
update_mode: UpdateModeId,
@ -2142,7 +2147,7 @@ impl<'a> Expr<'a> {
structure,
index,
..
} => text!(alloc, "UnionAtIndex (Id {}) (Index {}) ", tag_id, index)
} => text!(alloc, "UnionAtIndex (Id {tag_id}) (Index {index}) ")
.append(symbol_to_doc(alloc, *structure, pretty)),
UnionFieldPtrAtIndex {
@ -2150,13 +2155,15 @@ impl<'a> Expr<'a> {
structure,
index,
..
} => text!(
alloc,
"UnionFieldPtrAtIndex (Id {}) (Index {}) ",
tag_id,
index
)
.append(symbol_to_doc(alloc, *structure, pretty)),
} => text!(alloc, "UnionFieldPtrAtIndex (Id {tag_id}) (Index {index}) ",)
.append(symbol_to_doc(alloc, *structure, pretty)),
Alloca { initializer, .. } => match initializer {
Some(initializer) => {
text!(alloc, "Alloca ").append(symbol_to_doc(alloc, *initializer, pretty))
}
None => text!(alloc, "Alloca <uninitialized>"),
},
}
}
@ -7935,6 +7942,17 @@ fn substitute_in_expr<'a>(
}),
None => None,
},
Alloca {
element_layout,
initializer,
} => match substitute(subs, (*initializer)?) {
Some(initializer) => Some(Alloca {
element_layout: *element_layout,
initializer: Some(initializer),
}),
None => None,
},
}
}

View file

@ -1109,6 +1109,7 @@ fn expr_contains_symbol(expr: &Expr, needle: Symbol) -> bool {
value.map(|v| v == needle).unwrap_or(false) || needle == *callee
}
Expr::ErasedLoad { symbol, field: _ } => needle == *symbol,
Expr::Alloca { initializer, .. } => &Some(needle) == initializer,
}
}