Commit 7411a88d5f
Changed files (5)
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<ScopeElide *>(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();
+ }
+}
+
src/analyze.hpp
@@ -253,5 +253,6 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &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
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<ScopeElide *>(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);
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;
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