aboutsummaryrefslogtreecommitdiff
path: root/base/runtime
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-07-14 21:37:35 +0100
committergingerBill <bill@gingerbill.org>2024-07-14 21:37:35 +0100
commit399c3ab067d0bbacbf9732107b932d5bb910b67f (patch)
tree1dde731a905e97dd355829ff453551125a17c9a3 /base/runtime
parente7d37607ef9ce54a80d83230150874b71d628d6d (diff)
Reduce the size of `runtime.Type_Info`
Diffstat (limited to 'base/runtime')
-rw-r--r--base/runtime/core.odin50
-rw-r--r--base/runtime/print.odin11
2 files changed, 36 insertions, 25 deletions
diff --git a/base/runtime/core.odin b/base/runtime/core.odin
index a758a2fdd..f9bf57259 100644
--- a/base/runtime/core.odin
+++ b/base/runtime/core.odin
@@ -66,7 +66,7 @@ Type_Info_Named :: struct {
name: string,
base: ^Type_Info,
pkg: string,
- loc: Source_Code_Location,
+ loc: ^Source_Code_Location,
}
Type_Info_Integer :: struct {signed: bool, endianness: Platform_Endianness}
Type_Info_Rune :: struct {}
@@ -112,23 +112,32 @@ Type_Info_Parameters :: struct { // Only used for procedures parameters and resu
}
Type_Info_Tuple :: Type_Info_Parameters // Will be removed eventually
+Type_Info_Struct_Flags :: distinct bit_set[Type_Info_Struct_Flag; u8]
+Type_Info_Struct_Flag :: enum u8 {
+ packed = 0,
+ raw_union = 1,
+ no_copy = 2,
+ align = 3,
+}
+
Type_Info_Struct :: struct {
- types: []^Type_Info,
- names: []string,
- offsets: []uintptr,
- usings: []bool,
- tags: []string,
- is_packed: bool,
- is_raw_union: bool,
- is_no_copy: bool,
- custom_align: bool,
+ // Slice these with `field_count`
+ types: [^]^Type_Info,
+ names: [^]string,
+ offsets: [^]uintptr,
+ usings: [^]bool,
+ tags: [^]string,
- equal: Equal_Proc, // set only when the struct has .Comparable set but does not have .Simple_Compare set
+ field_count: i32,
+
+ flags: Type_Info_Struct_Flags,
// These are only set iff this structure is an SOA structure
soa_kind: Type_Info_Struct_Soa_Kind,
+ soa_len: i32,
soa_base_type: ^Type_Info,
- soa_len: int,
+
+ equal: Equal_Proc, // set only when the struct has .Comparable set but does not have .Simple_Compare set
}
Type_Info_Union :: struct {
variants: []^Type_Info,
@@ -142,9 +151,9 @@ Type_Info_Union :: struct {
shared_nil: bool,
}
Type_Info_Enum :: struct {
- base: ^Type_Info,
- names: []string,
- values: []Type_Info_Enum_Value,
+ base: ^Type_Info,
+ names: []string,
+ values: []Type_Info_Enum_Value,
}
Type_Info_Map :: struct {
key: ^Type_Info,
@@ -187,11 +196,12 @@ Type_Info_Soa_Pointer :: struct {
}
Type_Info_Bit_Field :: struct {
backing_type: ^Type_Info,
- names: []string,
- types: []^Type_Info,
- bit_sizes: []uintptr,
- bit_offsets: []uintptr,
- tags: []string,
+ names: [^]string,
+ types: [^]^Type_Info,
+ bit_sizes: [^]uintptr,
+ bit_offsets: [^]uintptr,
+ tags: [^]string,
+ field_count: int,
}
Type_Info_Flag :: enum u8 {
diff --git a/base/runtime/print.odin b/base/runtime/print.odin
index 0262e8ef6..45f6f01ef 100644
--- a/base/runtime/print.odin
+++ b/base/runtime/print.odin
@@ -401,15 +401,16 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) {
}
print_string("struct ")
- if info.is_packed { print_string("#packed ") }
- if info.is_raw_union { print_string("#raw_union ") }
- if info.custom_align {
+ if .packed in info.flags { print_string("#packed ") }
+ if .raw_union in info.flags { print_string("#raw_union ") }
+ if .no_copy in info.flags { print_string("#no_copy ") }
+ if .align in info.flags {
print_string("#align(")
print_u64(u64(ti.align))
print_string(") ")
}
print_byte('{')
- for name, i in info.names {
+ for name, i in info.names[:info.field_count] {
if i > 0 { print_string(", ") }
print_string(name)
print_string(": ")
@@ -469,7 +470,7 @@ print_type :: #force_no_inline proc "contextless" (ti: ^Type_Info) {
print_string("bit_field ")
print_type(info.backing_type)
print_string(" {")
- for name, i in info.names {
+ for name, i in info.names[:info.field_count] {
if i > 0 { print_string(", ") }
print_string(name)
print_string(": ")