Skip to content

Commit 6077f9c

Browse files
feat: improved type messages (#551)
1 parent 43df7de commit 6077f9c

15 files changed

+332
-154
lines changed

Cargo.lock

Lines changed: 10 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ biome_js_syntax = "0.5.7"
2323
biome_rowan = "0.5.7"
2424
biome_string_case = "0.5.8"
2525
bpaf = { version = "0.9.15", features = ["derive"] }
26+
criterion = "0.5"
2627
crossbeam = "0.8.4"
2728
enumflags2 = "0.7.11"
2829
ignore = "0.4.23"

crates/pgt_completions/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sqlx.workspace = true
3131
tokio = { version = "1.41.1", features = ["full"] }
3232

3333
[dev-dependencies]
34-
criterion = "0.5.1"
34+
criterion.workspace = true
3535
pgt_test_utils.workspace = true
3636

3737
[lib]

crates/pgt_statement_splitter/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pgt_text_size.workspace = true
1919
regex.workspace = true
2020

2121
[dev-dependencies]
22-
criterion = "0.3"
23-
ntest = "0.9.3"
22+
criterion.workspace = true
23+
ntest = "0.9.3"
2424

2525
[[bench]]
2626
harness = false

crates/pgt_typecheck/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,28 @@ version = "0.0.0"
1414
[dependencies]
1515
globset = "0.4.16"
1616
itertools = { version = "0.14.0" }
17+
once_cell = "1.20.2"
1718
pgt_console.workspace = true
1819
pgt_diagnostics.workspace = true
1920
pgt_query.workspace = true
2021
pgt_schema_cache.workspace = true
2122
pgt_text_size.workspace = true
2223
pgt_treesitter.workspace = true
2324
pgt_treesitter_grammar.workspace = true
25+
regex = "1.11.1"
2426
sqlx.workspace = true
2527
tokio.workspace = true
2628
tree-sitter.workspace = true
2729
uuid = { version = "1.18.1", features = ["v4"] }
2830

2931
[dev-dependencies]
32+
criterion.workspace = true
3033
insta.workspace = true
3134
pgt_test_utils.workspace = true
3235

36+
[[bench]]
37+
harness = false
38+
name = "error_rewriting"
39+
3340
[lib]
3441
doctest = false
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
2+
use pgt_typecheck::IdentifierReplacement;
3+
use pgt_typecheck::diagnostics::rewrite_error_message;
4+
5+
fn benchmark_error_rewriting(c: &mut Criterion) {
6+
let replacement = IdentifierReplacement {
7+
original_name: "user_id".to_string(),
8+
original_range: 0..7,
9+
default_value: "'00000000-0000-0000-0000-000000000000'".to_string(),
10+
type_name: "uuid".to_string(),
11+
};
12+
13+
// test case 1: matching the first pattern (most common case)
14+
c.bench_function("rewrite_invalid_input_syntax", |b| {
15+
b.iter(|| {
16+
rewrite_error_message(
17+
black_box(r#"invalid input syntax for type integer: "00000000-0000-0000-0000-000000000000""#),
18+
black_box(&replacement),
19+
)
20+
})
21+
});
22+
23+
// test case 2: matching the operator pattern
24+
c.bench_function("rewrite_operator_does_not_exist", |b| {
25+
b.iter(|| {
26+
rewrite_error_message(
27+
black_box("operator does not exist: integer + text"),
28+
black_box(&replacement),
29+
)
30+
})
31+
});
32+
33+
// test case 3: no pattern matches (fallback)
34+
c.bench_function("rewrite_fallback", |b| {
35+
b.iter(|| {
36+
rewrite_error_message(
37+
black_box("some other error message that doesn't match any pattern"),
38+
black_box(&replacement),
39+
)
40+
})
41+
});
42+
43+
// test case 4: longer error message with first pattern
44+
c.bench_function("rewrite_long_message", |b| {
45+
b.iter(|| {
46+
rewrite_error_message(
47+
black_box(r#"invalid input syntax for type timestamp: "00000000-0000-0000-0000-000000000000" at character 45"#),
48+
black_box(&replacement),
49+
)
50+
})
51+
});
52+
}
53+
54+
criterion_group!(benches, benchmark_error_rewriting);
55+
criterion_main!(benches);

0 commit comments

Comments
 (0)