made #solidify better
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 7 Jan 2022 17:34:23 +0000 (11:34 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 7 Jan 2022 17:34:23 +0000 (11:34 -0600)
core/container/iter.onyx
scripts/run_tests.onyx
src/checker.c
src/polymorph.h
src/symres.c

index 6a328d8fda07ab2e1ea3ee3b2d28b99f49f194ba..0979e9e7600c213d1d3ff05620e8efd65064f86b 100644 (file)
@@ -546,7 +546,7 @@ distributor :: #match {}
     return distributor(as_iterator(it));
 }
 
-#match distributor (it: Iterator($T)) -> Iterator(T) {
+#match distributor (it: Iterator) -> Iterator(it.Iter_Type) {
     Context :: struct (T: type_expr) {
         mutex: sync.Mutex;
         iterator: Iterator(T);
@@ -570,11 +570,11 @@ distributor :: #match {}
         cfree(c);
     }
 
-    c := new(Context(T));
+    c := new(Context(it.Iter_Type));
     sync.mutex_init(^c.mutex);
     c.iterator = it;
 
-    return .{c, #solidify next {T=T}, #solidify close {T=T}};
+    return .{c, #solidify next {T=it.Iter_Type}, #solidify close {T=it.Iter_Type}};
 }
 
 parallel_for :: #match {}
index 609bea2f8553f0dd09a1ac41a06bbe0136a80fbf..2e8783ad52f9c0064c0273ca4913b62c02d711c3 100644 (file)
@@ -83,6 +83,9 @@ Settings :: struct {
 
     ["--tests"]
     test_folder := "./tests";
+
+    ["--compile-only"]
+    compile_only := false;
 }
 
 args_parse :: (c_args: [] cstr, output: ^Settings) -> bool {
@@ -146,8 +149,10 @@ main :: (args) => {
         // The executable to use when compiling
         onyx_cmd: str;
         at_least_one_test_failed := false;
+        compile_only := false;   @Bug // why is this necessary? why is settings.compile_only false when in the thread code?
     }
     exec_context := init(Execution_Context);
+    exec_context.compile_only = settings.compile_only;
 
     switch runtime.compiler_os {
         case .Linux {
@@ -163,11 +168,18 @@ main :: (args) => {
     iter.parallel_for(cases, settings.threads, ^exec_context) {
         // Weird macros mean I have to forward external names
         use package core
-        print_color :: print_color
-
-        printf("[{}]  Running test {}...\n", context.thread_id, it.source_file);
+        print_color :: print_color;
+
+        args: [] str;
+        if thread_data.compile_only {
+            printf("[{}]  Compiling test {}...\n", context.thread_id, it.source_file);
+            args = .[it.source_file];
+        } else {
+            printf("[{}]  Running test {}...\n", context.thread_id, it.source_file);
+            args = .["run", it.source_file];
+        }
 
-        proc := os.process_spawn(thread_data.onyx_cmd, .["run", it.source_file]);
+        proc := os.process_spawn(thread_data.onyx_cmd, args);
         defer os.process_destroy(^proc);
 
         proc_reader := io.reader_make(^proc);
@@ -181,6 +193,8 @@ main :: (args) => {
             continue;
         }
 
+        if thread_data.compile_only do continue;
+
         for expected_file: os.with_file(it.expected_file) {
             expected_reader := io.reader_make(expected_file);
             expected_output := io.read_all(^expected_reader);
index efcdf7623b7ebf9d145fd66bd176fb9c2fa9f320..63ef8a18d9526861ac02c3c54691f1202db95431 100644 (file)
@@ -103,6 +103,7 @@ CheckStatus check_memres_type(AstMemRes* memres);
 CheckStatus check_memres(AstMemRes* memres);
 CheckStatus check_type(AstType** ptype);
 CheckStatus check_insert_directive(AstDirectiveInsert** pinsert);
+CheckStatus check_directive_solidify(AstDirectiveSolidify** psolid);
 CheckStatus check_do_block(AstDoBlock** pdoblock);
 CheckStatus check_constraint(AstConstraint *constraint);
 CheckStatus check_constraint_context(ConstraintContext *cc, Scope *scope, OnyxFilePos pos);
@@ -463,9 +464,7 @@ CheckStatus check_argument(AstArgument** parg) {
 static CheckStatus check_resolve_callee(AstCall* call, AstTyped** effective_callee) {
     if (call->kind == Ast_Kind_Intrinsic_Call) return Check_Success;
 
-    call->callee = (AstTyped *) strip_aliases((AstNode *) call->callee);
-
-    AstTyped* callee = call->callee;
+    AstTyped* callee = (AstTyped *) strip_aliases((AstNode *) call->callee);
     b32 calling_a_macro = 0;
 
     if (callee->kind == Ast_Kind_Overloaded_Function) {
@@ -1777,7 +1776,7 @@ CheckStatus check_expression(AstTyped** pexpr) {
             break;
 
         case Ast_Kind_Directive_Solidify:
-            *pexpr = (AstTyped *) ((AstDirectiveSolidify *) expr)->resolved_proc;
+            CHECK(directive_solidify, (AstDirectiveSolidify **) pexpr);
             break;
 
         case Ast_Kind_Directive_Defined:
@@ -1884,6 +1883,32 @@ CheckStatus check_insert_directive(AstDirectiveInsert** pinsert) {
     return Check_Return_To_Symres;
 }
 
+CheckStatus check_directive_solidify(AstDirectiveSolidify** psolid) {
+    AstDirectiveSolidify* solid = *psolid;
+
+    bh_arr_each(AstPolySolution, sln, solid->known_polyvars) {
+        CHECK(expression, &sln->value);
+
+        if (node_is_type((AstNode *) sln->value)) {
+            sln->type = type_build_from_ast(context.ast_alloc, sln->ast_type);
+            sln->kind = PSK_Type;
+        } else {
+            sln->kind = PSK_Value;
+        }
+    }
+
+    solid->resolved_proc = polymorphic_proc_try_solidify(solid->poly_proc, solid->known_polyvars, solid->token);
+    if (solid->resolved_proc == (AstNode *) &node_that_signals_a_yield) {
+        solid->resolved_proc = NULL;
+        YIELD(solid->token->pos, "Waiting for partially solidified procedure.");
+    }
+
+    // NOTE: Not a DirectiveSolidify.
+    *psolid = (AstDirectiveSolidify *) solid->resolved_proc;
+
+    return Check_Success;
+}
+
 CheckStatus check_statement(AstNode** pstmt) {
     AstNode* stmt = *pstmt;
 
index 64ecbe0499d22e5975086220c0401353b11d6787..95781d771586bbfaea57d588dabae54f79836540 100644 (file)
@@ -758,9 +758,14 @@ AstNode* polymorphic_proc_try_solidify(AstFunction* pp, bh_arr(AstPolySolution)
         if (found_match) {
             valid_argument_count++;
         } else {
-            onyx_report_error(tkn->pos, Error_Critical, "'%b' is not a type variable of '%b'.",
-                sln->poly_sym->token->text, sln->poly_sym->token->length,
-                pp->token->text, pp->token->length);
+            if (pp->name) {
+                onyx_report_error(tkn->pos, Error_Critical, "'%b' is not a type variable of '%s'.",
+                    sln->poly_sym->token->text, sln->poly_sym->token->length, pp->name);
+            } else {
+                onyx_report_error(tkn->pos, Error_Critical, "'%b' is not a type variable of '%b'.",
+                    sln->poly_sym->token->text, sln->poly_sym->token->length,
+                    pp->token->text, pp->token->length);
+            }
             return (AstNode *) pp;
         }
     }
index 452fd877cad99ba4575c4cb9f1093cdde11fa1a2..dc00eff98ddc9cf67a56a8cd6aba194f629bae6e 100644 (file)
@@ -758,13 +758,7 @@ cannot_use:
 }
 
 static SymresStatus symres_directive_solidify(AstDirectiveSolidify** psolid) {
-    // @Cleanup: A lot of this code should move to the checker?
-    
     AstDirectiveSolidify* solid = *psolid;
-    if (solid->resolved_proc != NULL) {
-        *psolid = (AstDirectiveSolidify *) solid->resolved_proc;
-        return Symres_Success;
-    }
 
     SYMRES(expression, (AstTyped **) &solid->poly_proc);
     if (solid->poly_proc && solid->poly_proc->kind == Ast_Kind_Directive_Solidify) {
@@ -778,27 +772,12 @@ static SymresStatus symres_directive_solidify(AstDirectiveSolidify** psolid) {
         onyx_report_error(solid->token->pos, Error_Critical, "Expected polymorphic procedure in #solidify directive.");
         return Symres_Error;
     }
-
+    
     bh_arr_each(AstPolySolution, sln, solid->known_polyvars) {
         // HACK: This assumes that 'ast_type' and 'value' are at the same offset.
         SYMRES(expression, &sln->value);
-
-        if (node_is_type((AstNode *) sln->value)) {
-            sln->type = type_build_from_ast(context.ast_alloc, sln->ast_type);
-            sln->kind = PSK_Type;
-        } else {
-            sln->kind = PSK_Value;
-        }
-    }
-
-    solid->resolved_proc = polymorphic_proc_try_solidify(solid->poly_proc, solid->known_polyvars, solid->token);
-    if (solid->resolved_proc == (AstNode *) &node_that_signals_a_yield) {
-        solid->resolved_proc = NULL;
-        return Symres_Yield_Macro;
     }
 
-    // NOTE: Not a DirectiveSolidify.
-    *psolid = (AstDirectiveSolidify *) solid->resolved_proc;
     return Symres_Success;
 }