Skip to content

Commit d486758

Browse files
committed
doc(rengine): add more to ast.rs
1 parent 3b6fd0d commit d486758

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

rust-printer/src/ast/span.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
//! Source positions.
22
33
use hax_rust_engine_macros::*;
4-
use std::sync::atomic::{AtomicUsize, Ordering};
54

6-
static CURRENT_ID: AtomicUsize = AtomicUsize::new(0);
7-
8-
fn new_id() -> usize {
5+
/// Creates a fresh identifier for a span.
6+
fn fresh_id() -> usize {
7+
use std::sync::atomic::{AtomicUsize, Ordering};
8+
static CURRENT_ID: AtomicUsize = AtomicUsize::new(0);
99
CURRENT_ID.fetch_add(1, Ordering::Relaxed)
1010
}
1111

12-
/// Id for the origin item of a span
12+
/// Identifier used to track the origin Rust item of a span
1313
#[derive_group_for_ast]
1414
pub struct OwnerId(usize);
1515

16-
/// Position in the source code
16+
/// Position of a Rust source
1717
#[derive_group_for_ast]
1818
pub struct Span {
19+
/// A vector of spans as defined by the frontend.
20+
/// This is useful for supporting in a trivial way union of spans.
1921
data: Vec<hax_frontend_exporter::Span>,
22+
/// A unique identifier. Since we store spans almost for every node of the
23+
/// AST, having a unique identifier for spans gives us a fine-grained way of
24+
/// refering to sub-nodes in debugging context. This id is indeed mostly
25+
/// used by the web debugger.
2026
id: usize,
27+
/// A reference to the item in which this span lives. This information is
28+
/// used for debugging and profiling purposes, e.g. for `cargo hax into
29+
/// --stats backend`.
2130
owner_hint: Option<OwnerId>,
2231
}
2332

2433
impl From<hax_frontend_exporter::Span> for Span {
2534
fn from(span: hax_frontend_exporter::Span) -> Self {
2635
Self {
2736
data: vec![span],
28-
id: new_id(),
37+
id: fresh_id(),
2938
owner_hint: None, // TODO: Have something there when we implement the importer
3039
}
3140
}

0 commit comments

Comments
 (0)