Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: memory mapping #117

Merged
merged 10 commits into from
Apr 19, 2020
2 changes: 1 addition & 1 deletion crates/mun_abi/c
Submodule c updated 1 files
+1 −1 include/mun_abi.h
4 changes: 2 additions & 2 deletions crates/mun_abi/src/autogen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::{Privacy, StructMemoryKind, TypeGroup};
#[doc = ""]
#[doc = " GUIDs are generated by taking the MD5 hash of a type's name."]
#[doc = ""]
#[doc = " <div rustbindgen derive=\"Clone\" derive=\"Copy\" derive=\"Debug\" derive=\"Eq\" derive=\"PartialEq\" derive=\"Ord\" derive=\"PartialOrd\"></div>"]
#[doc = " <div rustbindgen derive=\"Clone\" derive=\"Copy\" derive=\"Debug\" derive=\"Eq\" derive=\"PartialEq\" derive=\"Hash\" derive=\"Ord\" derive=\"PartialOrd\"></div>"]
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Guid {
#[doc = " 16-byte MD5 hash"]
pub b: [u8; 16usize],
Expand Down
6 changes: 6 additions & 0 deletions crates/mun_abi/src/autogen_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ impl PartialEq for TypeInfo {
}
}

impl std::hash::Hash for TypeInfo {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.guid.hash(state);
}
}

unsafe impl Send for TypeInfo {}
unsafe impl Sync for TypeInfo {}

Expand Down
11 changes: 11 additions & 0 deletions crates/mun_codegen/src/code_gen/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ impl Linker for Ld64Linker {
.to_str()
.ok_or_else(|| LinkerError::PathError(path.to_owned()))?;

let filename_str = path
.file_name()
.expect("path must have a filename")
.to_str()
.ok_or_else(|| LinkerError::PathError(path.to_owned()))?;

// Link as dynamic library
self.args.push("-dylib".to_owned());
self.args.push("-lsystem".to_owned());
Expand All @@ -119,6 +125,11 @@ impl Linker for Ld64Linker {
self.args.push("-o".to_owned());
self.args.push(path_str.to_owned());

// Ensure that the `install_name` is not a full path as it is used as a unique identifier on
// MacOS
self.args.push("-install_name".to_owned());
self.args.push(filename_str.to_owned());

Ok(())
}

Expand Down
13 changes: 5 additions & 8 deletions crates/mun_codegen/src/ir/ty.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::try_convert_any_to_basic;
use crate::{
type_info::TypeSize,
type_info::{TypeGroup, TypeInfo},
type_info::{TypeInfo, TypeSize},
CodeGenParams, IrDatabase,
};
use hir::{
Expand Down Expand Up @@ -105,30 +104,28 @@ pub fn type_info_query(db: &impl IrDatabase, ty: Ty) -> TypeInfo {
TypeCtor::Float(ty) => {
let ir_ty = float_ty_query(db, ty);
let type_size = TypeSize::from_ir_type(&ir_ty, target.as_ref());
TypeInfo::new(
TypeInfo::new_fundamental(
format!("core::{}", ty.resolve(&db.target_data_layout())),
TypeGroup::FundamentalTypes,
type_size,
)
}
TypeCtor::Int(ty) => {
let ir_ty = int_ty_query(db, ty);
let type_size = TypeSize::from_ir_type(&ir_ty, target.as_ref());
TypeInfo::new(
TypeInfo::new_fundamental(
format!("core::{}", ty.resolve(&db.target_data_layout())),
TypeGroup::FundamentalTypes,
type_size,
)
}
TypeCtor::Bool => {
let ir_ty = db.context().bool_type();
let type_size = TypeSize::from_ir_type(&ir_ty, target.as_ref());
TypeInfo::new("core::bool", TypeGroup::FundamentalTypes, type_size)
TypeInfo::new_fundamental("core::bool", type_size)
}
TypeCtor::Struct(s) => {
let ir_ty = db.struct_ty(s);
let type_size = TypeSize::from_ir_type(&ir_ty, target.as_ref());
TypeInfo::new(s.name(db).to_string(), TypeGroup::StructTypes(s), type_size)
TypeInfo::new_struct(db, s, type_size)
}
_ => unreachable!("{:?} unhandled", ctor),
},
Expand Down
14 changes: 7 additions & 7 deletions crates/mun_codegen/src/snapshots/test__field_crash.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ body:
%add = add i64 %c1, 5
%init = insertvalue %Foo undef, i64 %add, 0
%new_ptr = load i8* addrspace(4)* (i8 addrspace(4)*, i8*)*, i8* addrspace(4)* (i8 addrspace(4)*, i8*)** getelementptr inbounds (%DispatchTable, %DispatchTable* @dispatchTable, i32 0, i32 0)
%Foo_ptr = load %struct.MunTypeInfo addrspace(4)*, %struct.MunTypeInfo addrspace(4)** getelementptr inbounds ([5 x %struct.MunTypeInfo addrspace(4)*], [5 x %struct.MunTypeInfo addrspace(4)*]* @global_type_table, i32 0, i32 0)
%Foo_ptr = load %struct.MunTypeInfo addrspace(4)*, %struct.MunTypeInfo addrspace(4)** getelementptr inbounds ([5 x %struct.MunTypeInfo addrspace(4)*], [5 x %struct.MunTypeInfo addrspace(4)*]* @global_type_table, i32 0, i32 2)
%type_info_ptr_to_i8_ptr = bitcast %struct.MunTypeInfo addrspace(4)* %Foo_ptr to i8 addrspace(4)*
%allocator_handle = load i8*, i8** @allocatorHandle
%new = call i8* addrspace(4)* %new_ptr(i8 addrspace(4)* %type_info_ptr_to_i8_ptr, i8* %allocator_handle)
Expand All @@ -48,20 +48,20 @@ source_filename = "group_name"
%struct.MunStructInfo = type { i8 addrspace(4)* addrspace(4)*, %struct.MunTypeInfo addrspace(4)* addrspace(4)*, i16 addrspace(4)*, i16, i8 }

@dispatchTable = global %DispatchTable zeroinitializer
@"type_info::<*const TypeInfo>::name" = private unnamed_addr constant [16 x i8] c"*const TypeInfo\00"
@"type_info::<*const TypeInfo>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"=\A1-\1F\C2\A7\88`d\90\F4\B5\BEE}x", [16 x i8]* @"type_info::<*const TypeInfo>::name", i32 64, i8 8, i8 0 }
@"type_info::<core::i64>::name" = private unnamed_addr constant [10 x i8] c"core::i64\00"
@"type_info::<core::i64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::<core::i64>::name", i32 64, i8 8, i8 0 }
@"type_info::<Foo>::name" = private unnamed_addr constant [4 x i8] c"Foo\00"
@"struct_info::<Foo>::field_names" = private unnamed_addr constant [2 x i8] c"a\00"
@0 = private unnamed_addr constant [1 x i8 addrspace(4)*] [i8 addrspace(4)* @"struct_info::<Foo>::field_names"]
@"type_info::<core::i64>::name" = private unnamed_addr constant [10 x i8] c"core::i64\00"
@"type_info::<core::i64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::<core::i64>::name", i32 64, i8 8, i8 0 }
@"struct_info::<Foo>::field_types" = private unnamed_addr constant [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>"]
@"struct_info::<Foo>::field_offsets" = private unnamed_addr constant [1 x i16] zeroinitializer
@"type_info::<Foo>" = private unnamed_addr constant { %struct.MunTypeInfo, %struct.MunStructInfo } { %struct.MunTypeInfo { [16 x i8] c"\13V\C6}z\D1c\8D\81k\FB\82-\D2\C2]", [4 x i8]* @"type_info::<Foo>::name", i32 64, i8 8, i8 1 }, %struct.MunStructInfo { [1 x i8 addrspace(4)*]* @0, [1 x %struct.MunTypeInfo addrspace(4)*]* @"struct_info::<Foo>::field_types", [1 x i16]* @"struct_info::<Foo>::field_offsets", i16 1, i8 0 } }
@"type_info::<*const TypeInfo>::name" = private unnamed_addr constant [16 x i8] c"*const TypeInfo\00"
@"type_info::<*const TypeInfo>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"=\A1-\1F\C2\A7\88`d\90\F4\B5\BEE}x", [16 x i8]* @"type_info::<*const TypeInfo>::name", i32 64, i8 8, i8 0 }
@"type_info::<Foo>" = private unnamed_addr constant { %struct.MunTypeInfo, %struct.MunStructInfo } { %struct.MunTypeInfo { [16 x i8] c"\96\9D\B4\17\E0@\0B0\11:}(\A3\D3mQ", [4 x i8]* @"type_info::<Foo>::name", i32 64, i8 8, i8 1 }, %struct.MunStructInfo { [1 x i8 addrspace(4)*]* @0, [1 x %struct.MunTypeInfo addrspace(4)*]* @"struct_info::<Foo>::field_types", [1 x i16]* @"struct_info::<Foo>::field_offsets", i16 1, i8 0 } }
@"type_info::<*const *mut core::void>::name" = private unnamed_addr constant [23 x i8] c"*const *mut core::void\00"
@"type_info::<*const *mut core::void>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\C5fO\BD\84\DF\06\BFd+\B1\9Abv\CE\00", [23 x i8]* @"type_info::<*const *mut core::void>::name", i32 64, i8 8, i8 0 }
@"type_info::<*mut core::void>::name" = private unnamed_addr constant [16 x i8] c"*mut core::void\00"
@"type_info::<*mut core::void>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\F0Y\22\FC\95\9E\7F\CE\08T\B1\A2\CD\A7\FAz", [16 x i8]* @"type_info::<*mut core::void>::name", i32 64, i8 8, i8 0 }
@global_type_table = global [5 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<Foo>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*const TypeInfo>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*const *mut core::void>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*mut core::void>"]
@global_type_table = global [5 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<*const TypeInfo>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<Foo>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*const *mut core::void>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*mut core::void>"]
@allocatorHandle = unnamed_addr global i8* null

28 changes: 14 additions & 14 deletions crates/mun_codegen/src/snapshots/test__field_expr.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,30 @@ source_filename = "group_name"
%struct.MunStructInfo = type { i8 addrspace(4)* addrspace(4)*, %struct.MunTypeInfo addrspace(4)* addrspace(4)*, i16 addrspace(4)*, i16, i8 }

@dispatchTable = global %DispatchTable { i8* addrspace(4)* (i8 addrspace(4)*, i8*)* null, i64 (%Foo)* @foo_a, %Foo (%Bar)* @bar_1 }
@"type_info::<*const TypeInfo>::name" = private unnamed_addr constant [16 x i8] c"*const TypeInfo\00"
@"type_info::<*const TypeInfo>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"=\A1-\1F\C2\A7\88`d\90\F4\B5\BEE}x", [16 x i8]* @"type_info::<*const TypeInfo>::name", i32 64, i8 8, i8 0 }
@"type_info::<Bar>::name" = private unnamed_addr constant [4 x i8] c"Bar\00"
@"struct_info::<Bar>::field_names" = private unnamed_addr constant [2 x i8] c"0\00"
@"struct_info::<Bar>::field_names.1" = private unnamed_addr constant [2 x i8] c"1\00"
@0 = private unnamed_addr constant [2 x i8 addrspace(4)*] [i8 addrspace(4)* @"struct_info::<Bar>::field_names", i8 addrspace(4)* @"struct_info::<Bar>::field_names.1"]
@"type_info::<core::f64>::name" = private unnamed_addr constant [10 x i8] c"core::f64\00"
@"type_info::<core::f64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"`\DBF\9C?YJ%G\AD4\9F\D5\92%A", [10 x i8]* @"type_info::<core::f64>::name", i32 64, i8 8, i8 0 }
@"type_info::<Foo>::name" = private unnamed_addr constant [4 x i8] c"Foo\00"
@"struct_info::<Foo>::field_names" = private unnamed_addr constant [2 x i8] c"a\00"
@0 = private unnamed_addr constant [1 x i8 addrspace(4)*] [i8 addrspace(4)* @"struct_info::<Foo>::field_names"]
@1 = private unnamed_addr constant [1 x i8 addrspace(4)*] [i8 addrspace(4)* @"struct_info::<Foo>::field_names"]
@"type_info::<core::i64>::name" = private unnamed_addr constant [10 x i8] c"core::i64\00"
@"type_info::<core::i64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"G\13;t\97j8\18\D7M\83`\1D\C8\19%", [10 x i8]* @"type_info::<core::i64>::name", i32 64, i8 8, i8 0 }
@"struct_info::<Foo>::field_types" = private unnamed_addr constant [1 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>"]
@"struct_info::<Foo>::field_offsets" = private unnamed_addr constant [1 x i16] zeroinitializer
@"type_info::<Foo>" = private unnamed_addr constant { %struct.MunTypeInfo, %struct.MunStructInfo } { %struct.MunTypeInfo { [16 x i8] c"\13V\C6}z\D1c\8D\81k\FB\82-\D2\C2]", [4 x i8]* @"type_info::<Foo>::name", i32 64, i8 8, i8 1 }, %struct.MunStructInfo { [1 x i8 addrspace(4)*]* @0, [1 x %struct.MunTypeInfo addrspace(4)*]* @"struct_info::<Foo>::field_types", [1 x i16]* @"struct_info::<Foo>::field_offsets", i16 1, i8 1 } }
@"type_info::<*const TypeInfo>::name" = private unnamed_addr constant [16 x i8] c"*const TypeInfo\00"
@"type_info::<*const TypeInfo>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"=\A1-\1F\C2\A7\88`d\90\F4\B5\BEE}x", [16 x i8]* @"type_info::<*const TypeInfo>::name", i32 64, i8 8, i8 0 }
@"type_info::<core::f64>::name" = private unnamed_addr constant [10 x i8] c"core::f64\00"
@"type_info::<core::f64>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"`\DBF\9C?YJ%G\AD4\9F\D5\92%A", [10 x i8]* @"type_info::<core::f64>::name", i32 64, i8 8, i8 0 }
@"type_info::<*const *mut core::void>::name" = private unnamed_addr constant [23 x i8] c"*const *mut core::void\00"
@"type_info::<*const *mut core::void>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\C5fO\BD\84\DF\06\BFd+\B1\9Abv\CE\00", [23 x i8]* @"type_info::<*const *mut core::void>::name", i32 64, i8 8, i8 0 }
@"type_info::<Bar>::name" = private unnamed_addr constant [4 x i8] c"Bar\00"
@"struct_info::<Bar>::field_names" = private unnamed_addr constant [2 x i8] c"0\00"
@"struct_info::<Bar>::field_names.1" = private unnamed_addr constant [2 x i8] c"1\00"
@1 = private unnamed_addr constant [2 x i8 addrspace(4)*] [i8 addrspace(4)* @"struct_info::<Bar>::field_names", i8 addrspace(4)* @"struct_info::<Bar>::field_names.1"]
@"type_info::<Foo>" = private unnamed_addr constant { %struct.MunTypeInfo, %struct.MunStructInfo } { %struct.MunTypeInfo { [16 x i8] c"\96\9D\B4\17\E0@\0B0\11:}(\A3\D3mQ", [4 x i8]* @"type_info::<Foo>::name", i32 64, i8 8, i8 1 }, %struct.MunStructInfo { [1 x i8 addrspace(4)*]* @1, [1 x %struct.MunTypeInfo addrspace(4)*]* @"struct_info::<Foo>::field_types", [1 x i16]* @"struct_info::<Foo>::field_offsets", i16 1, i8 1 } }
@"struct_info::<Bar>::field_types" = private unnamed_addr constant [2 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<core::f64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<Foo>"]
@"struct_info::<Bar>::field_offsets" = private unnamed_addr constant [2 x i16] [i16 0, i16 8]
@"type_info::<Bar>" = private unnamed_addr constant { %struct.MunTypeInfo, %struct.MunStructInfo } { %struct.MunTypeInfo { [16 x i8] c"\DD\C3_\88\FAq\B6\EF\14*\E6\1F56FS", [4 x i8]* @"type_info::<Bar>::name", i32 128, i8 8, i8 1 }, %struct.MunStructInfo { [2 x i8 addrspace(4)*]* @1, [2 x %struct.MunTypeInfo addrspace(4)*]* @"struct_info::<Bar>::field_types", [2 x i16]* @"struct_info::<Bar>::field_offsets", i16 2, i8 1 } }
@"type_info::<Bar>" = private unnamed_addr constant { %struct.MunTypeInfo, %struct.MunStructInfo } { %struct.MunTypeInfo { [16 x i8] c"E\F1HA\A5\B2Ul0\9DY\1D./E[", [4 x i8]* @"type_info::<Bar>::name", i32 128, i8 8, i8 1 }, %struct.MunStructInfo { [2 x i8 addrspace(4)*]* @0, [2 x %struct.MunTypeInfo addrspace(4)*]* @"struct_info::<Bar>::field_types", [2 x i16]* @"struct_info::<Bar>::field_offsets", i16 2, i8 1 } }
@"type_info::<*const *mut core::void>::name" = private unnamed_addr constant [23 x i8] c"*const *mut core::void\00"
@"type_info::<*const *mut core::void>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\C5fO\BD\84\DF\06\BFd+\B1\9Abv\CE\00", [23 x i8]* @"type_info::<*const *mut core::void>::name", i32 64, i8 8, i8 0 }
@"type_info::<*mut core::void>::name" = private unnamed_addr constant [16 x i8] c"*mut core::void\00"
@"type_info::<*mut core::void>" = private unnamed_addr constant %struct.MunTypeInfo { [16 x i8] c"\F0Y\22\FC\95\9E\7F\CE\08T\B1\A2\CD\A7\FAz", [16 x i8]* @"type_info::<*mut core::void>::name", i32 64, i8 8, i8 0 }
@global_type_table = global [7 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<Foo>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*const TypeInfo>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::f64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*const *mut core::void>", %struct.MunTypeInfo addrspace(4)* @"type_info::<Bar>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*mut core::void>"]
@global_type_table = global [7 x %struct.MunTypeInfo addrspace(4)*] [%struct.MunTypeInfo addrspace(4)* @"type_info::<*const TypeInfo>", %struct.MunTypeInfo addrspace(4)* @"type_info::<Bar>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::i64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<core::f64>", %struct.MunTypeInfo addrspace(4)* @"type_info::<Foo>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*const *mut core::void>", %struct.MunTypeInfo addrspace(4)* @"type_info::<*mut core::void>"]
@allocatorHandle = unnamed_addr global i8* null

declare i64 @foo_a(%Foo)
Expand Down
Loading