From b1dae2d59ab1f35992d0f24b4f01d4d2123f9262 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 20 Mar 2024 13:28:17 +0000 Subject: [PATCH 01/11] Add `x: T; y: ^T = x` suggestion to do `&x` --- src/check_expr.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index e9a6f5122..e22d57814 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2248,6 +2248,12 @@ gb_internal void check_assignment_error_suggestion(CheckerContext *c, Operand *o gbString s = expr_to_string(c->type_hint_expr); error_line("\tSuggestion: make sure that `%s` is attached to the compound literal directly\n", s); gb_string_free(s); + } else if (is_type_pointer(type) && + o->mode == Addressing_Variable && + are_types_identical(type_deref(type), o->type)) { + gbString s = expr_to_string(o->expr); + error_line("\tSuggestion: Did you mean `&%s`\n", s); + gb_string_free(s); } } From ba77a9464c7e912dda52dd512dc98f3c241581ac Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 20 Mar 2024 13:36:14 +0000 Subject: [PATCH 02/11] Add suggestion for `x: ^T; y = x` to be `x^` --- src/check_expr.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index e22d57814..8fb2cf36b 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2254,6 +2254,11 @@ gb_internal void check_assignment_error_suggestion(CheckerContext *c, Operand *o gbString s = expr_to_string(o->expr); error_line("\tSuggestion: Did you mean `&%s`\n", s); gb_string_free(s); + } else if (is_type_pointer(o->type) && + are_types_identical(type_deref(o->type), type)) { + gbString s = expr_to_string(o->expr); + error_line("\tSuggestion: Did you mean `%s^`\n", s); + gb_string_free(s); } } From 1951bc45a68ec930d5e10620f9e4e9c84cf74ded Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 20 Mar 2024 13:55:47 +0000 Subject: [PATCH 03/11] Fix #3133 by show the line of the syntax error --- src/error.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.cpp b/src/error.cpp index b96719420..2458061c2 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -460,7 +460,7 @@ gb_internal void syntax_error_va(TokenPos const &pos, TokenPos end, char const * error_out_coloured("Syntax Error: ", TerminalStyle_Normal, TerminalColour_Red); error_out_va(fmt, va); error_out("\n"); - // show_error_on_line(pos, end); + show_error_on_line(pos, end); } else if (pos.line == 0) { error_out_empty(); error_out_coloured("Syntax Error: ", TerminalStyle_Normal, TerminalColour_Red); From b4fe9677a1f69acde12e7cf296269f0c4d98362f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 20 Mar 2024 16:06:50 +0000 Subject: [PATCH 04/11] Change ARM64 ABI for integer-like parameters --- src/llvm_abi.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/llvm_abi.cpp b/src/llvm_abi.cpp index 24e86fa64..fcd22a40d 100644 --- a/src/llvm_abi.cpp +++ b/src/llvm_abi.cpp @@ -1183,14 +1183,8 @@ namespace lbAbiArm64 { i64 size = lb_sizeof(type); if (size <= 16) { LLVMTypeRef cast_type = nullptr; - if (size <= 1) { - cast_type = LLVMIntTypeInContext(c, 8); - } else if (size <= 2) { - cast_type = LLVMIntTypeInContext(c, 16); - } else if (size <= 4) { - cast_type = LLVMIntTypeInContext(c, 32); - } else if (size <= 8) { - cast_type = LLVMIntTypeInContext(c, 64); + if (size <= 8) { + cast_type = LLVMIntTypeInContext(c, cast(unsigned)(size*8)); } else { unsigned count = cast(unsigned)((size+7)/8); cast_type = llvm_array_type(LLVMIntTypeInContext(c, 64), count); From 9c879e5e172b38ed054d2268c5839c5f3f38832b Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 20 Mar 2024 17:42:20 +0100 Subject: [PATCH 05/11] commonmark: add missing on_exit api --- vendor/commonmark/cmark.odin | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vendor/commonmark/cmark.odin b/vendor/commonmark/cmark.odin index 3563dff16..9ad71da3f 100644 --- a/vendor/commonmark/cmark.odin +++ b/vendor/commonmark/cmark.odin @@ -366,6 +366,16 @@ foreign lib { // Returns `true` on success, `false`on failure. node_set_on_enter :: proc(node: ^Node, on_enter: cstring) -> (success: b32) --- + // Returns the literal "on exit" text for a custom 'node', or + // an empty string if no on_exit is set. Returns NULL if + // called on a non-custom node. + node_get_on_exit :: proc(node: ^Node) -> (on_exit: cstring) --- + + // Sets the literal text to render "on exit" for a custom 'node'. + // Any children of the node will be rendered before this text. + // Returns 1 on success 0 on failure. + node_set_on_exit :: proc(node: ^Node, on_exit: cstring) -> (success: b32) --- + // Returns the line on which `node` begins. node_get_start_line :: proc(node: ^Node) -> (line: c.int) --- From f312adb26aab6b3e0fdbaa7f9d1462a00daa474c Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Wed, 20 Mar 2024 17:44:35 +0100 Subject: [PATCH 06/11] darwin: allow cross linking darwin_amd64 from darwin_arm64 --- src/build_settings.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 3c822e295..4be189cf1 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -1476,6 +1476,7 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta bc->link_flags = str_lit("/machine:x64 "); break; case TargetOs_darwin: + bc->link_flags = str_lit("-arch x86_64 "); break; case TargetOs_linux: bc->link_flags = str_lit("-arch x86-64 "); From e804fbd891092c89f21aa62e6ed05bc4feb4761b Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 20 Mar 2024 17:27:05 +0000 Subject: [PATCH 07/11] Force packed structs in ABI parameters --- src/llvm_abi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/llvm_abi.cpp b/src/llvm_abi.cpp index fcd22a40d..62658d178 100644 --- a/src/llvm_abi.cpp +++ b/src/llvm_abi.cpp @@ -876,7 +876,7 @@ namespace lbAbiAmd64SysV { if (types.count == 1) { return types[0]; } - return LLVMStructTypeInContext(c, types.data, cast(unsigned)types.count, false); + return LLVMStructTypeInContext(c, types.data, cast(unsigned)types.count, true); } gb_internal void classify_with(LLVMTypeRef t, Array *cls, i64 ix, i64 off) { @@ -1312,7 +1312,7 @@ namespace lbAbiWasm { // ignore padding LLVMStructGetTypeAtIndex(type, 2) }; - LLVMTypeRef new_type = LLVMStructTypeInContext(c, types, gb_count_of(types), false); + LLVMTypeRef new_type = LLVMStructTypeInContext(c, types, gb_count_of(types), true); return lb_arg_type_direct(type, new_type, nullptr, nullptr); } else { return is_struct(c, type, calling_convention); From c17adc98f5dfd313d4123c8a08d23eb1907e238f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 20 Mar 2024 17:39:00 +0000 Subject: [PATCH 08/11] Try doing `<{i64, i32}>` instead of `[i64, i64]` for ARM64 12-byte parameters --- src/llvm_abi.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/llvm_abi.cpp b/src/llvm_abi.cpp index 62658d178..375235752 100644 --- a/src/llvm_abi.cpp +++ b/src/llvm_abi.cpp @@ -1187,7 +1187,21 @@ namespace lbAbiArm64 { cast_type = LLVMIntTypeInContext(c, cast(unsigned)(size*8)); } else { unsigned count = cast(unsigned)((size+7)/8); - cast_type = llvm_array_type(LLVMIntTypeInContext(c, 64), count); + + LLVMTypeRef llvm_i64 = LLVMIntTypeInContext(c, 64); + LLVMTypeRef *types = gb_alloc_array(temporary_allocator(), LLVMTypeRef, count); + + i64 size_copy = size; + for (unsigned i = 0; i < count; i++) { + if (size_copy >= 8) { + types[i] = llvm_i64; + } else { + types[i] = LLVMIntTypeInContext(c, 8*cast(unsigned)size_copy); + } + size_copy -= 8; + } + GB_ASSERT(size_copy <= 0); + cast_type = LLVMStructTypeInContext(c, types, count, true); } args[i] = lb_arg_type_direct(type, cast_type, nullptr, nullptr); } else { From 8e0806be2d499c1eee1e9b4c124c012794d97b6d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 20 Mar 2024 18:09:57 +0000 Subject: [PATCH 09/11] Fix #3301 --- src/check_stmt.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 4280e7578..7cccab226 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1661,6 +1661,8 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) defer (gb_string_free(s)); defer (gb_string_free(t)); + ERROR_BLOCK(); + error(operand.expr, "Cannot iterate over '%s' of type '%s'", s, t); if (rs->vals.count == 1) { From 1cc5e2380158216ad65b4d9622c847479e495ebf Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 20 Mar 2024 18:14:29 +0000 Subject: [PATCH 10/11] Fix #3299 --- src/parser.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/parser.cpp b/src/parser.cpp index eb9e73342..54b0390bf 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5440,14 +5440,27 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String path, String const return nullptr; } + isize files_with_ext = 0; isize files_to_reserve = 1; // always reserve 1 for (FileInfo fi : list) { String name = fi.name; String ext = path_extension(name); + if (ext == FILE_EXT) { + files_with_ext += 1; + } if (ext == FILE_EXT && !is_excluded_target_filename(name)) { files_to_reserve += 1; } } + if (files_with_ext == 0 || files_to_reserve == 1) { + if (files_to_reserve == 1) { + syntax_error(pos, "Directory contains no .odin files for the specified platform: %.*s", LIT(rel_path)); + } else { + syntax_error(pos, "Empty directory that contains no .odin files: %.*s", LIT(rel_path)); + } + return nullptr; + } + array_reserve(&pkg->files, files_to_reserve); for (FileInfo fi : list) { From f39b34a8b7ce026d608532451f4f2aada40f5102 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 20 Mar 2024 18:17:06 +0000 Subject: [PATCH 11/11] Fix error message --- src/parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser.cpp b/src/parser.cpp index 54b0390bf..6a7be8a7c 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5453,7 +5453,7 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String path, String const } } if (files_with_ext == 0 || files_to_reserve == 1) { - if (files_to_reserve == 1) { + if (files_with_ext != 0) { syntax_error(pos, "Directory contains no .odin files for the specified platform: %.*s", LIT(rel_path)); } else { syntax_error(pos, "Empty directory that contains no .odin files: %.*s", LIT(rel_path));