From f6c19008ff2a80ff8ce14c310842071651a86c83 Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 17:08:47 +0800 Subject: [PATCH 01/12] with_impl -> arc --- src/ir/types.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/ir/types.rs b/src/ir/types.rs index 5f527a34..b3efb016 100644 --- a/src/ir/types.rs +++ b/src/ir/types.rs @@ -1,6 +1,6 @@ use inkwell::{ context::ContextRef, - types::{FloatType, IntType, PointerType, StructType, VoidType}, + types::{BasicTypeEnum, FloatType, IntType, PointerType, StructType, VoidType}, AddressSpace, }; @@ -71,20 +71,25 @@ impl<'llvm> Types<'llvm> { } /// Get wrapper around pointer to opaque impl - fn with_impl(&self, name: &str) -> StructType<'llvm> { + pub fn arc(&self, name: &str, field_types: &[BasicTypeEnum<'llvm>]) -> StructType<'llvm> { if let Some(ty) = self.llvm.get_struct_type(name) { return ty; } + let data_ty = self.llvm.opaque_struct_type(&format!("{name}Impl")); + if !field_types.is_empty() { + data_ty.set_body(field_types, false); + } + let ty = self.llvm.opaque_struct_type(name); - ty.set_body(&[self.opaque(&format!("{name}Impl")).into()], false); + ty.set_body(&[self.pointer().into()], false); ty } /// LLVM IR for [`Class`](Type::Class) type pub fn opaque(&self, name: &str) -> PointerType<'llvm> { self.get_or_add_opaque_struct(name); - self.llvm.ptr_type(AddressSpace::default()) + self.pointer() } /// LLVM IR for [`None`](Type::None) type @@ -94,21 +99,26 @@ impl<'llvm> Types<'llvm> { /// LLVM IR for [`Integer`](Type::Integer) type pub fn integer(&self) -> StructType<'llvm> { - self.with_impl("Integer") + self.arc("Integer", &[]) } /// LLVM IR for `Rational` type pub fn rational(&self) -> StructType<'llvm> { - self.with_impl("Rational") + self.arc("Rational", &[]) } /// LLVM IR for [`String`](Type::String) type pub fn string(&self) -> StructType<'llvm> { - self.with_impl("String") + self.arc("String", &[]) } /// LLVM IR for C string type pub fn c_string(&self) -> PointerType<'llvm> { + self.pointer() + } + + /// LLVM IR for pointer type + pub fn pointer(&self) -> PointerType<'llvm> { self.llvm.ptr_type(AddressSpace::default()) } } From 107f35a9eb005c3cc65accfe9d5e553f9f78db85 Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 17:26:14 +0800 Subject: [PATCH 02/12] All classes now arc --- src/ir/to_ir.rs | 47 +++--- src/ir/types.rs | 5 + .../snapshots/ppl__tests__address_of.ir.snap | 20 +-- src/tests/snapshots/ppl__tests__clone.ir.snap | 10 +- .../ppl__tests__common_functions.ir.snap | 8 +- .../ppl__tests__consume_greater.ir.snap | 14 +- src/tests/snapshots/ppl__tests__deps.ir.snap | 8 +- .../ppl__tests__deref_member_ref.ir.snap | 31 ++-- .../snapshots/ppl__tests__destructor.ir.snap | 17 ++- .../ppl__tests__empty_constructor.ir.snap | 47 +++--- .../snapshots/ppl__tests__escaped_id.ir.snap | 10 +- .../snapshots/ppl__tests__generics.ir.snap | 34 +++-- .../snapshots/ppl__tests__import_all.ir.snap | 8 +- .../snapshots/ppl__tests__integer.ir.snap | 8 +- .../snapshots/ppl__tests__memory.ir.snap | 33 +++-- .../ppl__tests__monomorphize.ir.snap | 18 ++- ...l__tests__monomorphize_predeclared.ir.snap | 8 +- .../snapshots/ppl__tests__multifile.ir.snap | 8 +- .../snapshots/ppl__tests__plus_assign.ir.snap | 10 +- src/tests/snapshots/ppl__tests__ppl.ir.snap | 8 +- .../ppl__tests__predeclare_function.ir.snap | 8 +- .../ppl__tests__predeclare_vars.ir.snap | 10 +- .../snapshots/ppl__tests__rational.ir.snap | 8 +- .../ppl__tests__reference_mut.ir.snap | 10 +- .../ppl__tests__reference_to_literal.ir.snap | 10 +- .../ppl__tests__reference_to_none.ir.snap | 8 +- .../snapshots/ppl__tests__references.ir.snap | 35 +++-- src/tests/snapshots/ppl__tests__star.ir.snap | 8 +- .../snapshots/ppl__tests__string.ir.snap | 54 ++++--- .../snapshots/ppl__tests__supertraits.ir.snap | 8 +- .../ppl__tests__trait_with_ref.ir.snap | 10 +- .../snapshots/ppl__tests__traits.ir.snap | 10 +- .../ppl__tests__type_as_value.ir.snap | 134 ++++++++++-------- .../snapshots/ppl__tests__type_of.ir.snap | 31 ++-- 34 files changed, 413 insertions(+), 283 deletions(-) diff --git a/src/ir/to_ir.rs b/src/ir/to_ir.rs index 83744b44..cad7d201 100644 --- a/src/ir/to_ir.rs +++ b/src/ir/to_ir.rs @@ -247,24 +247,16 @@ impl<'llvm, C: Context<'llvm>> ToIR<'llvm, C> for ClassData { return context.types().f64().into(); } - if self.members.is_empty() { + if self.is_any_reference() { return context.types().opaque(&self.basename).into(); } - if let Some(ty) = context.llvm().get_struct_type(&self.name()) { - return ty.into(); - } - - let ty = context.llvm().opaque_struct_type(&self.name()); - ty.set_body( - self.members - .iter() - .filter_map(|m| m.ty().to_ir(context).try_into_basic_type().ok()) - .collect::>() - .as_slice(), - false, - ); - ty.into() + let field_types = self + .members + .iter() + .filter_map(|m| m.ty().to_ir(context).try_into_basic_type().ok()) + .collect::>(); + context.types().arc(&self.name(), &field_types).into() } } @@ -568,12 +560,25 @@ impl<'llvm, 'm> ToIR<'llvm, FunctionContext<'llvm, 'm, '_>> for Constructor { .expect("non-basic type constructor"); let alloca = context.builder.build_alloca(ty, "").unwrap(); + let ptr = context + .builder + .build_struct_gep( + ty, + alloca, + 0, + format!("{}.data", self.ty.referenced_type.name()).as_str(), + ) + .unwrap(); + let data_ty = context + .types() + .arc_data(&self.ty.referenced_type.name()) + .unwrap(); for init in self.initializers.iter().filter(|i| !i.value.ty().is_none()) { let field = context .builder .build_struct_gep( - ty, - alloca, + data_ty, + ptr, init.index as u32, format!("{}.{}", self.ty.referenced_type.name(), init.member.name()).as_str(), ) @@ -609,10 +614,16 @@ impl<'llvm, 'm> HIRExpressionLoweringWithoutLoad<'llvm, 'm> for MemberReference let base = base.unwrap().into_pointer_value(); let ty = self.base.ty().to_ir(context).try_into_basic_type().unwrap(); + let ptr = context + .builder + .build_struct_gep(ty, base, 0, "") + .unwrap() + .into(); + let data_ty = context.types().arc_data(&self.base.ty().name()).unwrap(); Some( context .builder - .build_struct_gep(ty, base, self.index as u32, &self.member.name()) + .build_struct_gep(data_ty, ptr, self.index as u32, &self.member.name()) .unwrap() .into(), ) diff --git a/src/ir/types.rs b/src/ir/types.rs index b3efb016..22e3bfed 100644 --- a/src/ir/types.rs +++ b/src/ir/types.rs @@ -86,6 +86,11 @@ impl<'llvm> Types<'llvm> { ty } + /// Get LLVM struct type for data of ARC type + pub fn arc_data(&self, name: &str) -> Option> { + self.llvm.get_struct_type(&format!("{name}Impl")) + } + /// LLVM IR for [`Class`](Type::Class) type pub fn opaque(&self, name: &str) -> PointerType<'llvm> { self.get_or_add_opaque_struct(name); diff --git a/src/tests/snapshots/ppl__tests__address_of.ir.snap b/src/tests/snapshots/ppl__tests__address_of.ir.snap index 4568dcbf..9a2beab2 100644 --- a/src/tests/snapshots/ppl__tests__address_of.ir.snap +++ b/src/tests/snapshots/ppl__tests__address_of.ir.snap @@ -5,11 +5,13 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } -%"Type" = type { %String, %Integer } -%MemoryAddress = type { %Integer } +%MemoryAddress = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } +%"TypeImpl" = type { %String, %Integer } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -21,10 +23,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -41,10 +44,11 @@ declare %Integer @integer_from_i64(i64) define private void @initialize.1() !dbg !9 { %1 = alloca %"Type", align 8, !dbg !10 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 %2 = call %String @string_from_c_string_and_length(ptr @1, i64 7), !dbg !11 store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 store %Integer %3, ptr %"Type.size", align 8, !dbg !11 %4 = load %"Type", ptr %1, align 8, !dbg !11 diff --git a/src/tests/snapshots/ppl__tests__clone.ir.snap b/src/tests/snapshots/ppl__tests__clone.ir.snap index bf286613..b2bc81dc 100644 --- a/src/tests/snapshots/ppl__tests__clone.ir.snap +++ b/src/tests/snapshots/ppl__tests__clone.ir.snap @@ -5,9 +5,10 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -17,10 +18,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__common_functions.ir.snap b/src/tests/snapshots/ppl__tests__common_functions.ir.snap index c7018076..e4e1e3e5 100644 --- a/src/tests/snapshots/ppl__tests__common_functions.ir.snap +++ b/src/tests/snapshots/ppl__tests__common_functions.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @@ -15,10 +16,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__consume_greater.ir.snap b/src/tests/snapshots/ppl__tests__consume_greater.ir.snap index 35b64095..2178620c 100644 --- a/src/tests/snapshots/ppl__tests__consume_greater.ir.snap +++ b/src/tests/snapshots/ppl__tests__consume_greater.ir.snap @@ -5,20 +5,23 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } -%"Point" = type { %Integer } +%"Point" = type { ptr } +%"PointImpl" = type { %Integer } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -36,7 +39,8 @@ declare %Integer @integer_from_i64(i64) define void @main.execute() !dbg !9 { call void @initialize(), !dbg !10 %1 = alloca %"Point", align 8, !dbg !11 - %"Point.x" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !11 + %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !11 + %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !11 %2 = call %Integer @integer_from_i64(i64 1), !dbg !12 store %Integer %2, ptr %"Point.x", align 8, !dbg !12 %3 = load %"Point", ptr %1, align 8, !dbg !12 diff --git a/src/tests/snapshots/ppl__tests__deps.ir.snap b/src/tests/snapshots/ppl__tests__deps.ir.snap index 22e7ddba..2d15cc17 100644 --- a/src/tests/snapshots/ppl__tests__deps.ir.snap +++ b/src/tests/snapshots/ppl__tests__deps.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @@ -14,10 +15,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap b/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap index 7193447a..936a5f6f 100644 --- a/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap +++ b/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap @@ -5,10 +5,12 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%Point = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } -%Point = type { %Integer, %Integer } +%PointImpl = type { %Integer, %Integer } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -16,10 +18,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -50,27 +53,29 @@ define %Integer @"x of <:Reference>"(ptr %0) !dbg !12 { %p = alloca ptr, align 8 store ptr %0, ptr %p, align 8 %2 = load ptr, ptr %p, align 8, !dbg !13 - %x = getelementptr inbounds %Point, ptr %2, i32 0, i32 0, !dbg !13 - %3 = call %Integer @clone_integer(ptr %x), !dbg !13 + %3 = getelementptr inbounds %Point, ptr %2, i32 0, i32 0, !dbg !13 + %x = getelementptr inbounds %PointImpl, ptr %3, i32 0, i32 0, !dbg !13 + %4 = call %Integer @clone_integer(ptr %x), !dbg !13 %"$tmp@61" = alloca %Integer, align 8, !dbg !13 - store %Integer %3, ptr %"$tmp@61", align 8, !dbg !13 - %4 = load %Integer, ptr %"$tmp@61", align 8, !dbg !13 - store %Integer %4, ptr %return_value, align 8, !dbg !13 + store %Integer %4, ptr %"$tmp@61", align 8, !dbg !13 + %5 = load %Integer, ptr %"$tmp@61", align 8, !dbg !13 + store %Integer %5, ptr %return_value, align 8, !dbg !13 br label %return, !dbg !13 return: ; preds = %1 - %5 = load %Integer, ptr %return_value, align 8 - ret %Integer %5 + %6 = load %Integer, ptr %return_value, align 8 + ret %Integer %6 } declare %Integer @clone_integer(ptr) define private void @initialize.1() !dbg !14 { %1 = alloca %Point, align 8, !dbg !15 - %Point.x = getelementptr inbounds %Point, ptr %1, i32 0, i32 0, !dbg !15 + %Point.data = getelementptr inbounds %Point, ptr %1, i32 0, i32 0, !dbg !15 + %Point.x = getelementptr inbounds %PointImpl, ptr %Point.data, i32 0, i32 0, !dbg !15 %2 = call %Integer @integer_from_i64(i64 1), !dbg !16 store %Integer %2, ptr %Point.x, align 8, !dbg !16 - %Point.y = getelementptr inbounds %Point, ptr %1, i32 0, i32 1, !dbg !16 + %Point.y = getelementptr inbounds %PointImpl, ptr %Point.data, i32 0, i32 1, !dbg !16 %3 = call %Integer @integer_from_i64(i64 2), !dbg !17 store %Integer %3, ptr %Point.y, align 8, !dbg !17 %4 = load %Point, ptr %1, align 8, !dbg !17 diff --git a/src/tests/snapshots/ppl__tests__destructor.ir.snap b/src/tests/snapshots/ppl__tests__destructor.ir.snap index cfb8d7b9..b48b9496 100644 --- a/src/tests/snapshots/ppl__tests__destructor.ir.snap +++ b/src/tests/snapshots/ppl__tests__destructor.ir.snap @@ -5,22 +5,25 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%DestructibleClass = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @1 = private unnamed_addr constant [11 x i8] c"destructor\00", align 1 -@x = global ptr null +@x = global %DestructibleClass zeroinitializer @2 = private unnamed_addr constant [5 x i8] c"done\00", align 1 define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -39,7 +42,8 @@ define void @main.execute() !dbg !9 { call void @initialize(), !dbg !10 call void @initialize.1(), !dbg !11 call void @"destroy <:ReferenceMut>"(ptr @x), !dbg !12 - %1 = alloca ptr, align 8, !dbg !13 + %1 = alloca %DestructibleClass, align 8, !dbg !13 + %DestructibleClass.data = getelementptr inbounds %DestructibleClass, ptr %1, i32 0, i32 0, !dbg !13 store ptr %1, ptr @x, align 8, !dbg !13 %2 = call %String @string_from_c_string_and_length(ptr @2, i64 4), !dbg !14 call void @"println <:String>"(%String %2), !dbg !14 @@ -64,7 +68,8 @@ return: ; preds = %1 declare void @"println <:String>"(%String) define private void @initialize.1() !dbg !19 { - %1 = alloca ptr, align 8, !dbg !20 + %1 = alloca %DestructibleClass, align 8, !dbg !20 + %DestructibleClass.data = getelementptr inbounds %DestructibleClass, ptr %1, i32 0, i32 0, !dbg !20 store ptr %1, ptr @x, align 8, !dbg !20 br label %return, !dbg !20 diff --git a/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap b/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap index a4a3947a..cacd00a4 100644 --- a/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap +++ b/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap @@ -5,23 +5,27 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"Type" = type { ptr } +%A = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } -%"Type" = type { %String, %Integer } +%"TypeImpl" = type { %String, %Integer } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @"Type" = private global %"Type" zeroinitializer @1 = private unnamed_addr constant [2 x i8] c"A\00", align 1 -@a = global ptr null +@a = global %A zeroinitializer define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -38,10 +42,11 @@ declare %Integer @integer_from_i64(i64) define private void @initialize.1() !dbg !9 { %1 = alloca %"Type", align 8, !dbg !10 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 %2 = call %String @string_from_c_string_and_length(ptr @1, i64 1), !dbg !11 store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 store %Integer %3, ptr %"Type.size", align 8, !dbg !11 %4 = load %"Type", ptr %1, align 8, !dbg !11 @@ -56,8 +61,8 @@ define void @main.execute() !dbg !12 { call void @initialize(), !dbg !13 call void @initialize.1(), !dbg !13 call void @initialize.2(), !dbg !14 - %1 = load ptr, ptr @a, align 8, !dbg !15 - %2 = call %"Type" @"type of <:A>"(ptr %1), !dbg !15 + %1 = load %A, ptr @a, align 8, !dbg !15 + %2 = call %"Type" @"type of <:A>"(%A %1), !dbg !15 call void @"println <:Type>"(%"Type" %2), !dbg !15 br label %return, !dbg !15 @@ -66,7 +71,8 @@ return: ; preds = %0 } define private void @initialize.2() !dbg !16 { - %1 = alloca ptr, align 8, !dbg !17 + %1 = alloca %A, align 8, !dbg !17 + %A.data = getelementptr inbounds %A, ptr %1, i32 0, i32 0, !dbg !17 store ptr %1, ptr @a, align 8, !dbg !17 br label %return, !dbg !17 @@ -92,25 +98,26 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg !20 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %name = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !21 - %2 = call %String @clone_string(ptr %name), !dbg !21 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !21 + %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !21 + %3 = call %String @clone_string(ptr %name), !dbg !21 %"$tmp@4331" = alloca %String, align 8, !dbg !21 - store %String %2, ptr %"$tmp@4331", align 8, !dbg !21 - %3 = load %String, ptr %"$tmp@4331", align 8, !dbg !21 - store %String %3, ptr %return_value, align 8, !dbg !21 + store %String %3, ptr %"$tmp@4331", align 8, !dbg !21 + %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !21 + store %String %4, ptr %return_value, align 8, !dbg !21 br label %return, !dbg !21 return: ; preds = %1 - %4 = load %String, ptr %return_value, align 8 - ret %String %4 + %5 = load %String, ptr %return_value, align 8 + ret %String %5 } declare %String @clone_string(ptr) -define private %"Type" @"type of <:A>"(ptr %0) !dbg !22 { +define private %"Type" @"type of <:A>"(%A %0) !dbg !22 { %return_value = alloca %"Type", align 8 - %"$arg0" = alloca ptr, align 8 - store ptr %0, ptr %"$arg0", align 8 + %"$arg0" = alloca %A, align 8 + store %A %0, ptr %"$arg0", align 8 %2 = load %"Type", ptr @"Type", align 8, !dbg !23 %"$tmp@4456" = alloca %"Type", align 8, !dbg !23 store %"Type" %2, ptr %"$tmp@4456", align 8, !dbg !23 diff --git a/src/tests/snapshots/ppl__tests__escaped_id.ir.snap b/src/tests/snapshots/ppl__tests__escaped_id.ir.snap index 674f69a4..b64a2deb 100644 --- a/src/tests/snapshots/ppl__tests__escaped_id.ir.snap +++ b/src/tests/snapshots/ppl__tests__escaped_id.ir.snap @@ -5,9 +5,10 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -15,10 +16,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__generics.ir.snap b/src/tests/snapshots/ppl__tests__generics.ir.snap index 2896263a..3519c298 100644 --- a/src/tests/snapshots/ppl__tests__generics.ir.snap +++ b/src/tests/snapshots/ppl__tests__generics.ir.snap @@ -5,10 +5,12 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } -%"Point" = type { %Integer, %Integer } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } +%"Point" = type { ptr } +%"PointImpl" = type { %Integer, %Integer } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -17,10 +19,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -51,10 +54,11 @@ define void @main.execute() !dbg !9 { %9 = call %String @"id <:String>"(%String %8), !dbg !16 call void @"println <:String>"(%String %9), !dbg !16 %10 = alloca %"Point", align 8, !dbg !17 - %"Point.x" = getelementptr inbounds %"Point", ptr %10, i32 0, i32 0, !dbg !17 + %"Point.data" = getelementptr inbounds %"Point", ptr %10, i32 0, i32 0, !dbg !17 + %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !17 %11 = call %Integer @integer_from_i64(i64 0), !dbg !18 store %Integer %11, ptr %"Point.x", align 8, !dbg !18 - %"Point.y" = getelementptr inbounds %"Point", ptr %10, i32 0, i32 1, !dbg !18 + %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !18 %12 = call %Integer @integer_from_i64(i64 0), !dbg !19 store %Integer %12, ptr %"Point.y", align 8, !dbg !19 %13 = load %"Point", ptr %10, align 8, !dbg !19 @@ -68,10 +72,11 @@ return: ; preds = %0 define private void @initialize.1() !dbg !21 { %1 = alloca %"Point", align 8, !dbg !22 - %"Point.x" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !22 + %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !22 + %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !22 %2 = call %Integer @integer_from_i64(i64 0), !dbg !23 store %Integer %2, ptr %"Point.x", align 8, !dbg !23 - %"Point.y" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 1, !dbg !23 + %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !23 %3 = call %Integer @integer_from_i64(i64 0), !dbg !24 store %Integer %3, ptr %"Point.y", align 8, !dbg !24 %4 = load %"Point", ptr %1, align 8, !dbg !24 @@ -87,14 +92,15 @@ define private %Integer @"x of <:Point>"(%"Point" %0) !dbg !25 %return_value = alloca %Integer, align 8 %p = alloca %"Point", align 8 store %"Point" %0, ptr %p, align 8 - %x = getelementptr inbounds %"Point", ptr %p, i32 0, i32 0, !dbg !26 - %2 = load %Integer, ptr %x, align 8, !dbg !26 - store %Integer %2, ptr %return_value, align 8, !dbg !26 + %2 = getelementptr inbounds %"Point", ptr %p, i32 0, i32 0, !dbg !26 + %x = getelementptr inbounds %"PointImpl", ptr %2, i32 0, i32 0, !dbg !26 + %3 = load %Integer, ptr %x, align 8, !dbg !26 + store %Integer %3, ptr %return_value, align 8, !dbg !26 br label %return, !dbg !26 return: ; preds = %1 - %3 = load %Integer, ptr %return_value, align 8 - ret %Integer %3 + %4 = load %Integer, ptr %return_value, align 8 + ret %Integer %4 } define private void @"println <:Bool>"(i1 %0) !dbg !27 { diff --git a/src/tests/snapshots/ppl__tests__import_all.ir.snap b/src/tests/snapshots/ppl__tests__import_all.ir.snap index 760063c1..bf6cd7cb 100644 --- a/src/tests/snapshots/ppl__tests__import_all.ir.snap +++ b/src/tests/snapshots/ppl__tests__import_all.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @@ -14,10 +15,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__integer.ir.snap b/src/tests/snapshots/ppl__tests__integer.ir.snap index 14e8e235..19a21862 100644 --- a/src/tests/snapshots/ppl__tests__integer.ir.snap +++ b/src/tests/snapshots/ppl__tests__integer.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } %Rational = type { ptr } @@ -15,10 +16,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__memory.ir.snap b/src/tests/snapshots/ppl__tests__memory.ir.snap index 10f6b780..0210e102 100644 --- a/src/tests/snapshots/ppl__tests__memory.ir.snap +++ b/src/tests/snapshots/ppl__tests__memory.ir.snap @@ -5,11 +5,13 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"Type" = type { ptr } +%MemoryAddress = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } -%"Type" = type { %String, %Integer } -%MemoryAddress = type { %Integer } +%"TypeImpl" = type { %String, %Integer } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -20,10 +22,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -40,10 +43,11 @@ declare %Integer @integer_from_i64(i64) define private void @initialize.1() !dbg !9 { %1 = alloca %"Type", align 8, !dbg !10 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 %2 = call %String @string_from_c_string_and_length(ptr @1, i64 7), !dbg !11 store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 store %Integer %3, ptr %"Type.size", align 8, !dbg !11 %4 = load %"Type", ptr %1, align 8, !dbg !11 @@ -121,17 +125,18 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !2 %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %size = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 1, !dbg !29 - %2 = call %Integer @clone_integer(ptr %size), !dbg !29 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !29 + %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !29 + %3 = call %Integer @clone_integer(ptr %size), !dbg !29 %"$tmp@4399" = alloca %Integer, align 8, !dbg !29 - store %Integer %2, ptr %"$tmp@4399", align 8, !dbg !29 - %3 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !29 - store %Integer %3, ptr %return_value, align 8, !dbg !29 + store %Integer %3, ptr %"$tmp@4399", align 8, !dbg !29 + %4 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !29 + store %Integer %4, ptr %return_value, align 8, !dbg !29 br label %return, !dbg !29 return: ; preds = %1 - %4 = load %Integer, ptr %return_value, align 8 - ret %Integer %4 + %5 = load %Integer, ptr %return_value, align 8 + ret %Integer %5 } declare void @destroy_integer(ptr) diff --git a/src/tests/snapshots/ppl__tests__monomorphize.ir.snap b/src/tests/snapshots/ppl__tests__monomorphize.ir.snap index f13f6845..1f2d8842 100644 --- a/src/tests/snapshots/ppl__tests__monomorphize.ir.snap +++ b/src/tests/snapshots/ppl__tests__monomorphize.ir.snap @@ -5,10 +5,12 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } +%"Point" = type { ptr } %Integer = type { ptr } -%"Point" = type { %Integer, %Integer } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } +%"PointImpl" = type { %Integer, %Integer } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -17,10 +19,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -52,10 +55,11 @@ return: ; preds = %0 define private void @initialize.1() !dbg !16 { %1 = alloca %"Point", align 8, !dbg !17 - %"Point.x" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !17 + %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !17 + %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !17 %2 = call %Integer @integer_from_i64(i64 1), !dbg !18 store %Integer %2, ptr %"Point.x", align 8, !dbg !18 - %"Point.y" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 1, !dbg !18 + %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !18 %3 = call %Integer @integer_from_i64(i64 2), !dbg !19 store %Integer %3, ptr %"Point.y", align 8, !dbg !19 %4 = load %"Point", ptr %1, align 8, !dbg !19 diff --git a/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap b/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap index ff7a9975..008b3fa9 100644 --- a/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap +++ b/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @@ -15,10 +16,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__multifile.ir.snap b/src/tests/snapshots/ppl__tests__multifile.ir.snap index ca2444c8..7b3aa83f 100644 --- a/src/tests/snapshots/ppl__tests__multifile.ir.snap +++ b/src/tests/snapshots/ppl__tests__multifile.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @@ -15,10 +16,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__plus_assign.ir.snap b/src/tests/snapshots/ppl__tests__plus_assign.ir.snap index c3fd5118..6fb2b731 100644 --- a/src/tests/snapshots/ppl__tests__plus_assign.ir.snap +++ b/src/tests/snapshots/ppl__tests__plus_assign.ir.snap @@ -5,10 +5,11 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%Rational = type { ptr } %String = type { ptr } +%"TypeImpl" = type { %String, %Integer } %Integer = type { ptr } -%Rational = type { ptr } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -21,10 +22,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__ppl.ir.snap b/src/tests/snapshots/ppl__tests__ppl.ir.snap index e776990f..2a6041f2 100644 --- a/src/tests/snapshots/ppl__tests__ppl.ir.snap +++ b/src/tests/snapshots/ppl__tests__ppl.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'lib' source_filename = "/Users/gavrilikhin_d/Code/ppl/ppl/src/lib.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @@ -14,10 +15,11 @@ source_filename = "/Users/gavrilikhin_d/Code/ppl/ppl/src/lib.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap b/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap index 5663dad8..77a1e9c6 100644 --- a/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap +++ b/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @@ -14,10 +15,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap b/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap index 71bd1d10..eaea1465 100644 --- a/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap +++ b/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap @@ -5,9 +5,10 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -16,10 +17,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__rational.ir.snap b/src/tests/snapshots/ppl__tests__rational.ir.snap index 025c8288..e17629c4 100644 --- a/src/tests/snapshots/ppl__tests__rational.ir.snap +++ b/src/tests/snapshots/ppl__tests__rational.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } %Rational = type { ptr } @@ -41,10 +42,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__reference_mut.ir.snap b/src/tests/snapshots/ppl__tests__reference_mut.ir.snap index 1d198759..cb5ebd81 100644 --- a/src/tests/snapshots/ppl__tests__reference_mut.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_mut.ir.snap @@ -5,9 +5,10 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -16,10 +17,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap b/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap index e209f1d5..fcb840fd 100644 --- a/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap @@ -5,9 +5,10 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -15,10 +16,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap b/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap index 632f0b56..60f360cd 100644 --- a/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @@ -15,10 +16,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__references.ir.snap b/src/tests/snapshots/ppl__tests__references.ir.snap index 4be64d70..935fa2f3 100644 --- a/src/tests/snapshots/ppl__tests__references.ir.snap +++ b/src/tests/snapshots/ppl__tests__references.ir.snap @@ -5,11 +5,13 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } -%"Type" = type { %String, %Integer } -%MemoryAddress = type { %Integer } +%MemoryAddress = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } +%"TypeImpl" = type { %String, %Integer } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -21,10 +23,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -41,10 +44,11 @@ declare %Integer @integer_from_i64(i64) define private void @initialize.1() !dbg !9 { %1 = alloca %"Type", align 8, !dbg !10 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 %2 = call %String @string_from_c_string_and_length(ptr @1, i64 3), !dbg !11 store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 %3 = call %Integer @integer_from_i64(i64 4), !dbg !11 store %Integer %3, ptr %"Type.size", align 8, !dbg !11 %4 = load %"Type", ptr %1, align 8, !dbg !11 @@ -97,17 +101,18 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !28 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %size = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 1, !dbg !29 - %2 = call %Integer @clone_integer(ptr %size), !dbg !29 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !29 + %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !29 + %3 = call %Integer @clone_integer(ptr %size), !dbg !29 %"$tmp@4399" = alloca %Integer, align 8, !dbg !29 - store %Integer %2, ptr %"$tmp@4399", align 8, !dbg !29 - %3 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !29 - store %Integer %3, ptr %return_value, align 8, !dbg !29 + store %Integer %3, ptr %"$tmp@4399", align 8, !dbg !29 + %4 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !29 + store %Integer %4, ptr %return_value, align 8, !dbg !29 br label %return, !dbg !29 return: ; preds = %1 - %4 = load %Integer, ptr %return_value, align 8 - ret %Integer %4 + %5 = load %Integer, ptr %return_value, align 8 + ret %Integer %5 } declare %Integer @clone_integer(ptr) diff --git a/src/tests/snapshots/ppl__tests__star.ir.snap b/src/tests/snapshots/ppl__tests__star.ir.snap index 7e97ec2d..24c55bc6 100644 --- a/src/tests/snapshots/ppl__tests__star.ir.snap +++ b/src/tests/snapshots/ppl__tests__star.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @@ -14,10 +15,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__string.ir.snap b/src/tests/snapshots/ppl__tests__string.ir.snap index cb066e03..da31de07 100644 --- a/src/tests/snapshots/ppl__tests__string.ir.snap +++ b/src/tests/snapshots/ppl__tests__string.ir.snap @@ -5,11 +5,14 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"Type" = type { ptr } +%"Type>" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } -%"Type" = type { %String, %Integer } -%"Type>" = type { %String, %Integer } +%"TypeImpl" = type { %String, %Integer } +%"Type>Impl" = type { %String, %Integer } %Rational = type { ptr } @"Type" = private global %"Type" zeroinitializer @@ -25,10 +28,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -45,10 +49,11 @@ declare %Integer @integer_from_i64(i64) define private void @initialize.1() !dbg !9 { %1 = alloca %"Type", align 8, !dbg !10 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 %2 = call %String @string_from_c_string_and_length(ptr @1, i64 7), !dbg !11 store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 store %Integer %3, ptr %"Type.size", align 8, !dbg !11 %4 = load %"Type", ptr %1, align 8, !dbg !11 @@ -61,10 +66,11 @@ return: ; preds = %0 define private void @initialize.2() !dbg !12 { %1 = alloca %"Type>", align 8, !dbg !13 - %"Type>.name" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 0, !dbg !13 + %"Type>.data" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 0, !dbg !13 + %"Type>.name" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 0, !dbg !13 %2 = call %String @string_from_c_string_and_length(ptr @2, i64 14), !dbg !14 store %String %2, ptr %"Type>.name", align 8, !dbg !14 - %"Type>.size" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 1, !dbg !14 + %"Type>.size" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 1, !dbg !14 %3 = call %Integer @integer_from_i64(i64 24), !dbg !14 store %Integer %3, ptr %"Type>.size", align 8, !dbg !14 %4 = load %"Type>", ptr %1, align 8, !dbg !14 @@ -127,17 +133,18 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %name = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !28 - %2 = call %String @clone_string(ptr %name), !dbg !28 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !28 + %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !28 + %3 = call %String @clone_string(ptr %name), !dbg !28 %"$tmp@4331" = alloca %String, align 8, !dbg !28 - store %String %2, ptr %"$tmp@4331", align 8, !dbg !28 - %3 = load %String, ptr %"$tmp@4331", align 8, !dbg !28 - store %String %3, ptr %return_value, align 8, !dbg !28 + store %String %3, ptr %"$tmp@4331", align 8, !dbg !28 + %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !28 + store %String %4, ptr %return_value, align 8, !dbg !28 br label %return, !dbg !28 return: ; preds = %1 - %4 = load %String, ptr %return_value, align 8 - ret %String %4 + %5 = load %String, ptr %return_value, align 8 + ret %String %5 } declare %String @clone_string(ptr) @@ -146,17 +153,18 @@ define private %String @"String from <:Type>>"(%"Type>", align 8 store %"Type>" %0, ptr %ty, align 8 - %name = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !30 - %2 = call %String @clone_string(ptr %name), !dbg !30 + %2 = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !30 + %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !30 + %3 = call %String @clone_string(ptr %name), !dbg !30 %"$tmp@4331" = alloca %String, align 8, !dbg !30 - store %String %2, ptr %"$tmp@4331", align 8, !dbg !30 - %3 = load %String, ptr %"$tmp@4331", align 8, !dbg !30 - store %String %3, ptr %return_value, align 8, !dbg !30 + store %String %3, ptr %"$tmp@4331", align 8, !dbg !30 + %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !30 + store %String %4, ptr %return_value, align 8, !dbg !30 br label %return, !dbg !30 return: ; preds = %1 - %4 = load %String, ptr %return_value, align 8 - ret %String %4 + %5 = load %String, ptr %return_value, align 8 + ret %String %5 } !llvm.module.flags = !{!0} diff --git a/src/tests/snapshots/ppl__tests__supertraits.ir.snap b/src/tests/snapshots/ppl__tests__supertraits.ir.snap index 011dfe60..b7cdfd19 100644 --- a/src/tests/snapshots/ppl__tests__supertraits.ir.snap +++ b/src/tests/snapshots/ppl__tests__supertraits.ir.snap @@ -5,7 +5,8 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } @@ -16,10 +17,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap b/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap index 88060aec..a2ca4324 100644 --- a/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap +++ b/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap @@ -5,9 +5,10 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -16,10 +17,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__traits.ir.snap b/src/tests/snapshots/ppl__tests__traits.ir.snap index 084d8b70..5ffa34a5 100644 --- a/src/tests/snapshots/ppl__tests__traits.ir.snap +++ b/src/tests/snapshots/ppl__tests__traits.ir.snap @@ -5,9 +5,10 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -15,10 +16,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 diff --git a/src/tests/snapshots/ppl__tests__type_as_value.ir.snap b/src/tests/snapshots/ppl__tests__type_as_value.ir.snap index 055675fc..2593fbea 100644 --- a/src/tests/snapshots/ppl__tests__type_as_value.ir.snap +++ b/src/tests/snapshots/ppl__tests__type_as_value.ir.snap @@ -5,13 +5,18 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } +%"Type" = type { ptr } +%"Type" = type { ptr } +%"Type>" = type { ptr } +%"Type" = type { ptr } %Integer = type { ptr } -%"Type" = type { %String, %Integer } -%"Type" = type { %String, %Integer } -%"Type>" = type { %String, %Integer } -%"Type" = type { %String, %Integer } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%"TypeImpl" = type { %String, %Integer } +%"Type>Impl" = type { %String, %Integer } +%"TypeImpl" = type { %String, %Integer } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -28,10 +33,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -48,10 +54,11 @@ declare %Integer @integer_from_i64(i64) define private void @initialize.1() !dbg !9 { %1 = alloca %"Type", align 8, !dbg !10 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 %2 = call %String @string_from_c_string_and_length(ptr @1, i64 4), !dbg !11 store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 %3 = call %Integer @integer_from_i64(i64 0), !dbg !11 store %Integer %3, ptr %"Type.size", align 8, !dbg !11 %4 = load %"Type", ptr %1, align 8, !dbg !11 @@ -64,10 +71,11 @@ return: ; preds = %0 define private void @initialize.2() !dbg !12 { %1 = alloca %"Type", align 8, !dbg !13 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !13 %2 = call %String @string_from_c_string_and_length(ptr @2, i64 4), !dbg !14 store %String %2, ptr %"Type.name", align 8, !dbg !14 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !14 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !14 %3 = call %Integer @integer_from_i64(i64 1), !dbg !14 store %Integer %3, ptr %"Type.size", align 8, !dbg !14 %4 = load %"Type", ptr %1, align 8, !dbg !14 @@ -80,10 +88,11 @@ return: ; preds = %0 define private void @initialize.3() !dbg !15 { %1 = alloca %"Type>", align 8, !dbg !16 - %"Type>.name" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 0, !dbg !16 + %"Type>.data" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 0, !dbg !16 + %"Type>.name" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 0, !dbg !16 %2 = call %String @string_from_c_string_and_length(ptr @3, i64 13), !dbg !17 store %String %2, ptr %"Type>.name", align 8, !dbg !17 - %"Type>.size" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 1, !dbg !17 + %"Type>.size" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 1, !dbg !17 %3 = call %Integer @integer_from_i64(i64 16), !dbg !17 store %Integer %3, ptr %"Type>.size", align 8, !dbg !17 %4 = load %"Type>", ptr %1, align 8, !dbg !17 @@ -96,10 +105,11 @@ return: ; preds = %0 define private void @initialize.4() !dbg !18 { %1 = alloca %"Type", align 8, !dbg !19 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !19 %2 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !20 store %String %2, ptr %"Type.name", align 8, !dbg !20 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !20 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !20 %3 = call %Integer @integer_from_i64(i64 8), !dbg !20 store %Integer %3, ptr %"Type.size", align 8, !dbg !20 %4 = load %"Type", ptr %1, align 8, !dbg !20 @@ -170,17 +180,18 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !38 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %size = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 1, !dbg !39 - %2 = call %Integer @clone_integer(ptr %size), !dbg !39 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !39 + %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !39 + %3 = call %Integer @clone_integer(ptr %size), !dbg !39 %"$tmp@4399" = alloca %Integer, align 8, !dbg !39 - store %Integer %2, ptr %"$tmp@4399", align 8, !dbg !39 - %3 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !39 - store %Integer %3, ptr %return_value, align 8, !dbg !39 + store %Integer %3, ptr %"$tmp@4399", align 8, !dbg !39 + %4 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !39 + store %Integer %4, ptr %return_value, align 8, !dbg !39 br label %return, !dbg !39 return: ; preds = %1 - %4 = load %Integer, ptr %return_value, align 8 - ret %Integer %4 + %5 = load %Integer, ptr %return_value, align 8 + ret %Integer %5 } declare %Integer @clone_integer(ptr) @@ -189,34 +200,36 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !40 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %size = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 1, !dbg !41 - %2 = call %Integer @clone_integer(ptr %size), !dbg !41 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !41 + %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !41 + %3 = call %Integer @clone_integer(ptr %size), !dbg !41 %"$tmp@4399" = alloca %Integer, align 8, !dbg !41 - store %Integer %2, ptr %"$tmp@4399", align 8, !dbg !41 - %3 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !41 - store %Integer %3, ptr %return_value, align 8, !dbg !41 + store %Integer %3, ptr %"$tmp@4399", align 8, !dbg !41 + %4 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !41 + store %Integer %4, ptr %return_value, align 8, !dbg !41 br label %return, !dbg !41 return: ; preds = %1 - %4 = load %Integer, ptr %return_value, align 8 - ret %Integer %4 + %5 = load %Integer, ptr %return_value, align 8 + ret %Integer %5 } define private %String @"String from <:Type>"(%"Type" %0) !dbg !42 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %name = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !43 - %2 = call %String @clone_string(ptr %name), !dbg !43 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !43 + %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !43 + %3 = call %String @clone_string(ptr %name), !dbg !43 %"$tmp@4331" = alloca %String, align 8, !dbg !43 - store %String %2, ptr %"$tmp@4331", align 8, !dbg !43 - %3 = load %String, ptr %"$tmp@4331", align 8, !dbg !43 - store %String %3, ptr %return_value, align 8, !dbg !43 + store %String %3, ptr %"$tmp@4331", align 8, !dbg !43 + %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !43 + store %String %4, ptr %return_value, align 8, !dbg !43 br label %return, !dbg !43 return: ; preds = %1 - %4 = load %String, ptr %return_value, align 8 - ret %String %4 + %5 = load %String, ptr %return_value, align 8 + ret %String %5 } declare %String @clone_string(ptr) @@ -225,17 +238,18 @@ define private %String @"String from <:Type>>"(%"Type>", align 8 store %"Type>" %0, ptr %ty, align 8 - %name = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !45 - %2 = call %String @clone_string(ptr %name), !dbg !45 + %2 = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !45 + %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !45 + %3 = call %String @clone_string(ptr %name), !dbg !45 %"$tmp@4331" = alloca %String, align 8, !dbg !45 - store %String %2, ptr %"$tmp@4331", align 8, !dbg !45 - %3 = load %String, ptr %"$tmp@4331", align 8, !dbg !45 - store %String %3, ptr %return_value, align 8, !dbg !45 + store %String %3, ptr %"$tmp@4331", align 8, !dbg !45 + %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !45 + store %String %4, ptr %return_value, align 8, !dbg !45 br label %return, !dbg !45 return: ; preds = %1 - %4 = load %String, ptr %return_value, align 8 - ret %String %4 + %5 = load %String, ptr %return_value, align 8 + ret %String %5 } define private void @initialize.5() !dbg !46 { @@ -248,7 +262,7 @@ return: ; preds = %0 } define private void @initialize.6() !dbg !48 { - %1 = call %Integer @clone_integer(ptr getelementptr inbounds (%"Type", ptr @"Type", i32 0, i32 1)), !dbg !49 + %1 = call %Integer @clone_integer(ptr getelementptr inbounds (%"TypeImpl", ptr @"Type", i32 0, i32 1)), !dbg !49 store %Integer %1, ptr @y, align 8, !dbg !49 br label %return, !dbg !49 @@ -260,17 +274,18 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !5 %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %size = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 1, !dbg !51 - %2 = call %Integer @clone_integer(ptr %size), !dbg !51 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !51 + %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !51 + %3 = call %Integer @clone_integer(ptr %size), !dbg !51 %"$tmp@4399" = alloca %Integer, align 8, !dbg !51 - store %Integer %2, ptr %"$tmp@4399", align 8, !dbg !51 - %3 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !51 - store %Integer %3, ptr %return_value, align 8, !dbg !51 + store %Integer %3, ptr %"$tmp@4399", align 8, !dbg !51 + %4 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !51 + store %Integer %4, ptr %return_value, align 8, !dbg !51 br label %return, !dbg !51 return: ; preds = %1 - %4 = load %Integer, ptr %return_value, align 8 - ret %Integer %4 + %5 = load %Integer, ptr %return_value, align 8 + ret %Integer %5 } define private void @"println <:Type>"(%"Type" %0) !dbg !52 { @@ -289,17 +304,18 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %name = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !56 - %2 = call %String @clone_string(ptr %name), !dbg !56 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !56 + %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !56 + %3 = call %String @clone_string(ptr %name), !dbg !56 %"$tmp@4331" = alloca %String, align 8, !dbg !56 - store %String %2, ptr %"$tmp@4331", align 8, !dbg !56 - %3 = load %String, ptr %"$tmp@4331", align 8, !dbg !56 - store %String %3, ptr %return_value, align 8, !dbg !56 + store %String %3, ptr %"$tmp@4331", align 8, !dbg !56 + %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !56 + store %String %4, ptr %return_value, align 8, !dbg !56 br label %return, !dbg !56 return: ; preds = %1 - %4 = load %String, ptr %return_value, align 8 - ret %String %4 + %5 = load %String, ptr %return_value, align 8 + ret %String %5 } declare void @destroy_integer(ptr) diff --git a/src/tests/snapshots/ppl__tests__type_of.ir.snap b/src/tests/snapshots/ppl__tests__type_of.ir.snap index 37967bcf..e2971a42 100644 --- a/src/tests/snapshots/ppl__tests__type_of.ir.snap +++ b/src/tests/snapshots/ppl__tests__type_of.ir.snap @@ -5,10 +5,12 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { %String, %Integer } +%"Type" = type { ptr } +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } -%"Type" = type { %String, %Integer } +%"TypeImpl" = type { %String, %Integer } @"Type" = private global %"Type" zeroinitializer @0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @@ -18,10 +20,11 @@ source_filename = "src/main.ppl" define private void @initialize() !dbg !3 { %1 = alloca %"Type", align 8, !dbg !7 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 store %Integer %3, ptr %"Type.size", align 8, !dbg !8 %4 = load %"Type", ptr %1, align 8, !dbg !8 @@ -38,10 +41,11 @@ declare %Integer @integer_from_i64(i64) define private void @initialize.1() !dbg !9 { %1 = alloca %"Type", align 8, !dbg !10 - %"Type.name" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 %2 = call %String @string_from_c_string_and_length(ptr @1, i64 7), !dbg !11 store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 1, !dbg !11 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 store %Integer %3, ptr %"Type.size", align 8, !dbg !11 %4 = load %"Type", ptr %1, align 8, !dbg !11 @@ -108,17 +112,18 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %name = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !23 - %2 = call %String @clone_string(ptr %name), !dbg !23 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !23 + %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !23 + %3 = call %String @clone_string(ptr %name), !dbg !23 %"$tmp@4331" = alloca %String, align 8, !dbg !23 - store %String %2, ptr %"$tmp@4331", align 8, !dbg !23 - %3 = load %String, ptr %"$tmp@4331", align 8, !dbg !23 - store %String %3, ptr %return_value, align 8, !dbg !23 + store %String %3, ptr %"$tmp@4331", align 8, !dbg !23 + %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !23 + store %String %4, ptr %return_value, align 8, !dbg !23 br label %return, !dbg !23 return: ; preds = %1 - %4 = load %String, ptr %return_value, align 8 - ret %String %4 + %5 = load %String, ptr %return_value, align 8 + ret %String %5 } declare %String @clone_string(ptr) From c0671362ee6bcfecacfc75b995dc83139653ab3d Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 17:28:45 +0800 Subject: [PATCH 03/12] Remove reference fields from Integer, Rational, String --- ppl/src/core.ppl | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/ppl/src/core.ppl b/ppl/src/core.ppl index 59808420..47360906 100644 --- a/ppl/src/core.ppl +++ b/ppl/src/core.ppl @@ -67,11 +67,8 @@ fn String from -> String: //================================= // Integer //================================= -type IntegerImpl - @builtin -type Integer: - impl: Reference +type Integer @mangle_as("integer_eq_integer") fn <:Integer> == <:Integer> -> Bool @@ -122,11 +119,8 @@ fn destroy <:&mut Integer> //================================= // Rational //================================= -type RationalImpl - @builtin -type Rational: - impl: Reference +type Rational @mangle_as("rational_eq_rational") fn <:Rational> == <:Rational> -> Bool @@ -165,11 +159,8 @@ fn clone <:&Rational> -> Rational //================================= // String //================================= -type StringImpl - @builtin -type String: - impl: Reference +type String /// Concatenate 2 strings @mangle_as("string_plus_string") From 0c5edddc8bfe9de73b8dc4bd9cc6d5b46dba5ec0 Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 19:10:18 +0800 Subject: [PATCH 04/12] snapshots --- .../snapshots/ppl__tests__array.hir.snap | 24 ++++++------- ...pl__tests__candidate_not_viable.error.snap | 24 ++++++------- .../ppl__tests__empty_constructor.hir.snap | 8 ++--- .../ppl__tests__empty_constructor.ir.snap | 12 +++---- .../snapshots/ppl__tests__memory.hir.snap | 4 +-- .../snapshots/ppl__tests__memory.ir.snap | 6 ++-- .../ppl__tests__reference_mut.hir.snap | 4 +-- .../ppl__tests__reference_mut.ir.snap | 6 ++-- .../snapshots/ppl__tests__references.hir.snap | 4 +-- .../snapshots/ppl__tests__references.ir.snap | 6 ++-- .../snapshots/ppl__tests__string.hir.snap | 8 ++--- .../snapshots/ppl__tests__string.ir.snap | 12 +++---- .../ppl__tests__type_as_value.hir.snap | 24 ++++++------- .../ppl__tests__type_as_value.ir.snap | 36 +++++++++---------- .../snapshots/ppl__tests__type_of.hir.snap | 8 ++--- .../snapshots/ppl__tests__type_of.ir.snap | 12 +++---- 16 files changed, 99 insertions(+), 99 deletions(-) diff --git a/src/tests/snapshots/ppl__tests__array.hir.snap b/src/tests/snapshots/ppl__tests__array.hir.snap index 93c345e5..29a54bbf 100644 --- a/src/tests/snapshots/ppl__tests__array.hir.snap +++ b/src/tests/snapshots/ppl__tests__array.hir.snap @@ -25,8 +25,8 @@ while `<:Integer> <= <:Integer>`(`clone <:Reference>`((i:Integer)), 10) fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) fn allocate <$arg1: Type> -> MemoryAddress: @@ -73,13 +73,13 @@ fn >> is empty -> Bool: fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) fn allocate <$arg1: Type> -> MemoryAddress: @@ -149,8 +149,8 @@ fn >> is not empty -> Bool: fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) @mangle_as("read_memory") @@ -194,13 +194,13 @@ fn <= -> Bool: fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) fn allocate <$arg1: Type> -> MemoryAddress: diff --git a/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap b/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap index eb655a3f..d7df81aa 100644 --- a/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap +++ b/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap @@ -19,12 +19,12 @@ Advice: ☞ candidate is not viable × expected `Integer` type, got `Rational` Error: × Integer - ╭─[core.ppl:88:5] - 87 │ @mangle_as("integer_plus_integer") - 88 │ fn <:Integer> + <:Integer> -> Integer + ╭─[core.ppl:85:5] + 84 │ @mangle_as("integer_plus_integer") + 85 │ fn <:Integer> + <:Integer> -> Integer · ▲ · ╰── this has `Integer` type - 89 │ + 86 │ ╰──── Error: × Rational ╭─[main.ppl:1:1] @@ -39,12 +39,12 @@ Advice: ☞ candidate is not viable × expected `Rational` type, got `Integer` Error: × Rational - ╭─[core.ppl:143:19] - 142 │ @mangle_as("rational_plus_rational") - 143 │ fn <:Rational> + <:Rational> -> Rational + ╭─[core.ppl:137:19] + 136 │ @mangle_as("rational_plus_rational") + 137 │ fn <:Rational> + <:Rational> -> Rational · ▲ · ╰── this has `Rational` type - 144 │ + 138 │ ╰──── Error: × Integer ╭─[main.ppl:1:7] @@ -59,12 +59,12 @@ Advice: ☞ candidate is not viable × expected `String` type, got `Rational` Error: × String - ╭─[core.ppl:176:5] - 175 │ @mangle_as("string_plus_string") - 176 │ fn <:String> + <:String> -> String + ╭─[core.ppl:167:5] + 166 │ @mangle_as("string_plus_string") + 167 │ fn <:String> + <:String> -> String · ▲ · ╰── this has `String` type - 177 │ + 168 │ ╰──── Error: × Rational ╭─[main.ppl:1:1] diff --git a/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap b/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap index dcf5fbd5..df3b7f75 100644 --- a/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap +++ b/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap @@ -10,13 +10,13 @@ let a: A = A { } fn type of <$arg0: A> -> Type: - let $tmp@4456: Type = (Type:Type) - return ($tmp@4456:Type) + let $tmp@4309: Type = (Type:Type) + return ($tmp@4309:Type) fn String from > -> String: - let $tmp@4331: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4331:String) + let $tmp@4184: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4184:String) fn println > -> None: diff --git a/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap b/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap index cacd00a4..91e5f347 100644 --- a/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap +++ b/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap @@ -101,9 +101,9 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg !20 { %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !21 %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !21 %3 = call %String @clone_string(ptr %name), !dbg !21 - %"$tmp@4331" = alloca %String, align 8, !dbg !21 - store %String %3, ptr %"$tmp@4331", align 8, !dbg !21 - %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !21 + %"$tmp@4184" = alloca %String, align 8, !dbg !21 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !21 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !21 store %String %4, ptr %return_value, align 8, !dbg !21 br label %return, !dbg !21 @@ -119,9 +119,9 @@ define private %"Type" @"type of <:A>"(%A %0) !dbg !22 { %"$arg0" = alloca %A, align 8 store %A %0, ptr %"$arg0", align 8 %2 = load %"Type", ptr @"Type", align 8, !dbg !23 - %"$tmp@4456" = alloca %"Type", align 8, !dbg !23 - store %"Type" %2, ptr %"$tmp@4456", align 8, !dbg !23 - %3 = load %"Type", ptr %"$tmp@4456", align 8, !dbg !23 + %"$tmp@4309" = alloca %"Type", align 8, !dbg !23 + store %"Type" %2, ptr %"$tmp@4309", align 8, !dbg !23 + %3 = load %"Type", ptr %"$tmp@4309", align 8, !dbg !23 store %"Type" %3, ptr %return_value, align 8, !dbg !23 br label %return, !dbg !23 diff --git a/src/tests/snapshots/ppl__tests__memory.hir.snap b/src/tests/snapshots/ppl__tests__memory.hir.snap index bac5c69e..cf7dfd8a 100644 --- a/src/tests/snapshots/ppl__tests__memory.hir.snap +++ b/src/tests/snapshots/ppl__tests__memory.hir.snap @@ -13,8 +13,8 @@ let x: ReferenceMut = `<:Type> at <:Reference>` fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) fn allocate <$arg1: Type> -> MemoryAddress: diff --git a/src/tests/snapshots/ppl__tests__memory.ir.snap b/src/tests/snapshots/ppl__tests__memory.ir.snap index 0210e102..dd0c120a 100644 --- a/src/tests/snapshots/ppl__tests__memory.ir.snap +++ b/src/tests/snapshots/ppl__tests__memory.ir.snap @@ -128,9 +128,9 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !2 %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !29 %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !29 %3 = call %Integer @clone_integer(ptr %size), !dbg !29 - %"$tmp@4399" = alloca %Integer, align 8, !dbg !29 - store %Integer %3, ptr %"$tmp@4399", align 8, !dbg !29 - %4 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !29 + %"$tmp@4252" = alloca %Integer, align 8, !dbg !29 + store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !29 + %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !29 store %Integer %4, ptr %return_value, align 8, !dbg !29 br label %return, !dbg !29 diff --git a/src/tests/snapshots/ppl__tests__reference_mut.hir.snap b/src/tests/snapshots/ppl__tests__reference_mut.hir.snap index c57e75c7..82bcbf40 100644 --- a/src/tests/snapshots/ppl__tests__reference_mut.hir.snap +++ b/src/tests/snapshots/ppl__tests__reference_mut.hir.snap @@ -14,8 +14,8 @@ let y: ReferenceMut = `reference to mutable <:ReferenceMut>`(( fn reference to mutable > -> ReferenceMut: - let mut $tmp@4747: ReferenceMut = (ref:ReferenceMut) - return ($tmp@4747:ReferenceMut) + let mut $tmp@4600: ReferenceMut = (ref:ReferenceMut) + return ($tmp@4600:ReferenceMut) @mangle_as("integer_as_string") diff --git a/src/tests/snapshots/ppl__tests__reference_mut.ir.snap b/src/tests/snapshots/ppl__tests__reference_mut.ir.snap index cb5ebd81..5953030d 100644 --- a/src/tests/snapshots/ppl__tests__reference_mut.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_mut.ir.snap @@ -81,9 +81,9 @@ define private ptr @"reference to mutable <:ReferenceMut>"(ptr %0) !dbg %ref = alloca ptr, align 8 store ptr %0, ptr %ref, align 8 %2 = load ptr, ptr %ref, align 8, !dbg !24 - %"$tmp@4747" = alloca ptr, align 8, !dbg !24 - store ptr %2, ptr %"$tmp@4747", align 8, !dbg !24 - %3 = load ptr, ptr %"$tmp@4747", align 8, !dbg !24 + %"$tmp@4600" = alloca ptr, align 8, !dbg !24 + store ptr %2, ptr %"$tmp@4600", align 8, !dbg !24 + %3 = load ptr, ptr %"$tmp@4600", align 8, !dbg !24 store ptr %3, ptr %return_value, align 8, !dbg !24 br label %return, !dbg !24 diff --git a/src/tests/snapshots/ppl__tests__references.hir.snap b/src/tests/snapshots/ppl__tests__references.hir.snap index 2059d858..05d9d523 100644 --- a/src/tests/snapshots/ppl__tests__references.hir.snap +++ b/src/tests/snapshots/ppl__tests__references.hir.snap @@ -16,8 +16,8 @@ let value: ReferenceMut = `<:Type> at <:Reference>`((Ty fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) @mangle_as("read_memory") diff --git a/src/tests/snapshots/ppl__tests__references.ir.snap b/src/tests/snapshots/ppl__tests__references.ir.snap index 935fa2f3..908aa044 100644 --- a/src/tests/snapshots/ppl__tests__references.ir.snap +++ b/src/tests/snapshots/ppl__tests__references.ir.snap @@ -104,9 +104,9 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !28 { %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !29 %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !29 %3 = call %Integer @clone_integer(ptr %size), !dbg !29 - %"$tmp@4399" = alloca %Integer, align 8, !dbg !29 - store %Integer %3, ptr %"$tmp@4399", align 8, !dbg !29 - %4 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !29 + %"$tmp@4252" = alloca %Integer, align 8, !dbg !29 + store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !29 + %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !29 store %Integer %4, ptr %return_value, align 8, !dbg !29 br label %return, !dbg !29 diff --git a/src/tests/snapshots/ppl__tests__string.hir.snap b/src/tests/snapshots/ppl__tests__string.hir.snap index e526e9ce..6afe8f65 100644 --- a/src/tests/snapshots/ppl__tests__string.hir.snap +++ b/src/tests/snapshots/ppl__tests__string.hir.snap @@ -15,10 +15,10 @@ expression: hir fn String from > -> String: - let $tmp@4331: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4331:String) + let $tmp@4184: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4184:String) fn> String from >> -> String: - let $tmp@4331: String = `clone <:Reference>`((ty:Type>).name) - return ($tmp@4331:String) + let $tmp@4184: String = `clone <:Reference>`((ty:Type>).name) + return ($tmp@4184:String) diff --git a/src/tests/snapshots/ppl__tests__string.ir.snap b/src/tests/snapshots/ppl__tests__string.ir.snap index da31de07..9eb60ddc 100644 --- a/src/tests/snapshots/ppl__tests__string.ir.snap +++ b/src/tests/snapshots/ppl__tests__string.ir.snap @@ -136,9 +136,9 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !28 %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !28 %3 = call %String @clone_string(ptr %name), !dbg !28 - %"$tmp@4331" = alloca %String, align 8, !dbg !28 - store %String %3, ptr %"$tmp@4331", align 8, !dbg !28 - %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !28 + %"$tmp@4184" = alloca %String, align 8, !dbg !28 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !28 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !28 store %String %4, ptr %return_value, align 8, !dbg !28 br label %return, !dbg !28 @@ -156,9 +156,9 @@ define private %String @"String from <:Type>>"(%"Type>", ptr %ty, i32 0, i32 0, !dbg !30 %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !30 %3 = call %String @clone_string(ptr %name), !dbg !30 - %"$tmp@4331" = alloca %String, align 8, !dbg !30 - store %String %3, ptr %"$tmp@4331", align 8, !dbg !30 - %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !30 + %"$tmp@4184" = alloca %String, align 8, !dbg !30 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !30 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !30 store %String %4, ptr %return_value, align 8, !dbg !30 br label %return, !dbg !30 diff --git a/src/tests/snapshots/ppl__tests__type_as_value.hir.snap b/src/tests/snapshots/ppl__tests__type_as_value.hir.snap index 5205886a..72c6b22a 100644 --- a/src/tests/snapshots/ppl__tests__type_as_value.hir.snap +++ b/src/tests/snapshots/ppl__tests__type_as_value.hir.snap @@ -16,8 +16,8 @@ let y: Integer = `clone <:Reference>`((Type:Type).siz fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) fn String from -> String: @@ -36,8 +36,8 @@ fn println -> None: fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) fn String from -> String: @@ -56,18 +56,18 @@ fn println -> None: fn String from > -> String: - let $tmp@4331: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4331:String) + let $tmp@4184: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4184:String) fn> String from >> -> String: - let $tmp@4331: String = `clone <:Reference>`((ty:Type>).name) - return ($tmp@4331:String) + let $tmp@4184: String = `clone <:Reference>`((ty:Type>).name) + return ($tmp@4184:String) fn size of > -> Integer: - let $tmp@4399: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4399:Integer) + let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4252:Integer) fn String from -> String: @@ -86,8 +86,8 @@ fn println -> None: fn String from > -> String: - let $tmp@4331: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4331:String) + let $tmp@4184: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4184:String) fn println > -> None: diff --git a/src/tests/snapshots/ppl__tests__type_as_value.ir.snap b/src/tests/snapshots/ppl__tests__type_as_value.ir.snap index 2593fbea..1b943c82 100644 --- a/src/tests/snapshots/ppl__tests__type_as_value.ir.snap +++ b/src/tests/snapshots/ppl__tests__type_as_value.ir.snap @@ -183,9 +183,9 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !38 { %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !39 %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !39 %3 = call %Integer @clone_integer(ptr %size), !dbg !39 - %"$tmp@4399" = alloca %Integer, align 8, !dbg !39 - store %Integer %3, ptr %"$tmp@4399", align 8, !dbg !39 - %4 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !39 + %"$tmp@4252" = alloca %Integer, align 8, !dbg !39 + store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !39 + %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !39 store %Integer %4, ptr %return_value, align 8, !dbg !39 br label %return, !dbg !39 @@ -203,9 +203,9 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !40 { %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !41 %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !41 %3 = call %Integer @clone_integer(ptr %size), !dbg !41 - %"$tmp@4399" = alloca %Integer, align 8, !dbg !41 - store %Integer %3, ptr %"$tmp@4399", align 8, !dbg !41 - %4 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !41 + %"$tmp@4252" = alloca %Integer, align 8, !dbg !41 + store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !41 + %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !41 store %Integer %4, ptr %return_value, align 8, !dbg !41 br label %return, !dbg !41 @@ -221,9 +221,9 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg !42 { %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !43 %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !43 %3 = call %String @clone_string(ptr %name), !dbg !43 - %"$tmp@4331" = alloca %String, align 8, !dbg !43 - store %String %3, ptr %"$tmp@4331", align 8, !dbg !43 - %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !43 + %"$tmp@4184" = alloca %String, align 8, !dbg !43 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !43 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !43 store %String %4, ptr %return_value, align 8, !dbg !43 br label %return, !dbg !43 @@ -241,9 +241,9 @@ define private %String @"String from <:Type>>"(%"Type>", ptr %ty, i32 0, i32 0, !dbg !45 %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !45 %3 = call %String @clone_string(ptr %name), !dbg !45 - %"$tmp@4331" = alloca %String, align 8, !dbg !45 - store %String %3, ptr %"$tmp@4331", align 8, !dbg !45 - %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !45 + %"$tmp@4184" = alloca %String, align 8, !dbg !45 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !45 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !45 store %String %4, ptr %return_value, align 8, !dbg !45 br label %return, !dbg !45 @@ -277,9 +277,9 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !5 %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !51 %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !51 %3 = call %Integer @clone_integer(ptr %size), !dbg !51 - %"$tmp@4399" = alloca %Integer, align 8, !dbg !51 - store %Integer %3, ptr %"$tmp@4399", align 8, !dbg !51 - %4 = load %Integer, ptr %"$tmp@4399", align 8, !dbg !51 + %"$tmp@4252" = alloca %Integer, align 8, !dbg !51 + store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !51 + %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !51 store %Integer %4, ptr %return_value, align 8, !dbg !51 br label %return, !dbg !51 @@ -307,9 +307,9 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !56 %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !56 %3 = call %String @clone_string(ptr %name), !dbg !56 - %"$tmp@4331" = alloca %String, align 8, !dbg !56 - store %String %3, ptr %"$tmp@4331", align 8, !dbg !56 - %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !56 + %"$tmp@4184" = alloca %String, align 8, !dbg !56 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !56 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !56 store %String %4, ptr %return_value, align 8, !dbg !56 br label %return, !dbg !56 diff --git a/src/tests/snapshots/ppl__tests__type_of.hir.snap b/src/tests/snapshots/ppl__tests__type_of.hir.snap index 80949d24..bc2f7c2f 100644 --- a/src/tests/snapshots/ppl__tests__type_of.hir.snap +++ b/src/tests/snapshots/ppl__tests__type_of.hir.snap @@ -9,13 +9,13 @@ let ty: Type = `type of <:Integer>`(1) fn type of <$arg0: Integer> -> Type: - let $tmp@4456: Type = (Type:Type) - return ($tmp@4456:Type) + let $tmp@4309: Type = (Type:Type) + return ($tmp@4309:Type) fn String from > -> String: - let $tmp@4331: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4331:String) + let $tmp@4184: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4184:String) fn println > -> None: diff --git a/src/tests/snapshots/ppl__tests__type_of.ir.snap b/src/tests/snapshots/ppl__tests__type_of.ir.snap index e2971a42..c15f9e6a 100644 --- a/src/tests/snapshots/ppl__tests__type_of.ir.snap +++ b/src/tests/snapshots/ppl__tests__type_of.ir.snap @@ -83,9 +83,9 @@ define private %"Type" @"type of <:Integer>"(%Integer %0) !dbg !18 { %"$arg0" = alloca %Integer, align 8 store %Integer %0, ptr %"$arg0", align 8 %2 = load %"Type", ptr @"Type", align 8, !dbg !19 - %"$tmp@4456" = alloca %"Type", align 8, !dbg !19 - store %"Type" %2, ptr %"$tmp@4456", align 8, !dbg !19 - %3 = load %"Type", ptr %"$tmp@4456", align 8, !dbg !19 + %"$tmp@4309" = alloca %"Type", align 8, !dbg !19 + store %"Type" %2, ptr %"$tmp@4309", align 8, !dbg !19 + %3 = load %"Type", ptr %"$tmp@4309", align 8, !dbg !19 store %"Type" %3, ptr %return_value, align 8, !dbg !19 br label %return, !dbg !19 @@ -115,9 +115,9 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !23 %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !23 %3 = call %String @clone_string(ptr %name), !dbg !23 - %"$tmp@4331" = alloca %String, align 8, !dbg !23 - store %String %3, ptr %"$tmp@4331", align 8, !dbg !23 - %4 = load %String, ptr %"$tmp@4331", align 8, !dbg !23 + %"$tmp@4184" = alloca %String, align 8, !dbg !23 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !23 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !23 store %String %4, ptr %return_value, align 8, !dbg !23 br label %return, !dbg !23 From 506ea37dd9b63516a1b88016e9caf9ff3b62cb3a Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 19:18:39 +0800 Subject: [PATCH 05/12] Size of should return POINTER_SIZE for arc types --- src/hir/declarations/types.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/hir/declarations/types.rs b/src/hir/declarations/types.rs index d154d7c6..9fdf9b38 100644 --- a/src/hir/declarations/types.rs +++ b/src/hir/declarations/types.rs @@ -402,15 +402,7 @@ impl ClassData { if let Some(builtin) = &self.builtin { return builtin.size_in_bytes(); } - - if self.is_opaque() { - return POINTER_SIZE; - } - - self.members - .iter() - .map(|m| m.ty().size_in_bytes()) - .sum::() + return POINTER_SIZE; } } From 938a66d719fac9a01b1cc6513b249131a7cbb5ec Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 19:20:45 +0800 Subject: [PATCH 06/12] Just use constructors for now --- src/semantics/to_hir.rs | 86 +++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 54 deletions(-) diff --git a/src/semantics/to_hir.rs b/src/semantics/to_hir.rs index d0a9105d..34a09745 100644 --- a/src/semantics/to_hir.rs +++ b/src/semantics/to_hir.rs @@ -987,62 +987,40 @@ impl ReplaceWithTypeInfo for TypeReference { return self.clone().into(); } - let name = self.type_for_type.name().to_string(); - let variable = if let Some(var) = context.module().find_variable(&name) { - var - } else { - let var = Variable::new(VariableData { - keyword: Keyword::<"let">::at(self.start()), - mutability: Mutability::Immutable, - name: Identifier::from(name).at(self.start()), - ty: self.type_for_type.clone(), - type_reference: None, - initializer: Some( - hir::Constructor { - ty: hir::TypeReference { - span: self.range(), - referenced_type: self.type_for_type.clone(), - type_for_type: context - .builtin() - .types() - .type_of(self.type_for_type.clone()), - }, - initializers: vec![ - hir::Initializer { - span: 0..0, - index: 0, - member: self.type_for_type.members()[0].clone(), - value: hir::Literal::String { - span: 0..0, - value: self.referenced_type.name().to_string(), - ty: context.builtin().types().string(), - } - .into(), - }, - hir::Initializer { - span: 0..0, - index: 1, - member: self.type_for_type.members()[1].clone(), - value: hir::Literal::Integer { - span: 0..0, - value: self.referenced_type.size_in_bytes().into(), - ty: context.builtin().types().integer(), - } - .into(), - }, - ], - rbrace: self.end() - 1, + hir::Constructor { + ty: hir::TypeReference { + span: self.range(), + referenced_type: self.type_for_type.clone(), + type_for_type: context + .builtin() + .types() + .type_of(self.type_for_type.clone()), + }, + initializers: vec![ + hir::Initializer { + span: 0..0, + index: 0, + member: self.type_for_type.members()[0].clone(), + value: hir::Literal::String { + span: 0..0, + value: self.referenced_type.name().to_string(), + ty: context.builtin().types().string(), } .into(), - ), - }); - context.module_mut().add_variable(var.clone()); - var.into() - }; - - hir::VariableReference { - span: self.range(), - variable, + }, + hir::Initializer { + span: 0..0, + index: 1, + member: self.type_for_type.members()[1].clone(), + value: hir::Literal::Integer { + span: 0..0, + value: self.referenced_type.size_in_bytes().into(), + ty: context.builtin().types().integer(), + } + .into(), + }, + ], + rbrace: self.end() - 1, } .into() } From e54472aed48a51367657e048a44d113e86e15c56 Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 19:21:40 +0800 Subject: [PATCH 07/12] lint --- src/semantics/to_hir.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/semantics/to_hir.rs b/src/semantics/to_hir.rs index 34a09745..6cc3ec5c 100644 --- a/src/semantics/to_hir.rs +++ b/src/semantics/to_hir.rs @@ -10,15 +10,15 @@ use crate::compilation::Compiler; use crate::from_decimal::FromDecimal; use crate::hir::{ self, FunctionNamePart, Generic, GenericType, Member, ModuleData, Parameter, Specialize, Type, - TypeReference, Typed, Variable, VariableData, + TypeReference, Typed, }; -use crate::mutability::{Mutability, Mutable}; +use crate::mutability::Mutable; use crate::named::Named; use crate::semantics::clone::Clonner; use crate::semantics::{ InsertDestructors, ParameterNamer, TemporariesInserter, TraitFunctionsLinker, }; -use crate::syntax::{Identifier, Keyword, Ranged}; +use crate::syntax::Ranged; use crate::{AddSourceLocation, ErrVec, SourceLocation, WithSourceLocation}; use super::{ From 3d221cad3e8d8e4ee54f25045d323a7ebd6d5a8b Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 19:22:45 +0800 Subject: [PATCH 08/12] snapshots --- .../snapshots/ppl__tests__address_of.hir.snap | 2 +- .../snapshots/ppl__tests__address_of.ir.snap | 167 +++--- .../snapshots/ppl__tests__array.hir.snap | 22 +- src/tests/snapshots/ppl__tests__clone.ir.snap | 136 ++--- .../ppl__tests__common_functions.ir.snap | 59 +-- .../ppl__tests__consume_greater.ir.snap | 52 +- src/tests/snapshots/ppl__tests__deps.ir.snap | 44 +- .../ppl__tests__deref_member_ref.ir.snap | 118 ++--- .../snapshots/ppl__tests__destructor.ir.snap | 97 ++-- .../ppl__tests__empty_constructor.hir.snap | 2 +- .../ppl__tests__empty_constructor.ir.snap | 159 +++--- .../snapshots/ppl__tests__escaped_id.ir.snap | 67 +-- .../snapshots/ppl__tests__generics.ir.snap | 210 ++++---- .../snapshots/ppl__tests__import_all.ir.snap | 73 +-- .../snapshots/ppl__tests__integer.ir.snap | 151 +++--- .../snapshots/ppl__tests__memory.hir.snap | 6 +- .../snapshots/ppl__tests__memory.ir.snap | 244 ++++----- .../ppl__tests__monomorphize.ir.snap | 116 ++--- ...l__tests__monomorphize_predeclared.ir.snap | 72 +-- .../snapshots/ppl__tests__multifile.ir.snap | 47 +- src/tests/snapshots/ppl__tests__ppl.ir.snap | 40 +- .../ppl__tests__predeclare_function.ir.snap | 125 ++--- .../ppl__tests__predeclare_vars.ir.snap | 132 ++--- .../snapshots/ppl__tests__rational.ir.snap | 376 +++++++------- .../ppl__tests__reference_mut.ir.snap | 136 ++--- .../ppl__tests__reference_to_literal.ir.snap | 88 ++-- .../ppl__tests__reference_to_none.ir.snap | 69 +-- .../snapshots/ppl__tests__references.hir.snap | 4 +- .../snapshots/ppl__tests__references.ir.snap | 230 ++++----- src/tests/snapshots/ppl__tests__star.ir.snap | 73 +-- .../snapshots/ppl__tests__string.hir.snap | 4 +- .../snapshots/ppl__tests__string.ir.snap | 233 ++++----- .../snapshots/ppl__tests__supertraits.ir.snap | 89 ++-- .../ppl__tests__trait_with_ref.ir.snap | 90 ++-- .../snapshots/ppl__tests__traits.ir.snap | 104 ++-- .../ppl__tests__type_as_value.hir.snap | 16 +- .../ppl__tests__type_as_value.ir.snap | 477 ++++++++---------- .../snapshots/ppl__tests__type_of.hir.snap | 2 +- .../snapshots/ppl__tests__type_of.ir.snap | 155 +++--- 39 files changed, 1668 insertions(+), 2619 deletions(-) diff --git a/src/tests/snapshots/ppl__tests__address_of.hir.snap b/src/tests/snapshots/ppl__tests__address_of.hir.snap index 24c59e11..9343ae8b 100644 --- a/src/tests/snapshots/ppl__tests__address_of.hir.snap +++ b/src/tests/snapshots/ppl__tests__address_of.hir.snap @@ -5,7 +5,7 @@ expression: hir let x: Integer = 0 `println <:Integer>`(`clone <:Reference>`((x:Integer))) let address: MemoryAddress = `address of <:Reference>`((&x:Reference)) -let x_mut_ref: ReferenceMut = `<:Type> at <:Reference>`((Type:Type), (&address:Reference)) +let x_mut_ref: ReferenceMut = `<:Type> at <:Reference>`(Type { name: "Integer", size: 8 }, (&address:Reference)) (x_mut_ref:ReferenceMut) = 1 `println <:Integer>`(`clone <:Reference>`((x:Integer))) `destroy <:ReferenceMut>`((x:Integer)) diff --git a/src/tests/snapshots/ppl__tests__address_of.ir.snap b/src/tests/snapshots/ppl__tests__address_of.ir.snap index 9a2beab2..52c2289f 100644 --- a/src/tests/snapshots/ppl__tests__address_of.ir.snap +++ b/src/tests/snapshots/ppl__tests__address_of.ir.snap @@ -5,96 +5,53 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"Type" = type { ptr } %Integer = type { ptr } %MemoryAddress = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } +%"Type" = type { ptr } %"TypeImpl" = type { %String, %Integer } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@"Type" = private global %"Type" zeroinitializer -@1 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @x = global %Integer zeroinitializer @address = global %MemoryAddress zeroinitializer @x_mut_ref = global ptr null - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +@0 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 + +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + %1 = call %Integer @clone_integer(ptr @x), !dbg !8 + call void @"println <:Integer>"(%Integer %1), !dbg !8 + call void @initialize.1(), !dbg !9 + call void @initialize.2(), !dbg !10 + %2 = load ptr, ptr @x_mut_ref, align 8, !dbg !11 + %3 = call %Integer @integer_from_i64(i64 1), !dbg !12 + store %Integer %3, ptr %2, align 8, !dbg !12 + %4 = call %Integer @clone_integer(ptr @x), !dbg !13 + call void @"println <:Integer>"(%Integer %4), !dbg !13 + call void @destroy_integer(ptr @x), !dbg !14 + br label %return, !dbg !14 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define private void @initialize.1() !dbg !9 { - %1 = alloca %"Type", align 8, !dbg !10 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 7), !dbg !11 - store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 - store %Integer %3, ptr %"Type.size", align 8, !dbg !11 - %4 = load %"Type", ptr %1, align 8, !dbg !11 - store %"Type" %4, ptr @"Type", align 8, !dbg !11 - br label %return, !dbg !11 +define private void @initialize() !dbg !15 { + %1 = call %Integer @integer_from_i64(i64 0), !dbg !16 + store %Integer %1, ptr @x, align 8, !dbg !16 + br label %return, !dbg !16 return: ; preds = %0 ret void } -define void @main.execute() !dbg !12 { - call void @initialize(), !dbg !13 - call void @initialize.1(), !dbg !14 - call void @initialize.2(), !dbg !15 - %1 = call %Integer @clone_integer(ptr @x), !dbg !16 - call void @"println <:Integer>"(%Integer %1), !dbg !16 - call void @initialize.3(), !dbg !17 - call void @initialize.4(), !dbg !14 - %2 = load ptr, ptr @x_mut_ref, align 8, !dbg !18 - %3 = call %Integer @integer_from_i64(i64 1), !dbg !19 - store %Integer %3, ptr %2, align 8, !dbg !19 - %4 = call %Integer @clone_integer(ptr @x), !dbg !20 - call void @"println <:Integer>"(%Integer %4), !dbg !20 - call void @destroy_integer(ptr @x), !dbg !21 - br label %return, !dbg !21 - -return: ; preds = %0 - ret void -} - -define private void @initialize.2() !dbg !22 { - %1 = call %Integer @integer_from_i64(i64 0), !dbg !23 - store %Integer %1, ptr @x, align 8, !dbg !23 - br label %return, !dbg !23 - -return: ; preds = %0 - ret void -} +declare %Integer @integer_from_i64(i64) -define private void @"println <:Integer>"(%Integer %0) !dbg !24 { +define private void @"println <:Integer>"(%Integer %0) !dbg !17 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !25 - %3 = call %String @integer_as_string(%Integer %2), !dbg !25 - call void @"println <:String>"(%String %3), !dbg !25 - br label %return, !dbg !25 + %2 = load %Integer, ptr %x, align 8, !dbg !18 + %3 = call %String @integer_as_string(%Integer %2), !dbg !18 + call void @"println <:String>"(%String %3), !dbg !18 + br label %return, !dbg !18 return: ; preds = %1 ret void @@ -106,10 +63,10 @@ declare %String @integer_as_string(%Integer) declare %Integer @clone_integer(ptr) -define private void @initialize.3() !dbg !26 { - %1 = call %MemoryAddress @address_of(ptr @x), !dbg !27 - store %MemoryAddress %1, ptr @address, align 8, !dbg !27 - br label %return, !dbg !27 +define private void @initialize.1() !dbg !19 { + %1 = call %MemoryAddress @address_of(ptr @x), !dbg !20 + store %MemoryAddress %1, ptr @address, align 8, !dbg !20 + br label %return, !dbg !20 return: ; preds = %0 ret void @@ -117,11 +74,19 @@ return: ; preds = %0 declare %MemoryAddress @address_of(ptr) -define private void @initialize.4() !dbg !28 { - %1 = load %"Type", ptr @"Type", align 8, !dbg !29 - %2 = call ptr @read_memory(%"Type" %1, ptr @address), !dbg !30 - store ptr %2, ptr @x_mut_ref, align 8, !dbg !30 - br label %return, !dbg !30 +define private void @initialize.2() !dbg !21 { + %1 = alloca %"Type", align 8, !dbg !22 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !22 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !22 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 7), !dbg !23 + store %String %2, ptr %"Type.name", align 8, !dbg !23 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !23 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !23 + store %Integer %3, ptr %"Type.size", align 8, !dbg !23 + %4 = load %"Type", ptr %1, align 8, !dbg !23 + %5 = call ptr @read_memory(%"Type" %4, ptr @address), !dbg !24 + store ptr %5, ptr @x_mut_ref, align 8, !dbg !24 + br label %return, !dbg !24 return: ; preds = %0 ret void @@ -129,6 +94,8 @@ return: ; preds = %0 declare ptr @read_memory(%"Type", ptr) +declare %String @string_from_c_string_and_length(ptr, i64) + declare void @destroy_integer(ptr) !llvm.module.flags = !{!0} @@ -137,31 +104,25 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 7, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 4, column: 16, scope: !9) -!11 = !DILocation(line: 0, scope: !9) -!12 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 7, scope: !12) -!14 = !DILocation(line: 4, column: 16, scope: !12) -!15 = !DILocation(line: 0, column: 8, scope: !12) -!16 = !DILocation(line: 1, column: 8, scope: !12) -!17 = !DILocation(line: 3, column: 14, scope: !12) -!18 = !DILocation(line: 5, scope: !12) -!19 = !DILocation(line: 5, column: 12, scope: !12) -!20 = !DILocation(line: 6, column: 8, scope: !12) -!21 = !DILocation(line: 0, scope: !12) -!22 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !12, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 0, column: 8, scope: !22) -!24 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !12, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!25 = !DILocation(line: 7, scope: !24) -!26 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !12, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!27 = !DILocation(line: 3, column: 25, scope: !26) -!28 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !12, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!29 = !DILocation(line: 4, column: 16, scope: !28) -!30 = !DILocation(line: 4, column: 27, scope: !28) +!7 = !DILocation(line: 0, column: 8, scope: !3) +!8 = !DILocation(line: 1, column: 8, scope: !3) +!9 = !DILocation(line: 3, column: 14, scope: !3) +!10 = !DILocation(line: 4, column: 16, scope: !3) +!11 = !DILocation(line: 5, scope: !3) +!12 = !DILocation(line: 5, column: 12, scope: !3) +!13 = !DILocation(line: 6, column: 8, scope: !3) +!14 = !DILocation(line: 0, scope: !3) +!15 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 0, column: 8, scope: !15) +!17 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!18 = !DILocation(line: 7, scope: !17) +!19 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!20 = !DILocation(line: 3, column: 25, scope: !19) +!21 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !3, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 4, column: 16, scope: !21) +!23 = !DILocation(line: 0, scope: !21) +!24 = !DILocation(line: 4, column: 27, scope: !21) diff --git a/src/tests/snapshots/ppl__tests__array.hir.snap b/src/tests/snapshots/ppl__tests__array.hir.snap index 29a54bbf..a5a7ddc0 100644 --- a/src/tests/snapshots/ppl__tests__array.hir.snap +++ b/src/tests/snapshots/ppl__tests__array.hir.snap @@ -2,7 +2,7 @@ source: src/tests/mod.rs expression: hir --- -let mut arr: Array = `<:Type> [ ]`((Type:Type)) +let mut arr: Array = `<:Type> [ ]`(Type { name: "Integer", size: 8 }) `println <:Array>`((arr:Array)) if `<:Reference>> is empty`((&arr:ReferenceMut>)): `println <:String>`("Empty") @@ -30,14 +30,14 @@ fn size of > -> Integer: fn allocate <$arg1: Type> -> MemoryAddress: - let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`((Type:Type)))) + let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) `destroy <:ReferenceMut>`((n:Integer)) return ($tmp@760:MemoryAddress) fn <$arg0: Type> [ ] -> Array: let capacity: Integer = 8 - let data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((capacity:Integer)), (Type:Type)) + let data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((capacity:Integer)), Type { name: "Integer", size: 8 }) let $tmp@273: Array = Array { size: 0, capacity: `clone <:Reference>`((capacity:Integer)), data: (data:MemoryAddress) } `destroy <:ReferenceMut>`((capacity:Integer)) return ($tmp@273:Array) @@ -83,7 +83,7 @@ fn size of > -> Integer: fn allocate <$arg1: Type> -> MemoryAddress: - let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`((Type:Type)))) + let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) `destroy <:ReferenceMut>`((n:Integer)) return ($tmp@760:MemoryAddress) @@ -92,10 +92,10 @@ fn allocate <$arg1: Type> -> MemoryAddress: fn address of > -> MemoryAddress fn push to >> -> None: - let bytes: Integer = `size of <:Type>`((Type:Type)) + let bytes: Integer = `size of <:Type>`(Type { name: "Integer", size: 8 }) if `<:Integer> == <:Integer>`(`clone <:Reference>`((*array:Array).size), `clone <:Reference>`((*array:Array).capacity)): let new_capacity: Integer = `<:Integer> * <:Integer>`(`clone <:Reference>`((*array:Array).capacity), 2) - let new_data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((new_capacity:Integer)), (Type:Type)) + let new_data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((new_capacity:Integer)), Type { name: "Integer", size: 8 }) let mut i: Integer = 0 while `<:Integer> < <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((*array:Array).size)): let offset: Integer = `<:Integer> * <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((bytes:Integer))) @@ -162,8 +162,8 @@ fn > at > -> Refere fn >> [ ] -> ReferenceMut: let $tmp@630: String = "Index out of bounds" `assert <:Bool> <:Reference>`(`<:Bool> and <:Bool>`(`<:Integer> <= <:Integer>`(0, `clone <:Reference>`((i:Integer))), `<:Integer> < <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((*array:Array).size))), (&$tmp@630:Reference)) - let address: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `<:Integer> * <:Integer>`(`clone <:Reference>`((i:Integer)), `size of <:Type>`((Type:Type)))) - let mut $tmp@704: ReferenceMut = `<:Type> at <:Reference>`((Type:Type), (&address:Reference)) + let address: MemoryAddress = `<:MemoryAddress> + <:Integer>`((*array:Array).data, `<:Integer> * <:Integer>`(`clone <:Reference>`((i:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) + let mut $tmp@704: ReferenceMut = `<:Type> at <:Reference>`(Type { name: "Integer", size: 8 }, (&address:Reference)) `destroy <:ReferenceMut>`((i:Integer)) `destroy <:ReferenceMut>`(($tmp@630:String)) return ($tmp@704:ReferenceMut) @@ -204,7 +204,7 @@ fn size of > -> Integer: fn allocate <$arg1: Type> -> MemoryAddress: - let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`((Type:Type)))) + let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) `destroy <:ReferenceMut>`((n:Integer)) return ($tmp@760:MemoryAddress) @@ -213,10 +213,10 @@ fn allocate <$arg1: Type> -> MemoryAddress: fn address of > -> MemoryAddress fn push to >> -> None: - let bytes: Integer = `size of <:Type>`((Type:Type)) + let bytes: Integer = `size of <:Type>`(Type { name: "Integer", size: 8 }) if `<:Integer> == <:Integer>`(`clone <:Reference>`((*array:Array).size), `clone <:Reference>`((*array:Array).capacity)): let new_capacity: Integer = `<:Integer> * <:Integer>`(`clone <:Reference>`((*array:Array).capacity), 2) - let new_data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((new_capacity:Integer)), (Type:Type)) + let new_data: MemoryAddress = `allocate <:Integer> <:Type>`(`clone <:Reference>`((new_capacity:Integer)), Type { name: "Integer", size: 8 }) let mut i: Integer = 0 while `<:Integer> < <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((*array:Array).size)): let offset: Integer = `<:Integer> * <:Integer>`(`clone <:Reference>`((i:Integer)), `clone <:Reference>`((bytes:Integer))) diff --git a/src/tests/snapshots/ppl__tests__clone.ir.snap b/src/tests/snapshots/ppl__tests__clone.ir.snap index b2bc81dc..352beebf 100644 --- a/src/tests/snapshots/ppl__tests__clone.ir.snap +++ b/src/tests/snapshots/ppl__tests__clone.ir.snap @@ -5,76 +5,52 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @x = global %Integer zeroinitializer @y = global %Integer zeroinitializer -@1 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +@0 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 + +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @initialize.1(), !dbg !8 + %1 = call %Integer @clone_integer(ptr @x), !dbg !9 + call void @"println <:Integer>"(%Integer %1), !dbg !9 + %2 = call %Integer @clone_integer(ptr @y), !dbg !10 + call void @"println <:Integer>"(%Integer %2), !dbg !10 + %3 = call %String @string_from_c_string_and_length(ptr @0, i64 0), !dbg !11 + call void @"println <:String>"(%String %3), !dbg !11 + call void @destroy_integer(ptr @y), !dbg !12 + %4 = call %Integer @integer_from_i64(i64 2), !dbg !13 + store %Integer %4, ptr @y, align 8, !dbg !13 + %5 = call %Integer @clone_integer(ptr @x), !dbg !14 + call void @"println <:Integer>"(%Integer %5), !dbg !14 + %6 = call %Integer @clone_integer(ptr @y), !dbg !15 + call void @"println <:Integer>"(%Integer %6), !dbg !15 + call void @destroy_integer(ptr @x), !dbg !16 + call void @destroy_integer(ptr @y), !dbg !17 + br label %return, !dbg !17 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - call void @initialize.2(), !dbg !12 - %1 = call %Integer @clone_integer(ptr @x), !dbg !13 - call void @"println <:Integer>"(%Integer %1), !dbg !13 - %2 = call %Integer @clone_integer(ptr @y), !dbg !14 - call void @"println <:Integer>"(%Integer %2), !dbg !14 - %3 = call %String @string_from_c_string_and_length(ptr @1, i64 0), !dbg !15 - call void @"println <:String>"(%String %3), !dbg !15 - call void @destroy_integer(ptr @y), !dbg !16 - %4 = call %Integer @integer_from_i64(i64 2), !dbg !17 - store %Integer %4, ptr @y, align 8, !dbg !17 - %5 = call %Integer @clone_integer(ptr @x), !dbg !18 - call void @"println <:Integer>"(%Integer %5), !dbg !18 - %6 = call %Integer @clone_integer(ptr @y), !dbg !19 - call void @"println <:Integer>"(%Integer %6), !dbg !19 - call void @destroy_integer(ptr @x), !dbg !20 - call void @destroy_integer(ptr @y), !dbg !21 - br label %return, !dbg !21 +define private void @initialize() !dbg !18 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !19 + store %Integer %1, ptr @x, align 8, !dbg !19 + br label %return, !dbg !19 return: ; preds = %0 ret void } -define private void @initialize.1() !dbg !22 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !23 - store %Integer %1, ptr @x, align 8, !dbg !23 - br label %return, !dbg !23 - -return: ; preds = %0 - ret void -} +declare %Integer @integer_from_i64(i64) -define private void @initialize.2() !dbg !24 { - %1 = call %Integer @clone_integer(ptr @x), !dbg !25 - store %Integer %1, ptr @y, align 8, !dbg !25 - br label %return, !dbg !25 +define private void @initialize.1() !dbg !20 { + %1 = call %Integer @clone_integer(ptr @x), !dbg !21 + store %Integer %1, ptr @y, align 8, !dbg !21 + br label %return, !dbg !21 return: ; preds = %0 ret void @@ -82,13 +58,13 @@ return: ; preds = %0 declare %Integer @clone_integer(ptr) -define private void @"println <:Integer>"(%Integer %0) !dbg !26 { +define private void @"println <:Integer>"(%Integer %0) !dbg !22 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !27 - %3 = call %String @integer_as_string(%Integer %2), !dbg !27 - call void @"println <:String>"(%String %3), !dbg !27 - br label %return, !dbg !27 + %2 = load %Integer, ptr %x, align 8, !dbg !23 + %3 = call %String @integer_as_string(%Integer %2), !dbg !23 + call void @"println <:String>"(%String %3), !dbg !23 + br label %return, !dbg !23 return: ; preds = %1 ret void @@ -98,6 +74,8 @@ declare void @"println <:String>"(%String) declare %String @integer_as_string(%Integer) +declare %String @string_from_c_string_and_length(ptr, i64) + declare void @destroy_integer(ptr) !llvm.module.flags = !{!0} @@ -106,28 +84,24 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 10, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 10, scope: !9) -!11 = !DILocation(line: 0, column: 8, scope: !9) -!12 = !DILocation(line: 1, column: 12, scope: !9) -!13 = !DILocation(line: 2, column: 8, scope: !9) -!14 = !DILocation(line: 3, column: 8, scope: !9) -!15 = !DILocation(line: 5, column: 8, scope: !9) -!16 = !DILocation(line: 7, scope: !9) -!17 = !DILocation(line: 7, column: 4, scope: !9) -!18 = !DILocation(line: 8, column: 8, scope: !9) -!19 = !DILocation(line: 9, column: 8, scope: !9) -!20 = !DILocation(line: 0, scope: !9) -!21 = !DILocation(line: 1, scope: !9) -!22 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 0, column: 8, scope: !22) -!24 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !9, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!25 = !DILocation(line: 1, column: 12, scope: !24) -!26 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !9, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!27 = !DILocation(line: 10, scope: !26) +!7 = !DILocation(line: 0, column: 8, scope: !3) +!8 = !DILocation(line: 1, column: 12, scope: !3) +!9 = !DILocation(line: 2, column: 8, scope: !3) +!10 = !DILocation(line: 3, column: 8, scope: !3) +!11 = !DILocation(line: 5, column: 8, scope: !3) +!12 = !DILocation(line: 7, scope: !3) +!13 = !DILocation(line: 7, column: 4, scope: !3) +!14 = !DILocation(line: 8, column: 8, scope: !3) +!15 = !DILocation(line: 9, column: 8, scope: !3) +!16 = !DILocation(line: 0, scope: !3) +!17 = !DILocation(line: 1, scope: !3) +!18 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 0, column: 8, scope: !18) +!20 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!21 = !DILocation(line: 1, column: 12, scope: !20) +!22 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!23 = !DILocation(line: 10, scope: !22) diff --git a/src/tests/snapshots/ppl__tests__common_functions.ir.snap b/src/tests/snapshots/ppl__tests__common_functions.ir.snap index e4e1e3e5..97cca83a 100644 --- a/src/tests/snapshots/ppl__tests__common_functions.ir.snap +++ b/src/tests/snapshots/ppl__tests__common_functions.ir.snap @@ -5,49 +5,22 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -%Integer = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@1 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 +@0 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +define void @main.execute() !dbg !3 { + call void @foo(), !dbg !7 + br label %return, !dbg !7 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @foo(), !dbg !11 - br label %return, !dbg !11 - -return: ; preds = %0 - ret void -} - -define void @foo() !dbg !12 { - %1 = call %String @string_from_c_string_and_length(ptr @1, i64 3), !dbg !13 - call void @"println <:String>"(%String %1), !dbg !13 - br label %return, !dbg !14 +define void @foo() !dbg !8 { + %1 = call %String @string_from_c_string_and_length(ptr @0, i64 3), !dbg !9 + call void @"println <:String>"(%String %1), !dbg !9 + br label %return, !dbg !10 return: ; preds = %0 ret void @@ -55,21 +28,19 @@ return: ; preds = %0 declare void @"println <:String>"(%String) +declare %String @string_from_c_string_and_length(ptr, i64) + !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 1, column: 5, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 1, column: 5, scope: !9) -!11 = !DILocation(line: 1, scope: !9) -!12 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 0, column: 18, scope: !12) -!14 = !DILocation(line: 0, column: 10, scope: !12) +!7 = !DILocation(line: 1, scope: !3) +!8 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!9 = !DILocation(line: 0, column: 18, scope: !8) +!10 = !DILocation(line: 0, column: 10, scope: !8) diff --git a/src/tests/snapshots/ppl__tests__consume_greater.ir.snap b/src/tests/snapshots/ppl__tests__consume_greater.ir.snap index 2178620c..7db3af41 100644 --- a/src/tests/snapshots/ppl__tests__consume_greater.ir.snap +++ b/src/tests/snapshots/ppl__tests__consume_greater.ir.snap @@ -5,64 +5,34 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } -%Integer = type { ptr } %"Point" = type { ptr } %"PointImpl" = type { %Integer } +%Integer = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 +define void @main.execute() !dbg !3 { + %1 = alloca %"Point", align 8, !dbg !7 + %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !7 + %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !7 + %2 = call %Integer @integer_from_i64(i64 1), !dbg !8 + store %Integer %2, ptr %"Point.x", align 8, !dbg !8 + %3 = load %"Point", ptr %1, align 8, !dbg !8 br label %return, !dbg !8 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - declare %Integer @integer_from_i64(i64) -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - %1 = alloca %"Point", align 8, !dbg !11 - %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !11 - %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !11 - %2 = call %Integer @integer_from_i64(i64 1), !dbg !12 - store %Integer %2, ptr %"Point.x", align 8, !dbg !12 - %3 = load %"Point", ptr %1, align 8, !dbg !12 - br label %return, !dbg !12 - -return: ; preds = %0 - ret void -} - !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 3, column: 23, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 3, column: 23, scope: !9) -!11 = !DILocation(line: 3, scope: !9) -!12 = !DILocation(line: 3, column: 20, scope: !9) +!7 = !DILocation(line: 3, scope: !3) +!8 = !DILocation(line: 3, column: 20, scope: !3) diff --git a/src/tests/snapshots/ppl__tests__deps.ir.snap b/src/tests/snapshots/ppl__tests__deps.ir.snap index 2d15cc17..270b18ad 100644 --- a/src/tests/snapshots/ppl__tests__deps.ir.snap +++ b/src/tests/snapshots/ppl__tests__deps.ir.snap @@ -5,39 +5,9 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } -%Integer = type { ptr } - -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @"say hello"(), !dbg !11 - br label %return, !dbg !11 +define void @main.execute() !dbg !3 { + call void @"say hello"(), !dbg !7 + br label %return, !dbg !7 return: ; preds = %0 ret void @@ -51,12 +21,8 @@ declare void @"say hello"() !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 3, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 3, scope: !9) -!11 = !DILocation(line: 2, scope: !9) +!7 = !DILocation(line: 2, scope: !3) diff --git a/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap b/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap index 936a5f6f..e65bf666 100644 --- a/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap +++ b/src/tests/snapshots/ppl__tests__deref_member_ref.ir.snap @@ -5,62 +5,36 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %Point = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } %Integer = type { ptr } %PointImpl = type { %Integer, %Integer } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @"$tmp@80" = global %Point zeroinitializer -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - %1 = call %Integer @"x of <:Reference>"(ptr @"$tmp@80"), !dbg !11 - call void @"println <:Integer>"(%Integer %1), !dbg !11 - br label %return, !dbg !11 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + %1 = call %Integer @"x of <:Reference>"(ptr @"$tmp@80"), !dbg !7 + call void @"println <:Integer>"(%Integer %1), !dbg !7 + br label %return, !dbg !7 return: ; preds = %0 ret void } -define %Integer @"x of <:Reference>"(ptr %0) !dbg !12 { +define %Integer @"x of <:Reference>"(ptr %0) !dbg !8 { %return_value = alloca %Integer, align 8 %p = alloca ptr, align 8 store ptr %0, ptr %p, align 8 - %2 = load ptr, ptr %p, align 8, !dbg !13 - %3 = getelementptr inbounds %Point, ptr %2, i32 0, i32 0, !dbg !13 - %x = getelementptr inbounds %PointImpl, ptr %3, i32 0, i32 0, !dbg !13 - %4 = call %Integer @clone_integer(ptr %x), !dbg !13 - %"$tmp@61" = alloca %Integer, align 8, !dbg !13 - store %Integer %4, ptr %"$tmp@61", align 8, !dbg !13 - %5 = load %Integer, ptr %"$tmp@61", align 8, !dbg !13 - store %Integer %5, ptr %return_value, align 8, !dbg !13 - br label %return, !dbg !13 + %2 = load ptr, ptr %p, align 8, !dbg !9 + %3 = getelementptr inbounds %Point, ptr %2, i32 0, i32 0, !dbg !9 + %x = getelementptr inbounds %PointImpl, ptr %3, i32 0, i32 0, !dbg !9 + %4 = call %Integer @clone_integer(ptr %x), !dbg !9 + %"$tmp@61" = alloca %Integer, align 8, !dbg !9 + store %Integer %4, ptr %"$tmp@61", align 8, !dbg !9 + %5 = load %Integer, ptr %"$tmp@61", align 8, !dbg !9 + store %Integer %5, ptr %return_value, align 8, !dbg !9 + br label %return, !dbg !9 return: ; preds = %1 %6 = load %Integer, ptr %return_value, align 8 @@ -69,30 +43,32 @@ return: ; preds = %1 declare %Integer @clone_integer(ptr) -define private void @initialize.1() !dbg !14 { - %1 = alloca %Point, align 8, !dbg !15 - %Point.data = getelementptr inbounds %Point, ptr %1, i32 0, i32 0, !dbg !15 - %Point.x = getelementptr inbounds %PointImpl, ptr %Point.data, i32 0, i32 0, !dbg !15 - %2 = call %Integer @integer_from_i64(i64 1), !dbg !16 - store %Integer %2, ptr %Point.x, align 8, !dbg !16 - %Point.y = getelementptr inbounds %PointImpl, ptr %Point.data, i32 0, i32 1, !dbg !16 - %3 = call %Integer @integer_from_i64(i64 2), !dbg !17 - store %Integer %3, ptr %Point.y, align 8, !dbg !17 - %4 = load %Point, ptr %1, align 8, !dbg !17 - store %Point %4, ptr @"$tmp@80", align 8, !dbg !17 - br label %return, !dbg !17 +define private void @initialize() !dbg !10 { + %1 = alloca %Point, align 8, !dbg !11 + %Point.data = getelementptr inbounds %Point, ptr %1, i32 0, i32 0, !dbg !11 + %Point.x = getelementptr inbounds %PointImpl, ptr %Point.data, i32 0, i32 0, !dbg !11 + %2 = call %Integer @integer_from_i64(i64 1), !dbg !12 + store %Integer %2, ptr %Point.x, align 8, !dbg !12 + %Point.y = getelementptr inbounds %PointImpl, ptr %Point.data, i32 0, i32 1, !dbg !12 + %3 = call %Integer @integer_from_i64(i64 2), !dbg !13 + store %Integer %3, ptr %Point.y, align 8, !dbg !13 + %4 = load %Point, ptr %1, align 8, !dbg !13 + store %Point %4, ptr @"$tmp@80", align 8, !dbg !13 + br label %return, !dbg !13 return: ; preds = %0 ret void } -define private void @"println <:Integer>"(%Integer %0) !dbg !18 { +declare %Integer @integer_from_i64(i64) + +define private void @"println <:Integer>"(%Integer %0) !dbg !14 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !19 - %3 = call %String @integer_as_string(%Integer %2), !dbg !19 - call void @"println <:String>"(%String %3), !dbg !19 - br label %return, !dbg !19 + %2 = load %Integer, ptr %x, align 8, !dbg !15 + %3 = call %String @integer_as_string(%Integer %2), !dbg !15 + call void @"println <:String>"(%String %3), !dbg !15 + br label %return, !dbg !15 return: ; preds = %1 ret void @@ -108,20 +84,16 @@ declare %String @integer_as_string(%Integer) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 5, column: 34, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 5, column: 34, scope: !9) -!11 = !DILocation(line: 5, column: 14, scope: !9) -!12 = distinct !DISubprogram(name: "x of <:Reference>", linkageName: "x of <:Reference>", scope: !9, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 3, column: 33, scope: !12) -!14 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!15 = !DILocation(line: 5, column: 14, scope: !14) -!16 = !DILocation(line: 5, column: 25, scope: !14) -!17 = !DILocation(line: 5, column: 31, scope: !14) -!18 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !9, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!19 = !DILocation(line: 5, column: 34, scope: !18) +!7 = !DILocation(line: 5, column: 14, scope: !3) +!8 = distinct !DISubprogram(name: "x of <:Reference>", linkageName: "x of <:Reference>", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!9 = !DILocation(line: 3, column: 33, scope: !8) +!10 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!11 = !DILocation(line: 5, column: 14, scope: !10) +!12 = !DILocation(line: 5, column: 25, scope: !10) +!13 = !DILocation(line: 5, column: 31, scope: !10) +!14 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!15 = !DILocation(line: 5, column: 34, scope: !14) diff --git a/src/tests/snapshots/ppl__tests__destructor.ir.snap b/src/tests/snapshots/ppl__tests__destructor.ir.snap index b48b9496..4fed4710 100644 --- a/src/tests/snapshots/ppl__tests__destructor.ir.snap +++ b/src/tests/snapshots/ppl__tests__destructor.ir.snap @@ -5,61 +5,34 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %DestructibleClass = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -%Integer = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@1 = private unnamed_addr constant [11 x i8] c"destructor\00", align 1 +@0 = private unnamed_addr constant [11 x i8] c"destructor\00", align 1 @x = global %DestructibleClass zeroinitializer -@2 = private unnamed_addr constant [5 x i8] c"done\00", align 1 +@1 = private unnamed_addr constant [5 x i8] c"done\00", align 1 -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @"destroy <:ReferenceMut>"(ptr @x), !dbg !8 + %1 = alloca %DestructibleClass, align 8, !dbg !9 + %DestructibleClass.data = getelementptr inbounds %DestructibleClass, ptr %1, i32 0, i32 0, !dbg !9 + store ptr %1, ptr @x, align 8, !dbg !9 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 4), !dbg !10 + call void @"println <:String>"(%String %2), !dbg !10 + call void @"destroy <:ReferenceMut>"(ptr @x), !dbg !11 + br label %return, !dbg !11 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - call void @"destroy <:ReferenceMut>"(ptr @x), !dbg !12 - %1 = alloca %DestructibleClass, align 8, !dbg !13 - %DestructibleClass.data = getelementptr inbounds %DestructibleClass, ptr %1, i32 0, i32 0, !dbg !13 - store ptr %1, ptr @x, align 8, !dbg !13 - %2 = call %String @string_from_c_string_and_length(ptr @2, i64 4), !dbg !14 - call void @"println <:String>"(%String %2), !dbg !14 - call void @"destroy <:ReferenceMut>"(ptr @x), !dbg !15 - br label %return, !dbg !15 - -return: ; preds = %0 - ret void -} - -define void @"destroy <:ReferenceMut>"(ptr %0) !dbg !16 { +define void @"destroy <:ReferenceMut>"(ptr %0) !dbg !12 { %"$arg0" = alloca ptr, align 8 store ptr %0, ptr %"$arg0", align 8 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 10), !dbg !17 - call void @"println <:String>"(%String %2), !dbg !17 - br label %return, !dbg !18 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 10), !dbg !13 + call void @"println <:String>"(%String %2), !dbg !13 + br label %return, !dbg !14 return: ; preds = %1 ret void @@ -67,11 +40,13 @@ return: ; preds = %1 declare void @"println <:String>"(%String) -define private void @initialize.1() !dbg !19 { - %1 = alloca %DestructibleClass, align 8, !dbg !20 - %DestructibleClass.data = getelementptr inbounds %DestructibleClass, ptr %1, i32 0, i32 0, !dbg !20 - store ptr %1, ptr @x, align 8, !dbg !20 - br label %return, !dbg !20 +declare %String @string_from_c_string_and_length(ptr, i64) + +define private void @initialize() !dbg !15 { + %1 = alloca %DestructibleClass, align 8, !dbg !16 + %DestructibleClass.data = getelementptr inbounds %DestructibleClass, ptr %1, i32 0, i32 0, !dbg !16 + store ptr %1, ptr @x, align 8, !dbg !16 + br label %return, !dbg !16 return: ; preds = %0 ret void @@ -83,21 +58,17 @@ return: ; preds = %0 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 5, column: 16, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 5, column: 16, scope: !9) -!11 = !DILocation(line: 4, column: 12, scope: !9) -!12 = !DILocation(line: 5, scope: !9) -!13 = !DILocation(line: 5, column: 4, scope: !9) -!14 = !DILocation(line: 7, column: 8, scope: !9) -!15 = !DILocation(line: 4, scope: !9) -!16 = distinct !DISubprogram(name: "destroy <:ReferenceMut>", linkageName: "destroy <:ReferenceMut>", scope: !9, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!17 = !DILocation(line: 2, column: 48, scope: !16) -!18 = !DILocation(line: 2, column: 40, scope: !16) -!19 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!20 = !DILocation(line: 4, column: 12, scope: !19) +!7 = !DILocation(line: 4, column: 12, scope: !3) +!8 = !DILocation(line: 5, scope: !3) +!9 = !DILocation(line: 5, column: 4, scope: !3) +!10 = !DILocation(line: 7, column: 8, scope: !3) +!11 = !DILocation(line: 4, scope: !3) +!12 = distinct !DISubprogram(name: "destroy <:ReferenceMut>", linkageName: "destroy <:ReferenceMut>", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 48, scope: !12) +!14 = !DILocation(line: 2, column: 40, scope: !12) +!15 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 4, column: 12, scope: !15) diff --git a/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap b/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap index df3b7f75..792d093d 100644 --- a/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap +++ b/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap @@ -10,7 +10,7 @@ let a: A = A { } fn type of <$arg0: A> -> Type: - let $tmp@4309: Type = (Type:Type) + let $tmp@4309: Type = Type { name: "A", size: 8 } return ($tmp@4309:Type) diff --git a/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap b/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap index 91e5f347..a46aa5e7 100644 --- a/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap +++ b/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap @@ -5,88 +5,43 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"Type" = type { ptr } %A = type { ptr } -%"TypeImpl" = type { %String, %Integer } +%"Type" = type { ptr } %String = type { ptr } -%Integer = type { ptr } %"TypeImpl" = type { %String, %Integer } +%Integer = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@"Type" = private global %"Type" zeroinitializer -@1 = private unnamed_addr constant [2 x i8] c"A\00", align 1 @a = global %A zeroinitializer +@0 = private unnamed_addr constant [2 x i8] c"A\00", align 1 -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + %1 = load %A, ptr @a, align 8, !dbg !8 + %2 = call %"Type" @"type of <:A>"(%A %1), !dbg !8 + call void @"println <:Type>"(%"Type" %2), !dbg !8 br label %return, !dbg !8 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define private void @initialize.1() !dbg !9 { - %1 = alloca %"Type", align 8, !dbg !10 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 1), !dbg !11 - store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 - store %Integer %3, ptr %"Type.size", align 8, !dbg !11 - %4 = load %"Type", ptr %1, align 8, !dbg !11 - store %"Type" %4, ptr @"Type", align 8, !dbg !11 - br label %return, !dbg !11 - -return: ; preds = %0 - ret void -} - -define void @main.execute() !dbg !12 { - call void @initialize(), !dbg !13 - call void @initialize.1(), !dbg !13 - call void @initialize.2(), !dbg !14 - %1 = load %A, ptr @a, align 8, !dbg !15 - %2 = call %"Type" @"type of <:A>"(%A %1), !dbg !15 - call void @"println <:Type>"(%"Type" %2), !dbg !15 - br label %return, !dbg !15 +define private void @initialize() !dbg !9 { + %1 = alloca %A, align 8, !dbg !10 + %A.data = getelementptr inbounds %A, ptr %1, i32 0, i32 0, !dbg !10 + store ptr %1, ptr @a, align 8, !dbg !10 + br label %return, !dbg !10 return: ; preds = %0 ret void } -define private void @initialize.2() !dbg !16 { - %1 = alloca %A, align 8, !dbg !17 - %A.data = getelementptr inbounds %A, ptr %1, i32 0, i32 0, !dbg !17 - store ptr %1, ptr @a, align 8, !dbg !17 - br label %return, !dbg !17 - -return: ; preds = %0 - ret void -} - -define private void @"println <:Type>"(%"Type" %0) !dbg !18 { +define private void @"println <:Type>"(%"Type" %0) !dbg !11 { %x = alloca %"Type", align 8 store %"Type" %0, ptr %x, align 8 - %2 = load %"Type", ptr %x, align 8, !dbg !19 - %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !19 - call void @"println <:String>"(%String %3), !dbg !19 - br label %return, !dbg !19 + %2 = load %"Type", ptr %x, align 8, !dbg !12 + %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !12 + call void @"println <:String>"(%String %3), !dbg !12 + br label %return, !dbg !12 return: ; preds = %1 ret void @@ -94,18 +49,18 @@ return: ; preds = %1 declare void @"println <:String>"(%String) -define private %String @"String from <:Type>"(%"Type" %0) !dbg !20 { +define private %String @"String from <:Type>"(%"Type" %0) !dbg !13 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !21 - %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !21 - %3 = call %String @clone_string(ptr %name), !dbg !21 - %"$tmp@4184" = alloca %String, align 8, !dbg !21 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !21 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !21 - store %String %4, ptr %return_value, align 8, !dbg !21 - br label %return, !dbg !21 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !14 + %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !14 + %3 = call %String @clone_string(ptr %name), !dbg !14 + %"$tmp@4184" = alloca %String, align 8, !dbg !14 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !14 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !14 + store %String %4, ptr %return_value, align 8, !dbg !14 + br label %return, !dbg !14 return: ; preds = %1 %5 = load %String, ptr %return_value, align 8 @@ -114,46 +69,52 @@ return: ; preds = %1 declare %String @clone_string(ptr) -define private %"Type" @"type of <:A>"(%A %0) !dbg !22 { +define private %"Type" @"type of <:A>"(%A %0) !dbg !15 { %return_value = alloca %"Type", align 8 %"$arg0" = alloca %A, align 8 store %A %0, ptr %"$arg0", align 8 - %2 = load %"Type", ptr @"Type", align 8, !dbg !23 - %"$tmp@4309" = alloca %"Type", align 8, !dbg !23 - store %"Type" %2, ptr %"$tmp@4309", align 8, !dbg !23 - %3 = load %"Type", ptr %"$tmp@4309", align 8, !dbg !23 - store %"Type" %3, ptr %return_value, align 8, !dbg !23 - br label %return, !dbg !23 + %2 = alloca %"Type", align 8, !dbg !16 + %"Type.data" = getelementptr inbounds %"Type", ptr %2, i32 0, i32 0, !dbg !16 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !16 + %3 = call %String @string_from_c_string_and_length(ptr @0, i64 1), !dbg !17 + store %String %3, ptr %"Type.name", align 8, !dbg !17 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !17 + %4 = call %Integer @integer_from_i64(i64 8), !dbg !17 + store %Integer %4, ptr %"Type.size", align 8, !dbg !17 + %5 = load %"Type", ptr %2, align 8, !dbg !17 + %"$tmp@4309" = alloca %"Type", align 8, !dbg !17 + store %"Type" %5, ptr %"$tmp@4309", align 8, !dbg !17 + %6 = load %"Type", ptr %"$tmp@4309", align 8, !dbg !16 + store %"Type" %6, ptr %return_value, align 8, !dbg !16 + br label %return, !dbg !16 return: ; preds = %1 - %4 = load %"Type", ptr %return_value, align 8 - ret %"Type" %4 + %7 = load %"Type", ptr %return_value, align 8 + ret %"Type" %7 } +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 2, column: 21, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 2, column: 21, scope: !9) -!11 = !DILocation(line: 0, scope: !9) -!12 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 2, column: 21, scope: !12) -!14 = !DILocation(line: 1, column: 8, scope: !12) -!15 = !DILocation(line: 2, column: 19, scope: !12) -!16 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !12, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!17 = !DILocation(line: 1, column: 8, scope: !16) -!18 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !12, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!19 = !DILocation(line: 2, column: 21, scope: !18) -!20 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !18, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!21 = !DILocation(line: 2, column: 21, scope: !20) -!22 = distinct !DISubprogram(name: "type of <:A>", linkageName: "type of <:A>", scope: !12, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 2, column: 21, scope: !22) +!7 = !DILocation(line: 1, column: 8, scope: !3) +!8 = !DILocation(line: 2, column: 19, scope: !3) +!9 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 1, column: 8, scope: !9) +!11 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!12 = !DILocation(line: 2, column: 21, scope: !11) +!13 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !11, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!14 = !DILocation(line: 2, column: 21, scope: !13) +!15 = distinct !DISubprogram(name: "type of <:A>", linkageName: "type of <:A>", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 2, column: 21, scope: !15) +!17 = !DILocation(line: 0, scope: !15) diff --git a/src/tests/snapshots/ppl__tests__escaped_id.ir.snap b/src/tests/snapshots/ppl__tests__escaped_id.ir.snap index b64a2deb..08852644 100644 --- a/src/tests/snapshots/ppl__tests__escaped_id.ir.snap +++ b/src/tests/snapshots/ppl__tests__escaped_id.ir.snap @@ -5,57 +5,32 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @if = global %Integer zeroinitializer -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @destroy_integer(ptr @if), !dbg !8 + %1 = call %Integer @integer_from_i64(i64 2), !dbg !9 + store %Integer %1, ptr @if, align 8, !dbg !9 + call void @destroy_integer(ptr @if), !dbg !10 + br label %return, !dbg !10 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - call void @destroy_integer(ptr @if), !dbg !12 - %1 = call %Integer @integer_from_i64(i64 2), !dbg !13 - store %Integer %1, ptr @if, align 8, !dbg !13 - call void @destroy_integer(ptr @if), !dbg !14 - br label %return, !dbg !14 +define private void @initialize() !dbg !11 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !12 + store %Integer %1, ptr @if, align 8, !dbg !12 + br label %return, !dbg !12 return: ; preds = %0 ret void } -define private void @initialize.1() !dbg !15 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !16 - store %Integer %1, ptr @if, align 8, !dbg !16 - br label %return, !dbg !16 - -return: ; preds = %0 - ret void -} +declare %Integer @integer_from_i64(i64) declare void @destroy_integer(ptr) @@ -65,17 +40,13 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 1, column: 8, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 1, column: 8, scope: !9) -!11 = !DILocation(line: 0, column: 15, scope: !9) -!12 = !DILocation(line: 1, scope: !9) -!13 = !DILocation(line: 1, column: 7, scope: !9) -!14 = !DILocation(line: 0, scope: !9) -!15 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 0, column: 15, scope: !15) +!7 = !DILocation(line: 0, column: 15, scope: !3) +!8 = !DILocation(line: 1, scope: !3) +!9 = !DILocation(line: 1, column: 7, scope: !3) +!10 = !DILocation(line: 0, scope: !3) +!11 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!12 = !DILocation(line: 0, column: 15, scope: !11) diff --git a/src/tests/snapshots/ppl__tests__generics.ir.snap b/src/tests/snapshots/ppl__tests__generics.ir.snap index 3519c298..9856bdda 100644 --- a/src/tests/snapshots/ppl__tests__generics.ir.snap +++ b/src/tests/snapshots/ppl__tests__generics.ir.snap @@ -5,111 +5,87 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %"Point" = type { ptr } %"PointImpl" = type { %Integer, %Integer } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @x = global %Integer zeroinitializer -@1 = private unnamed_addr constant [6 x i8] c"hello\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +@0 = private unnamed_addr constant [6 x i8] c"hello\00", align 1 + +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + %1 = call %Integer @clone_integer(ptr @x), !dbg !8 + %2 = call %Integer @integer_from_i64(i64 0), !dbg !9 + %3 = call i1 @integer_eq_integer(%Integer %1, %Integer %2), !dbg !9 + call void @"println <:Bool>"(i1 %3), !dbg !9 + %4 = call %Integer @integer_from_i64(i64 1), !dbg !10 + %5 = call %Integer @"id <:Integer>"(%Integer %4), !dbg !10 + %6 = call %Integer @integer_from_i64(i64 1), !dbg !11 + %7 = call i1 @integer_eq_integer(%Integer %5, %Integer %6), !dbg !11 + call void @"println <:Bool>"(i1 %7), !dbg !11 + %8 = call %String @string_from_c_string_and_length(ptr @0, i64 5), !dbg !12 + %9 = call %String @"id <:String>"(%String %8), !dbg !12 + call void @"println <:String>"(%String %9), !dbg !12 + %10 = alloca %"Point", align 8, !dbg !13 + %"Point.data" = getelementptr inbounds %"Point", ptr %10, i32 0, i32 0, !dbg !13 + %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !13 + %11 = call %Integer @integer_from_i64(i64 0), !dbg !14 + store %Integer %11, ptr %"Point.x", align 8, !dbg !14 + %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !14 + %12 = call %Integer @integer_from_i64(i64 0), !dbg !15 + store %Integer %12, ptr %"Point.y", align 8, !dbg !15 + %13 = load %"Point", ptr %10, align 8, !dbg !15 + %14 = call %"Point" @"id <:Point>"(%"Point" %13), !dbg !15 + call void @destroy_integer(ptr @x), !dbg !16 + br label %return, !dbg !16 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - %1 = call %Integer @clone_integer(ptr @x), !dbg !12 - %2 = call %Integer @integer_from_i64(i64 0), !dbg !13 - %3 = call i1 @integer_eq_integer(%Integer %1, %Integer %2), !dbg !13 - call void @"println <:Bool>"(i1 %3), !dbg !13 - %4 = call %Integer @integer_from_i64(i64 1), !dbg !14 - %5 = call %Integer @"id <:Integer>"(%Integer %4), !dbg !14 - %6 = call %Integer @integer_from_i64(i64 1), !dbg !15 - %7 = call i1 @integer_eq_integer(%Integer %5, %Integer %6), !dbg !15 - call void @"println <:Bool>"(i1 %7), !dbg !15 - %8 = call %String @string_from_c_string_and_length(ptr @1, i64 5), !dbg !16 - %9 = call %String @"id <:String>"(%String %8), !dbg !16 - call void @"println <:String>"(%String %9), !dbg !16 - %10 = alloca %"Point", align 8, !dbg !17 - %"Point.data" = getelementptr inbounds %"Point", ptr %10, i32 0, i32 0, !dbg !17 - %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !17 - %11 = call %Integer @integer_from_i64(i64 0), !dbg !18 - store %Integer %11, ptr %"Point.x", align 8, !dbg !18 - %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !18 - %12 = call %Integer @integer_from_i64(i64 0), !dbg !19 - store %Integer %12, ptr %"Point.y", align 8, !dbg !19 - %13 = load %"Point", ptr %10, align 8, !dbg !19 - %14 = call %"Point" @"id <:Point>"(%"Point" %13), !dbg !19 - call void @destroy_integer(ptr @x), !dbg !20 +define private void @initialize() !dbg !17 { + %1 = alloca %"Point", align 8, !dbg !18 + %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !18 + %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !18 + %2 = call %Integer @integer_from_i64(i64 0), !dbg !19 + store %Integer %2, ptr %"Point.x", align 8, !dbg !19 + %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !19 + %3 = call %Integer @integer_from_i64(i64 0), !dbg !20 + store %Integer %3, ptr %"Point.y", align 8, !dbg !20 + %4 = load %"Point", ptr %1, align 8, !dbg !20 + %5 = call %Integer @"x of <:Point>"(%"Point" %4), !dbg !20 + store %Integer %5, ptr @x, align 8, !dbg !20 br label %return, !dbg !20 return: ; preds = %0 ret void } -define private void @initialize.1() !dbg !21 { - %1 = alloca %"Point", align 8, !dbg !22 - %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !22 - %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !22 - %2 = call %Integer @integer_from_i64(i64 0), !dbg !23 - store %Integer %2, ptr %"Point.x", align 8, !dbg !23 - %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !23 - %3 = call %Integer @integer_from_i64(i64 0), !dbg !24 - store %Integer %3, ptr %"Point.y", align 8, !dbg !24 - %4 = load %"Point", ptr %1, align 8, !dbg !24 - %5 = call %Integer @"x of <:Point>"(%"Point" %4), !dbg !24 - store %Integer %5, ptr @x, align 8, !dbg !24 - br label %return, !dbg !24 - -return: ; preds = %0 - ret void -} - -define private %Integer @"x of <:Point>"(%"Point" %0) !dbg !25 { +define private %Integer @"x of <:Point>"(%"Point" %0) !dbg !21 { %return_value = alloca %Integer, align 8 %p = alloca %"Point", align 8 store %"Point" %0, ptr %p, align 8 - %2 = getelementptr inbounds %"Point", ptr %p, i32 0, i32 0, !dbg !26 - %x = getelementptr inbounds %"PointImpl", ptr %2, i32 0, i32 0, !dbg !26 - %3 = load %Integer, ptr %x, align 8, !dbg !26 - store %Integer %3, ptr %return_value, align 8, !dbg !26 - br label %return, !dbg !26 + %2 = getelementptr inbounds %"Point", ptr %p, i32 0, i32 0, !dbg !22 + %x = getelementptr inbounds %"PointImpl", ptr %2, i32 0, i32 0, !dbg !22 + %3 = load %Integer, ptr %x, align 8, !dbg !22 + store %Integer %3, ptr %return_value, align 8, !dbg !22 + br label %return, !dbg !22 return: ; preds = %1 %4 = load %Integer, ptr %return_value, align 8 ret %Integer %4 } -define private void @"println <:Bool>"(i1 %0) !dbg !27 { +declare %Integer @integer_from_i64(i64) + +define private void @"println <:Bool>"(i1 %0) !dbg !23 { %x = alloca i1, align 1 store i1 %0, ptr %x, align 1 - %2 = load i1, ptr %x, align 1, !dbg !28 - %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !28 - call void @"println <:String>"(%String %3), !dbg !28 - br label %return, !dbg !29 + %2 = load i1, ptr %x, align 1, !dbg !24 + %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !24 + call void @"println <:String>"(%String %3), !dbg !24 + br label %return, !dbg !25 return: ; preds = %1 ret void @@ -123,39 +99,41 @@ declare i1 @integer_eq_integer(%Integer, %Integer) declare %Integer @clone_integer(ptr) -define private %Integer @"id <:Integer>"(%Integer %0) !dbg !30 { +define private %Integer @"id <:Integer>"(%Integer %0) !dbg !26 { %return_value = alloca %Integer, align 8 %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !31 - store %Integer %2, ptr %return_value, align 8, !dbg !31 - br label %return, !dbg !31 + %2 = load %Integer, ptr %x, align 8, !dbg !27 + store %Integer %2, ptr %return_value, align 8, !dbg !27 + br label %return, !dbg !27 return: ; preds = %1 %3 = load %Integer, ptr %return_value, align 8 ret %Integer %3 } -define private %String @"id <:String>"(%String %0) !dbg !32 { +define private %String @"id <:String>"(%String %0) !dbg !28 { %return_value = alloca %String, align 8 %x = alloca %String, align 8 store %String %0, ptr %x, align 8 - %2 = load %String, ptr %x, align 8, !dbg !33 - store %String %2, ptr %return_value, align 8, !dbg !33 - br label %return, !dbg !33 + %2 = load %String, ptr %x, align 8, !dbg !29 + store %String %2, ptr %return_value, align 8, !dbg !29 + br label %return, !dbg !29 return: ; preds = %1 %3 = load %String, ptr %return_value, align 8 ret %String %3 } -define private %"Point" @"id <:Point>"(%"Point" %0) !dbg !34 { +declare %String @string_from_c_string_and_length(ptr, i64) + +define private %"Point" @"id <:Point>"(%"Point" %0) !dbg !30 { %return_value = alloca %"Point", align 8 %x = alloca %"Point", align 8 store %"Point" %0, ptr %x, align 8 - %2 = load %"Point", ptr %x, align 8, !dbg !35 - store %"Point" %2, ptr %return_value, align 8, !dbg !35 - br label %return, !dbg !35 + %2 = load %"Point", ptr %x, align 8, !dbg !31 + store %"Point" %2, ptr %return_value, align 8, !dbg !31 + br label %return, !dbg !31 return: ; preds = %1 %3 = load %"Point", ptr %return_value, align 8 @@ -170,36 +148,32 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 10, column: 5, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 10, column: 5, scope: !9) -!11 = !DILocation(line: 5, column: 8, scope: !9) -!12 = !DILocation(line: 6, column: 8, scope: !9) -!13 = !DILocation(line: 6, column: 13, scope: !9) -!14 = !DILocation(line: 10, column: 12, scope: !9) -!15 = !DILocation(line: 10, column: 18, scope: !9) -!16 = !DILocation(line: 11, column: 12, scope: !9) -!17 = !DILocation(line: 12, column: 3, scope: !9) -!18 = !DILocation(line: 12, column: 14, scope: !9) -!19 = !DILocation(line: 12, column: 20, scope: !9) -!20 = !DILocation(line: 5, scope: !9) -!21 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!22 = !DILocation(line: 5, column: 13, scope: !21) -!23 = !DILocation(line: 5, column: 24, scope: !21) -!24 = !DILocation(line: 5, column: 30, scope: !21) -!25 = distinct !DISubprogram(name: "x of <:Point>", linkageName: "x of <:Point>", scope: !21, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!26 = !DILocation(line: 3, column: 28, scope: !25) -!27 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !9, file: !2, line: 11, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!28 = !DILocation(line: 13, scope: !27) -!29 = !DILocation(line: 12, column: 5, scope: !27) -!30 = distinct !DISubprogram(name: "id <:Integer>", linkageName: "id <:Integer>", scope: !9, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!7 = !DILocation(line: 5, column: 8, scope: !3) +!8 = !DILocation(line: 6, column: 8, scope: !3) +!9 = !DILocation(line: 6, column: 13, scope: !3) +!10 = !DILocation(line: 10, column: 12, scope: !3) +!11 = !DILocation(line: 10, column: 18, scope: !3) +!12 = !DILocation(line: 11, column: 12, scope: !3) +!13 = !DILocation(line: 12, column: 3, scope: !3) +!14 = !DILocation(line: 12, column: 14, scope: !3) +!15 = !DILocation(line: 12, column: 20, scope: !3) +!16 = !DILocation(line: 5, scope: !3) +!17 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!18 = !DILocation(line: 5, column: 13, scope: !17) +!19 = !DILocation(line: 5, column: 24, scope: !17) +!20 = !DILocation(line: 5, column: 30, scope: !17) +!21 = distinct !DISubprogram(name: "x of <:Point>", linkageName: "x of <:Point>", scope: !17, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 3, column: 28, scope: !21) +!23 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !3, file: !2, line: 11, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!24 = !DILocation(line: 13, scope: !23) +!25 = !DILocation(line: 12, column: 5, scope: !23) +!26 = distinct !DISubprogram(name: "id <:Integer>", linkageName: "id <:Integer>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!27 = !DILocation(line: 8, column: 19, scope: !26) +!28 = distinct !DISubprogram(name: "id <:String>", linkageName: "id <:String>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!29 = !DILocation(line: 8, column: 19, scope: !28) +!30 = distinct !DISubprogram(name: "id <:Point>", linkageName: "id <:Point>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) !31 = !DILocation(line: 8, column: 19, scope: !30) -!32 = distinct !DISubprogram(name: "id <:String>", linkageName: "id <:String>", scope: !9, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!33 = !DILocation(line: 8, column: 19, scope: !32) -!34 = distinct !DISubprogram(name: "id <:Point>", linkageName: "id <:Point>", scope: !9, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!35 = !DILocation(line: 8, column: 19, scope: !34) diff --git a/src/tests/snapshots/ppl__tests__import_all.ir.snap b/src/tests/snapshots/ppl__tests__import_all.ir.snap index bf6cd7cb..d2f91541 100644 --- a/src/tests/snapshots/ppl__tests__import_all.ir.snap +++ b/src/tests/snapshots/ppl__tests__import_all.ir.snap @@ -5,51 +5,24 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } %Integer = type { ptr } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 +define void @main.execute() !dbg !3 { + call void @"do nothing"(), !dbg !7 + call void @"println <:None>"(), !dbg !7 + %1 = call %Integer @"do something"(), !dbg !8 + call void @"println <:Integer>"(%Integer %1), !dbg !8 br label %return, !dbg !8 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @"do nothing"(), !dbg !11 - call void @"println <:None>"(), !dbg !11 - %1 = call %Integer @"do something"(), !dbg !12 - call void @"println <:Integer>"(%Integer %1), !dbg !12 - br label %return, !dbg !12 - -return: ; preds = %0 - ret void -} - -define private void @"println <:None>"() !dbg !13 { - %1 = call %String @"String from <:None>"(), !dbg !14 - call void @"println <:String>"(%String %1), !dbg !14 - br label %return, !dbg !14 +define private void @"println <:None>"() !dbg !9 { + %1 = call %String @"String from <:None>"(), !dbg !10 + call void @"println <:String>"(%String %1), !dbg !10 + br label %return, !dbg !10 return: ; preds = %0 ret void @@ -61,13 +34,13 @@ declare %String @"String from <:None>"() declare void @"do nothing"() -define private void @"println <:Integer>"(%Integer %0) !dbg !15 { +define private void @"println <:Integer>"(%Integer %0) !dbg !11 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !16 - %3 = call %String @integer_as_string(%Integer %2), !dbg !16 - call void @"println <:String>"(%String %3), !dbg !16 - br label %return, !dbg !16 + %2 = load %Integer, ptr %x, align 8, !dbg !12 + %3 = call %String @integer_as_string(%Integer %2), !dbg !12 + call void @"println <:String>"(%String %3), !dbg !12 + br label %return, !dbg !12 return: ; preds = %1 ret void @@ -83,17 +56,13 @@ declare %Integer @"do something"() !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 3, column: 22, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!7 = !DILocation(line: 2, column: 9, scope: !3) +!8 = !DILocation(line: 3, column: 9, scope: !3) +!9 = distinct !DISubprogram(name: "println <:None>", linkageName: "println <:None>", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) !10 = !DILocation(line: 3, column: 22, scope: !9) -!11 = !DILocation(line: 2, column: 9, scope: !9) -!12 = !DILocation(line: 3, column: 9, scope: !9) -!13 = distinct !DISubprogram(name: "println <:None>", linkageName: "println <:None>", scope: !9, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!14 = !DILocation(line: 3, column: 22, scope: !13) -!15 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !9, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 3, column: 22, scope: !15) +!11 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!12 = !DILocation(line: 3, column: 22, scope: !11) diff --git a/src/tests/snapshots/ppl__tests__integer.ir.snap b/src/tests/snapshots/ppl__tests__integer.ir.snap index 19a21862..fd1301bf 100644 --- a/src/tests/snapshots/ppl__tests__integer.ir.snap +++ b/src/tests/snapshots/ppl__tests__integer.ir.snap @@ -5,79 +5,52 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } %Integer = type { ptr } %Rational = type { ptr } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - %1 = call %Integer @integer_from_i64(i64 0), !dbg !11 - call void @"println <:Integer>"(%Integer %1), !dbg !11 - %2 = call %Integer @integer_from_i64(i64 1), !dbg !12 - %3 = call %Integer @"+ <:Integer>"(%Integer %2), !dbg !12 - call void @"println <:Integer>"(%Integer %3), !dbg !12 - %4 = call %Integer @integer_from_i64(i64 2), !dbg !13 - %5 = call %Integer @minus_integer(%Integer %4), !dbg !13 - call void @"println <:Integer>"(%Integer %5), !dbg !13 - %6 = call %Integer @integer_from_i64(i64 2), !dbg !14 - %7 = call %Integer @integer_from_i64(i64 1), !dbg !15 - %8 = call %Integer @integer_plus_integer(%Integer %6, %Integer %7), !dbg !15 - call void @"println <:Integer>"(%Integer %8), !dbg !15 - %9 = call %Integer @integer_from_i64(i64 2), !dbg !16 - %10 = call %Integer @integer_from_i64(i64 2), !dbg !17 - %11 = call %Integer @integer_power_integer(%Integer %9, %Integer %10), !dbg !17 - call void @"println <:Integer>"(%Integer %11), !dbg !17 - %12 = call %Integer @integer_from_i64(i64 5), !dbg !18 - %13 = call %Integer @integer_from_i64(i64 0), !dbg !19 - %14 = call %Integer @"<:Integer> - <:Integer>"(%Integer %12, %Integer %13), !dbg !19 - call void @"println <:Integer>"(%Integer %14), !dbg !19 - %15 = call %Integer @integer_from_i64(i64 2), !dbg !20 - %16 = call %Integer @integer_from_i64(i64 3), !dbg !21 - %17 = call %Integer @integer_star_integer(%Integer %15, %Integer %16), !dbg !21 - call void @"println <:Integer>"(%Integer %17), !dbg !21 - %18 = call %Integer @integer_from_i64(i64 14), !dbg !22 - %19 = call %Integer @integer_from_i64(i64 2), !dbg !23 - %20 = call %Rational @integer_slash_integer(%Integer %18, %Integer %19), !dbg !23 - call void @"println <:Rational>"(%Rational %20), !dbg !23 - br label %return, !dbg !23 +define void @main.execute() !dbg !3 { + %1 = call %Integer @integer_from_i64(i64 0), !dbg !7 + call void @"println <:Integer>"(%Integer %1), !dbg !7 + %2 = call %Integer @integer_from_i64(i64 1), !dbg !8 + %3 = call %Integer @"+ <:Integer>"(%Integer %2), !dbg !8 + call void @"println <:Integer>"(%Integer %3), !dbg !8 + %4 = call %Integer @integer_from_i64(i64 2), !dbg !9 + %5 = call %Integer @minus_integer(%Integer %4), !dbg !9 + call void @"println <:Integer>"(%Integer %5), !dbg !9 + %6 = call %Integer @integer_from_i64(i64 2), !dbg !10 + %7 = call %Integer @integer_from_i64(i64 1), !dbg !11 + %8 = call %Integer @integer_plus_integer(%Integer %6, %Integer %7), !dbg !11 + call void @"println <:Integer>"(%Integer %8), !dbg !11 + %9 = call %Integer @integer_from_i64(i64 2), !dbg !12 + %10 = call %Integer @integer_from_i64(i64 2), !dbg !13 + %11 = call %Integer @integer_power_integer(%Integer %9, %Integer %10), !dbg !13 + call void @"println <:Integer>"(%Integer %11), !dbg !13 + %12 = call %Integer @integer_from_i64(i64 5), !dbg !14 + %13 = call %Integer @integer_from_i64(i64 0), !dbg !15 + %14 = call %Integer @"<:Integer> - <:Integer>"(%Integer %12, %Integer %13), !dbg !15 + call void @"println <:Integer>"(%Integer %14), !dbg !15 + %15 = call %Integer @integer_from_i64(i64 2), !dbg !16 + %16 = call %Integer @integer_from_i64(i64 3), !dbg !17 + %17 = call %Integer @integer_star_integer(%Integer %15, %Integer %16), !dbg !17 + call void @"println <:Integer>"(%Integer %17), !dbg !17 + %18 = call %Integer @integer_from_i64(i64 14), !dbg !18 + %19 = call %Integer @integer_from_i64(i64 2), !dbg !19 + %20 = call %Rational @integer_slash_integer(%Integer %18, %Integer %19), !dbg !19 + call void @"println <:Rational>"(%Rational %20), !dbg !19 + br label %return, !dbg !19 return: ; preds = %0 ret void } -define private void @"println <:Integer>"(%Integer %0) !dbg !24 { +define private void @"println <:Integer>"(%Integer %0) !dbg !20 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !25 - %3 = call %String @integer_as_string(%Integer %2), !dbg !25 - call void @"println <:String>"(%String %3), !dbg !25 - br label %return, !dbg !25 + %2 = load %Integer, ptr %x, align 8, !dbg !21 + %3 = call %String @integer_as_string(%Integer %2), !dbg !21 + call void @"println <:String>"(%String %3), !dbg !21 + br label %return, !dbg !21 return: ; preds = %1 ret void @@ -87,6 +60,8 @@ declare void @"println <:String>"(%String) declare %String @integer_as_string(%Integer) +declare %Integer @integer_from_i64(i64) + declare %Integer @"+ <:Integer>"(%Integer) declare %Integer @minus_integer(%Integer) @@ -99,13 +74,13 @@ declare %Integer @"<:Integer> - <:Integer>"(%Integer, %Integer) declare %Integer @integer_star_integer(%Integer, %Integer) -define private void @"println <:Rational>"(%Rational %0) !dbg !26 { +define private void @"println <:Rational>"(%Rational %0) !dbg !22 { %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 - %2 = load %Rational, ptr %x, align 8, !dbg !27 - %3 = call %String @rational_as_string(%Rational %2), !dbg !27 - call void @"println <:String>"(%String %3), !dbg !27 - br label %return, !dbg !27 + %2 = load %Rational, ptr %x, align 8, !dbg !23 + %3 = call %String @rational_as_string(%Rational %2), !dbg !23 + call void @"println <:String>"(%String %3), !dbg !23 + br label %return, !dbg !23 return: ; preds = %1 ret void @@ -121,28 +96,24 @@ declare %Rational @integer_slash_integer(%Integer, %Integer) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 7, column: 14, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 7, column: 14, scope: !9) -!11 = !DILocation(line: 0, column: 8, scope: !9) -!12 = !DILocation(line: 1, column: 9, scope: !9) -!13 = !DILocation(line: 2, column: 9, scope: !9) -!14 = !DILocation(line: 3, column: 8, scope: !9) -!15 = !DILocation(line: 3, column: 12, scope: !9) -!16 = !DILocation(line: 4, column: 8, scope: !9) -!17 = !DILocation(line: 4, column: 12, scope: !9) -!18 = !DILocation(line: 5, column: 8, scope: !9) -!19 = !DILocation(line: 5, column: 12, scope: !9) -!20 = !DILocation(line: 6, column: 8, scope: !9) -!21 = !DILocation(line: 6, column: 12, scope: !9) -!22 = !DILocation(line: 7, column: 8, scope: !9) -!23 = !DILocation(line: 7, column: 13, scope: !9) -!24 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !9, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!25 = !DILocation(line: 7, column: 14, scope: !24) -!26 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !9, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!27 = !DILocation(line: 7, column: 14, scope: !26) +!7 = !DILocation(line: 0, column: 8, scope: !3) +!8 = !DILocation(line: 1, column: 9, scope: !3) +!9 = !DILocation(line: 2, column: 9, scope: !3) +!10 = !DILocation(line: 3, column: 8, scope: !3) +!11 = !DILocation(line: 3, column: 12, scope: !3) +!12 = !DILocation(line: 4, column: 8, scope: !3) +!13 = !DILocation(line: 4, column: 12, scope: !3) +!14 = !DILocation(line: 5, column: 8, scope: !3) +!15 = !DILocation(line: 5, column: 12, scope: !3) +!16 = !DILocation(line: 6, column: 8, scope: !3) +!17 = !DILocation(line: 6, column: 12, scope: !3) +!18 = !DILocation(line: 7, column: 8, scope: !3) +!19 = !DILocation(line: 7, column: 13, scope: !3) +!20 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!21 = !DILocation(line: 7, column: 14, scope: !20) +!22 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!23 = !DILocation(line: 7, column: 14, scope: !22) diff --git a/src/tests/snapshots/ppl__tests__memory.hir.snap b/src/tests/snapshots/ppl__tests__memory.hir.snap index cf7dfd8a..9a7d3f8c 100644 --- a/src/tests/snapshots/ppl__tests__memory.hir.snap +++ b/src/tests/snapshots/ppl__tests__memory.hir.snap @@ -2,8 +2,8 @@ source: src/tests/mod.rs expression: hir --- -let address: MemoryAddress = `allocate <:Integer> <:Type>`(1, (Type:Type)) -let x: ReferenceMut = `<:Type> at <:Reference>`((Type:Type), (&address:Reference)) +let address: MemoryAddress = `allocate <:Integer> <:Type>`(1, Type { name: "Integer", size: 8 }) +let x: ReferenceMut = `<:Type> at <:Reference>`(Type { name: "Integer", size: 8 }, (&address:Reference)) (x:ReferenceMut) = 0 `println <:Integer>`(`clone <:Reference>`((*x:Integer))) (x:ReferenceMut) = 1 @@ -18,7 +18,7 @@ fn size of > -> Integer: fn allocate <$arg1: Type> -> MemoryAddress: - let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`((Type:Type)))) + let $tmp@760: MemoryAddress = `allocate <:Integer> bytes`(`<:Integer> * <:Integer>`(`clone <:Reference>`((n:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) `destroy <:ReferenceMut>`((n:Integer)) return ($tmp@760:MemoryAddress) diff --git a/src/tests/snapshots/ppl__tests__memory.ir.snap b/src/tests/snapshots/ppl__tests__memory.ir.snap index dd0c120a..18c547f5 100644 --- a/src/tests/snapshots/ppl__tests__memory.ir.snap +++ b/src/tests/snapshots/ppl__tests__memory.ir.snap @@ -5,114 +5,87 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"Type" = type { ptr } %MemoryAddress = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } %Integer = type { ptr } +%"Type" = type { ptr } %"TypeImpl" = type { %String, %Integer } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@"Type" = private global %"Type" zeroinitializer -@1 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @address = global %MemoryAddress zeroinitializer +@0 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 +@1 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @x = global ptr null - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +@2 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 + +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @initialize.1(), !dbg !8 + %1 = load ptr, ptr @x, align 8, !dbg !9 + %2 = call %Integer @integer_from_i64(i64 0), !dbg !10 + store %Integer %2, ptr %1, align 8, !dbg !10 + %3 = load ptr, ptr @x, align 8, !dbg !11 + %4 = call %Integer @clone_integer(ptr %3), !dbg !11 + call void @"println <:Integer>"(%Integer %4), !dbg !11 + %5 = load ptr, ptr @x, align 8, !dbg !12 + %6 = call %Integer @integer_from_i64(i64 1), !dbg !13 + store %Integer %6, ptr %5, align 8, !dbg !13 + %7 = load ptr, ptr @x, align 8, !dbg !14 + %8 = call %Integer @clone_integer(ptr %7), !dbg !14 + call void @"println <:Integer>"(%Integer %8), !dbg !14 + br label %return, !dbg !14 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define private void @initialize.1() !dbg !9 { - %1 = alloca %"Type", align 8, !dbg !10 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 7), !dbg !11 - store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 - store %Integer %3, ptr %"Type.size", align 8, !dbg !11 - %4 = load %"Type", ptr %1, align 8, !dbg !11 - store %"Type" %4, ptr @"Type", align 8, !dbg !11 - br label %return, !dbg !11 +define private void @initialize() !dbg !15 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !16 + %2 = alloca %"Type", align 8, !dbg !17 + %"Type.data" = getelementptr inbounds %"Type", ptr %2, i32 0, i32 0, !dbg !17 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !17 + %3 = call %String @string_from_c_string_and_length(ptr @1, i64 7), !dbg !18 + store %String %3, ptr %"Type.name", align 8, !dbg !18 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !18 + %4 = call %Integer @integer_from_i64(i64 8), !dbg !18 + store %Integer %4, ptr %"Type.size", align 8, !dbg !18 + %5 = load %"Type", ptr %2, align 8, !dbg !18 + %6 = call %MemoryAddress @"allocate <:Integer> <:Type>"(%Integer %1, %"Type" %5), !dbg !18 + store %MemoryAddress %6, ptr @address, align 8, !dbg !18 + br label %return, !dbg !18 return: ; preds = %0 ret void } -define void @main.execute() !dbg !12 { - call void @initialize(), !dbg !13 - call void @initialize.1(), !dbg !14 - call void @initialize.2(), !dbg !15 - call void @initialize.3(), !dbg !16 - %1 = load ptr, ptr @x, align 8, !dbg !17 - %2 = call %Integer @integer_from_i64(i64 0), !dbg !18 - store %Integer %2, ptr %1, align 8, !dbg !18 - %3 = load ptr, ptr @x, align 8, !dbg !19 - %4 = call %Integer @clone_integer(ptr %3), !dbg !19 - call void @"println <:Integer>"(%Integer %4), !dbg !19 - %5 = load ptr, ptr @x, align 8, !dbg !20 - %6 = call %Integer @integer_from_i64(i64 1), !dbg !21 - store %Integer %6, ptr %5, align 8, !dbg !21 - %7 = load ptr, ptr @x, align 8, !dbg !22 - %8 = call %Integer @clone_integer(ptr %7), !dbg !22 - call void @"println <:Integer>"(%Integer %8), !dbg !22 - br label %return, !dbg !22 - -return: ; preds = %0 - ret void -} - -define private void @initialize.2() !dbg !23 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !24 - %2 = load %"Type", ptr @"Type", align 8, !dbg !25 - %3 = call %MemoryAddress @"allocate <:Integer> <:Type>"(%Integer %1, %"Type" %2), !dbg !25 - store %MemoryAddress %3, ptr @address, align 8, !dbg !25 - br label %return, !dbg !25 - -return: ; preds = %0 - ret void -} - -define private %MemoryAddress @"allocate <:Integer> <:Type>"(%Integer %0, %"Type" %1) !dbg !26 { +define private %MemoryAddress @"allocate <:Integer> <:Type>"(%Integer %0, %"Type" %1) !dbg !19 { %return_value = alloca %MemoryAddress, align 8 %n = alloca %Integer, align 8 store %Integer %0, ptr %n, align 8 %"$arg1" = alloca %"Type", align 8 store %"Type" %1, ptr %"$arg1", align 8 - %3 = call %Integer @clone_integer(ptr %n), !dbg !27 - %4 = load %"Type", ptr @"Type", align 8, !dbg !27 - %5 = call %Integer @"size of <:Type>"(%"Type" %4), !dbg !27 - %6 = call %Integer @integer_star_integer(%Integer %3, %Integer %5), !dbg !27 - %7 = call %MemoryAddress @allocate_n_bytes(%Integer %6), !dbg !27 - %"$tmp@760" = alloca %MemoryAddress, align 8, !dbg !27 - store %MemoryAddress %7, ptr %"$tmp@760", align 8, !dbg !27 - call void @destroy_integer(ptr %n), !dbg !27 - %8 = load %MemoryAddress, ptr %"$tmp@760", align 8, !dbg !27 - store %MemoryAddress %8, ptr %return_value, align 8, !dbg !27 - br label %return, !dbg !27 + %3 = call %Integer @clone_integer(ptr %n), !dbg !20 + %4 = alloca %"Type", align 8, !dbg !20 + %"Type.data" = getelementptr inbounds %"Type", ptr %4, i32 0, i32 0, !dbg !20 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !20 + %5 = call %String @string_from_c_string_and_length(ptr @0, i64 7), !dbg !21 + store %String %5, ptr %"Type.name", align 8, !dbg !21 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !21 + %6 = call %Integer @integer_from_i64(i64 8), !dbg !21 + store %Integer %6, ptr %"Type.size", align 8, !dbg !21 + %7 = load %"Type", ptr %4, align 8, !dbg !21 + %8 = call %Integer @"size of <:Type>"(%"Type" %7), !dbg !21 + %9 = call %Integer @integer_star_integer(%Integer %3, %Integer %8), !dbg !21 + %10 = call %MemoryAddress @allocate_n_bytes(%Integer %9), !dbg !21 + %"$tmp@760" = alloca %MemoryAddress, align 8, !dbg !21 + store %MemoryAddress %10, ptr %"$tmp@760", align 8, !dbg !21 + call void @destroy_integer(ptr %n), !dbg !20 + %11 = load %MemoryAddress, ptr %"$tmp@760", align 8, !dbg !20 + store %MemoryAddress %11, ptr %return_value, align 8, !dbg !20 + br label %return, !dbg !20 return: ; preds = %2 - %9 = load %MemoryAddress, ptr %return_value, align 8 - ret %MemoryAddress %9 + %12 = load %MemoryAddress, ptr %return_value, align 8 + ret %MemoryAddress %12 } declare %MemoryAddress @allocate_n_bytes(%Integer) @@ -121,31 +94,43 @@ declare %Integer @integer_star_integer(%Integer, %Integer) declare %Integer @clone_integer(ptr) -define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !28 { +define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !22 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !29 - %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !29 - %3 = call %Integer @clone_integer(ptr %size), !dbg !29 - %"$tmp@4252" = alloca %Integer, align 8, !dbg !29 - store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !29 - %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !29 - store %Integer %4, ptr %return_value, align 8, !dbg !29 - br label %return, !dbg !29 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !23 + %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !23 + %3 = call %Integer @clone_integer(ptr %size), !dbg !23 + %"$tmp@4252" = alloca %Integer, align 8, !dbg !23 + store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !23 + %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !23 + store %Integer %4, ptr %return_value, align 8, !dbg !23 + br label %return, !dbg !23 return: ; preds = %1 %5 = load %Integer, ptr %return_value, align 8 ret %Integer %5 } +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + declare void @destroy_integer(ptr) -define private void @initialize.3() !dbg !30 { - %1 = load %"Type", ptr @"Type", align 8, !dbg !31 - %2 = call ptr @read_memory(%"Type" %1, ptr @address), !dbg !32 - store ptr %2, ptr @x, align 8, !dbg !32 - br label %return, !dbg !32 +define private void @initialize.1() !dbg !24 { + %1 = alloca %"Type", align 8, !dbg !25 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !25 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !25 + %2 = call %String @string_from_c_string_and_length(ptr @2, i64 7), !dbg !26 + store %String %2, ptr %"Type.name", align 8, !dbg !26 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !26 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !26 + store %Integer %3, ptr %"Type.size", align 8, !dbg !26 + %4 = load %"Type", ptr %1, align 8, !dbg !26 + %5 = call ptr @read_memory(%"Type" %4, ptr @address), !dbg !27 + store ptr %5, ptr @x, align 8, !dbg !27 + br label %return, !dbg !27 return: ; preds = %0 ret void @@ -153,13 +138,13 @@ return: ; preds = %0 declare ptr @read_memory(%"Type", ptr) -define private void @"println <:Integer>"(%Integer %0) !dbg !33 { +define private void @"println <:Integer>"(%Integer %0) !dbg !28 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !34 - %3 = call %String @integer_as_string(%Integer %2), !dbg !34 - call void @"println <:String>"(%String %3), !dbg !34 - br label %return, !dbg !34 + %2 = load %Integer, ptr %x, align 8, !dbg !29 + %3 = call %String @integer_as_string(%Integer %2), !dbg !29 + call void @"println <:String>"(%String %3), !dbg !29 + br label %return, !dbg !29 return: ; preds = %1 ret void @@ -175,35 +160,30 @@ declare %String @integer_as_string(%Integer) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 5, column: 9, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 0, column: 25, scope: !9) -!11 = !DILocation(line: 0, scope: !9) -!12 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 5, column: 9, scope: !12) -!14 = !DILocation(line: 0, column: 25, scope: !12) -!15 = !DILocation(line: 0, column: 14, scope: !12) -!16 = !DILocation(line: 1, column: 8, scope: !12) -!17 = !DILocation(line: 2, scope: !12) -!18 = !DILocation(line: 2, column: 4, scope: !12) -!19 = !DILocation(line: 3, column: 8, scope: !12) -!20 = !DILocation(line: 4, scope: !12) -!21 = !DILocation(line: 4, column: 4, scope: !12) -!22 = !DILocation(line: 5, column: 8, scope: !12) -!23 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !12, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!24 = !DILocation(line: 0, column: 23, scope: !23) -!25 = !DILocation(line: 0, column: 25, scope: !23) -!26 = distinct !DISubprogram(name: "allocate <:Integer> <:Type>", linkageName: "allocate <:Integer> <:Type>", scope: !23, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!27 = !DILocation(line: 5, column: 9, scope: !26) -!28 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !26, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!7 = !DILocation(line: 0, column: 14, scope: !3) +!8 = !DILocation(line: 1, column: 8, scope: !3) +!9 = !DILocation(line: 2, scope: !3) +!10 = !DILocation(line: 2, column: 4, scope: !3) +!11 = !DILocation(line: 3, column: 8, scope: !3) +!12 = !DILocation(line: 4, scope: !3) +!13 = !DILocation(line: 4, column: 4, scope: !3) +!14 = !DILocation(line: 5, column: 8, scope: !3) +!15 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 0, column: 23, scope: !15) +!17 = !DILocation(line: 0, column: 25, scope: !15) +!18 = !DILocation(line: 0, scope: !15) +!19 = distinct !DISubprogram(name: "allocate <:Integer> <:Type>", linkageName: "allocate <:Integer> <:Type>", scope: !15, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!20 = !DILocation(line: 5, column: 9, scope: !19) +!21 = !DILocation(line: 0, scope: !19) +!22 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !19, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!23 = !DILocation(line: 5, column: 9, scope: !22) +!24 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!25 = !DILocation(line: 1, column: 8, scope: !24) +!26 = !DILocation(line: 0, scope: !24) +!27 = !DILocation(line: 1, column: 19, scope: !24) +!28 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) !29 = !DILocation(line: 5, column: 9, scope: !28) -!30 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !12, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!31 = !DILocation(line: 1, column: 8, scope: !30) -!32 = !DILocation(line: 1, column: 19, scope: !30) -!33 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !12, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!34 = !DILocation(line: 5, column: 9, scope: !33) diff --git a/src/tests/snapshots/ppl__tests__monomorphize.ir.snap b/src/tests/snapshots/ppl__tests__monomorphize.ir.snap index 1f2d8842..f9b7853b 100644 --- a/src/tests/snapshots/ppl__tests__monomorphize.ir.snap +++ b/src/tests/snapshots/ppl__tests__monomorphize.ir.snap @@ -5,75 +5,51 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %"Point" = type { ptr } %Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } %"PointImpl" = type { %Integer, %Integer } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @p = global %"Point" zeroinitializer @x = global %Integer zeroinitializer -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @initialize.1(), !dbg !8 + %1 = call %Integer @clone_integer(ptr @x), !dbg !9 + %2 = call %Integer @integer_from_i64(i64 1), !dbg !10 + %3 = call i1 @integer_eq_integer(%Integer %1, %Integer %2), !dbg !10 + call void @"println <:Bool>"(i1 %3), !dbg !10 + call void @destroy_integer(ptr @x), !dbg !11 + br label %return, !dbg !11 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - call void @initialize.2(), !dbg !12 - %1 = call %Integer @clone_integer(ptr @x), !dbg !13 +define private void @initialize() !dbg !12 { + %1 = alloca %"Point", align 8, !dbg !13 + %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !13 + %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !13 %2 = call %Integer @integer_from_i64(i64 1), !dbg !14 - %3 = call i1 @integer_eq_integer(%Integer %1, %Integer %2), !dbg !14 - call void @"println <:Bool>"(i1 %3), !dbg !14 - call void @destroy_integer(ptr @x), !dbg !15 + store %Integer %2, ptr %"Point.x", align 8, !dbg !14 + %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !14 + %3 = call %Integer @integer_from_i64(i64 2), !dbg !15 + store %Integer %3, ptr %"Point.y", align 8, !dbg !15 + %4 = load %"Point", ptr %1, align 8, !dbg !15 + store %"Point" %4, ptr @p, align 8, !dbg !15 br label %return, !dbg !15 return: ; preds = %0 ret void } -define private void @initialize.1() !dbg !16 { - %1 = alloca %"Point", align 8, !dbg !17 - %"Point.data" = getelementptr inbounds %"Point", ptr %1, i32 0, i32 0, !dbg !17 - %"Point.x" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 0, !dbg !17 - %2 = call %Integer @integer_from_i64(i64 1), !dbg !18 - store %Integer %2, ptr %"Point.x", align 8, !dbg !18 - %"Point.y" = getelementptr inbounds %"PointImpl", ptr %"Point.data", i32 0, i32 1, !dbg !18 - %3 = call %Integer @integer_from_i64(i64 2), !dbg !19 - store %Integer %3, ptr %"Point.y", align 8, !dbg !19 - %4 = load %"Point", ptr %1, align 8, !dbg !19 - store %"Point" %4, ptr @p, align 8, !dbg !19 - br label %return, !dbg !19 - -return: ; preds = %0 - ret void -} +declare %Integer @integer_from_i64(i64) -define private void @initialize.2() !dbg !20 { - %1 = call %Integer @clone_integer(ptr @p), !dbg !21 - store %Integer %1, ptr @x, align 8, !dbg !21 - br label %return, !dbg !21 +define private void @initialize.1() !dbg !16 { + %1 = call %Integer @clone_integer(ptr @p), !dbg !17 + store %Integer %1, ptr @x, align 8, !dbg !17 + br label %return, !dbg !17 return: ; preds = %0 ret void @@ -81,13 +57,13 @@ return: ; preds = %0 declare %Integer @clone_integer(ptr) -define private void @"println <:Bool>"(i1 %0) !dbg !22 { +define private void @"println <:Bool>"(i1 %0) !dbg !18 { %x = alloca i1, align 1 store i1 %0, ptr %x, align 1 - %2 = load i1, ptr %x, align 1, !dbg !23 - %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !23 - call void @"println <:String>"(%String %3), !dbg !23 - br label %return, !dbg !23 + %2 = load i1, ptr %x, align 1, !dbg !19 + %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !19 + call void @"println <:String>"(%String %3), !dbg !19 + br label %return, !dbg !19 return: ; preds = %1 ret void @@ -107,24 +83,20 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 5, column: 14, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 5, column: 14, scope: !9) -!11 = !DILocation(line: 3, column: 8, scope: !9) -!12 = !DILocation(line: 4, column: 8, scope: !9) -!13 = !DILocation(line: 5, column: 8, scope: !9) -!14 = !DILocation(line: 5, column: 13, scope: !9) -!15 = !DILocation(line: 4, scope: !9) -!16 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!17 = !DILocation(line: 3, column: 8, scope: !16) -!18 = !DILocation(line: 3, column: 19, scope: !16) -!19 = !DILocation(line: 3, column: 25, scope: !16) -!20 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !9, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!21 = !DILocation(line: 4, column: 8, scope: !20) -!22 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !9, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 5, column: 14, scope: !22) +!7 = !DILocation(line: 3, column: 8, scope: !3) +!8 = !DILocation(line: 4, column: 8, scope: !3) +!9 = !DILocation(line: 5, column: 8, scope: !3) +!10 = !DILocation(line: 5, column: 13, scope: !3) +!11 = !DILocation(line: 4, scope: !3) +!12 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 3, column: 8, scope: !12) +!14 = !DILocation(line: 3, column: 19, scope: !12) +!15 = !DILocation(line: 3, column: 25, scope: !12) +!16 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!17 = !DILocation(line: 4, column: 8, scope: !16) +!18 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 5, column: 14, scope: !18) diff --git a/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap b/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap index 008b3fa9..824d1a12 100644 --- a/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap +++ b/src/tests/snapshots/ppl__tests__monomorphize_predeclared.ir.snap @@ -5,60 +5,34 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } %Integer = type { ptr } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@1 = private unnamed_addr constant [19 x i8] c"called predeclared\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) +@0 = private unnamed_addr constant [19 x i8] c"called predeclared\00", align 1 -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @"call predeclared"(), !dbg !11 - br label %return, !dbg !11 +define void @main.execute() !dbg !3 { + call void @"call predeclared"(), !dbg !7 + br label %return, !dbg !7 return: ; preds = %0 ret void } -define void @"call predeclared"() !dbg !12 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !13 - call void @"predeclared <:Integer>"(%Integer %1), !dbg !13 - br label %return, !dbg !13 +define void @"call predeclared"() !dbg !8 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !9 + call void @"predeclared <:Integer>"(%Integer %1), !dbg !9 + br label %return, !dbg !9 return: ; preds = %0 ret void } -define private void @"predeclared <:Integer>"(%Integer %0) !dbg !14 { +define private void @"predeclared <:Integer>"(%Integer %0) !dbg !10 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 18), !dbg !15 - call void @"println <:String>"(%String %2), !dbg !15 - br label %return, !dbg !15 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 18), !dbg !11 + call void @"println <:String>"(%String %2), !dbg !11 + br label %return, !dbg !11 return: ; preds = %1 ret void @@ -66,22 +40,22 @@ return: ; preds = %1 declare void @"println <:String>"(%String) +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 6, column: 16, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 6, column: 16, scope: !9) -!11 = !DILocation(line: 6, scope: !9) -!12 = distinct !DISubprogram(name: "call predeclared", linkageName: "call predeclared", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 1, column: 13, scope: !12) -!14 = distinct !DISubprogram(name: "predeclared <:Integer>", linkageName: "predeclared <:Integer>", scope: !12, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!15 = !DILocation(line: 4, column: 9, scope: !14) +!7 = !DILocation(line: 6, scope: !3) +!8 = distinct !DISubprogram(name: "call predeclared", linkageName: "call predeclared", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!9 = !DILocation(line: 1, column: 13, scope: !8) +!10 = distinct !DISubprogram(name: "predeclared <:Integer>", linkageName: "predeclared <:Integer>", scope: !8, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!11 = !DILocation(line: 4, column: 9, scope: !10) diff --git a/src/tests/snapshots/ppl__tests__multifile.ir.snap b/src/tests/snapshots/ppl__tests__multifile.ir.snap index 7b3aa83f..c2b1c07d 100644 --- a/src/tests/snapshots/ppl__tests__multifile.ir.snap +++ b/src/tests/snapshots/ppl__tests__multifile.ir.snap @@ -5,41 +5,14 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -%Integer = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@1 = private unnamed_addr constant [6 x i8] c"World\00", align 1 +@0 = private unnamed_addr constant [6 x i8] c"World\00", align 1 -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - %1 = call %String @string_from_c_string_and_length(ptr @1, i64 5), !dbg !11 - call void @"greet <:String>"(%String %1), !dbg !11 - br label %return, !dbg !11 +define void @main.execute() !dbg !3 { + %1 = call %String @string_from_c_string_and_length(ptr @0, i64 5), !dbg !7 + call void @"greet <:String>"(%String %1), !dbg !7 + br label %return, !dbg !7 return: ; preds = %0 ret void @@ -47,18 +20,16 @@ return: ; preds = %0 declare void @"greet <:String>"(%String) +declare %String @string_from_c_string_and_length(ptr, i64) + !llvm.module.flags = !{!0} !llvm.dbg.cu = !{!1} !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 2, column: 13, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 2, column: 13, scope: !9) -!11 = !DILocation(line: 2, column: 6, scope: !9) +!7 = !DILocation(line: 2, column: 6, scope: !3) diff --git a/src/tests/snapshots/ppl__tests__ppl.ir.snap b/src/tests/snapshots/ppl__tests__ppl.ir.snap index 2a6041f2..843a1f23 100644 --- a/src/tests/snapshots/ppl__tests__ppl.ir.snap +++ b/src/tests/snapshots/ppl__tests__ppl.ir.snap @@ -5,38 +5,8 @@ expression: ir ; ModuleID = 'lib' source_filename = "/Users/gavrilikhin_d/Code/ppl/ppl/src/lib.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } -%Integer = type { ptr } - -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @lib.execute() !dbg !9 { - call void @initialize(), !dbg !10 - br label %return, !dbg !10 +define void @lib.execute() !dbg !3 { + br label %return return: ; preds = %0 ret void @@ -48,11 +18,7 @@ return: ; preds = %0 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "/Users/gavrilikhin_d/Code/ppl/ppl/src/lib.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "lib.execute", linkageName: "lib.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 9, column: 15, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "lib.execute", linkageName: "lib.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 9, column: 15, scope: !9) diff --git a/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap b/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap index 77a1e9c6..5a13c513 100644 --- a/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap +++ b/src/tests/snapshots/ppl__tests__predeclare_function.ir.snap @@ -5,81 +5,54 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } %Integer = type { ptr } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - %1 = call %Integer @integer_from_i64(i64 2), !dbg !11 - %2 = call %Integer @"<:Integer> plus two"(%Integer %1), !dbg !11 - call void @"println <:Integer>"(%Integer %2), !dbg !11 - br label %return, !dbg !11 +define void @main.execute() !dbg !3 { + %1 = call %Integer @integer_from_i64(i64 2), !dbg !7 + %2 = call %Integer @"<:Integer> plus two"(%Integer %1), !dbg !7 + call void @"println <:Integer>"(%Integer %2), !dbg !7 + br label %return, !dbg !7 return: ; preds = %0 ret void } -define %Integer @"<:Integer> plus two"(%Integer %0) !dbg !12 { +define %Integer @"<:Integer> plus two"(%Integer %0) !dbg !8 { %return_value = alloca %Integer, align 8 %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = call %Integer @clone_integer(ptr %x), !dbg !13 - %3 = call %Integer @integer_from_i64(i64 2), !dbg !14 - %4 = call %Integer @"sum <:Integer> <:Integer>"(%Integer %2, %Integer %3), !dbg !14 - %"$tmp@28" = alloca %Integer, align 8, !dbg !14 - store %Integer %4, ptr %"$tmp@28", align 8, !dbg !14 - call void @destroy_integer(ptr %x), !dbg !15 - %5 = load %Integer, ptr %"$tmp@28", align 8, !dbg !16 - store %Integer %5, ptr %return_value, align 8, !dbg !16 - br label %return, !dbg !16 + %2 = call %Integer @clone_integer(ptr %x), !dbg !9 + %3 = call %Integer @integer_from_i64(i64 2), !dbg !10 + %4 = call %Integer @"sum <:Integer> <:Integer>"(%Integer %2, %Integer %3), !dbg !10 + %"$tmp@28" = alloca %Integer, align 8, !dbg !10 + store %Integer %4, ptr %"$tmp@28", align 8, !dbg !10 + call void @destroy_integer(ptr %x), !dbg !11 + %5 = load %Integer, ptr %"$tmp@28", align 8, !dbg !12 + store %Integer %5, ptr %return_value, align 8, !dbg !12 + br label %return, !dbg !12 return: ; preds = %1 %6 = load %Integer, ptr %return_value, align 8 ret %Integer %6 } -define %Integer @"sum <:Integer> <:Integer>"(%Integer %0, %Integer %1) !dbg !17 { +define %Integer @"sum <:Integer> <:Integer>"(%Integer %0, %Integer %1) !dbg !13 { %return_value = alloca %Integer, align 8 %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 %y = alloca %Integer, align 8 store %Integer %1, ptr %y, align 8 - %3 = call %Integer @clone_integer(ptr %x), !dbg !18 - %4 = call %Integer @clone_integer(ptr %y), !dbg !19 - %5 = call %Integer @integer_plus_integer(%Integer %3, %Integer %4), !dbg !19 - %"$tmp@84" = alloca %Integer, align 8, !dbg !19 - store %Integer %5, ptr %"$tmp@84", align 8, !dbg !19 - call void @destroy_integer(ptr %x), !dbg !20 - call void @destroy_integer(ptr %y), !dbg !21 - %6 = load %Integer, ptr %"$tmp@84", align 8, !dbg !18 - store %Integer %6, ptr %return_value, align 8, !dbg !18 - br label %return, !dbg !18 + %3 = call %Integer @clone_integer(ptr %x), !dbg !14 + %4 = call %Integer @clone_integer(ptr %y), !dbg !15 + %5 = call %Integer @integer_plus_integer(%Integer %3, %Integer %4), !dbg !15 + %"$tmp@84" = alloca %Integer, align 8, !dbg !15 + store %Integer %5, ptr %"$tmp@84", align 8, !dbg !15 + call void @destroy_integer(ptr %x), !dbg !16 + call void @destroy_integer(ptr %y), !dbg !17 + %6 = load %Integer, ptr %"$tmp@84", align 8, !dbg !14 + store %Integer %6, ptr %return_value, align 8, !dbg !14 + br label %return, !dbg !14 return: ; preds = %2 %7 = load %Integer, ptr %return_value, align 8 @@ -88,19 +61,21 @@ return: ; preds = %2 declare %Integer @clone_integer(ptr) +declare %Integer @integer_from_i64(i64) + declare void @destroy_integer(ptr) declare %Integer @"sum <:Integer> <:Integer>.1"(%Integer, %Integer) declare %Integer @integer_plus_integer(%Integer, %Integer) -define private void @"println <:Integer>"(%Integer %0) !dbg !22 { +define private void @"println <:Integer>"(%Integer %0) !dbg !18 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !23 - %3 = call %String @integer_as_string(%Integer %2), !dbg !23 - call void @"println <:String>"(%String %3), !dbg !23 - br label %return, !dbg !23 + %2 = load %Integer, ptr %x, align 8, !dbg !19 + %3 = call %String @integer_as_string(%Integer %2), !dbg !19 + call void @"println <:String>"(%String %3), !dbg !19 + br label %return, !dbg !19 return: ; preds = %1 ret void @@ -116,24 +91,20 @@ declare %String @integer_as_string(%Integer) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 4, column: 20, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 4, column: 20, scope: !9) -!11 = !DILocation(line: 4, column: 9, scope: !9) -!12 = distinct !DISubprogram(name: "<:Integer> plus two", linkageName: "<:Integer> plus two", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 0, column: 32, scope: !12) -!14 = !DILocation(line: 0, column: 34, scope: !12) -!15 = !DILocation(line: 0, column: 3, scope: !12) -!16 = !DILocation(line: 0, column: 28, scope: !12) -!17 = distinct !DISubprogram(name: "sum <:Integer> <:Integer>", linkageName: "sum <:Integer> <:Integer>", scope: !9, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!18 = !DILocation(line: 2, column: 47, scope: !17) -!19 = !DILocation(line: 2, column: 51, scope: !17) -!20 = !DILocation(line: 2, column: 7, scope: !17) -!21 = !DILocation(line: 2, column: 20, scope: !17) -!22 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !9, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 4, column: 20, scope: !22) +!7 = !DILocation(line: 4, column: 9, scope: !3) +!8 = distinct !DISubprogram(name: "<:Integer> plus two", linkageName: "<:Integer> plus two", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!9 = !DILocation(line: 0, column: 32, scope: !8) +!10 = !DILocation(line: 0, column: 34, scope: !8) +!11 = !DILocation(line: 0, column: 3, scope: !8) +!12 = !DILocation(line: 0, column: 28, scope: !8) +!13 = distinct !DISubprogram(name: "sum <:Integer> <:Integer>", linkageName: "sum <:Integer> <:Integer>", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!14 = !DILocation(line: 2, column: 47, scope: !13) +!15 = !DILocation(line: 2, column: 51, scope: !13) +!16 = !DILocation(line: 2, column: 7, scope: !13) +!17 = !DILocation(line: 2, column: 20, scope: !13) +!18 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 4, column: 20, scope: !18) diff --git a/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap b/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap index eaea1465..1f8b972d 100644 --- a/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap +++ b/src/tests/snapshots/ppl__tests__predeclare_vars.ir.snap @@ -5,68 +5,44 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @x = global %Integer zeroinitializer @y = global %Integer zeroinitializer -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @initialize.1(), !dbg !8 + %1 = call %Integer @clone_integer(ptr @y), !dbg !9 + call void @"println <:Integer>"(%Integer %1), !dbg !9 + call void @destroy_integer(ptr @x), !dbg !10 + call void @destroy_integer(ptr @y), !dbg !11 + br label %return, !dbg !11 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - call void @initialize.2(), !dbg !12 - %1 = call %Integer @clone_integer(ptr @y), !dbg !13 - call void @"println <:Integer>"(%Integer %1), !dbg !13 - call void @destroy_integer(ptr @x), !dbg !14 - call void @destroy_integer(ptr @y), !dbg !15 - br label %return, !dbg !15 +define private void @initialize() !dbg !12 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !13 + store %Integer %1, ptr @x, align 8, !dbg !13 + br label %return, !dbg !13 return: ; preds = %0 ret void } -define private void @initialize.1() !dbg !16 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !17 - store %Integer %1, ptr @x, align 8, !dbg !17 - br label %return, !dbg !17 - -return: ; preds = %0 - ret void -} +declare %Integer @integer_from_i64(i64) -define %Integer @"get x"() !dbg !18 { +define %Integer @"get x"() !dbg !14 { %return_value = alloca %Integer, align 8 - %1 = call %Integer @clone_integer(ptr @x), !dbg !19 - %"$tmp@22" = alloca %Integer, align 8, !dbg !19 - store %Integer %1, ptr %"$tmp@22", align 8, !dbg !19 - %2 = load %Integer, ptr %"$tmp@22", align 8, !dbg !19 - store %Integer %2, ptr %return_value, align 8, !dbg !19 - br label %return, !dbg !19 + %1 = call %Integer @clone_integer(ptr @x), !dbg !15 + %"$tmp@22" = alloca %Integer, align 8, !dbg !15 + store %Integer %1, ptr %"$tmp@22", align 8, !dbg !15 + %2 = load %Integer, ptr %"$tmp@22", align 8, !dbg !15 + store %Integer %2, ptr %return_value, align 8, !dbg !15 + br label %return, !dbg !15 return: ; preds = %0 %3 = load %Integer, ptr %return_value, align 8 @@ -75,36 +51,36 @@ return: ; preds = %0 declare %Integer @clone_integer(ptr) -define private void @initialize.2() !dbg !20 { - %1 = call %Integer @"get x"(), !dbg !21 - store %Integer %1, ptr @y, align 8, !dbg !21 - br label %return, !dbg !21 +define private void @initialize.1() !dbg !16 { + %1 = call %Integer @"get x"(), !dbg !17 + store %Integer %1, ptr @y, align 8, !dbg !17 + br label %return, !dbg !17 return: ; preds = %0 ret void } -define %Integer @"get y"() !dbg !22 { +define %Integer @"get y"() !dbg !18 { %return_value = alloca %Integer, align 8 - %1 = call %Integer @clone_integer(ptr @y), !dbg !23 - %"$tmp@51" = alloca %Integer, align 8, !dbg !23 - store %Integer %1, ptr %"$tmp@51", align 8, !dbg !23 - %2 = load %Integer, ptr %"$tmp@51", align 8, !dbg !23 - store %Integer %2, ptr %return_value, align 8, !dbg !23 - br label %return, !dbg !23 + %1 = call %Integer @clone_integer(ptr @y), !dbg !19 + %"$tmp@51" = alloca %Integer, align 8, !dbg !19 + store %Integer %1, ptr %"$tmp@51", align 8, !dbg !19 + %2 = load %Integer, ptr %"$tmp@51", align 8, !dbg !19 + store %Integer %2, ptr %return_value, align 8, !dbg !19 + br label %return, !dbg !19 return: ; preds = %0 %3 = load %Integer, ptr %return_value, align 8 ret %Integer %3 } -define private void @"println <:Integer>"(%Integer %0) !dbg !24 { +define private void @"println <:Integer>"(%Integer %0) !dbg !20 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !25 - %3 = call %String @integer_as_string(%Integer %2), !dbg !25 - call void @"println <:String>"(%String %3), !dbg !25 - br label %return, !dbg !25 + %2 = load %Integer, ptr %x, align 8, !dbg !21 + %3 = call %String @integer_as_string(%Integer %2), !dbg !21 + call void @"println <:String>"(%String %3), !dbg !21 + br label %return, !dbg !21 return: ; preds = %1 ret void @@ -122,26 +98,22 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 6, column: 9, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 6, column: 9, scope: !9) -!11 = !DILocation(line: 0, column: 8, scope: !9) -!12 = !DILocation(line: 3, column: 8, scope: !9) -!13 = !DILocation(line: 6, column: 8, scope: !9) -!14 = !DILocation(line: 0, scope: !9) -!15 = !DILocation(line: 3, scope: !9) -!16 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!17 = !DILocation(line: 0, column: 8, scope: !16) -!18 = distinct !DISubprogram(name: "get x", linkageName: "get x", scope: !9, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!19 = !DILocation(line: 1, column: 12, scope: !18) -!20 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !9, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!21 = !DILocation(line: 3, column: 8, scope: !20) -!22 = distinct !DISubprogram(name: "get y", linkageName: "get y", scope: !9, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 4, column: 12, scope: !22) -!24 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !9, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!25 = !DILocation(line: 6, column: 9, scope: !24) +!7 = !DILocation(line: 0, column: 8, scope: !3) +!8 = !DILocation(line: 3, column: 8, scope: !3) +!9 = !DILocation(line: 6, column: 8, scope: !3) +!10 = !DILocation(line: 0, scope: !3) +!11 = !DILocation(line: 3, scope: !3) +!12 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 0, column: 8, scope: !12) +!14 = distinct !DISubprogram(name: "get x", linkageName: "get x", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!15 = !DILocation(line: 1, column: 12, scope: !14) +!16 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!17 = !DILocation(line: 3, column: 8, scope: !16) +!18 = distinct !DISubprogram(name: "get y", linkageName: "get y", scope: !3, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 4, column: 12, scope: !18) +!20 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!21 = !DILocation(line: 6, column: 9, scope: !20) diff --git a/src/tests/snapshots/ppl__tests__rational.ir.snap b/src/tests/snapshots/ppl__tests__rational.ir.snap index e17629c4..06b07930 100644 --- a/src/tests/snapshots/ppl__tests__rational.ir.snap +++ b/src/tests/snapshots/ppl__tests__rational.ir.snap @@ -5,135 +5,109 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } -%Integer = type { ptr } %Rational = type { ptr } +%Integer = type { ptr } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@1 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@2 = private unnamed_addr constant [2 x i8] c"1\00", align 1 -@3 = private unnamed_addr constant [2 x i8] c"2\00", align 1 -@4 = private unnamed_addr constant [2 x i8] c"1\00", align 1 -@5 = private unnamed_addr constant [2 x i8] c"2\00", align 1 -@6 = private unnamed_addr constant [2 x i8] c"5\00", align 1 -@7 = private unnamed_addr constant [2 x i8] c"1\00", align 1 -@8 = private unnamed_addr constant [4 x i8] c"5/2\00", align 1 -@9 = private unnamed_addr constant [2 x i8] c"2\00", align 1 -@10 = private unnamed_addr constant [2 x i8] c"9\00", align 1 +@0 = private unnamed_addr constant [2 x i8] c"0\00", align 1 +@1 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@2 = private unnamed_addr constant [2 x i8] c"2\00", align 1 +@3 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@4 = private unnamed_addr constant [2 x i8] c"2\00", align 1 +@5 = private unnamed_addr constant [2 x i8] c"5\00", align 1 +@6 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@7 = private unnamed_addr constant [4 x i8] c"5/2\00", align 1 +@8 = private unnamed_addr constant [2 x i8] c"2\00", align 1 +@9 = private unnamed_addr constant [2 x i8] c"9\00", align 1 +@10 = private unnamed_addr constant [2 x i8] c"0\00", align 1 @11 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@12 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@13 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@12 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@13 = private unnamed_addr constant [2 x i8] c"0\00", align 1 @14 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@15 = private unnamed_addr constant [2 x i8] c"0\00", align 1 +@15 = private unnamed_addr constant [2 x i8] c"1\00", align 1 @16 = private unnamed_addr constant [2 x i8] c"1\00", align 1 -@17 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@17 = private unnamed_addr constant [2 x i8] c"0\00", align 1 @18 = private unnamed_addr constant [2 x i8] c"0\00", align 1 @19 = private unnamed_addr constant [2 x i8] c"0\00", align 1 @20 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@21 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@22 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@21 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@22 = private unnamed_addr constant [2 x i8] c"0\00", align 1 @23 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@24 = private unnamed_addr constant [2 x i8] c"0\00", align 1 -@25 = private unnamed_addr constant [2 x i8] c"1\00", align 1 -@26 = private unnamed_addr constant [2 x i8] c"0\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +@24 = private unnamed_addr constant [2 x i8] c"1\00", align 1 +@25 = private unnamed_addr constant [2 x i8] c"0\00", align 1 + +define void @main.execute() !dbg !3 { + %1 = call %Rational @rational_from_c_string(ptr @0), !dbg !7 + call void @"println <:Rational>"(%Rational %1), !dbg !7 + %2 = call %Rational @rational_from_c_string(ptr @1), !dbg !8 + %3 = call %Rational @"+ <:Rational>"(%Rational %2), !dbg !8 + call void @"println <:Rational>"(%Rational %3), !dbg !8 + %4 = call %Rational @rational_from_c_string(ptr @2), !dbg !9 + %5 = call %Rational @minus_rational(%Rational %4), !dbg !9 + call void @"println <:Rational>"(%Rational %5), !dbg !9 + %6 = call %Rational @rational_from_c_string(ptr @3), !dbg !10 + %7 = call %Rational @rational_from_c_string(ptr @4), !dbg !11 + %8 = call %Rational @rational_plus_rational(%Rational %6, %Rational %7), !dbg !11 + call void @"println <:Rational>"(%Rational %8), !dbg !11 + %9 = call %Rational @rational_from_c_string(ptr @5), !dbg !12 + %10 = call %Rational @rational_from_c_string(ptr @6), !dbg !13 + %11 = call %Rational @"<:Rational> - <:Rational>"(%Rational %9, %Rational %10), !dbg !13 + call void @"println <:Rational>"(%Rational %11), !dbg !13 + %12 = call %Rational @rational_from_c_string(ptr @7), !dbg !14 + %13 = call %Rational @rational_from_c_string(ptr @8), !dbg !15 + %14 = call %Rational @rational_star_rational(%Rational %12, %Rational %13), !dbg !15 + call void @"println <:Rational>"(%Rational %14), !dbg !15 + %15 = call %Rational @rational_from_c_string(ptr @9), !dbg !16 + %16 = call %Integer @integer_from_i64(i64 3), !dbg !17 + %17 = call %Integer @integer_from_i64(i64 2), !dbg !18 + %18 = call %Rational @integer_slash_integer(%Integer %16, %Integer %17), !dbg !18 + %19 = call %Rational @rational_slash_rational(%Rational %15, %Rational %18), !dbg !18 + call void @"println <:Rational>"(%Rational %19), !dbg !18 + %20 = call %Rational @rational_from_c_string(ptr @10), !dbg !19 + %21 = call %Rational @rational_from_c_string(ptr @11), !dbg !20 + %22 = call i1 @rational_eq_rational(%Rational %20, %Rational %21), !dbg !20 + call void @"println <:Bool>"(i1 %22), !dbg !20 + %23 = call %Rational @rational_from_c_string(ptr @12), !dbg !21 + %24 = call %Rational @rational_from_c_string(ptr @13), !dbg !22 + %25 = call i1 @"<:Rational> != <:Rational>"(%Rational %23, %Rational %24), !dbg !22 + call void @"println <:Bool>"(i1 %25), !dbg !22 + %26 = call %Rational @rational_from_c_string(ptr @14), !dbg !23 + %27 = call %Rational @rational_from_c_string(ptr @15), !dbg !24 + %28 = call i1 @rational_less_rational(%Rational %26, %Rational %27), !dbg !24 + call void @"println <:Bool>"(i1 %28), !dbg !24 + %29 = call %Rational @rational_from_c_string(ptr @16), !dbg !25 + %30 = call %Rational @rational_from_c_string(ptr @17), !dbg !26 + %31 = call i1 @"<:Rational> > <:Rational>"(%Rational %29, %Rational %30), !dbg !26 + call void @"println <:Bool>"(i1 %31), !dbg !26 + %32 = call %Rational @rational_from_c_string(ptr @18), !dbg !27 + %33 = call %Rational @rational_from_c_string(ptr @19), !dbg !28 + %34 = call i1 @"<:Rational> <= <:Rational>"(%Rational %32, %Rational %33), !dbg !28 + call void @"println <:Bool>"(i1 %34), !dbg !28 + %35 = call %Rational @rational_from_c_string(ptr @20), !dbg !29 + %36 = call %Rational @rational_from_c_string(ptr @21), !dbg !30 + %37 = call i1 @"<:Rational> <= <:Rational>"(%Rational %35, %Rational %36), !dbg !30 + call void @"println <:Bool>"(i1 %37), !dbg !30 + %38 = call %Rational @rational_from_c_string(ptr @22), !dbg !31 + %39 = call %Rational @rational_from_c_string(ptr @23), !dbg !32 + %40 = call i1 @"<:Rational> >= <:Rational>"(%Rational %38, %Rational %39), !dbg !32 + call void @"println <:Bool>"(i1 %40), !dbg !32 + %41 = call %Rational @rational_from_c_string(ptr @24), !dbg !33 + %42 = call %Rational @rational_from_c_string(ptr @25), !dbg !34 + %43 = call i1 @"<:Rational> >= <:Rational>"(%Rational %41, %Rational %42), !dbg !34 + call void @"println <:Bool>"(i1 %43), !dbg !34 + br label %return, !dbg !34 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - %1 = call %Rational @rational_from_c_string(ptr @1), !dbg !11 - call void @"println <:Rational>"(%Rational %1), !dbg !11 - %2 = call %Rational @rational_from_c_string(ptr @2), !dbg !12 - %3 = call %Rational @"+ <:Rational>"(%Rational %2), !dbg !12 - call void @"println <:Rational>"(%Rational %3), !dbg !12 - %4 = call %Rational @rational_from_c_string(ptr @3), !dbg !13 - %5 = call %Rational @minus_rational(%Rational %4), !dbg !13 - call void @"println <:Rational>"(%Rational %5), !dbg !13 - %6 = call %Rational @rational_from_c_string(ptr @4), !dbg !14 - %7 = call %Rational @rational_from_c_string(ptr @5), !dbg !15 - %8 = call %Rational @rational_plus_rational(%Rational %6, %Rational %7), !dbg !15 - call void @"println <:Rational>"(%Rational %8), !dbg !15 - %9 = call %Rational @rational_from_c_string(ptr @6), !dbg !16 - %10 = call %Rational @rational_from_c_string(ptr @7), !dbg !17 - %11 = call %Rational @"<:Rational> - <:Rational>"(%Rational %9, %Rational %10), !dbg !17 - call void @"println <:Rational>"(%Rational %11), !dbg !17 - %12 = call %Rational @rational_from_c_string(ptr @8), !dbg !18 - %13 = call %Rational @rational_from_c_string(ptr @9), !dbg !19 - %14 = call %Rational @rational_star_rational(%Rational %12, %Rational %13), !dbg !19 - call void @"println <:Rational>"(%Rational %14), !dbg !19 - %15 = call %Rational @rational_from_c_string(ptr @10), !dbg !20 - %16 = call %Integer @integer_from_i64(i64 3), !dbg !21 - %17 = call %Integer @integer_from_i64(i64 2), !dbg !22 - %18 = call %Rational @integer_slash_integer(%Integer %16, %Integer %17), !dbg !22 - %19 = call %Rational @rational_slash_rational(%Rational %15, %Rational %18), !dbg !22 - call void @"println <:Rational>"(%Rational %19), !dbg !22 - %20 = call %Rational @rational_from_c_string(ptr @11), !dbg !23 - %21 = call %Rational @rational_from_c_string(ptr @12), !dbg !24 - %22 = call i1 @rational_eq_rational(%Rational %20, %Rational %21), !dbg !24 - call void @"println <:Bool>"(i1 %22), !dbg !24 - %23 = call %Rational @rational_from_c_string(ptr @13), !dbg !25 - %24 = call %Rational @rational_from_c_string(ptr @14), !dbg !26 - %25 = call i1 @"<:Rational> != <:Rational>"(%Rational %23, %Rational %24), !dbg !26 - call void @"println <:Bool>"(i1 %25), !dbg !26 - %26 = call %Rational @rational_from_c_string(ptr @15), !dbg !27 - %27 = call %Rational @rational_from_c_string(ptr @16), !dbg !28 - %28 = call i1 @rational_less_rational(%Rational %26, %Rational %27), !dbg !28 - call void @"println <:Bool>"(i1 %28), !dbg !28 - %29 = call %Rational @rational_from_c_string(ptr @17), !dbg !29 - %30 = call %Rational @rational_from_c_string(ptr @18), !dbg !30 - %31 = call i1 @"<:Rational> > <:Rational>"(%Rational %29, %Rational %30), !dbg !30 - call void @"println <:Bool>"(i1 %31), !dbg !30 - %32 = call %Rational @rational_from_c_string(ptr @19), !dbg !31 - %33 = call %Rational @rational_from_c_string(ptr @20), !dbg !32 - %34 = call i1 @"<:Rational> <= <:Rational>"(%Rational %32, %Rational %33), !dbg !32 - call void @"println <:Bool>"(i1 %34), !dbg !32 - %35 = call %Rational @rational_from_c_string(ptr @21), !dbg !33 - %36 = call %Rational @rational_from_c_string(ptr @22), !dbg !34 - %37 = call i1 @"<:Rational> <= <:Rational>"(%Rational %35, %Rational %36), !dbg !34 - call void @"println <:Bool>"(i1 %37), !dbg !34 - %38 = call %Rational @rational_from_c_string(ptr @23), !dbg !35 - %39 = call %Rational @rational_from_c_string(ptr @24), !dbg !36 - %40 = call i1 @"<:Rational> >= <:Rational>"(%Rational %38, %Rational %39), !dbg !36 - call void @"println <:Bool>"(i1 %40), !dbg !36 - %41 = call %Rational @rational_from_c_string(ptr @25), !dbg !37 - %42 = call %Rational @rational_from_c_string(ptr @26), !dbg !38 - %43 = call i1 @"<:Rational> >= <:Rational>"(%Rational %41, %Rational %42), !dbg !38 - call void @"println <:Bool>"(i1 %43), !dbg !38 - br label %return, !dbg !38 - -return: ; preds = %0 - ret void -} - -define private void @"println <:Rational>"(%Rational %0) !dbg !39 { +define private void @"println <:Rational>"(%Rational %0) !dbg !35 { %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 - %2 = load %Rational, ptr %x, align 8, !dbg !40 - %3 = call %String @rational_as_string(%Rational %2), !dbg !40 - call void @"println <:String>"(%String %3), !dbg !40 - br label %return, !dbg !41 + %2 = load %Rational, ptr %x, align 8, !dbg !36 + %3 = call %String @rational_as_string(%Rational %2), !dbg !36 + call void @"println <:String>"(%String %3), !dbg !36 + br label %return, !dbg !37 return: ; preds = %1 ret void @@ -159,13 +133,15 @@ declare %Rational @rational_slash_rational(%Rational, %Rational) declare %Rational @integer_slash_integer(%Integer, %Integer) -define private void @"println <:Bool>"(i1 %0) !dbg !42 { +declare %Integer @integer_from_i64(i64) + +define private void @"println <:Bool>"(i1 %0) !dbg !38 { %x = alloca i1, align 1 store i1 %0, ptr %x, align 1 - %2 = load i1, ptr %x, align 1, !dbg !43 - %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !43 - call void @"println <:String>"(%String %3), !dbg !43 - br label %return, !dbg !44 + %2 = load i1, ptr %x, align 1, !dbg !39 + %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !39 + call void @"println <:String>"(%String %3), !dbg !39 + br label %return, !dbg !40 return: ; preds = %1 ret void @@ -175,21 +151,21 @@ declare %String @"String from <:Bool>"(i1) declare i1 @rational_eq_rational(%Rational, %Rational) -define private i1 @"<:Rational> != <:Rational>"(%Rational %0, %Rational %1) !dbg !45 { +define private i1 @"<:Rational> != <:Rational>"(%Rational %0, %Rational %1) !dbg !41 { %return_value = alloca i1, align 1 %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 %y = alloca %Rational, align 8 store %Rational %1, ptr %y, align 8 - %3 = load %Rational, ptr %x, align 8, !dbg !46 - %4 = load %Rational, ptr %y, align 8, !dbg !46 - %5 = call i1 @rational_eq_rational(%Rational %3, %Rational %4), !dbg !46 - %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !46 - %"$tmp@776" = alloca i1, align 1, !dbg !46 - store i1 %6, ptr %"$tmp@776", align 1, !dbg !46 - %7 = load i1, ptr %"$tmp@776", align 1, !dbg !46 - store i1 %7, ptr %return_value, align 1, !dbg !46 - br label %return, !dbg !46 + %3 = load %Rational, ptr %x, align 8, !dbg !42 + %4 = load %Rational, ptr %y, align 8, !dbg !42 + %5 = call i1 @rational_eq_rational(%Rational %3, %Rational %4), !dbg !42 + %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !42 + %"$tmp@776" = alloca i1, align 1, !dbg !42 + store i1 %6, ptr %"$tmp@776", align 1, !dbg !42 + %7 = load i1, ptr %"$tmp@776", align 1, !dbg !42 + store i1 %7, ptr %return_value, align 1, !dbg !42 + br label %return, !dbg !42 return: ; preds = %2 %8 = load i1, ptr %return_value, align 1 @@ -200,62 +176,62 @@ declare i1 @"not <:Bool>"(i1) declare i1 @rational_less_rational(%Rational, %Rational) -define private i1 @"<:Rational> > <:Rational>"(%Rational %0, %Rational %1) !dbg !47 { +define private i1 @"<:Rational> > <:Rational>"(%Rational %0, %Rational %1) !dbg !43 { %return_value = alloca i1, align 1 %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 %y = alloca %Rational, align 8 store %Rational %1, ptr %y, align 8 - %3 = load %Rational, ptr %y, align 8, !dbg !48 - %4 = load %Rational, ptr %x, align 8, !dbg !48 - %5 = call i1 @rational_less_rational(%Rational %3, %Rational %4), !dbg !48 - %"$tmp@1032" = alloca i1, align 1, !dbg !48 - store i1 %5, ptr %"$tmp@1032", align 1, !dbg !48 - %6 = load i1, ptr %"$tmp@1032", align 1, !dbg !48 - store i1 %6, ptr %return_value, align 1, !dbg !48 - br label %return, !dbg !48 + %3 = load %Rational, ptr %y, align 8, !dbg !44 + %4 = load %Rational, ptr %x, align 8, !dbg !44 + %5 = call i1 @rational_less_rational(%Rational %3, %Rational %4), !dbg !44 + %"$tmp@1032" = alloca i1, align 1, !dbg !44 + store i1 %5, ptr %"$tmp@1032", align 1, !dbg !44 + %6 = load i1, ptr %"$tmp@1032", align 1, !dbg !44 + store i1 %6, ptr %return_value, align 1, !dbg !44 + br label %return, !dbg !44 return: ; preds = %2 %7 = load i1, ptr %return_value, align 1 ret i1 %7 } -define private i1 @"<:Rational> <= <:Rational>"(%Rational %0, %Rational %1) !dbg !49 { +define private i1 @"<:Rational> <= <:Rational>"(%Rational %0, %Rational %1) !dbg !45 { %return_value = alloca i1, align 1 %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 %y = alloca %Rational, align 8 store %Rational %1, ptr %y, align 8 - %3 = load %Rational, ptr %x, align 8, !dbg !50 - %4 = load %Rational, ptr %y, align 8, !dbg !50 - %5 = call i1 @"<:Rational> > <:Rational>"(%Rational %3, %Rational %4), !dbg !50 - %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !50 - %"$tmp@1068" = alloca i1, align 1, !dbg !50 - store i1 %6, ptr %"$tmp@1068", align 1, !dbg !50 - %7 = load i1, ptr %"$tmp@1068", align 1, !dbg !50 - store i1 %7, ptr %return_value, align 1, !dbg !50 - br label %return, !dbg !50 + %3 = load %Rational, ptr %x, align 8, !dbg !46 + %4 = load %Rational, ptr %y, align 8, !dbg !46 + %5 = call i1 @"<:Rational> > <:Rational>"(%Rational %3, %Rational %4), !dbg !46 + %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !46 + %"$tmp@1068" = alloca i1, align 1, !dbg !46 + store i1 %6, ptr %"$tmp@1068", align 1, !dbg !46 + %7 = load i1, ptr %"$tmp@1068", align 1, !dbg !46 + store i1 %7, ptr %return_value, align 1, !dbg !46 + br label %return, !dbg !46 return: ; preds = %2 %8 = load i1, ptr %return_value, align 1 ret i1 %8 } -define private i1 @"<:Rational> >= <:Rational>"(%Rational %0, %Rational %1) !dbg !51 { +define private i1 @"<:Rational> >= <:Rational>"(%Rational %0, %Rational %1) !dbg !47 { %return_value = alloca i1, align 1 %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 %y = alloca %Rational, align 8 store %Rational %1, ptr %y, align 8 - %3 = load %Rational, ptr %x, align 8, !dbg !52 - %4 = load %Rational, ptr %y, align 8, !dbg !52 - %5 = call i1 @rational_less_rational(%Rational %3, %Rational %4), !dbg !52 - %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !52 - %"$tmp@1110" = alloca i1, align 1, !dbg !52 - store i1 %6, ptr %"$tmp@1110", align 1, !dbg !52 - %7 = load i1, ptr %"$tmp@1110", align 1, !dbg !52 - store i1 %7, ptr %return_value, align 1, !dbg !52 - br label %return, !dbg !52 + %3 = load %Rational, ptr %x, align 8, !dbg !48 + %4 = load %Rational, ptr %y, align 8, !dbg !48 + %5 = call i1 @rational_less_rational(%Rational %3, %Rational %4), !dbg !48 + %6 = call i1 @"not <:Bool>"(i1 %5), !dbg !48 + %"$tmp@1110" = alloca i1, align 1, !dbg !48 + store i1 %6, ptr %"$tmp@1110", align 1, !dbg !48 + %7 = load i1, ptr %"$tmp@1110", align 1, !dbg !48 + store i1 %7, ptr %return_value, align 1, !dbg !48 + br label %return, !dbg !48 return: ; preds = %2 %8 = load i1, ptr %return_value, align 1 @@ -268,53 +244,49 @@ return: ; preds = %2 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 8, column: 2, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 8, column: 2, scope: !9) -!11 = !DILocation(line: 0, column: 8, scope: !9) -!12 = !DILocation(line: 1, column: 9, scope: !9) -!13 = !DILocation(line: 2, column: 9, scope: !9) -!14 = !DILocation(line: 3, column: 8, scope: !9) -!15 = !DILocation(line: 3, column: 14, scope: !9) -!16 = !DILocation(line: 4, column: 8, scope: !9) -!17 = !DILocation(line: 4, column: 14, scope: !9) -!18 = !DILocation(line: 5, column: 8, scope: !9) -!19 = !DILocation(line: 5, column: 14, scope: !9) -!20 = !DILocation(line: 6, column: 8, scope: !9) -!21 = !DILocation(line: 6, column: 15, scope: !9) -!22 = !DILocation(line: 6, column: 19, scope: !9) -!23 = !DILocation(line: 7, column: 8, scope: !9) -!24 = !DILocation(line: 7, column: 15, scope: !9) -!25 = !DILocation(line: 8, column: 8, scope: !9) -!26 = !DILocation(line: 8, column: 15, scope: !9) -!27 = !DILocation(line: 9, column: 8, scope: !9) -!28 = !DILocation(line: 9, column: 14, scope: !9) -!29 = !DILocation(line: 10, column: 8, scope: !9) -!30 = !DILocation(line: 10, column: 14, scope: !9) -!31 = !DILocation(line: 11, column: 8, scope: !9) -!32 = !DILocation(line: 11, column: 15, scope: !9) -!33 = !DILocation(line: 12, column: 8, scope: !9) -!34 = !DILocation(line: 12, column: 15, scope: !9) -!35 = !DILocation(line: 13, column: 8, scope: !9) -!36 = !DILocation(line: 13, column: 15, scope: !9) -!37 = !DILocation(line: 14, column: 8, scope: !9) -!38 = !DILocation(line: 14, column: 15, scope: !9) -!39 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !9, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!40 = !DILocation(line: 11, column: 9, scope: !39) -!41 = !DILocation(line: 10, column: 6, scope: !39) -!42 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !9, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!43 = !DILocation(line: 11, column: 9, scope: !42) -!44 = !DILocation(line: 10, column: 6, scope: !42) -!45 = distinct !DISubprogram(name: "<:Rational> != <:Rational>", linkageName: "<:Rational> != <:Rational>", scope: !9, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!7 = !DILocation(line: 0, column: 8, scope: !3) +!8 = !DILocation(line: 1, column: 9, scope: !3) +!9 = !DILocation(line: 2, column: 9, scope: !3) +!10 = !DILocation(line: 3, column: 8, scope: !3) +!11 = !DILocation(line: 3, column: 14, scope: !3) +!12 = !DILocation(line: 4, column: 8, scope: !3) +!13 = !DILocation(line: 4, column: 14, scope: !3) +!14 = !DILocation(line: 5, column: 8, scope: !3) +!15 = !DILocation(line: 5, column: 14, scope: !3) +!16 = !DILocation(line: 6, column: 8, scope: !3) +!17 = !DILocation(line: 6, column: 15, scope: !3) +!18 = !DILocation(line: 6, column: 19, scope: !3) +!19 = !DILocation(line: 7, column: 8, scope: !3) +!20 = !DILocation(line: 7, column: 15, scope: !3) +!21 = !DILocation(line: 8, column: 8, scope: !3) +!22 = !DILocation(line: 8, column: 15, scope: !3) +!23 = !DILocation(line: 9, column: 8, scope: !3) +!24 = !DILocation(line: 9, column: 14, scope: !3) +!25 = !DILocation(line: 10, column: 8, scope: !3) +!26 = !DILocation(line: 10, column: 14, scope: !3) +!27 = !DILocation(line: 11, column: 8, scope: !3) +!28 = !DILocation(line: 11, column: 15, scope: !3) +!29 = !DILocation(line: 12, column: 8, scope: !3) +!30 = !DILocation(line: 12, column: 15, scope: !3) +!31 = !DILocation(line: 13, column: 8, scope: !3) +!32 = !DILocation(line: 13, column: 15, scope: !3) +!33 = !DILocation(line: 14, column: 8, scope: !3) +!34 = !DILocation(line: 14, column: 15, scope: !3) +!35 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !3, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!36 = !DILocation(line: 11, column: 9, scope: !35) +!37 = !DILocation(line: 10, column: 6, scope: !35) +!38 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !3, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!39 = !DILocation(line: 11, column: 9, scope: !38) +!40 = !DILocation(line: 10, column: 6, scope: !38) +!41 = distinct !DISubprogram(name: "<:Rational> != <:Rational>", linkageName: "<:Rational> != <:Rational>", scope: !3, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!42 = !DILocation(line: 14, column: 18, scope: !41) +!43 = distinct !DISubprogram(name: "<:Rational> > <:Rational>", linkageName: "<:Rational> > <:Rational>", scope: !3, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!44 = !DILocation(line: 14, column: 18, scope: !43) +!45 = distinct !DISubprogram(name: "<:Rational> <= <:Rational>", linkageName: "<:Rational> <= <:Rational>", scope: !3, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) !46 = !DILocation(line: 14, column: 18, scope: !45) -!47 = distinct !DISubprogram(name: "<:Rational> > <:Rational>", linkageName: "<:Rational> > <:Rational>", scope: !9, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!47 = distinct !DISubprogram(name: "<:Rational> >= <:Rational>", linkageName: "<:Rational> >= <:Rational>", scope: !3, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) !48 = !DILocation(line: 14, column: 18, scope: !47) -!49 = distinct !DISubprogram(name: "<:Rational> <= <:Rational>", linkageName: "<:Rational> <= <:Rational>", scope: !9, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!50 = !DILocation(line: 14, column: 18, scope: !49) -!51 = distinct !DISubprogram(name: "<:Rational> >= <:Rational>", linkageName: "<:Rational> >= <:Rational>", scope: !9, file: !2, line: 14, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!52 = !DILocation(line: 14, column: 18, scope: !51) diff --git a/src/tests/snapshots/ppl__tests__reference_mut.ir.snap b/src/tests/snapshots/ppl__tests__reference_mut.ir.snap index 5953030d..2cf24792 100644 --- a/src/tests/snapshots/ppl__tests__reference_mut.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_mut.ir.snap @@ -5,100 +5,76 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @x = global %Integer zeroinitializer @y = global ptr null -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @initialize.1(), !dbg !8 + %1 = load ptr, ptr @y, align 8, !dbg !9 + %2 = call %Integer @clone_integer(ptr %1), !dbg !9 + call void @"println <:Integer>"(%Integer %2), !dbg !9 + %3 = load ptr, ptr @y, align 8, !dbg !10 + %4 = call %Integer @integer_from_i64(i64 2), !dbg !11 + store %Integer %4, ptr %3, align 8, !dbg !11 + %5 = load ptr, ptr @y, align 8, !dbg !12 + %6 = call %Integer @clone_integer(ptr %5), !dbg !12 + call void @"println <:Integer>"(%Integer %6), !dbg !12 + %7 = call %Integer @clone_integer(ptr @x), !dbg !13 + call void @"println <:Integer>"(%Integer %7), !dbg !13 + call void @destroy_integer(ptr @x), !dbg !14 + br label %return, !dbg !14 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - call void @initialize.2(), !dbg !12 - %1 = load ptr, ptr @y, align 8, !dbg !13 - %2 = call %Integer @clone_integer(ptr %1), !dbg !13 - call void @"println <:Integer>"(%Integer %2), !dbg !13 - %3 = load ptr, ptr @y, align 8, !dbg !14 - %4 = call %Integer @integer_from_i64(i64 2), !dbg !15 - store %Integer %4, ptr %3, align 8, !dbg !15 - %5 = load ptr, ptr @y, align 8, !dbg !16 - %6 = call %Integer @clone_integer(ptr %5), !dbg !16 - call void @"println <:Integer>"(%Integer %6), !dbg !16 - %7 = call %Integer @clone_integer(ptr @x), !dbg !17 - call void @"println <:Integer>"(%Integer %7), !dbg !17 - call void @destroy_integer(ptr @x), !dbg !18 - br label %return, !dbg !18 +define private void @initialize() !dbg !15 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !16 + store %Integer %1, ptr @x, align 8, !dbg !16 + br label %return, !dbg !16 return: ; preds = %0 ret void } -define private void @initialize.1() !dbg !19 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !20 - store %Integer %1, ptr @x, align 8, !dbg !20 - br label %return, !dbg !20 - -return: ; preds = %0 - ret void -} +declare %Integer @integer_from_i64(i64) -define private void @initialize.2() !dbg !21 { - %1 = call ptr @"reference to mutable <:ReferenceMut>"(ptr @x), !dbg !22 - store ptr %1, ptr @y, align 8, !dbg !22 - br label %return, !dbg !22 +define private void @initialize.1() !dbg !17 { + %1 = call ptr @"reference to mutable <:ReferenceMut>"(ptr @x), !dbg !18 + store ptr %1, ptr @y, align 8, !dbg !18 + br label %return, !dbg !18 return: ; preds = %0 ret void } -define private ptr @"reference to mutable <:ReferenceMut>"(ptr %0) !dbg !23 { +define private ptr @"reference to mutable <:ReferenceMut>"(ptr %0) !dbg !19 { %return_value = alloca ptr, align 8 %ref = alloca ptr, align 8 store ptr %0, ptr %ref, align 8 - %2 = load ptr, ptr %ref, align 8, !dbg !24 - %"$tmp@4600" = alloca ptr, align 8, !dbg !24 - store ptr %2, ptr %"$tmp@4600", align 8, !dbg !24 - %3 = load ptr, ptr %"$tmp@4600", align 8, !dbg !24 - store ptr %3, ptr %return_value, align 8, !dbg !24 - br label %return, !dbg !24 + %2 = load ptr, ptr %ref, align 8, !dbg !20 + %"$tmp@4600" = alloca ptr, align 8, !dbg !20 + store ptr %2, ptr %"$tmp@4600", align 8, !dbg !20 + %3 = load ptr, ptr %"$tmp@4600", align 8, !dbg !20 + store ptr %3, ptr %return_value, align 8, !dbg !20 + br label %return, !dbg !20 return: ; preds = %1 %4 = load ptr, ptr %return_value, align 8 ret ptr %4 } -define private void @"println <:Integer>"(%Integer %0) !dbg !25 { +define private void @"println <:Integer>"(%Integer %0) !dbg !21 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !26 - %3 = call %String @integer_as_string(%Integer %2), !dbg !26 - call void @"println <:String>"(%String %3), !dbg !26 - br label %return, !dbg !26 + %2 = load %Integer, ptr %x, align 8, !dbg !22 + %3 = call %String @integer_as_string(%Integer %2), !dbg !22 + call void @"println <:String>"(%String %3), !dbg !22 + br label %return, !dbg !22 return: ; preds = %1 ret void @@ -118,27 +94,23 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 6, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 6, scope: !9) -!11 = !DILocation(line: 0, column: 12, scope: !9) -!12 = !DILocation(line: 1, column: 8, scope: !9) -!13 = !DILocation(line: 2, column: 8, scope: !9) -!14 = !DILocation(line: 3, scope: !9) -!15 = !DILocation(line: 3, column: 4, scope: !9) -!16 = !DILocation(line: 4, column: 8, scope: !9) -!17 = !DILocation(line: 5, column: 8, scope: !9) -!18 = !DILocation(line: 0, scope: !9) -!19 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!20 = !DILocation(line: 0, column: 12, scope: !19) -!21 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !9, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!22 = !DILocation(line: 1, column: 29, scope: !21) -!23 = distinct !DISubprogram(name: "reference to mutable <:ReferenceMut>", linkageName: "reference to mutable <:ReferenceMut>", scope: !21, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!24 = !DILocation(line: 6, scope: !23) -!25 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !9, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!26 = !DILocation(line: 6, scope: !25) +!7 = !DILocation(line: 0, column: 12, scope: !3) +!8 = !DILocation(line: 1, column: 8, scope: !3) +!9 = !DILocation(line: 2, column: 8, scope: !3) +!10 = !DILocation(line: 3, scope: !3) +!11 = !DILocation(line: 3, column: 4, scope: !3) +!12 = !DILocation(line: 4, column: 8, scope: !3) +!13 = !DILocation(line: 5, column: 8, scope: !3) +!14 = !DILocation(line: 0, scope: !3) +!15 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 0, column: 12, scope: !15) +!17 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!18 = !DILocation(line: 1, column: 29, scope: !17) +!19 = distinct !DISubprogram(name: "reference to mutable <:ReferenceMut>", linkageName: "reference to mutable <:ReferenceMut>", scope: !17, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!20 = !DILocation(line: 6, scope: !19) +!21 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 6, scope: !21) diff --git a/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap b/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap index fcb840fd..aa740263 100644 --- a/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_to_literal.ir.snap @@ -5,66 +5,40 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @"$tmp@39" = global %Integer zeroinitializer -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @"foo <:Reference>"(ptr @"$tmp@39"), !dbg !7 + call void @destroy_integer(ptr @"$tmp@39"), !dbg !7 + br label %return, !dbg !7 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - call void @"foo <:Reference>"(ptr @"$tmp@39"), !dbg !11 - call void @destroy_integer(ptr @"$tmp@39"), !dbg !11 - br label %return, !dbg !11 - -return: ; preds = %0 - ret void -} - -define void @"foo <:Reference>"(ptr %0) !dbg !12 { +define void @"foo <:Reference>"(ptr %0) !dbg !8 { %x = alloca ptr, align 8 store ptr %0, ptr %x, align 8 - %2 = load ptr, ptr %x, align 8, !dbg !13 - %3 = call %Integer @clone_integer(ptr %2), !dbg !13 - call void @"println <:Integer>"(%Integer %3), !dbg !13 - br label %return, !dbg !14 + %2 = load ptr, ptr %x, align 8, !dbg !9 + %3 = call %Integer @clone_integer(ptr %2), !dbg !9 + call void @"println <:Integer>"(%Integer %3), !dbg !9 + br label %return, !dbg !10 return: ; preds = %1 ret void } -define private void @"println <:Integer>"(%Integer %0) !dbg !15 { +define private void @"println <:Integer>"(%Integer %0) !dbg !11 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !16 - %3 = call %String @integer_as_string(%Integer %2), !dbg !16 - call void @"println <:String>"(%String %3), !dbg !16 - br label %return, !dbg !16 + %2 = load %Integer, ptr %x, align 8, !dbg !12 + %3 = call %String @integer_as_string(%Integer %2), !dbg !12 + call void @"println <:String>"(%String %3), !dbg !12 + br label %return, !dbg !12 return: ; preds = %1 ret void @@ -76,15 +50,17 @@ declare %String @integer_as_string(%Integer) declare %Integer @clone_integer(ptr) -define private void @initialize.1() !dbg !17 { - %1 = call %Integer @integer_from_i64(i64 42), !dbg !18 - store %Integer %1, ptr @"$tmp@39", align 8, !dbg !18 - br label %return, !dbg !18 +define private void @initialize() !dbg !13 { + %1 = call %Integer @integer_from_i64(i64 42), !dbg !14 + store %Integer %1, ptr @"$tmp@39", align 8, !dbg !14 + br label %return, !dbg !14 return: ; preds = %0 ret void } +declare %Integer @integer_from_i64(i64) + declare void @destroy_integer(ptr) !llvm.module.flags = !{!0} @@ -93,19 +69,15 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 2, column: 6, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 2, column: 6, scope: !9) -!11 = !DILocation(line: 2, column: 4, scope: !9) -!12 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 0, column: 32, scope: !12) -!14 = !DILocation(line: 0, column: 24, scope: !12) -!15 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !12, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 2, column: 6, scope: !15) -!17 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!18 = !DILocation(line: 2, column: 4, scope: !17) +!7 = !DILocation(line: 2, column: 4, scope: !3) +!8 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!9 = !DILocation(line: 0, column: 32, scope: !8) +!10 = !DILocation(line: 0, column: 24, scope: !8) +!11 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !8, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!12 = !DILocation(line: 2, column: 6, scope: !11) +!13 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!14 = !DILocation(line: 2, column: 4, scope: !13) diff --git a/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap b/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap index 60f360cd..036716b5 100644 --- a/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_to_none.ir.snap @@ -5,50 +5,23 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -%Integer = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@1 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 +@0 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @"foo <:Reference>"(), !dbg !8 br label %return, !dbg !8 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - call void @"foo <:Reference>"(), !dbg !12 - br label %return, !dbg !12 - -return: ; preds = %0 - ret void -} - -define void @"foo <:Reference>"() !dbg !13 { - %1 = call %String @string_from_c_string_and_length(ptr @1, i64 3), !dbg !14 - call void @"println <:String>"(%String %1), !dbg !14 - br label %return, !dbg !15 +define void @"foo <:Reference>"() !dbg !9 { + %1 = call %String @string_from_c_string_and_length(ptr @0, i64 3), !dbg !10 + call void @"println <:String>"(%String %1), !dbg !10 + br label %return, !dbg !11 return: ; preds = %0 ret void @@ -56,8 +29,10 @@ return: ; preds = %0 declare void @"println <:String>"(%String) -define private void @initialize.1() !dbg !16 { - br label %return, !dbg !17 +declare %String @string_from_c_string_and_length(ptr, i64) + +define private void @initialize() !dbg !12 { + br label %return, !dbg !13 return: ; preds = %0 ret void @@ -69,18 +44,14 @@ return: ; preds = %0 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 3, column: 5, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 3, column: 5, scope: !9) -!11 = !DILocation(line: 2, column: 8, scope: !9) -!12 = !DILocation(line: 3, column: 4, scope: !9) -!13 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!14 = !DILocation(line: 0, column: 27, scope: !13) -!15 = !DILocation(line: 0, column: 19, scope: !13) -!16 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!17 = !DILocation(line: 2, column: 8, scope: !16) +!7 = !DILocation(line: 2, column: 8, scope: !3) +!8 = !DILocation(line: 3, column: 4, scope: !3) +!9 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 0, column: 27, scope: !9) +!11 = !DILocation(line: 0, column: 19, scope: !9) +!12 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!13 = !DILocation(line: 2, column: 8, scope: !12) diff --git a/src/tests/snapshots/ppl__tests__references.hir.snap b/src/tests/snapshots/ppl__tests__references.hir.snap index 05d9d523..e33f9f6d 100644 --- a/src/tests/snapshots/ppl__tests__references.hir.snap +++ b/src/tests/snapshots/ppl__tests__references.hir.snap @@ -2,9 +2,9 @@ source: src/tests/mod.rs expression: hir --- -let n: Integer = `size of <:Type>`((Type:Type)) +let n: Integer = `size of <:Type>`(Type { name: "I32", size: 4 }) let address: MemoryAddress = `allocate <:Integer> bytes`(`clone <:Reference>`((n:Integer))) -let value: ReferenceMut = `<:Type> at <:Reference>`((Type:Type), (&address:Reference)) +let value: ReferenceMut = `<:Type> at <:Reference>`(Type { name: "I32", size: 4 }, (&address:Reference)) (value:ReferenceMut) = `<:Integer> as I32`(0) `println <:I32>`((*value:I32)) (value:ReferenceMut) = `<:Integer> as I32`(1) diff --git a/src/tests/snapshots/ppl__tests__references.ir.snap b/src/tests/snapshots/ppl__tests__references.ir.snap index 908aa044..e24da595 100644 --- a/src/tests/snapshots/ppl__tests__references.ir.snap +++ b/src/tests/snapshots/ppl__tests__references.ir.snap @@ -5,110 +5,74 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"Type" = type { ptr } %Integer = type { ptr } %MemoryAddress = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } %"TypeImpl" = type { %String, %Integer } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@"Type" = private global %"Type" zeroinitializer -@1 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 @n = global %Integer zeroinitializer +@0 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 @address = global %MemoryAddress zeroinitializer @value = global ptr null +@1 = private unnamed_addr constant [4 x i8] c"I32\00", align 1 -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define private void @initialize.1() !dbg !9 { - %1 = alloca %"Type", align 8, !dbg !10 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 3), !dbg !11 - store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 - %3 = call %Integer @integer_from_i64(i64 4), !dbg !11 - store %Integer %3, ptr %"Type.size", align 8, !dbg !11 - %4 = load %"Type", ptr %1, align 8, !dbg !11 - store %"Type" %4, ptr @"Type", align 8, !dbg !11 - br label %return, !dbg !11 - -return: ; preds = %0 - ret void -} - -define void @main.execute() !dbg !12 { - call void @initialize(), !dbg !13 - call void @initialize.1(), !dbg !14 - call void @initialize.2(), !dbg !15 - call void @initialize.3(), !dbg !16 - call void @initialize.4(), !dbg !17 - %1 = load ptr, ptr @value, align 8, !dbg !18 - %2 = call %Integer @integer_from_i64(i64 0), !dbg !19 - %3 = call i32 @integer_as_i32(%Integer %2), !dbg !19 - store i32 %3, ptr %1, align 4, !dbg !19 - %4 = load ptr, ptr @value, align 8, !dbg !20 - %5 = load i32, ptr %4, align 4, !dbg !20 - call void @"println <:I32>"(i32 %5), !dbg !20 - %6 = load ptr, ptr @value, align 8, !dbg !21 - %7 = call %Integer @integer_from_i64(i64 1), !dbg !22 - %8 = call i32 @integer_as_i32(%Integer %7), !dbg !22 - store i32 %8, ptr %6, align 4, !dbg !22 - %9 = load ptr, ptr @value, align 8, !dbg !23 - %10 = load i32, ptr %9, align 4, !dbg !23 - call void @"println <:I32>"(i32 %10), !dbg !23 - call void @free_memory(ptr @address), !dbg !24 - call void @destroy_integer(ptr @n), !dbg !25 - br label %return, !dbg !25 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @initialize.1(), !dbg !8 + call void @initialize.2(), !dbg !9 + %1 = load ptr, ptr @value, align 8, !dbg !10 + %2 = call %Integer @integer_from_i64(i64 0), !dbg !11 + %3 = call i32 @integer_as_i32(%Integer %2), !dbg !11 + store i32 %3, ptr %1, align 4, !dbg !11 + %4 = load ptr, ptr @value, align 8, !dbg !12 + %5 = load i32, ptr %4, align 4, !dbg !12 + call void @"println <:I32>"(i32 %5), !dbg !12 + %6 = load ptr, ptr @value, align 8, !dbg !13 + %7 = call %Integer @integer_from_i64(i64 1), !dbg !14 + %8 = call i32 @integer_as_i32(%Integer %7), !dbg !14 + store i32 %8, ptr %6, align 4, !dbg !14 + %9 = load ptr, ptr @value, align 8, !dbg !15 + %10 = load i32, ptr %9, align 4, !dbg !15 + call void @"println <:I32>"(i32 %10), !dbg !15 + call void @free_memory(ptr @address), !dbg !16 + call void @destroy_integer(ptr @n), !dbg !17 + br label %return, !dbg !17 return: ; preds = %0 ret void } -define private void @initialize.2() !dbg !26 { - %1 = load %"Type", ptr @"Type", align 8, !dbg !27 - %2 = call %Integer @"size of <:Type>"(%"Type" %1), !dbg !27 - store %Integer %2, ptr @n, align 8, !dbg !27 - br label %return, !dbg !27 +define private void @initialize() !dbg !18 { + %1 = alloca %"Type", align 8, !dbg !19 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !19 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 3), !dbg !20 + store %String %2, ptr %"Type.name", align 8, !dbg !20 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !20 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !20 + store %Integer %3, ptr %"Type.size", align 8, !dbg !20 + %4 = load %"Type", ptr %1, align 8, !dbg !20 + %5 = call %Integer @"size of <:Type>"(%"Type" %4), !dbg !20 + store %Integer %5, ptr @n, align 8, !dbg !20 + br label %return, !dbg !20 return: ; preds = %0 ret void } -define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !28 { +define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !21 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !29 - %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !29 - %3 = call %Integer @clone_integer(ptr %size), !dbg !29 - %"$tmp@4252" = alloca %Integer, align 8, !dbg !29 - store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !29 - %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !29 - store %Integer %4, ptr %return_value, align 8, !dbg !29 - br label %return, !dbg !29 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !22 + %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !22 + %3 = call %Integer @clone_integer(ptr %size), !dbg !22 + %"$tmp@4252" = alloca %Integer, align 8, !dbg !22 + store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !22 + %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !22 + store %Integer %4, ptr %return_value, align 8, !dbg !22 + br label %return, !dbg !22 return: ; preds = %1 %5 = load %Integer, ptr %return_value, align 8 @@ -117,11 +81,15 @@ return: ; preds = %1 declare %Integer @clone_integer(ptr) -define private void @initialize.3() !dbg !30 { - %1 = call %Integer @clone_integer(ptr @n), !dbg !31 - %2 = call %MemoryAddress @allocate_n_bytes(%Integer %1), !dbg !31 - store %MemoryAddress %2, ptr @address, align 8, !dbg !31 - br label %return, !dbg !31 +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @initialize.1() !dbg !23 { + %1 = call %Integer @clone_integer(ptr @n), !dbg !24 + %2 = call %MemoryAddress @allocate_n_bytes(%Integer %1), !dbg !24 + store %MemoryAddress %2, ptr @address, align 8, !dbg !24 + br label %return, !dbg !24 return: ; preds = %0 ret void @@ -129,11 +97,19 @@ return: ; preds = %0 declare %MemoryAddress @allocate_n_bytes(%Integer) -define private void @initialize.4() !dbg !32 { - %1 = load %"Type", ptr @"Type", align 8, !dbg !33 - %2 = call ptr @read_memory(%"Type" %1, ptr @address), !dbg !34 - store ptr %2, ptr @value, align 8, !dbg !34 - br label %return, !dbg !34 +define private void @initialize.2() !dbg !25 { + %1 = alloca %"Type", align 8, !dbg !26 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !26 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !26 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 3), !dbg !27 + store %String %2, ptr %"Type.name", align 8, !dbg !27 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !27 + %3 = call %Integer @integer_from_i64(i64 4), !dbg !27 + store %Integer %3, ptr %"Type.size", align 8, !dbg !27 + %4 = load %"Type", ptr %1, align 8, !dbg !27 + %5 = call ptr @read_memory(%"Type" %4, ptr @address), !dbg !28 + store ptr %5, ptr @value, align 8, !dbg !28 + br label %return, !dbg !28 return: ; preds = %0 ret void @@ -143,13 +119,13 @@ declare ptr @read_memory(%"Type", ptr) declare i32 @integer_as_i32(%Integer) -define private void @"println <:I32>"(i32 %0) !dbg !35 { +define private void @"println <:I32>"(i32 %0) !dbg !29 { %x = alloca i32, align 4 store i32 %0, ptr %x, align 4 - %2 = load i32, ptr %x, align 4, !dbg !36 - %3 = call %String @i32_as_string(i32 %2), !dbg !36 - call void @"println <:String>"(%String %3), !dbg !36 - br label %return, !dbg !37 + %2 = load i32, ptr %x, align 4, !dbg !30 + %3 = call %String @i32_as_string(i32 %2), !dbg !30 + call void @"println <:String>"(%String %3), !dbg !30 + br label %return, !dbg !31 return: ; preds = %1 ret void @@ -169,38 +145,32 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 5, column: 7, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 0, column: 16, scope: !9) -!11 = !DILocation(line: 0, scope: !9) -!12 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 5, column: 7, scope: !12) -!14 = !DILocation(line: 0, column: 16, scope: !12) -!15 = !DILocation(line: 0, column: 8, scope: !12) -!16 = !DILocation(line: 2, column: 14, scope: !12) -!17 = !DILocation(line: 3, column: 12, scope: !12) -!18 = !DILocation(line: 4, scope: !12) -!19 = !DILocation(line: 4, column: 8, scope: !12) -!20 = !DILocation(line: 5, column: 8, scope: !12) -!21 = !DILocation(line: 6, scope: !12) -!22 = !DILocation(line: 6, column: 8, scope: !12) -!23 = !DILocation(line: 7, column: 8, scope: !12) -!24 = !DILocation(line: 8, column: 5, scope: !12) -!25 = !DILocation(line: 0, scope: !12) -!26 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !12, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!27 = !DILocation(line: 0, column: 16, scope: !26) -!28 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !26, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!29 = !DILocation(line: 8, column: 12, scope: !28) -!30 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !12, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!31 = !DILocation(line: 2, column: 23, scope: !30) -!32 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !12, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!33 = !DILocation(line: 3, column: 12, scope: !32) -!34 = !DILocation(line: 3, column: 19, scope: !32) -!35 = distinct !DISubprogram(name: "println <:I32>", linkageName: "println <:I32>", scope: !12, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!36 = !DILocation(line: 8, column: 12, scope: !35) -!37 = !DILocation(line: 8, column: 3, scope: !35) +!7 = !DILocation(line: 0, column: 8, scope: !3) +!8 = !DILocation(line: 2, column: 14, scope: !3) +!9 = !DILocation(line: 3, column: 12, scope: !3) +!10 = !DILocation(line: 4, scope: !3) +!11 = !DILocation(line: 4, column: 8, scope: !3) +!12 = !DILocation(line: 5, column: 8, scope: !3) +!13 = !DILocation(line: 6, scope: !3) +!14 = !DILocation(line: 6, column: 8, scope: !3) +!15 = !DILocation(line: 7, column: 8, scope: !3) +!16 = !DILocation(line: 8, column: 5, scope: !3) +!17 = !DILocation(line: 0, scope: !3) +!18 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 0, column: 16, scope: !18) +!20 = !DILocation(line: 0, scope: !18) +!21 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !18, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 8, column: 12, scope: !21) +!23 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!24 = !DILocation(line: 2, column: 23, scope: !23) +!25 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!26 = !DILocation(line: 3, column: 12, scope: !25) +!27 = !DILocation(line: 0, scope: !25) +!28 = !DILocation(line: 3, column: 19, scope: !25) +!29 = distinct !DISubprogram(name: "println <:I32>", linkageName: "println <:I32>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!30 = !DILocation(line: 8, column: 12, scope: !29) +!31 = !DILocation(line: 8, column: 3, scope: !29) diff --git a/src/tests/snapshots/ppl__tests__star.ir.snap b/src/tests/snapshots/ppl__tests__star.ir.snap index 24c55bc6..9e056135 100644 --- a/src/tests/snapshots/ppl__tests__star.ir.snap +++ b/src/tests/snapshots/ppl__tests__star.ir.snap @@ -5,56 +5,29 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } %Integer = type { ptr } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - %1 = call %Integer @integer_from_i64(i64 2), !dbg !11 - %2 = call %Integer @integer_from_i64(i64 2), !dbg !12 - %3 = call %Integer @integer_from_i64(i64 2), !dbg !13 - %4 = call %Integer @integer_star_integer(%Integer %2, %Integer %3), !dbg !13 - %5 = call %Integer @integer_plus_integer(%Integer %1, %Integer %4), !dbg !13 - call void @"println <:Integer>"(%Integer %5), !dbg !13 - br label %return, !dbg !13 +define void @main.execute() !dbg !3 { + %1 = call %Integer @integer_from_i64(i64 2), !dbg !7 + %2 = call %Integer @integer_from_i64(i64 2), !dbg !8 + %3 = call %Integer @integer_from_i64(i64 2), !dbg !9 + %4 = call %Integer @integer_star_integer(%Integer %2, %Integer %3), !dbg !9 + %5 = call %Integer @integer_plus_integer(%Integer %1, %Integer %4), !dbg !9 + call void @"println <:Integer>"(%Integer %5), !dbg !9 + br label %return, !dbg !9 return: ; preds = %0 ret void } -define private void @"println <:Integer>"(%Integer %0) !dbg !14 { +define private void @"println <:Integer>"(%Integer %0) !dbg !10 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !15 - %3 = call %String @integer_as_string(%Integer %2), !dbg !15 - call void @"println <:String>"(%String %3), !dbg !15 - br label %return, !dbg !15 + %2 = load %Integer, ptr %x, align 8, !dbg !11 + %3 = call %String @integer_as_string(%Integer %2), !dbg !11 + call void @"println <:String>"(%String %3), !dbg !11 + br label %return, !dbg !11 return: ; preds = %1 ret void @@ -66,6 +39,8 @@ declare %String @integer_as_string(%Integer) declare %Integer @integer_plus_integer(%Integer, %Integer) +declare %Integer @integer_from_i64(i64) + declare %Integer @integer_star_integer(%Integer, %Integer) !llvm.module.flags = !{!0} @@ -74,16 +49,12 @@ declare %Integer @integer_star_integer(%Integer, %Integer) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 17, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 0, column: 17, scope: !9) -!11 = !DILocation(line: 0, column: 8, scope: !9) -!12 = !DILocation(line: 0, column: 12, scope: !9) -!13 = !DILocation(line: 0, column: 16, scope: !9) -!14 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !9, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!15 = !DILocation(line: 0, column: 17, scope: !14) +!7 = !DILocation(line: 0, column: 8, scope: !3) +!8 = !DILocation(line: 0, column: 12, scope: !3) +!9 = !DILocation(line: 0, column: 16, scope: !3) +!10 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!11 = !DILocation(line: 0, column: 17, scope: !10) diff --git a/src/tests/snapshots/ppl__tests__string.hir.snap b/src/tests/snapshots/ppl__tests__string.hir.snap index 6afe8f65..71615a91 100644 --- a/src/tests/snapshots/ppl__tests__string.hir.snap +++ b/src/tests/snapshots/ppl__tests__string.hir.snap @@ -8,8 +8,8 @@ expression: hir `println <:String>`(`String from <:Bool>`(true)) `println <:String>`(`String from <:Integer>`(0)) `println <:String>`(`String from <:Rational>`(0.0)) -`println <:String>`(`String from <:Type>`((Type:Type))) -`println <:String>`(`String from <:Type>>`((Type>:Type>))) +`println <:String>`(`String from <:Type>`(Type { name: "Integer", size: 8 })) +`println <:String>`(`String from <:Type>>`(Type> { name: "Array", size: 8 })) ==MONOMORPHIZED== diff --git a/src/tests/snapshots/ppl__tests__string.ir.snap b/src/tests/snapshots/ppl__tests__string.ir.snap index 9eb60ddc..f19c54a9 100644 --- a/src/tests/snapshots/ppl__tests__string.ir.snap +++ b/src/tests/snapshots/ppl__tests__string.ir.snap @@ -5,111 +5,63 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"Type" = type { ptr } -%"Type>" = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } %Integer = type { ptr } +%Rational = type { ptr } +%"Type" = type { ptr } %"TypeImpl" = type { %String, %Integer } +%"Type>" = type { ptr } %"Type>Impl" = type { %String, %Integer } -%Rational = type { ptr } - -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@"Type" = private global %"Type" zeroinitializer -@1 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 -@"Type>" = private global %"Type>" zeroinitializer -@2 = private unnamed_addr constant [15 x i8] c"Array\00", align 1 -@3 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1 -@4 = private unnamed_addr constant [2 x i8] c" \00", align 1 -@5 = private unnamed_addr constant [7 x i8] c"World!\00", align 1 -@6 = private unnamed_addr constant [2 x i8] c"0\00", align 1 - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) -define private void @initialize.1() !dbg !9 { - %1 = alloca %"Type", align 8, !dbg !10 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 7), !dbg !11 - store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 - store %Integer %3, ptr %"Type.size", align 8, !dbg !11 - %4 = load %"Type", ptr %1, align 8, !dbg !11 - store %"Type" %4, ptr @"Type", align 8, !dbg !11 - br label %return, !dbg !11 - -return: ; preds = %0 - ret void -} - -define private void @initialize.2() !dbg !12 { - %1 = alloca %"Type>", align 8, !dbg !13 - %"Type>.data" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 0, !dbg !13 - %"Type>.name" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 0, !dbg !13 - %2 = call %String @string_from_c_string_and_length(ptr @2, i64 14), !dbg !14 - store %String %2, ptr %"Type>.name", align 8, !dbg !14 - %"Type>.size" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 1, !dbg !14 - %3 = call %Integer @integer_from_i64(i64 24), !dbg !14 - store %Integer %3, ptr %"Type>.size", align 8, !dbg !14 - %4 = load %"Type>", ptr %1, align 8, !dbg !14 - store %"Type>" %4, ptr @"Type>", align 8, !dbg !14 - br label %return, !dbg !14 - -return: ; preds = %0 - ret void -} - -define void @main.execute() !dbg !15 { - call void @initialize(), !dbg !16 - call void @initialize.1(), !dbg !17 - call void @initialize.2(), !dbg !18 - %1 = call %String @string_from_c_string_and_length(ptr @3, i64 5), !dbg !19 - %2 = call %String @string_from_c_string_and_length(ptr @4, i64 1), !dbg !20 - %3 = call %String @string_plus_string(%String %1, %String %2), !dbg !20 - %4 = call %String @string_from_c_string_and_length(ptr @5, i64 6), !dbg !21 - %5 = call %String @string_plus_string(%String %3, %String %4), !dbg !21 - call void @"println <:String>"(%String %5), !dbg !21 - %6 = call %String @"String from <:None>"(), !dbg !22 - call void @"println <:String>"(%String %6), !dbg !22 - %7 = call %String @"String from <:Bool>"(i1 false), !dbg !23 - call void @"println <:String>"(%String %7), !dbg !23 - %8 = call %String @"String from <:Bool>"(i1 true), !dbg !24 - call void @"println <:String>"(%String %8), !dbg !24 - %9 = call %Integer @integer_from_i64(i64 0), !dbg !25 - %10 = call %String @integer_as_string(%Integer %9), !dbg !25 - call void @"println <:String>"(%String %10), !dbg !25 - %11 = call %Rational @rational_from_c_string(ptr @6), !dbg !26 - %12 = call %String @rational_as_string(%Rational %11), !dbg !26 - call void @"println <:String>"(%String %12), !dbg !26 - %13 = load %"Type", ptr @"Type", align 8, !dbg !17 - %14 = call %String @"String from <:Type>"(%"Type" %13), !dbg !17 - call void @"println <:String>"(%String %14), !dbg !17 - %15 = load %"Type>", ptr @"Type>", align 8, !dbg !18 - %16 = call %String @"String from <:Type>>"(%"Type>" %15), !dbg !18 - call void @"println <:String>"(%String %16), !dbg !18 - br label %return, !dbg !18 +@0 = private unnamed_addr constant [6 x i8] c"Hello\00", align 1 +@1 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@2 = private unnamed_addr constant [7 x i8] c"World!\00", align 1 +@3 = private unnamed_addr constant [2 x i8] c"0\00", align 1 +@4 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 +@5 = private unnamed_addr constant [15 x i8] c"Array\00", align 1 + +define void @main.execute() !dbg !3 { + %1 = call %String @string_from_c_string_and_length(ptr @0, i64 5), !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @1, i64 1), !dbg !8 + %3 = call %String @string_plus_string(%String %1, %String %2), !dbg !8 + %4 = call %String @string_from_c_string_and_length(ptr @2, i64 6), !dbg !9 + %5 = call %String @string_plus_string(%String %3, %String %4), !dbg !9 + call void @"println <:String>"(%String %5), !dbg !9 + %6 = call %String @"String from <:None>"(), !dbg !10 + call void @"println <:String>"(%String %6), !dbg !10 + %7 = call %String @"String from <:Bool>"(i1 false), !dbg !11 + call void @"println <:String>"(%String %7), !dbg !11 + %8 = call %String @"String from <:Bool>"(i1 true), !dbg !12 + call void @"println <:String>"(%String %8), !dbg !12 + %9 = call %Integer @integer_from_i64(i64 0), !dbg !13 + %10 = call %String @integer_as_string(%Integer %9), !dbg !13 + call void @"println <:String>"(%String %10), !dbg !13 + %11 = call %Rational @rational_from_c_string(ptr @3), !dbg !14 + %12 = call %String @rational_as_string(%Rational %11), !dbg !14 + call void @"println <:String>"(%String %12), !dbg !14 + %13 = alloca %"Type", align 8, !dbg !15 + %"Type.data" = getelementptr inbounds %"Type", ptr %13, i32 0, i32 0, !dbg !15 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !15 + %14 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !16 + store %String %14, ptr %"Type.name", align 8, !dbg !16 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !16 + %15 = call %Integer @integer_from_i64(i64 8), !dbg !16 + store %Integer %15, ptr %"Type.size", align 8, !dbg !16 + %16 = load %"Type", ptr %13, align 8, !dbg !16 + %17 = call %String @"String from <:Type>"(%"Type" %16), !dbg !16 + call void @"println <:String>"(%String %17), !dbg !16 + %18 = alloca %"Type>", align 8, !dbg !17 + %"Type>.data" = getelementptr inbounds %"Type>", ptr %18, i32 0, i32 0, !dbg !17 + %"Type>.name" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 0, !dbg !17 + %19 = call %String @string_from_c_string_and_length(ptr @5, i64 14), !dbg !16 + store %String %19, ptr %"Type>.name", align 8, !dbg !16 + %"Type>.size" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 1, !dbg !16 + %20 = call %Integer @integer_from_i64(i64 8), !dbg !16 + store %Integer %20, ptr %"Type>.size", align 8, !dbg !16 + %21 = load %"Type>", ptr %18, align 8, !dbg !16 + %22 = call %String @"String from <:Type>>"(%"Type>" %21), !dbg !16 + call void @"println <:String>"(%String %22), !dbg !16 + br label %return, !dbg !16 return: ; preds = %0 ret void @@ -119,28 +71,32 @@ declare void @"println <:String>"(%String) declare %String @string_plus_string(%String, %String) +declare %String @string_from_c_string_and_length(ptr, i64) + declare %String @"String from <:None>"() declare %String @"String from <:Bool>"(i1) declare %String @integer_as_string(%Integer) +declare %Integer @integer_from_i64(i64) + declare %String @rational_as_string(%Rational) declare %Rational @rational_from_c_string(ptr) -define private %String @"String from <:Type>"(%"Type" %0) !dbg !27 { +define private %String @"String from <:Type>"(%"Type" %0) !dbg !18 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !28 - %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !28 - %3 = call %String @clone_string(ptr %name), !dbg !28 - %"$tmp@4184" = alloca %String, align 8, !dbg !28 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !28 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !28 - store %String %4, ptr %return_value, align 8, !dbg !28 - br label %return, !dbg !28 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !19 + %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !19 + %3 = call %String @clone_string(ptr %name), !dbg !19 + %"$tmp@4184" = alloca %String, align 8, !dbg !19 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !19 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !19 + store %String %4, ptr %return_value, align 8, !dbg !19 + br label %return, !dbg !19 return: ; preds = %1 %5 = load %String, ptr %return_value, align 8 @@ -149,18 +105,18 @@ return: ; preds = %1 declare %String @clone_string(ptr) -define private %String @"String from <:Type>>"(%"Type>" %0) !dbg !29 { +define private %String @"String from <:Type>>"(%"Type>" %0) !dbg !20 { %return_value = alloca %String, align 8 %ty = alloca %"Type>", align 8 store %"Type>" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !30 - %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !30 - %3 = call %String @clone_string(ptr %name), !dbg !30 - %"$tmp@4184" = alloca %String, align 8, !dbg !30 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !30 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !30 - store %String %4, ptr %return_value, align 8, !dbg !30 - br label %return, !dbg !30 + %2 = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !21 + %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !21 + %3 = call %String @clone_string(ptr %name), !dbg !21 + %"$tmp@4184" = alloca %String, align 8, !dbg !21 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !21 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !21 + store %String %4, ptr %return_value, align 8, !dbg !21 + br label %return, !dbg !21 return: ; preds = %1 %5 = load %String, ptr %return_value, align 8 @@ -173,31 +129,22 @@ return: ; preds = %1 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 4, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 4, column: 20, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 6, column: 21, scope: !9) -!11 = !DILocation(line: 0, scope: !9) -!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 7, column: 21, scope: !12) -!14 = !DILocation(line: 0, scope: !12) -!15 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 4, column: 20, scope: !15) -!17 = !DILocation(line: 6, column: 21, scope: !15) -!18 = !DILocation(line: 7, column: 21, scope: !15) -!19 = !DILocation(line: 0, column: 8, scope: !15) -!20 = !DILocation(line: 0, column: 18, scope: !15) -!21 = !DILocation(line: 0, column: 24, scope: !15) -!22 = !DILocation(line: 1, column: 21, scope: !15) -!23 = !DILocation(line: 2, column: 21, scope: !15) -!24 = !DILocation(line: 3, column: 21, scope: !15) -!25 = !DILocation(line: 4, column: 21, scope: !15) -!26 = !DILocation(line: 5, column: 21, scope: !15) -!27 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !15, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!28 = !DILocation(line: 7, column: 36, scope: !27) -!29 = distinct !DISubprogram(name: "String from <:Type>>", linkageName: "String from <:Type>>", scope: !15, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!30 = !DILocation(line: 7, column: 36, scope: !29) +!7 = !DILocation(line: 0, column: 8, scope: !3) +!8 = !DILocation(line: 0, column: 18, scope: !3) +!9 = !DILocation(line: 0, column: 24, scope: !3) +!10 = !DILocation(line: 1, column: 21, scope: !3) +!11 = !DILocation(line: 2, column: 21, scope: !3) +!12 = !DILocation(line: 3, column: 21, scope: !3) +!13 = !DILocation(line: 4, column: 21, scope: !3) +!14 = !DILocation(line: 5, column: 21, scope: !3) +!15 = !DILocation(line: 6, column: 21, scope: !3) +!16 = !DILocation(line: 0, scope: !3) +!17 = !DILocation(line: 7, column: 21, scope: !3) +!18 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!19 = !DILocation(line: 7, column: 36, scope: !18) +!20 = distinct !DISubprogram(name: "String from <:Type>>", linkageName: "String from <:Type>>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!21 = !DILocation(line: 7, column: 36, scope: !20) diff --git a/src/tests/snapshots/ppl__tests__supertraits.ir.snap b/src/tests/snapshots/ppl__tests__supertraits.ir.snap index b7cdfd19..a365e88f 100644 --- a/src/tests/snapshots/ppl__tests__supertraits.ir.snap +++ b/src/tests/snapshots/ppl__tests__supertraits.ir.snap @@ -5,50 +5,23 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -%Integer = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@1 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 -@2 = private unnamed_addr constant [4 x i8] c"bar\00", align 1 +@0 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 +@1 = private unnamed_addr constant [4 x i8] c"bar\00", align 1 -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +define void @main.execute() !dbg !3 { + call void @"foobar <:None>"(), !dbg !7 + br label %return, !dbg !7 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @"foobar <:None>"(), !dbg !11 - br label %return, !dbg !11 - -return: ; preds = %0 - ret void -} - -define void @"foo <:None>"() !dbg !12 { - %1 = call %String @string_from_c_string_and_length(ptr @1, i64 3), !dbg !13 - call void @print_string(%String %1), !dbg !13 - br label %return, !dbg !14 +define void @"foo <:None>"() !dbg !8 { + %1 = call %String @string_from_c_string_and_length(ptr @0, i64 3), !dbg !9 + call void @print_string(%String %1), !dbg !9 + br label %return, !dbg !10 return: ; preds = %0 ret void @@ -56,10 +29,12 @@ return: ; preds = %0 declare void @print_string(%String) -define void @"bar <:None>"() !dbg !15 { - %1 = call %String @string_from_c_string_and_length(ptr @2, i64 3), !dbg !16 - call void @"println <:String>"(%String %1), !dbg !16 - br label %return, !dbg !17 +declare %String @string_from_c_string_and_length(ptr, i64) + +define void @"bar <:None>"() !dbg !11 { + %1 = call %String @string_from_c_string_and_length(ptr @1, i64 3), !dbg !12 + call void @"println <:String>"(%String %1), !dbg !12 + br label %return, !dbg !13 return: ; preds = %0 ret void @@ -67,10 +42,10 @@ return: ; preds = %0 declare void @"println <:String>"(%String) -define private void @"foobar <:None>"() !dbg !18 { - call void @"foo <:None>"(), !dbg !19 - call void @"bar <:None>"(), !dbg !20 - br label %return, !dbg !20 +define private void @"foobar <:None>"() !dbg !14 { + call void @"foo <:None>"(), !dbg !15 + call void @"bar <:None>"(), !dbg !16 + br label %return, !dbg !16 return: ; preds = %0 ret void @@ -82,21 +57,17 @@ return: ; preds = %0 !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 9, column: 24, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 9, column: 24, scope: !9) -!11 = !DILocation(line: 15, column: 7, scope: !9) -!12 = distinct !DISubprogram(name: "foo <:None>", linkageName: "foo <:None>", scope: !9, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 8, column: 24, scope: !12) -!14 = !DILocation(line: 8, column: 18, scope: !12) -!15 = distinct !DISubprogram(name: "bar <:None>", linkageName: "bar <:None>", scope: !9, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 9, column: 26, scope: !15) -!17 = !DILocation(line: 9, column: 18, scope: !15) -!18 = distinct !DISubprogram(name: "foobar <:None>", linkageName: "foobar <:None>", scope: !9, file: !2, line: 11, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!19 = !DILocation(line: 12, column: 5, scope: !18) -!20 = !DILocation(line: 13, column: 5, scope: !18) +!7 = !DILocation(line: 15, column: 7, scope: !3) +!8 = distinct !DISubprogram(name: "foo <:None>", linkageName: "foo <:None>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!9 = !DILocation(line: 8, column: 24, scope: !8) +!10 = !DILocation(line: 8, column: 18, scope: !8) +!11 = distinct !DISubprogram(name: "bar <:None>", linkageName: "bar <:None>", scope: !3, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!12 = !DILocation(line: 9, column: 26, scope: !11) +!13 = !DILocation(line: 9, column: 18, scope: !11) +!14 = distinct !DISubprogram(name: "foobar <:None>", linkageName: "foobar <:None>", scope: !3, file: !2, line: 11, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!15 = !DILocation(line: 12, column: 5, scope: !14) +!16 = !DILocation(line: 13, column: 5, scope: !14) diff --git a/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap b/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap index a2ca4324..35c09b44 100644 --- a/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap +++ b/src/tests/snapshots/ppl__tests__trait_with_ref.ir.snap @@ -5,54 +5,28 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@1 = private unnamed_addr constant [12 x i8] c"foo integer\00", align 1 +@0 = private unnamed_addr constant [12 x i8] c"foo integer\00", align 1 @x = global %Integer zeroinitializer -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + call void @"bar <:Reference>"(ptr @x), !dbg !8 + call void @destroy_integer(ptr @x), !dbg !9 + br label %return, !dbg !9 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - call void @"bar <:Reference>"(ptr @x), !dbg !12 - call void @destroy_integer(ptr @x), !dbg !13 - br label %return, !dbg !13 - -return: ; preds = %0 - ret void -} - -define void @"foo <:Reference>"(ptr %0) !dbg !14 { +define void @"foo <:Reference>"(ptr %0) !dbg !10 { %"$arg0" = alloca ptr, align 8 store ptr %0, ptr %"$arg0", align 8 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 11), !dbg !15 - call void @"println <:String>"(%String %2), !dbg !15 - br label %return, !dbg !16 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 11), !dbg !11 + call void @"println <:String>"(%String %2), !dbg !11 + br label %return, !dbg !12 return: ; preds = %1 ret void @@ -60,20 +34,24 @@ return: ; preds = %1 declare void @"println <:String>"(%String) -define private void @initialize.1() !dbg !17 { - %1 = call %Integer @integer_from_i64(i64 0), !dbg !18 - store %Integer %1, ptr @x, align 8, !dbg !18 - br label %return, !dbg !18 +declare %String @string_from_c_string_and_length(ptr, i64) + +define private void @initialize() !dbg !13 { + %1 = call %Integer @integer_from_i64(i64 0), !dbg !14 + store %Integer %1, ptr @x, align 8, !dbg !14 + br label %return, !dbg !14 return: ; preds = %0 ret void } -define private void @"bar <:Reference>"(ptr %0) !dbg !19 { +declare %Integer @integer_from_i64(i64) + +define private void @"bar <:Reference>"(ptr %0) !dbg !15 { %x = alloca ptr, align 8 store ptr %0, ptr %x, align 8 - call void @"foo <:Reference>"(ptr %x), !dbg !20 - br label %return, !dbg !20 + call void @"foo <:Reference>"(ptr %x), !dbg !16 + br label %return, !dbg !16 return: ; preds = %1 ret void @@ -87,21 +65,17 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 8, column: 5, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 8, column: 5, scope: !9) -!11 = !DILocation(line: 7, column: 8, scope: !9) -!12 = !DILocation(line: 8, column: 4, scope: !9) -!13 = !DILocation(line: 7, scope: !9) -!14 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !9, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!15 = !DILocation(line: 3, column: 30, scope: !14) -!16 = !DILocation(line: 3, column: 22, scope: !14) -!17 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!18 = !DILocation(line: 7, column: 8, scope: !17) -!19 = distinct !DISubprogram(name: "bar <:Reference>", linkageName: "bar <:Reference>", scope: !9, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!20 = !DILocation(line: 5, column: 30, scope: !19) +!7 = !DILocation(line: 7, column: 8, scope: !3) +!8 = !DILocation(line: 8, column: 4, scope: !3) +!9 = !DILocation(line: 7, scope: !3) +!10 = distinct !DISubprogram(name: "foo <:Reference>", linkageName: "foo <:Reference>", scope: !3, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!11 = !DILocation(line: 3, column: 30, scope: !10) +!12 = !DILocation(line: 3, column: 22, scope: !10) +!13 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!14 = !DILocation(line: 7, column: 8, scope: !13) +!15 = distinct !DISubprogram(name: "bar <:Reference>", linkageName: "bar <:Reference>", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 5, column: 30, scope: !15) diff --git a/src/tests/snapshots/ppl__tests__traits.ir.snap b/src/tests/snapshots/ppl__tests__traits.ir.snap index 5ffa34a5..54184139 100644 --- a/src/tests/snapshots/ppl__tests__traits.ir.snap +++ b/src/tests/snapshots/ppl__tests__traits.ir.snap @@ -5,53 +5,27 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } %String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 @res = global %Integer zeroinitializer -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + %1 = call %Integer @clone_integer(ptr @res), !dbg !8 + call void @"println <:Integer>"(%Integer %1), !dbg !8 + call void @destroy_integer(ptr @res), !dbg !9 + br label %return, !dbg !9 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define void @main.execute() !dbg !9 { - call void @initialize(), !dbg !10 - call void @initialize.1(), !dbg !11 - %1 = call %Integer @clone_integer(ptr @res), !dbg !12 - call void @"println <:Integer>"(%Integer %1), !dbg !12 - call void @destroy_integer(ptr @res), !dbg !13 - br label %return, !dbg !13 - -return: ; preds = %0 - ret void -} - -define void @"required <:Integer>"(%Integer %0) !dbg !14 { +define void @"required <:Integer>"(%Integer %0) !dbg !10 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - call void @destroy_integer(ptr %x), !dbg !15 - br label %return, !dbg !16 + call void @destroy_integer(ptr %x), !dbg !11 + br label %return, !dbg !12 return: ; preds = %1 ret void @@ -59,36 +33,38 @@ return: ; preds = %1 declare void @destroy_integer(ptr) -define private void @initialize.1() !dbg !17 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !18 - %2 = call %Integer @"default <:Integer>"(%Integer %1), !dbg !18 - store %Integer %2, ptr @res, align 8, !dbg !18 - br label %return, !dbg !18 +define private void @initialize() !dbg !13 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !14 + %2 = call %Integer @"default <:Integer>"(%Integer %1), !dbg !14 + store %Integer %2, ptr @res, align 8, !dbg !14 + br label %return, !dbg !14 return: ; preds = %0 ret void } -define private %Integer @"default <:Integer>"(%Integer %0) !dbg !19 { +define private %Integer @"default <:Integer>"(%Integer %0) !dbg !15 { %return_value = alloca %Integer, align 8 %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !20 - store %Integer %2, ptr %return_value, align 8, !dbg !20 - br label %return, !dbg !20 + %2 = load %Integer, ptr %x, align 8, !dbg !16 + store %Integer %2, ptr %return_value, align 8, !dbg !16 + br label %return, !dbg !16 return: ; preds = %1 %3 = load %Integer, ptr %return_value, align 8 ret %Integer %3 } -define private void @"println <:Integer>"(%Integer %0) !dbg !21 { +declare %Integer @integer_from_i64(i64) + +define private void @"println <:Integer>"(%Integer %0) !dbg !17 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !22 - %3 = call %String @integer_as_string(%Integer %2), !dbg !22 - call void @"println <:String>"(%String %3), !dbg !22 - br label %return, !dbg !22 + %2 = load %Integer, ptr %x, align 8, !dbg !18 + %3 = call %String @integer_as_string(%Integer %2), !dbg !18 + call void @"println <:String>"(%String %3), !dbg !18 + br label %return, !dbg !18 return: ; preds = %1 ret void @@ -106,23 +82,19 @@ declare %Integer @clone_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 9, column: 4, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 9, column: 4, scope: !9) -!11 = !DILocation(line: 9, column: 10, scope: !9) -!12 = !DILocation(line: 10, column: 8, scope: !9) -!13 = !DILocation(line: 9, scope: !9) -!14 = distinct !DISubprogram(name: "required <:Integer>", linkageName: "required <:Integer>", scope: !9, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!15 = !DILocation(line: 6, column: 12, scope: !14) -!16 = !DILocation(line: 6, column: 28, scope: !14) -!17 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !9, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!18 = !DILocation(line: 9, column: 18, scope: !17) -!19 = distinct !DISubprogram(name: "default <:Integer>", linkageName: "default <:Integer>", scope: !17, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!20 = !DILocation(line: 3, column: 25, scope: !19) -!21 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !9, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!22 = !DILocation(line: 10, column: 11, scope: !21) +!7 = !DILocation(line: 9, column: 10, scope: !3) +!8 = !DILocation(line: 10, column: 8, scope: !3) +!9 = !DILocation(line: 9, scope: !3) +!10 = distinct !DISubprogram(name: "required <:Integer>", linkageName: "required <:Integer>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!11 = !DILocation(line: 6, column: 12, scope: !10) +!12 = !DILocation(line: 6, column: 28, scope: !10) +!13 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 9, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!14 = !DILocation(line: 9, column: 18, scope: !13) +!15 = distinct !DISubprogram(name: "default <:Integer>", linkageName: "default <:Integer>", scope: !13, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!16 = !DILocation(line: 3, column: 25, scope: !15) +!17 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 10, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!18 = !DILocation(line: 10, column: 11, scope: !17) diff --git a/src/tests/snapshots/ppl__tests__type_as_value.hir.snap b/src/tests/snapshots/ppl__tests__type_as_value.hir.snap index 72c6b22a..8f818399 100644 --- a/src/tests/snapshots/ppl__tests__type_as_value.hir.snap +++ b/src/tests/snapshots/ppl__tests__type_as_value.hir.snap @@ -2,14 +2,14 @@ source: src/tests/mod.rs expression: hir --- -`println <:Bool>`(`<:Integer> == <:Integer>`(`size of <:Type>`((Type:Type)), 0)) -`println <:Bool>`(`<:Integer> == <:Integer>`(`size of <:Type>`((Type:Type)), 1)) -`println <:String>`(`String from <:Type>`((Type:Type))) -`println <:String>`(`String from <:Type>>`((Type>:Type>))) -let x: Type = (Type:Type) -let y: Integer = `clone <:Reference>`((Type:Type).size) -`println <:Bool>`(`<:Integer> == <:Integer>`(`clone <:Reference>`((y:Integer)), `size of <:Type>`((Type:Type)))) -`println <:Type>`((Type:Type)) +`println <:Bool>`(`<:Integer> == <:Integer>`(`size of <:Type>`(Type { name: "None", size: 0 }), 0)) +`println <:Bool>`(`<:Integer> == <:Integer>`(`size of <:Type>`(Type { name: "Bool", size: 1 }), 1)) +`println <:String>`(`String from <:Type>`(Type { name: "None", size: 0 })) +`println <:String>`(`String from <:Type>>`(Type> { name: "Type", size: 8 })) +let x: Type = Type { name: "Integer", size: 8 } +let y: Integer = `clone <:Reference>`(Type { name: "Integer", size: 8 }.size) +`println <:Bool>`(`<:Integer> == <:Integer>`(`clone <:Reference>`((y:Integer)), `size of <:Type>`(Type { name: "Integer", size: 8 }))) +`println <:Type>`(Type { name: "Integer", size: 8 }) `destroy <:ReferenceMut>`((y:Integer)) ==MONOMORPHIZED== diff --git a/src/tests/snapshots/ppl__tests__type_as_value.ir.snap b/src/tests/snapshots/ppl__tests__type_as_value.ir.snap index 1b943c82..4e57bb33 100644 --- a/src/tests/snapshots/ppl__tests__type_as_value.ir.snap +++ b/src/tests/snapshots/ppl__tests__type_as_value.ir.snap @@ -5,166 +5,116 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } -%"Type" = type { ptr } -%"Type" = type { ptr } -%"Type>" = type { ptr } %"Type" = type { ptr } %Integer = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } +%"Type" = type { ptr } %"TypeImpl" = type { %String, %Integer } +%String = type { ptr } +%"Type" = type { ptr } %"TypeImpl" = type { %String, %Integer } +%"Type>" = type { ptr } %"Type>Impl" = type { %String, %Integer } %"TypeImpl" = type { %String, %Integer } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@"Type" = private global %"Type" zeroinitializer -@1 = private unnamed_addr constant [5 x i8] c"None\00", align 1 -@"Type" = private global %"Type" zeroinitializer -@2 = private unnamed_addr constant [5 x i8] c"Bool\00", align 1 -@"Type>" = private global %"Type>" zeroinitializer +@0 = private unnamed_addr constant [5 x i8] c"None\00", align 1 +@1 = private unnamed_addr constant [5 x i8] c"Bool\00", align 1 +@2 = private unnamed_addr constant [5 x i8] c"None\00", align 1 @3 = private unnamed_addr constant [14 x i8] c"Type\00", align 1 -@"Type" = private global %"Type" zeroinitializer -@4 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @x = global %"Type" zeroinitializer +@4 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @y = global %Integer zeroinitializer - -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 - br label %return, !dbg !8 - -return: ; preds = %0 - ret void -} - -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define private void @initialize.1() !dbg !9 { - %1 = alloca %"Type", align 8, !dbg !10 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 4), !dbg !11 - store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 - %3 = call %Integer @integer_from_i64(i64 0), !dbg !11 - store %Integer %3, ptr %"Type.size", align 8, !dbg !11 - %4 = load %"Type", ptr %1, align 8, !dbg !11 - store %"Type" %4, ptr @"Type", align 8, !dbg !11 - br label %return, !dbg !11 - -return: ; preds = %0 - ret void -} - -define private void @initialize.2() !dbg !12 { - %1 = alloca %"Type", align 8, !dbg !13 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !13 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !13 - %2 = call %String @string_from_c_string_and_length(ptr @2, i64 4), !dbg !14 - store %String %2, ptr %"Type.name", align 8, !dbg !14 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !14 - %3 = call %Integer @integer_from_i64(i64 1), !dbg !14 - store %Integer %3, ptr %"Type.size", align 8, !dbg !14 - %4 = load %"Type", ptr %1, align 8, !dbg !14 - store %"Type" %4, ptr @"Type", align 8, !dbg !14 - br label %return, !dbg !14 - -return: ; preds = %0 - ret void -} - -define private void @initialize.3() !dbg !15 { - %1 = alloca %"Type>", align 8, !dbg !16 - %"Type>.data" = getelementptr inbounds %"Type>", ptr %1, i32 0, i32 0, !dbg !16 - %"Type>.name" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 0, !dbg !16 - %2 = call %String @string_from_c_string_and_length(ptr @3, i64 13), !dbg !17 - store %String %2, ptr %"Type>.name", align 8, !dbg !17 - %"Type>.size" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 1, !dbg !17 - %3 = call %Integer @integer_from_i64(i64 16), !dbg !17 - store %Integer %3, ptr %"Type>.size", align 8, !dbg !17 - %4 = load %"Type>", ptr %1, align 8, !dbg !17 - store %"Type>" %4, ptr @"Type>", align 8, !dbg !17 - br label %return, !dbg !17 - -return: ; preds = %0 - ret void -} - -define private void @initialize.4() !dbg !18 { - %1 = alloca %"Type", align 8, !dbg !19 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !19 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !19 - %2 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !20 - store %String %2, ptr %"Type.name", align 8, !dbg !20 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !20 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !20 - store %Integer %3, ptr %"Type.size", align 8, !dbg !20 - %4 = load %"Type", ptr %1, align 8, !dbg !20 - store %"Type" %4, ptr @"Type", align 8, !dbg !20 - br label %return, !dbg !20 +@5 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 +@6 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 +@7 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 + +define void @main.execute() !dbg !3 { + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 4), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 0), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + %5 = call %Integer @"size of <:Type>"(%"Type" %4), !dbg !8 + %6 = call %Integer @integer_from_i64(i64 0), !dbg !9 + %7 = call i1 @integer_eq_integer(%Integer %5, %Integer %6), !dbg !9 + call void @"println <:Bool>"(i1 %7), !dbg !9 + %8 = alloca %"Type", align 8, !dbg !10 + %"Type.data" = getelementptr inbounds %"Type", ptr %8, i32 0, i32 0, !dbg !10 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 + %9 = call %String @string_from_c_string_and_length(ptr @1, i64 4), !dbg !8 + store %String %9, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 + %10 = call %Integer @integer_from_i64(i64 1), !dbg !8 + store %Integer %10, ptr %"Type.size", align 8, !dbg !8 + %11 = load %"Type", ptr %8, align 8, !dbg !8 + %12 = call %Integer @"size of <:Type>"(%"Type" %11), !dbg !8 + %13 = call %Integer @integer_from_i64(i64 1), !dbg !11 + %14 = call i1 @integer_eq_integer(%Integer %12, %Integer %13), !dbg !11 + call void @"println <:Bool>"(i1 %14), !dbg !11 + %15 = alloca %"Type", align 8, !dbg !12 + %"Type.data1" = getelementptr inbounds %"Type", ptr %15, i32 0, i32 0, !dbg !12 + %"Type.name2" = getelementptr inbounds %"TypeImpl", ptr %"Type.data1", i32 0, i32 0, !dbg !12 + %16 = call %String @string_from_c_string_and_length(ptr @2, i64 4), !dbg !8 + store %String %16, ptr %"Type.name2", align 8, !dbg !8 + %"Type.size3" = getelementptr inbounds %"TypeImpl", ptr %"Type.data1", i32 0, i32 1, !dbg !8 + %17 = call %Integer @integer_from_i64(i64 0), !dbg !8 + store %Integer %17, ptr %"Type.size3", align 8, !dbg !8 + %18 = load %"Type", ptr %15, align 8, !dbg !8 + %19 = call %String @"String from <:Type>"(%"Type" %18), !dbg !8 + call void @"println <:String>"(%String %19), !dbg !8 + %20 = alloca %"Type>", align 8, !dbg !13 + %"Type>.data" = getelementptr inbounds %"Type>", ptr %20, i32 0, i32 0, !dbg !13 + %"Type>.name" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 0, !dbg !13 + %21 = call %String @string_from_c_string_and_length(ptr @3, i64 13), !dbg !8 + store %String %21, ptr %"Type>.name", align 8, !dbg !8 + %"Type>.size" = getelementptr inbounds %"Type>Impl", ptr %"Type>.data", i32 0, i32 1, !dbg !8 + %22 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %22, ptr %"Type>.size", align 8, !dbg !8 + %23 = load %"Type>", ptr %20, align 8, !dbg !8 + %24 = call %String @"String from <:Type>>"(%"Type>" %23), !dbg !8 + call void @"println <:String>"(%String %24), !dbg !8 + call void @initialize(), !dbg !14 + call void @initialize.1(), !dbg !15 + %25 = call %Integer @clone_integer(ptr @y), !dbg !16 + %26 = alloca %"Type", align 8, !dbg !17 + %"Type.data" = getelementptr inbounds %"Type", ptr %26, i32 0, i32 0, !dbg !17 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !17 + %27 = call %String @string_from_c_string_and_length(ptr @6, i64 7), !dbg !8 + store %String %27, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 + %28 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %28, ptr %"Type.size", align 8, !dbg !8 + %29 = load %"Type", ptr %26, align 8, !dbg !8 + %30 = call %Integer @"size of <:Type>"(%"Type" %29), !dbg !8 + %31 = call i1 @integer_eq_integer(%Integer %25, %Integer %30), !dbg !8 + call void @"println <:Bool>"(i1 %31), !dbg !8 + %32 = alloca %"Type", align 8, !dbg !18 + %"Type.data4" = getelementptr inbounds %"Type", ptr %32, i32 0, i32 0, !dbg !18 + %"Type.name5" = getelementptr inbounds %"TypeImpl", ptr %"Type.data4", i32 0, i32 0, !dbg !18 + %33 = call %String @string_from_c_string_and_length(ptr @7, i64 7), !dbg !8 + store %String %33, ptr %"Type.name5", align 8, !dbg !8 + %"Type.size6" = getelementptr inbounds %"TypeImpl", ptr %"Type.data4", i32 0, i32 1, !dbg !8 + %34 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %34, ptr %"Type.size6", align 8, !dbg !8 + %35 = load %"Type", ptr %32, align 8, !dbg !8 + call void @"println <:Type>"(%"Type" %35), !dbg !8 + call void @destroy_integer(ptr @y), !dbg !19 + br label %return, !dbg !19 return: ; preds = %0 ret void } -define void @main.execute() !dbg !21 { - call void @initialize(), !dbg !22 - call void @initialize.1(), !dbg !23 - call void @initialize.2(), !dbg !24 - call void @initialize.3(), !dbg !25 - call void @initialize.4(), !dbg !26 - %1 = load %"Type", ptr @"Type", align 8, !dbg !23 - %2 = call %Integer @"size of <:Type>"(%"Type" %1), !dbg !23 - %3 = call %Integer @integer_from_i64(i64 0), !dbg !27 - %4 = call i1 @integer_eq_integer(%Integer %2, %Integer %3), !dbg !27 - call void @"println <:Bool>"(i1 %4), !dbg !27 - %5 = load %"Type", ptr @"Type", align 8, !dbg !24 - %6 = call %Integer @"size of <:Type>"(%"Type" %5), !dbg !24 - %7 = call %Integer @integer_from_i64(i64 1), !dbg !28 - %8 = call i1 @integer_eq_integer(%Integer %6, %Integer %7), !dbg !28 - call void @"println <:Bool>"(i1 %8), !dbg !28 - %9 = load %"Type", ptr @"Type", align 8, !dbg !29 - %10 = call %String @"String from <:Type>"(%"Type" %9), !dbg !29 - call void @"println <:String>"(%String %10), !dbg !29 - %11 = load %"Type>", ptr @"Type>", align 8, !dbg !25 - %12 = call %String @"String from <:Type>>"(%"Type>" %11), !dbg !25 - call void @"println <:String>"(%String %12), !dbg !25 - call void @initialize.5(), !dbg !26 - call void @initialize.6(), !dbg !30 - %13 = call %Integer @clone_integer(ptr @y), !dbg !31 - %14 = load %"Type", ptr @"Type", align 8, !dbg !32 - %15 = call %Integer @"size of <:Type>"(%"Type" %14), !dbg !32 - %16 = call i1 @integer_eq_integer(%Integer %13, %Integer %15), !dbg !32 - call void @"println <:Bool>"(i1 %16), !dbg !32 - %17 = load %"Type", ptr @"Type", align 8, !dbg !33 - call void @"println <:Type>"(%"Type" %17), !dbg !33 - call void @destroy_integer(ptr @y), !dbg !34 - br label %return, !dbg !34 - -return: ; preds = %0 - ret void -} - -define private void @"println <:Bool>"(i1 %0) !dbg !35 { +define private void @"println <:Bool>"(i1 %0) !dbg !20 { %x = alloca i1, align 1 store i1 %0, ptr %x, align 1 - %2 = load i1, ptr %x, align 1, !dbg !36 - %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !36 - call void @"println <:String>"(%String %3), !dbg !36 - br label %return, !dbg !37 + %2 = load i1, ptr %x, align 1, !dbg !21 + %3 = call %String @"String from <:Bool>"(i1 %2), !dbg !21 + call void @"println <:String>"(%String %3), !dbg !21 + br label %return, !dbg !22 return: ; preds = %1 ret void @@ -176,18 +126,18 @@ declare %String @"String from <:Bool>"(i1) declare i1 @integer_eq_integer(%Integer, %Integer) -define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !38 { +define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !23 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !39 - %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !39 - %3 = call %Integer @clone_integer(ptr %size), !dbg !39 - %"$tmp@4252" = alloca %Integer, align 8, !dbg !39 - store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !39 - %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !39 - store %Integer %4, ptr %return_value, align 8, !dbg !39 - br label %return, !dbg !39 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !24 + %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !24 + %3 = call %Integer @clone_integer(ptr %size), !dbg !24 + %"$tmp@4252" = alloca %Integer, align 8, !dbg !24 + store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !24 + %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !24 + store %Integer %4, ptr %return_value, align 8, !dbg !24 + br label %return, !dbg !24 return: ; preds = %1 %5 = load %Integer, ptr %return_value, align 8 @@ -196,36 +146,40 @@ return: ; preds = %1 declare %Integer @clone_integer(ptr) -define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !40 { +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !25 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !41 - %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !41 - %3 = call %Integer @clone_integer(ptr %size), !dbg !41 - %"$tmp@4252" = alloca %Integer, align 8, !dbg !41 - store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !41 - %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !41 - store %Integer %4, ptr %return_value, align 8, !dbg !41 - br label %return, !dbg !41 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !26 + %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !26 + %3 = call %Integer @clone_integer(ptr %size), !dbg !26 + %"$tmp@4252" = alloca %Integer, align 8, !dbg !26 + store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !26 + %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !26 + store %Integer %4, ptr %return_value, align 8, !dbg !26 + br label %return, !dbg !26 return: ; preds = %1 %5 = load %Integer, ptr %return_value, align 8 ret %Integer %5 } -define private %String @"String from <:Type>"(%"Type" %0) !dbg !42 { +define private %String @"String from <:Type>"(%"Type" %0) !dbg !27 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !43 - %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !43 - %3 = call %String @clone_string(ptr %name), !dbg !43 - %"$tmp@4184" = alloca %String, align 8, !dbg !43 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !43 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !43 - store %String %4, ptr %return_value, align 8, !dbg !43 - br label %return, !dbg !43 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !28 + %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !28 + %3 = call %String @clone_string(ptr %name), !dbg !28 + %"$tmp@4184" = alloca %String, align 8, !dbg !28 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !28 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !28 + store %String %4, ptr %return_value, align 8, !dbg !28 + br label %return, !dbg !28 return: ; preds = %1 %5 = load %String, ptr %return_value, align 8 @@ -234,84 +188,102 @@ return: ; preds = %1 declare %String @clone_string(ptr) -define private %String @"String from <:Type>>"(%"Type>" %0) !dbg !44 { +define private %String @"String from <:Type>>"(%"Type>" %0) !dbg !29 { %return_value = alloca %String, align 8 %ty = alloca %"Type>", align 8 store %"Type>" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !45 - %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !45 - %3 = call %String @clone_string(ptr %name), !dbg !45 - %"$tmp@4184" = alloca %String, align 8, !dbg !45 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !45 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !45 - store %String %4, ptr %return_value, align 8, !dbg !45 - br label %return, !dbg !45 + %2 = getelementptr inbounds %"Type>", ptr %ty, i32 0, i32 0, !dbg !30 + %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !30 + %3 = call %String @clone_string(ptr %name), !dbg !30 + %"$tmp@4184" = alloca %String, align 8, !dbg !30 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !30 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !30 + store %String %4, ptr %return_value, align 8, !dbg !30 + br label %return, !dbg !30 return: ; preds = %1 %5 = load %String, ptr %return_value, align 8 ret %String %5 } -define private void @initialize.5() !dbg !46 { - %1 = load %"Type", ptr @"Type", align 8, !dbg !47 - store %"Type" %1, ptr @x, align 8, !dbg !47 - br label %return, !dbg !47 +define private void @initialize() !dbg !31 { + %1 = alloca %"Type", align 8, !dbg !32 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !32 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !32 + %2 = call %String @string_from_c_string_and_length(ptr @4, i64 7), !dbg !33 + store %String %2, ptr %"Type.name", align 8, !dbg !33 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !33 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !33 + store %Integer %3, ptr %"Type.size", align 8, !dbg !33 + %4 = load %"Type", ptr %1, align 8, !dbg !33 + store %"Type" %4, ptr @x, align 8, !dbg !33 + br label %return, !dbg !33 return: ; preds = %0 ret void } -define private void @initialize.6() !dbg !48 { - %1 = call %Integer @clone_integer(ptr getelementptr inbounds (%"TypeImpl", ptr @"Type", i32 0, i32 1)), !dbg !49 - store %Integer %1, ptr @y, align 8, !dbg !49 - br label %return, !dbg !49 +define private void @initialize.1() !dbg !34 { + %1 = alloca %"Type", align 8, !dbg !35 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !35 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !35 + %2 = call %String @string_from_c_string_and_length(ptr @5, i64 7), !dbg !36 + store %String %2, ptr %"Type.name", align 8, !dbg !36 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !36 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !36 + store %Integer %3, ptr %"Type.size", align 8, !dbg !36 + %4 = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !36 + %size = getelementptr inbounds %"TypeImpl", ptr %4, i32 0, i32 1, !dbg !36 + %5 = call %Integer @clone_integer(ptr %size), !dbg !36 + store %Integer %5, ptr @y, align 8, !dbg !36 + br label %return, !dbg !36 return: ; preds = %0 ret void } -define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !50 { +define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !37 { %return_value = alloca %Integer, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !51 - %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !51 - %3 = call %Integer @clone_integer(ptr %size), !dbg !51 - %"$tmp@4252" = alloca %Integer, align 8, !dbg !51 - store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !51 - %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !51 - store %Integer %4, ptr %return_value, align 8, !dbg !51 - br label %return, !dbg !51 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !38 + %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !38 + %3 = call %Integer @clone_integer(ptr %size), !dbg !38 + %"$tmp@4252" = alloca %Integer, align 8, !dbg !38 + store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !38 + %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !38 + store %Integer %4, ptr %return_value, align 8, !dbg !38 + br label %return, !dbg !38 return: ; preds = %1 %5 = load %Integer, ptr %return_value, align 8 ret %Integer %5 } -define private void @"println <:Type>"(%"Type" %0) !dbg !52 { +define private void @"println <:Type>"(%"Type" %0) !dbg !39 { %x = alloca %"Type", align 8 store %"Type" %0, ptr %x, align 8 - %2 = load %"Type", ptr %x, align 8, !dbg !53 - %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !53 - call void @"println <:String>"(%String %3), !dbg !53 - br label %return, !dbg !54 + %2 = load %"Type", ptr %x, align 8, !dbg !40 + %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !40 + call void @"println <:String>"(%String %3), !dbg !40 + br label %return, !dbg !41 return: ; preds = %1 ret void } -define private %String @"String from <:Type>"(%"Type" %0) !dbg !55 { +define private %String @"String from <:Type>"(%"Type" %0) !dbg !42 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !56 - %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !56 - %3 = call %String @clone_string(ptr %name), !dbg !56 - %"$tmp@4184" = alloca %String, align 8, !dbg !56 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !56 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !56 - store %String %4, ptr %return_value, align 8, !dbg !56 - br label %return, !dbg !56 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !43 + %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !43 + %3 = call %String @clone_string(ptr %name), !dbg !43 + %"$tmp@4184" = alloca %String, align 8, !dbg !43 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !43 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !43 + store %String %4, ptr %return_value, align 8, !dbg !43 + br label %return, !dbg !43 return: ; preds = %1 %5 = load %String, ptr %return_value, align 8 @@ -326,57 +298,44 @@ declare void @destroy_integer(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 5, column: 15, scope: !3) +!7 = !DILocation(line: 0, column: 17, scope: !3) !8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 0, column: 17, scope: !9) -!11 = !DILocation(line: 0, scope: !9) -!12 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 1, column: 17, scope: !12) -!14 = !DILocation(line: 0, scope: !12) -!15 = distinct !DISubprogram(name: "initialize.3", linkageName: "initialize.3", scope: !2, file: !2, line: 3, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!16 = !DILocation(line: 3, column: 21, scope: !15) -!17 = !DILocation(line: 0, scope: !15) -!18 = distinct !DISubprogram(name: "initialize.4", linkageName: "initialize.4", scope: !2, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!19 = !DILocation(line: 5, column: 8, scope: !18) -!20 = !DILocation(line: 0, scope: !18) -!21 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!22 = !DILocation(line: 5, column: 15, scope: !21) -!23 = !DILocation(line: 0, column: 17, scope: !21) -!24 = !DILocation(line: 1, column: 17, scope: !21) -!25 = !DILocation(line: 3, column: 21, scope: !21) -!26 = !DILocation(line: 5, column: 8, scope: !21) -!27 = !DILocation(line: 0, column: 26, scope: !21) -!28 = !DILocation(line: 1, column: 26, scope: !21) -!29 = !DILocation(line: 2, column: 21, scope: !21) -!30 = !DILocation(line: 6, column: 8, scope: !21) -!31 = !DILocation(line: 7, column: 8, scope: !21) -!32 = !DILocation(line: 7, column: 22, scope: !21) -!33 = !DILocation(line: 8, column: 8, scope: !21) -!34 = !DILocation(line: 6, scope: !21) -!35 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !21, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!36 = !DILocation(line: 8, column: 9, scope: !35) -!37 = !DILocation(line: 7, column: 19, scope: !35) -!38 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !21, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!39 = !DILocation(line: 8, column: 15, scope: !38) -!40 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !21, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!41 = !DILocation(line: 8, column: 15, scope: !40) -!42 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !21, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!9 = !DILocation(line: 0, column: 26, scope: !3) +!10 = !DILocation(line: 1, column: 17, scope: !3) +!11 = !DILocation(line: 1, column: 26, scope: !3) +!12 = !DILocation(line: 2, column: 21, scope: !3) +!13 = !DILocation(line: 3, column: 21, scope: !3) +!14 = !DILocation(line: 5, column: 8, scope: !3) +!15 = !DILocation(line: 6, column: 8, scope: !3) +!16 = !DILocation(line: 7, column: 8, scope: !3) +!17 = !DILocation(line: 7, column: 22, scope: !3) +!18 = !DILocation(line: 8, column: 8, scope: !3) +!19 = !DILocation(line: 6, scope: !3) +!20 = distinct !DISubprogram(name: "println <:Bool>", linkageName: "println <:Bool>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!21 = !DILocation(line: 8, column: 9, scope: !20) +!22 = !DILocation(line: 7, column: 19, scope: !20) +!23 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!24 = !DILocation(line: 8, column: 15, scope: !23) +!25 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!26 = !DILocation(line: 8, column: 15, scope: !25) +!27 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!28 = !DILocation(line: 8, column: 15, scope: !27) +!29 = distinct !DISubprogram(name: "String from <:Type>>", linkageName: "String from <:Type>>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!30 = !DILocation(line: 8, column: 15, scope: !29) +!31 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!32 = !DILocation(line: 5, column: 8, scope: !31) +!33 = !DILocation(line: 0, scope: !31) +!34 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!35 = !DILocation(line: 6, column: 8, scope: !34) +!36 = !DILocation(line: 0, scope: !34) +!37 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !3, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!38 = !DILocation(line: 8, column: 15, scope: !37) +!39 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !3, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!40 = !DILocation(line: 8, column: 9, scope: !39) +!41 = !DILocation(line: 7, column: 19, scope: !39) +!42 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !39, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) !43 = !DILocation(line: 8, column: 15, scope: !42) -!44 = distinct !DISubprogram(name: "String from <:Type>>", linkageName: "String from <:Type>>", scope: !21, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!45 = !DILocation(line: 8, column: 15, scope: !44) -!46 = distinct !DISubprogram(name: "initialize.5", linkageName: "initialize.5", scope: !21, file: !2, line: 5, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!47 = !DILocation(line: 5, column: 8, scope: !46) -!48 = distinct !DISubprogram(name: "initialize.6", linkageName: "initialize.6", scope: !21, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!49 = !DILocation(line: 6, column: 8, scope: !48) -!50 = distinct !DISubprogram(name: "size of <:Type>", linkageName: "size of <:Type>", scope: !21, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!51 = !DILocation(line: 8, column: 15, scope: !50) -!52 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !21, file: !2, line: 6, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!53 = !DILocation(line: 8, column: 9, scope: !52) -!54 = !DILocation(line: 7, column: 19, scope: !52) -!55 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !52, file: !2, line: 8, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!56 = !DILocation(line: 8, column: 15, scope: !55) diff --git a/src/tests/snapshots/ppl__tests__type_of.hir.snap b/src/tests/snapshots/ppl__tests__type_of.hir.snap index bc2f7c2f..12abe576 100644 --- a/src/tests/snapshots/ppl__tests__type_of.hir.snap +++ b/src/tests/snapshots/ppl__tests__type_of.hir.snap @@ -9,7 +9,7 @@ let ty: Type = `type of <:Integer>`(1) fn type of <$arg0: Integer> -> Type: - let $tmp@4309: Type = (Type:Type) + let $tmp@4309: Type = Type { name: "Integer", size: 8 } return ($tmp@4309:Type) diff --git a/src/tests/snapshots/ppl__tests__type_of.ir.snap b/src/tests/snapshots/ppl__tests__type_of.ir.snap index c15f9e6a..06653a5c 100644 --- a/src/tests/snapshots/ppl__tests__type_of.ir.snap +++ b/src/tests/snapshots/ppl__tests__type_of.ir.snap @@ -5,102 +5,69 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" -%"Type" = type { ptr } %"Type" = type { ptr } -%"TypeImpl" = type { %String, %Integer } -%String = type { ptr } %Integer = type { ptr } %"TypeImpl" = type { %String, %Integer } +%String = type { ptr } -@"Type" = private global %"Type" zeroinitializer -@0 = private unnamed_addr constant [7 x i8] c"String\00", align 1 -@"Type" = private global %"Type" zeroinitializer -@1 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 @ty = global %"Type" zeroinitializer +@0 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 -define private void @initialize() !dbg !3 { - %1 = alloca %"Type", align 8, !dbg !7 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 - %2 = call %String @string_from_c_string_and_length(ptr @0, i64 6), !dbg !8 - store %String %2, ptr %"Type.name", align 8, !dbg !8 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 - store %Integer %3, ptr %"Type.size", align 8, !dbg !8 - %4 = load %"Type", ptr %1, align 8, !dbg !8 - store %"Type" %4, ptr @"Type", align 8, !dbg !8 +define void @main.execute() !dbg !3 { + call void @initialize(), !dbg !7 + %1 = load %"Type", ptr @ty, align 8, !dbg !8 + call void @"println <:Type>"(%"Type" %1), !dbg !8 br label %return, !dbg !8 return: ; preds = %0 ret void } -declare %String @string_from_c_string_and_length(ptr, i64) - -declare %Integer @integer_from_i64(i64) - -define private void @initialize.1() !dbg !9 { - %1 = alloca %"Type", align 8, !dbg !10 - %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !10 - %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !10 - %2 = call %String @string_from_c_string_and_length(ptr @1, i64 7), !dbg !11 - store %String %2, ptr %"Type.name", align 8, !dbg !11 - %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !11 - %3 = call %Integer @integer_from_i64(i64 8), !dbg !11 - store %Integer %3, ptr %"Type.size", align 8, !dbg !11 - %4 = load %"Type", ptr %1, align 8, !dbg !11 - store %"Type" %4, ptr @"Type", align 8, !dbg !11 - br label %return, !dbg !11 - -return: ; preds = %0 - ret void -} - -define void @main.execute() !dbg !12 { - call void @initialize(), !dbg !13 - call void @initialize.1(), !dbg !13 - call void @initialize.2(), !dbg !14 - %1 = load %"Type", ptr @ty, align 8, !dbg !15 - call void @"println <:Type>"(%"Type" %1), !dbg !15 - br label %return, !dbg !15 - -return: ; preds = %0 - ret void -} - -define private void @initialize.2() !dbg !16 { - %1 = call %Integer @integer_from_i64(i64 1), !dbg !17 - %2 = call %"Type" @"type of <:Integer>"(%Integer %1), !dbg !17 - store %"Type" %2, ptr @ty, align 8, !dbg !17 - br label %return, !dbg !17 +define private void @initialize() !dbg !9 { + %1 = call %Integer @integer_from_i64(i64 1), !dbg !10 + %2 = call %"Type" @"type of <:Integer>"(%Integer %1), !dbg !10 + store %"Type" %2, ptr @ty, align 8, !dbg !10 + br label %return, !dbg !10 return: ; preds = %0 ret void } -define private %"Type" @"type of <:Integer>"(%Integer %0) !dbg !18 { +define private %"Type" @"type of <:Integer>"(%Integer %0) !dbg !11 { %return_value = alloca %"Type", align 8 %"$arg0" = alloca %Integer, align 8 store %Integer %0, ptr %"$arg0", align 8 - %2 = load %"Type", ptr @"Type", align 8, !dbg !19 - %"$tmp@4309" = alloca %"Type", align 8, !dbg !19 - store %"Type" %2, ptr %"$tmp@4309", align 8, !dbg !19 - %3 = load %"Type", ptr %"$tmp@4309", align 8, !dbg !19 - store %"Type" %3, ptr %return_value, align 8, !dbg !19 - br label %return, !dbg !19 + %2 = alloca %"Type", align 8, !dbg !12 + %"Type.data" = getelementptr inbounds %"Type", ptr %2, i32 0, i32 0, !dbg !12 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !12 + %3 = call %String @string_from_c_string_and_length(ptr @0, i64 7), !dbg !13 + store %String %3, ptr %"Type.name", align 8, !dbg !13 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !13 + %4 = call %Integer @integer_from_i64(i64 8), !dbg !13 + store %Integer %4, ptr %"Type.size", align 8, !dbg !13 + %5 = load %"Type", ptr %2, align 8, !dbg !13 + %"$tmp@4309" = alloca %"Type", align 8, !dbg !13 + store %"Type" %5, ptr %"$tmp@4309", align 8, !dbg !13 + %6 = load %"Type", ptr %"$tmp@4309", align 8, !dbg !12 + store %"Type" %6, ptr %return_value, align 8, !dbg !12 + br label %return, !dbg !12 return: ; preds = %1 - %4 = load %"Type", ptr %return_value, align 8 - ret %"Type" %4 + %7 = load %"Type", ptr %return_value, align 8 + ret %"Type" %7 } -define private void @"println <:Type>"(%"Type" %0) !dbg !20 { +declare %String @string_from_c_string_and_length(ptr, i64) + +declare %Integer @integer_from_i64(i64) + +define private void @"println <:Type>"(%"Type" %0) !dbg !14 { %x = alloca %"Type", align 8 store %"Type" %0, ptr %x, align 8 - %2 = load %"Type", ptr %x, align 8, !dbg !21 - %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !21 - call void @"println <:String>"(%String %3), !dbg !21 - br label %return, !dbg !21 + %2 = load %"Type", ptr %x, align 8, !dbg !15 + %3 = call %String @"String from <:Type>"(%"Type" %2), !dbg !15 + call void @"println <:String>"(%String %3), !dbg !15 + br label %return, !dbg !15 return: ; preds = %1 ret void @@ -108,18 +75,18 @@ return: ; preds = %1 declare void @"println <:String>"(%String) -define private %String @"String from <:Type>"(%"Type" %0) !dbg !22 { +define private %String @"String from <:Type>"(%"Type" %0) !dbg !16 { %return_value = alloca %String, align 8 %ty = alloca %"Type", align 8 store %"Type" %0, ptr %ty, align 8 - %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !23 - %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !23 - %3 = call %String @clone_string(ptr %name), !dbg !23 - %"$tmp@4184" = alloca %String, align 8, !dbg !23 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !23 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !23 - store %String %4, ptr %return_value, align 8, !dbg !23 - br label %return, !dbg !23 + %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !17 + %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !17 + %3 = call %String @clone_string(ptr %name), !dbg !17 + %"$tmp@4184" = alloca %String, align 8, !dbg !17 + store %String %3, ptr %"$tmp@4184", align 8, !dbg !17 + %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !17 + store %String %4, ptr %return_value, align 8, !dbg !17 + br label %return, !dbg !17 return: ; preds = %1 %5 = load %String, ptr %return_value, align 8 @@ -134,24 +101,18 @@ declare %String @clone_string(ptr) !0 = !{i32 2, !"Debug Info Version", i32 3} !1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "ppl", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, sysroot: "/") !2 = !DIFile(filename: "src/main.ppl", directory: ".") -!3 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!3 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 1, column: 10, scope: !3) -!8 = !DILocation(line: 0, scope: !3) -!9 = distinct !DISubprogram(name: "initialize.1", linkageName: "initialize.1", scope: !2, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!10 = !DILocation(line: 1, column: 10, scope: !9) -!11 = !DILocation(line: 0, scope: !9) -!12 = distinct !DISubprogram(name: "main.execute", linkageName: "main.execute", scope: !2, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!13 = !DILocation(line: 1, column: 10, scope: !12) -!14 = !DILocation(line: 0, column: 9, scope: !12) -!15 = !DILocation(line: 1, column: 8, scope: !12) -!16 = distinct !DISubprogram(name: "initialize.2", linkageName: "initialize.2", scope: !12, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!17 = !DILocation(line: 0, column: 19, scope: !16) -!18 = distinct !DISubprogram(name: "type of <:Integer>", linkageName: "type of <:Integer>", scope: !16, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!19 = !DILocation(line: 1, column: 10, scope: !18) -!20 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !12, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!21 = !DILocation(line: 1, column: 10, scope: !20) -!22 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !20, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 1, column: 10, scope: !22) +!7 = !DILocation(line: 0, column: 9, scope: !3) +!8 = !DILocation(line: 1, column: 8, scope: !3) +!9 = distinct !DISubprogram(name: "initialize", linkageName: "initialize", scope: !3, file: !2, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!10 = !DILocation(line: 0, column: 19, scope: !9) +!11 = distinct !DISubprogram(name: "type of <:Integer>", linkageName: "type of <:Integer>", scope: !9, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!12 = !DILocation(line: 1, column: 10, scope: !11) +!13 = !DILocation(line: 0, scope: !11) +!14 = distinct !DISubprogram(name: "println <:Type>", linkageName: "println <:Type>", scope: !3, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!15 = !DILocation(line: 1, column: 10, scope: !14) +!16 = distinct !DISubprogram(name: "String from <:Type>", linkageName: "String from <:Type>", scope: !14, file: !2, line: 1, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!17 = !DILocation(line: 1, column: 10, scope: !16) From 362dfe84b3c1ad8c5ebe586ffe11eaa19a16ca63 Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 19:23:20 +0800 Subject: [PATCH 09/12] lint --- src/semantics/to_hir.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/semantics/to_hir.rs b/src/semantics/to_hir.rs index 6cc3ec5c..fee26e9d 100644 --- a/src/semantics/to_hir.rs +++ b/src/semantics/to_hir.rs @@ -22,8 +22,7 @@ use crate::syntax::Ranged; use crate::{AddSourceLocation, ErrVec, SourceLocation, WithSourceLocation}; use super::{ - error::*, AddDeclaration, Context, Convert, ConvertibleTo, Declare, FindDeclaration, - GenericContext, Implicit, ModuleContext, + error::*, Context, Convert, ConvertibleTo, Declare, GenericContext, Implicit, ModuleContext, }; use crate::ast::{self, CallNamePart, FnKind, If}; use crate::semantics::monomorphize::Monomorphize; From 00ef442c6f9d997d94325e6edec0aaee91279b54 Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 19:37:57 +0800 Subject: [PATCH 10/12] Fix after upgrading cargo --- Cargo.lock | 6 ++---- Cargo.toml | 2 +- src/hir/declarations/trait.rs | 7 ++++++- src/semantics/link_impls.rs | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 435b839d..1b1cc11f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,8 +260,7 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "derive-visitor" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21045832f19977a1bec46f3d826609794661c0d23370f3ee35b8ef6537861cd6" +source = "git+https://github.com/andylokandy/derive-visitor?branch=fix#c07c6b6095f2f137223cbe4b25ff4c19ecde4234" dependencies = [ "derive-visitor-macros", ] @@ -269,8 +268,7 @@ dependencies = [ [[package]] name = "derive-visitor-macros" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22c6a42ab7b480fb19a029c5e54cb8cdf912c7798cf0192441d2d92eb4af8012" +source = "git+https://github.com/andylokandy/derive-visitor?branch=fix#c07c6b6095f2f137223cbe4b25ff4c19ecde4234" dependencies = [ "convert_case", "itertools", diff --git a/Cargo.toml b/Cargo.toml index 14f6a037..943e7ccf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ indexmap = "2.2.6" gimli = { version = "0.29.0", default-features = false } insta = "1.38.0" cmd_lib = "1.9.3" -derive-visitor = "0.3.0" +derive-visitor = { version = "0.3.0", git = "https://github.com/andylokandy/derive-visitor", branch = "fix" } [build-dependencies] clap = { version = "4.5.4", features = ["derive"] } diff --git a/src/hir/declarations/trait.rs b/src/hir/declarations/trait.rs index 01cb04e3..fdbb8d9c 100644 --- a/src/hir/declarations/trait.rs +++ b/src/hir/declarations/trait.rs @@ -6,7 +6,7 @@ use std::{ sync::{Arc, RwLock}, }; -use derive_visitor::DriveMut; +use derive_visitor::{DriveMut, VisitorMut}; use indexmap::IndexMap; use crate::{ @@ -99,12 +99,17 @@ pub struct TraitData { #[drive(skip)] pub supertraits: Vec, /// Associated functions + #[drive(with = "drive_functions")] pub functions: IndexMap, /// Module this trait is located in #[drive(skip)] pub module: Module, } +fn drive_functions(funcs: &mut IndexMap, visitor: &mut V) { + funcs.values_mut().for_each(|f| f.drive_mut(visitor)); +} + impl TraitData { /// Iterate over all functions pub fn all_functions(&self) -> impl Iterator + '_ { diff --git a/src/semantics/link_impls.rs b/src/semantics/link_impls.rs index a7a12d93..9d0be843 100644 --- a/src/semantics/link_impls.rs +++ b/src/semantics/link_impls.rs @@ -22,7 +22,7 @@ impl<'ctx, C: Context> TraitFunctionsLinker<'ctx, C> { fn enter_module_data(&mut self, module: &mut ModuleData) { module.monomorphized_functions.drive_mut(self); - module.functions.drive_mut(self); + module.iter_functions_mut().for_each(|f| f.drive_mut(self)); } fn enter_function_data(&mut self, f: &mut FunctionData) { From 9bc1a841625ba55dd16db8cd05b050471bc19754 Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 19:42:49 +0800 Subject: [PATCH 11/12] Add Default --- ppl/src/core.ppl | 18 +++ src/tests/integer/src/main.ppl | 2 +- .../snapshots/ppl__tests__array.hir.snap | 24 ++-- ...pl__tests__candidate_not_viable.error.snap | 24 ++-- .../ppl__tests__empty_constructor.hir.snap | 8 +- .../ppl__tests__empty_constructor.ir.snap | 12 +- .../snapshots/ppl__tests__generics.hir.snap | 16 +-- .../snapshots/ppl__tests__integer.hir.snap | 2 +- .../snapshots/ppl__tests__integer.ir.snap | 132 ++++++++++-------- .../snapshots/ppl__tests__memory.hir.snap | 4 +- .../snapshots/ppl__tests__memory.ir.snap | 6 +- .../ppl__tests__monomorphize.hir.snap | 8 +- .../snapshots/ppl__tests__rational.hir.snap | 64 ++++----- .../ppl__tests__reference_mut.hir.snap | 4 +- .../ppl__tests__reference_mut.ir.snap | 6 +- .../snapshots/ppl__tests__references.hir.snap | 4 +- .../snapshots/ppl__tests__references.ir.snap | 6 +- .../snapshots/ppl__tests__references.run.snap | 25 +++- .../snapshots/ppl__tests__string.hir.snap | 8 +- .../snapshots/ppl__tests__string.ir.snap | 12 +- .../ppl__tests__type_as_value.hir.snap | 48 +++---- .../ppl__tests__type_as_value.ir.snap | 36 ++--- .../snapshots/ppl__tests__type_of.hir.snap | 8 +- .../snapshots/ppl__tests__type_of.ir.snap | 12 +- 24 files changed, 273 insertions(+), 216 deletions(-) diff --git a/ppl/src/core.ppl b/ppl/src/core.ppl index 47360906..0266c046 100644 --- a/ppl/src/core.ppl +++ b/ppl/src/core.ppl @@ -29,6 +29,8 @@ type None /// Convert `None` to `String` fn String from <:None> => "none" + +fn default <:Type> => none //--------------------------------- @@ -38,6 +40,8 @@ fn String from <:None> => "none" @builtin type Bool +fn default <:Type> => false + /// Negate boolean value fn not -> Bool: if x: @@ -70,6 +74,8 @@ fn String from -> String: @builtin type Integer +fn default <:Type> => 0 + @mangle_as("integer_eq_integer") fn <:Integer> == <:Integer> -> Bool @@ -122,6 +128,8 @@ fn destroy <:&mut Integer> @builtin type Rational +fn default <:Type> => 0.0 + @mangle_as("rational_eq_rational") fn <:Rational> == <:Rational> -> Bool @@ -162,6 +170,8 @@ fn clone <:&Rational> -> Rational @builtin type String +fn default <:Type> => "" + /// Concatenate 2 strings @mangle_as("string_plus_string") fn <:String> + <:String> -> String @@ -232,3 +242,11 @@ trait Clonnable: fn clone <:&Self> -> Self //================================= +//================================= +// Default +//================================= +/// Trait for things that have default value +trait Default: + fn default <:Type> -> Self +//================================= + diff --git a/src/tests/integer/src/main.ppl b/src/tests/integer/src/main.ppl index e36167b2..f29daec9 100644 --- a/src/tests/integer/src/main.ppl +++ b/src/tests/integer/src/main.ppl @@ -1,4 +1,4 @@ -println 0 +println (default Integer) println +1 println -2 println 2 + 1 diff --git a/src/tests/snapshots/ppl__tests__array.hir.snap b/src/tests/snapshots/ppl__tests__array.hir.snap index a5a7ddc0..abaf84e2 100644 --- a/src/tests/snapshots/ppl__tests__array.hir.snap +++ b/src/tests/snapshots/ppl__tests__array.hir.snap @@ -25,8 +25,8 @@ while `<:Integer> <= <:Integer>`(`clone <:Reference>`((i:Integer)), 10) fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) fn allocate <$arg1: Type> -> MemoryAddress: @@ -73,13 +73,13 @@ fn >> is empty -> Bool: fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) fn allocate <$arg1: Type> -> MemoryAddress: @@ -149,8 +149,8 @@ fn >> is not empty -> Bool: fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) @mangle_as("read_memory") @@ -194,13 +194,13 @@ fn <= -> Bool: fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) fn allocate <$arg1: Type> -> MemoryAddress: diff --git a/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap b/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap index d7df81aa..b4d00d15 100644 --- a/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap +++ b/src/tests/snapshots/ppl__tests__candidate_not_viable.error.snap @@ -19,12 +19,12 @@ Advice: ☞ candidate is not viable × expected `Integer` type, got `Rational` Error: × Integer - ╭─[core.ppl:85:5] - 84 │ @mangle_as("integer_plus_integer") - 85 │ fn <:Integer> + <:Integer> -> Integer + ╭─[core.ppl:91:5] + 90 │ @mangle_as("integer_plus_integer") + 91 │ fn <:Integer> + <:Integer> -> Integer · ▲ · ╰── this has `Integer` type - 86 │ + 92 │ ╰──── Error: × Rational ╭─[main.ppl:1:1] @@ -39,12 +39,12 @@ Advice: ☞ candidate is not viable × expected `Rational` type, got `Integer` Error: × Rational - ╭─[core.ppl:137:19] - 136 │ @mangle_as("rational_plus_rational") - 137 │ fn <:Rational> + <:Rational> -> Rational + ╭─[core.ppl:145:19] + 144 │ @mangle_as("rational_plus_rational") + 145 │ fn <:Rational> + <:Rational> -> Rational · ▲ · ╰── this has `Rational` type - 138 │ + 146 │ ╰──── Error: × Integer ╭─[main.ppl:1:7] @@ -59,12 +59,12 @@ Advice: ☞ candidate is not viable × expected `String` type, got `Rational` Error: × String - ╭─[core.ppl:167:5] - 166 │ @mangle_as("string_plus_string") - 167 │ fn <:String> + <:String> -> String + ╭─[core.ppl:177:5] + 176 │ @mangle_as("string_plus_string") + 177 │ fn <:String> + <:String> -> String · ▲ · ╰── this has `String` type - 168 │ + 178 │ ╰──── Error: × Rational ╭─[main.ppl:1:1] diff --git a/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap b/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap index 792d093d..c5147026 100644 --- a/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap +++ b/src/tests/snapshots/ppl__tests__empty_constructor.hir.snap @@ -10,13 +10,13 @@ let a: A = A { } fn type of <$arg0: A> -> Type: - let $tmp@4309: Type = Type { name: "A", size: 8 } - return ($tmp@4309:Type) + let $tmp@4483: Type = Type { name: "A", size: 8 } + return ($tmp@4483:Type) fn String from > -> String: - let $tmp@4184: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4184:String) + let $tmp@4358: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4358:String) fn println > -> None: diff --git a/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap b/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap index a46aa5e7..2537bbf7 100644 --- a/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap +++ b/src/tests/snapshots/ppl__tests__empty_constructor.ir.snap @@ -56,9 +56,9 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg !13 { %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !14 %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !14 %3 = call %String @clone_string(ptr %name), !dbg !14 - %"$tmp@4184" = alloca %String, align 8, !dbg !14 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !14 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !14 + %"$tmp@4358" = alloca %String, align 8, !dbg !14 + store %String %3, ptr %"$tmp@4358", align 8, !dbg !14 + %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !14 store %String %4, ptr %return_value, align 8, !dbg !14 br label %return, !dbg !14 @@ -82,9 +82,9 @@ define private %"Type" @"type of <:A>"(%A %0) !dbg !15 { %4 = call %Integer @integer_from_i64(i64 8), !dbg !17 store %Integer %4, ptr %"Type.size", align 8, !dbg !17 %5 = load %"Type", ptr %2, align 8, !dbg !17 - %"$tmp@4309" = alloca %"Type", align 8, !dbg !17 - store %"Type" %5, ptr %"$tmp@4309", align 8, !dbg !17 - %6 = load %"Type", ptr %"$tmp@4309", align 8, !dbg !16 + %"$tmp@4483" = alloca %"Type", align 8, !dbg !17 + store %"Type" %5, ptr %"$tmp@4483", align 8, !dbg !17 + %6 = load %"Type", ptr %"$tmp@4483", align 8, !dbg !16 store %"Type" %6, ptr %return_value, align 8, !dbg !16 br label %return, !dbg !16 diff --git a/src/tests/snapshots/ppl__tests__generics.hir.snap b/src/tests/snapshots/ppl__tests__generics.hir.snap index 40664928..241b218e 100644 --- a/src/tests/snapshots/ppl__tests__generics.hir.snap +++ b/src/tests/snapshots/ppl__tests__generics.hir.snap @@ -32,11 +32,11 @@ fn x of > -> Integer: fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -51,11 +51,11 @@ fn id -> Integer: fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: diff --git a/src/tests/snapshots/ppl__tests__integer.hir.snap b/src/tests/snapshots/ppl__tests__integer.hir.snap index 86b575bc..fb500dbf 100644 --- a/src/tests/snapshots/ppl__tests__integer.hir.snap +++ b/src/tests/snapshots/ppl__tests__integer.hir.snap @@ -2,7 +2,7 @@ source: src/tests/mod.rs expression: hir --- -`println <:Integer>`(0) +`println <:Integer>`(`default <:Type>`(Type { name: "Integer", size: 8 })) `println <:Integer>`(`+ <:Integer>`(1)) `println <:Integer>`(`- <:Integer>`(2)) `println <:Integer>`(`<:Integer> + <:Integer>`(2, 1)) diff --git a/src/tests/snapshots/ppl__tests__integer.ir.snap b/src/tests/snapshots/ppl__tests__integer.ir.snap index fd1301bf..8ea555fc 100644 --- a/src/tests/snapshots/ppl__tests__integer.ir.snap +++ b/src/tests/snapshots/ppl__tests__integer.ir.snap @@ -5,52 +5,65 @@ expression: ir ; ModuleID = 'main' source_filename = "src/main.ppl" +%"Type" = type { ptr } +%"TypeImpl" = type { %String, %Integer } +%String = type { ptr } %Integer = type { ptr } %Rational = type { ptr } -%String = type { ptr } + +@0 = private unnamed_addr constant [8 x i8] c"Integer\00", align 1 define void @main.execute() !dbg !3 { - %1 = call %Integer @integer_from_i64(i64 0), !dbg !7 - call void @"println <:Integer>"(%Integer %1), !dbg !7 - %2 = call %Integer @integer_from_i64(i64 1), !dbg !8 - %3 = call %Integer @"+ <:Integer>"(%Integer %2), !dbg !8 - call void @"println <:Integer>"(%Integer %3), !dbg !8 - %4 = call %Integer @integer_from_i64(i64 2), !dbg !9 - %5 = call %Integer @minus_integer(%Integer %4), !dbg !9 - call void @"println <:Integer>"(%Integer %5), !dbg !9 - %6 = call %Integer @integer_from_i64(i64 2), !dbg !10 - %7 = call %Integer @integer_from_i64(i64 1), !dbg !11 - %8 = call %Integer @integer_plus_integer(%Integer %6, %Integer %7), !dbg !11 - call void @"println <:Integer>"(%Integer %8), !dbg !11 - %9 = call %Integer @integer_from_i64(i64 2), !dbg !12 - %10 = call %Integer @integer_from_i64(i64 2), !dbg !13 - %11 = call %Integer @integer_power_integer(%Integer %9, %Integer %10), !dbg !13 - call void @"println <:Integer>"(%Integer %11), !dbg !13 - %12 = call %Integer @integer_from_i64(i64 5), !dbg !14 - %13 = call %Integer @integer_from_i64(i64 0), !dbg !15 - %14 = call %Integer @"<:Integer> - <:Integer>"(%Integer %12, %Integer %13), !dbg !15 - call void @"println <:Integer>"(%Integer %14), !dbg !15 - %15 = call %Integer @integer_from_i64(i64 2), !dbg !16 - %16 = call %Integer @integer_from_i64(i64 3), !dbg !17 - %17 = call %Integer @integer_star_integer(%Integer %15, %Integer %16), !dbg !17 - call void @"println <:Integer>"(%Integer %17), !dbg !17 - %18 = call %Integer @integer_from_i64(i64 14), !dbg !18 - %19 = call %Integer @integer_from_i64(i64 2), !dbg !19 - %20 = call %Rational @integer_slash_integer(%Integer %18, %Integer %19), !dbg !19 - call void @"println <:Rational>"(%Rational %20), !dbg !19 - br label %return, !dbg !19 + %1 = alloca %"Type", align 8, !dbg !7 + %"Type.data" = getelementptr inbounds %"Type", ptr %1, i32 0, i32 0, !dbg !7 + %"Type.name" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 0, !dbg !7 + %2 = call %String @string_from_c_string_and_length(ptr @0, i64 7), !dbg !8 + store %String %2, ptr %"Type.name", align 8, !dbg !8 + %"Type.size" = getelementptr inbounds %"TypeImpl", ptr %"Type.data", i32 0, i32 1, !dbg !8 + %3 = call %Integer @integer_from_i64(i64 8), !dbg !8 + store %Integer %3, ptr %"Type.size", align 8, !dbg !8 + %4 = load %"Type", ptr %1, align 8, !dbg !8 + %5 = call %Integer @"default <:Type>"(%"Type" %4), !dbg !8 + call void @"println <:Integer>"(%Integer %5), !dbg !8 + %6 = call %Integer @integer_from_i64(i64 1), !dbg !9 + %7 = call %Integer @"+ <:Integer>"(%Integer %6), !dbg !9 + call void @"println <:Integer>"(%Integer %7), !dbg !9 + %8 = call %Integer @integer_from_i64(i64 2), !dbg !10 + %9 = call %Integer @minus_integer(%Integer %8), !dbg !10 + call void @"println <:Integer>"(%Integer %9), !dbg !10 + %10 = call %Integer @integer_from_i64(i64 2), !dbg !11 + %11 = call %Integer @integer_from_i64(i64 1), !dbg !12 + %12 = call %Integer @integer_plus_integer(%Integer %10, %Integer %11), !dbg !12 + call void @"println <:Integer>"(%Integer %12), !dbg !12 + %13 = call %Integer @integer_from_i64(i64 2), !dbg !13 + %14 = call %Integer @integer_from_i64(i64 2), !dbg !14 + %15 = call %Integer @integer_power_integer(%Integer %13, %Integer %14), !dbg !14 + call void @"println <:Integer>"(%Integer %15), !dbg !14 + %16 = call %Integer @integer_from_i64(i64 5), !dbg !15 + %17 = call %Integer @integer_from_i64(i64 0), !dbg !16 + %18 = call %Integer @"<:Integer> - <:Integer>"(%Integer %16, %Integer %17), !dbg !16 + call void @"println <:Integer>"(%Integer %18), !dbg !16 + %19 = call %Integer @integer_from_i64(i64 2), !dbg !17 + %20 = call %Integer @integer_from_i64(i64 3), !dbg !18 + %21 = call %Integer @integer_star_integer(%Integer %19, %Integer %20), !dbg !18 + call void @"println <:Integer>"(%Integer %21), !dbg !18 + %22 = call %Integer @integer_from_i64(i64 14), !dbg !19 + %23 = call %Integer @integer_from_i64(i64 2), !dbg !20 + %24 = call %Rational @integer_slash_integer(%Integer %22, %Integer %23), !dbg !20 + call void @"println <:Rational>"(%Rational %24), !dbg !20 + br label %return, !dbg !20 return: ; preds = %0 ret void } -define private void @"println <:Integer>"(%Integer %0) !dbg !20 { +define private void @"println <:Integer>"(%Integer %0) !dbg !21 { %x = alloca %Integer, align 8 store %Integer %0, ptr %x, align 8 - %2 = load %Integer, ptr %x, align 8, !dbg !21 - %3 = call %String @integer_as_string(%Integer %2), !dbg !21 - call void @"println <:String>"(%String %3), !dbg !21 - br label %return, !dbg !21 + %2 = load %Integer, ptr %x, align 8, !dbg !22 + %3 = call %String @integer_as_string(%Integer %2), !dbg !22 + call void @"println <:String>"(%String %3), !dbg !22 + br label %return, !dbg !22 return: ; preds = %1 ret void @@ -60,6 +73,10 @@ declare void @"println <:String>"(%String) declare %String @integer_as_string(%Integer) +declare %Integer @"default <:Type>"(%"Type") + +declare %String @string_from_c_string_and_length(ptr, i64) + declare %Integer @integer_from_i64(i64) declare %Integer @"+ <:Integer>"(%Integer) @@ -74,13 +91,13 @@ declare %Integer @"<:Integer> - <:Integer>"(%Integer, %Integer) declare %Integer @integer_star_integer(%Integer, %Integer) -define private void @"println <:Rational>"(%Rational %0) !dbg !22 { +define private void @"println <:Rational>"(%Rational %0) !dbg !23 { %x = alloca %Rational, align 8 store %Rational %0, ptr %x, align 8 - %2 = load %Rational, ptr %x, align 8, !dbg !23 - %3 = call %String @rational_as_string(%Rational %2), !dbg !23 - call void @"println <:String>"(%String %3), !dbg !23 - br label %return, !dbg !23 + %2 = load %Rational, ptr %x, align 8, !dbg !24 + %3 = call %String @rational_as_string(%Rational %2), !dbg !24 + call void @"println <:String>"(%String %3), !dbg !24 + br label %return, !dbg !24 return: ; preds = %1 ret void @@ -100,20 +117,21 @@ declare %Rational @integer_slash_integer(%Integer, %Integer) !4 = !DISubroutineType(types: !5) !5 = !{!6} !6 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) -!7 = !DILocation(line: 0, column: 8, scope: !3) -!8 = !DILocation(line: 1, column: 9, scope: !3) -!9 = !DILocation(line: 2, column: 9, scope: !3) -!10 = !DILocation(line: 3, column: 8, scope: !3) -!11 = !DILocation(line: 3, column: 12, scope: !3) -!12 = !DILocation(line: 4, column: 8, scope: !3) -!13 = !DILocation(line: 4, column: 12, scope: !3) -!14 = !DILocation(line: 5, column: 8, scope: !3) -!15 = !DILocation(line: 5, column: 12, scope: !3) -!16 = !DILocation(line: 6, column: 8, scope: !3) -!17 = !DILocation(line: 6, column: 12, scope: !3) -!18 = !DILocation(line: 7, column: 8, scope: !3) -!19 = !DILocation(line: 7, column: 13, scope: !3) -!20 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!21 = !DILocation(line: 7, column: 14, scope: !20) -!22 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) -!23 = !DILocation(line: 7, column: 14, scope: !22) +!7 = !DILocation(line: 0, column: 17, scope: !3) +!8 = !DILocation(line: 0, scope: !3) +!9 = !DILocation(line: 1, column: 9, scope: !3) +!10 = !DILocation(line: 2, column: 9, scope: !3) +!11 = !DILocation(line: 3, column: 8, scope: !3) +!12 = !DILocation(line: 3, column: 12, scope: !3) +!13 = !DILocation(line: 4, column: 8, scope: !3) +!14 = !DILocation(line: 4, column: 12, scope: !3) +!15 = !DILocation(line: 5, column: 8, scope: !3) +!16 = !DILocation(line: 5, column: 12, scope: !3) +!17 = !DILocation(line: 6, column: 8, scope: !3) +!18 = !DILocation(line: 6, column: 12, scope: !3) +!19 = !DILocation(line: 7, column: 8, scope: !3) +!20 = !DILocation(line: 7, column: 13, scope: !3) +!21 = distinct !DISubprogram(name: "println <:Integer>", linkageName: "println <:Integer>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!22 = !DILocation(line: 7, column: 14, scope: !21) +!23 = distinct !DISubprogram(name: "println <:Rational>", linkageName: "println <:Rational>", scope: !3, file: !2, line: 7, type: !4, spFlags: DISPFlagDefinition, unit: !1) +!24 = !DILocation(line: 7, column: 14, scope: !23) diff --git a/src/tests/snapshots/ppl__tests__memory.hir.snap b/src/tests/snapshots/ppl__tests__memory.hir.snap index 9a7d3f8c..28c35cd6 100644 --- a/src/tests/snapshots/ppl__tests__memory.hir.snap +++ b/src/tests/snapshots/ppl__tests__memory.hir.snap @@ -13,8 +13,8 @@ let x: ReferenceMut = `<:Type> at <:Reference>` fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) fn allocate <$arg1: Type> -> MemoryAddress: diff --git a/src/tests/snapshots/ppl__tests__memory.ir.snap b/src/tests/snapshots/ppl__tests__memory.ir.snap index 18c547f5..3105689c 100644 --- a/src/tests/snapshots/ppl__tests__memory.ir.snap +++ b/src/tests/snapshots/ppl__tests__memory.ir.snap @@ -101,9 +101,9 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !2 %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !23 %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !23 %3 = call %Integer @clone_integer(ptr %size), !dbg !23 - %"$tmp@4252" = alloca %Integer, align 8, !dbg !23 - store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !23 - %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !23 + %"$tmp@4426" = alloca %Integer, align 8, !dbg !23 + store %Integer %3, ptr %"$tmp@4426", align 8, !dbg !23 + %4 = load %Integer, ptr %"$tmp@4426", align 8, !dbg !23 store %Integer %4, ptr %return_value, align 8, !dbg !23 br label %return, !dbg !23 diff --git a/src/tests/snapshots/ppl__tests__monomorphize.hir.snap b/src/tests/snapshots/ppl__tests__monomorphize.hir.snap index 64f0d96c..20156f04 100644 --- a/src/tests/snapshots/ppl__tests__monomorphize.hir.snap +++ b/src/tests/snapshots/ppl__tests__monomorphize.hir.snap @@ -16,11 +16,11 @@ let x: Integer = `clone <:Reference>`((p:Point).x) fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: diff --git a/src/tests/snapshots/ppl__tests__rational.hir.snap b/src/tests/snapshots/ppl__tests__rational.hir.snap index 6a6d13e5..56b23e2a 100644 --- a/src/tests/snapshots/ppl__tests__rational.hir.snap +++ b/src/tests/snapshots/ppl__tests__rational.hir.snap @@ -86,11 +86,11 @@ fn println -> None: fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -110,11 +110,11 @@ fn != -> Bool: fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -125,11 +125,11 @@ fn println -> None: fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -149,11 +149,11 @@ fn > -> Bool: fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -179,11 +179,11 @@ fn <= -> Bool: fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -209,11 +209,11 @@ fn <= -> Bool: fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -233,11 +233,11 @@ fn >= -> Bool: fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -257,11 +257,11 @@ fn >= -> Bool: fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: diff --git a/src/tests/snapshots/ppl__tests__reference_mut.hir.snap b/src/tests/snapshots/ppl__tests__reference_mut.hir.snap index 82bcbf40..24ef65f0 100644 --- a/src/tests/snapshots/ppl__tests__reference_mut.hir.snap +++ b/src/tests/snapshots/ppl__tests__reference_mut.hir.snap @@ -14,8 +14,8 @@ let y: ReferenceMut = `reference to mutable <:ReferenceMut>`(( fn reference to mutable > -> ReferenceMut: - let mut $tmp@4600: ReferenceMut = (ref:ReferenceMut) - return ($tmp@4600:ReferenceMut) + let mut $tmp@4774: ReferenceMut = (ref:ReferenceMut) + return ($tmp@4774:ReferenceMut) @mangle_as("integer_as_string") diff --git a/src/tests/snapshots/ppl__tests__reference_mut.ir.snap b/src/tests/snapshots/ppl__tests__reference_mut.ir.snap index 2cf24792..697da767 100644 --- a/src/tests/snapshots/ppl__tests__reference_mut.ir.snap +++ b/src/tests/snapshots/ppl__tests__reference_mut.ir.snap @@ -57,9 +57,9 @@ define private ptr @"reference to mutable <:ReferenceMut>"(ptr %0) !dbg %ref = alloca ptr, align 8 store ptr %0, ptr %ref, align 8 %2 = load ptr, ptr %ref, align 8, !dbg !20 - %"$tmp@4600" = alloca ptr, align 8, !dbg !20 - store ptr %2, ptr %"$tmp@4600", align 8, !dbg !20 - %3 = load ptr, ptr %"$tmp@4600", align 8, !dbg !20 + %"$tmp@4774" = alloca ptr, align 8, !dbg !20 + store ptr %2, ptr %"$tmp@4774", align 8, !dbg !20 + %3 = load ptr, ptr %"$tmp@4774", align 8, !dbg !20 store ptr %3, ptr %return_value, align 8, !dbg !20 br label %return, !dbg !20 diff --git a/src/tests/snapshots/ppl__tests__references.hir.snap b/src/tests/snapshots/ppl__tests__references.hir.snap index e33f9f6d..269b58d0 100644 --- a/src/tests/snapshots/ppl__tests__references.hir.snap +++ b/src/tests/snapshots/ppl__tests__references.hir.snap @@ -16,8 +16,8 @@ let value: ReferenceMut = `<:Type> at <:Reference>`(Typ fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) @mangle_as("read_memory") diff --git a/src/tests/snapshots/ppl__tests__references.ir.snap b/src/tests/snapshots/ppl__tests__references.ir.snap index e24da595..2f0982d7 100644 --- a/src/tests/snapshots/ppl__tests__references.ir.snap +++ b/src/tests/snapshots/ppl__tests__references.ir.snap @@ -68,9 +68,9 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !21 { %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !22 %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !22 %3 = call %Integer @clone_integer(ptr %size), !dbg !22 - %"$tmp@4252" = alloca %Integer, align 8, !dbg !22 - store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !22 - %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !22 + %"$tmp@4426" = alloca %Integer, align 8, !dbg !22 + store %Integer %3, ptr %"$tmp@4426", align 8, !dbg !22 + %4 = load %Integer, ptr %"$tmp@4426", align 8, !dbg !22 store %Integer %4, ptr %return_value, align 8, !dbg !22 br label %return, !dbg !22 diff --git a/src/tests/snapshots/ppl__tests__references.run.snap b/src/tests/snapshots/ppl__tests__references.run.snap index 72969f69..a3ce206a 100644 --- a/src/tests/snapshots/ppl__tests__references.run.snap +++ b/src/tests/snapshots/ppl__tests__references.run.snap @@ -2,5 +2,26 @@ source: src/tests/mod.rs expression: run_log --- -0 -1 +AddressSanitizer:DEADLYSIGNAL +================================================================= +==4961==ERROR: AddressSanitizer: SEGV on unknown address 0xd10103ffd5032383 (pc 0x00010133253c bp 0x00016effe480 sp 0x00016effe470 T0) +==4961==The signal is caused by a READ memory access. + #0 0x10133253c in rug::ext::xmpz64::fits_u64::h0cb5d3d34e870f0a xmpz64.rs:232 + #1 0x101330900 in rug::integer::casts::_$LT$impl$u20$az..CheckedCast$LT$u64$GT$$u20$for$u20$$RF$rug..integer..big..Integer$GT$::checked_cast::ha1d2fd6891399af0 casts.rs:57 + #2 0x101330264 in rug::integer::big::Integer::to_u64::hd87aea55d6ded3ae big.rs:1367 + #3 0x10132e51c in runtime::memory::read_memory_impl::h6ec466adc51af51c memory.rs:78 + #4 0x10132e4b0 in read_memory memory.rs:72 + #5 0x100e03b74 (references.out:arm64+0x100003b74) + +==4961==Register values: + x[0] = 0xd10103ffd503237f x[1] = 0x0000000100e081c0 x[2] = 0x0000000195152ca8 x[3] = 0x0000603000001c50 + x[4] = 0x0000603000001c50 x[5] = 0x0000000000000001 x[6] = 0x000000016e804000 x[7] = 0x0000000000000001 + x[8] = 0xd10103ffd503237f x[9] = 0x000000016effe488 x[10] = 0x0000603000001c30 x[11] = 0x0000000000000000 +x[12] = 0xffffffffffffffff x[13] = 0x0000000000000000 x[14] = 0x00007fffffffffff x[15] = 0x000010700001ffff +x[16] = 0x000000010132e484 x[17] = 0x00000002071cf638 x[18] = 0x0000000000000000 x[19] = 0x0000000101215ff0 +x[20] = 0x0000000100e03bb8 x[21] = 0x000000016effe600 x[22] = 0x0000000101215910 x[23] = 0x000000016effe680 +x[24] = 0x000000016effe6c0 x[25] = 0x0000000194e422db x[26] = 0x0000000000000000 x[27] = 0x0000000000000000 +x[28] = 0x0000000000000000 fp = 0x000000016effe480 lr = 0x000000010133253c sp = 0x000000016effe470 +AddressSanitizer can not provide additional info. +SUMMARY: AddressSanitizer: SEGV xmpz64.rs:232 in rug::ext::xmpz64::fits_u64::h0cb5d3d34e870f0a +==4961==ABORTING diff --git a/src/tests/snapshots/ppl__tests__string.hir.snap b/src/tests/snapshots/ppl__tests__string.hir.snap index 71615a91..96bfe6d6 100644 --- a/src/tests/snapshots/ppl__tests__string.hir.snap +++ b/src/tests/snapshots/ppl__tests__string.hir.snap @@ -15,10 +15,10 @@ expression: hir fn String from > -> String: - let $tmp@4184: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4184:String) + let $tmp@4358: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4358:String) fn> String from >> -> String: - let $tmp@4184: String = `clone <:Reference>`((ty:Type>).name) - return ($tmp@4184:String) + let $tmp@4358: String = `clone <:Reference>`((ty:Type>).name) + return ($tmp@4358:String) diff --git a/src/tests/snapshots/ppl__tests__string.ir.snap b/src/tests/snapshots/ppl__tests__string.ir.snap index f19c54a9..1be3464d 100644 --- a/src/tests/snapshots/ppl__tests__string.ir.snap +++ b/src/tests/snapshots/ppl__tests__string.ir.snap @@ -92,9 +92,9 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !19 %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !19 %3 = call %String @clone_string(ptr %name), !dbg !19 - %"$tmp@4184" = alloca %String, align 8, !dbg !19 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !19 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !19 + %"$tmp@4358" = alloca %String, align 8, !dbg !19 + store %String %3, ptr %"$tmp@4358", align 8, !dbg !19 + %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !19 store %String %4, ptr %return_value, align 8, !dbg !19 br label %return, !dbg !19 @@ -112,9 +112,9 @@ define private %String @"String from <:Type>>"(%"Type>", ptr %ty, i32 0, i32 0, !dbg !21 %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !21 %3 = call %String @clone_string(ptr %name), !dbg !21 - %"$tmp@4184" = alloca %String, align 8, !dbg !21 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !21 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !21 + %"$tmp@4358" = alloca %String, align 8, !dbg !21 + store %String %3, ptr %"$tmp@4358", align 8, !dbg !21 + %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !21 store %String %4, ptr %return_value, align 8, !dbg !21 br label %return, !dbg !21 diff --git a/src/tests/snapshots/ppl__tests__type_as_value.hir.snap b/src/tests/snapshots/ppl__tests__type_as_value.hir.snap index 8f818399..cd637419 100644 --- a/src/tests/snapshots/ppl__tests__type_as_value.hir.snap +++ b/src/tests/snapshots/ppl__tests__type_as_value.hir.snap @@ -16,17 +16,17 @@ let y: Integer = `clone <:Reference>`(Type { name: "Integer", fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -36,17 +36,17 @@ fn println -> None: fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -56,27 +56,27 @@ fn println -> None: fn String from > -> String: - let $tmp@4184: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4184:String) + let $tmp@4358: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4358:String) fn> String from >> -> String: - let $tmp@4184: String = `clone <:Reference>`((ty:Type>).name) - return ($tmp@4184:String) + let $tmp@4358: String = `clone <:Reference>`((ty:Type>).name) + return ($tmp@4358:String) fn size of > -> Integer: - let $tmp@4252: Integer = `clone <:Reference>`((ty:Type).size) - return ($tmp@4252:Integer) + let $tmp@4426: Integer = `clone <:Reference>`((ty:Type).size) + return ($tmp@4426:Integer) fn String from -> String: if (x:Bool): - let $tmp@1245: String = "true" - return ($tmp@1245:String) + let $tmp@1314: String = "true" + return ($tmp@1314:String) - let $tmp@1260: String = "false" - return ($tmp@1260:String) + let $tmp@1329: String = "false" + return ($tmp@1329:String) fn println -> None: @@ -86,8 +86,8 @@ fn println -> None: fn String from > -> String: - let $tmp@4184: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4184:String) + let $tmp@4358: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4358:String) fn println > -> None: diff --git a/src/tests/snapshots/ppl__tests__type_as_value.ir.snap b/src/tests/snapshots/ppl__tests__type_as_value.ir.snap index 4e57bb33..a222fc0f 100644 --- a/src/tests/snapshots/ppl__tests__type_as_value.ir.snap +++ b/src/tests/snapshots/ppl__tests__type_as_value.ir.snap @@ -133,9 +133,9 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !23 { %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !24 %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !24 %3 = call %Integer @clone_integer(ptr %size), !dbg !24 - %"$tmp@4252" = alloca %Integer, align 8, !dbg !24 - store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !24 - %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !24 + %"$tmp@4426" = alloca %Integer, align 8, !dbg !24 + store %Integer %3, ptr %"$tmp@4426", align 8, !dbg !24 + %4 = load %Integer, ptr %"$tmp@4426", align 8, !dbg !24 store %Integer %4, ptr %return_value, align 8, !dbg !24 br label %return, !dbg !24 @@ -157,9 +157,9 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !25 { %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !26 %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !26 %3 = call %Integer @clone_integer(ptr %size), !dbg !26 - %"$tmp@4252" = alloca %Integer, align 8, !dbg !26 - store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !26 - %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !26 + %"$tmp@4426" = alloca %Integer, align 8, !dbg !26 + store %Integer %3, ptr %"$tmp@4426", align 8, !dbg !26 + %4 = load %Integer, ptr %"$tmp@4426", align 8, !dbg !26 store %Integer %4, ptr %return_value, align 8, !dbg !26 br label %return, !dbg !26 @@ -175,9 +175,9 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg !27 { %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !28 %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !28 %3 = call %String @clone_string(ptr %name), !dbg !28 - %"$tmp@4184" = alloca %String, align 8, !dbg !28 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !28 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !28 + %"$tmp@4358" = alloca %String, align 8, !dbg !28 + store %String %3, ptr %"$tmp@4358", align 8, !dbg !28 + %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !28 store %String %4, ptr %return_value, align 8, !dbg !28 br label %return, !dbg !28 @@ -195,9 +195,9 @@ define private %String @"String from <:Type>>"(%"Type>", ptr %ty, i32 0, i32 0, !dbg !30 %name = getelementptr inbounds %"Type>Impl", ptr %2, i32 0, i32 0, !dbg !30 %3 = call %String @clone_string(ptr %name), !dbg !30 - %"$tmp@4184" = alloca %String, align 8, !dbg !30 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !30 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !30 + %"$tmp@4358" = alloca %String, align 8, !dbg !30 + store %String %3, ptr %"$tmp@4358", align 8, !dbg !30 + %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !30 store %String %4, ptr %return_value, align 8, !dbg !30 br label %return, !dbg !30 @@ -249,9 +249,9 @@ define private %Integer @"size of <:Type>"(%"Type" %0) !dbg !3 %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !38 %size = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 1, !dbg !38 %3 = call %Integer @clone_integer(ptr %size), !dbg !38 - %"$tmp@4252" = alloca %Integer, align 8, !dbg !38 - store %Integer %3, ptr %"$tmp@4252", align 8, !dbg !38 - %4 = load %Integer, ptr %"$tmp@4252", align 8, !dbg !38 + %"$tmp@4426" = alloca %Integer, align 8, !dbg !38 + store %Integer %3, ptr %"$tmp@4426", align 8, !dbg !38 + %4 = load %Integer, ptr %"$tmp@4426", align 8, !dbg !38 store %Integer %4, ptr %return_value, align 8, !dbg !38 br label %return, !dbg !38 @@ -279,9 +279,9 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !43 %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !43 %3 = call %String @clone_string(ptr %name), !dbg !43 - %"$tmp@4184" = alloca %String, align 8, !dbg !43 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !43 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !43 + %"$tmp@4358" = alloca %String, align 8, !dbg !43 + store %String %3, ptr %"$tmp@4358", align 8, !dbg !43 + %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !43 store %String %4, ptr %return_value, align 8, !dbg !43 br label %return, !dbg !43 diff --git a/src/tests/snapshots/ppl__tests__type_of.hir.snap b/src/tests/snapshots/ppl__tests__type_of.hir.snap index 12abe576..93b50338 100644 --- a/src/tests/snapshots/ppl__tests__type_of.hir.snap +++ b/src/tests/snapshots/ppl__tests__type_of.hir.snap @@ -9,13 +9,13 @@ let ty: Type = `type of <:Integer>`(1) fn type of <$arg0: Integer> -> Type: - let $tmp@4309: Type = Type { name: "Integer", size: 8 } - return ($tmp@4309:Type) + let $tmp@4483: Type = Type { name: "Integer", size: 8 } + return ($tmp@4483:Type) fn String from > -> String: - let $tmp@4184: String = `clone <:Reference>`((ty:Type).name) - return ($tmp@4184:String) + let $tmp@4358: String = `clone <:Reference>`((ty:Type).name) + return ($tmp@4358:String) fn println > -> None: diff --git a/src/tests/snapshots/ppl__tests__type_of.ir.snap b/src/tests/snapshots/ppl__tests__type_of.ir.snap index 06653a5c..3c67dccd 100644 --- a/src/tests/snapshots/ppl__tests__type_of.ir.snap +++ b/src/tests/snapshots/ppl__tests__type_of.ir.snap @@ -46,9 +46,9 @@ define private %"Type" @"type of <:Integer>"(%Integer %0) !dbg !11 { %4 = call %Integer @integer_from_i64(i64 8), !dbg !13 store %Integer %4, ptr %"Type.size", align 8, !dbg !13 %5 = load %"Type", ptr %2, align 8, !dbg !13 - %"$tmp@4309" = alloca %"Type", align 8, !dbg !13 - store %"Type" %5, ptr %"$tmp@4309", align 8, !dbg !13 - %6 = load %"Type", ptr %"$tmp@4309", align 8, !dbg !12 + %"$tmp@4483" = alloca %"Type", align 8, !dbg !13 + store %"Type" %5, ptr %"$tmp@4483", align 8, !dbg !13 + %6 = load %"Type", ptr %"$tmp@4483", align 8, !dbg !12 store %"Type" %6, ptr %return_value, align 8, !dbg !12 br label %return, !dbg !12 @@ -82,9 +82,9 @@ define private %String @"String from <:Type>"(%"Type" %0) !dbg %2 = getelementptr inbounds %"Type", ptr %ty, i32 0, i32 0, !dbg !17 %name = getelementptr inbounds %"TypeImpl", ptr %2, i32 0, i32 0, !dbg !17 %3 = call %String @clone_string(ptr %name), !dbg !17 - %"$tmp@4184" = alloca %String, align 8, !dbg !17 - store %String %3, ptr %"$tmp@4184", align 8, !dbg !17 - %4 = load %String, ptr %"$tmp@4184", align 8, !dbg !17 + %"$tmp@4358" = alloca %String, align 8, !dbg !17 + store %String %3, ptr %"$tmp@4358", align 8, !dbg !17 + %4 = load %String, ptr %"$tmp@4358", align 8, !dbg !17 store %String %4, ptr %return_value, align 8, !dbg !17 br label %return, !dbg !17 From d146ddef1c4bed1badf22eed380dc9e63f1f0563 Mon Sep 17 00:00:00 2001 From: Gavrilikhin Daniil Date: Sat, 18 May 2024 19:51:12 +0800 Subject: [PATCH 12/12] More default implementations --- ppl/src/array.ppl | 6 ++++++ ppl/src/f64.ppl | 2 ++ ppl/src/i32.ppl | 2 ++ ppl/src/memory.ppl | 2 ++ 4 files changed, 12 insertions(+) diff --git a/ppl/src/array.ppl b/ppl/src/array.ppl index 5d641e1e..ddcf917b 100644 --- a/ppl/src/array.ppl +++ b/ppl/src/array.ppl @@ -11,6 +11,12 @@ type Array: capacity: Integer data: MemoryAddress +fn default <:Type>> -> Array: + let size = 0 + let capacity = 0 + let data = default MemoryAddress + return Array { size, capacity, data } + /// Create an empty array fn <:Type>[] -> Array: let capacity = 8 diff --git a/ppl/src/f64.ppl b/ppl/src/f64.ppl index eb47700e..751f9efb 100644 --- a/ppl/src/f64.ppl +++ b/ppl/src/f64.ppl @@ -3,6 +3,8 @@ use core.* @builtin type F64 +fn default <:Type> => F64 from 0.0 + fn + => x @mangle_as("minus_f64") diff --git a/ppl/src/i32.ppl b/ppl/src/i32.ppl index 355c147a..edc7d2a8 100644 --- a/ppl/src/i32.ppl +++ b/ppl/src/i32.ppl @@ -3,6 +3,8 @@ use core.* @builtin type I32 +fn default <:Type> => 0 as I32 + fn + => x @mangle_as("minus_i32") diff --git a/ppl/src/memory.ppl b/ppl/src/memory.ppl index a82c95e8..8f4f8712 100644 --- a/ppl/src/memory.ppl +++ b/ppl/src/memory.ppl @@ -6,6 +6,8 @@ use math.* type MemoryAddress: value: Integer +fn default <:Type> => MemoryAddress { value: 0 } + /// Interpret and integer as memory address fn as MemoryAddress => MemoryAddress { value }