mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
add alloca as an expression
This commit is contained in:
parent
750234f2de
commit
cdd2aab217
15 changed files with 171 additions and 14 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -513,6 +513,7 @@ fn format_use_kind(use_kind: UseKind) -> &'static str {
|
|||
},
|
||||
UseKind::Erased => "erasure",
|
||||
UseKind::FunctionPointer => "function pointer",
|
||||
UseKind::Alloca => "alloca initializer",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue