|
1 | 1 | //! Source positions.
|
2 | 2 |
|
3 | 3 | use hax_rust_engine_macros::*;
|
4 |
| -use std::sync::atomic::{AtomicUsize, Ordering}; |
5 | 4 |
|
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); |
9 | 9 | CURRENT_ID.fetch_add(1, Ordering::Relaxed)
|
10 | 10 | }
|
11 | 11 |
|
12 |
| -/// Id for the origin item of a span |
| 12 | +/// Identifier used to track the origin Rust item of a span |
13 | 13 | #[derive_group_for_ast]
|
14 | 14 | pub struct OwnerId(usize);
|
15 | 15 |
|
16 |
| -/// Position in the source code |
| 16 | +/// Position of a Rust source |
17 | 17 | #[derive_group_for_ast]
|
18 | 18 | 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. |
19 | 21 | 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. |
20 | 26 | 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`. |
21 | 30 | owner_hint: Option<OwnerId>,
|
22 | 31 | }
|
23 | 32 |
|
24 | 33 | impl From<hax_frontend_exporter::Span> for Span {
|
25 | 34 | fn from(span: hax_frontend_exporter::Span) -> Self {
|
26 | 35 | Self {
|
27 | 36 | data: vec![span],
|
28 |
| - id: new_id(), |
| 37 | + id: fresh_id(), |
29 | 38 | owner_hint: None, // TODO: Have something there when we implement the importer
|
30 | 39 | }
|
31 | 40 | }
|
|
0 commit comments