diff --git a/core/_preload.odin b/core/_preload.odin index ebdf55702..90ebcde56 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -25,7 +25,7 @@ Calling_Convention :: enum { FAST = 3, } -Type_Info_Record :: struct { +Type_Info_Record :: struct #ordered { types: []^Type_Info, names: []string, offsets: []int, // offsets may not be used in tuples @@ -144,13 +144,13 @@ Allocator_Mode :: enum u8 { Allocator_Proc :: #type proc(allocator_data: rawptr, mode: Allocator_Mode, size, alignment: int, old_memory: rawptr, old_size: int, flags: u64) -> rawptr; -Allocator :: struct { +Allocator :: struct #ordered { procedure: Allocator_Proc, data: rawptr, } -Context :: struct { +Context :: struct #ordered { thread_id: int, allocator: Allocator, @@ -559,18 +559,18 @@ __default_hash_string :: proc(s: string) -> u64 { __INITIAL_MAP_CAP :: 16; -__Map_Key :: struct { +__Map_Key :: struct #ordered { hash: u64, str: string, } -__Map_Find_Result :: struct { +__Map_Find_Result :: struct #ordered { hash_index: int, entry_prev: int, entry_index: int, } -__Map_Entry_Header :: struct { +__Map_Entry_Header :: struct #ordered { key: __Map_Key, next: int, /* @@ -578,7 +578,7 @@ __Map_Entry_Header :: struct { */ } -__Map_Header :: struct { +__Map_Header :: struct #ordered { m: ^raw.Dynamic_Map, is_key_string: bool, entry_size: int, diff --git a/core/os_linux.odin b/core/os_linux.odin index eeea9bf56..90250a625 100644 --- a/core/os_linux.odin +++ b/core/os_linux.odin @@ -36,7 +36,7 @@ RTLD_GLOBAL :: 0x100; // "Argv" arguments converted to Odin strings immutable args := _alloc_command_line_arguments(); -_File_Time :: struct { +_File_Time :: struct #ordered { seconds: i64, nanoseconds: i32, reserved: i32, @@ -46,7 +46,7 @@ _File_Time :: struct { // https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/jb-dev/sysroot/usr/include/bits/stat.h // Validity is not guaranteed. -Stat :: struct { +Stat :: struct #ordered { device_id: u64, // ID of device containing file serial: u64, // File serial number nlink: u32, // Number of hard links diff --git a/core/os_x.odin b/core/os_x.odin index a330d1350..ecbed3f27 100644 --- a/core/os_x.odin +++ b/core/os_x.odin @@ -41,12 +41,12 @@ RTLD_FIRST :: 0x100; args: [dynamic]string; -FileTime :: struct { +FileTime :: struct #ordered { seconds: i64, nanoseconds: i64 } -Stat :: struct { +Stat :: struct #ordered { device_id : i32, // ID of device containing file mode : u16, // Mode of the file nlink : u16, // Number of hard links diff --git a/core/sys/windows.odin b/core/sys/windows.odin index 82d0d8953..7ea62bb4c 100644 --- a/core/sys/windows.odin +++ b/core/sys/windows.odin @@ -65,11 +65,11 @@ SM_CYSCREEN :: 1; SW_SHOW :: 5; -Point :: struct { +Point :: struct #ordered { x, y: i32, } -WndClassExA :: struct { +WndClassExA :: struct #ordered { size, style: u32, wnd_proc: Wnd_Proc, cls_extra, wnd_extra: i32, @@ -81,7 +81,7 @@ WndClassExA :: struct { sm: Hicon, } -Msg :: struct { +Msg :: struct #ordered { hwnd: Hwnd, message: u32, wparam: Wparam, @@ -90,24 +90,24 @@ Msg :: struct { pt: Point, } -Rect :: struct { +Rect :: struct #ordered { left: i32, top: i32, right: i32, bottom: i32, } -Filetime :: struct { +Filetime :: struct #ordered { lo, hi: u32, } -Systemtime :: struct { +Systemtime :: struct #ordered { year, month: u16, day_of_week, day: u16, hour, minute, second, millisecond: u16, } -By_Handle_File_Information :: struct { +By_Handle_File_Information :: struct #ordered { file_attributes: u32, creation_time, last_access_time, @@ -120,7 +120,7 @@ By_Handle_File_Information :: struct { file_index_low: u32, } -File_Attribute_Data :: struct { +File_Attribute_Data :: struct #ordered { file_attributes: u32, creation_time, last_access_time, @@ -129,7 +129,7 @@ File_Attribute_Data :: struct { file_size_low: u32, } -Find_Data :: struct { +Find_Data :: struct #ordered { file_attributes : u32, creation_time : Filetime, last_access_time : Filetime, @@ -299,7 +299,7 @@ HEAP_ZERO_MEMORY :: 0x00000008; // Synchronization -Security_Attributes :: struct { +Security_Attributes :: struct #ordered { length: u32, security_descriptor: rawptr, inherit_handle: Bool, @@ -350,14 +350,14 @@ SWP_NOSIZE :: 0x0001; SWP_NOMOVE :: 0x0002; -Monitor_Info :: struct { +Monitor_Info :: struct #ordered { size: u32, monitor: Rect, work: Rect, flags: u32, } -Window_Placement :: struct { +Window_Placement :: struct #ordered { length: u32, flags: u32, show_cmd: u32, @@ -394,7 +394,7 @@ LOWORD :: proc(lParam: Lparam) -> u16 { return u16(lParam); } -Bitmap_Info_Header :: struct { +Bitmap_Info_Header :: struct #ordered { size: u32, width, height: i32, planes, bit_count: i16, @@ -405,13 +405,13 @@ Bitmap_Info_Header :: struct { clr_used: u32, clr_important: u32, } -Bitmap_Info :: struct { +Bitmap_Info :: struct #ordered { using header: Bitmap_Info_Header, colors: [1]Rgb_Quad, } -Rgb_Quad :: struct { blue, green, red, reserved: byte } +Rgb_Quad :: struct #ordered { blue, green, red, reserved: byte } BI_RGB :: 0; DIB_RGB_COLORS :: 0x00; @@ -457,7 +457,7 @@ PFD_DOUBLEBUFFER_DONTCARE :: 0x40000000; PFD_STEREO_DONTCARE :: 0x80000000; -PIXELFORMATDESCRIPTOR :: struct { +PIXELFORMATDESCRIPTOR :: struct #ordered { size, version, flags: u32, diff --git a/src/check_expr.c b/src/check_expr.c index f205935c2..a7e85f819 100644 --- a/src/check_expr.c +++ b/src/check_expr.c @@ -555,7 +555,13 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) { struct_type->Record.field_count = field_count; struct_type->Record.names = make_names_field_for_record(c, c->context.scope); - if (false && !st->is_packed && !st->is_ordered) { + type_set_offsets(c->allocator, struct_type); + + + if (!struct_type->failure && !st->is_packed && !st->is_ordered) { + struct_type->failure = false; + struct_type->Record.are_offsets_set = false; + struct_type->Record.offsets = NULL; // NOTE(bill): Reorder fields for reduced size/performance Entity **reordered_fields = gb_alloc_array(c->allocator, Entity *, field_count); @@ -576,12 +582,9 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) { struct_type->Record.fields = reordered_fields; } - { - // i64 size = type_size_of(c->allocator, struct_type); - } - type_set_offsets(c->allocator, struct_type); + if (st->align != NULL) { if (st->is_packed) { syntax_error_node(st->align, "`#align` cannot be applied with `#packed`"); diff --git a/src/parser.c b/src/parser.c index fb8d5d91b..403fcdda2 100644 --- a/src/parser.c +++ b/src/parser.c @@ -2746,11 +2746,11 @@ AstNode *parse_type_or_ident(AstFile *f) { syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string)); } is_packed = true; - // } else if (str_eq(tag.string, str_lit("ordered"))) { - // if (is_ordered) { - // syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string)); - // } - // is_ordered = true; + } else if (str_eq(tag.string, str_lit("ordered"))) { + if (is_ordered) { + syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string)); + } + is_ordered = true; } else if (str_eq(tag.string, str_lit("align"))) { if (align) { syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));