Merge remote-tracking branch 'remote/main' into rebuild-platform

This commit is contained in:
Luke Boswell 2024-08-14 09:12:12 +10:00
commit 5c43bd2cee
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
7 changed files with 637 additions and 593 deletions

View file

@ -9,7 +9,7 @@ use roc_fmt::header::fmt_header;
use roc_fmt::Buf;
use roc_parse::ast::{FullAst, SpacesBefore};
use roc_parse::header::parse_module_defs;
use roc_parse::remove_spaces::RemoveSpaces;
use roc_parse::normalize::Normalize;
use roc_parse::{header, parser::SyntaxError, state::State};
#[derive(Copy, Clone, Debug)]
@ -200,8 +200,8 @@ pub fn format_src(arena: &Bump, src: &str) -> Result<String, FormatProblem> {
}
};
let ast_normalized = ast.remove_spaces(arena);
let reparsed_ast_normalized = reparsed_ast.remove_spaces(arena);
let ast_normalized = ast.normalize(arena);
let reparsed_ast_normalized = reparsed_ast.normalize(arena);
// HACK!
// We compare the debug format strings of the ASTs, because I'm finding in practice that _somewhere_ deep inside the ast,

View file

@ -13,10 +13,10 @@ pub mod header;
pub mod highlight;
pub mod ident;
pub mod keyword;
pub mod normalize;
pub mod number_literal;
pub mod pattern;
pub mod problems;
pub mod remove_spaces;
pub mod src64;
pub mod state;
pub mod string_literal;

View file

@ -7,7 +7,7 @@
use crate::test_helpers::{Input, InputKind};
use bumpalo::Bump;
use roc_parse::{ast::Malformed, remove_spaces::RemoveSpaces};
use roc_parse::{ast::Malformed, normalize::Normalize};
pub fn print_minimizations(text: &str, kind: InputKind) {
let Some(original_error) = round_trip_once_and_extract_error(text, kind) else {
@ -81,12 +81,7 @@ fn round_trip_once(input: Input<'_>) -> Option<String> {
let actual = match input.parse_in(&arena) {
Ok(a) => a,
Err(e) => {
return Some(format!(
"Initial parse failed: {:?}",
e.remove_spaces(&arena)
))
}
Err(e) => return Some(format!("Initial parse failed: {:?}", e.normalize(&arena))),
};
if actual.is_malformed() {
@ -97,11 +92,11 @@ fn round_trip_once(input: Input<'_>) -> Option<String> {
let reparsed_ast = match output.as_ref().parse_in(&arena) {
Ok(r) => r,
Err(e) => return Some(format!("Reparse failed: {:?}", e.remove_spaces(&arena))),
Err(e) => return Some(format!("Reparse failed: {:?}", e.normalize(&arena))),
};
let ast_normalized = actual.remove_spaces(&arena);
let reparsed_ast_normalized = reparsed_ast.remove_spaces(&arena);
let ast_normalized = actual.normalize(&arena);
let reparsed_ast_normalized = reparsed_ast.normalize(&arena);
if format!("{ast_normalized:?}") != format!("{reparsed_ast_normalized:?}") {
return Some("Different ast".to_string());

View file

@ -3,8 +3,8 @@ use roc_fmt::{annotation::Formattable, header::fmt_header};
use roc_parse::{
ast::{Defs, Expr, FullAst, Header, Malformed, SpacesBefore},
header::parse_module_defs,
normalize::Normalize,
parser::{Parser, SyntaxError},
remove_spaces::RemoveSpaces,
state::State,
test_helpers::{parse_defs_with, parse_expr_with, parse_header_with},
};
@ -128,13 +128,13 @@ impl<'a> Malformed for Output<'a> {
}
}
impl<'a> RemoveSpaces<'a> for Output<'a> {
fn remove_spaces(&self, arena: &'a Bump) -> Self {
impl<'a> Normalize<'a> for Output<'a> {
fn normalize(&self, arena: &'a Bump) -> Self {
match self {
Output::Header(header) => Output::Header(header.remove_spaces(arena)),
Output::ModuleDefs(defs) => Output::ModuleDefs(defs.remove_spaces(arena)),
Output::Expr(expr) => Output::Expr(expr.remove_spaces(arena)),
Output::Full(full) => Output::Full(full.remove_spaces(arena)),
Output::Header(header) => Output::Header(header.normalize(arena)),
Output::ModuleDefs(defs) => Output::ModuleDefs(defs.normalize(arena)),
Output::Expr(expr) => Output::Expr(expr.normalize(arena)),
Output::Full(full) => Output::Full(full.normalize(arena)),
}
}
}
@ -221,8 +221,8 @@ impl<'a> Input<'a> {
);
});
let ast_normalized = actual.remove_spaces(&arena);
let reparsed_ast_normalized = reparsed_ast.remove_spaces(&arena);
let ast_normalized = actual.normalize(&arena);
let reparsed_ast_normalized = reparsed_ast.normalize(&arena);
// HACK!
// We compare the debug format strings of the ASTs, because I'm finding in practice that _somewhere_ deep inside the ast,

View file

@ -63,7 +63,7 @@ mod test_fmt {
match header::parse_header(&arena, State::new(src.as_bytes())) {
Ok((actual, state)) => {
use roc_parse::remove_spaces::RemoveSpaces;
use roc_parse::normalize::Normalize;
let mut buf = Buf::new_in(&arena);
@ -77,8 +77,8 @@ mod test_fmt {
);
});
let ast_normalized = actual.remove_spaces(&arena);
let reparsed_ast_normalized = reparsed_ast.remove_spaces(&arena);
let ast_normalized = actual.normalize(&arena);
let reparsed_ast_normalized = reparsed_ast.normalize(&arena);
// HACK!
// We compare the debug format strings of the ASTs, because I'm finding in practice that _somewhere_ deep inside the ast,

View file

@ -2219,21 +2219,24 @@ fn single_tag_payload_fields<'a, 'b>(
types: &mut Types,
) -> (String, RocSingleTagPayload) {
let layout = env.layout_cache.interner.get(in_layout);
// There should be a glue_procs_by_layout entry iff this layout has a closure in it,
// so we shouldn't need to separately check that. Howeevr, we still do a debug_assert
// anyway just so we have some warning in case that relationship somehow didn't hold!
debug_assert_eq!(
env.glue_procs_by_layout.get(&layout).is_some(),
env.layout_cache
.interner
.has_varying_stack_size(in_layout, env.arena),
"glue_procs_by_layout for {:?} was {:?}, but the layout cache said its has_varying_stack_size was {}",
&layout,
env.glue_procs_by_layout.get(&layout),
if std::env::var("SINGLE_TAG_GLUE_CHECK_OFF").as_deref() != Ok("1") {
// There should be a glue_procs_by_layout entry iff this layout has a closure in it,
// so we shouldn't need to separately check that. Howeevr, we still do a debug_assert
// anyway just so we have some warning in case that relationship somehow didn't hold!
debug_assert_eq!(
env.glue_procs_by_layout.get(&layout).is_some(),
env.layout_cache
.interner
.has_varying_stack_size(in_layout, env.arena)
);
.has_varying_stack_size(in_layout, env.arena),
"glue_procs_by_layout for {:?} was {:?}, but the layout cache said its has_varying_stack_size was {}",
&layout,
env.glue_procs_by_layout.get(&layout),
env.layout_cache
.interner
.has_varying_stack_size(in_layout, env.arena)
);
}
let (tag_name, payload_vars) = single_tag_payload(union_tags, subs);