Skip to content

Commit

Permalink
boots: Initial load elimination for class fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Oct 23, 2024
1 parent 33b6507 commit cafd8bb
Show file tree
Hide file tree
Showing 15 changed files with 371 additions and 52 deletions.
1 change: 1 addition & 0 deletions dora-bytecode/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub enum BytecodeTypeKind {
Lambda,
TypeAlias,
Assoc,
This,
}

#[derive(IntoPrimitive, TryFromPrimitive, Copy, Clone, PartialEq, Eq)]
Expand Down
1 change: 1 addition & 0 deletions dora-runtime/src/boots/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ pub fn decode_bytecode_type(reader: &mut ByteReader) -> BytecodeType {
BytecodeTypeKind::Float32 => BytecodeType::Float32,
BytecodeTypeKind::Float64 => BytecodeType::Float64,
BytecodeTypeKind::Ptr => BytecodeType::Ptr,
BytecodeTypeKind::This => BytecodeType::This,
BytecodeTypeKind::Class => {
let cls_id = reader.read_u32();
let type_params = decode_bytecode_type_array(reader);
Expand Down
4 changes: 3 additions & 1 deletion dora-runtime/src/boots/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ fn encode_bytecode_type(vm: &VM, ty: &BytecodeType, buffer: &mut ByteBuffer) {
BytecodeType::Ptr => {
buffer.emit_u8(BytecodeTypeKind::Ptr as u8);
}
BytecodeType::This => unreachable!(),
BytecodeType::This => {
buffer.emit_u8(BytecodeTypeKind::This as u8);
}
BytecodeType::Tuple(subtypes) => {
buffer.emit_u8(BytecodeTypeKind::Tuple as u8);
encode_bytecode_type_array(vm, subtypes, buffer);
Expand Down
18 changes: 12 additions & 6 deletions dora-runtime/src/compiler/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::compiler::{compile_fct_aot, trait_object_thunk, NativeFct, NativeFctK
use crate::gc::{formatted_size, Address};
use crate::os;
use crate::vm::{
ensure_class_instance_for_lambda, ensure_class_instance_for_trait_object, execute_on_main,
find_trait_impl, specialize_bty, specialize_bty_array, BytecodeTypeExt, ClassInstanceId, Code,
LazyCompilationSite, ShapeKind, VM,
display_fct, ensure_class_instance_for_lambda, ensure_class_instance_for_trait_object,
execute_on_main, find_trait_impl, specialize_bty, specialize_bty_array, BytecodeTypeExt,
ClassInstanceId, Code, LazyCompilationSite, ShapeKind, VM,
};

pub fn compile_boots_aot(vm: &VM) {
Expand All @@ -34,7 +34,7 @@ pub fn compile_boots_aot(vm: &VM) {
stage2_compiler(vm, &tc, entry_id, stage1_compiler_address);
let (stage3_compiler_address, stage3_ctc) =
stage3_compiler(vm, &tc, entry_id, stage2_compiler_address);
assert_builds_identical(&stage2_ctc, &stage3_ctc);
assert_builds_identical(vm, &stage2_ctc, &stage3_ctc);

(stage3_compiler_address, stage3_ctc)
})
Expand Down Expand Up @@ -119,13 +119,19 @@ fn compiler_stage_n(
(compile_address, ctc)
}

fn assert_builds_identical(stage2: &CompiledTransitiveClosure, stage3: &CompiledTransitiveClosure) {
fn assert_builds_identical(
vm: &VM,
stage2: &CompiledTransitiveClosure,
stage3: &CompiledTransitiveClosure,
) {
assert_eq!(stage2.code_objects.len(), stage3.code_objects.len());

for (stage2_code, stage3_code) in stage2.code_objects.iter().zip(&stage3.code_objects) {
assert_eq!(
stage2_code.instruction_slice(),
stage3_code.instruction_slice()
stage3_code.instruction_slice(),
"stage2 and stage3 differ in function {}",
display_fct(vm, stage2_code.fct_id())
);
}
}
Expand Down
164 changes: 158 additions & 6 deletions pkgs/boots/bytecode/data.dora
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::Equals;
use std::Hash;

use package::bytecode::{AliasId, ClassId, ClassFieldId, EnumId, FunctionId, StructId, StructFieldId, TraitId};
use package::bytecode::opcode as opc;
use package::graph::Block;

pub class BytecodeFunction {
Expand Down Expand Up @@ -180,12 +181,6 @@ impl Stringable for BytecodeRegister {

pub struct ConstPoolId(pub value: Int32)

impl ConstPoolId {
fn equals(rhs: ConstPoolId): Bool {
self.value == rhs.value
}
}

pub enum BytecodeType {
Unit,
Ptr,
Expand Down Expand Up @@ -313,6 +308,163 @@ impl BytecodeType {
}
}

impl Equals for BytecodeType {
fn equals(other: BytecodeType): Bool {
match self {
BytecodeType::Unit => {
match other {
BytecodeType::Unit => true,
_ => false,
}
}

BytecodeType::Ptr => {
match other {
BytecodeType::Ptr => true,
_ => false,
}
}

BytecodeType::UInt8 => {
match other {
BytecodeType::UInt8 => true,
_ => false,
}
}

BytecodeType::Bool => {
match other {
BytecodeType::Bool => true,
_ => false,
}
}

BytecodeType::Char => {
match other {
BytecodeType::Char => true,
_ => false,
}
}

BytecodeType::Int32 => {
match other {
BytecodeType::Int32 => true,
_ => false,
}
}

BytecodeType::Int64 => {
match other {
BytecodeType::Int64 => true,
_ => false,
}
}

BytecodeType::Float32 => {
match other {
BytecodeType::Float32 => true,
_ => false,
}
}

BytecodeType::Float64 => {
match other {
BytecodeType::Float64 => true,
_ => false,
}
}

BytecodeType::This => {
match other {
BytecodeType::This => true,
_ => false,
}
}

BytecodeType::Struct(id, type_params) => {
match other {
BytecodeType::Struct(other_id, other_type_params) => id == other_id && type_params == other_type_params,
_ => false,
}
}

BytecodeType::Enum(id, type_params) => {
match other {
BytecodeType::Enum(other_id, other_type_params) => id == other_id && type_params == other_type_params,
_ => false,
}
}

BytecodeType::Class(id, type_params) => {
match other {
BytecodeType::Class(other_id, other_type_params) => id == other_id && type_params == other_type_params,
_ => false,
}
}

BytecodeType::Trait(id, type_params) => {
match other {
BytecodeType::Trait(other_id, other_type_params) => id == other_id && type_params == other_type_params,
_ => false,
}
}

BytecodeType::Tuple(subtypes) => {
match other {
BytecodeType::Tuple(other_subtypes) => subtypes == other_subtypes,
_ => false,
}
}

BytecodeType::TypeParam(id) => {
match other {
BytecodeType::TypeParam(other_id) => id == other_id,
_ => false,
}
}

BytecodeType::Lambda(params, ret) => {
match other {
BytecodeType::Lambda(other_params, other_ret) => params == other_params && ret == other_ret,
_ => false,
}
}

BytecodeType::TypeAlias(id) => {
match other {
BytecodeType::TypeAlias(other_id) => id == other_id,
_ => false,
}
}
}
}
}

impl Hash for BytecodeType {
fn hash(): Int32 {
match self {
BytecodeType::Unit => opc::BC_TYPE_UNIT,
BytecodeType::Ptr => opc::BC_TYPE_PTR,
BytecodeType::UInt8 => opc::BC_TYPE_U_INT8,
BytecodeType::Bool => opc::BC_TYPE_BOOL,
BytecodeType::Char => opc::BC_TYPE_CHAR,
BytecodeType::Int32 => opc::BC_TYPE_INT32,
BytecodeType::Int64 => opc::BC_TYPE_INT64,
BytecodeType::Float32 => opc::BC_TYPE_FLOAT32,
BytecodeType::Float64 => opc::BC_TYPE_FLOAT64,
BytecodeType::This => opc::BC_TYPE_THIS,
BytecodeType::Struct(id, type_params) => opc::BC_TYPE_STRUCT ^ id.hash() ^ type_params.hash(),
BytecodeType::Enum(id, type_params) => opc::BC_TYPE_ENUM ^ id.hash() ^ type_params.hash(),
BytecodeType::Class(id, type_params) => opc::BC_TYPE_CLASS ^ id.hash() ^ type_params.hash(),
BytecodeType::Trait(id, type_params) => opc::BC_TYPE_TRAIT_OBJECT ^ id.hash() ^ type_params.hash(),
BytecodeType::Tuple(subtypes) => opc::BC_TYPE_TUPLE ^ subtypes.hash(),
BytecodeType::TypeParam(id) => opc::BC_TYPE_TYPE_PARAM ^ id,
BytecodeType::Lambda(params, ret) => params.hash() ^ ret.hash(),
BytecodeType::TypeAlias(id) => opc::BC_TYPE_TYPE_ALIAS ^ id.hash(),
}
}
}

impl Stringable for BytecodeType {
fn toString(): String {
match self {
Expand Down
2 changes: 2 additions & 0 deletions pkgs/boots/bytecode/opcode.dora
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub const BC_TYPE_TRAIT_OBJECT: Int32 = 14;
pub const BC_TYPE_LAMBDA: Int32 = 15;
pub const BC_TYPE_TYPE_ALIAS: Int32 = 16;
pub const BC_TYPE_ASSOC: Int32 = 17;
pub const BC_TYPE_THIS: Int32 = 18;

pub const CONSTPOOL_OPCODE_STRING: Int32 = 0;
pub const CONSTPOOL_OPCODE_FLOAT32: Int32 = 1;
Expand Down Expand Up @@ -343,6 +344,7 @@ pub fn bytecodeTypeName(code: Int32): String {
if code == BC_TYPE_LAMBDA { return "Lambda"; }
if code == BC_TYPE_TYPE_ALIAS { return "TypeAlias"; }
if code == BC_TYPE_ASSOC { return "Assoc"; }
if code == BC_TYPE_THIS { return "This"; }
unreachable[String]()
}

Expand Down
61 changes: 61 additions & 0 deletions pkgs/boots/bytecode/program.dora
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::{Equals, Hash};
use package::bytecode::{BytecodeType, Location};

pub struct PackageId(pub value: Int32)
Expand Down Expand Up @@ -66,6 +67,18 @@ pub class GlobalData {

pub struct ClassId(pub value: Int32)

impl Equals for ClassId {
fn equals(other: ClassId): Bool {
self.value == other.value
}
}

impl Hash for ClassId {
fn hash(): Int32 {
self.value
}
}

pub class ClassData {
module_id: ModuleId,
name: String,
Expand All @@ -82,6 +95,18 @@ pub class ClassField {

pub struct StructId(pub value: Int32)

impl Equals for StructId {
fn equals(other: StructId): Bool {
self.value == other.value
}
}

impl Hash for StructId {
fn hash(): Int32 {
self.value
}
}

pub class StructData {
module_id: ModuleId,
name: String,
Expand All @@ -98,6 +123,18 @@ pub class StructField {

pub struct EnumId(pub value: Int32)

impl Equals for EnumId {
fn equals(other: EnumId): Bool {
self.value == other.value
}
}

impl Hash for EnumId {
fn hash(): Int32 {
self.value
}
}

pub class EnumData {
module_id: ModuleId,
name: String,
Expand All @@ -112,6 +149,18 @@ pub class EnumVariant {

pub struct TraitId(pub value: Int32)

impl Equals for TraitId {
fn equals(other: TraitId): Bool {
self.value == other.value
}
}

impl Hash for TraitId {
fn hash(): Int32 {
self.value
}
}

pub class TraitData {
module_id: ModuleId,
name: String,
Expand Down Expand Up @@ -148,6 +197,18 @@ pub class ImplData {

pub struct AliasId(pub value: Int32)

impl Equals for AliasId {
fn equals(other: AliasId): Bool {
self.value == other.value
}
}

impl Hash for AliasId {
fn hash(): Int32 {
self.value
}
}

pub class AliasData {
name: String,
ty: Option[BytecodeType],
Expand Down
2 changes: 1 addition & 1 deletion pkgs/boots/codegen/x64.dora
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use package::assembler::{FloatRegister, Label, Register, RegSet};
use package::bytecode::data::ConstPoolId;
use package::codegen::{CODE_SIZE_ALIGNMENT, STACK_FRAME_ALIGNMENT, CodeGen, computeOffsetsInLiveSet, getLiveValuesWithoutCurrentInst, getRegisterSnapshotWithout};
use package::compilation::CompilationInfo;
use package::interface::{Address, Architecture, ConstPool, ConstPoolEntry, ConstPoolValue, config, LazyCompilationSite, LazyCompilationSiteDirect, getFieldOffset, getClassSize, getClassPointer, getFunctionVtableIndex, getGlobalValueAddress, getGlobalStateAddress, getGlobalInitializerFunctionId, InlinedFunction, InlinedFunctionId, InlinedLocation};
use package::interface::{Address, Architecture, ConstPool, ConstPoolEntry, ConstPoolValue, config, LazyCompilationSite, LazyCompilationSiteDirect, getClassSize, getClassPointer, getFunctionVtableIndex, getGlobalValueAddress, getGlobalStateAddress, getGlobalInitializerFunctionId, InlinedFunction, InlinedFunctionId, InlinedLocation};
use package::interface::{LAMBDA_SIZE, PTR_SIZE, GLOBAL_STATE_INITIALIZED};
use package::interface::{THREAD_LOCAL_DATA_TLAB_TOP_OFFSET, THREAD_LOCAL_DATA_TLAB_END_OFFSET, THREAD_LOCAL_DATA_STACK_LIMIT_OFFSET, THREAD_LOCAL_DATA_STATE_OFFSET, THREAD_LOCAL_DATA_MARKING_OFFSET, OBJECT_HEADER_LENGTH, OBJECT_METADATA_OFFSET, METADATA_REMEMBERED_BIT, ARRAY_HEADER_LENGTH, THREAD_LOCAL_DATA_MANAGED_THREAD_HANDLE_OFFSET};
use package::interface as iface;
Expand Down
Loading

0 comments on commit cafd8bb

Please sign in to comment.