Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Remove Boxing of SymbolicExpressions #4530

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions clarity/src/vm/ast/parser/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ pub fn parse_lexed(input: Vec<(LexItem, u32, u32)>) -> ParseResult<Vec<PreSymbol
if let Some((list, start_line, start_column, parse_context)) = parse_stack.pop() {
match parse_context {
ParseContext::CollectList => {
let checked_list: ParseResult<Box<[PreSymbolicExpression]>> = list
let checked_list: ParseResult<Vec<PreSymbolicExpression>> = list
.into_iter()
.map(|i| match i {
ParseStackItem::Expression(e) => Ok(e),
Expand Down Expand Up @@ -601,8 +601,7 @@ pub fn parse_lexed(input: Vec<(LexItem, u32, u32)>) -> ParseResult<Vec<PreSymbol
_ => unreachable!("More than four modulos of four."),
}?;
}
let mut pre_expr =
PreSymbolicExpression::tuple(checked_list.into_boxed_slice());
let mut pre_expr = PreSymbolicExpression::tuple(checked_list);
pre_expr.set_span(start_line, start_column, line_pos, column_pos);
handle_expression(&mut parse_stack, &mut output_list, pre_expr);
}
Expand Down Expand Up @@ -772,7 +771,7 @@ mod test {
start_column: u32,
end_line: u32,
end_column: u32,
x: Box<[PreSymbolicExpression]>,
x: Vec<PreSymbolicExpression>,
) -> PreSymbolicExpression {
let mut e = PreSymbolicExpression::list(x);
e.set_span(start_line, start_column, end_line, end_column);
Expand All @@ -784,7 +783,7 @@ mod test {
start_column: u32,
end_line: u32,
end_column: u32,
x: Box<[PreSymbolicExpression]>,
x: Vec<PreSymbolicExpression>,
) -> PreSymbolicExpression {
let mut e = PreSymbolicExpression::tuple(x);
e.set_span(start_line, start_column, end_line, end_column);
Expand All @@ -808,84 +807,84 @@ mod test {
3,
6,
11,
Box::new([
vec![
make_atom("let", 1, 4, 1, 6),
make_list(
1,
8,
1,
20,
Box::new([
vec![
make_list(
1,
9,
1,
13,
Box::new([
vec![
make_atom("x", 1, 10, 1, 10),
make_atom_value(Value::Int(1), 1, 12, 1, 12),
]),
],
),
make_list(
1,
15,
1,
19,
Box::new([
vec![
make_atom("y", 1, 16, 1, 16),
make_atom_value(Value::Int(2), 1, 18, 1, 18),
]),
],
),
]),
],
),
make_list(
2,
5,
6,
10,
Box::new([
vec![
make_atom("+", 2, 6, 2, 6),
make_atom("x", 2, 8, 2, 8),
make_list(
4,
9,
5,
16,
Box::new([
vec![
make_atom("let", 4, 10, 4, 12),
make_list(
4,
14,
4,
20,
Box::new([make_list(
vec![make_list(
4,
15,
4,
19,
Box::new([
vec![
make_atom("x", 4, 16, 4, 16),
make_atom_value(Value::Int(3), 4, 18, 4, 18),
]),
)]),
],
)],
),
make_list(
5,
9,
5,
15,
Box::new([
vec![
make_atom("+", 5, 10, 5, 10),
make_atom("x", 5, 12, 5, 12),
make_atom("y", 5, 14, 5, 14),
]),
],
),
]),
],
),
make_atom("x", 6, 9, 6, 9),
]),
],
),
]),
],
),
make_atom("x", 6, 13, 6, 13),
make_atom("y", 6, 15, 6, 15),
Expand All @@ -907,11 +906,11 @@ mod test {
9,
2,
17,
Box::new([
vec![
make_atom("-", 2, 10, 2, 10),
make_atom_value(Value::Int(12), 2, 12, 2, 13),
make_atom_value(Value::Int(34), 2, 15, 2, 16),
]),
],
),
];

Expand All @@ -931,10 +930,10 @@ mod test {
1,
1,
11,
Box::new([
vec![
make_atom("id", 1, 2, 1, 3),
make_atom_value(Value::Int(1337), 1, 6, 1, 9),
]),
],
)];
let parsed = ast::parser::v1::parse(input);
assert_eq!(Ok(program), parsed, "Should match expected tuple literal");
Expand Down
20 changes: 9 additions & 11 deletions clarity/src/vm/ast/parser/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl<'a> Parser<'a> {
span.end_line = token.span.end_line;
span.end_column = token.span.end_column;
let out_nodes: Vec<_> = std::mem::take(nodes);
let mut e = PreSymbolicExpression::list(out_nodes.into_boxed_slice());
let mut e = PreSymbolicExpression::list(out_nodes);
e.copy_span(span);
Ok(Some(e))
}
Expand All @@ -253,7 +253,7 @@ impl<'a> Parser<'a> {
span.end_line = token.span.end_line;
span.end_column = token.span.end_column;
let out_nodes: Vec<_> = std::mem::take(nodes);
let mut e = PreSymbolicExpression::list(out_nodes.into_boxed_slice());
let mut e = PreSymbolicExpression::list(out_nodes);
e.copy_span(span);
Ok(Some(e))
}
Expand Down Expand Up @@ -301,8 +301,7 @@ impl<'a> Parser<'a> {
open_tuple.span.clone(),
)?;
let out_nodes: Vec<_> = open_tuple.nodes.drain(..).collect();
let mut e =
PreSymbolicExpression::tuple(out_nodes.into_boxed_slice());
let mut e = PreSymbolicExpression::tuple(out_nodes);
let span_before_eof = &self.tokens[self.tokens.len() - 2].span;
open_tuple.span.end_line = span_before_eof.end_line;
open_tuple.span.end_column = span_before_eof.end_column;
Expand Down Expand Up @@ -341,7 +340,7 @@ impl<'a> Parser<'a> {
placeholder.copy_span(&token.span);
open_tuple.nodes.push(placeholder); // Placeholder value
let out_nodes: Vec<_> = open_tuple.nodes.drain(..).collect();
let mut e = PreSymbolicExpression::tuple(out_nodes.into_boxed_slice());
let mut e = PreSymbolicExpression::tuple(out_nodes);
let span_before_eof = &self.tokens[self.tokens.len() - 2].span;
open_tuple.span.end_line = span_before_eof.end_line;
open_tuple.span.end_column = span_before_eof.end_column;
Expand Down Expand Up @@ -386,8 +385,7 @@ impl<'a> Parser<'a> {
placeholder.copy_span(&eof_span);
open_tuple.nodes.push(placeholder); // Placeholder value
let out_nodes: Vec<_> = open_tuple.nodes.drain(..).collect();
let mut e =
PreSymbolicExpression::tuple(out_nodes.into_boxed_slice());
let mut e = PreSymbolicExpression::tuple(out_nodes);
open_tuple.span.end_line =
open_tuple.diagnostic_token.span.end_line;
open_tuple.span.end_column =
Expand Down Expand Up @@ -422,7 +420,7 @@ impl<'a> Parser<'a> {
open_tuple.span.end_column = token.span.end_column;
self.next_token();
let out_nodes: Vec<_> = open_tuple.nodes.drain(..).collect();
let mut e = PreSymbolicExpression::tuple(out_nodes.into_boxed_slice());
let mut e = PreSymbolicExpression::tuple(out_nodes);
e.copy_span(&open_tuple.span);
return Ok(Some(e));
}
Expand All @@ -440,7 +438,7 @@ impl<'a> Parser<'a> {
open_tuple.span.end_column = token.span.end_column;
self.next_token();
let out_nodes: Vec<_> = open_tuple.nodes.drain(..).collect();
let mut e = PreSymbolicExpression::tuple(out_nodes.into_boxed_slice());
let mut e = PreSymbolicExpression::tuple(out_nodes);
e.copy_span(&open_tuple.span);
return Ok(Some(e));
}
Expand Down Expand Up @@ -479,7 +477,7 @@ impl<'a> Parser<'a> {
open_tuple.span.end_column = token.span.end_column;
self.next_token();
let out_nodes: Vec<_> = open_tuple.nodes.drain(..).collect();
let mut e = PreSymbolicExpression::tuple(out_nodes.into_boxed_slice());
let mut e = PreSymbolicExpression::tuple(out_nodes);
e.copy_span(&open_tuple.span);
return Ok(SetupTupleResult::Closed(e));
}
Expand All @@ -496,7 +494,7 @@ impl<'a> Parser<'a> {
open_tuple.span.end_column = token.span.end_column;
self.next_token();
let out_nodes: Vec<_> = open_tuple.nodes.drain(..).collect();
let mut e = PreSymbolicExpression::tuple(out_nodes.into_boxed_slice());
let mut e = PreSymbolicExpression::tuple(out_nodes);
e.copy_span(&open_tuple.span);
return Ok(SetupTupleResult::Closed(e));
}
Expand Down
Loading