Skip to content

Commit

Permalink
misc: bump inkwell to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Jun 10, 2023
1 parent e762f13 commit 08de88d
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 125 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Bump LLVM from 13 to 14 [#495](https://github.com/mun-lang/mun/pull/495)
- Bump Inkwell to v0.2.0 [#528](https://github.com/mun-lang/mun/pull/528)

## [0.4.0] - 2022-12-12

Expand Down
2 changes: 1 addition & 1 deletion crates/mun_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ array-init = { version = "2.0.0", default-features = false }
by_address = { version = "1.0.4", default-features = false }
bytemuck = { version = "1.4.1", default-features = false }
mun_hir = { version = "0.4.0", path = "../mun_hir" }
inkwell = { version = "=0.1.0-beta.5", default-features = false, features = ["llvm14-0", "target-x86", "target-aarch64"] }
inkwell = { version = "0.2.0", default-features = false, features = ["llvm14-0", "target-x86", "target-aarch64"] }
itertools = { version = "0.10.3", default-features = false }
mun_codegen_macros = { version = "0.4.0", path = "../mun_codegen_macros" }
mun_target = { version = "0.4.0", path = "../mun_target" }
Expand Down
8 changes: 4 additions & 4 deletions crates/mun_codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,25 @@ pub trait IsPointerType<'ink> {

impl<'ink, S: BasicType<'ink>, T: IsIrType<'ink, Type = S>> IsPointerType<'ink> for *const T {
fn ir_type(context: &'ink Context, target: &TargetData) -> PointerType<'ink> {
T::ir_type(context, target).ptr_type(AddressSpace::Generic)
T::ir_type(context, target).ptr_type(AddressSpace::default())
}
}

impl<'ink> IsPointerType<'ink> for *const std::ffi::c_void {
fn ir_type(context: &'ink Context, _target: &TargetData) -> PointerType<'ink> {
context.i8_type().ptr_type(AddressSpace::Generic)
context.i8_type().ptr_type(AddressSpace::default())
}
}

impl<'ink> IsPointerType<'ink> for *mut std::ffi::c_void {
fn ir_type(context: &'ink Context, _target: &TargetData) -> PointerType<'ink> {
context.i8_type().ptr_type(AddressSpace::Generic)
context.i8_type().ptr_type(AddressSpace::default())
}
}

impl<'ink, S: BasicType<'ink>, T: IsIrType<'ink, Type = S>> IsPointerType<'ink> for *mut T {
fn ir_type(context: &'ink Context, target: &TargetData) -> PointerType<'ink> {
T::ir_type(context, target).ptr_type(AddressSpace::Generic)
T::ir_type(context, target).ptr_type(AddressSpace::default())
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/mun_codegen/src/ir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
// HACK: We should be able to use pointers for built-in struct types like `TypeInfo` in intrinsics
let type_info_ptr = self.builder.build_bitcast(
type_info_ptr,
self.context.i8_type().ptr_type(AddressSpace::Generic),
self.context.i8_type().ptr_type(AddressSpace::default()),
"type_info_ptr_to_i8_ptr",
);

Expand All @@ -417,8 +417,8 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
.build_bitcast(
untyped_reference,
struct_ir_ty
.ptr_type(AddressSpace::Generic)
.ptr_type(AddressSpace::Generic),
.ptr_type(AddressSpace::default())
.ptr_type(AddressSpace::default()),
&format!("ref<{}>", hir_struct.name(self.db)),
)
.into_pointer_value();
Expand Down Expand Up @@ -1463,7 +1463,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
// HACK: We should be able to use pointers for built-in struct types like `TypeInfo` in intrinsics
let type_info_ptr = self.builder.build_bitcast(
type_info_ptr,
self.context.i8_type().ptr_type(AddressSpace::Generic),
self.context.i8_type().ptr_type(AddressSpace::default()),
"type_info_ptr_to_i8_ptr",
);

Expand Down Expand Up @@ -1499,8 +1499,8 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
.build_bitcast(
untyped_array_ptr,
array_ty
.ptr_type(AddressSpace::Generic)
.ptr_type(AddressSpace::Generic),
.ptr_type(AddressSpace::default())
.ptr_type(AddressSpace::default()),
&format!("ref<[{}]>", element_ty.display(self.db)),
)
.into_pointer_value();
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_codegen/src/ir/dispatch_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl<'db, 'ink, 't> DispatchTableBuilder<'db, 'ink, 't> {
let table_body: Vec<BasicTypeEnum> = self
.entries
.iter()
.map(|f| f.ir_type.ptr_type(inkwell::AddressSpace::Generic).into())
.map(|f| f.ir_type.ptr_type(inkwell::AddressSpace::default()).into())
.collect();

// We can fill in the DispatchTable body, i.e: struct DispatchTable { <this part> };
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_codegen/src/ir/file_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub(crate) fn gen_file_group_ir<'ink>(

// Create the allocator handle global value
let allocator_handle_type = if needs_alloc {
let allocator_handle_type = code_gen.context.i8_type().ptr_type(AddressSpace::Generic);
let allocator_handle_type = code_gen.context.i8_type().ptr_type(AddressSpace::default());
let global = llvm_module.add_global(allocator_handle_type, None, "allocatorHandle");
global.set_initializer(&allocator_handle_type.const_null());
global.set_unnamed_address(UnnamedAddress::Global);
Expand Down
4 changes: 2 additions & 2 deletions crates/mun_codegen/src/ir/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ impl<'ink> RuntimeReferenceValue<'ink> {
object_type: impl BasicType<'ink>,
) -> Result<Self, String> {
let reference_type = object_type
.ptr_type(AddressSpace::Generic)
.ptr_type(AddressSpace::Generic);
.ptr_type(AddressSpace::default())
.ptr_type(AddressSpace::default());
if ptr.get_type() == reference_type {
Ok(Self(ptr))
} else {
Expand Down
12 changes: 6 additions & 6 deletions crates/mun_codegen/src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ impl<'db, 'ink> HirTypeCache<'db, 'ink> {
pub fn get_array_reference_type(&self, element_ty: &Ty) -> PointerType<'ink> {
let ir_ty = self.get_array_type(element_ty);
ir_ty
.ptr_type(AddressSpace::Generic)
.ptr_type(AddressSpace::Generic)
.ptr_type(AddressSpace::default())
.ptr_type(AddressSpace::default())
}

/// Returns the type of the struct that should be used for variables. Depending on the memory
Expand All @@ -176,8 +176,8 @@ impl<'db, 'ink> HirTypeCache<'db, 'ink> {
// struct Foo {}
// Foo**
ir_ty
.ptr_type(AddressSpace::Generic)
.ptr_type(AddressSpace::Generic)
.ptr_type(AddressSpace::default())
.ptr_type(AddressSpace::default())
.into()
}
mun_hir::StructMemoryKind::Value => {
Expand All @@ -201,8 +201,8 @@ impl<'db, 'ink> HirTypeCache<'db, 'ink> {
//
// Value structs are converted to GC types in the public API.
ir_ty
.ptr_type(AddressSpace::Generic)
.ptr_type(AddressSpace::Generic)
.ptr_type(AddressSpace::default())
.ptr_type(AddressSpace::default())
.into()
}

Expand Down
4 changes: 2 additions & 2 deletions crates/mun_codegen/src/value/float_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ impl<'ink> PointerValueType<'ink> for f32 {
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> PointerType<'ink> {
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::Generic))
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default()))
}
}
impl<'ink> PointerValueType<'ink> for f64 {
fn get_ptr_type(
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> PointerType<'ink> {
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::Generic))
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default()))
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/mun_codegen/src/value/function_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ macro_rules! into_function_info_impl {
) -> inkwell::types::PointerType<'ink>
{
debug_assert!(
address_space.is_none() || address_space == Some(inkwell::AddressSpace::Generic),
address_space.is_none() || address_space == Some(inkwell::AddressSpace::default()),
"Functions can only live in generic address space"
);
Self::get_ir_type(context).ptr_type(inkwell::AddressSpace::Generic)
Self::get_ir_type(context).ptr_type(inkwell::AddressSpace::default())
}
}
)+
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_codegen/src/value/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ where
fn get_ir_type(
context: &IrTypeContext<'ink, '_>,
) -> <<Self as ConcreteValueType<'ink>>::Value as ValueType<'ink>>::Type {
<T as SizedValueType>::get_ir_type(context).ptr_type(AddressSpace::Generic)
<T as SizedValueType>::get_ir_type(context).ptr_type(AddressSpace::default())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/mun_codegen/src/value/int_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ macro_rules! impl_as_int_ir_value {

impl<'ink> PointerValueType<'ink> for $ty {
fn get_ptr_type(context: &IrTypeContext<'ink, '_>, address_space: Option<AddressSpace>) -> inkwell::types::PointerType<'ink> {
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::Generic))
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default()))
}
}

Expand Down
192 changes: 96 additions & 96 deletions crates/mun_codegen/src/value/pointer_value.rs
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
use super::{
AddressableType, AsBytesAndPtrs, BytesOrPtr, ConcreteValueType, HasConstValue, IrTypeContext,
IrValueContext, PointerValueType, SizedValueType, Value,
};
use crate::value::ValueType;
use inkwell::{types::PointerType, AddressSpace};

impl<'ink> ConcreteValueType<'ink> for *const std::ffi::c_void {
type Value = inkwell::values::PointerValue<'ink>;
}

impl<'ink> SizedValueType<'ink> for *const std::ffi::c_void {
fn get_ir_type(
context: &IrTypeContext<'ink, '_>,
) -> <<Self as ConcreteValueType<'ink>>::Value as ValueType<'ink>>::Type {
context
.context
.ptr_sized_int_type(context.target_data, None)
.ptr_type(AddressSpace::Generic)
}
}

impl<'ink> PointerValueType<'ink> for *const std::ffi::c_void {
fn get_ptr_type(
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> PointerType<'ink> {
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::Generic))
}
}

impl<'ink, T: PointerValueType<'ink>> ConcreteValueType<'ink> for *const T {
type Value = inkwell::values::PointerValue<'ink>;
}

impl<'ink, T: PointerValueType<'ink>> ConcreteValueType<'ink> for *mut T {
type Value = inkwell::values::PointerValue<'ink>;
}

impl<'ink, T: PointerValueType<'ink>> SizedValueType<'ink> for *const T {
fn get_ir_type(context: &IrTypeContext<'ink, '_>) -> inkwell::types::PointerType<'ink> {
T::get_ptr_type(context, None)
}
}
impl<'ink, T: PointerValueType<'ink>> SizedValueType<'ink> for *mut T {
fn get_ir_type(context: &IrTypeContext<'ink, '_>) -> inkwell::types::PointerType<'ink> {
T::get_ptr_type(context, None)
}
}

impl<'ink, T: PointerValueType<'ink>> PointerValueType<'ink> for *mut T {
fn get_ptr_type(
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> PointerType<'ink> {
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::Generic))
}
}

impl<'ink, T: PointerValueType<'ink>> PointerValueType<'ink> for *const T {
fn get_ptr_type(
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> PointerType<'ink> {
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::Generic))
}
}

impl<'ink, T: SizedValueType<'ink, Value = inkwell::values::PointerValue<'ink>>> Value<'ink, T> {
/// Constructs a `null` pointer of type `T`
pub fn null(context: &IrValueContext<'ink, '_, '_>) -> Self {
Value::from_raw(T::get_ir_type(context.type_context).const_null())
}
}

impl<'ink, T> AddressableType<'ink, *const T> for *const T where *const T: ConcreteValueType<'ink> {}

impl<'ink, T> AddressableType<'ink, *mut T> for *mut T where *mut T: ConcreteValueType<'ink> {}

impl<'ink, T> HasConstValue for Value<'ink, T>
where
T: SizedValueType<'ink, Value = inkwell::values::PointerValue<'ink>>,
{
fn has_const_value() -> bool {
true
}
}

impl<'ink, T> AsBytesAndPtrs<'ink> for Value<'ink, T>
where
T: SizedValueType<'ink, Value = inkwell::values::PointerValue<'ink>>,
{
fn as_bytes_and_ptrs(&self, _: &IrTypeContext<'ink, '_>) -> Vec<BytesOrPtr<'ink>> {
vec![BytesOrPtr::UntypedPtr(self.value)]
}
}
use super::{
AddressableType, AsBytesAndPtrs, BytesOrPtr, ConcreteValueType, HasConstValue, IrTypeContext,
IrValueContext, PointerValueType, SizedValueType, Value,
};
use crate::value::ValueType;
use inkwell::{types::PointerType, AddressSpace};

impl<'ink> ConcreteValueType<'ink> for *const std::ffi::c_void {
type Value = inkwell::values::PointerValue<'ink>;
}

impl<'ink> SizedValueType<'ink> for *const std::ffi::c_void {
fn get_ir_type(
context: &IrTypeContext<'ink, '_>,
) -> <<Self as ConcreteValueType<'ink>>::Value as ValueType<'ink>>::Type {
context
.context
.ptr_sized_int_type(context.target_data, None)
.ptr_type(AddressSpace::default())
}
}

impl<'ink> PointerValueType<'ink> for *const std::ffi::c_void {
fn get_ptr_type(
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> PointerType<'ink> {
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default()))
}
}

impl<'ink, T: PointerValueType<'ink>> ConcreteValueType<'ink> for *const T {
type Value = inkwell::values::PointerValue<'ink>;
}

impl<'ink, T: PointerValueType<'ink>> ConcreteValueType<'ink> for *mut T {
type Value = inkwell::values::PointerValue<'ink>;
}

impl<'ink, T: PointerValueType<'ink>> SizedValueType<'ink> for *const T {
fn get_ir_type(context: &IrTypeContext<'ink, '_>) -> inkwell::types::PointerType<'ink> {
T::get_ptr_type(context, None)
}
}
impl<'ink, T: PointerValueType<'ink>> SizedValueType<'ink> for *mut T {
fn get_ir_type(context: &IrTypeContext<'ink, '_>) -> inkwell::types::PointerType<'ink> {
T::get_ptr_type(context, None)
}
}

impl<'ink, T: PointerValueType<'ink>> PointerValueType<'ink> for *mut T {
fn get_ptr_type(
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> PointerType<'ink> {
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default()))
}
}

impl<'ink, T: PointerValueType<'ink>> PointerValueType<'ink> for *const T {
fn get_ptr_type(
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> PointerType<'ink> {
Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default()))
}
}

impl<'ink, T: SizedValueType<'ink, Value = inkwell::values::PointerValue<'ink>>> Value<'ink, T> {
/// Constructs a `null` pointer of type `T`
pub fn null(context: &IrValueContext<'ink, '_, '_>) -> Self {
Value::from_raw(T::get_ir_type(context.type_context).const_null())
}
}

impl<'ink, T> AddressableType<'ink, *const T> for *const T where *const T: ConcreteValueType<'ink> {}

impl<'ink, T> AddressableType<'ink, *mut T> for *mut T where *mut T: ConcreteValueType<'ink> {}

impl<'ink, T> HasConstValue for Value<'ink, T>
where
T: SizedValueType<'ink, Value = inkwell::values::PointerValue<'ink>>,
{
fn has_const_value() -> bool {
true
}
}

impl<'ink, T> AsBytesAndPtrs<'ink> for Value<'ink, T>
where
T: SizedValueType<'ink, Value = inkwell::values::PointerValue<'ink>>,
{
fn as_bytes_and_ptrs(&self, _: &IrTypeContext<'ink, '_>) -> Vec<BytesOrPtr<'ink>> {
vec![BytesOrPtr::UntypedPtr(self.value)]
}
}
Loading

0 comments on commit 08de88d

Please sign in to comment.