Skip to content

Commit

Permalink
runtime: Switch display_fct from VM to Program
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Oct 24, 2024
1 parent 322875f commit 41b3728
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 75 deletions.
44 changes: 44 additions & 0 deletions dora-bytecode/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,47 @@ pub struct Program {
pub boots_package_id: Option<PackageId>,
pub main_fct_id: Option<FunctionId>,
}

impl Program {
pub fn fct(&self, id: FunctionId) -> &FunctionData {
&self.functions[id.0 as usize]
}

pub fn trait_(&self, id: TraitId) -> &TraitData {
&self.traits[id.0 as usize]
}

pub fn extension(&self, id: ExtensionId) -> &ExtensionData {
&self.extensions[id.0 as usize]
}

pub fn alias(&self, id: AliasId) -> &AliasData {
&self.aliases[id.0 as usize]
}

pub fn struct_(&self, id: StructId) -> &StructData {
&self.structs[id.0 as usize]
}

pub fn class(&self, id: ClassId) -> &ClassData {
&self.classes[id.0 as usize]
}

pub fn enum_(&self, id: EnumId) -> &EnumData {
&self.enums[id.0 as usize]
}

pub fn impl_(&self, id: ImplId) -> &ImplData {
&self.impls[id.0 as usize]
}

pub fn module(&self, id: ModuleId) -> &ModuleData {
&self.modules[id.0 as usize]
}

pub fn program_module_id(&self) -> ModuleId {
let pkg_id = self.program_package_id.0 as usize;
let pkg = &self.packages[pkg_id];
pkg.root_module_id
}
}
2 changes: 1 addition & 1 deletion dora-runtime/src/boots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ extern "C" fn get_intrinsic_for_function_raw(id: u32) -> i32 {
extern "C" fn get_function_display_name_raw(id: FunctionId) -> Ref<UInt8Array> {
let vm = get_vm();

let name = display_fct(vm, id);
let name = display_fct(&vm.program, id);

Str::from_buffer(vm, name.as_bytes()).cast()
}
Expand Down
55 changes: 39 additions & 16 deletions dora-runtime/src/cannon/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4094,7 +4094,7 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
_ => unreachable!(),
};

let tuple_name = display_ty(self.vm, tuple_ty);
let tuple_name = display_ty(&self.vm.program, tuple_ty);
format!(
"LoadTupleElement {}, {}, ConstPoolIdx({}) # {}.{}",
dest, src, idx.0, tuple_name, subtype_idx,
Expand All @@ -4113,7 +4113,10 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
_ => unreachable!(),
};
let enum_ = self.vm.enum_(enum_id);
let enum_name = display_ty(self.vm, &BytecodeType::Enum(enum_id, type_params.clone()));
let enum_name = display_ty(
&self.vm.program,
&BytecodeType::Enum(enum_id, type_params.clone()),
);
let variant = &enum_.variants[variant_idx as usize];
format!(
"LoadEnumElement {}, {}, ConstPoolIdx({}), {} # {}::{}.{}",
Expand All @@ -4129,7 +4132,10 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
ConstPoolEntry::Enum(enum_id, type_params) => (*enum_id, type_params),
_ => unreachable!(),
};
let enum_name = display_ty(self.vm, &BytecodeType::Enum(enum_id, type_params.clone()));
let enum_name = display_ty(
&self.vm.program,
&BytecodeType::Enum(enum_id, type_params.clone()),
);
format!(
"LoadEnumVariant {}, {}, ConstPoolIdx({}) # {}",
dest, src, idx.0, enum_name,
Expand All @@ -4148,7 +4154,7 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
};
let struct_ = self.vm.struct_(struct_id);
let struct_name = display_ty(
self.vm,
&self.vm.program,
&BytecodeType::Struct(struct_id, type_params.clone()),
);

Expand All @@ -4166,8 +4172,10 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
comment!(self, {
match self.bytecode.const_pool(field_idx) {
ConstPoolEntry::Field(cls_id, type_params, field_id) => {
let cname =
display_ty(self.vm, &BytecodeType::Class(*cls_id, type_params.clone()));
let cname = display_ty(
&self.vm.program,
&BytecodeType::Class(*cls_id, type_params.clone()),
);

let cls = self.vm.class(*cls_id);
let field = &cls.fields[*field_id as usize];
Expand All @@ -4191,7 +4199,10 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
}
_ => unreachable!(),
};
let cname = display_ty(self.vm, &BytecodeType::Class(cls_id, type_params.clone()));
let cname = display_ty(
&self.vm.program,
&BytecodeType::Class(cls_id, type_params.clone()),
);

let cls = self.vm.class(cls_id);
let field = &cls.fields[field_id as usize];
Expand Down Expand Up @@ -4452,7 +4463,10 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
ConstPoolEntry::Class(cls_id, type_params) => (*cls_id, type_params),
_ => unreachable!(),
};
let cname = display_ty(self.vm, &BytecodeType::Class(cls_id, type_params.clone()));
let cname = display_ty(
&self.vm.program,
&BytecodeType::Class(cls_id, type_params.clone()),
);
format!("NewObject {}, ConstPoolIdx({}) # {}", dest, idx.0, cname)
});
self.emit_new_object(dest, idx)
Expand All @@ -4464,7 +4478,10 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
ConstPoolEntry::Class(cls_id, type_params) => (*cls_id, type_params),
_ => unreachable!(),
};
let cname = display_ty(self.vm, &BytecodeType::Class(cls_id, type_params.clone()));
let cname = display_ty(
&self.vm.program,
&BytecodeType::Class(cls_id, type_params.clone()),
);
format!(
"NewObjectInitialized {}, ConstPoolIdx({}) # {}",
dest, idx.0, cname
Expand All @@ -4479,7 +4496,10 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
ConstPoolEntry::Class(cls_id, type_params) => (*cls_id, type_params),
_ => unreachable!(),
};
let cname = display_ty(self.vm, &BytecodeType::Class(cls_id, type_params.clone()));
let cname = display_ty(
&self.vm.program,
&BytecodeType::Class(cls_id, type_params.clone()),
);
format!(
"NewArray {}, ConstPoolIdx({}), {} # {}",
dest, idx.0, length, cname
Expand All @@ -4494,7 +4514,7 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
ConstPoolEntry::Tuple(ref subtypes) => subtypes,
_ => unreachable!(),
};
let tuple_name = display_ty(self.vm, &BytecodeType::Tuple(subtypes.clone()));
let tuple_name = display_ty(&self.vm.program, &BytecodeType::Tuple(subtypes.clone()));
format!(
"NewTuple {}, ConstPoolIdx({}) # {}",
dest, idx.0, tuple_name,
Expand All @@ -4512,7 +4532,10 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
_ => unreachable!(),
};
let enum_ = self.vm.enum_(enum_id);
let enum_name = display_ty(self.vm, &BytecodeType::Enum(enum_id, type_params.clone()));
let enum_name = display_ty(
&self.vm.program,
&BytecodeType::Enum(enum_id, type_params.clone()),
);
let variant = &enum_.variants[variant_idx as usize];
format!(
"NewEnum {}, ConstPoolIdx({}) # {}::{}",
Expand All @@ -4529,7 +4552,7 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
_ => unreachable!(),
};
let struct_name = display_ty(
self.vm,
&self.vm.program,
&BytecodeType::Struct(struct_id, type_params.clone()),
);
format!(
Expand All @@ -4549,8 +4572,8 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
} => (trait_ty, actual_object_ty),
_ => unreachable!(),
};
let trait_name = display_ty(self.vm, trait_ty);
let object_name = display_ty(self.vm, actual_object_ty);
let trait_name = display_ty(&self.vm.program, trait_ty);
let object_name = display_ty(&self.vm.program, actual_object_ty);
format!(
"NewTraitObject {}, ConstPoolIdx({}), {} # {} from object {}",
dest, idx.0, src, trait_name, object_name,
Expand All @@ -4565,7 +4588,7 @@ impl<'a> BytecodeVisitor for CannonCodeGen<'a> {
ConstPoolEntry::Fct(fct_id, type_params) => (*fct_id, type_params),
_ => unreachable!(),
};
let fct_name = display_fct(self.vm, fct_id);
let fct_name = display_fct(&self.vm.program, fct_id);
format!("NewLambda {}, ConstPoolIdx({}) # {}", dest, idx.0, fct_name,)
});
self.emit_new_lambda(dest, idx);
Expand Down
2 changes: 1 addition & 1 deletion dora-runtime/src/compiler/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn assert_builds_identical(
stage2_code.instruction_slice(),
stage3_code.instruction_slice(),
"stage2 and stage3 differ in function {}",
display_fct(vm, stage2_code.fct_id())
display_fct(&vm.program, stage2_code.fct_id())
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions dora-runtime/src/compiler/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub(super) fn compile_fct_to_code(
}

if vm.flags.enable_perf {
let name = display_fct(vm, fct_id);
let name = display_fct(&vm.program, fct_id);
os::perf::register_with_perf(&code, &name);
}

Expand All @@ -155,7 +155,7 @@ fn compile_fct_to_descriptor(
let emit_bytecode = should_emit_bytecode(vm, fct_id, compiler.to_compiler());

if emit_bytecode {
println!("Bytecode for {}:", display_fct(vm, fct_id));
println!("Bytecode for {}:", display_fct(&vm.program, fct_id));
dump_stdout(&vm.program, &bytecode_fct);
}

Expand Down Expand Up @@ -196,7 +196,7 @@ fn compile_fct_to_descriptor(

if emit_compiler {
let duration = start.expect("missing start time").elapsed();
let mut name = display_fct(vm, fct_id);
let mut name = display_fct(&vm.program, fct_id);
if type_params.len() > 0 {
name.push_str(" with [");
let mut first = true;
Expand All @@ -206,7 +206,7 @@ fn compile_fct_to_descriptor(
name.push_str(", ");
}

name.push_str(&display_ty_without_type_params(vm, &ty));
name.push_str(&display_ty_without_type_params(&vm.program, &ty));
first = false;
}

Expand Down Expand Up @@ -301,7 +301,7 @@ fn fct_pattern_match(vm: &VM, fct_id: FunctionId, pattern: &str) -> (bool, bool)
return (true, true);
}

let fct_name = display_fct(vm, fct_id);
let fct_name = display_fct(&vm.program, fct_id);

for part in pattern.split(';') {
let (part, plus) = if part.ends_with('+') {
Expand Down
4 changes: 2 additions & 2 deletions dora-runtime/src/disassembler/capstone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ pub fn disassemble(vm: &VM, fct_id: FunctionId, type_params: &BytecodeTypeArray,
.disasm_all(buf, start_addr)
.expect("could not disassemble code");

let name = display_fct(vm, fct_id);
let name = display_fct(&vm.program, fct_id);

let type_params = if !type_params.is_empty() {
let mut ty_names = Vec::new();

for ty in type_params.iter() {
ty_names.push(display_ty(vm, &ty));
ty_names.push(display_ty(&vm.program, &ty));
}

format!(" [{}]", ty_names.join(", "))
Expand Down
6 changes: 3 additions & 3 deletions dora-runtime/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl NativeStacktrace {
let inlined_function =
code.inlined_function(inlined_location.inlined_function_id());
let fct = vm.fct(inlined_function.fct_id);
let fct_name = display_fct(vm, inlined_function.fct_id);
let fct_name = display_fct(&vm.program, inlined_function.fct_id);
let file = &vm.file(fct.file_id).path;
writeln!(
w,
Expand All @@ -53,7 +53,7 @@ impl NativeStacktrace {
};

let file = &vm.file(fct.file_id).path;
let fct_name = display_fct(vm, fct_id);
let fct_name = display_fct(&vm.program, fct_id);
writeln!(w, " {} ({}:{})", fct_name, file, location)?;
}

Expand Down Expand Up @@ -208,7 +208,7 @@ pub extern "C" fn symbolize_stack_trace_element(mut obj: Handle<StacktraceIterat

let fct = vm.fct(fct_id);
let file = &vm.file(fct.file_id).path;
let fct_name = display_fct(vm, fct_id);
let fct_name = display_fct(&vm.program, fct_id);

let text = format!("{} ({}:{})", fct_name, file, location);
obj.text = Str::from_buffer(vm, text.as_bytes());
Expand Down
4 changes: 1 addition & 3 deletions dora-runtime/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,7 @@ impl VM {
}

pub fn program_module_id(&self) -> ModuleId {
let pkg_id = self.program.program_package_id.0 as usize;
let pkg = &self.program.packages[pkg_id];
pkg.root_module_id
self.program.program_module_id()
}

pub fn byte_array(&self) -> ClassInstanceId {
Expand Down
6 changes: 3 additions & 3 deletions dora-runtime/src/vm/code_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ impl CodeMap {

match code.descriptor() {
CodeKind::BaselineFct(fct_id) => {
println!("dora {}", display_fct(vm, fct_id));
println!("dora {}", display_fct(&vm.program, fct_id));
}
CodeKind::OptimizedFct(fct_id) => {
println!("dora(opt) {}", display_fct(vm, fct_id));
println!("dora(opt) {}", display_fct(&vm.program, fct_id));
}
CodeKind::LazyCompilationStub => println!("compile_stub"),
CodeKind::TrapTrampoline => println!("trap_stub"),
CodeKind::AllocationFailureTrampoline => println!("alloc_stub"),
CodeKind::RuntimeEntryTrampoline(fct_id) => {
println!("native stub {}", display_fct(vm, fct_id));
println!("native stub {}", display_fct(&vm.program, fct_id));
}
CodeKind::DoraEntryTrampoline => println!("dora_stub"),
CodeKind::StackOverflowTrampoline => println!("guard_check_stub"),
Expand Down
Loading

0 comments on commit 41b3728

Please sign in to comment.