aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-08-08 13:44:57 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-08-08 13:44:57 -0400
commitbfa1d12fbad2031402fbafe51c3a0c481fe69351 (patch)
treeff1e8878a8f6dc8a7d70d0716b3ab1d94e51726d /src
parent8be95af48011f71f1902dff4ffbf5ea95cf1bcf4 (diff)
downloadzig-bfa1d12fbad2031402fbafe51c3a0c481fe69351.tar.gz
zig-bfa1d12fbad2031402fbafe51c3a0c481fe69351.zip
better compile errors when frame depends on itself
Diffstat (limited to 'src')
-rw-r--r--src/analyze.cpp11
-rw-r--r--src/ir.cpp12
-rw-r--r--src/ir.hpp2
3 files changed, 19 insertions, 6 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index aa5c3c88f7..cc90573f41 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -5179,11 +5179,14 @@ static Error resolve_coro_frame(CodeGen *g, ZigType *frame_type) {
if (fn->anal_state == FnAnalStateInvalid)
return ErrorSemanticAnalyzeFail;
break;
- case FnAnalStateProbing:
- add_node_error(g, fn->proto_node,
+ case FnAnalStateProbing: {
+ ErrorMsg *msg = add_node_error(g, fn->proto_node,
buf_sprintf("cannot resolve '%s': function not fully analyzed yet",
buf_ptr(&frame_type->name)));
+ ir_add_analysis_trace(fn->ir_executable.analysis, msg,
+ buf_sprintf("depends on its own frame here"));
return ErrorSemanticAnalyzeFail;
+ }
}
ZigType *fn_type = get_async_fn_type(g, fn->type_entry);
@@ -5201,8 +5204,10 @@ static Error resolve_coro_frame(CodeGen *g, ZigType *frame_type) {
if (callee->anal_state == FnAnalStateProbing) {
ErrorMsg *msg = add_node_error(g, fn->proto_node,
buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name)));
- add_error_note(g, msg, call->base.source_node,
+ ErrorMsg *note = add_error_note(g, msg, call->base.source_node,
buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name)));
+ ir_add_analysis_trace(callee->ir_executable.analysis, note,
+ buf_sprintf("depends on the frame here"));
return ErrorSemanticAnalyzeFail;
}
diff --git a/src/ir.cpp b/src/ir.cpp
index b2389d1501..f92434bb33 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -8217,18 +8217,24 @@ bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable);
}
-static void add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg *err_msg, int limit) {
+static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg *err_msg, int limit) {
if (!exec || !exec->source_node || limit < 0) return;
add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));
- add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1);
+ ir_add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1);
+}
+
+void ir_add_analysis_trace(IrAnalyze *ira, ErrorMsg *err_msg, Buf *text) {
+ IrInstruction *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
+ add_error_note(ira->codegen, err_msg, old_instruction->source_node, text);
+ ir_add_call_stack_errors(ira->codegen, ira->new_irb.exec, err_msg, 10);
}
static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg) {
invalidate_exec(exec);
ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
if (exec->parent_exec) {
- add_call_stack_errors(codegen, exec, err_msg, 10);
+ ir_add_call_stack_errors(codegen, exec, err_msg, 10);
}
return err_msg;
}
diff --git a/src/ir.hpp b/src/ir.hpp
index 597624e2e6..3761c5a97d 100644
--- a/src/ir.hpp
+++ b/src/ir.hpp
@@ -28,4 +28,6 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal
AstNode *source_node);
const char *float_op_to_name(BuiltinFnId op, bool llvm_name);
+void ir_add_analysis_trace(IrAnalyze *ira, ErrorMsg *err_msg, Buf *text);
+
#endif