special-case rose tree field access

This commit is contained in:
Folkert 2021-06-16 23:16:14 +02:00
parent a1231058da
commit 11ed2cbcf8
5 changed files with 14 additions and 3 deletions

View File

@ -1438,6 +1438,12 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
structure,
wrapped: Wrapped::RecordOrSingleTagUnion,
..
}
| AccessAtIndex {
index,
structure,
wrapped: Wrapped::LikeARoseTree,
..
} => {
// extract field from a record
match load_symbol_and_layout(scope, structure) {

View File

@ -880,6 +880,10 @@ fn expr_spec(
Wrapped::RecordOrSingleTagUnion => {
builder.add_get_tuple_field(block, value_id, *index as u32)
}
Wrapped::LikeARoseTree => {
let result_type = layout_spec(builder, layout)?;
builder.add_unknown_with(block, &[value_id], result_type)
}
Wrapped::MultiTagUnion => {
// Clearly this is not generally correct, but it should be for our examples
let hacky_is_recursive =

View File

@ -597,7 +597,7 @@ fn to_relevant_branch_help<'a>(
start.extend(end);
}
}
Wrapped::RecordOrSingleTagUnion => {
Wrapped::RecordOrSingleTagUnion | Wrapped::LikeARoseTree => {
let sub_positions = arguments.into_iter().enumerate().map(
|(index, (pattern, _))| {
let mut new_path = path.to_vec();

View File

@ -1014,6 +1014,8 @@ pub enum Wrapped {
EmptyRecord,
SingleElementRecord,
RecordOrSingleTagUnion,
/// Like a rose tree; recursive, but only one tag
LikeARoseTree,
MultiTagUnion,
}
@ -1046,7 +1048,7 @@ impl Wrapped {
},
_ => Some(Wrapped::MultiTagUnion),
},
NonNullableUnwrapped(_) => Some(Wrapped::RecordOrSingleTagUnion),
NonNullableUnwrapped(_) => Some(Wrapped::LikeARoseTree),
NullableWrapped { .. } | NullableUnwrapped { .. } => {
Some(Wrapped::MultiTagUnion)

View File

@ -1997,7 +1997,6 @@ fn case_or_pattern() {
}
#[test]
#[ignore]
fn rosetree_basic() {
assert_non_opt_evals_to!(
indoc!(