| ... | ... | @@ -5197,6 +5197,27 @@ static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) { |
| 5197 | 5197 | return fn_type; |
| 5198 | 5198 | } |
| 5199 | 5199 | |
| 5200 | static void emit_error_notes_for_type_loop(CodeGen *g, ErrorMsg *msg, ZigType *stop_type, |
| 5201 | ZigType *ty, AstNode *src_node) |
| 5202 | { |
| 5203 | ErrorMsg *note = add_error_note(g, msg, src_node, |
| 5204 | buf_sprintf("when analyzing type '%s' here", buf_ptr(&ty->name))); |
| 5205 | if (ty == stop_type) |
| 5206 | return; |
| 5207 | switch (ty->id) { |
| 5208 | case ZigTypeIdFnFrame: { |
| 5209 | ty->data.frame.reported_loop_err = true; |
| 5210 | ZigType *depending_type = ty->data.frame.resolve_loop_type; |
| 5211 | if (depending_type == nullptr) |
| 5212 | return; |
| 5213 | emit_error_notes_for_type_loop(g, note, stop_type, |
| 5214 | depending_type, ty->data.frame.resolve_loop_src_node); |
| 5215 | } |
| 5216 | default: |
| 5217 | return; |
| 5218 | } |
| 5219 | } |
| 5220 | |
| 5200 | 5221 | static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5201 | 5222 | Error err; |
| 5202 | 5223 | |
| ... | ... | @@ -5206,6 +5227,20 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5206 | 5227 | ZigFn *fn = frame_type->data.frame.fn; |
| 5207 | 5228 | assert(!fn->type_entry->data.fn.is_generic); |
| 5208 | 5229 | |
| 5230 | if (frame_type->data.frame.resolve_loop_type != nullptr) { |
| 5231 | if (!frame_type->data.frame.reported_loop_err) { |
| 5232 | frame_type->data.frame.reported_loop_err = true; |
| 5233 | ErrorMsg *msg = add_node_error(g, fn->proto_node, |
| 5234 | buf_sprintf("'%s' depends on itself", buf_ptr(&frame_type->name))); |
| 5235 | emit_error_notes_for_type_loop(g, msg, |
| 5236 | frame_type, |
| 5237 | frame_type->data.frame.resolve_loop_type, |
| 5238 | frame_type->data.frame.resolve_loop_src_node); |
| 5239 | emit_error_notes_for_ref_stack(g, msg); |
| 5240 | } |
| 5241 | return ErrorSemanticAnalyzeFail; |
| 5242 | } |
| 5243 | |
| 5209 | 5244 | switch (fn->anal_state) { |
| 5210 | 5245 | case FnAnalStateInvalid: |
| 5211 | 5246 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -5299,6 +5334,10 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5299 | 5334 | return ErrorSemanticAnalyzeFail; |
| 5300 | 5335 | } |
| 5301 | 5336 | |
| 5337 | ZigType *callee_frame_type = get_fn_frame_type(g, callee); |
| 5338 | frame_type->data.frame.resolve_loop_type = callee_frame_type; |
| 5339 | frame_type->data.frame.resolve_loop_src_node = call->base.source_node; |
| 5340 | |
| 5302 | 5341 | analyze_fn_body(g, callee); |
| 5303 | 5342 | if (callee->anal_state == FnAnalStateInvalid) { |
| 5304 | 5343 | frame_type->data.frame.locals_struct = g->builtin_types.entry_invalid; |
| ... | ... | @@ -5308,8 +5347,6 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5308 | 5347 | if (!fn_is_async(callee)) |
| 5309 | 5348 | continue; |
| 5310 | 5349 | |
| 5311 | | ZigType *callee_frame_type = get_fn_frame_type(g, callee); |
| 5312 | | |
| 5313 | 5350 | IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1); |
| 5314 | 5351 | alloca_gen->base.id = IrInstructionIdAllocaGen; |
| 5315 | 5352 | alloca_gen->base.source_node = call->base.source_node; |
| ... | ... | @@ -5378,9 +5415,13 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5378 | 5415 | continue; |
| 5379 | 5416 | } |
| 5380 | 5417 | } |
| 5418 | |
| 5419 | frame_type->data.frame.resolve_loop_type = child_type; |
| 5420 | frame_type->data.frame.resolve_loop_src_node = instruction->base.source_node; |
| 5381 | 5421 | if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) { |
| 5382 | 5422 | return err; |
| 5383 | 5423 | } |
| 5424 | |
| 5384 | 5425 | const char *name; |
| 5385 | 5426 | if (*instruction->name_hint == 0) { |
| 5386 | 5427 | name = buf_ptr(buf_sprintf("@local%" ZIG_PRI_usize, alloca_i)); |