mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
get rid of Wrapped
This commit is contained in:
parent
205b168f16
commit
f3b23a6a54
6 changed files with 44 additions and 135 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::exhaustive::{Ctor, RenderAs, TagId, Union};
|
||||
use crate::ir::{
|
||||
BranchInfo, DestructType, Env, Expr, JoinPointId, Literal, Param, Pattern, Procs, Stmt, Wrapped,
|
||||
BranchInfo, DestructType, Env, Expr, JoinPointId, Literal, Param, Pattern, Procs, Stmt,
|
||||
};
|
||||
use crate::layout::{Builtin, Layout, LayoutCache, UnionLayout};
|
||||
use roc_collections::all::{MutMap, MutSet};
|
||||
|
@ -1036,52 +1036,51 @@ fn path_to_expr_help<'a>(
|
|||
let mut it = instructions.iter().peekable();
|
||||
|
||||
while let Some(PathInstruction { index, tag_id }) = it.next() {
|
||||
match Wrapped::is_indexable(&layout) {
|
||||
false => {
|
||||
// this MUST be an index into a single-element (hence unwrapped) record
|
||||
let index = *index;
|
||||
|
||||
debug_assert_eq!(*index, 0, "{:?}", &layout);
|
||||
debug_assert_eq!(*tag_id, 0);
|
||||
debug_assert!(it.peek().is_none());
|
||||
|
||||
break;
|
||||
}
|
||||
true => {
|
||||
let index = *index;
|
||||
|
||||
let (inner_layout, inner_expr) = match layout {
|
||||
Layout::Union(union_layout) => {
|
||||
let expr = Expr::CoerceToTagId {
|
||||
tag_id: *tag_id,
|
||||
structure: symbol,
|
||||
index,
|
||||
union_layout,
|
||||
};
|
||||
|
||||
(union_layout.layout_at(*tag_id as u8, index as usize), expr)
|
||||
}
|
||||
Layout::Struct(field_layouts) => {
|
||||
debug_assert!(field_layouts.len() > 1);
|
||||
|
||||
let expr = Expr::StructAtIndex {
|
||||
index,
|
||||
field_layouts,
|
||||
structure: symbol,
|
||||
wrapped: Wrapped::RecordOrSingleTagUnion,
|
||||
};
|
||||
|
||||
let layout = field_layouts[index as usize];
|
||||
|
||||
(layout, expr)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
match &layout {
|
||||
Layout::Union(union_layout) => {
|
||||
let inner_expr = Expr::CoerceToTagId {
|
||||
tag_id: *tag_id,
|
||||
structure: symbol,
|
||||
index,
|
||||
union_layout: *union_layout,
|
||||
};
|
||||
|
||||
let inner_layout = union_layout.layout_at(*tag_id as u8, index as usize);
|
||||
|
||||
symbol = env.unique_symbol();
|
||||
stores.push((symbol, inner_layout, inner_expr));
|
||||
|
||||
layout = inner_layout;
|
||||
}
|
||||
|
||||
Layout::Struct(field_layouts) => {
|
||||
debug_assert!(field_layouts.len() > 1);
|
||||
|
||||
let inner_expr = Expr::StructAtIndex {
|
||||
index,
|
||||
field_layouts,
|
||||
structure: symbol,
|
||||
};
|
||||
|
||||
let inner_layout = field_layouts[index as usize];
|
||||
|
||||
symbol = env.unique_symbol();
|
||||
stores.push((symbol, inner_layout, inner_expr));
|
||||
|
||||
layout = inner_layout;
|
||||
}
|
||||
|
||||
_ => {
|
||||
// this MUST be an index into a single-element (hence unwrapped) record
|
||||
|
||||
debug_assert_eq!(index, 0, "{:?}", &layout);
|
||||
debug_assert_eq!(*tag_id, 0);
|
||||
debug_assert!(it.peek().is_none());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue