Skip to content

Commit e2fff44

Browse files
committed
feat: add DropVariable event, rename some variable-related api-s
rename the Variable event to VariableName; register_variable_event to register_variable_name register_variable_cell to register_variable this makes it possible to register variables at certain points and drop them at the end of scope/calls, like Stan imagined before it shouldn't contradict or stop the original mechanism from working: which should be able to register explicitly variables with full values wherever it's needed hopefully
1 parent 807368c commit e2fff44

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "runtime_tracing"
3-
version = "0.5.14-experimental-4"
3+
version = "0.5.14-experimental-5"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ mod tests {
7474
type_id,
7575
},
7676
);
77-
tracer.register_variable_cell("test_variable3", ValueId(1));
77+
tracer.register_variable("test_variable3", ValueId(1));
7878
tracer.assign_cell(ValueId(1), int_value_2.clone());
7979
tracer.register_cell_value(ValueId(2), int_value_2.clone());
8080
tracer.assign_compound_item(ValueId(0), 0, ValueId(2));
8181

8282
tracer.register_return(NONE_VALUE);
83+
tracer.drop_variable("test_variable3");
8384

84-
assert_eq!(tracer.events.len(), 31);
85+
assert_eq!(tracer.events.len(), 32);
8586
// visible with
8687
// cargo tets -- --nocapture
8788
// println!("{:#?}", tracer.events);

src/tracer.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Tracer {
9797
pub fn ensure_variable_id(&mut self, variable_name: &str) -> VariableId {
9898
if !self.variables.contains_key(variable_name) {
9999
self.variables.insert(variable_name.to_string(), VariableId(self.variables.len()));
100-
self.register_variable_event(variable_name);
100+
self.register_variable_name(variable_name);
101101
}
102102
*self.variables.get(variable_name).unwrap()
103103
}
@@ -170,8 +170,8 @@ impl Tracer {
170170
self.register_full_value(variable_id, value);
171171
}
172172

173-
pub fn register_variable_event(&mut self, variable_name: &str) {
174-
self.events.push(TraceLowLevelEvent::Variable(variable_name.to_string()));
173+
pub fn register_variable_name(&mut self, variable_name: &str) {
174+
self.events.push(TraceLowLevelEvent::VariableName(variable_name.to_string()));
175175
}
176176

177177
pub fn register_full_value(&mut self, variable_id: VariableId, value: ValueRecord) {
@@ -198,12 +198,17 @@ impl Tracer {
198198
self.events.push(TraceLowLevelEvent::AssignCell(AssignCellRecord { value_id, new_value }));
199199
}
200200

201-
pub fn register_variable_cell(&mut self, variable_name: &str, value_id: ValueId) {
201+
pub fn register_variable(&mut self, variable_name: &str, value_id: ValueId) {
202202
let variable_id = self.ensure_variable_id(variable_name);
203203
self.events
204204
.push(TraceLowLevelEvent::VariableCell(VariableCellRecord { variable_id, value_id }));
205205
}
206206

207+
pub fn drop_variable(&mut self, variable_name: &str) {
208+
let variable_id = self.ensure_variable_id(variable_name);
209+
self.events.push(TraceLowLevelEvent::DropVariable(variable_id));
210+
}
211+
207212
pub fn drop_last_step(&mut self) {
208213
self.events.push(TraceLowLevelEvent::DropLastStep);
209214
}

src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use serde_repr::*;
1010
pub enum TraceLowLevelEvent {
1111
Step(StepRecord),
1212
Path(PathBuf), // should be always generated before usage, so we can stop stream at random n
13-
Variable(String), // interning new name for it
13+
VariableName(String), // interning new name for it
1414
Type(TypeRecord), // should be always generated before Value referencing it
1515
Value(FullValueRecord), // full values: simpler case working even without modification support
1616
Function(FunctionRecord), // should be always generated before CallRecord referencing it
@@ -22,6 +22,7 @@ pub enum TraceLowLevelEvent {
2222
AssignCompoundItem(AssignCompoundItemRecord),
2323
AssignCell(AssignCellRecord),
2424
VariableCell(VariableCellRecord),
25+
DropVariable(VariableId),
2526
DropLastStep,
2627
}
2728

0 commit comments

Comments
 (0)