changed how '#defined' works to be more reliable
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 22 May 2022 21:04:21 +0000 (16:04 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 22 May 2022 21:04:21 +0000 (16:04 -0500)
include/astnodes.h
src/onyx.c
src/symres.c

index d0cdca9f20bab6b47e08f1e3d98c35cbb09092cf..b337faa49e518d58e8038efa298a0cb641db156c 100644 (file)
@@ -1534,6 +1534,7 @@ struct Context {
     // NOTE: This is defined in onyxwasm.h
     struct OnyxWasmModule* wasm_module;
 
+    b32 cycle_almost_detected : 1;
     b32 cycle_detected : 1;
 };
 
index c73d01efe83a0449cd595553ef46247251fce420..4343c816fa397b057db8c28bd318ca5f8f05a5e7 100644 (file)
@@ -234,6 +234,7 @@ static void context_init(CompileOptions* opts) {
 
     context.options = opts;
     context.cycle_detected = 0;
+    context.cycle_almost_detected = 0;
 
     OnyxFilePos internal_location = { 0 };
     internal_location.filename = "<compiler internal>";
@@ -607,7 +608,12 @@ static i32 onyx_compile() {
             else if (watermarked_node == ent) {
                 if (ent->macro_attempts > highest_watermark) {
                     entity_heap_insert_existing(&context.entities, ent);
-                    dump_cycles();
+
+                    if (context.cycle_almost_detected) {
+                        dump_cycles();
+                    } else {
+                        context.cycle_almost_detected = 1;
+                    }
                 }
             }
             else if (watermarked_node->macro_attempts < ent->macro_attempts) {
@@ -616,6 +622,7 @@ static i32 onyx_compile() {
             }
         } else {
             watermarked_node = NULL;
+            context.cycle_almost_detected = 0;
         }
 
         if (onyx_has_errors()) return ONYX_COMPILER_PROGRESS_ERROR;
index 5b3ea1bb9bb2e64057fca68858749e881127e5a7..ad71c40eaae90d28a646e3b440cc6e148c0bbfc8 100644 (file)
@@ -899,11 +899,11 @@ static SymresStatus symres_directive_solidify(AstDirectiveSolidify** psolid) {
 static SymresStatus symres_directive_defined(AstDirectiveDefined** pdefined) {
     AstDirectiveDefined* defined = *pdefined;
 
-    b32 use_package_count = (context.entities.type_count[Entity_Type_Use_Package] == 0);
+    b32 has_to_be_resolved = context.cycle_almost_detected;
 
     resolved_a_symbol = 0;
     SymresStatus ss = symres_expression(&defined->expr);
-    if (use_package_count && ss != Symres_Success && !resolved_a_symbol) {
+    if (has_to_be_resolved && ss != Symres_Success && !resolved_a_symbol) {
         // The symbol definitely was not found and there is no chance that it could be found.
         defined->is_defined = 0;
         return Symres_Success;