Skip to content

Commit

Permalink
Hide spans from ast debug output to fix insta tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillig committed Jun 23, 2024
1 parent 13b1a3c commit e7cb9bf
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 384 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
toolchain: ${{ matrix.rust }}

- name: Test
run: cargo test --workspace --all-targets
run: cargo test --workspace --all-targets --no-fail-fast

- name: Filecheck
run: cargo run -p sonatina-filecheck
Expand Down
1 change: 1 addition & 0 deletions crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ either = { version = "1.12.0", default-features = false }
annotate-snippets = "0.11.4"
rustc-hash = "2.0.0"
bimap = "0.6.3"
derive_more = { version = "=1.0.0-beta.6", default-features = false, features = ["debug"] }

[dev-dependencies]
dir-test = "0.3"
Expand Down
16 changes: 12 additions & 4 deletions crates/parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ use smol_str::SmolStr;
pub use sonatina_triple::{InvalidTriple, TargetTriple};
use std::str::FromStr;

// `Span`s aren't printed in the Debug output because the pest
// code locations differ on windows vs *nix, which breaks the ast tests.
use derive_more::Debug as Dbg;

pub fn parse(input: &str) -> Result<Module, Vec<Error>> {
match Parser::parse(Rule::module, input) {
Err(err) => Err(vec![Error::SyntaxError(err)]),
Expand Down Expand Up @@ -237,9 +241,10 @@ impl FromSyntax<Error> for Block {
}
}

#[derive(Debug)]
#[derive(Dbg)]
pub struct BlockId {
pub id: Option<u32>,
#[debug(skip)]
pub span: Span,
}

Expand Down Expand Up @@ -309,9 +314,10 @@ impl FromSyntax<Error> for (Value, BlockId) {
}
}

#[derive(Debug)]
#[derive(Dbg)]
pub struct Type {
pub kind: TypeKind,
#[debug(skip)]
pub span: Span,
}

Expand Down Expand Up @@ -417,9 +423,10 @@ impl FromSyntax<Error> for Expr {
#[derive(Debug)]
pub struct Call(pub Spanned<FunctionName>, pub Vec<Value>);

#[derive(Debug)]
#[derive(Dbg)]
pub struct ValueName {
pub string: SmolStr,
#[debug(skip)]
pub span: Span,
}

Expand All @@ -441,9 +448,10 @@ impl FromSyntax<Error> for ValueDeclaration {
}
}

#[derive(Debug)]
#[derive(Dbg)]
pub struct Value {
pub kind: ValueKind,
#[debug(skip)]
pub span: Span,
}

Expand Down
7 changes: 4 additions & 3 deletions crates/parser/src/syntax.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{ops::Range, str::FromStr};

use derive_more::Debug as Dbg;
use either::Either;
use pest::iterators::Pair;
use std::{ops::Range, str::FromStr};

#[derive(pest_derive::Parser)]
#[grammar = "sonatina.pest"]
Expand All @@ -20,8 +20,9 @@ impl Span {
}
}

#[derive(Debug, Clone)]
#[derive(Dbg, Clone)]
pub struct Spanned<T> {
#[debug(skip)]
pub span: Span,
pub inner: T,
}
Expand Down
84 changes: 84 additions & 0 deletions crates/parser/test_files/syntax/module/newlines.ast.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
source: crates/parser/tests/syntax.rs
expression: "format!(\"{:#?}\", module)"
input_file: crates/parser/test_files/syntax/module/newlines.sntn
---
Module {
target: Some(
TargetTriple {
architecture: Evm,
chain: Ethereum,
version: EvmVersion(
London,
),
},
),
declared_functions: [],
struct_types: [],
functions: [
Func {
signature: FuncSignature {
linkage: Public,
name: FunctionName(
"main",
),
params: [],
ret_type: None,
},
blocks: [
Block {
id: BlockId {
id: Some(
0,
),
..
},
stmts: [
Stmt {
kind: Define(
ValueDeclaration(
ValueName {
string: "v0",
..
},
Type {
kind: Int(
I8,
),
..
},
),
Binary(
Add,
Value {
kind: Immediate(
I8(
1,
),
),
..
},
Value {
kind: Immediate(
I8(
2,
),
),
..
},
),
),
},
Stmt {
kind: Return(
None,
),
},
],
},
],
comments: [],
},
],
comments: [],
}
12 changes: 12 additions & 0 deletions crates/parser/test_files/syntax/module/newlines.ir.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: crates/parser/tests/syntax.rs
expression: w.dump_string().unwrap()
input_file: crates/parser/test_files/syntax/module/newlines.sntn
---
target = evm-ethereum-london
func public %main() -> void {
block0:
v0.i8 = add 1.i8 2.i8;
return;

}
48 changes: 48 additions & 0 deletions crates/parser/test_files/syntax/module/newlines.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
source: crates/parser/tests/syntax.rs
expression: s
input_file: crates/parser/test_files/syntax/module/newlines.sntn
---
module "target = "evm-ethereum-london"
func public %main() {
block0:
v0.i8 = add 1.i8 2.i8;
return;
}
"
target_triple "evm-ethereum-london"
function "func public %main() {
block0:
v0.i8 = add 1.i8 2.i8;
return;
}"
function_signature "func public %main() "
function_linkage "public"
function_identifier "%main"
function_name "main"
function_params "()"
block "block0:
v0.i8 = add 1.i8 2.i8;
return;"
block_ident "block0"
block_number "0"
stmt "v0.i8 = add 1.i8 2.i8;"
define_stmt "v0.i8 = add 1.i8 2.i8"
value_declaration "v0.i8"
value_name "v0"
type_name "i8"
primitive_type "i8"
expr "add 1.i8 2.i8"
bin_expr "add 1.i8 2.i8"
bin_op "add"
value "1.i8"
imm_number "1.i8"
decimal "1"
primitive_type "i8"
value "2.i8"
imm_number "2.i8"
decimal "2"
primitive_type "i8"
stmt "return;"
return_stmt "return"
EOI ""
6 changes: 6 additions & 0 deletions crates/parser/test_files/syntax/module/newlines.sntn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target = "evm-ethereum-london"
func public %main() {
block0:
v0.i8 = add 1.i8 2.i8;
return;
}
Loading

0 comments on commit e7cb9bf

Please sign in to comment.