authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-11 00:27:10-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-11 00:27:10-04:00
log7411a88d5f8109ced238cf14205ae36575f02f21
treec61dd9c7a046e113509dc96c8a1bd42d57ce21dc
parent33371ab55c01d896b91df13eafe6e5c601400a07
signature Commit is signed but in an unrecognized format.

fix comptime function calls


5 files changed, 33 insertions(+), 30 deletions(-)

BRANCH_TODO+2-2
......@@ -1,7 +1,7 @@
11Scratch pad for stuff to do before merging master
22=================================================
33
4uncomment all the behavior tests
5
46look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated
57 return ir_gen_comptime(irb, scope, node, lval);
6
7comptime expressions
src/analyze.cpp+28
......@@ -7293,3 +7293,31 @@ void src_assert(bool ok, AstNode *source_node) {
72937293 const char *msg = "assertion failed. This is a bug in the Zig compiler.";
72947294 stage2_panic(msg, strlen(msg));
72957295}
7296
7297bool scope_is_elided(Scope *scope) {
7298 for (;;) {
7299 switch (scope->id) {
7300 case ScopeIdElide:
7301 if (reinterpret_cast<ScopeElide *>(scope)->activated)
7302 return true;
7303 // fallthrough
7304 case ScopeIdBlock:
7305 case ScopeIdDefer:
7306 case ScopeIdDeferExpr:
7307 case ScopeIdVarDecl:
7308 case ScopeIdLoop:
7309 case ScopeIdSuspend:
7310 case ScopeIdCoroPrelude:
7311 case ScopeIdRuntime:
7312 scope = scope->parent;
7313 continue;
7314 case ScopeIdFnDef:
7315 case ScopeIdCompTime:
7316 case ScopeIdDecls:
7317 case ScopeIdCImport:
7318 return false;
7319 }
7320 zig_unreachable();
7321 }
7322}
7323
src/analyze.hpp+1
......@@ -253,5 +253,6 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
253253void src_assert(bool ok, AstNode *source_node);
254254bool is_container(ZigType *type_entry);
255255ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name);
256bool scope_is_elided(Scope *scope);
256257
257258#endif
src/codegen.cpp-28
......@@ -5709,34 +5709,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
57095709 zig_unreachable();
57105710}
57115711
5712static bool scope_is_elided(Scope *scope) {
5713 for (;;) {
5714 switch (scope->id) {
5715 case ScopeIdDecls:
5716 case ScopeIdCompTime:
5717 case ScopeIdCImport:
5718 zig_unreachable();
5719 case ScopeIdElide:
5720 if (reinterpret_cast<ScopeElide *>(scope)->activated)
5721 return true;
5722 // fallthrough
5723 case ScopeIdBlock:
5724 case ScopeIdDefer:
5725 case ScopeIdDeferExpr:
5726 case ScopeIdVarDecl:
5727 case ScopeIdLoop:
5728 case ScopeIdSuspend:
5729 case ScopeIdCoroPrelude:
5730 case ScopeIdRuntime:
5731 scope = scope->parent;
5732 continue;
5733 case ScopeIdFnDef:
5734 return false;
5735 }
5736 zig_unreachable();
5737 }
5738}
5739
57405712static void ir_render(CodeGen *g, ZigFn *fn_entry) {
57415713 assert(fn_entry);
57425714
src/ir.cpp+2
......@@ -8503,6 +8503,8 @@ static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec
85038503 IrBasicBlock *bb = exec->basic_block_list.at(0);
85048504 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
85058505 IrInstruction *instruction = bb->instruction_list.at(i);
8506 if (scope_is_elided(instruction->scope))
8507 continue;
85068508 if (instruction->id == IrInstructionIdReturn) {
85078509 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;
85088510 IrInstruction *value = ret_inst->value;