Refactor NodeIdentity to use unique IDs

The `NodeIdentity` struct has been refactored to use a unique `id` field
generated by an atomic counter. This ensures that each `NodeIdentity`
instance is distinct, even if it has the same `SourceLocation`. The
`location` field is now optional, allowing for anonymous nodes.

This change improves the reliability of identity comparisons and
provides a more robust way to manage AST node identities.
This commit is contained in:
Michael Schimmel
2026-02-25 13:43:57 +01:00
parent 7436edc9b5
commit 3ff7ba9d59
6 changed files with 56 additions and 37 deletions
+1 -3
View File
@@ -130,9 +130,7 @@ impl Binder {
};
binder.functions.push(FunctionCompiler::new(
ScopeKind::Root,
Rc::new(crate::ast::types::NodeIdentity {
location: crate::ast::types::SourceLocation { line: 0, col: 0 },
}),
crate::ast::types::NodeIdentity::new(crate::ast::types::SourceLocation { line: 0, col: 0 }),
));
binder
}
+2 -1
View File
@@ -101,9 +101,10 @@ impl Dumper {
if !captured_by.is_empty() {
for capturer in captured_by {
self.write_indent();
let loc = capturer.location.unwrap_or(crate::ast::types::SourceLocation { line: 0, col: 0 });
self.output.push_str(&format!(
"- Capturer: Lambda at line {}, col {}\n",
capturer.location.line, capturer.location.col
loc.line, loc.col
));
}
}
+1 -3
View File
@@ -717,9 +717,7 @@ mod tests {
Symbol::from("*"),
(
0,
Rc::new(crate::ast::types::NodeIdentity {
location: crate::ast::types::SourceLocation { line: 0, col: 0 },
}),
crate::ast::types::NodeIdentity::new(crate::ast::types::SourceLocation { line: 0, col: 0 }),
),
);
let globals = Rc::new(RefCell::new(global_names));