Skip to content

Commit 3e2f1c3

Browse files
committed
Attach file ids to spans
1 parent 49e2ce9 commit 3e2f1c3

28 files changed

Lines changed: 191 additions & 215 deletions

crates/analyzer/src/db/queries/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn module_all_items(db: &dyn AnalyzerDb, module: ModuleId) -> Rc<Vec<Item>>
7171
)))),
7272
ast::ModuleStmt::Constant(node) => Some(Item::Constant(db.intern_module_const(
7373
Rc::new(ModuleConstant {
74-
ast: node.clone(),
74+
ast: *node.clone(),
7575
module,
7676
}),
7777
))),

crates/analyzer/src/traversal/call_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub fn validate_arg_labels(
156156
scope.fancy_error(
157157
"missing argument label",
158158
vec![Label::primary(
159-
Span::new(arg_val.span.start, arg_val.span.start),
159+
Span::new(arg_val.span.file_id, arg_val.span.start, arg_val.span.start),
160160
format!("add `{}=` here", expected_label),
161161
)],
162162
vec![format!(

crates/analyzer/tests/analysis.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ macro_rules! test_analysis {
2424
let mut files = FileStore::new();
2525
let src = test_files::fixture($path);
2626
let id = files.add_file($path, src);
27-
let fe_module = match fe_parser::parse_file(&src) {
27+
let fe_module = match fe_parser::parse_file(id, &src) {
2828
Ok((module, _)) => module,
2929
Err(diags) => {
30-
print_diagnostics(&diags, id, &files);
30+
print_diagnostics(&diags, &files);
3131
panic!("parsing failed");
3232
}
3333
};
@@ -36,7 +36,7 @@ macro_rules! test_analysis {
3636
let module = db.intern_module(Rc::new(items::Module { ast: fe_module }));
3737
let diagnostics = module.diagnostics(&db);
3838
if !diagnostics.is_empty() {
39-
print_diagnostics(&diagnostics, id, &files);
39+
print_diagnostics(&diagnostics, &files);
4040
panic!("analysis failed")
4141
}
4242

@@ -46,10 +46,10 @@ macro_rules! test_analysis {
4646
// for larger diffs. I recommend commenting out all tests but one.
4747
fe_common::assert_snapshot_wasm!(
4848
concat!("snapshots/analysis__", stringify!($name), ".snap"),
49-
build_snapshot($path, &src, module, &db)
49+
build_snapshot(files, module, &db)
5050
);
5151
} else {
52-
assert_snapshot!(build_snapshot($path, &src, module, &db));
52+
assert_snapshot!(build_snapshot(files, module, &db));
5353
}
5454
}
5555
};
@@ -162,10 +162,7 @@ test_analysis! { data_copying_stress, "stress/data_copying_stress.fe"}
162162
test_analysis! { tuple_stress, "stress/tuple_stress.fe"}
163163
test_analysis! { type_aliases, "features/type_aliases.fe"}
164164

165-
fn build_snapshot(path: &str, src: &str, module: items::ModuleId, db: &dyn AnalyzerDb) -> String {
166-
let mut file_store = FileStore::new();
167-
let id = file_store.add_file(path, src);
168-
165+
fn build_snapshot(file_store: FileStore, module: items::ModuleId, db: &dyn AnalyzerDb) -> String {
169166
// contract and struct types aren't worth printing
170167
let type_aliases = module
171168
.all_items(db)
@@ -286,7 +283,7 @@ fn build_snapshot(path: &str, src: &str, module: items::ModuleId, db: &dyn Analy
286283
]
287284
.concat();
288285

289-
diagnostics_string(&diagnostics, id, &file_store)
286+
diagnostics_string(&diagnostics, &file_store)
290287
}
291288

292289
fn lookup_spans<T: Clone>(

crates/analyzer/tests/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ fn error_string(path: &str, src: &str) -> String {
1010
let mut files = FileStore::new();
1111
let id = files.add_file(path, src);
1212

13-
let fe_module = match fe_parser::parse_file(src) {
13+
let fe_module = match fe_parser::parse_file(id, src) {
1414
Ok((module, _)) => module,
1515
Err(diags) => {
16-
print_diagnostics(&diags, id, &files);
16+
print_diagnostics(&diags, &files);
1717
panic!("parsing failed");
1818
}
1919
};
2020

2121
let db = Db::default();
2222
match fe_analyzer::analyze(&db, fe_module) {
2323
Ok(_) => panic!("expected analysis to fail with an error"),
24-
Err(diags) => diagnostics_string(&diags, id, &files),
24+
Err(diags) => diagnostics_string(&diags, &files),
2525
}
2626
}
2727

crates/analyzer/tests/snapshots/analysis__call_statement_with_args.snap

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/analyzer/tests/analysis.rs
3-
expression: "build_snapshot(\"features/call_statement_with_args.fe\", &src, module, &db)"
3+
expression: "build_snapshot(files, module, &db)"
44

55
---
66
note:
@@ -115,14 +115,11 @@ note:
115115
┌─ features/call_statement_with_args.fe:8:9
116116
117117
8self.assign(100)
118-
^^^^^^^^^^^ attributes hash: 8420354620523897173
118+
^^^^^^^^^^^ attributes hash: 8522453005002335674
119119
120120
= SelfAttribute {
121121
func_name: "assign",
122-
self_span: Span {
123-
start: 137,
124-
end: 141,
125-
},
122+
self_span: 137..141,
126123
}
127124

128125

crates/analyzer/tests/snapshots/analysis__call_statement_with_args_2.snap

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/analyzer/tests/analysis.rs
3-
expression: "build_snapshot(\"features/call_statement_with_args_2.fe\", &src, module, &db)"
3+
expression: "build_snapshot(files, module, &db)"
44

55
---
66
note:
@@ -124,14 +124,11 @@ note:
124124
┌─ features/call_statement_with_args_2.fe:9:9
125125
126126
9self.assign(100)
127-
^^^^^^^^^^^ attributes hash: 511266823031776296
127+
^^^^^^^^^^^ attributes hash: 2997557065728909304
128128
129129
= SelfAttribute {
130130
func_name: "assign",
131-
self_span: Span {
132-
start: 164,
133-
end: 168,
134-
},
131+
self_span: 164..168,
135132
}
136133

137134

crates/analyzer/tests/snapshots/analysis__call_statement_without_args.snap

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/analyzer/tests/analysis.rs
3-
expression: "build_snapshot(\"features/call_statement_without_args.fe\", &src, module, &db)"
3+
expression: "build_snapshot(files, module, &db)"
44

55
---
66
note:
@@ -98,14 +98,11 @@ note:
9898
┌─ features/call_statement_without_args.fe:8:9
9999
100100
8self.assign()
101-
^^^^^^^^^^^ attributes hash: 17318279018058750260
101+
^^^^^^^^^^^ attributes hash: 1845414425399096131
102102
103103
= SelfAttribute {
104104
func_name: "assign",
105-
self_span: Span {
106-
start: 126,
107-
end: 130,
108-
},
105+
self_span: 126..130,
109106
}
110107

111108

crates/analyzer/tests/snapshots/analysis__erc20_token.snap

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/analyzer/tests/analysis.rs
3-
expression: "build_snapshot(\"demos/erc20_token.fe\", &src, module, &db)"
3+
expression: "build_snapshot(files, module, &db)"
44

55
---
66
note:
@@ -1949,14 +1949,11 @@ note:
19491949
┌─ demos/erc20_token.fe:23:9
19501950
19511951
23self._mint(msg.sender, 1000000000000000000000000)
1952-
^^^^^^^^^^ attributes hash: 16096825613720258282
1952+
^^^^^^^^^^ attributes hash: 3032414134331615192
19531953
19541954
= SelfAttribute {
19551955
func_name: "_mint",
1956-
self_span: Span {
1957-
start: 542,
1958-
end: 546,
1959-
},
1956+
self_span: 542..546,
19601957
}
19611958

19621959
note:
@@ -1979,84 +1976,66 @@ note:
19791976
┌─ demos/erc20_token.fe:41:9
19801977
19811978
41self._transfer(msg.sender, recipient, value)
1982-
^^^^^^^^^^^^^^ attributes hash: 11998329377771437848
1979+
^^^^^^^^^^^^^^ attributes hash: 15399895119751945816
19831980
19841981
= SelfAttribute {
19851982
func_name: "_transfer",
1986-
self_span: Span {
1987-
start: 1052,
1988-
end: 1056,
1989-
},
1983+
self_span: 1052..1056,
19901984
}
19911985

19921986
note:
19931987
┌─ demos/erc20_token.fe:48:9
19941988
19951989
48self._approve(msg.sender, spender, value)
1996-
^^^^^^^^^^^^^ attributes hash: 47467343444821621
1990+
^^^^^^^^^^^^^ attributes hash: 10047856837296232623
19971991
19981992
= SelfAttribute {
19991993
func_name: "_approve",
2000-
self_span: Span {
2001-
start: 1310,
2002-
end: 1314,
2003-
},
1994+
self_span: 1310..1314,
20041995
}
20051996

20061997
note:
20071998
┌─ demos/erc20_token.fe:53:9
20081999
20092000
53self._transfer(sender, recipient, value)
2010-
^^^^^^^^^^^^^^ attributes hash: 14187559596189701922
2001+
^^^^^^^^^^^^^^ attributes hash: 13311941709994158162
20112002
20122003
= SelfAttribute {
20132004
func_name: "_transfer",
2014-
self_span: Span {
2015-
start: 1531,
2016-
end: 1535,
2017-
},
2005+
self_span: 1531..1535,
20182006
}
20192007

20202008
note:
20212009
┌─ demos/erc20_token.fe:54:9
20222010
20232011
54self._approve(sender, msg.sender, self._allowances[sender][msg.sender] - value)
2024-
^^^^^^^^^^^^^ attributes hash: 337359114556530356
2012+
^^^^^^^^^^^^^ attributes hash: 5596759839039037729
20252013
20262014
= SelfAttribute {
20272015
func_name: "_approve",
2028-
self_span: Span {
2029-
start: 1580,
2030-
end: 1584,
2031-
},
2016+
self_span: 1580..1584,
20322017
}
20332018

20342019
note:
20352020
┌─ demos/erc20_token.fe:58:9
20362021
20372022
58self._approve(msg.sender, spender, self._allowances[msg.sender][spender] + addedValue)
2038-
^^^^^^^^^^^^^ attributes hash: 10097494349759349093
2023+
^^^^^^^^^^^^^ attributes hash: 10420458525874606876
20392024
20402025
= SelfAttribute {
20412026
func_name: "_approve",
2042-
self_span: Span {
2043-
start: 1769,
2044-
end: 1773,
2045-
},
2027+
self_span: 1769..1773,
20462028
}
20472029

20482030
note:
20492031
┌─ demos/erc20_token.fe:62:9
20502032
20512033
62self._approve(msg.sender, spender, self._allowances[msg.sender][spender] - subtractedValue)
2052-
^^^^^^^^^^^^^ attributes hash: 9207024764946008481
2034+
^^^^^^^^^^^^^ attributes hash: 1575892034280724253
20532035
20542036
= SelfAttribute {
20552037
func_name: "_approve",
2056-
self_span: Span {
2057-
start: 1970,
2058-
end: 1974,
2059-
},
2038+
self_span: 1970..1974,
20602039
}
20612040

20622041
note:

crates/analyzer/tests/snapshots/analysis__pure_fn_standalone.snap

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
source: crates/analyzer/tests/analysis.rs
3-
expression: "build_snapshot(\"features/pure_fn_standalone.fe\", &src, module, &db)"
3+
expression: "build_snapshot(files, module, &db)"
44

55
---
66
note:
@@ -284,28 +284,22 @@ note:
284284
┌─ features/pure_fn_standalone.fe:17:9
285285
286286
17self.add_points(a, 100)
287-
^^^^^^^^^^^^^^^ attributes hash: 8626870049799486243
287+
^^^^^^^^^^^^^^^ attributes hash: 5094765954567266946
288288
289289
= SelfAttribute {
290290
func_name: "add_points",
291-
self_span: Span {
292-
start: 400,
293-
end: 404,
294-
},
291+
self_span: 400..404,
295292
}
296293

297294
note:
298295
┌─ features/pure_fn_standalone.fe:19:9
299296
300297
19self.add_points(a, 100)
301-
^^^^^^^^^^^^^^^ attributes hash: 13248801714086080881
298+
^^^^^^^^^^^^^^^ attributes hash: 5317772279976617936
302299
303300
= SelfAttribute {
304301
func_name: "add_points",
305-
self_span: Span {
306-
start: 466,
307-
end: 470,
308-
},
302+
self_span: 466..470,
309303
}
310304

311305

0 commit comments

Comments
 (0)