diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-07-05 14:07:36 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-07-05 14:07:36 -0700 |
| commit | 0ff9a4d21c1b65c574659be295446f2dd7591723 (patch) | |
| tree | f9e68028c1ac06222194b00015fd741f7dae4f27 /src/stage1/ir.cpp | |
| parent | 0e5fa87ac9695378683e770fbe0d577521860d35 (diff) | |
| download | zig-0ff9a4d21c1b65c574659be295446f2dd7591723.tar.gz zig-0ff9a4d21c1b65c574659be295446f2dd7591723.zip | |
stage1: resolve lazy values before comptime fn call
Diffstat (limited to 'src/stage1/ir.cpp')
| -rw-r--r-- | src/stage1/ir.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index b5dbdd3c21..062750225d 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -12754,6 +12754,29 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, Scope *scope, AstNode *sour bool cacheable = fn_eval_cacheable(exec_scope, return_type); ZigValue *result = nullptr; if (cacheable) { + // We are about to put ZigValues into a hash map. The hash of a lazy value and a + // fully resolved value must equal, and so we must resolve the lazy values here. + // The hash function asserts that none of the values are lazy. + { + Scope *scope = exec_scope; + while (scope) { + if (scope->id == ScopeIdVarDecl) { + ScopeVarDecl *var_scope = (ScopeVarDecl *)scope; + if ((err = ir_resolve_lazy_recurse(ira, + var_scope->var->decl_node, + var_scope->var->const_value))) + { + return ira->codegen->invalid_inst_gen; + } + } else if (scope->id == ScopeIdFnDef) { + break; + } else { + zig_unreachable(); + } + scope = scope->parent; + } + } + auto entry = ira->codegen->memoized_fn_eval_table.maybe_get(exec_scope); if (entry) result = entry->value; @@ -25558,7 +25581,7 @@ static Error ir_resolve_lazy_recurse(IrAnalyze *ira, AstNode *source_node, ZigVa // This shouldn't be possible, it indicates an ICE. // NO_COMMIT ir_add_error_node(ira, source_node, - buf_sprintf("This is a bug in the Zig compiler. Runtime value found in comptime known parameter.")); + buf_sprintf("This is a bug in the Zig compiler. Runtime value found in comptime known value.")); return ErrorSemanticAnalyzeFail; } if (val->special != ConstValSpecialStatic) |
