From: Brendan Hansen Date: Thu, 16 Dec 2021 03:53:43 +0000 (-0600) Subject: made '<<' work for heaps; better overload robustness X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=6bf443480ae40ae9b4c9d3c022e848cacc54a2ce;p=onyx.git made '<<' work for heaps; better overload robustness --- diff --git a/include/astnodes.h b/include/astnodes.h index b43811b0..04c18923 100644 --- a/include/astnodes.h +++ b/include/astnodes.h @@ -1645,7 +1645,7 @@ void report_unable_to_match_overload(AstCall* call); void expand_macro(AstCall** pcall, AstFunction* template); AstFunction* macro_resolve_header(AstMacro* macro, Arguments* args, OnyxToken* callsite, b32 error_if_failed); -Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySolution) slns, OnyxFilePos pos); +Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySolution) slns, OnyxFilePos pos, b32 error_if_failed); // NOTE: Useful inlined functions static inline b32 is_lval(AstNode* node) { diff --git a/src/checker.c b/src/checker.c index 36f6f9a2..73c3fe3d 100644 --- a/src/checker.c +++ b/src/checker.c @@ -2032,7 +2032,7 @@ CheckStatus check_struct(AstStructType* s_node) { YIELD(s_node->token->pos, "Waiting for struct member defaults to pass symbol resolution."); if (s_node->constraints.constraints) { - s_node->constraints.produce_errors = 1; + s_node->constraints.produce_errors = (s_node->flags & Ast_Flag_Header_Check_No_Error) == 0; CHECK(constraint_context, &s_node->constraints, s_node->scope, s_node->token->pos); } @@ -2179,14 +2179,15 @@ CheckStatus check_function_header(AstFunction* func) { expect_default_param = 1; } - if (local->type_node != NULL) CHECK(type, local->type_node); + if (local->type_node != NULL) { + // If the function has the no_error flag, then the type node should have it set too. + // This allows for polymorphic structures with constraints to fail gracefully. + local->type_node->flags |= (func->flags & Ast_Flag_Header_Check_No_Error); + CHECK(type, local->type_node); + } fill_in_type((AstTyped *) local); if (local->type == NULL) { - // onyx_report_error(param->local->token->pos, - // "Unable to resolve type for parameter, '%b'", - // local->token->text, - // local->token->length); YIELD(local->token->pos, "Waiting for parameter type to be known."); } @@ -2613,9 +2614,14 @@ CheckStatus check_constraint_context(ConstraintContext *cc, Scope *scope, OnyxFi onyx_report_error(constraint->exprs[constraint->expr_idx]->token->pos, "Failed to satisfy constraint where %s.", constraint_map); onyx_report_error(constraint->token->pos, "Here is where the interface was used."); - } - return Check_Error; + return Check_Error; + + } else { + // If no error are suppose to be produced, we still need to signal that + // the node reached a completed state. + return Check_Failed; + } } if (cc->constraint_checks[i] == Constraint_Check_Status_Queued) { diff --git a/src/polymorph.h b/src/polymorph.h index 23c8cc24..b1b5c6c3 100644 --- a/src/polymorph.h +++ b/src/polymorph.h @@ -890,7 +890,7 @@ char* build_poly_struct_name(AstPolyStructType* ps_type, Type* cs_type) { return bh_aprintf(global_heap_allocator, "%s", name_buf); } -Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySolution) slns, OnyxFilePos pos) { +Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySolution) slns, OnyxFilePos pos, b32 error_if_failed) { // @Cleanup assert(ps_type->scope != NULL); @@ -910,7 +910,7 @@ Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySoluti i32 i = 0; bh_arr_each(AstPolySolution, sln, slns) { sln->poly_sym = (AstNode *) &ps_type->poly_params[i]; - + PolySolutionKind expected_kind = PSK_Undefined; if ((AstNode *) ps_type->poly_params[i].type_node == (AstNode *) &basic_type_type_expr) { expected_kind = PSK_Type; @@ -974,6 +974,7 @@ Type* polymorphic_struct_lookup(AstPolyStructType* ps_type, bh_arr(AstPolySoluti insert_poly_slns_into_scope(sln_scope, slns); AstStructType* concrete_struct = (AstStructType *) ast_clone(context.ast_alloc, ps_type->base_struct); + BH_MASK_SET(concrete_struct->flags, !error_if_failed, Ast_Flag_Header_Check_No_Error); shput(ps_type->concrete_structs, unique_key, concrete_struct); add_entities_for_node(NULL, (AstNode *) concrete_struct, sln_scope, NULL); diff --git a/src/types.c b/src/types.c index 3cf40a3c..ca2bb4d5 100644 --- a/src/types.c +++ b/src/types.c @@ -589,7 +589,7 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) { } } - Type* concrete = polymorphic_struct_lookup(ps_type, slns, pc_type->token->pos); + Type* concrete = polymorphic_struct_lookup(ps_type, slns, pc_type->token->pos, (pc_type->flags & Ast_Flag_Header_Check_No_Error) == 0); // This should be copied in the previous function. // CLEANUP: Maybe don't copy it and just use this one since it is allocated on the heap? diff --git a/tests/aoc-2021/day15.onyx b/tests/aoc-2021/day15.onyx index a9a869a3..7b1e641d 100644 --- a/tests/aoc-2021/day15.onyx +++ b/tests/aoc-2021/day15.onyx @@ -28,7 +28,7 @@ main :: (args) => { to_try := heap.make(queued, (x, y) => x.cost - y.cost); tried := set.make(pos); - heap.insert(^to_try, .{ 0, 0, -cast(i32) (cells[0] - #char "0") }); + to_try << .{ 0, 0, -cast(i32) (cells[0] - #char "0") }; minimum := 0; while to_try.data.count != 0 { @@ -50,7 +50,7 @@ main :: (args) => { if found := array.find_ptr(to_try.data, .{try.x + dx, try.y + dy, 0}); found != null { found.cost = math.min(cell_value, found.cost); } else { - heap.insert(^to_try, .{try.x + dx, try.y + dy, cell_value }); + to_try << .{try.x + dx, try.y + dy, cell_value }; } } }