diff --git a/doc/langref.html.in b/doc/langref.html.in
index 9dc0a31b23b3..a78b073a25a6 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -6785,7 +6785,6 @@ pub const TypeId = enum {
Enum,
Union,
Fn,
- Namespace,
Block,
BoundFn,
ArgTuple,
@@ -6820,7 +6819,6 @@ pub const TypeInfo = union(TypeId) {
Enum: Enum,
Union: Union,
Fn: Fn,
- Namespace: void,
BoundFn: Fn,
ArgTuple: void,
Opaque: void,
@@ -8167,17 +8165,18 @@ coding style.
-
- If {#syntax#}x{#endsyntax#} is a {#syntax#}struct{#endsyntax#} (or an alias of a {#syntax#}struct{#endsyntax#}),
- then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}.
+ If {#syntax#}x{#endsyntax#} is a {#syntax#}type{#endsyntax#}
+ then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}, unless it
+ is a {#syntax#}struct{#endsyntax#} with 0 fields and is never meant to be instantiated,
+ in which case it is considered to be a "namespace" and uses {#syntax#}snake_case{#end_syntax#}.
-
- If {#syntax#}x{#endsyntax#} otherwise identifies a type, {#syntax#}x{#endsyntax#} should have {#syntax#}snake_case{#endsyntax#}.
+ If {#syntax#}x{#endsyntax#} is callable, and {#syntax#}x{#endsyntax#}'s return type is
+ {#syntax#}type{#endsyntax#}, then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}.
-
- If {#syntax#}x{#endsyntax#} is callable, and {#syntax#}x{#endsyntax#}'s return type is {#syntax#}type{#endsyntax#}, then {#syntax#}x{#endsyntax#} should be {#syntax#}TitleCase{#endsyntax#}.
-
- -
- If {#syntax#}x{#endsyntax#} is otherwise callable, then {#syntax#}x{#endsyntax#} should be {#syntax#}camelCase{#endsyntax#}.
+ If {#syntax#}x{#endsyntax#} is otherwise callable, then {#syntax#}x{#endsyntax#} should
+ be {#syntax#}camelCase{#endsyntax#}.
-
Otherwise, {#syntax#}x{#endsyntax#} should be {#syntax#}snake_case{#endsyntax#}.
@@ -8203,7 +8202,9 @@ const const_name = 42;
const primitive_type_alias = f32;
const string_alias = []u8;
-const StructName = struct {};
+const StructName = struct {
+ field: i32,
+};
const StructAlias = StructName;
fn functionName(param_name: TypeName) void {
@@ -8231,7 +8232,9 @@ const xml_document =
\\
\\
;
-const XmlParser = struct {};
+const XmlParser = struct {
+ field: i32,
+};
// The initials BE (Big Endian) are just another word in Zig identifier names.
fn readU32Be() u32 {}
diff --git a/src-self-hosted/type.zig b/src-self-hosted/type.zig
index 7d611bb78793..4c9fb58a18fd 100644
--- a/src-self-hosted/type.zig
+++ b/src-self-hosted/type.zig
@@ -39,7 +39,6 @@ pub const Type = struct {
Id.ErrorSet => @fieldParentPtr(ErrorSet, "base", base).destroy(comp),
Id.Enum => @fieldParentPtr(Enum, "base", base).destroy(comp),
Id.Union => @fieldParentPtr(Union, "base", base).destroy(comp),
- Id.Namespace => @fieldParentPtr(Namespace, "base", base).destroy(comp),
Id.BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp),
Id.ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp),
Id.Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp),
@@ -73,7 +72,6 @@ pub const Type = struct {
Id.ErrorSet => return @fieldParentPtr(ErrorSet, "base", base).getLlvmType(allocator, llvm_context),
Id.Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context),
Id.Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context),
- Id.Namespace => unreachable,
Id.BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context),
Id.ArgTuple => unreachable,
Id.Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context),
@@ -89,7 +87,6 @@ pub const Type = struct {
Id.ComptimeInt,
Id.Undefined,
Id.Null,
- Id.Namespace,
Id.BoundFn,
Id.ArgTuple,
Id.Opaque,
@@ -123,7 +120,6 @@ pub const Type = struct {
Id.ComptimeInt,
Id.Undefined,
Id.Null,
- Id.Namespace,
Id.BoundFn,
Id.ArgTuple,
Id.Opaque,
@@ -1020,14 +1016,6 @@ pub const Type = struct {
}
};
- pub const Namespace = struct {
- base: Type,
-
- pub fn destroy(self: *Namespace, comp: *Compilation) void {
- comp.gpa().destroy(self);
- }
- };
-
pub const BoundFn = struct {
base: Type,
diff --git a/src/all_types.hpp b/src/all_types.hpp
index 902c6e13c234..e094f0f8eb6e 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -21,7 +21,6 @@
#include "libc_installation.hpp"
struct AstNode;
-struct ImportTableEntry;
struct ZigFn;
struct Scope;
struct ScopeBlock;
@@ -317,7 +316,6 @@ struct ConstExprValue {
ConstUnionValue x_union;
ConstArrayValue x_array;
ConstPtrValue x_ptr;
- ImportTableEntry *x_import;
ConstArgTuple x_arg_tuple;
// populated if special == ConstValSpecialRuntime
@@ -369,7 +367,7 @@ struct Tld {
VisibMod visib_mod;
AstNode *source_node;
- ImportTableEntry *import;
+ ZigType *import;
Scope *parent_scope;
// set this flag temporarily to detect infinite loops
bool dep_loop_flag;
@@ -937,7 +935,7 @@ struct AstNode {
enum NodeType type;
size_t line;
size_t column;
- ImportTableEntry *owner;
+ ZigType *owner;
union {
AstNodeFnDef fn_def;
AstNodeFnProto fn_proto;
@@ -1075,12 +1073,32 @@ enum ResolveStatus {
ResolveStatusSizeKnown,
};
+struct ZigPackage {
+ Buf root_src_dir;
+ Buf root_src_path; // relative to root_src_dir
+
+ // reminder: hash tables must be initialized before use
+ HashMap package_table;
+};
+
+// Stuff that only applies to a struct which is the implicit root struct of a file
+struct RootStruct {
+ ZigPackage *package;
+ Buf *path; // relative to root_package->root_src_dir
+ ZigList *line_offsets;
+ Buf *source_code;
+ AstNode *c_import_node;
+ ZigLLVMDIFile *di_file;
+ bool scanned;
+};
+
struct ZigTypeStruct {
AstNode *decl_node;
TypeStructField *fields;
ScopeDecls *decls_scope;
uint64_t size_bytes;
HashMap fields_by_name;
+ RootStruct *root_struct;
uint32_t src_field_count;
uint32_t gen_field_count;
@@ -1232,7 +1250,6 @@ enum ZigTypeId {
ZigTypeIdEnum,
ZigTypeIdUnion,
ZigTypeIdFn,
- ZigTypeIdNamespace,
ZigTypeIdBoundFn,
ZigTypeIdArgTuple,
ZigTypeIdOpaque,
@@ -1285,29 +1302,6 @@ struct ZigType {
bool gen_h_loop_flag;
};
-struct PackageTableEntry {
- Buf root_src_dir;
- Buf root_src_path; // relative to root_src_dir
-
- // reminder: hash tables must be initialized before use
- HashMap package_table;
-};
-
-struct ImportTableEntry {
- AstNode *root;
- Buf *path; // relative to root_package->root_src_dir
- PackageTableEntry *package;
- ZigLLVMDIFile *di_file;
- Buf *source_code;
- ZigList *line_offsets;
- ScopeDecls *decls_scope;
- AstNode *c_import_node;
- bool any_imports_failed;
- bool scanned;
-
- ZigList use_decls;
-};
-
enum FnAnalState {
FnAnalStateReady,
FnAnalStateProbing,
@@ -1670,7 +1664,7 @@ struct CodeGen {
LLVMValueRef return_err_fn;
// reminder: hash tables must be initialized before use
- HashMap import_table;
+ HashMap import_table;
HashMap builtin_fn_table;
HashMap primitive_type_table;
HashMap type_table;
@@ -1684,7 +1678,7 @@ struct CodeGen {
HashMap string_literals_table;
HashMap type_info_cache;
- ZigList import_queue;
+ ZigList import_queue;
size_t import_queue_index;
ZigList resolve_queue;
size_t resolve_queue_index;
@@ -1699,14 +1693,14 @@ struct CodeGen {
ZigList errors_by_index;
size_t largest_err_name_len;
- PackageTableEntry *std_package;
- PackageTableEntry *panic_package;
- PackageTableEntry *test_runner_package;
- PackageTableEntry *compile_var_package;
- ImportTableEntry *compile_var_import;
- ImportTableEntry *root_import;
- ImportTableEntry *bootstrap_import;
- ImportTableEntry *test_runner_import;
+ ZigPackage *std_package;
+ ZigPackage *panic_package;
+ ZigPackage *test_runner_package;
+ ZigPackage *compile_var_package;
+ ZigType *compile_var_import;
+ ZigType *root_import;
+ ZigType *bootstrap_import;
+ ZigType *test_runner_import;
struct {
ZigType *entry_bool;
@@ -1731,7 +1725,6 @@ struct CodeGen {
ZigType *entry_unreachable;
ZigType *entry_type;
ZigType *entry_invalid;
- ZigType *entry_namespace;
ZigType *entry_block;
ZigType *entry_num_lit_int;
ZigType *entry_num_lit_float;
@@ -1851,7 +1844,7 @@ struct CodeGen {
Buf *root_out_name;
Buf *test_filter;
Buf *test_name_prefix;
- PackageTableEntry *root_package;
+ ZigPackage *root_package;
Buf *zig_lib_dir;
Buf *zig_std_dir;
@@ -1945,13 +1938,16 @@ struct ScopeDecls {
Scope base;
HashMap decl_table;
- bool safety_off;
+ ZigList use_decls;
AstNode *safety_set_node;
- bool fast_math_on;
AstNode *fast_math_set_node;
- ImportTableEntry *import;
+ ZigType *import;
// If this is a scope from a container, this is the type entry, otherwise null
ZigType *container_type;
+
+ bool safety_off;
+ bool fast_math_on;
+ bool any_imports_failed;
};
// This scope comes from a block expression in user code.
@@ -3507,7 +3503,7 @@ struct FnWalkTypes {
};
struct FnWalkVars {
- ImportTableEntry *import;
+ ZigType *import;
LLVMValueRef llvm_fn;
ZigFn *fn;
ZigVar *var;
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 3ceda4193422..a6944e85143a 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -28,10 +28,14 @@ static Error ATTRIBUTE_MUST_USE resolve_enum_zero_bits(CodeGen *g, ZigType *enum
static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, ZigType *union_type);
static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry);
-static ErrorMsg *add_error_note_token(CodeGen *g, ErrorMsg *parent_msg, ImportTableEntry *owner, Token *token,
- Buf *msg)
-{
- if (owner->c_import_node != nullptr) {
+static bool is_top_level_struct(ZigType *import) {
+ return import->id == ZigTypeIdStruct && import->data.structure.root_struct != nullptr;
+}
+
+static ErrorMsg *add_error_note_token(CodeGen *g, ErrorMsg *parent_msg, ZigType *owner, Token *token, Buf *msg) {
+ assert(is_top_level_struct(owner));
+ RootStruct *root_struct = owner->data.structure.root_struct;
+ if (root_struct->c_import_node != nullptr) {
// if this happens, then translate_c generated code that
// failed semantic analysis, which isn't supposed to happen
@@ -46,18 +50,20 @@ static ErrorMsg *add_error_note_token(CodeGen *g, ErrorMsg *parent_msg, ImportTa
return note;
}
- ErrorMsg *err = err_msg_create_with_line(owner->path, token->start_line, token->start_column,
- owner->source_code, owner->line_offsets, msg);
+ ErrorMsg *err = err_msg_create_with_line(root_struct->path, token->start_line, token->start_column,
+ root_struct->source_code, root_struct->line_offsets, msg);
err_msg_add_note(parent_msg, err);
return err;
}
-ErrorMsg *add_token_error(CodeGen *g, ImportTableEntry *owner, Token *token, Buf *msg) {
- if (owner->c_import_node != nullptr) {
+ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg) {
+ assert(is_top_level_struct(owner));
+ RootStruct *root_struct = owner->data.structure.root_struct;
+ if (root_struct->c_import_node != nullptr) {
// if this happens, then translate_c generated code that
// failed semantic analysis, which isn't supposed to happen
- ErrorMsg *err = add_node_error(g, owner->c_import_node,
+ ErrorMsg *err = add_node_error(g, root_struct->c_import_node,
buf_sprintf("compiler bug: @cImport generated invalid zig code"));
add_error_note_token(g, err, owner, token, msg);
@@ -65,8 +71,8 @@ ErrorMsg *add_token_error(CodeGen *g, ImportTableEntry *owner, Token *token, Buf
g->errors.append(err);
return err;
}
- ErrorMsg *err = err_msg_create_with_line(owner->path, token->start_line, token->start_column,
- owner->source_code, owner->line_offsets, msg);
+ ErrorMsg *err = err_msg_create_with_line(root_struct->path, token->start_line, token->start_column,
+ root_struct->source_code, root_struct->line_offsets, msg);
g->errors.append(err);
return err;
@@ -114,7 +120,7 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope
dest->parent = parent;
}
-ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import) {
+ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ZigType *import) {
assert(node == nullptr || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr);
ScopeDecls *scope = allocate(1);
init_scope(g, &scope->base, ScopeIdDecls, node, parent);
@@ -207,11 +213,11 @@ Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent) {
return &scope->base;
}
-ImportTableEntry *get_scope_import(Scope *scope) {
+ZigType *get_scope_import(Scope *scope) {
while (scope) {
if (scope->id == ScopeIdDecls) {
ScopeDecls *decls_scope = (ScopeDecls *)scope;
- assert(decls_scope->import);
+ assert(is_top_level_struct(decls_scope->import));
return decls_scope->import;
}
scope = scope->parent;
@@ -261,7 +267,6 @@ AstNode *type_decl_node(ZigType *type_entry) {
case ZigTypeIdErrorUnion:
case ZigTypeIdErrorSet:
case ZigTypeIdFn:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdPromise:
@@ -323,7 +328,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
case ZigTypeIdErrorUnion:
case ZigTypeIdErrorSet:
case ZigTypeIdFn:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdPromise:
@@ -1010,14 +1014,14 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c
buf_init_from_str(&entry->name, name);
- ImportTableEntry *import = scope ? get_scope_import(scope) : nullptr;
+ ZigType *import = scope ? get_scope_import(scope) : nullptr;
unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0;
entry->type_ref = LLVMInt8Type();
entry->di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder,
ZigLLVMTag_DW_structure_type(), buf_ptr(&entry->name),
- import ? ZigLLVMFileToScope(import->di_file) : nullptr,
- import ? import->di_file : nullptr,
+ import ? ZigLLVMFileToScope(import->data.structure.root_struct->di_file) : nullptr,
+ import ? import->data.structure.root_struct->di_file : nullptr,
line);
entry->zero_bits = false;
@@ -1288,6 +1292,25 @@ static ZigTypeId container_to_type(ContainerKind kind) {
zig_unreachable();
}
+// This is like get_partial_container_type except it's for the implicit root struct of files.
+ZigType *get_root_container_type(CodeGen *g, const char *name, RootStruct *root_struct) {
+ ZigType *entry = new_type_table_entry(ZigTypeIdStruct);
+ entry->data.structure.decls_scope = create_decls_scope(g, nullptr, nullptr, nullptr, entry);
+ entry->data.structure.root_struct = root_struct;
+ entry->data.structure.layout = ContainerLayoutAuto;
+ entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), name);
+
+ size_t line = 0; // root therefore first line
+ unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();
+
+ entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,
+ dwarf_kind, name,
+ ZigLLVMFileToScope(root_struct->di_file), root_struct->di_file, (unsigned)(line + 1));
+
+ buf_init_from_str(&entry->name, name);
+ return entry;
+}
+
ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
AstNode *decl_node, const char *name, ContainerLayout layout)
{
@@ -1312,11 +1335,12 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind
size_t line = decl_node ? decl_node->line : 0;
unsigned dwarf_kind = ZigLLVMTag_DW_structure_type();
- ImportTableEntry *import = get_scope_import(scope);
+ ZigType *import = get_scope_import(scope);
entry->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), name);
entry->di_type = ZigLLVMCreateReplaceableCompositeType(g->dbuilder,
dwarf_kind, name,
- ZigLLVMFileToScope(import->di_file), import->di_file, (unsigned)(line + 1));
+ ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
+ import->data.structure.root_struct->di_file, (unsigned)(line + 1));
buf_init_from_str(&entry->name, name);
@@ -1459,7 +1483,6 @@ static Error emit_error_unless_type_allowed_in_packed_struct(CodeGen *g, ZigType
case ZigTypeIdNull:
case ZigTypeIdErrorUnion:
case ZigTypeIdErrorSet:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdOpaque:
@@ -1547,7 +1570,6 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
case ZigTypeIdNull:
case ZigTypeIdErrorUnion:
case ZigTypeIdErrorSet:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdPromise:
@@ -1706,7 +1728,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
return g->builtin_types.entry_invalid;
case ZigTypeIdComptimeFloat:
case ZigTypeIdComptimeInt:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdMetaType:
case ZigTypeIdVoid:
@@ -1801,7 +1822,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
case ZigTypeIdComptimeFloat:
case ZigTypeIdComptimeInt:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdMetaType:
case ZigTypeIdUnreachable:
@@ -1895,7 +1915,7 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
ZigLLVMDIEnumerator **di_enumerators = allocate(field_count);
Scope *scope = &enum_type->data.enumeration.decls_scope->base;
- ImportTableEntry *import = get_scope_import(scope);
+ ZigType *import = get_scope_import(scope);
// set temporary flag
enum_type->data.enumeration.embedded_in_current = true;
@@ -1924,9 +1944,9 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
ZigLLVMDIType **di_root_members = nullptr;
size_t debug_member_count = 0;
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
- ZigLLVMFileToScope(import->di_file),
+ ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
buf_ptr(&enum_type->name),
- import->di_file, (unsigned)(decl_node->line + 1),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
0, nullptr, di_root_members, (int)debug_member_count, 0, nullptr, "");
@@ -1942,8 +1962,8 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
uint64_t tag_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, tag_int_type->type_ref);
uint64_t tag_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_int_type->type_ref);
ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder,
- ZigLLVMFileToScope(import->di_file), buf_ptr(&enum_type->name),
- import->di_file, (unsigned)(decl_node->line + 1),
+ ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&enum_type->name),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
tag_debug_size_in_bits,
tag_debug_align_in_bits,
di_enumerators, field_count,
@@ -2159,15 +2179,15 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
if (struct_type->zero_bits) {
struct_type->type_ref = LLVMVoidType();
- ImportTableEntry *import = get_scope_import(scope);
+ ZigType *import = get_scope_import(scope);
uint64_t debug_size_in_bits = 0;
uint64_t debug_align_in_bits = 0;
ZigLLVMDIType **di_element_types = nullptr;
size_t debug_field_count = 0;
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
- ZigLLVMFileToScope(import->di_file),
+ ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
buf_ptr(&struct_type->name),
- import->di_file, (unsigned)(decl_node->line + 1),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");
@@ -2191,7 +2211,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
ZigLLVMDIType **di_element_types = allocate(debug_field_count);
- ImportTableEntry *import = get_scope_import(scope);
+ ZigType *import = get_scope_import(scope);
size_t debug_field_index = 0;
for (size_t i = 0; i < field_count; i += 1) {
AstNode *field_node = decl_node->data.container_decl.fields.at(i);
@@ -2234,7 +2254,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
}
di_element_types[debug_field_index] = ZigLLVMCreateDebugMemberType(g->dbuilder,
ZigLLVMTypeToScope(struct_type->di_type), buf_ptr(type_struct_field->name),
- import->di_file, (unsigned)(field_node->line + 1),
+ import->data.structure.root_struct->di_file, (unsigned)(field_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
debug_offset_in_bits,
@@ -2247,9 +2267,9 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, struct_type->type_ref);
uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, struct_type->type_ref);
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
- ZigLLVMFileToScope(import->di_file),
+ ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
buf_ptr(&struct_type->name),
- import->di_file, (unsigned)(decl_node->line + 1),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
0, nullptr, di_element_types, (int)debug_field_count, 0, nullptr, "");
@@ -2298,7 +2318,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
uint64_t biggest_size_in_bits = 0;
Scope *scope = &union_type->data.unionation.decls_scope->base;
- ImportTableEntry *import = get_scope_import(scope);
+ ZigType *import = get_scope_import(scope);
// set temporary flag
union_type->data.unionation.embedded_in_current = true;
@@ -2325,7 +2345,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
union_inner_di_types[union_field->gen_index] = ZigLLVMCreateDebugMemberType(g->dbuilder,
ZigLLVMTypeToScope(union_type->di_type), buf_ptr(union_field->enum_field->name),
- import->di_file, (unsigned)(field_node->line + 1),
+ import->data.structure.root_struct->di_file, (unsigned)(field_node->line + 1),
store_size_in_bits,
abi_align_in_bits,
0,
@@ -2358,9 +2378,9 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
ZigLLVMDIType **di_root_members = nullptr;
size_t debug_member_count = 0;
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,
- ZigLLVMFileToScope(import->di_file),
+ ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
buf_ptr(&union_type->name),
- import->di_file, (unsigned)(decl_node->line + 1),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
0, di_root_members, (int)debug_member_count, 0, "");
@@ -2396,8 +2416,8 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
// create debug type for union
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,
- ZigLLVMFileToScope(import->di_file), buf_ptr(&union_type->name),
- import->di_file, (unsigned)(decl_node->line + 1),
+ ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&union_type->name),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
biggest_size_in_bits, biggest_align_in_bits, 0, union_inner_di_types,
gen_field_count, 0, "");
@@ -2452,7 +2472,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
// create debug type for union
ZigLLVMDIType *union_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,
ZigLLVMTypeToScope(union_type->di_type), "AnonUnion",
- import->di_file, (unsigned)(decl_node->line + 1),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
biggest_size_in_bits, biggest_align_in_bits, 0, union_inner_di_types,
gen_field_count, 0, "");
@@ -2463,7 +2483,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
ZigLLVMDIType *union_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder,
ZigLLVMTypeToScope(union_type->di_type), "payload",
- import->di_file, (unsigned)(decl_node->line + 1),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
biggest_size_in_bits,
biggest_align_in_bits,
union_offset_in_bits,
@@ -2474,7 +2494,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
ZigLLVMDIType *tag_member_di_type = ZigLLVMCreateDebugMemberType(g->dbuilder,
ZigLLVMTypeToScope(union_type->di_type), "tag",
- import->di_file, (unsigned)(decl_node->line + 1),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
tag_debug_size_in_bits,
tag_debug_align_in_bits,
tag_offset_in_bits,
@@ -2487,9 +2507,9 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, union_type->type_ref);
uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, union_type->type_ref);
ZigLLVMDIType *replacement_di_type = ZigLLVMCreateDebugStructType(g->dbuilder,
- ZigLLVMFileToScope(import->di_file),
+ ZigLLVMFileToScope(import->data.structure.root_struct->di_file),
buf_ptr(&union_type->name),
- import->di_file, (unsigned)(decl_node->line + 1),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
debug_size_in_bits,
debug_align_in_bits,
0, nullptr, di_root_members, 2, 0, nullptr, "");
@@ -3185,15 +3205,15 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
}
if (create_enum_type) {
- ImportTableEntry *import = get_scope_import(scope);
+ ZigType *import = get_scope_import(scope);
uint64_t tag_debug_size_in_bits = tag_type->zero_bits ? 0 :
8*LLVMStoreSizeOfType(g->target_data_ref, tag_type->type_ref);
uint64_t tag_debug_align_in_bits = tag_type->zero_bits ? 0 :
8*LLVMABIAlignmentOfType(g->target_data_ref, tag_type->type_ref);
// TODO get a more accurate debug scope
ZigLLVMDIType *tag_di_type = ZigLLVMCreateDebugEnumerationType(g->dbuilder,
- ZigLLVMFileToScope(import->di_file), buf_ptr(&tag_type->name),
- import->di_file, (unsigned)(decl_node->line + 1),
+ ZigLLVMFileToScope(import->data.structure.root_struct->di_file), buf_ptr(&tag_type->name),
+ import->data.structure.root_struct->di_file, (unsigned)(decl_node->line + 1),
tag_debug_size_in_bits, tag_debug_align_in_bits, di_enumerators, field_count,
tag_type->di_type, "");
tag_type->di_type = tag_di_type;
@@ -3265,7 +3285,8 @@ static bool scope_is_root_decls(Scope *scope) {
while (scope) {
if (scope->id == ScopeIdDecls) {
ScopeDecls *scope_decls = (ScopeDecls *)scope;
- return (scope_decls->container_type == nullptr);
+ return scope_decls->container_type == nullptr ||
+ is_top_level_struct(scope_decls->container_type);
}
scope = scope->parent;
}
@@ -3326,7 +3347,7 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi
}
static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
- ImportTableEntry *import = tld_fn->base.import;
+ ZigType *import = tld_fn->base.import;
AstNode *source_node = tld_fn->base.source_node;
if (source_node->type == NodeTypeFnProto) {
AstNodeFnProto *fn_proto = &source_node->data.fn_proto;
@@ -3382,11 +3403,11 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
}
if (scope_is_root_decls(tld_fn->base.parent_scope) &&
- (import == g->root_import || import->package == g->panic_package))
+ (import == g->root_import || import->data.structure.root_struct->package == g->panic_package))
{
if (g->have_pub_main && buf_eql_str(&fn_table_entry->symbol_name, "main")) {
g->main_fn = fn_table_entry;
- } else if ((import->package == g->panic_package || g->have_pub_panic) &&
+ } else if ((import->data.structure.root_struct->package == g->panic_package || g->have_pub_panic) &&
buf_eql_str(&fn_table_entry->symbol_name, "panic"))
{
g->panic_fn = fn_table_entry;
@@ -3473,8 +3494,8 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope
if (!g->is_test_build)
return;
- ImportTableEntry *import = get_scope_import(&decls_scope->base);
- if (import->package != g->root_package)
+ ZigType *import = get_scope_import(&decls_scope->base);
+ if (import->data.structure.root_struct->package != g->root_package)
return;
Buf *decl_name_buf = node->data.test_decl.name;
@@ -3511,8 +3532,8 @@ void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source
}
void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value) {
- Tld *tld = g->compile_var_import->decls_scope->decl_table.get(name);
- resolve_top_level_decl(g, tld, false, tld->source_node);
+ Tld *tld = get_container_scope(g->compile_var_import)->decl_table.get(name);
+ resolve_top_level_decl(g, tld, tld->source_node);
assert(tld->id == TldIdVar);
TldVar *tld_var = (TldVar *)tld;
tld_var->var->const_value = value;
@@ -3561,8 +3582,8 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
case NodeTypeUse:
{
g->use_queue.append(node);
- ImportTableEntry *import = get_scope_import(&decls_scope->base);
- import->use_decls.append(node);
+ ZigType *import = get_scope_import(&decls_scope->base);
+ get_container_scope(import)->use_decls.append(node);
break;
}
case NodeTypeTestDecl:
@@ -3654,7 +3675,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
return g->builtin_types.entry_invalid;
case ZigTypeIdComptimeFloat:
case ZigTypeIdComptimeInt:
- case ZigTypeIdNamespace:
case ZigTypeIdMetaType:
case ZigTypeIdVoid:
case ZigTypeIdBool:
@@ -3847,16 +3867,10 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
g->global_vars.append(tld_var);
}
-void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node) {
+void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node) {
if (tld->resolution != TldResolutionUnresolved)
return;
- if (tld->dep_loop_flag) {
- add_node_error(g, tld->source_node, buf_sprintf("'%s' depends on itself", buf_ptr(tld->name)));
- tld->resolution = TldResolutionInvalid;
- return;
- }
-
tld->dep_loop_flag = true;
g->tld_ref_source_node_stack.append(source_node);
@@ -3894,9 +3908,9 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *so
Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {
// we must resolve all the use decls
- ImportTableEntry *import = get_scope_import(scope);
- for (size_t i = 0; i < import->use_decls.length; i += 1) {
- AstNode *use_decl_node = import->use_decls.at(i);
+ ZigType *import = get_scope_import(scope);
+ for (size_t i = 0; i < get_container_scope(import)->use_decls.length; i += 1) {
+ AstNode *use_decl_node = get_container_scope(import)->use_decls.at(i);
if (use_decl_node->data.use.resolution == TldResolutionUnresolved) {
preview_use_decl(g, use_decl_node);
resolve_use_decl(g, use_decl_node);
@@ -4039,7 +4053,6 @@ static bool is_container(ZigType *type_entry) {
case ZigTypeIdErrorUnion:
case ZigTypeIdErrorSet:
case ZigTypeIdFn:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdOpaque:
@@ -4098,7 +4111,6 @@ void resolve_container_type(CodeGen *g, ZigType *type_entry) {
case ZigTypeIdErrorUnion:
case ZigTypeIdErrorSet:
case ZigTypeIdFn:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdInvalid:
case ZigTypeIdArgTuple:
@@ -4344,7 +4356,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
ConstExprValue *use_target_value = src_use_node->data.use.value;
if (type_is_invalid(use_target_value->type)) {
- dst_use_node->owner->any_imports_failed = true;
+ get_container_scope(dst_use_node->owner)->any_imports_failed = true;
return;
}
@@ -4352,14 +4364,15 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
assert(use_target_value->special != ConstValSpecialRuntime);
- ImportTableEntry *target_import = use_target_value->data.x_import;
+ ZigType *target_import = use_target_value->data.x_type;
assert(target_import);
+ assert(target_import->id == ZigTypeIdStruct);
- if (target_import->any_imports_failed) {
- dst_use_node->owner->any_imports_failed = true;
+ if (get_container_scope(target_import)->any_imports_failed) {
+ get_container_scope(dst_use_node->owner)->any_imports_failed = true;
}
- auto it = target_import->decls_scope->decl_table.entry_iterator();
+ auto it = get_container_scope(target_import)->decl_table.entry_iterator();
for (;;) {
auto *entry = it.next();
if (!entry)
@@ -4374,7 +4387,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
Buf *target_tld_name = entry->key;
- auto existing_entry = dst_use_node->owner->decls_scope->decl_table.put_unique(target_tld_name, target_tld);
+ auto existing_entry = get_container_scope(dst_use_node->owner)->decl_table.put_unique(target_tld_name, target_tld);
if (existing_entry) {
Tld *existing_decl = existing_entry->value;
if (existing_decl != target_tld) {
@@ -4387,8 +4400,8 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
}
}
- for (size_t i = 0; i < target_import->use_decls.length; i += 1) {
- AstNode *use_decl_node = target_import->use_decls.at(i);
+ for (size_t i = 0; i < get_container_scope(target_import)->use_decls.length; i += 1) {
+ AstNode *use_decl_node = get_container_scope(target_import)->use_decls.at(i);
if (use_decl_node->data.use.visib_mod != VisibModPrivate)
add_symbols_from_import(g, use_decl_node, dst_use_node);
}
@@ -4415,16 +4428,16 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
}
node->data.use.resolution = TldResolutionResolving;
- ConstExprValue *result = analyze_const_value(g, &node->owner->decls_scope->base,
- node->data.use.expr, g->builtin_types.entry_namespace, nullptr);
+ ConstExprValue *result = analyze_const_value(g, &get_container_scope(node->owner)->base,
+ node->data.use.expr, g->builtin_types.entry_type, nullptr);
if (type_is_invalid(result->type))
- node->owner->any_imports_failed = true;
+ get_container_scope(node->owner)->any_imports_failed = true;
node->data.use.value = result;
}
-ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *resolved_path, Buf *source_code) {
+ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Buf *source_code) {
if (g->verbose_tokenize) {
fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(resolved_path));
fprintf(stderr, "----------------\n");
@@ -4452,32 +4465,34 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r
fprintf(stderr, "------\n");
}
- ImportTableEntry *import_entry = allocate(1);
- import_entry->package = package;
- import_entry->source_code = source_code;
- import_entry->line_offsets = tokenization.line_offsets;
- import_entry->path = resolved_path;
-
- import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);
- assert(import_entry->root);
- if (g->verbose_ast) {
- ast_print(stderr, import_entry->root, 0);
- }
-
Buf *src_dirname = buf_alloc();
Buf *src_basename = buf_alloc();
os_path_split(resolved_path, src_dirname, src_basename);
- import_entry->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
+ Buf noextname = BUF_INIT;
+ os_path_extname(src_basename, &noextname, nullptr);
+ RootStruct *root_struct = allocate(1);
+ root_struct->package = package;
+ root_struct->source_code = source_code;
+ root_struct->line_offsets = tokenization.line_offsets;
+ root_struct->path = resolved_path;
+ root_struct->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
+ ZigType *import_entry = get_root_container_type(g, buf_ptr(&noextname), root_struct);
+
+ AstNode *root_node = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);
+ assert(root_node != nullptr);
+ assert(root_node->type == NodeTypeContainerDecl);
+ import_entry->data.structure.decl_node = root_node;
+ import_entry->data.structure.decls_scope->base.source_node = root_node;
+ if (g->verbose_ast) {
+ ast_print(stderr, root_node, 0);
+ }
+
g->import_table.put(resolved_path, import_entry);
g->import_queue.append(import_entry);
- import_entry->decls_scope = create_decls_scope(g, import_entry->root, nullptr, nullptr, import_entry);
-
-
- assert(import_entry->root->type == NodeTypeContainerDecl);
- for (size_t decl_i = 0; decl_i < import_entry->root->data.container_decl.decls.length; decl_i += 1) {
- AstNode *top_level_decl = import_entry->root->data.container_decl.decls.at(decl_i);
+ for (size_t decl_i = 0; decl_i < root_node->data.container_decl.decls.length; decl_i += 1) {
+ AstNode *top_level_decl = root_node->data.container_decl.decls.at(decl_i);
if (top_level_decl->type == NodeTypeFnDef) {
AstNode *proto_node = top_level_decl->data.fn_def.fn_proto;
@@ -4502,16 +4517,16 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r
return import_entry;
}
-void scan_import(CodeGen *g, ImportTableEntry *import) {
- if (!import->scanned) {
- import->scanned = true;
- scan_decls(g, import->decls_scope, import->root);
+void scan_import(CodeGen *g, ZigType *import) {
+ if (!import->data.structure.root_struct->scanned) {
+ import->data.structure.root_struct->scanned = true;
+ scan_decls(g, import->data.structure.decls_scope, import->data.structure.decl_node);
}
}
void semantic_analyze(CodeGen *g) {
for (; g->import_queue_index < g->import_queue.length; g->import_queue_index += 1) {
- ImportTableEntry *import = g->import_queue.at(g->import_queue_index);
+ ZigType *import = g->import_queue.at(g->import_queue_index);
scan_import(g, import);
}
@@ -4530,9 +4545,8 @@ void semantic_analyze(CodeGen *g) {
{
for (; g->resolve_queue_index < g->resolve_queue.length; g->resolve_queue_index += 1) {
Tld *tld = g->resolve_queue.at(g->resolve_queue_index);
- bool pointer_only = false;
AstNode *source_node = nullptr;
- resolve_top_level_decl(g, tld, pointer_only, source_node);
+ resolve_top_level_decl(g, tld, source_node);
}
for (; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) {
@@ -4613,7 +4627,6 @@ bool handle_is_ptr(ZigType *type_entry) {
case ZigTypeIdComptimeInt:
case ZigTypeIdUndefined:
case ZigTypeIdNull:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdOpaque:
@@ -4880,8 +4893,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
return 3415065496;
case ZigTypeIdErrorSet:
return hash_const_val_error_set(const_val);
- case ZigTypeIdNamespace:
- return hash_ptr(const_val->data.x_import);
case ZigTypeIdVector:
// TODO better hashing algorithm
return 3647867726;
@@ -4943,7 +4954,6 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
case ZigTypeIdComptimeInt:
case ZigTypeIdUndefined:
case ZigTypeIdNull:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdFn:
case ZigTypeIdOpaque:
@@ -5013,7 +5023,6 @@ static bool return_type_is_cacheable(ZigType *return_type) {
case ZigTypeIdComptimeInt:
case ZigTypeIdUndefined:
case ZigTypeIdNull:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdFn:
case ZigTypeIdOpaque:
@@ -5143,7 +5152,6 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
case ZigTypeIdComptimeFloat:
case ZigTypeIdComptimeInt:
case ZigTypeIdMetaType:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdOptional:
@@ -5209,7 +5217,6 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry) {
case ZigTypeIdUndefined:
case ZigTypeIdNull:
case ZigTypeIdMetaType:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
return ReqCompTimeYes;
@@ -5797,8 +5804,6 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
}
case ZigTypeIdErrorUnion:
zig_panic("TODO");
- case ZigTypeIdNamespace:
- return a->data.x_import == b->data.x_import;
case ZigTypeIdArgTuple:
return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index &&
a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index;
@@ -6072,16 +6077,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
}
return;
}
- case ZigTypeIdNamespace:
- {
- ImportTableEntry *import = const_val->data.x_import;
- if (import->c_import_node) {
- buf_appendf(buf, "(namespace from C import)");
- } else {
- buf_appendf(buf, "(namespace: %s)", buf_ptr(import->path));
- }
- return;
- }
case ZigTypeIdBoundFn:
{
ZigFn *fn_entry = const_val->data.x_bound_fn.fn;
@@ -6203,7 +6198,6 @@ uint32_t type_id_hash(TypeId x) {
case ZigTypeIdEnum:
case ZigTypeIdUnion:
case ZigTypeIdFn:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdPromise:
@@ -6252,7 +6246,6 @@ bool type_id_eql(TypeId a, TypeId b) {
case ZigTypeIdEnum:
case ZigTypeIdUnion:
case ZigTypeIdFn:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdOpaque:
@@ -6419,7 +6412,6 @@ static const ZigTypeId all_type_ids[] = {
ZigTypeIdEnum,
ZigTypeIdUnion,
ZigTypeIdFn,
- ZigTypeIdNamespace,
ZigTypeIdBoundFn,
ZigTypeIdArgTuple,
ZigTypeIdOpaque,
@@ -6480,18 +6472,16 @@ size_t type_id_index(ZigType *entry) {
return 17;
case ZigTypeIdFn:
return 18;
- case ZigTypeIdNamespace:
- return 19;
case ZigTypeIdBoundFn:
- return 20;
+ return 19;
case ZigTypeIdArgTuple:
- return 21;
+ return 20;
case ZigTypeIdOpaque:
- return 22;
+ return 21;
case ZigTypeIdPromise:
- return 23;
+ return 22;
case ZigTypeIdVector:
- return 24;
+ return 23;
}
zig_unreachable();
}
@@ -6538,8 +6528,6 @@ const char *type_id_name(ZigTypeId id) {
return "Union";
case ZigTypeIdFn:
return "Fn";
- case ZigTypeIdNamespace:
- return "Namespace";
case ZigTypeIdBoundFn:
return "BoundFn";
case ZigTypeIdArgTuple:
@@ -6619,8 +6607,8 @@ bool type_ptr_eql(const ZigType *a, const ZigType *b) {
}
ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
- Tld *tld = codegen->compile_var_import->decls_scope->decl_table.get(buf_create_from_str(name));
- resolve_top_level_decl(codegen, tld, false, nullptr);
+ Tld *tld = get_container_scope(codegen->compile_var_import)->decl_table.get(buf_create_from_str(name));
+ resolve_top_level_decl(codegen, tld, nullptr);
assert(tld->id == TldIdVar);
TldVar *tld_var = (TldVar *)tld;
ConstExprValue *var_value = tld_var->var->const_value;
diff --git a/src/analyze.hpp b/src/analyze.hpp
index e8838ae57eb4..58b27d71de6d 100644
--- a/src/analyze.hpp
+++ b/src/analyze.hpp
@@ -12,7 +12,7 @@
void semantic_analyze(CodeGen *g);
ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);
-ErrorMsg *add_token_error(CodeGen *g, ImportTableEntry *owner, Token *token, Buf *msg);
+ErrorMsg *add_token_error(CodeGen *g, ZigType *owner, Token *token, Buf *msg);
ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);
ZigType *new_type_table_entry(ZigTypeId id);
ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const);
@@ -30,6 +30,7 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size);
ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type);
ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
AstNode *decl_node, const char *name, ContainerLayout layout);
+ZigType *get_root_container_type(CodeGen *g, const char *name, RootStruct *root_struct);
ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type);
ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);
@@ -46,12 +47,12 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry);
bool ptr_allows_addr_zero(ZigType *ptr_type);
bool type_is_nonnull_ptr(ZigType *type);
-ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code);
+ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *abs_full_path, Buf *source_code);
ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name, ScopeFnDef **crossed_fndef_scope);
Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
-void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);
+void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node);
bool type_is_codegen_pointer(ZigType *type);
ZigType *get_src_ptr_type(ZigType *type);
@@ -77,11 +78,11 @@ bool is_array_ref(ZigType *type_entry);
bool is_container_ref(ZigType *type_entry);
bool is_valid_vector_elem_type(ZigType *elem_type);
void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);
-void scan_import(CodeGen *g, ImportTableEntry *import);
+void scan_import(CodeGen *g, ZigType *import);
void preview_use_decl(CodeGen *g, AstNode *node);
void resolve_use_decl(CodeGen *g, AstNode *node);
ZigFn *scope_fn_entry(Scope *scope);
-ImportTableEntry *get_scope_import(Scope *scope);
+ZigType *get_scope_import(Scope *scope);
void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
bool is_const, ConstExprValue *init_value, Tld *src_tld, ZigType *var_type);
@@ -109,7 +110,7 @@ ScopeCImport *create_cimport_scope(CodeGen *g, AstNode *node, Scope *parent);
ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);
ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);
ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);
-ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import);
+ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type, ZigType *import);
Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);
Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent);
Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime);
@@ -186,7 +187,7 @@ LinkLib *add_link_lib(CodeGen *codegen, Buf *lib);
uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
ZigType *get_align_amt_type(CodeGen *g);
-PackageTableEntry *new_anonymous_package(void);
+ZigPackage *new_anonymous_package(void);
Buf *const_value_to_buffer(ConstExprValue *const_val);
void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 520c1eed0005..ed486c0d43e0 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -48,15 +48,15 @@ static void init_darwin_native(CodeGen *g) {
}
}
-static PackageTableEntry *new_package(const char *root_src_dir, const char *root_src_path) {
- PackageTableEntry *entry = allocate(1);
+static ZigPackage *new_package(const char *root_src_dir, const char *root_src_path) {
+ ZigPackage *entry = allocate(1);
entry->package_table.init(4);
buf_init_from_str(&entry->root_src_dir, root_src_dir);
buf_init_from_str(&entry->root_src_path, root_src_path);
return entry;
}
-PackageTableEntry *new_anonymous_package(void) {
+ZigPackage *new_anonymous_package(void) {
return new_package("", "");
}
@@ -621,7 +621,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
if (scope->di_scope)
return scope->di_scope;
- ImportTableEntry *import = get_scope_import(scope);
+ ZigType *import = get_scope_import(scope);
switch (scope->id) {
case ScopeIdCImport:
zig_unreachable();
@@ -644,7 +644,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
assert(fn_di_scope != nullptr);
ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder,
fn_di_scope, buf_ptr(&fn_table_entry->symbol_name), "",
- import->di_file, line_number,
+ import->data.structure.root_struct->di_file, line_number,
fn_table_entry->type_entry->data.fn.raw_di_type, is_internal_linkage,
is_definition, scope_line, flags, is_optimized, nullptr);
@@ -658,7 +658,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
assert(decls_scope->container_type);
scope->di_scope = ZigLLVMTypeToScope(decls_scope->container_type->di_type);
} else {
- scope->di_scope = ZigLLVMFileToScope(import->di_file);
+ scope->di_scope = ZigLLVMFileToScope(import->data.structure.root_struct->di_file);
}
return scope->di_scope;
case ScopeIdBlock:
@@ -668,7 +668,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
assert(scope->parent);
ZigLLVMDILexicalBlock *di_block = ZigLLVMCreateLexicalBlock(g->dbuilder,
get_di_scope(g, scope->parent),
- import->di_file,
+ import->data.structure.root_struct->di_file,
(unsigned)scope->source_node->line + 1,
(unsigned)scope->source_node->column + 1);
scope->di_scope = ZigLLVMLexicalBlockToScope(di_block);
@@ -2196,7 +2196,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
if (dest_ty != nullptr && var->decl_node) {
// arg index + 1 because the 0 index is return value
var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
- buf_ptr(&var->name), fn_walk->data.vars.import->di_file,
+ buf_ptr(&var->name), fn_walk->data.vars.import->data.structure.root_struct->di_file,
(unsigned)(var->decl_node->line + 1),
dest_ty->di_type, !g->strip_debug_symbols, 0, di_arg_index + 1);
}
@@ -5800,7 +5800,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
case ZigTypeIdNull:
case ZigTypeIdErrorUnion:
case ZigTypeIdErrorSet:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdVoid:
@@ -6400,7 +6399,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
case ZigTypeIdComptimeInt:
case ZigTypeIdUndefined:
case ZigTypeIdNull:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdOpaque:
@@ -6506,12 +6504,12 @@ static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val,
assert(var->gen_is_const);
assert(type_entry);
- ImportTableEntry *import = get_scope_import(var->parent_scope);
+ ZigType *import = get_scope_import(var->parent_scope);
assert(import);
bool is_local_to_unit = true;
ZigLLVMCreateGlobalVariable(g->dbuilder, get_di_scope(g, var->parent_scope), buf_ptr(&var->name),
- buf_ptr(&var->name), import->di_file,
+ buf_ptr(&var->name), import->data.structure.root_struct->di_file,
(unsigned)(var->decl_node->line + 1),
type_entry->di_type, is_local_to_unit);
@@ -6767,7 +6765,7 @@ static void do_code_gen(CodeGen *g) {
*slot = build_alloca(g, slot_type, "", alignment_bytes);
}
- ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base);
+ ZigType *import = get_scope_import(&fn_table_entry->fndef_scope->base);
unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0;
@@ -6799,7 +6797,7 @@ static void do_code_gen(CodeGen *g) {
var->value_ref = build_alloca(g, var->var_type, buf_ptr(&var->name), var->align_bytes);
var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
- buf_ptr(&var->name), import->di_file, (unsigned)(var->decl_node->line + 1),
+ buf_ptr(&var->name), import->data.structure.root_struct->di_file, (unsigned)(var->decl_node->line + 1),
var->var_type->di_type, !g->strip_debug_symbols, 0);
} else if (is_c_abi) {
@@ -6823,7 +6821,7 @@ static void do_code_gen(CodeGen *g) {
}
if (var->decl_node) {
var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
- buf_ptr(&var->name), import->di_file,
+ buf_ptr(&var->name), import->data.structure.root_struct->di_file,
(unsigned)(var->decl_node->line + 1),
gen_type->di_type, !g->strip_debug_symbols, 0, (unsigned)(var->gen_arg_index + 1));
}
@@ -6971,12 +6969,6 @@ static void define_builtin_types(CodeGen *g) {
entry->zero_bits = true;
g->builtin_types.entry_invalid = entry;
}
- {
- ZigType *entry = new_type_table_entry(ZigTypeIdNamespace);
- buf_init_from_str(&entry->name, "(namespace)");
- entry->zero_bits = true;
- g->builtin_types.entry_namespace = entry;
- }
{
ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat);
buf_init_from_str(&entry->name, "comptime_float");
@@ -7470,7 +7462,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
" Enum: Enum,\n"
" Union: Union,\n"
" Fn: Fn,\n"
- " Namespace: void,\n"
" BoundFn: Fn,\n"
" ArgTuple: void,\n"
" Opaque: void,\n"
@@ -7948,17 +7939,21 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) {
Buf *src_dirname = buf_alloc();
os_path_split(full_path, src_dirname, src_basename);
- ImportTableEntry *import = allocate(1);
- import->source_code = nullptr;
- import->path = full_path;
+ Buf noextname = BUF_INIT;
+ os_path_extname(src_basename, &noextname, nullptr);
+
+ RootStruct *root_struct = allocate(1);
+ root_struct->source_code = nullptr;
+ root_struct->path = full_path;
+ root_struct->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
+
+ ZigType *import = get_root_container_type(g, buf_ptr(&noextname), root_struct);
g->root_import = import;
- import->decls_scope = create_decls_scope(g, nullptr, nullptr, nullptr, import);
detect_libc(g);
init(g);
- import->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
ZigList errors = {0};
Error err = parse_h_file(import, &errors, buf_ptr(full_path), g, nullptr);
@@ -7977,7 +7972,7 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) {
}
}
-static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package, const char *basename) {
+static ZigType *add_special_code(CodeGen *g, ZigPackage *package, const char *basename) {
Buf *code_basename = buf_create_from_str(basename);
Buf path_to_code_src = BUF_INIT;
os_path_join(g->zig_std_special_dir, code_basename, &path_to_code_src);
@@ -7994,17 +7989,17 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package
return add_source_file(g, package, resolved_path, import_code);
}
-static PackageTableEntry *create_bootstrap_pkg(CodeGen *g, PackageTableEntry *pkg_with_main) {
- PackageTableEntry *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig");
+static ZigPackage *create_bootstrap_pkg(CodeGen *g, ZigPackage *pkg_with_main) {
+ ZigPackage *package = codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "bootstrap.zig");
package->package_table.put(buf_create_from_str("@root"), pkg_with_main);
return package;
}
-static PackageTableEntry *create_test_runner_pkg(CodeGen *g) {
+static ZigPackage *create_test_runner_pkg(CodeGen *g) {
return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "test_runner.zig");
}
-static PackageTableEntry *create_panic_pkg(CodeGen *g) {
+static ZigPackage *create_panic_pkg(CodeGen *g) {
return codegen_create_package(g, buf_ptr(g->zig_std_special_dir), "panic.zig");
}
@@ -8096,7 +8091,7 @@ static void gen_root_source(CodeGen *g) {
{
// Zig has lazy top level definitions. Here we semantically analyze the panic function.
- ImportTableEntry *import_with_panic;
+ ZigType *import_with_panic;
if (g->have_pub_panic) {
import_with_panic = g->root_import;
} else {
@@ -8104,9 +8099,9 @@ static void gen_root_source(CodeGen *g) {
import_with_panic = add_special_code(g, g->panic_package, "panic.zig");
}
scan_import(g, import_with_panic);
- Tld *panic_tld = find_decl(g, &import_with_panic->decls_scope->base, buf_create_from_str("panic"));
+ Tld *panic_tld = find_decl(g, &get_container_scope(import_with_panic)->base, buf_create_from_str("panic"));
assert(panic_tld != nullptr);
- resolve_top_level_decl(g, panic_tld, false, nullptr);
+ resolve_top_level_decl(g, panic_tld, nullptr);
}
@@ -8341,7 +8336,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
case ZigTypeIdComptimeInt:
case ZigTypeIdUndefined:
case ZigTypeIdNull:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdErrorUnion:
@@ -8524,7 +8518,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
case ZigTypeIdInvalid:
case ZigTypeIdMetaType:
case ZigTypeIdBoundFn:
- case ZigTypeIdNamespace:
case ZigTypeIdComptimeFloat:
case ZigTypeIdComptimeInt:
case ZigTypeIdUndefined:
@@ -8676,7 +8669,6 @@ static void gen_h_file(CodeGen *g) {
case ZigTypeIdNull:
case ZigTypeIdErrorUnion:
case ZigTypeIdErrorSet:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdOptional:
@@ -8775,7 +8767,7 @@ void codegen_add_time_event(CodeGen *g, const char *name) {
g->timing_events.append({os_get_time(), name});
}
-static void add_cache_pkg(CodeGen *g, CacheHash *ch, PackageTableEntry *pkg) {
+static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {
if (buf_len(&pkg->root_src_path) == 0)
return;
@@ -9029,9 +9021,9 @@ void codegen_build_and_link(CodeGen *g) {
codegen_add_time_event(g, "Done");
}
-PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path) {
+ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path) {
init(g);
- PackageTableEntry *pkg = new_package(root_src_dir, root_src_path);
+ ZigPackage *pkg = new_package(root_src_dir, root_src_path);
if (g->std_package != nullptr) {
assert(g->compile_var_package != nullptr);
pkg->package_table.put(buf_create_from_str("std"), g->std_package);
diff --git a/src/codegen.hpp b/src/codegen.hpp
index 4f62cc4cbc71..147b5d2db4a0 100644
--- a/src/codegen.hpp
+++ b/src/codegen.hpp
@@ -48,7 +48,7 @@ void codegen_print_timing_report(CodeGen *g, FILE *f);
void codegen_link(CodeGen *g);
void codegen_build_and_link(CodeGen *g);
-PackageTableEntry *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path);
+ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path);
void codegen_add_assembly(CodeGen *g, Buf *path);
void codegen_add_object(CodeGen *g, Buf *object_path);
diff --git a/src/ir.cpp b/src/ir.cpp
index 87e03ea51910..c7c16bd07ea9 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -258,7 +258,6 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
case ZigTypeIdPointer:
case ZigTypeIdUndefined:
case ZigTypeIdNull:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdErrorSet:
case ZigTypeIdOpaque:
@@ -1123,11 +1122,11 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *
return &const_instruction->base;
}
-static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ImportTableEntry *import) {
+static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) {
IrInstructionConst *const_instruction = ir_build_instruction(irb, scope, source_node);
- const_instruction->base.value.type = irb->codegen->builtin_types.entry_namespace;
+ const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;
const_instruction->base.value.special = ConstValSpecialStatic;
- const_instruction->base.value.data.x_import = import;
+ const_instruction->base.value.data.x_type = import;
return &const_instruction->base;
}
@@ -3824,7 +3823,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
if (tld)
return ir_build_decl_ref(irb, scope, node, tld, lval);
- if (node->owner->any_imports_failed) {
+ if (get_container_scope(node->owner)->any_imports_failed) {
// skip the error message since we had a failing import in this file
// if an import breaks we don't need redundant undeclared identifier errors
return irb->codegen->invalid_instruction;
@@ -6620,9 +6619,12 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char
buf_appendf(name, ")");
return name;
} else {
- //Note: C-imports do not have valid location information
+ // Note: C-imports do not have valid location information
+ // TODO this will get fixed by https://github.com/ziglang/zig/issues/2015
return buf_sprintf("(anonymous %s at %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", kind_name,
- (source_node->owner->path != nullptr) ? buf_ptr(source_node->owner->path) : "(null)", source_node->line + 1, source_node->column + 1);
+ (source_node->owner->data.structure.root_struct->path != nullptr) ?
+ buf_ptr(source_node->owner->data.structure.root_struct->path) :
+ "(null)", source_node->line + 1, source_node->column + 1);
}
}
@@ -12065,7 +12067,6 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
case ZigTypeIdErrorSet:
case ZigTypeIdFn:
case ZigTypeIdOpaque:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdPromise:
@@ -13407,7 +13408,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
case ZigTypeIdOptional:
case ZigTypeIdErrorUnion:
case ZigTypeIdErrorSet:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdOpaque:
@@ -13432,7 +13432,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
case ZigTypeIdErrorSet:
case ZigTypeIdVector:
zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdOpaque:
@@ -14616,7 +14615,6 @@ static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_
case ZigTypeIdEnum:
case ZigTypeIdUnion:
case ZigTypeIdFn:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdPromise:
@@ -15368,7 +15366,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
auto entry = container_scope->decl_table.maybe_get(field_name);
Tld *tld = entry ? entry->value : nullptr;
if (tld && tld->id == TldIdFn) {
- resolve_top_level_decl(ira->codegen, tld, false, source_instr->source_node);
+ resolve_top_level_decl(ira->codegen, tld, source_instr->source_node);
if (tld->resolution == TldResolutionInvalid)
return ira->codegen->invalid_instruction;
TldFn *tld_fn = (TldFn *)tld;
@@ -15557,8 +15555,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
- bool pointer_only = false;
- resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node);
+ resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node);
if (tld->resolution == TldResolutionInvalid)
return ira->codegen->invalid_instruction;
@@ -15971,37 +15968,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
return ira->codegen->invalid_instruction;
}
- } else if (container_type->id == ZigTypeIdNamespace) {
- assert(container_ptr->value.type->id == ZigTypeIdPointer);
- ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
- if (!container_ptr_val)
- return ira->codegen->invalid_instruction;
-
- ConstExprValue *namespace_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val,
- field_ptr_instruction->base.source_node);
- if (namespace_val == nullptr)
- return ira->codegen->invalid_instruction;
- assert(namespace_val->special == ConstValSpecialStatic);
-
- ImportTableEntry *namespace_import = namespace_val->data.x_import;
-
- Tld *tld = find_decl(ira->codegen, &namespace_import->decls_scope->base, field_name);
- if (tld) {
- if (tld->visib_mod == VisibModPrivate &&
- tld->import != source_node->owner)
- {
- ErrorMsg *msg = ir_add_error_node(ira, source_node,
- buf_sprintf("'%s' is private", buf_ptr(field_name)));
- add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
- return ira->codegen->invalid_instruction;
- }
- return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
- } else {
- const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)";
- ir_add_error_node(ira, source_node,
- buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), import_name));
- return ira->codegen->invalid_instruction;
- }
} else {
ir_add_error_node(ira, field_ptr_instruction->base.source_node,
buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
@@ -16281,7 +16247,6 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
case ZigTypeIdEnum:
case ZigTypeIdUnion:
case ZigTypeIdFn:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdPromise:
case ZigTypeIdVector:
@@ -16402,7 +16367,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
case ZigTypeIdEnum:
case ZigTypeIdUnion:
case ZigTypeIdFn:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdPromise:
case ZigTypeIdVector:
@@ -16452,7 +16416,6 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,
case ZigTypeIdComptimeInt:
case ZigTypeIdBoundFn:
case ZigTypeIdMetaType:
- case ZigTypeIdNamespace:
case ZigTypeIdArgTuple:
case ZigTypeIdOpaque:
ir_add_error_node(ira, size_of_instruction->base.source_node,
@@ -16860,7 +16823,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
case ZigTypeIdPointer:
case ZigTypeIdPromise:
case ZigTypeIdFn:
- case ZigTypeIdNamespace:
case ZigTypeIdErrorSet: {
if (pointee_val) {
IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);
@@ -17009,25 +16971,25 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
return ira->codegen->invalid_instruction;
AstNode *source_node = import_instruction->base.source_node;
- ImportTableEntry *import = source_node->owner;
+ ZigType *import = source_node->owner;
Buf *import_target_path;
Buf *search_dir;
- assert(import->package);
- PackageTableEntry *target_package;
- auto package_entry = import->package->package_table.maybe_get(import_target_str);
+ assert(import->data.structure.root_struct->package);
+ ZigPackage *target_package;
+ auto package_entry = import->data.structure.root_struct->package->package_table.maybe_get(import_target_str);
if (package_entry) {
target_package = package_entry->value;
import_target_path = &target_package->root_src_path;
search_dir = &target_package->root_src_dir;
} else {
// try it as a filename
- target_package = import->package;
+ target_package = import->data.structure.root_struct->package;
import_target_path = import_target_str;
// search relative to importing file
search_dir = buf_alloc();
- os_path_dirname(import->path, search_dir);
+ os_path_dirname(import->data.structure.root_struct->path, search_dir);
}
Buf full_path = BUF_INIT;
@@ -17041,10 +17003,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
auto import_entry = ira->codegen->import_table.maybe_get(resolved_path);
if (import_entry) {
- IrInstruction *result = ir_const(ira, &import_instruction->base,
- ira->codegen->builtin_types.entry_namespace);
- result->value.data.x_import = import_entry->value;
- return result;
+ return ir_const_type(ira, &import_instruction->base, import_entry->value);
}
if ((err = file_fetch(ira->codegen, resolved_path, import_code))) {
@@ -17059,13 +17018,11 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
}
}
- ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code);
+ ZigType *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code);
scan_import(ira->codegen, target_import);
- IrInstruction *result = ir_const(ira, &import_instruction->base, ira->codegen->builtin_types.entry_namespace);
- result->value.data.x_import = target_import;
- return result;
+ return ir_const_type(ira, &import_instruction->base, target_import);
}
static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
@@ -17741,7 +17698,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
while ((curr_entry = decl_it.next()) != nullptr) {
// If the definition is unresolved, force it to be resolved again.
if (curr_entry->value->resolution == TldResolutionUnresolved) {
- resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node);
+ resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node);
if (curr_entry->value->resolution != TldResolutionOk) {
return ErrorSemanticAnalyzeFail;
}
@@ -18056,7 +18013,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, AstNode *source_node, ZigTy
case ZigTypeIdComptimeInt:
case ZigTypeIdUndefined:
case ZigTypeIdNull:
- case ZigTypeIdNamespace:
case ZigTypeIdArgTuple:
case ZigTypeIdOpaque:
*out = nullptr;
@@ -18702,14 +18658,14 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
if (type_is_invalid(cimport_result->type))
return ira->codegen->invalid_instruction;
- ImportTableEntry *child_import = allocate(1);
- child_import->decls_scope = create_decls_scope(ira->codegen, node, nullptr, nullptr, child_import);
- child_import->c_import_node = node;
- child_import->package = new_anonymous_package();
- child_import->package->package_table.put(buf_create_from_str("builtin"), ira->codegen->compile_var_package);
- child_import->package->package_table.put(buf_create_from_str("std"), ira->codegen->std_package);
- child_import->di_file = ZigLLVMCreateFile(ira->codegen->dbuilder,
+ RootStruct *root_struct = allocate(1);
+ root_struct->package = new_anonymous_package();
+ root_struct->package->package_table.put(buf_create_from_str("builtin"), ira->codegen->compile_var_package);
+ root_struct->package->package_table.put(buf_create_from_str("std"), ira->codegen->std_package);
+ root_struct->c_import_node = node;
+ root_struct->di_file = ZigLLVMCreateFile(ira->codegen->dbuilder,
buf_ptr(buf_create_from_str("cimport.h")), buf_ptr(buf_create_from_str(".")));
+ ZigType *child_import = get_root_container_type(ira->codegen, "cimport", root_struct);
ZigList errors = {0};
@@ -18738,14 +18694,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
if (ira->codegen->verbose_cimport) {
fprintf(stderr, "\nC imports:\n");
fprintf(stderr, "-----------\n");
- ast_render(ira->codegen, stderr, child_import->root, 4);
+ ast_render(ira->codegen, stderr, child_import->data.structure.decl_node, 4);
}
- scan_decls(ira->codegen, child_import->decls_scope, child_import->root);
+ scan_decls(ira->codegen, get_container_scope(child_import), child_import->data.structure.decl_node);
- IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_namespace);
- result->value.data.x_import = child_import;
- return result;
+ return ir_const_type(ira, &instruction->base, child_import);
}
static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
@@ -18819,10 +18773,10 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru
if (!rel_file_path)
return ira->codegen->invalid_instruction;
- ImportTableEntry *import = get_scope_import(instruction->base.scope);
+ ZigType *import = get_scope_import(instruction->base.scope);
// figure out absolute path to resource
Buf source_dir_path = BUF_INIT;
- os_path_dirname(import->path, &source_dir_path);
+ os_path_dirname(import->data.structure.root_struct->path, &source_dir_path);
Buf *resolve_paths[] = {
&source_dir_path,
@@ -20179,7 +20133,6 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
case ZigTypeIdComptimeInt:
case ZigTypeIdUndefined:
case ZigTypeIdNull:
- case ZigTypeIdNamespace:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
case ZigTypeIdVoid:
@@ -21025,7 +20978,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
case ZigTypeIdOpaque:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
- case ZigTypeIdNamespace:
case ZigTypeIdUnreachable:
case ZigTypeIdComptimeFloat:
case ZigTypeIdComptimeInt:
@@ -21185,7 +21137,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
case ZigTypeIdOpaque:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
- case ZigTypeIdNamespace:
case ZigTypeIdUnreachable:
case ZigTypeIdComptimeFloat:
case ZigTypeIdComptimeInt:
@@ -21343,7 +21294,6 @@ static bool type_can_bit_cast(ZigType *t) {
case ZigTypeIdOpaque:
case ZigTypeIdBoundFn:
case ZigTypeIdArgTuple:
- case ZigTypeIdNamespace:
case ZigTypeIdUnreachable:
case ZigTypeIdComptimeFloat:
case ZigTypeIdComptimeInt:
@@ -21516,7 +21466,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
Tld *tld = instruction->tld;
LVal lval = instruction->lval;
- resolve_top_level_decl(ira->codegen, tld, lval == LValPtr, instruction->base.source_node);
+ resolve_top_level_decl(ira->codegen, tld, instruction->base.source_node);
if (tld->resolution == TldResolutionInvalid)
return ira->codegen->invalid_instruction;
diff --git a/src/main.cpp b/src/main.cpp
index d2099a9f80c7..eb92db357622 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -215,7 +215,7 @@ struct CliPkg {
CliPkg *parent;
};
-static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
+static void add_package(CodeGen *g, CliPkg *cli_pkg, ZigPackage *pkg) {
for (size_t i = 0; i < cli_pkg->children.length; i += 1) {
CliPkg *child_cli_pkg = cli_pkg->children.at(i);
@@ -223,10 +223,10 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) {
Buf *basename = buf_alloc();
os_path_split(buf_create_from_str(child_cli_pkg->path), dirname, basename);
- PackageTableEntry *child_pkg = codegen_create_package(g, buf_ptr(dirname), buf_ptr(basename));
+ ZigPackage *child_pkg = codegen_create_package(g, buf_ptr(dirname), buf_ptr(basename));
auto entry = pkg->package_table.put_unique(buf_create_from_str(child_cli_pkg->name), child_pkg);
if (entry) {
- PackageTableEntry *existing_pkg = entry->value;
+ ZigPackage *existing_pkg = entry->value;
Buf *full_path = buf_alloc();
os_path_join(&existing_pkg->root_src_dir, &existing_pkg->root_src_path, full_path);
fprintf(stderr, "Unable to add package '%s'->'%s': already exists as '%s'\n",
@@ -543,7 +543,7 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
- PackageTableEntry *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname),
+ ZigPackage *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname),
buf_ptr(&build_file_basename));
g->root_package->package_table.put(buf_create_from_str("@build"), build_pkg);
g->enable_cache = get_cache_opt(enable_cache, true);
@@ -1145,7 +1145,7 @@ int main(int argc, char **argv) {
}
} else if (cmd == CmdTranslateC) {
codegen_translate_c(g, in_file_buf);
- ast_render(g, stdout, g->root_import->root, 4);
+ ast_render(g, stdout, g->root_import->data.structure.decl_node, 4);
if (timing_info)
codegen_print_timing_report(g, stdout);
return EXIT_SUCCESS;
diff --git a/src/parser.cpp b/src/parser.cpp
index 6fe78c14c341..2fd453c67fc4 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -18,7 +18,7 @@ struct ParseContext {
Buf *buf;
size_t current_token;
ZigList *tokens;
- ImportTableEntry *owner;
+ ZigType *owner;
ErrColor err_color;
};
@@ -130,8 +130,10 @@ static void ast_error(ParseContext *pc, Token *token, const char *format, ...) {
va_end(ap);
- ErrorMsg *err = err_msg_create_with_line(pc->owner->path, token->start_line, token->start_column,
- pc->owner->source_code, pc->owner->line_offsets, msg);
+ ErrorMsg *err = err_msg_create_with_line(pc->owner->data.structure.root_struct->path,
+ token->start_line, token->start_column,
+ pc->owner->data.structure.root_struct->source_code,
+ pc->owner->data.structure.root_struct->line_offsets, msg);
err->line_start = token->start_line;
err->column_start = token->start_column;
@@ -148,8 +150,10 @@ static void ast_asm_error(ParseContext *pc, AstNode *node, size_t offset, const
Buf *msg = buf_vprintf(format, ap);
va_end(ap);
- ErrorMsg *err = err_msg_create_with_line(pc->owner->path, node->line, node->column,
- pc->owner->source_code, pc->owner->line_offsets, msg);
+ ErrorMsg *err = err_msg_create_with_line(pc->owner->data.structure.root_struct->path,
+ node->line, node->column,
+ pc->owner->data.structure.root_struct->source_code,
+ pc->owner->data.structure.root_struct->line_offsets, msg);
print_err_msg(err, pc->err_color);
exit(EXIT_FAILURE);
@@ -570,9 +574,7 @@ static void ast_parse_asm_template(ParseContext *pc, AstNode *node) {
}
}
-AstNode *ast_parse(Buf *buf, ZigList *tokens, ImportTableEntry *owner,
- ErrColor err_color)
-{
+AstNode *ast_parse(Buf *buf, ZigList *tokens, ZigType *owner, ErrColor err_color) {
ParseContext pc = {};
pc.err_color = err_color;
pc.owner = owner;
diff --git a/src/parser.hpp b/src/parser.hpp
index 7243431e4fcc..73950993f394 100644
--- a/src/parser.hpp
+++ b/src/parser.hpp
@@ -16,7 +16,7 @@ ATTRIBUTE_PRINTF(2, 3)
void ast_token_error(Token *token, const char *format, ...);
-AstNode * ast_parse(Buf *buf, ZigList *tokens, ImportTableEntry *owner, ErrColor err_color);
+AstNode * ast_parse(Buf *buf, ZigList *tokens, ZigType *owner, ErrColor err_color);
void ast_print(AstNode *node, int indent);
diff --git a/src/translate_c.cpp b/src/translate_c.cpp
index a0db33906567..1c37627feaf0 100644
--- a/src/translate_c.cpp
+++ b/src/translate_c.cpp
@@ -76,7 +76,7 @@ struct TransScopeWhile {
};
struct Context {
- ImportTableEntry *import;
+ ZigType *import;
ZigList *errors;
VisibMod visib_mod;
bool want_export;
@@ -4732,7 +4732,7 @@ static void process_preprocessor_entities(Context *c, ZigClangASTUnit *zunit) {
}
}
-Error parse_h_buf(ImportTableEntry *import, ZigList *errors, Buf *source,
+Error parse_h_buf(ZigType *import, ZigList *errors, Buf *source,
CodeGen *codegen, AstNode *source_node)
{
Error err;
@@ -4748,7 +4748,7 @@ Error parse_h_buf(ImportTableEntry *import, ZigList *errors, Buf *so
return err;
}
-Error parse_h_file(ImportTableEntry *import, ZigList *errors, const char *target_file,
+Error parse_h_file(ZigType *import, ZigList *errors, const char *target_file,
CodeGen *codegen, AstNode *source_node)
{
Context context = {0};
@@ -4958,7 +4958,8 @@ Error parse_h_file(ImportTableEntry *import, ZigList *errors, const
render_macros(c);
render_aliases(c);
- import->root = c->root;
+ import->data.structure.decl_node = c->root;
+ import->data.structure.decls_scope->base.source_node = c->root;
return ErrorNone;
}
diff --git a/src/translate_c.hpp b/src/translate_c.hpp
index 4323e98c1eca..c4bd270c21bc 100644
--- a/src/translate_c.hpp
+++ b/src/translate_c.hpp
@@ -11,10 +11,10 @@
#include "all_types.hpp"
-Error parse_h_file(ImportTableEntry *import, ZigList *errors, const char *target_file,
+Error parse_h_file(ZigType *import, ZigList *errors, const char *target_file,
CodeGen *codegen, AstNode *source_node);
-Error parse_h_buf(ImportTableEntry *import, ZigList *errors, Buf *source,
+Error parse_h_buf(ZigType *import, ZigList *errors, Buf *source,
CodeGen *codegen, AstNode *source_node);
#endif
diff --git a/std/hash_map.zig b/std/hash_map.zig
index 4519890bb75b..6ae9e8e2c327 100644
--- a/std/hash_map.zig
+++ b/std/hash_map.zig
@@ -486,7 +486,6 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type
builtin.TypeId.ErrorSet => return autoHash(@errorToInt(key), rng),
builtin.TypeId.Promise, builtin.TypeId.Fn => return autoHash(@ptrToInt(key), rng),
- builtin.TypeId.Namespace,
builtin.TypeId.BoundFn,
builtin.TypeId.ComptimeFloat,
builtin.TypeId.ComptimeInt,
@@ -532,7 +531,6 @@ pub fn autoEql(a: var, b: @typeOf(a)) bool {
builtin.TypeId.Float,
builtin.TypeId.ComptimeFloat,
builtin.TypeId.ComptimeInt,
- builtin.TypeId.Namespace,
builtin.TypeId.Promise,
builtin.TypeId.Enum,
builtin.TypeId.BoundFn,
diff --git a/std/testing.zig b/std/testing.zig
index 2f14974481e6..359a7879604d 100644
--- a/std/testing.zig
+++ b/std/testing.zig
@@ -44,7 +44,6 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
TypeId.ComptimeFloat,
TypeId.ComptimeInt,
TypeId.Enum,
- TypeId.Namespace,
TypeId.Fn,
TypeId.Promise,
TypeId.Vector,
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 1e6dc846050e..aa377286c478 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -2,6 +2,47 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
+ cases.add(
+ "@typeInfo causing depend on itself compile error",
+ \\const start = struct {
+ \\ fn crash() bug() {
+ \\ return bug;
+ \\ }
+ \\};
+ \\fn bug() void {
+ \\ _ = @typeInfo(start).Struct;
+ \\}
+ \\export fn entry() void {
+ \\ var boom = start.crash();
+ \\}
+ ,
+ ".tmp_source.zig:2:5: error: 'crash' depends on itself",
+ );
+
+ cases.add(
+ "enum field value references enum",
+ \\pub const Foo = extern enum {
+ \\ A = Foo.B,
+ \\ C = D,
+ \\};
+ \\export fn entry() void {
+ \\ var s: Foo = Foo.E;
+ \\}
+ ,
+ ".tmp_source.zig:1:17: error: 'Foo' depends on itself",
+ );
+
+ cases.add(
+ "top level decl dependency loop",
+ \\const a : @typeOf(b) = 0;
+ \\const b : @typeOf(a) = 0;
+ \\export fn entry() void {
+ \\ const c = a + b;
+ \\}
+ ,
+ ".tmp_source.zig:1:1: error: 'a' depends on itself",
+ );
+
cases.addTest(
"not an enum type",
\\export fn entry() void {
@@ -917,23 +958,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
".tmp_source.zig:1:1: error: non-extern function has no body",
);
- cases.add(
- "@typeInfo causing depend on itself compile error",
- \\const start = struct {
- \\ fn crash() bug() {
- \\ return bug;
- \\ }
- \\};
- \\fn bug() void {
- \\ _ = @typeInfo(start).Struct;
- \\}
- \\export fn entry() void {
- \\ var boom = start.crash();
- \\}
- ,
- ".tmp_source.zig:2:5: error: 'crash' depends on itself",
- );
-
cases.add(
"@handle() called outside of function definition",
\\var handle_undef: promise = undefined;
@@ -1182,19 +1206,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
break :x tc;
});
- cases.add(
- "enum field value references enum",
- \\pub const Foo = extern enum {
- \\ A = Foo.B,
- \\ C = D,
- \\};
- \\export fn entry() void {
- \\ var s: Foo = Foo.E;
- \\}
- ,
- ".tmp_source.zig:1:17: error: 'Foo' depends on itself",
- );
-
cases.add(
"@floatToInt comptime safety",
\\comptime {
@@ -2622,17 +2633,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
".tmp_source.zig:1:8: error: invalid builtin function: 'bogus'",
);
- cases.add(
- "top level decl dependency loop",
- \\const a : @typeOf(b) = 0;
- \\const b : @typeOf(a) = 0;
- \\export fn entry() void {
- \\ const c = a + b;
- \\}
- ,
- ".tmp_source.zig:1:1: error: 'a' depends on itself",
- );
-
cases.add(
"noalias on non pointer param",
\\fn f(noalias x: i32) void {}
diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig
index 91cab78bc722..1ff9687836d1 100644
--- a/test/stage1/behavior/misc.zig
+++ b/test/stage1/behavior/misc.zig
@@ -469,7 +469,7 @@ test "@typeId" {
expect(@typeId(AUnionEnum) == Tid.Union);
expect(@typeId(AUnion) == Tid.Union);
expect(@typeId(fn () void) == Tid.Fn);
- expect(@typeId(@typeOf(builtin)) == Tid.Namespace);
+ expect(@typeId(@typeOf(builtin)) == Tid.Type);
// TODO bound fn
// TODO arg tuple
// TODO opaque
diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig
index dc185cc96038..510a56f61938 100644
--- a/test/stage1/behavior/type_info.zig
+++ b/test/stage1/behavior/type_info.zig
@@ -186,7 +186,7 @@ fn testUnion() void {
expect(TypeId(typeinfo_info) == TypeId.Union);
expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
expect(typeinfo_info.Union.tag_type.? == TypeId);
- expect(typeinfo_info.Union.fields.len == 25);
+ expect(typeinfo_info.Union.fields.len == 24);
expect(typeinfo_info.Union.fields[4].enum_field != null);
expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));