renamed core.hash.to_u32 to core.hash.hash
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 7 Feb 2023 21:14:27 +0000 (15:14 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 7 Feb 2023 21:14:27 +0000 (15:14 -0600)
compiler/src/symres.c
core/hash/hash.onyx

index bbd01ace524731b27fe3b830d8db8dc71e0976dc..1ed93a935dcc6bff5895994dca77312aa4cef380 100644 (file)
@@ -1381,12 +1381,21 @@ static SymresStatus symres_process_directive(AstNode* directive) {
             SYMRES(expression, (AstTyped **) &add_overload->overloaded_function);
             if (add_overload->overloaded_function == NULL) return Symres_Error; // NOTE: Error message will already be generated
 
-            if (add_overload->overloaded_function->kind != Ast_Kind_Overloaded_Function) {
+            AstOverloadedFunction *ofunc = (AstOverloadedFunction *) strip_aliases((AstNode *) add_overload->overloaded_function);
+            if (ofunc->kind == Ast_Kind_Symbol) {
+                if (context.cycle_detected) {
+                    onyx_report_error(add_overload->token->pos, Error_Waiting_On, "Waiting for matched procedure to be known.");
+                    return Symres_Error;
+                }
+
+                return Symres_Yield_Macro;
+            }
+
+            if (ofunc->kind != Ast_Kind_Overloaded_Function) {
                 onyx_report_error(add_overload->token->pos, Error_Critical, "#match directive expects a matched procedure.");
                 return Symres_Error;
             }
 
-            AstOverloadedFunction* ofunc = (AstOverloadedFunction *) add_overload->overloaded_function;
             if (ofunc->locked) {
                 onyx_report_error(add_overload->token->pos, Error_Critical, "Cannot add match option here as the original #match was declared as #locked.");
                 onyx_report_error(ofunc->token->pos, Error_Critical, "Here is the original #match.");
index 9ab6333f5aae22eba5fd5ba2cabad6605c6903a7..1208f6dcbcac4ac7c46ea647089e8c13e52babc3 100644 (file)
@@ -1,6 +1,25 @@
 package core.hash
 
-to_u32 :: #match -> u32 {
+//
+// DEPRECATED: to_u32 is the old name that kind of
+// makes sense, but is a little unintuitive. Use
+// core.hash.hash instead.
+to_u32 :: hash
+
+//
+// This overloaded procedure defines how to hash something.
+// It is used throughout the standard library to hash values.
+// There are many overloads to it in the standard library, and
+// more can be added using #overload. Or, a hash method can be
+// defined for a structure or distinct type.
+//
+//     Person :: struct {
+//         hash :: (p: Person) {
+//             return // ...
+//         }
+//     }
+
+hash :: #match -> u32 {
     // Does this need to have a higher precedence value?
     // Because if I wanted to have a custom type as the key
     // of a map that only looks at some of the members of the
@@ -26,7 +45,7 @@ to_u32 :: #match -> u32 {
 }
 
 Hashable :: interface (t: $T) {
-    { to_u32(t) } -> u32;
+    { hash(t) } -> u32;
 }
 
 #local