From 7411a88d5f8109ced238cf14205ae36575f02f21 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 11 Jun 2019 00:27:10 -0400 Subject: [PATCH] fix comptime function calls --- BRANCH_TODO | 4 ++-- src/analyze.cpp | 28 ++++++++++++++++++++++++++++ src/analyze.hpp | 1 + src/codegen.cpp | 28 ---------------------------- src/ir.cpp | 2 ++ 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/BRANCH_TODO b/BRANCH_TODO index f730eb64f..854b2c0ee 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -1,7 +1,7 @@ Scratch pad for stuff to do before merging master ================================================= +uncomment all the behavior tests + look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated return ir_gen_comptime(irb, scope, node, lval); - -comptime expressions diff --git a/src/analyze.cpp b/src/analyze.cpp index 0168dad6e..beaa9f148 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -7293,3 +7293,31 @@ void src_assert(bool ok, AstNode *source_node) { const char *msg = "assertion failed. This is a bug in the Zig compiler."; stage2_panic(msg, strlen(msg)); } + +bool scope_is_elided(Scope *scope) { + for (;;) { + switch (scope->id) { + case ScopeIdElide: + if (reinterpret_cast(scope)->activated) + return true; + // fallthrough + case ScopeIdBlock: + case ScopeIdDefer: + case ScopeIdDeferExpr: + case ScopeIdVarDecl: + case ScopeIdLoop: + case ScopeIdSuspend: + case ScopeIdCoroPrelude: + case ScopeIdRuntime: + scope = scope->parent; + continue; + case ScopeIdFnDef: + case ScopeIdCompTime: + case ScopeIdDecls: + case ScopeIdCImport: + return false; + } + zig_unreachable(); + } +} + diff --git a/src/analyze.hpp b/src/analyze.hpp index 2f3ec663d..2c5250d7e 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -253,5 +253,6 @@ void add_cc_args(CodeGen *g, ZigList &args, const char *out_dep_pa void src_assert(bool ok, AstNode *source_node); bool is_container(ZigType *type_entry); ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name); +bool scope_is_elided(Scope *scope); #endif diff --git a/src/codegen.cpp b/src/codegen.cpp index a75ef2916..7ee299aab 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -5709,34 +5709,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, zig_unreachable(); } -static bool scope_is_elided(Scope *scope) { - for (;;) { - switch (scope->id) { - case ScopeIdDecls: - case ScopeIdCompTime: - case ScopeIdCImport: - zig_unreachable(); - case ScopeIdElide: - if (reinterpret_cast(scope)->activated) - return true; - // fallthrough - case ScopeIdBlock: - case ScopeIdDefer: - case ScopeIdDeferExpr: - case ScopeIdVarDecl: - case ScopeIdLoop: - case ScopeIdSuspend: - case ScopeIdCoroPrelude: - case ScopeIdRuntime: - scope = scope->parent; - continue; - case ScopeIdFnDef: - return false; - } - zig_unreachable(); - } -} - static void ir_render(CodeGen *g, ZigFn *fn_entry) { assert(fn_entry); diff --git a/src/ir.cpp b/src/ir.cpp index 07df62fd0..1ea509745 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -8503,6 +8503,8 @@ static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec IrBasicBlock *bb = exec->basic_block_list.at(0); for (size_t i = 0; i < bb->instruction_list.length; i += 1) { IrInstruction *instruction = bb->instruction_list.at(i); + if (scope_is_elided(instruction->scope)) + continue; if (instruction->id == IrInstructionIdReturn) { IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction; IrInstruction *value = ret_inst->value;