From b025193de5b951734e5108e4762e5dc40359431b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 17 Jun 2019 13:31:19 -0400 Subject: inferred comptime values rather than elided scopes because of this example: ```zig export fn entry(b: bool) usize { var runtime = [1]i32{3}; comptime var i: usize = 0; inline while (i < 2) : (i += 1) { const result = if (i == 0) [1]i32{2} else runtime; } comptime { return i; } } ``` The problem is that the concept of "resetting" a result location, introduced in the previous commit, cannot handle elision scopes. This concept is inherently broken with inline loops. --- src/analyze.cpp | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 1f9b1ffbed..b39b1e35ca 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -166,12 +166,6 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruct return &scope->base; } -ScopeElide *create_elide_scope(CodeGen *g, AstNode *node, Scope *parent) { - ScopeElide *scope = allocate(1); - init_scope(g, &scope->base, ScopeIdElide, node, parent); - return scope; -} - ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent) { assert(node->type == NodeTypeSuspend); ScopeSuspend *scope = allocate(1); @@ -4187,6 +4181,7 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) { case ConstPtrMutComptimeConst: hash_val += (uint32_t)4214318515; break; + case ConstPtrMutInfer: case ConstPtrMutComptimeVar: hash_val += (uint32_t)1103195694; break; @@ -7286,31 +7281,3 @@ 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(); - } -} - -- cgit v1.2.3