Skip to content

Commit

Permalink
remove namespace type; files are empty structs
Browse files Browse the repository at this point in the history
closes #1047
  • Loading branch information
andrewrk committed Feb 28, 2019
1 parent d093f51 commit 5424b43
Show file tree
Hide file tree
Showing 18 changed files with 329 additions and 411 deletions.
25 changes: 14 additions & 11 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -6785,7 +6785,6 @@ pub const TypeId = enum {
Enum,
Union,
Fn,
Namespace,
Block,
BoundFn,
ArgTuple,
Expand Down Expand Up @@ -6820,7 +6819,6 @@ pub const TypeInfo = union(TypeId) {
Enum: Enum,
Union: Union,
Fn: Fn,
Namespace: void,
BoundFn: Fn,
ArgTuple: void,
Opaque: void,
Expand Down Expand Up @@ -8167,17 +8165,18 @@ coding style.
</p>
<ul>
<li>
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#}.
</li>
<li>
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#}.
</li>
<li>
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#}.
</li>
<li>
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#}.
</li>
<li>
Otherwise, {#syntax#}x{#endsyntax#} should be {#syntax#}snake_case{#endsyntax#}.
Expand All @@ -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 {
Expand Down Expand Up @@ -8231,7 +8232,9 @@ const xml_document =
\\<document>
\\</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 {}
Expand Down
12 changes: 0 additions & 12 deletions src-self-hosted/type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -89,7 +87,6 @@ pub const Type = struct {
Id.ComptimeInt,
Id.Undefined,
Id.Null,
Id.Namespace,
Id.BoundFn,
Id.ArgTuple,
Id.Opaque,
Expand Down Expand Up @@ -123,7 +120,6 @@ pub const Type = struct {
Id.ComptimeInt,
Id.Undefined,
Id.Null,
Id.Namespace,
Id.BoundFn,
Id.ArgTuple,
Id.Opaque,
Expand Down Expand Up @@ -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,

Expand Down
84 changes: 40 additions & 44 deletions src/all_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "libc_installation.hpp"

struct AstNode;
struct ImportTableEntry;
struct ZigFn;
struct Scope;
struct ScopeBlock;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Buf *, ZigPackage *, buf_hash, buf_eql_buf> 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<size_t> *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<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
RootStruct *root_struct;

uint32_t src_field_count;
uint32_t gen_field_count;
Expand Down Expand Up @@ -1232,7 +1250,6 @@ enum ZigTypeId {
ZigTypeIdEnum,
ZigTypeIdUnion,
ZigTypeIdFn,
ZigTypeIdNamespace,
ZigTypeIdBoundFn,
ZigTypeIdArgTuple,
ZigTypeIdOpaque,
Expand Down Expand Up @@ -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<Buf *, PackageTableEntry *, buf_hash, buf_eql_buf> package_table;
};

struct ImportTableEntry {
AstNode *root;
Buf *path; // relative to root_package->root_src_dir
PackageTableEntry *package;
ZigLLVMDIFile *di_file;
Buf *source_code;
ZigList<size_t> *line_offsets;
ScopeDecls *decls_scope;
AstNode *c_import_node;
bool any_imports_failed;
bool scanned;

ZigList<AstNode *> use_decls;
};

enum FnAnalState {
FnAnalStateReady,
FnAnalStateProbing,
Expand Down Expand Up @@ -1670,7 +1664,7 @@ struct CodeGen {
LLVMValueRef return_err_fn;

// reminder: hash tables must be initialized before use
HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table;
HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> import_table;
HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;
HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> primitive_type_table;
HashMap<TypeId, ZigType *, type_id_hash, type_id_eql> type_table;
Expand All @@ -1684,7 +1678,7 @@ struct CodeGen {
HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;
HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;

ZigList<ImportTableEntry *> import_queue;
ZigList<ZigType *> import_queue;
size_t import_queue_index;
ZigList<Tld *> resolve_queue;
size_t resolve_queue_index;
Expand All @@ -1699,14 +1693,14 @@ struct CodeGen {
ZigList<ErrorTableEntry *> 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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1945,13 +1938,16 @@ struct ScopeDecls {
Scope base;

HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> decl_table;
bool safety_off;
ZigList<AstNode *> 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.
Expand Down Expand Up @@ -3507,7 +3503,7 @@ struct FnWalkTypes {
};

struct FnWalkVars {
ImportTableEntry *import;
ZigType *import;
LLVMValueRef llvm_fn;
ZigFn *fn;
ZigVar *var;
Expand Down
Loading

0 comments on commit 5424b43

Please sign in to comment.