Simplifying PR per reviewers request

This commit is contained in:
Micah Kendall 2024-04-01 23:17:50 +11:00 committed by Lucas
parent d39dbd6697
commit ff4ddfbe1b
6 changed files with 11 additions and 91 deletions

View File

@ -1814,6 +1814,7 @@ pub enum TraceKind {
Trace, Trace,
Todo, Todo,
Error, Error,
Emit,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]

View File

@ -550,12 +550,6 @@ pub enum UntypedExpr {
text: Box<Self>, text: Box<Self>,
}, },
Emit {
location: Span,
then: Box<Self>,
text: Box<Self>,
},
TraceIfFalse { TraceIfFalse {
location: Span, location: Span,
value: Box<Self>, value: Box<Self>,
@ -1267,7 +1261,6 @@ impl UntypedExpr {
match self { match self {
Self::PipeLine { expressions, .. } => expressions.last().location(), Self::PipeLine { expressions, .. } => expressions.last().location(),
Self::Trace { then, .. } => then.location(), Self::Trace { then, .. } => then.location(),
Self::Emit { then, .. } => then.location(),
Self::TraceIfFalse { location, .. } Self::TraceIfFalse { location, .. }
| Self::Fn { location, .. } | Self::Fn { location, .. }
| Self::Var { location, .. } | Self::Var { location, .. }
@ -1307,9 +1300,7 @@ impl UntypedExpr {
.map(|e| e.start_byte_index()) .map(|e| e.start_byte_index())
.unwrap_or(location.start), .unwrap_or(location.start),
Self::PipeLine { expressions, .. } => expressions.first().start_byte_index(), Self::PipeLine { expressions, .. } => expressions.first().start_byte_index(),
Self::Trace { location, .. } Self::Trace { location, .. } | Self::Assignment { location, .. } => location.start,
| Self::Emit { location, .. }
| Self::Assignment { location, .. } => location.start,
_ => self.location().start, _ => self.location().start,
} }
} }

View File

@ -639,7 +639,7 @@ impl<'comments> Formatter<'comments> {
) -> Document<'a> { ) -> Document<'a> {
let args = wrap_args(args.iter().map(|e| (self.fn_arg(e), false))).group(); let args = wrap_args(args.iter().map(|e| (self.fn_arg(e), false))).group();
let body = match body { let body = match body {
UntypedExpr::Trace { .. } | UntypedExpr::Emit { .. } | UntypedExpr::When { .. } => { UntypedExpr::Trace { .. } | UntypedExpr::When { .. } => {
self.expr(body, true).force_break() self.expr(body, true).force_break()
} }
_ => self.expr(body, true), _ => self.expr(body, true),
@ -957,8 +957,6 @@ impl<'comments> Formatter<'comments> {
kind, text, then, .. kind, text, then, ..
} => self.trace(kind, text, then), } => self.trace(kind, text, then),
UntypedExpr::Emit { text, then, .. } => self.emit(text, then),
UntypedExpr::When { UntypedExpr::When {
subject, clauses, .. subject, clauses, ..
} => self.when(subject, clauses), } => self.when(subject, clauses),
@ -1022,6 +1020,7 @@ impl<'comments> Formatter<'comments> {
TraceKind::Trace => ("trace", None), TraceKind::Trace => ("trace", None),
TraceKind::Error => ("fail", Some(DEFAULT_ERROR_STR.to_string())), TraceKind::Error => ("fail", Some(DEFAULT_ERROR_STR.to_string())),
TraceKind::Todo => ("todo", Some(DEFAULT_TODO_STR.to_string())), TraceKind::Todo => ("todo", Some(DEFAULT_TODO_STR.to_string())),
TraceKind::Emit => ("emit", None),
}; };
let body = match text { let body = match text {
@ -1037,7 +1036,7 @@ impl<'comments> Formatter<'comments> {
match kind { match kind {
TraceKind::Error | TraceKind::Todo => body, TraceKind::Error | TraceKind::Todo => body,
TraceKind::Trace => body TraceKind::Trace | TraceKind::Emit => body
.append(if self.pop_empty_lines(then.start_byte_index()) { .append(if self.pop_empty_lines(then.start_byte_index()) {
lines(2) lines(2)
} else { } else {
@ -1047,20 +1046,6 @@ impl<'comments> Formatter<'comments> {
} }
} }
pub fn emit<'a>(&mut self, text: &'a UntypedExpr, then: &'a UntypedExpr) -> Document<'a> {
let body = "emit"
.to_doc()
.append(" ")
.append(self.wrap_expr(text))
.group();
body.append(if self.pop_empty_lines(then.start_byte_index()) {
lines(2)
} else {
line()
})
.append(self.expr(then, true))
}
pub fn pattern_constructor<'a>( pub fn pattern_constructor<'a>(
&mut self, &mut self,
name: &'a str, name: &'a str,
@ -1675,7 +1660,6 @@ impl<'comments> Formatter<'comments> {
kind: TraceKind::Trace, kind: TraceKind::Trace,
.. ..
} }
| UntypedExpr::Emit { .. }
| UntypedExpr::Sequence { .. } | UntypedExpr::Sequence { .. }
| UntypedExpr::Assignment { .. } => "{" | UntypedExpr::Assignment { .. } => "{"
.to_doc() .to_doc()
@ -1718,7 +1702,6 @@ impl<'comments> Formatter<'comments> {
kind: TraceKind::Trace, kind: TraceKind::Trace,
.. ..
} }
| UntypedExpr::Emit { .. }
| UntypedExpr::Sequence { .. } | UntypedExpr::Sequence { .. }
| UntypedExpr::Assignment { .. } => " {" | UntypedExpr::Assignment { .. } => " {"
.to_doc() .to_doc()

View File

@ -354,11 +354,6 @@ pub enum AirTree {
msg: Box<AirTree>, msg: Box<AirTree>,
then: Box<AirTree>, then: Box<AirTree>,
}, },
Emit {
tipo: Rc<Type>,
msg: Box<AirTree>,
then: Box<AirTree>,
},
// End Expressions // End Expressions
} }
@ -836,7 +831,7 @@ impl AirTree {
} }
} }
pub fn emit(msg: AirTree, tipo: Rc<Type>, then: AirTree) -> AirTree { pub fn emit(msg: AirTree, tipo: Rc<Type>, then: AirTree) -> AirTree {
AirTree::Emit { AirTree::Trace {
tipo, tipo,
msg: msg.into(), msg: msg.into(),
then: then.into(), then: then.into(),
@ -1391,11 +1386,6 @@ impl AirTree {
msg.create_air_vec(air_vec); msg.create_air_vec(air_vec);
then.create_air_vec(air_vec); then.create_air_vec(air_vec);
} }
AirTree::Emit { tipo, msg, then } => {
air_vec.push(Air::Emit { tipo: tipo.clone() });
msg.create_air_vec(air_vec);
then.create_air_vec(air_vec);
}
} }
} }
@ -1417,8 +1407,7 @@ impl AirTree {
| AirTree::Constr { tipo, .. } | AirTree::Constr { tipo, .. }
| AirTree::RecordUpdate { tipo, .. } | AirTree::RecordUpdate { tipo, .. }
| AirTree::ErrorTerm { tipo, .. } | AirTree::ErrorTerm { tipo, .. }
| AirTree::Trace { tipo, .. } | AirTree::Trace { tipo, .. } => tipo.clone(),
| AirTree::Emit { tipo, .. } => tipo.clone(),
AirTree::Void => void(), AirTree::Void => void(),
AirTree::Var { constructor, .. } => constructor.tipo.clone(), AirTree::Var { constructor, .. } => constructor.tipo.clone(),
AirTree::Fn { func_body, .. } => func_body.return_type(), AirTree::Fn { func_body, .. } => func_body.return_type(),
@ -1474,8 +1463,7 @@ impl AirTree {
| AirTree::If { tipo, .. } | AirTree::If { tipo, .. }
| AirTree::Constr { tipo, .. } | AirTree::Constr { tipo, .. }
| AirTree::ErrorTerm { tipo, .. } | AirTree::ErrorTerm { tipo, .. }
| AirTree::Trace { tipo, .. } | AirTree::Trace { tipo, .. } => vec![tipo],
| AirTree::Emit { tipo, .. } => vec![tipo],
AirTree::Var { constructor, .. } => { AirTree::Var { constructor, .. } => {
vec![constructor.tipo.borrow_mut()] vec![constructor.tipo.borrow_mut()]
} }
@ -1959,23 +1947,6 @@ impl AirTree {
apply_with_func_last, apply_with_func_last,
); );
} }
AirTree::Emit { msg, then, .. } => {
msg.do_traverse_tree_with(
tree_path,
current_depth + 1,
index_count.next_number(),
with,
apply_with_func_last,
);
then.do_traverse_tree_with(
tree_path,
current_depth + 1,
index_count.next_number(),
with,
apply_with_func_last,
);
}
AirTree::DefineFunc { AirTree::DefineFunc {
func_body, then, .. func_body, then, ..
} => { } => {
@ -2320,15 +2291,6 @@ impl AirTree {
panic!("Tree Path index outside tree children nodes") panic!("Tree Path index outside tree children nodes")
} }
} }
AirTree::Emit { msg, then, .. } => {
if *index == 0 {
msg.as_mut().do_find_air_tree_node(tree_path_iter)
} else if *index == 1 {
then.as_mut().do_find_air_tree_node(tree_path_iter)
} else {
panic!("Tree Path index outside tree children nodes")
}
}
_ => { _ => {
panic!("A tree node with no children was encountered with a longer tree path.") panic!("A tree node with no children was encountered with a longer tree path.")
} }

View File

@ -39,7 +39,8 @@ pub fn parser<'a>(
just(Token::Emit) just(Token::Emit)
.ignore_then(choice((string::hybrid(), expression.clone()))) .ignore_then(choice((string::hybrid(), expression.clone())))
.then(sequence.clone().or_not()) .then(sequence.clone().or_not())
.map_with_span(|(text, then_), span| UntypedExpr::Emit { .map_with_span(|(text, then_), span| UntypedExpr::Trace {
kind: TraceKind::Emit,
location: span, location: span,
then: Box::new(then_.unwrap_or_else(|| UntypedExpr::todo(None, span))), then: Box::new(then_.unwrap_or_else(|| UntypedExpr::todo(None, span))),
text: Box::new(text), text: Box::new(text),

View File

@ -281,22 +281,6 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
kind, kind,
} => self.infer_trace(kind, *then, location, *text), } => self.infer_trace(kind, *then, location, *text),
UntypedExpr::Emit {
location,
then,
text,
} => {
let text = self.infer(*text)?;
self.unify(string(), text.tipo(), text.location(), false)?;
let then = self.infer(*then)?;
Ok(TypedExpr::Emit {
location,
tipo: then.tipo(),
then: Box::new(then),
text: Box::new(text),
})
}
UntypedExpr::When { UntypedExpr::When {
location, location,
subject, subject,
@ -2340,9 +2324,7 @@ fn assert_no_assignment(expr: &UntypedExpr) -> Result<(), Error> {
location: expr.location(), location: expr.location(),
expr: *value.clone(), expr: *value.clone(),
}), }),
UntypedExpr::Trace { then, .. } | UntypedExpr::Emit { then, .. } => { UntypedExpr::Trace { then, .. } => assert_no_assignment(then),
assert_no_assignment(then)
}
UntypedExpr::Fn { .. } UntypedExpr::Fn { .. }
| UntypedExpr::BinOp { .. } | UntypedExpr::BinOp { .. }
| UntypedExpr::ByteArray { .. } | UntypedExpr::ByteArray { .. }