From f63f28302e5d493183fb77ceedcda759dcc1c3c6 Mon Sep 17 00:00:00 2001 From: DanielGavin Date: Mon, 22 Jan 2024 20:35:26 +0100 Subject: [PATCH 1/5] Recover from faulty parameter in parse_proc_type --- core/odin/parser/parser.odin | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index f11d0eb73..3383f3514 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -436,6 +436,24 @@ expect_closing_brace_of_field_list :: proc(p: ^Parser) -> tokenizer.Token { return expect_brace } +expect_closing_parentheses_of_field_list :: proc(p: ^Parser) -> tokenizer.Token { + token := p.curr_tok + if allow_token(p, .Close_Paren) { + return token + } + + if allow_token(p, .Semicolon) && !tokenizer.is_newline(token) { + str := tokenizer.token_to_string(token) + error(p, end_of_line_pos(p, p.prev_tok), "expected a comma, got %s", str) + } + + for p.curr_tok.kind != .Close_Paren && p.curr_tok.kind != .EOF && !is_non_inserted_semicolon(p.curr_tok) { + advance_token(p) + } + + return expect_token(p, .Close_Paren) +} + is_non_inserted_semicolon :: proc(tok: tokenizer.Token) -> bool { return tok.kind == .Semicolon && tok.text != "\n" } @@ -2095,7 +2113,7 @@ parse_proc_type :: proc(p: ^Parser, tok: tokenizer.Token) -> ^ast.Proc_Type { expect_token(p, .Open_Paren) params, _ := parse_field_list(p, .Close_Paren, ast.Field_Flags_Signature_Params) - expect_token(p, .Close_Paren) + expect_closing_parentheses_of_field_list(p) results, diverging := parse_results(p) is_generic := false From 2097b09abb74208b2548c93528b9dd775ec3e411 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Mon, 22 Jan 2024 21:07:17 +0100 Subject: [PATCH 2/5] fix for wasm on llvm 17 --- src/checker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/checker.cpp b/src/checker.cpp index 917340a20..4d7514d0b 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1085,7 +1085,7 @@ gb_internal void init_universal(void) { add_global_constant("ODIN_COMPILE_TIMESTAMP", t_untyped_integer, exact_value_i64(odin_compile_timestamp())); - add_global_bool_constant("__ODIN_LLVM_F16_SUPPORTED", lb_use_new_pass_system()); + add_global_bool_constant("__ODIN_LLVM_F16_SUPPORTED", lb_use_new_pass_system() && !is_arch_wasm()); { GlobalEnumValue values[3] = { From 90d1f9ab276c6dc5ed3d208d3f3c7e6323f681d8 Mon Sep 17 00:00:00 2001 From: Dragos Popescu Date: Tue, 23 Jan 2024 20:56:13 +0200 Subject: [PATCH 3/5] Removed return value of assertf. assertf now correctly responds to -disable-assert. Added log.assert and log.assertf. All asserts now do the @cold trick, first added to builtin.assert --- core/fmt/fmt.odin | 24 +++++++++++++++--------- core/log/log.odin | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index c9e284edc..f4fddd18d 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -253,18 +253,24 @@ bprintf :: proc(buf: []byte, fmt: string, args: ..any) -> string { // - args: A variadic list of arguments to be formatted // - loc: The location of the caller // -// Returns: True if the condition is met, otherwise triggers a runtime assertion with a formatted message -// -assertf :: proc(condition: bool, fmt: string, args: ..any, loc := #caller_location) -> bool { +@(disabled=ODIN_DISABLE_ASSERT) +assertf :: proc(condition: bool, fmt: string, args: ..any, loc := #caller_location) { if !condition { - p := context.assertion_failure_proc - if p == nil { - p = runtime.default_assertion_failure_proc + // NOTE(dragos): We are using the same trick as in builtin.assert + // to improve performance to make the CPU not + // execute speculatively, making it about an order of + // magnitude faster + @(cold) + internal :: proc(loc: runtime.Source_Code_Location, fmt: string, args: ..any) { + p := context.assertion_failure_proc + if p == nil { + p = runtime.default_assertion_failure_proc + } + message := tprintf(fmt, ..args) + p("Runtime assertion", message, loc) } - message := tprintf(fmt, ..args) - p("Runtime assertion", message, loc) + internal(loc, fmt, ..args) } - return condition } // Runtime panic with a formatted message // diff --git a/core/log/log.odin b/core/log/log.odin index 021a46000..b4039caa0 100644 --- a/core/log/log.odin +++ b/core/log/log.odin @@ -116,6 +116,42 @@ panicf :: proc(fmt_str: string, args: ..any, location := #caller_location) -> ! runtime.panic("log.panicf", location) } +@(disabled=ODIN_DISABLE_ASSERT) +assert :: proc(condition: bool, message := "", loc := #caller_location) { + if !condition { + @(cold) + internal :: proc(message: string, loc: runtime.Source_Code_Location) { + p := context.assertion_failure_proc + if p == nil { + p = runtime.default_assertion_failure_proc + } + log(.Fatal, message, location=loc) + p("runtime assertion", message, loc) + } + internal(message, loc) + } +} + +@(disabled=ODIN_DISABLE_ASSERT) +assertf :: proc(condition: bool, fmt_str: string, args: ..any, loc := #caller_location) { + if !condition { + // NOTE(dragos): We are using the same trick as in builtin.assert + // to improve performance to make the CPU not + // execute speculatively, making it about an order of + // magnitude faster + @(cold) + internal :: proc(loc: runtime.Source_Code_Location, fmt_str: string, args: ..any) { + p := context.assertion_failure_proc + if p == nil { + p = runtime.default_assertion_failure_proc + } + message := fmt.tprintf(fmt_str, ..args) + log(.Fatal, message, location=loc) + p("Runtime assertion", message, loc) + } + internal(loc, fmt_str, ..args) + } +} From a66009810652dbf5edae7e5224270cd11445624f Mon Sep 17 00:00:00 2001 From: flysand7 Date: Wed, 24 Jan 2024 15:51:47 +1100 Subject: [PATCH 4/5] os2: Add .Resize_Non_Zeroed allocation mode to os2/heap_windows --- core/os/os2/heap_windows.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/os/os2/heap_windows.odin b/core/os/os2/heap_windows.odin index eba403c1d..4afc016a0 100644 --- a/core/os/os2/heap_windows.odin +++ b/core/os/os2/heap_windows.odin @@ -85,7 +85,7 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode, case .Free_All: return nil, .Mode_Not_Implemented - case .Resize: + case .Resize, .Resize_Non_Zeroed: if old_memory == nil { return aligned_alloc(size, alignment, true) } From 14e2cc17d6420e4c25a8d4fa815fffde87fd7239 Mon Sep 17 00:00:00 2001 From: Kyle Burke Date: Wed, 24 Jan 2024 09:39:47 -0600 Subject: [PATCH 5/5] Remove mention of `map` in builtin resize proc group --- core/runtime/core_builtin.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin index bc85cd7f2..3f4ebbc74 100644 --- a/core/runtime/core_builtin.odin +++ b/core/runtime/core_builtin.odin @@ -172,7 +172,7 @@ reserve :: proc{reserve_dynamic_array, reserve_map} @builtin non_zero_reserve :: proc{non_zero_reserve_dynamic_array} -// `resize` will try to resize memory of a passed dynamic array or map to the requested element count (setting the `len`, and possibly `cap`). +// `resize` will try to resize memory of a passed dynamic array to the requested element count (setting the `len`, and possibly `cap`). @builtin resize :: proc{resize_dynamic_array}