Skip to content

Commit 946dc4e

Browse files
authored
Merge pull request #503 from savi-lang/fix/trait-bitmap-max
Fix trait bitmap entries to correctly use 64-bit values
2 parents ecff6c3 + 73eb7bd commit 946dc4e

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/savi/compiler/code_gen.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3457,15 +3457,15 @@ class Savi::Compiler::CodeGen
34573457
# This code is shamelessly copied from gen_desc, with a few modifications,
34583458
# because we already know that we are just targeting exactly one gtype
34593459
# (the mutator_gtype which this object is tailor-made to fit).
3460-
traits_bitmap = trait_bitmap_size.times.map { 0 }.to_a
3460+
traits_bitmap = trait_bitmap_size.times.map { 0_u64 }.to_a
34613461
mutator_gtype.type_def.tap do |other_def|
34623462
raise "can't be subtype of a concrete" unless other_def.is_abstract?(ctx)
34633463

34643464
index = other_def.desc_id >> Math.log2(@bitwidth).to_i
34653465
raise "bad index or trait_bitmap_size" unless index < trait_bitmap_size
34663466

34673467
bit = other_def.desc_id & (@bitwidth - 1)
3468-
traits_bitmap[index] |= (1 << bit)
3468+
traits_bitmap[index] |= (1_u64 << bit)
34693469
end
34703470
traits_bitmap_global = gen_global_for_const \
34713471
@isize.const_array(traits_bitmap.map { |bits| @isize.const_int(bits) })

src/savi/compiler/code_gen/debug_info.cr

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ class Savi::Compiler::CodeGen
176176
t : Reach::Ref,
177177
llvm_struct_type : LLVM::Type,
178178
)
179-
ident = t.single!.defn(ctx).ident
180-
name = ident.value
179+
name = t.single_def!(ctx).llvm_name
181180

182181
# Create a temporary stand-in for this debug type, which is used to
183182
# prevent unwanted recursion if it (directly or indirectly) contains
@@ -220,6 +219,17 @@ class Savi::Compiler::CodeGen
220219
di_create_struct_type(name, llvm_type, di_member_info, pos)
221220
end
222221

222+
@di_opaque_object_pointer_type : LibLLVM::MetadataRef?
223+
def di_opaque_object_pointer_type
224+
@di_opaque_object_pointer_type ||= begin
225+
di_create_pointer_type("OPAQUE*",
226+
di_create_struct_type("OPAQUE",
227+
@runtime.obj, di_runtime_member_info, Source::Pos.none
228+
)
229+
)
230+
end
231+
end
232+
223233
def di_create_fields_struct_type(
224234
t : Reach::Ref,
225235
llvm_type : LLVM::Type,
@@ -332,8 +342,7 @@ class Savi::Compiler::CodeGen
332342
ctx.code_gen.gtypes[ctx.reach[t.single!].llvm_name].struct_type,
333343
)
334344
elsif t.llvm_use_type(ctx) == :struct_ptr_opaque
335-
# TODO: Some more descriptive debug type?
336-
di_create_basic_type(t, llvm_type, LLVM::DwarfTypeEncoding::Address)
345+
di_opaque_object_pointer_type
337346
else
338347
raise NotImplementedError.new(t)
339348
end

src/savi/compiler/code_gen/ponyrt.cr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,17 +378,20 @@ class Savi::Compiler::CodeGen::PonyRT
378378

379379
def di_runtime_member_info(debug : DebugInfo)
380380
di_type_u32 = debug.di_create_basic_type("uint32_t", @i32, LLVM::DwarfTypeEncoding::Unsigned)
381+
di_type_usize = debug.di_create_basic_type("size_t", @isize, LLVM::DwarfTypeEncoding::Unsigned)
381382
di_type_char = debug.di_create_basic_type("char", @i8, LLVM::DwarfTypeEncoding::Signed)
382383
di_type_cstring = debug.di_create_pointer_type("char*", di_type_char)
383384
di_type_typestring_ptr = debug.di_create_pointer_type("TYPESTRING*",
384385
debug.di_create_struct_type("TYPESTRING", @typestring, {
385386
3 => {"_ptr", @ptr, di_type_cstring},
386387
}),
387388
)
389+
di_type_trait_bitmap_ptr = debug.di_create_pointer_type("size_t*", di_type_usize)
388390
di_type_desc_ptr = debug.di_create_pointer_type("TYPE*",
389391
debug.di_create_struct_type("TYPE", @desc, {
390392
DESC_ID => {"id", @i32, di_type_u32},
391393
DESC_TYPE_NAME => {"name", @ptr, di_type_typestring_ptr},
394+
DESC_TRAITS => {"traits", @ptr, di_type_trait_bitmap_ptr},
392395
}),
393396
)
394397
{ 0 => {"TYPE", @ptr, di_type_desc_ptr} }
@@ -442,14 +445,14 @@ class Savi::Compiler::CodeGen::PonyRT
442445
# the corresponding bit set in their version of the bitmap.
443446
# This is used for runtime type matching against abstract types (traits).
444447
is_asio_event_actor = false
445-
traits_bitmap = g.trait_bitmap_size.times.map { 0 }.to_a
448+
traits_bitmap = g.trait_bitmap_size.times.map { 0_u64 }.to_a
446449
g.ctx.reach.each_type_def.each { |other_def|
447450
if gtype.type_def.is_subtype_of?(g.ctx, other_def)
448451
index = other_def.desc_id >> Math.log2(g.bitwidth).to_i
449452
raise "bad index or trait_bitmap_size" unless index < g.trait_bitmap_size
450453

451454
bit = other_def.desc_id & (g.bitwidth - 1)
452-
traits_bitmap[index] |= (1 << bit)
455+
traits_bitmap[index] |= (1_u64 << bit)
453456

454457
# Take special note if this type is a subtype of AsioEvent.Actor.
455458
is_asio_event_actor = true if other_def.llvm_name == "AsioEvent.Actor"

tooling/lldb/savi_commands.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def get_command(debugger, command, result, internal_dict):
1212
# Get the root value by name, then dig into it using the child field names.
1313
value = frame.FindVariable(names[0])
1414
for name in names[1:]:
15+
# If we're looking for a field in a struct, we need to use the FIELDS field.
16+
if name != "TYPE" and name != "FIELDS":
17+
value = value.GetChildMemberWithName("FIELDS")
18+
1519
# TODO: If the value has an abstract type, we need to use its TYPE field
1620
# here to .Cast() it to the corresponding concrete type.
1721
# However it may be difficult to find the appropriate concrete type by name;

0 commit comments

Comments
 (0)