From aba01ad62a94a25086069e5fd64c5bbf40fd6cc6 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sun, 20 Jun 2021 21:33:25 +0200 Subject: [PATCH] add index --- compiler/mono/src/borrow.rs | 19 ++++++++++++++----- compiler/mono/src/inc_dec.rs | 23 ++++++++++++----------- compiler/mono/src/ir.rs | 2 ++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/compiler/mono/src/borrow.rs b/compiler/mono/src/borrow.rs index a69a978671..137db5cf13 100644 --- a/compiler/mono/src/borrow.rs +++ b/compiler/mono/src/borrow.rs @@ -565,6 +565,11 @@ impl<'a> BorrowInfState<'a> { EmptyArray => { self.own_var(z); } + + Call(call) => self.collect_call(z, call), + + Literal(_) | RuntimeErrorFunction(_) => {} + AccessAtIndex { structure: x, .. } => { // if the structure (record/tag/array) is owned, the extracted value is if self.is_owned(*x) { @@ -577,12 +582,16 @@ impl<'a> BorrowInfState<'a> { } } - Call(call) => self.collect_call(z, call), + CoerceToTagId { structure: x, .. } => { + // if the structure (record/tag/array) is owned, the extracted value is + if self.is_owned(*x) { + self.own_var(z); + } - Literal(_) | RuntimeErrorFunction(_) => {} - - CoerceToTagId { .. } => { - // do nothing for now; when we extract the fields here, that must change + // if the extracted value is owned, the structure must be too + if self.is_owned(z) { + self.own_var(*x); + } } GetTagId { structure: x, .. } => { diff --git a/compiler/mono/src/inc_dec.rs b/compiler/mono/src/inc_dec.rs index a0d2f2ed14..f5a15792de 100644 --- a/compiler/mono/src/inc_dec.rs +++ b/compiler/mono/src/inc_dec.rs @@ -743,17 +743,6 @@ impl<'a> Context<'a> { self.arena.alloc(Stmt::Let(z, v, l, b)), &b_live_vars, ), - AccessAtIndex { structure: x, .. } => { - let b = self.add_dec_if_needed(x, b, b_live_vars); - let info_x = self.get_var_info(x); - let b = if info_x.consume { - self.add_inc(z, 1, b) - } else { - b - }; - - self.arena.alloc(Stmt::Let(z, v, l, b)) - } Call(crate::ir::Call { call_type, @@ -766,6 +755,18 @@ impl<'a> Context<'a> { self.arena.alloc(Stmt::Let(z, v, l, b)) } + AccessAtIndex { structure: x, .. } => { + let b = self.add_dec_if_needed(x, b, b_live_vars); + let info_x = self.get_var_info(x); + let b = if info_x.consume { + self.add_inc(z, 1, b) + } else { + b + }; + + self.arena.alloc(Stmt::Let(z, v, l, b)) + } + GetTagId { structure: x, .. } => { let b = self.add_dec_if_needed(x, b, b_live_vars); let info_x = self.get_var_info(x); diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index e0242ab41a..fe0dd551c7 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -1200,6 +1200,8 @@ pub enum Expr<'a> { CoerceToTagId { structure: Symbol, tag_id: u8, + union_layout: UnionLayout<'a>, + index: u64, }, Array {