aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflysand7 <thebumboni@gmail.com>2024-01-25 20:57:18 +1100
committerflysand7 <thebumboni@gmail.com>2024-01-25 20:57:18 +1100
commit57b7822e121678187c510d56b25e3d5b2327241e (patch)
tree94a8470024572ec0ce8e35776170fdd7946cb042
parent03736d8bcb7e376e6d26071e2aca38566e17e203 (diff)
parent9cfd4a953e2a7d19237891993b643b2d1477f8b3 (diff)
Merge branch 'master' into unsigned-file-attrib
-rw-r--r--core/fmt/fmt.odin24
-rw-r--r--core/log/log.odin36
-rw-r--r--core/odin/parser/parser.odin20
-rw-r--r--core/os/os2/heap_windows.odin2
-rw-r--r--core/runtime/core_builtin.odin2
-rw-r--r--src/checker.cpp2
6 files changed, 73 insertions, 13 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)
+ }
+}
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
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)
}
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}
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] = {