Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime_tracing"
version = "0.8.0"
version = "0.9.0"
edition = "2021"
authors = ["Metacraft Labs Ltd"]
description = "A library for the schema and tracing helpers for the CodeTracer db trace format"
Expand Down
17 changes: 16 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,24 @@ mod tests {
let rvalue_2 = tracer.compound_rvalue(&["variable2".to_string(), "variable3".to_string()]);
tracer.assign("variable1", rvalue_2, PassBy::Value);

// example for reference types
let reference_type = TypeRecord {
kind: TypeKind::Pointer,
lang_type: "MyReference<Int>".to_string(),
specific_info: TypeSpecificInfo::Pointer {
dereference_type_id: tracer.ensure_type_id(TypeKind::Int, "Int")
}
};
let reference_type_id = tracer.ensure_raw_type_id(reference_type);
let _reference_value = ValueRecord::Reference {
dereferenced: Box::new(int_value_1.clone()),
mutable: false,
type_id: reference_type_id,
};

tracer.drop_variables(&["variable1".to_string(), "variable2".to_string(), "variable3".to_string()]);

assert_eq!(tracer.events.len(), 46);
assert_eq!(tracer.events.len(), 47);
// visible with
// cargo tets -- --nocapture
// println!("{:#?}", tracer.events);
Expand Down
27 changes: 20 additions & 7 deletions src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,16 @@ impl Tracer {
}

pub fn ensure_type_id(&mut self, kind: TypeKind, lang_type: &str) -> TypeId {
if !self.types.contains_key(lang_type) {
self.types.insert(lang_type.to_string(), TypeId(self.types.len()));
self.register_type(kind, lang_type);
let typ = self.to_raw_type(kind, lang_type);
self.ensure_raw_type_id(typ)
}

pub fn ensure_raw_type_id(&mut self, typ: TypeRecord) -> TypeId {
if !self.types.contains_key(&typ.lang_type) {
self.types.insert(typ.lang_type.clone(), TypeId(self.types.len()));
self.register_raw_type(typ.clone());
}
*self.types.get(lang_type).unwrap()
*self.types.get(&typ.lang_type).unwrap()
}

pub fn ensure_variable_id(&mut self, variable_name: &str) -> VariableId {
Expand Down Expand Up @@ -157,12 +162,20 @@ impl Tracer {
}));
}

pub fn register_type(&mut self, kind: TypeKind, lang_type: &str) {
let typ = TypeRecord {
pub fn to_raw_type(&self, kind: TypeKind, lang_type: &str) -> TypeRecord {
TypeRecord {
kind,
lang_type: lang_type.to_string(),
specific_info: TypeSpecificInfo::None,
};
}
}

pub fn register_type(&mut self, kind: TypeKind, lang_type: &str) {
let typ = self.to_raw_type(kind, lang_type);
self.events.push(TraceLowLevelEvent::Type(typ));
}

pub fn register_raw_type(&mut self, typ: TypeRecord) {
self.events.push(TraceLowLevelEvent::Type(typ));
}

Expand Down
12 changes: 10 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub struct VariableRecord {
pub struct TypeRecord {
pub kind: TypeKind,
pub lang_type: String,
// for now only for Struct: TODO eventually
// for now only for Struct and Pointer: TODO eventually
// replace with an enum for TypeRecord, or with more cases
// in TypeSpecificInfo for collections, etc
pub specific_info: TypeSpecificInfo,
Expand All @@ -297,6 +297,7 @@ pub struct FieldTypeRecord {
pub enum TypeSpecificInfo {
None,
Struct { fields: Vec<FieldTypeRecord> },
Pointer { dereference_type_id: TypeId },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -340,8 +341,8 @@ pub enum ValueRecord {
},
Sequence {
elements: Vec<ValueRecord>,
type_id: TypeId,
is_slice: bool,
type_id: TypeId,
},
Tuple {
elements: Vec<ValueRecord>,
Expand All @@ -356,6 +357,13 @@ pub enum ValueRecord {
contents: Box<ValueRecord>, // usually a Struct or a Tuple
type_id: TypeId,
},
// TODO: eventually add more pointer-like variants
// or more fields (address?)
Reference {
dereferenced: Box<ValueRecord>,
mutable: bool,
type_id: TypeId,
},
Raw {
r: String,
type_id: TypeId,
Expand Down