From c9d9127da63bf0a81aec58cce02ab004df11eb13 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 5 Jun 2025 12:51:35 +0200 Subject: [PATCH] Deprecate `foo.#bar`. --- lib/std/core/builtin.c3 | 2 +- lib/std/core/runtime.c3 | 8 ++++++++ lib/std/threads/fixed_pool.c3 | 6 +++--- lib/std/threads/pool.c3 | 9 +++++---- releasenotes.md | 1 + src/compiler/sema_expr.c | 13 ++++++------- src/compiler/symtab.c | 2 +- test/test_suite/expressions/deref_access_null.c3t | 6 +++--- test/test_suite/macros/hash_ident_nested.c3t | 10 +++++----- test/test_suite/macros/typed_hash_access.c3 | 11 ----------- 10 files changed, 33 insertions(+), 35 deletions(-) delete mode 100644 test/test_suite/macros/typed_hash_access.c3 diff --git a/lib/std/core/builtin.c3 b/lib/std/core/builtin.c3 index d02948744..cccfca726 100644 --- a/lib/std/core/builtin.c3 +++ b/lib/std/core/builtin.c3 @@ -284,7 +284,7 @@ macro enum_by_name($Type, String enum_name) @builtin @ensure @typeis(return, $Type) @return? NOT_FOUND *> -macro @enum_from_value($Type, #value, value) @builtin +macro @enum_from_value($Type, #value, value) @builtin @deprecated("Use Enum.lookup_field and Enum.lookup") { foreach (e : $Type.values) { diff --git a/lib/std/core/runtime.c3 b/lib/std/core/runtime.c3 index 819bce123..f7583773f 100644 --- a/lib/std/core/runtime.c3 +++ b/lib/std/core/runtime.c3 @@ -30,6 +30,14 @@ macro @enum_lookup($Type, #value, value) return NOT_FOUND?; } +macro @enum_lookup_new($Type, $name, value) +{ + $foreach $val : $Type.values: + if ($val.$eval($name) == value) return $val; + $endforeach + return NOT_FOUND?; +} + module std::core::runtime @if(WASM_NOLIBC); diff --git a/lib/std/threads/fixed_pool.c3 b/lib/std/threads/fixed_pool.c3 index 8eada681d..17b4f7cc1 100644 --- a/lib/std/threads/fixed_pool.c3 +++ b/lib/std/threads/fixed_pool.c3 @@ -61,7 +61,7 @@ fn void? FixedThreadPool.init(&self, usz threads, usz queue_size = 0) *> fn void? FixedThreadPool.destroy(&self) { - return self.@shutdown(stop_now); + return self.@shutdown(self.stop_now); } <* @@ -70,7 +70,7 @@ fn void? FixedThreadPool.destroy(&self) *> fn void? FixedThreadPool.stop_and_destroy(&self) { - return self.@shutdown(stop); + return self.@shutdown(self.stop); } macro void? FixedThreadPool.@shutdown(&self, #stop) @private @@ -78,7 +78,7 @@ macro void? FixedThreadPool.@shutdown(&self, #stop) @private if (self.initialized) { self.mu.lock()!; - self.#stop = true; + #stop = true; self.notify.broadcast()!; self.mu.unlock()!; // Wait for all threads to shutdown. diff --git a/lib/std/threads/pool.c3 b/lib/std/threads/pool.c3 index 0fc2a55b2..ccec23741 100644 --- a/lib/std/threads/pool.c3 +++ b/lib/std/threads/pool.c3 @@ -7,7 +7,8 @@ struct ThreadPool QueueItem[SIZE] queue; usz qindex; usz num_threads; - bitstruct : char { + bitstruct : char + { bool initialized; bool stop; bool stop_now; @@ -46,7 +47,7 @@ fn void? ThreadPool.init(&self) *> fn void? ThreadPool.destroy(&self) { - return self.@shutdown(stop_now); + return self.@shutdown(self.stop_now); } <* @@ -55,7 +56,7 @@ fn void? ThreadPool.destroy(&self) *> fn void? ThreadPool.stop_and_destroy(&self) { - return self.@shutdown(stop); + return self.@shutdown(self.stop); } macro void? ThreadPool.@shutdown(&self, #stop) @private @@ -63,7 +64,7 @@ macro void? ThreadPool.@shutdown(&self, #stop) @private if (self.initialized) { self.mu.lock()!; - self.#stop = true; + #stop = true; self.notify.broadcast()!; self.mu.unlock()!; // Wait for all threads to shutdown. diff --git a/releasenotes.md b/releasenotes.md index 69914bb21..af2f0826e 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -8,6 +8,7 @@ - `-0xFF` will now be a signed integer. - Implicitly convert from constant typeid to Type in `$Type` assignment, and `$assignable`. - Make $Type parameters accept constant typeid values. +- Deprecate `foo.#bar`. ### Fixes - `-2147483648`, MIN literals work correctly. diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index a5c2dbe09..abcd6d8e7 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -2920,9 +2920,8 @@ FOUND:; expr->expr_kind = EXPR_CALL; while (vec_size(args) < 3) vec_add(args, NULL); args[0] = type; - Expr *unresolved_ident = expr_new_expr(EXPR_UNRESOLVED_IDENTIFIER, expr); - unresolved_ident->unresolved_ident_expr.ident = match->name; - args[1] = unresolved_ident; + + args[1] = expr_new_const_string(expr->span, match->name); args[2] = key; Expr *call = expr_new_expr(EXPR_UNRESOLVED_IDENTIFIER, expr); Path *new_path = CALLOCS(Path); @@ -4070,10 +4069,9 @@ static inline bool sema_expr_analyse_slice(SemaContext *context, Expr *expr, Che * 2. .foo -> It is a function. * 3. .@foo -> It is a macro. * 4. .#bar -> It is an identifier to resolve as a member or a function - * 5. .@#bar -> It is an identifier to resolve as a macro - * 6. .$eval(...) -> resolve the eval and retry. - * 7. .$ident -> It is a child to resolve as CT param - * 8. .$Type -> It is a child to resolve as CT type param + * 5. .$eval(...) -> resolve the eval and retry. + * 6. .$ident -> It is a child to resolve as CT param + * 7. .$Type -> It is a child to resolve as CT type param */ Expr *sema_expr_resolve_access_child(SemaContext *context, Expr *child, bool *missing) { @@ -4083,6 +4081,7 @@ RETRY: switch (child->expr_kind) { case EXPR_HASH_IDENT: + SEMA_DEPRECATED(child, "Using 'abc.#foo' access style is deprecated. Use 'abc.eval($foo)' instead."); if (!sema_expr_fold_hash(context, child)) return false; in_hash = true; goto RETRY; diff --git a/src/compiler/symtab.c b/src/compiler/symtab.c index 2bdd8918b..f2da0c806 100644 --- a/src/compiler/symtab.c +++ b/src/compiler/symtab.c @@ -320,7 +320,7 @@ void symtab_init(uint32_t capacity) kw_at_deprecated = KW_DEF("@deprecated"); kw_at_ensure = KW_DEF("@ensure"); - kw_at_enum_lookup = KW_DEF("@enum_lookup"); + kw_at_enum_lookup = KW_DEF("@enum_lookup_new"); kw_at_jump = KW_DEF("@jump"); kw_at_param = KW_DEF("@param"); kw_at_pure = KW_DEF("@pure"); diff --git a/test/test_suite/expressions/deref_access_null.c3t b/test/test_suite/expressions/deref_access_null.c3t index 2ebe621b1..ce7844c00 100644 --- a/test/test_suite/expressions/deref_access_null.c3t +++ b/test/test_suite/expressions/deref_access_null.c3t @@ -8,15 +8,15 @@ struct Foo float b; } -macro @offset_buggy($Type, #member) +macro @offset_buggy($Type, $member) { $Type *t = null; - return (usz)(uptr)&t.#member; + return (usz)(uptr)&t.$eval($member); } fn int main() { - usz a = @offset_buggy(Foo, b); + usz a = @offset_buggy(Foo, "b"); return (int)a; } diff --git a/test/test_suite/macros/hash_ident_nested.c3t b/test/test_suite/macros/hash_ident_nested.c3t index 8404a6d65..b7a4aeeb2 100644 --- a/test/test_suite/macros/hash_ident_nested.c3t +++ b/test/test_suite/macros/hash_ident_nested.c3t @@ -2,20 +2,20 @@ module test; fn void main() { - @foo(x); + @foo("x"); } struct Point { float x; float y; } -macro @foo(#x) +macro @foo(String $x) { - @bar(#x); + @bar($x); } -macro @bar(#x) +macro @bar($x) { Point pt; - var z = pt.#x; + var z = pt.$eval($x); } /* #expect: test.ll diff --git a/test/test_suite/macros/typed_hash_access.c3 b/test/test_suite/macros/typed_hash_access.c3 deleted file mode 100644 index a0cf3291e..000000000 --- a/test/test_suite/macros/typed_hash_access.c3 +++ /dev/null @@ -1,11 +0,0 @@ - -macro void @foo(int #a) -{ - var x = float.#a; // #error: cannot already be resolved -} - -fn void main() -{ - int inf; - @foo(inf); -} \ No newline at end of file