From 855be9288121d0f7a67d277f7bbbbf57fbfa2597 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 21 Feb 2025 21:34:48 +0100 Subject: [PATCH] Regression with .gitkeep in project init. List.init incorrectly didn't have the first argument the allocator. Added .init to priority queue. Created `mem` thread allocator alias. Correctly handle ident aliases. Allow ident on builtin aliases. --- lib/std/collections/list.c3 | 4 ++-- lib/std/collections/priorityqueue.c3 | 5 +++++ lib/std/core/mem_allocator.c3 | 1 + lib/std/experimental/FrameScheduler.c3 | 6 +++--- lib/std/math/math.c3 | 28 +++++++++++++------------- releasenotes.md | 2 ++ src/compiler/ast.c | 1 + src/compiler/parse_global.c | 4 +++- src/compiler/sema_expr.c | 3 +++ src/utils/file_utils.c | 2 +- 10 files changed, 35 insertions(+), 21 deletions(-) diff --git a/lib/std/collections/list.c3 b/lib/std/collections/list.c3 index 5db7a4bab..8f6a45e00 100644 --- a/lib/std/collections/list.c3 +++ b/lib/std/collections/list.c3 @@ -23,7 +23,7 @@ struct List (Printable) @param initial_capacity "The initial capacity to reserve" @param [&inout] allocator "The allocator to use, defaults to the heap allocator" *> -fn List* List.init(&self, usz initial_capacity = 16, Allocator allocator) +fn List* List.init(&self, Allocator allocator, usz initial_capacity = 16) { self.allocator = allocator; self.size = 0; @@ -54,7 +54,7 @@ fn List* List.new_init(&self, usz initial_capacity = 16, Allocator allocator = a *> fn List* List.temp_init(&self, usz initial_capacity = 16) { - return self.init(initial_capacity, allocator::temp()) @inline; + return self.init(allocator::temp(), initial_capacity) @inline; } <* diff --git a/lib/std/collections/priorityqueue.c3 b/lib/std/collections/priorityqueue.c3 index e83a00cb9..a4d0a3144 100644 --- a/lib/std/collections/priorityqueue.c3 +++ b/lib/std/collections/priorityqueue.c3 @@ -36,6 +36,11 @@ struct PrivatePriorityQueue (Printable) Heap heap; } +fn void PrivatePriorityQueue.init(&self, Allocator allocator, usz initial_capacity = 16, ) @inline +{ + self.heap.new_init(initial_capacity, allocator); +} + fn void PrivatePriorityQueue.new_init(&self, usz initial_capacity = 16, Allocator allocator = allocator::heap()) @inline { self.heap.new_init(initial_capacity, allocator); diff --git a/lib/std/core/mem_allocator.c3 b/lib/std/core/mem_allocator.c3 index d810d9439..aecdb270c 100644 --- a/lib/std/core/mem_allocator.c3 +++ b/lib/std/core/mem_allocator.c3 @@ -360,6 +360,7 @@ macro void*! @aligned_realloc(#calloc_fn, #free_fn, void* old_pointer, usz bytes // All allocators +def mem = thread_allocator @builtin; tlocal Allocator thread_allocator @private = base_allocator(); Allocator temp_base_allocator @private = base_allocator(); diff --git a/lib/std/experimental/FrameScheduler.c3 b/lib/std/experimental/FrameScheduler.c3 index 423a52ca5..e44fe18a1 100644 --- a/lib/std/experimental/FrameScheduler.c3 +++ b/lib/std/experimental/FrameScheduler.c3 @@ -28,9 +28,9 @@ struct FrameScheduler fn void FrameScheduler.init(&self) { - self.events.new_init(); - self.pending_events.new_init(); - self.delayed_events.new_init(); + self.events.init(mem); + self.pending_events.init(mem); + self.delayed_events.init(mem); (void)self.mtx.init(); bool pending; } diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index aa76cefe2..93a70a607 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -92,13 +92,13 @@ fault MatrixError def Complexf = Complex(); def Complex = Complex(); -def COMPLEX_IDENTITY = complex::IDENTITY(); -def COMPLEXF_IDENTITY = complex::IDENTITY(); +def COMPLEX_IDENTITY = complex::IDENTITY() @builtin; +def COMPLEXF_IDENTITY = complex::IDENTITY() @builtin; def Quaternionf = Quaternion(); def Quaternion = Quaternion(); -def QUATERNION_IDENTITY = quaternion::IDENTITY(); -def QUATERNIONF_IDENTITY = quaternion::IDENTITY(); +def QUATERNION_IDENTITY = quaternion::IDENTITY() @builtin; +def QUATERNIONF_IDENTITY = quaternion::IDENTITY() @builtin; def Matrix2f = Matrix2x2(); def Matrix2 = Matrix2x2(); @@ -106,17 +106,17 @@ def Matrix3f = Matrix3x3(); def Matrix3 = Matrix3x3(); def Matrix4f = Matrix4x4(); def Matrix4 = Matrix4x4(); -def matrix4_ortho = matrix::ortho(); -def matrix4_perspective = matrix::perspective(); -def matrix4f_ortho = matrix::ortho(); -def matrix4f_perspective = matrix::perspective(); +def matrix4_ortho = matrix::ortho() @builtin; +def matrix4_perspective = matrix::perspective() @builtin; +def matrix4f_ortho = matrix::ortho() @builtin; +def matrix4f_perspective = matrix::perspective() @builtin; -def MATRIX2_IDENTITY = matrix::IDENTITY2(); -def MATRIX2F_IDENTITY = matrix::IDENTITY2(); -def MATRIX3_IDENTITY = matrix::IDENTITY3(); -def MATRIX3F_IDENTITY = matrix::IDENTITY3(); -def MATRIX4_IDENTITY = matrix::IDENTITY4(); -def MATRIX4F_IDENTITY = matrix::IDENTITY4(); +def MATRIX2_IDENTITY = matrix::IDENTITY2() @builtin; +def MATRIX2F_IDENTITY = matrix::IDENTITY2() @builtin; +def MATRIX3_IDENTITY = matrix::IDENTITY3() @builtin; +def MATRIX3F_IDENTITY = matrix::IDENTITY3() @builtin; +def MATRIX4_IDENTITY = matrix::IDENTITY4() @builtin; +def MATRIX4F_IDENTITY = matrix::IDENTITY4() @builtin; <* diff --git a/releasenotes.md b/releasenotes.md index 6aeacd863..6a1ee0529 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -16,6 +16,8 @@ - Correctly give an error if a character literal contains a line break. - Implicitly unwrapped optional value in defer incorrectly copied #1982. - Crash when trying to define a method macro that isn't `@construct` but has no arguments. +- Regression, `.gitkeep` files were generated incorrectly. +- Aliases are now correctly handled as if they were variables/functions in regards to namespacing and accept `@builtin`. ### Stdlib changes diff --git a/src/compiler/ast.c b/src/compiler/ast.c index a5bcab549..4c98c3e15 100644 --- a/src/compiler/ast.c +++ b/src/compiler/ast.c @@ -406,6 +406,7 @@ bool decl_needs_prefix(Decl *decl) switch (decl->decl_kind) { case DECL_VAR: + case DECL_DEFINE: case DECL_FUNC: case DECL_MACRO: return !decl->is_autoimport; diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 56cb2483d..c28ea0db8 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -2109,10 +2109,12 @@ static inline Decl *parse_def_attribute(ParseContext *c) CONSUME_OR_RET(TOKEN_LBRACE, poisoned_decl); bool is_cond; - if (!parse_attributes(c, &attributes, NULL, NULL, &is_cond)) return poisoned_decl; + bool is_builtin; + if (!parse_attributes(c, &attributes, NULL, decl_needs_prefix(decl) ? &is_builtin : NULL, &is_cond)) return poisoned_decl; CONSUME_OR_RET(TOKEN_RBRACE, poisoned_decl); decl->attr_decl.attrs = attributes; decl->is_cond = is_cond; + decl->is_autoimport = is_builtin; if (!parse_attributes_for_global(c, decl)) return poisoned_decl; CONSUME_EOS_OR_RET(poisoned_decl); return decl; diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index c9a0aa97c..9cd70e0a0 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1093,6 +1093,9 @@ static inline bool sema_expr_analyse_identifier(SemaContext *context, Type *to, case DECL_MACRO: message = "Macros from other modules must be prefixed with the module name."; break; + case DECL_DEFINE: + message = "Aliases from other modules must be prefixed with the module name."; + break; default: UNREACHABLE } diff --git a/src/utils/file_utils.c b/src/utils/file_utils.c index 3f0a5159a..295006963 100644 --- a/src/utils/file_utils.c +++ b/src/utils/file_utils.c @@ -509,7 +509,7 @@ const char *file_append_path_temp(const char *path, const char *name) #endif // format the string safely - bool insert_separator = path[path_len - 1] == '/' || path[path_len - 1] == separator; + bool insert_separator = path[path_len - 1] != '/' && path[path_len - 1] != separator; int written = insert_separator ? snprintf(path_buffer, PATH_BUFFER_SIZE, "%s%c%s", path, separator, name) : snprintf(path_buffer, PATH_BUFFER_SIZE, "%s%s", path, name);