mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Merge pull request #7468 from joshuawarner32/fuzzing-bugs-9
And... more fuzzing bugs!
This commit is contained in:
commit
89ef225f5b
24 changed files with 499 additions and 279 deletions
38
crates/compiler/test_syntax/src/bin/dump_syntax.rs
Normal file
38
crates/compiler/test_syntax/src/bin/dump_syntax.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
//! Dump a syntax tree for a given input file.
|
||||
//!
|
||||
//! Typical usage:
|
||||
//! `cargo run --bin dump_syntax -- full file.roc`
|
||||
|
||||
use std::process::exit;
|
||||
|
||||
use bumpalo::Bump;
|
||||
use test_syntax::test_helpers::InputKind;
|
||||
|
||||
fn main() {
|
||||
let args = std::env::args().collect::<Vec<String>>();
|
||||
if args.len() != 3 {
|
||||
eprintln!("Usage: {} [expr|full|moduledefs|header] <input>", args[0]);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let kind = match args[1].as_str() {
|
||||
"expr" => InputKind::Expr,
|
||||
"full" => InputKind::Full,
|
||||
"moduledefs" => InputKind::ModuleDefs,
|
||||
"header" => InputKind::Header,
|
||||
_ => {
|
||||
eprintln!("Invalid input kind: {}", args[1]);
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let text = std::fs::read_to_string(&args[2]).unwrap_or_else(|e| {
|
||||
eprintln!("Error reading file: {}", e);
|
||||
exit(1);
|
||||
});
|
||||
let input = kind.with_text(&text);
|
||||
let arena = Bump::new();
|
||||
let output = input.parse_in(&arena);
|
||||
eprintln!("memory used: {}", arena.allocated_bytes());
|
||||
println!("{:#?}", output);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
x :
|
||||
(a where e
|
||||
implements K)
|
||||
-> Z
|
||||
s
|
|
@ -0,0 +1,81 @@
|
|||
@0-31 SpaceAfter(
|
||||
Defs(
|
||||
Defs {
|
||||
tags: [
|
||||
EitherIndex(2147483648),
|
||||
],
|
||||
regions: [
|
||||
@0-29,
|
||||
],
|
||||
space_before: [
|
||||
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
|
||||
],
|
||||
space_after: [
|
||||
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
|
||||
],
|
||||
spaces: [],
|
||||
type_defs: [],
|
||||
value_defs: [
|
||||
Annotation(
|
||||
@0-1 Identifier {
|
||||
ident: "x",
|
||||
},
|
||||
@3-28 Function(
|
||||
[
|
||||
@3-25 Where(
|
||||
@3-4 SpaceAfter(
|
||||
BoundVariable(
|
||||
"a",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
[
|
||||
@11-25 ImplementsClause {
|
||||
var: @11-12 SpaceBefore(
|
||||
SpaceAfter(
|
||||
"e",
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
abilities: [
|
||||
@24-25 Apply(
|
||||
"",
|
||||
"K",
|
||||
[],
|
||||
),
|
||||
],
|
||||
},
|
||||
],
|
||||
),
|
||||
],
|
||||
Pure,
|
||||
@27-28 Apply(
|
||||
"",
|
||||
"Z",
|
||||
[],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
},
|
||||
@30-31 SpaceBefore(
|
||||
Var {
|
||||
module_name: "",
|
||||
ident: "s",
|
||||
},
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
)
|
|
@ -0,0 +1,5 @@
|
|||
x:(a
|
||||
where
|
||||
e
|
||||
implements K->Z)
|
||||
s
|
|
@ -24,16 +24,16 @@
|
|||
"p",
|
||||
),
|
||||
derived: Some(
|
||||
@18-20 SpaceBefore(
|
||||
Implements(
|
||||
[],
|
||||
),
|
||||
[
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [
|
||||
LineComment(
|
||||
"",
|
||||
),
|
||||
],
|
||||
),
|
||||
implements: @8-18,
|
||||
after_implements_kw: [],
|
||||
item: @18-20 [],
|
||||
},
|
||||
),
|
||||
},
|
||||
],
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
P := W
|
||||
implements []
|
||||
t
|
|
@ -0,0 +1,57 @@
|
|||
@0-25 SpaceAfter(
|
||||
Defs(
|
||||
Defs {
|
||||
tags: [
|
||||
EitherIndex(0),
|
||||
],
|
||||
regions: [
|
||||
@0-23,
|
||||
],
|
||||
space_before: [
|
||||
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
|
||||
],
|
||||
space_after: [
|
||||
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
|
||||
],
|
||||
spaces: [],
|
||||
type_defs: [
|
||||
Opaque {
|
||||
header: TypeHeader {
|
||||
name: @0-1 "P",
|
||||
vars: [],
|
||||
},
|
||||
typ: @3-4 Apply(
|
||||
"",
|
||||
"W",
|
||||
[],
|
||||
),
|
||||
derived: Some(
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [
|
||||
Newline,
|
||||
],
|
||||
implements: @7-17,
|
||||
after_implements_kw: [
|
||||
Newline,
|
||||
],
|
||||
item: @21-23 [],
|
||||
},
|
||||
),
|
||||
},
|
||||
],
|
||||
value_defs: [],
|
||||
},
|
||||
@24-25 SpaceBefore(
|
||||
Var {
|
||||
module_name: "",
|
||||
ident: "t",
|
||||
},
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
)
|
|
@ -0,0 +1,4 @@
|
|||
P:=W
|
||||
implements
|
||||
[]
|
||||
t
|
|
@ -81,8 +81,11 @@
|
|||
[],
|
||||
),
|
||||
derived: Some(
|
||||
@19-29 Implements(
|
||||
[
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [],
|
||||
implements: @8-18,
|
||||
after_implements_kw: [],
|
||||
item: @19-29 [
|
||||
@20-22 ImplementsAbility {
|
||||
ability: @20-22 Apply(
|
||||
"",
|
||||
|
@ -100,7 +103,7 @@
|
|||
impls: None,
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
Opaque {
|
||||
|
@ -126,8 +129,11 @@
|
|||
],
|
||||
),
|
||||
derived: Some(
|
||||
@74-84 Implements(
|
||||
[
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [],
|
||||
implements: @63-73,
|
||||
after_implements_kw: [],
|
||||
item: @74-84 [
|
||||
@75-77 ImplementsAbility {
|
||||
ability: @75-77 Apply(
|
||||
"",
|
||||
|
@ -145,7 +151,7 @@
|
|||
impls: None,
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
Opaque {
|
||||
|
@ -171,31 +177,31 @@
|
|||
],
|
||||
),
|
||||
derived: Some(
|
||||
@134-144 SpaceBefore(
|
||||
Implements(
|
||||
[
|
||||
@135-137 ImplementsAbility {
|
||||
ability: @135-137 Apply(
|
||||
"",
|
||||
"Eq",
|
||||
[],
|
||||
),
|
||||
impls: None,
|
||||
},
|
||||
@139-143 ImplementsAbility {
|
||||
ability: @139-143 Apply(
|
||||
"",
|
||||
"Hash",
|
||||
[],
|
||||
),
|
||||
impls: None,
|
||||
},
|
||||
],
|
||||
),
|
||||
[
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
implements: @123-133,
|
||||
after_implements_kw: [],
|
||||
item: @134-144 [
|
||||
@135-137 ImplementsAbility {
|
||||
ability: @135-137 Apply(
|
||||
"",
|
||||
"Eq",
|
||||
[],
|
||||
),
|
||||
impls: None,
|
||||
},
|
||||
@139-143 ImplementsAbility {
|
||||
ability: @139-143 Apply(
|
||||
"",
|
||||
"Hash",
|
||||
[],
|
||||
),
|
||||
impls: None,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
Opaque {
|
||||
|
@ -209,8 +215,11 @@
|
|||
[],
|
||||
),
|
||||
derived: Some(
|
||||
@165-187 Implements(
|
||||
[
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [],
|
||||
implements: @154-164,
|
||||
after_implements_kw: [],
|
||||
item: @165-187 [
|
||||
@166-173 ImplementsAbility {
|
||||
ability: @166-168 Apply(
|
||||
"",
|
||||
|
@ -244,7 +253,7 @@
|
|||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
Opaque {
|
||||
|
@ -258,8 +267,11 @@
|
|||
[],
|
||||
),
|
||||
derived: Some(
|
||||
@208-222 Implements(
|
||||
[
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [],
|
||||
implements: @197-207,
|
||||
after_implements_kw: [],
|
||||
item: @208-222 [
|
||||
@209-221 ImplementsAbility {
|
||||
ability: @209-211 Apply(
|
||||
"",
|
||||
|
@ -280,7 +292,7 @@
|
|||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
Opaque {
|
||||
|
@ -294,8 +306,11 @@
|
|||
[],
|
||||
),
|
||||
derived: Some(
|
||||
@243-263 Implements(
|
||||
[
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [],
|
||||
implements: @232-242,
|
||||
after_implements_kw: [],
|
||||
item: @243-263 [
|
||||
@244-256 ImplementsAbility {
|
||||
ability: @244-246 Apply(
|
||||
"",
|
||||
|
@ -324,7 +339,7 @@
|
|||
impls: None,
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
Opaque {
|
||||
|
@ -338,8 +353,11 @@
|
|||
[],
|
||||
),
|
||||
derived: Some(
|
||||
@284-304 Implements(
|
||||
[
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [],
|
||||
implements: @273-283,
|
||||
after_implements_kw: [],
|
||||
item: @284-304 [
|
||||
@285-289 ImplementsAbility {
|
||||
ability: @285-289 Apply(
|
||||
"",
|
||||
|
@ -368,7 +386,7 @@
|
|||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
Opaque {
|
||||
|
@ -382,9 +400,12 @@
|
|||
[],
|
||||
),
|
||||
derived: Some(
|
||||
@325-327 Implements(
|
||||
[],
|
||||
),
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [],
|
||||
implements: @314-324,
|
||||
after_implements_kw: [],
|
||||
item: @325-327 [],
|
||||
},
|
||||
),
|
||||
},
|
||||
Opaque {
|
||||
|
@ -410,47 +431,47 @@
|
|||
],
|
||||
),
|
||||
derived: Some(
|
||||
@377-399 SpaceBefore(
|
||||
Implements(
|
||||
[
|
||||
@378-385 ImplementsAbility {
|
||||
ability: @378-380 Apply(
|
||||
"",
|
||||
"Eq",
|
||||
[],
|
||||
),
|
||||
impls: Some(
|
||||
@381-385 AbilityImpls(
|
||||
[
|
||||
@382-384 LabelOnly(
|
||||
@382-384 "eq",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
@387-398 ImplementsAbility {
|
||||
ability: @387-391 Apply(
|
||||
"",
|
||||
"Hash",
|
||||
[],
|
||||
),
|
||||
impls: Some(
|
||||
@392-398 AbilityImpls(
|
||||
[
|
||||
@393-397 LabelOnly(
|
||||
@393-397 "hash",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
[
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
implements: @366-376,
|
||||
after_implements_kw: [],
|
||||
item: @377-399 [
|
||||
@378-385 ImplementsAbility {
|
||||
ability: @378-380 Apply(
|
||||
"",
|
||||
"Eq",
|
||||
[],
|
||||
),
|
||||
impls: Some(
|
||||
@381-385 AbilityImpls(
|
||||
[
|
||||
@382-384 LabelOnly(
|
||||
@382-384 "eq",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
@387-398 ImplementsAbility {
|
||||
ability: @387-391 Apply(
|
||||
"",
|
||||
"Hash",
|
||||
[],
|
||||
),
|
||||
impls: Some(
|
||||
@392-398 AbilityImpls(
|
||||
[
|
||||
@393-397 LabelOnly(
|
||||
@393-397 "hash",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
Opaque {
|
||||
|
@ -464,8 +485,11 @@
|
|||
[],
|
||||
),
|
||||
derived: Some(
|
||||
@420-427 Implements(
|
||||
[
|
||||
ImplementsAbilities {
|
||||
before_implements_kw: [],
|
||||
implements: @409-419,
|
||||
after_implements_kw: [],
|
||||
item: @420-427 [
|
||||
@421-426 ImplementsAbility {
|
||||
ability: @421-423 Apply(
|
||||
"",
|
||||
|
@ -479,7 +503,7 @@
|
|||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
],
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
{ i #
|
||||
& }
|
||||
& }
|
|
@ -0,0 +1,2 @@
|
|||
return { #
|
||||
g & } e
|
|
@ -0,0 +1,36 @@
|
|||
@0-15 SpaceAfter(
|
||||
Return(
|
||||
@0-15 SpaceBefore(
|
||||
Apply(
|
||||
@8-14 RecordUpdate {
|
||||
update: @11-12 SpaceBefore(
|
||||
Var {
|
||||
module_name: "",
|
||||
ident: "g",
|
||||
},
|
||||
[
|
||||
LineComment(
|
||||
"",
|
||||
),
|
||||
],
|
||||
),
|
||||
fields: [],
|
||||
},
|
||||
[
|
||||
@14-15 Var {
|
||||
module_name: "",
|
||||
ident: "e",
|
||||
},
|
||||
],
|
||||
Space,
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
None,
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
)
|
|
@ -0,0 +1,3 @@
|
|||
return
|
||||
{#
|
||||
g&}e
|
|
@ -301,6 +301,7 @@ mod test_snapshots {
|
|||
pass/ann_effectful_fn.expr,
|
||||
pass/ann_open_union.expr,
|
||||
pass/ann_parens_comments.expr,
|
||||
pass/ann_parens_where_implements_func.expr,
|
||||
pass/ann_pattern_comment_before_body.expr,
|
||||
pass/ann_record_pat_with_comment.expr,
|
||||
pass/ann_tag_union_newline_comment.expr,
|
||||
|
@ -552,6 +553,7 @@ mod test_snapshots {
|
|||
pass/newline_after_sub.expr,
|
||||
pass/newline_and_spaces_before_less_than.expr,
|
||||
pass/newline_before_add.expr,
|
||||
pass/newline_before_and_after_implements_opaque.expr,
|
||||
pass/newline_before_import_curlies.expr,
|
||||
pass/newline_before_sub.expr,
|
||||
pass/newline_in_packages.full,
|
||||
|
@ -666,6 +668,7 @@ mod test_snapshots {
|
|||
pass/return_multiline.expr,
|
||||
pass/return_only_statement.expr,
|
||||
pass/return_parens_comments.expr,
|
||||
pass/return_record_update_comment_empty_fields.expr,
|
||||
pass/return_then_nested_parens.expr,
|
||||
pass/return_with_after.expr,
|
||||
pass/separate_defs.moduledefs,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue