From 262e09c482d98a78531c049a18b7f24146fe157f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 12 Apr 2021 15:54:28 -0700 Subject: [PATCH] stage1: resolve builtin types and values via std.builtin rather than via `@import("builtin")`. This helps avoid the need for `usingnamespace` used in builtin.zig or in std.builtin. --- src/stage1/all_types.hpp | 1 + src/stage1/analyze.cpp | 8 ++++++-- src/stage1/codegen.cpp | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/stage1/all_types.hpp b/src/stage1/all_types.hpp index 9085acd557..6cd28f4bbc 100644 --- a/src/stage1/all_types.hpp +++ b/src/stage1/all_types.hpp @@ -2077,6 +2077,7 @@ struct CodeGen { ZigType *compile_var_import; ZigType *root_import; ZigType *start_import; + ZigType *std_builtin_import; struct { ZigType *entry_bool; diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index d7535ed806..21ad55b8f7 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -8185,14 +8185,18 @@ bool err_ptr_eql(const ErrorTableEntry *a, const ErrorTableEntry *b) { } ZigValue *get_builtin_value(CodeGen *codegen, const char *name) { - ScopeDecls *builtin_scope = get_container_scope(codegen->compile_var_import); - Tld *tld = find_container_decl(codegen, builtin_scope, buf_create_from_str(name)); + Buf *buf_name = buf_create_from_str(name); + + ScopeDecls *builtin_scope = get_container_scope(codegen->std_builtin_import); + Tld *tld = find_container_decl(codegen, builtin_scope, buf_name); assert(tld != nullptr); resolve_top_level_decl(codegen, tld, nullptr, false); assert(tld->id == TldIdVar && tld->resolution == TldResolutionOk); TldVar *tld_var = (TldVar *)tld; ZigValue *var_value = tld_var->var->const_value; assert(var_value != nullptr); + + buf_destroy(buf_name); return var_value; } diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index 6e966fe75d..1dec1f8b27 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -9495,9 +9495,9 @@ static void gen_root_source(CodeGen *g) { TldVar *builtin_tld_var = (TldVar*)builtin_tld; ZigValue *builtin_val = builtin_tld_var->var->const_value; assert(builtin_val->type->id == ZigTypeIdMetaType); - ZigType *builtin_type = builtin_val->data.x_type; + g->std_builtin_import = builtin_val->data.x_type; - Tld *panic_tld = find_decl(g, &get_container_scope(builtin_type)->base, + Tld *panic_tld = find_decl(g, &get_container_scope(g->std_builtin_import)->base, buf_create_from_str("panic")); assert(panic_tld != nullptr); resolve_top_level_decl(g, panic_tld, nullptr, false);