remove update field from normal Record constructor

This commit is contained in:
Folkert 2021-03-20 16:49:14 +01:00
parent 60265b5d2a
commit e0c211081a
8 changed files with 15 additions and 77 deletions

View File

@ -121,7 +121,6 @@ fn jit_to_ast_help<'a>(
}
Layout::PhantomEmptyStruct => Ok(run_jit_function!(lib, main_fn_name, &u8, |_| {
Expr::Record {
update: None,
fields: &[],
final_comments: env.arena.alloc([]),
}
@ -474,7 +473,6 @@ fn struct_to_ast<'a>(
let output = env.arena.alloc([loc_field]);
Expr::Record {
update: None,
fields: output,
final_comments: &[],
}
@ -510,7 +508,6 @@ fn struct_to_ast<'a>(
let output = output.into_bump_slice();
Expr::Record {
update: None,
fields: output,
final_comments: &[],
}
@ -554,7 +551,6 @@ fn bool_to_ast<'a>(env: &Env<'a, '_>, value: bool, content: &Content) -> Expr<'a
};
Expr::Record {
update: None,
fields: arena.alloc([loc_assigned_field]),
final_comments: arena.alloc([]),
}
@ -667,7 +663,6 @@ fn byte_to_ast<'a>(env: &Env<'a, '_>, value: u8, content: &Content) -> Expr<'a>
};
Expr::Record {
update: None,
fields: arena.alloc([loc_assigned_field]),
final_comments: &[],
}
@ -783,7 +778,6 @@ fn num_to_ast<'a>(env: &Env<'a, '_>, num_expr: Expr<'a>, content: &Content) -> E
};
Expr::Record {
update: None,
fields: arena.alloc([loc_assigned_field]),
final_comments: arena.alloc([]),
}

View File

@ -207,55 +207,6 @@ pub fn canonicalize_expr<'a>(
}
ast::Expr::Record {
fields,
update: Some(loc_update),
final_comments: _,
} => {
let (can_update, update_out) =
canonicalize_expr(env, var_store, scope, loc_update.region, &loc_update.value);
if let Var(symbol) = &can_update.value {
match canonicalize_fields(env, var_store, scope, region, fields) {
Ok((can_fields, mut output)) => {
output.references = output.references.union(update_out.references);
let answer = Update {
record_var: var_store.fresh(),
ext_var: var_store.fresh(),
symbol: *symbol,
updates: can_fields,
};
(answer, output)
}
Err(CanonicalizeRecordProblem::InvalidOptionalValue {
field_name,
field_region,
record_region,
}) => (
Expr::RuntimeError(roc_problem::can::RuntimeError::InvalidOptionalValue {
field_name,
field_region,
record_region,
}),
Output::default(),
),
}
} else {
// only (optionally qualified) variables can be updated, not arbitrary expressions
let error = roc_problem::can::RuntimeError::InvalidRecordUpdate {
region: can_update.region,
};
let answer = Expr::RuntimeError(error.clone());
env.problems.push(Problem::RuntimeError(error));
(answer, Output::default())
}
}
ast::Expr::Record {
fields,
update: None,
final_comments: _,
} => {
if fields.is_empty() {

View File

@ -160,12 +160,10 @@ pub fn desugar_expr<'a>(arena: &'a Bump, loc_expr: &'a Located<Expr<'a>>) -> &'a
}
Record {
fields,
update,
final_comments,
}
| Nested(Record {
fields,
update,
final_comments,
}) => {
let mut new_fields = Vec::with_capacity_in(fields.len(), arena);
@ -184,7 +182,6 @@ pub fn desugar_expr<'a>(arena: &'a Bump, loc_expr: &'a Located<Expr<'a>>) -> &'a
arena.alloc(Located {
region: loc_expr.region,
value: Record {
update: *update,
fields: new_fields,
final_comments,
},

View File

@ -243,10 +243,9 @@ impl<'a> Formattable<'a> for Expr<'a> {
}
Record {
fields,
update,
final_comments,
} => {
fmt_record(buf, *update, fields, final_comments, indent);
fmt_record(buf, None, fields, final_comments, indent);
}
RecordUpdate {
fields,

View File

@ -105,7 +105,6 @@ pub enum Expr<'a> {
},
Record {
update: Option<&'a Loc<Expr<'a>>>,
fields: &'a [Loc<AssignedField<'a, Expr<'a>>>],
final_comments: &'a [CommentOrNewline<'a>],
},

View File

@ -1352,7 +1352,6 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<
Expr::Record {
fields,
update: None,
final_comments: _,
} => {
let mut loc_patterns = Vec::with_capacity_in(fields.len(), arena);
@ -1390,9 +1389,6 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<
| Expr::When(_, _)
| Expr::MalformedClosure
| Expr::PrecedenceConflict { .. }
| Expr::Record {
update: Some(_), ..
}
| Expr::RecordUpdate { .. }
| Expr::UnaryOp(_, _) => Err(()),
@ -2086,10 +2082,16 @@ fn record_literal_help<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>, EExpr<'
let (opt_update, loc_assigned_fields_with_comments) = loc_record.value;
// This is a record literal, not a destructure.
let mut value = Expr::Record {
update: opt_update.map(|loc_expr| &*arena.alloc(loc_expr)),
fields: loc_assigned_fields_with_comments.value.0.into_bump_slice(),
final_comments: loc_assigned_fields_with_comments.value.1,
let mut value = match opt_update {
Some(update) => Expr::RecordUpdate {
update: &*arena.alloc(update),
fields: loc_assigned_fields_with_comments.value.0.into_bump_slice(),
final_comments: loc_assigned_fields_with_comments.value.1,
},
None => Expr::Record {
fields: loc_assigned_fields_with_comments.value.0.into_bump_slice(),
final_comments: loc_assigned_fields_with_comments.value.1,
},
};
// there can be field access, e.g. `{ x : 4 }.x`

View File

@ -414,7 +414,6 @@ mod test_parse {
let arena = Bump::new();
let expected = Record {
fields: &[],
update: None,
final_comments: &[],
};
let actual = parse_expr_with(&arena, "{}");
@ -444,8 +443,8 @@ mod test_parse {
ident: "baz",
};
let update_target = Located::new(0, 0, 2, 13, var);
let expected = Record {
update: Some(&*arena.alloc(update_target)),
let expected = RecordUpdate {
update: &*arena.alloc(update_target),
fields,
final_comments: &[],
};
@ -480,7 +479,6 @@ mod test_parse {
Located::new(0, 0, 28, 32, label2),
];
let expected = Record {
update: None,
fields,
final_comments: &[],
};
@ -1860,7 +1858,6 @@ mod test_parse {
let identifier_z = Located::new(2, 2, 0, 1, Identifier("z"));
let empty_record = Record {
update: None,
fields: &[],
final_comments: &[],
};

View File

@ -379,9 +379,9 @@ pub fn to_expr2<'a>(
)
}
Record {
RecordUpdate {
fields,
update: Some(loc_update),
update: loc_update,
final_comments: _,
} => {
let (can_update, update_out) =
@ -435,7 +435,6 @@ pub fn to_expr2<'a>(
Record {
fields,
update: None,
final_comments: _,
} => {
if fields.is_empty() {