add NullPointer to mono::ir::Expr

This commit is contained in:
Folkert 2023-03-30 19:57:16 +02:00
parent 63cdd00d13
commit 09779f65ad
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
9 changed files with 28 additions and 3 deletions

View file

@ -1289,6 +1289,11 @@ fn expr_spec<'a>(
match expr {
Literal(literal) => literal_spec(builder, block, literal),
NullPointer => {
let pointer_type = layout_spec(env, builder, interner, layout)?;
builder.add_unknown_with(block, &[], pointer_type)
}
Call(call) => call_spec(builder, interner, env, block, layout, call),
Reuse {
tag_layout,

View file

@ -1501,6 +1501,7 @@ trait Backend<'a> {
self.set_last_seen(*sym, stmt);
match expr {
Expr::Literal(_) => {}
Expr::NullPointer => {}
Expr::Call(call) => self.scan_ast_call(call, stmt),

View file

@ -1082,6 +1082,12 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
match expr {
Literal(literal) => build_exp_literal(env, layout_interner, parent, layout, literal),
NullPointer => {
let basic_type = basic_type_from_layout(env, layout_interner, layout);
debug_assert!(basic_type.is_pointer_type());
basic_type.into_pointer_type().const_zero().into()
}
Call(call) => build_exp_call(
env,

View file

@ -1041,6 +1041,8 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
match expr {
Expr::Literal(lit) => self.expr_literal(lit, storage),
Expr::NullPointer => self.expr_null_pointer(),
Expr::Call(roc_mono::ir::Call {
call_type,
arguments,
@ -1232,6 +1234,10 @@ impl<'a, 'r> WasmBackend<'a, 'r> {
elements_addr
}
fn expr_null_pointer(&mut self) {
self.code_builder.i32_const(0);
}
/*******************************************************************
* Call expressions
*******************************************************************/

View file

@ -761,7 +761,7 @@ impl<'a> BorrowInfState<'a> {
Call(call) => self.collect_call(interner, param_map, z, call),
Literal(_) | RuntimeErrorFunction(_) => {}
Literal(_) | NullPointer | RuntimeErrorFunction(_) => {}
StructAtIndex { structure: x, .. } => {
// if the structure (record/tag/array) is owned, the extracted value is

View file

@ -390,6 +390,7 @@ impl<'a, 'r> Ctx<'a, 'r> {
fn check_expr(&mut self, e: &Expr<'a>) -> Option<InLayout<'a>> {
match e {
Expr::Literal(_) => None,
Expr::NullPointer => None,
Expr::Call(call) => self.check_call(call),
&Expr::Tag {
tag_layout,

View file

@ -213,7 +213,7 @@ pub fn occurring_variables_expr(expr: &Expr<'_>, result: &mut MutSet<Symbol>) {
result.insert(*symbol);
}
EmptyArray | RuntimeErrorFunction(_) | Literal(_) => {}
EmptyArray | RuntimeErrorFunction(_) | Literal(_) | NullPointer => {}
GetTagId {
structure: symbol, ..
@ -946,7 +946,7 @@ impl<'a, 'i> Context<'a, 'i> {
self.arena.alloc(Stmt::Let(z, v, l, b))
}
EmptyArray | Literal(_) | Reset { .. } | RuntimeErrorFunction(_) => {
EmptyArray | Literal(_) | Reset { .. } | NullPointer | RuntimeErrorFunction(_) => {
// EmptyArray is always stack-allocated function pointers are persistent
self.arena.alloc(Stmt::Let(z, v, l, b))
}

View file

@ -1878,6 +1878,7 @@ pub enum Expr<'a> {
arguments: &'a [Symbol],
},
Struct(&'a [Symbol]),
NullPointer,
StructAtIndex {
index: u64,
@ -2016,6 +2017,7 @@ impl<'a> Expr<'a> {
.append(alloc.space())
.append(alloc.intersperse(it, " "))
}
NullPointer => alloc.text("NullPointer"),
Reuse {
symbol,
tag_id,
@ -7462,6 +7464,8 @@ fn substitute_in_expr<'a>(
}
}
NullPointer => None,
Reuse { .. } | Reset { .. } => unreachable!("reset/reuse have not been introduced yet"),
Struct(args) => {

View file

@ -319,6 +319,7 @@ fn insert_reset<'a>(
}
Literal(_)
| NullPointer
| Call(_)
| Tag { .. }
| Struct(_)
@ -839,6 +840,7 @@ fn has_live_var<'a>(jp_live_vars: &JPLiveVarMap, stmt: &'a Stmt<'a>, needle: Sym
fn has_live_var_expr<'a>(expr: &'a Expr<'a>, needle: Symbol) -> bool {
match expr {
Expr::Literal(_) => false,
Expr::NullPointer => false,
Expr::Call(call) => has_live_var_call(call, needle),
Expr::Array { elems: fields, .. } => {
for element in fields.iter() {