commit c9474faa4e6cfd6480c1bd24216c26f4320e3c29 (tree)
parent f27d82fe90e1d0007bf2d3ef52eac8cdbc381e0d
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Mon, 10 Sep 2018 12:30:57 -0400
Merge remote-tracking branch 'origin/master' into llvm7
Diffstat:
33 files changed, 5794 insertions(+), 3670 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -199,7 +199,7 @@ else()
if(MSVC)
set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -D_CRT_SECURE_NO_WARNINGS /w")
else()
- set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -fno-exceptions -fno-rtti -Wno-comment -Wno-class-memaccess -Wno-unknown-warning-option")
+ set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -fno-exceptions -fno-rtti -Wno-comment")
endif()
set_target_properties(embedded_lld_lib PROPERTIES
COMPILE_FLAGS ${ZIG_LLD_COMPILE_FLAGS}
@@ -775,20 +775,25 @@ include_directories(
"${CMAKE_SOURCE_DIR}/src"
)
-if(MSVC)
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /w")
-elseif(MINGW)
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Werror -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")
-else()
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -Wall")
+# These have to go before the -Wno- flags
+set(EXE_CFLAGS "-std=c++11")
+if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
+ if(MSVC)
+ set(EXE_CFLAGS "${EXE_CFLAGS} /w")
+ elseif(MINGW)
+ set(EXE_CFLAGS "${EXE_CFLAGS} -Wall -Werror -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")
+ else()
+ set(EXE_CFLAGS "${EXE_CFLAGS} -Werror -Wall")
+ endif()
endif()
if(MSVC)
- set(EXE_CFLAGS "-std=c++11")
+ set(EXE_CFLAGS "${EXE_CFLAGS}")
else()
- set(EXE_CFLAGS "-std=c++11 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fno-exceptions -fno-rtti -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces")
+ set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fno-exceptions -fno-rtti -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces")
endif()
+
set(EXE_LDFLAGS " ")
if(MINGW)
set(EXE_LDFLAGS "-static -static-libgcc -static-libstdc++")
diff --git a/doc/langref.html.in b/doc/langref.html.in
@@ -1587,7 +1587,7 @@ test "pointer casting" {
// operation that Zig cannot protect you against. Use @ptrCast only when other
// conversions are not possible.
const bytes align(@alignOf(u32)) = []u8{ 0x12, 0x12, 0x12, 0x12 };
- const u32_ptr = @ptrCast(*const u32, &bytes[0]);
+ const u32_ptr = @ptrCast(*const u32, &bytes);
assert(u32_ptr.* == 0x12121212);
// Even this example is contrived - there are better ways to do the above than
diff --git a/src/all_types.hpp b/src/all_types.hpp
@@ -20,12 +20,12 @@
struct AstNode;
struct ImportTableEntry;
-struct FnTableEntry;
+struct ZigFn;
struct Scope;
struct ScopeBlock;
struct ScopeFnDef;
-struct TypeTableEntry;
-struct VariableTableEntry;
+struct ZigType;
+struct ZigVar;
struct ErrorTableEntry;
struct BuiltinFnEntry;
struct TypeStructField;
@@ -40,10 +40,17 @@ struct Tld;
struct TldExport;
struct IrAnalyze;
+enum X64CABIClass {
+ X64CABIClass_Unknown,
+ X64CABIClass_MEMORY,
+ X64CABIClass_INTEGER,
+ X64CABIClass_SSE,
+};
+
struct IrExecutable {
ZigList<IrBasicBlock *> basic_block_list;
Buf *name;
- FnTableEntry *name_fn;
+ ZigFn *name_fn;
size_t mem_slot_count;
size_t next_debug_id;
size_t *backward_branch_count;
@@ -51,7 +58,7 @@ struct IrExecutable {
bool invalid;
bool is_inline;
bool is_generic_instantiation;
- FnTableEntry *fn_entry;
+ ZigFn *fn_entry;
Buf *c_import_buf;
AstNode *source_node;
IrExecutable *parent_exec;
@@ -69,7 +76,7 @@ struct IrExecutable {
IrBasicBlock *coro_normal_final;
IrBasicBlock *coro_suspend_block;
IrBasicBlock *coro_final_cleanup_block;
- VariableTableEntry *coro_allocator_var;
+ ZigVar *coro_allocator_var;
};
enum OutType {
@@ -191,7 +198,7 @@ struct ConstPtrValue {
uint64_t addr;
} hard_coded_addr;
struct {
- FnTableEntry *fn_entry;
+ ZigFn *fn_entry;
} fn;
} data;
};
@@ -202,7 +209,7 @@ struct ConstErrValue {
};
struct ConstBoundFnValue {
- FnTableEntry *fn;
+ ZigFn *fn;
IrInstruction *first_arg;
};
@@ -251,7 +258,7 @@ struct ConstGlobalRefs {
};
struct ConstExprValue {
- TypeTableEntry *type;
+ ZigType *type;
ConstValSpecial special;
ConstGlobalRefs *global_refs;
@@ -265,7 +272,7 @@ struct ConstExprValue {
float128_t x_f128;
bool x_bool;
ConstBoundFnValue x_bound_fn;
- TypeTableEntry *x_type;
+ ZigType *x_type;
ConstExprValue *x_optional;
ConstErrValue x_err_union;
ErrorTableEntry *x_err_set;
@@ -337,7 +344,7 @@ struct Tld {
struct TldVar {
Tld base;
- VariableTableEntry *var;
+ ZigVar *var;
Buf *extern_lib_name;
Buf *section_name;
};
@@ -345,7 +352,7 @@ struct TldVar {
struct TldFn {
Tld base;
- FnTableEntry *fn_entry;
+ ZigFn *fn_entry;
Buf *extern_lib_name;
};
@@ -353,7 +360,7 @@ struct TldContainer {
Tld base;
ScopeDecls *decls_scope;
- TypeTableEntry *type_entry;
+ ZigType *type_entry;
};
struct TldCompTime {
@@ -370,7 +377,7 @@ struct TypeEnumField {
struct TypeUnionField {
Buf *name;
TypeEnumField *enum_field;
- TypeTableEntry *type_entry;
+ ZigType *type_entry;
AstNode *decl_node;
uint32_t gen_index;
};
@@ -973,11 +980,11 @@ struct AstNode {
// this struct is allocated with allocate_nonzero
struct FnTypeParamInfo {
bool is_noalias;
- TypeTableEntry *type;
+ ZigType *type;
};
struct GenericFnTypeId {
- FnTableEntry *fn_entry;
+ ZigFn *fn_entry;
ConstExprValue *params;
size_t param_count;
};
@@ -986,14 +993,14 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id);
bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b);
struct FnTypeId {
- TypeTableEntry *return_type;
+ ZigType *return_type;
FnTypeParamInfo *param_info;
size_t param_count;
size_t next_param_index;
bool is_var_args;
CallingConvention cc;
uint32_t alignment;
- TypeTableEntry *async_allocator_type;
+ ZigType *async_allocator_type;
};
uint32_t fn_type_id_hash(FnTypeId*);
@@ -1004,34 +1011,34 @@ enum PtrLen {
PtrLenSingle,
};
-struct TypeTableEntryPointer {
- TypeTableEntry *child_type;
+struct ZigTypePointer {
+ ZigType *child_type;
PtrLen ptr_len;
bool is_const;
bool is_volatile;
uint32_t alignment;
uint32_t bit_offset;
uint32_t unaligned_bit_count;
- TypeTableEntry *slice_parent;
+ ZigType *slice_parent;
};
-struct TypeTableEntryInt {
+struct ZigTypeInt {
uint32_t bit_count;
bool is_signed;
};
-struct TypeTableEntryFloat {
+struct ZigTypeFloat {
size_t bit_count;
};
-struct TypeTableEntryArray {
- TypeTableEntry *child_type;
+struct ZigTypeArray {
+ ZigType *child_type;
uint64_t len;
};
struct TypeStructField {
Buf *name;
- TypeTableEntry *type_entry;
+ ZigType *type_entry;
size_t src_index;
size_t gen_index;
// offset from the memory at gen_index
@@ -1040,7 +1047,7 @@ struct TypeStructField {
size_t unaligned_bit_count;
AstNode *decl_node;
};
-struct TypeTableEntryStruct {
+struct ZigTypeStruct {
AstNode *decl_node;
ContainerLayout layout;
uint32_t src_field_count;
@@ -1068,28 +1075,28 @@ struct TypeTableEntryStruct {
HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
};
-struct TypeTableEntryOptional {
- TypeTableEntry *child_type;
+struct ZigTypeOptional {
+ ZigType *child_type;
};
-struct TypeTableEntryErrorUnion {
- TypeTableEntry *err_set_type;
- TypeTableEntry *payload_type;
+struct ZigTypeErrorUnion {
+ ZigType *err_set_type;
+ ZigType *payload_type;
};
-struct TypeTableEntryErrorSet {
+struct ZigTypeErrorSet {
uint32_t err_count;
ErrorTableEntry **errors;
- FnTableEntry *infer_fn;
+ ZigFn *infer_fn;
};
-struct TypeTableEntryEnum {
+struct ZigTypeEnum {
AstNode *decl_node;
ContainerLayout layout;
uint32_t src_field_count;
TypeEnumField *fields;
bool is_invalid; // true if any fields are invalid
- TypeTableEntry *tag_int_type;
+ ZigType *tag_int_type;
ScopeDecls *decls_scope;
@@ -1107,17 +1114,17 @@ struct TypeTableEntryEnum {
HashMap<Buf *, TypeEnumField *, buf_hash, buf_eql_buf> fields_by_name;
};
-uint32_t type_ptr_hash(const TypeTableEntry *ptr);
-bool type_ptr_eql(const TypeTableEntry *a, const TypeTableEntry *b);
+uint32_t type_ptr_hash(const ZigType *ptr);
+bool type_ptr_eql(const ZigType *a, const ZigType *b);
-struct TypeTableEntryUnion {
+struct ZigTypeUnion {
AstNode *decl_node;
ContainerLayout layout;
uint32_t src_field_count;
uint32_t gen_field_count;
TypeUnionField *fields;
bool is_invalid; // true if any fields are invalid
- TypeTableEntry *tag_type; // always an enum or null
+ ZigType *tag_type; // always an enum or null
LLVMTypeRef union_type_ref;
ScopeDecls *decls_scope;
@@ -1142,7 +1149,7 @@ struct TypeTableEntryUnion {
bool have_explicit_tag_type;
uint32_t union_size_bytes;
- TypeTableEntry *most_aligned_union_member;
+ ZigType *most_aligned_union_member;
HashMap<Buf *, TypeUnionField *, buf_hash, buf_eql_buf> fields_by_name;
};
@@ -1151,61 +1158,61 @@ struct FnGenParamInfo {
size_t src_index;
size_t gen_index;
bool is_byval;
- TypeTableEntry *type;
+ ZigType *type;
};
-struct TypeTableEntryFn {
+struct ZigTypeFn {
FnTypeId fn_type_id;
bool is_generic;
- TypeTableEntry *gen_return_type;
+ ZigType *gen_return_type;
size_t gen_param_count;
FnGenParamInfo *gen_param_info;
LLVMTypeRef raw_type_ref;
- TypeTableEntry *bound_fn_parent;
+ ZigType *bound_fn_parent;
};
-struct TypeTableEntryBoundFn {
- TypeTableEntry *fn_type;
+struct ZigTypeBoundFn {
+ ZigType *fn_type;
};
-struct TypeTableEntryPromise {
+struct ZigTypePromise {
// null if `promise` instead of `promise->T`
- TypeTableEntry *result_type;
-};
-
-enum TypeTableEntryId {
- TypeTableEntryIdInvalid,
- TypeTableEntryIdMetaType,
- TypeTableEntryIdVoid,
- TypeTableEntryIdBool,
- TypeTableEntryIdUnreachable,
- TypeTableEntryIdInt,
- TypeTableEntryIdFloat,
- TypeTableEntryIdPointer,
- TypeTableEntryIdArray,
- TypeTableEntryIdStruct,
- TypeTableEntryIdComptimeFloat,
- TypeTableEntryIdComptimeInt,
- TypeTableEntryIdUndefined,
- TypeTableEntryIdNull,
- TypeTableEntryIdOptional,
- TypeTableEntryIdErrorUnion,
- TypeTableEntryIdErrorSet,
- TypeTableEntryIdEnum,
- TypeTableEntryIdUnion,
- TypeTableEntryIdFn,
- TypeTableEntryIdNamespace,
- TypeTableEntryIdBlock,
- TypeTableEntryIdBoundFn,
- TypeTableEntryIdArgTuple,
- TypeTableEntryIdOpaque,
- TypeTableEntryIdPromise,
-};
-
-struct TypeTableEntry {
- TypeTableEntryId id;
+ ZigType *result_type;
+};
+
+enum ZigTypeId {
+ ZigTypeIdInvalid,
+ ZigTypeIdMetaType,
+ ZigTypeIdVoid,
+ ZigTypeIdBool,
+ ZigTypeIdUnreachable,
+ ZigTypeIdInt,
+ ZigTypeIdFloat,
+ ZigTypeIdPointer,
+ ZigTypeIdArray,
+ ZigTypeIdStruct,
+ ZigTypeIdComptimeFloat,
+ ZigTypeIdComptimeInt,
+ ZigTypeIdUndefined,
+ ZigTypeIdNull,
+ ZigTypeIdOptional,
+ ZigTypeIdErrorUnion,
+ ZigTypeIdErrorSet,
+ ZigTypeIdEnum,
+ ZigTypeIdUnion,
+ ZigTypeIdFn,
+ ZigTypeIdNamespace,
+ ZigTypeIdBlock,
+ ZigTypeIdBoundFn,
+ ZigTypeIdArgTuple,
+ ZigTypeIdOpaque,
+ ZigTypeIdPromise,
+};
+
+struct ZigType {
+ ZigTypeId id;
Buf name;
LLVMTypeRef type_ref;
@@ -1216,26 +1223,26 @@ struct TypeTableEntry {
bool gen_h_loop_flag;
union {
- TypeTableEntryPointer pointer;
- TypeTableEntryInt integral;
- TypeTableEntryFloat floating;
- TypeTableEntryArray array;
- TypeTableEntryStruct structure;
- TypeTableEntryOptional maybe;
- TypeTableEntryErrorUnion error_union;
- TypeTableEntryErrorSet error_set;
- TypeTableEntryEnum enumeration;
- TypeTableEntryUnion unionation;
- TypeTableEntryFn fn;
- TypeTableEntryBoundFn bound_fn;
- TypeTableEntryPromise promise;
+ ZigTypePointer pointer;
+ ZigTypeInt integral;
+ ZigTypeFloat floating;
+ ZigTypeArray array;
+ ZigTypeStruct structure;
+ ZigTypeOptional maybe;
+ ZigTypeErrorUnion error_union;
+ ZigTypeErrorSet error_set;
+ ZigTypeEnum enumeration;
+ ZigTypeUnion unionation;
+ ZigTypeFn fn;
+ ZigTypeBoundFn bound_fn;
+ ZigTypePromise promise;
} data;
// use these fields to make sure we don't duplicate type table entries for the same type
- TypeTableEntry *pointer_parent[2]; // [0 - mut, 1 - const]
- TypeTableEntry *optional_parent;
- TypeTableEntry *promise_parent;
- TypeTableEntry *promise_frame_parent;
+ ZigType *pointer_parent[2]; // [0 - mut, 1 - const]
+ ZigType *optional_parent;
+ ZigType *promise_parent;
+ ZigType *promise_frame_parent;
// If we generate a constant name value for this type, we memoize it here.
// The type of this is array
ConstExprValue *cached_const_name_val;
@@ -1282,7 +1289,7 @@ struct FnExport {
GlobalLinkageId linkage;
};
-struct FnTableEntry {
+struct ZigFn {
LLVMValueRef llvm_value;
const char *llvm_name;
AstNode *proto_node;
@@ -1291,11 +1298,11 @@ struct FnTableEntry {
Scope *child_scope; // parent is scope for last parameter
ScopeBlock *def_scope; // parent is child_scope
Buf symbol_name;
- TypeTableEntry *type_entry; // function type
+ ZigType *type_entry; // function type
// in the case of normal functions this is the implicit return type
// in the case of async functions this is the implicit return type according to the
// zig source code, not according to zig ir
- TypeTableEntry *src_implicit_return_type;
+ ZigType *src_implicit_return_type;
bool is_test;
FnInline fn_inline;
FnAnalState anal_state;
@@ -1310,7 +1317,7 @@ struct FnTableEntry {
AstNode *fn_static_eval_set_node;
ZigList<IrInstruction *> alloca_list;
- ZigList<VariableTableEntry *> variable_list;
+ ZigList<ZigVar *> variable_list;
Buf *section_name;
AstNode *set_alignstack_node;
@@ -1323,8 +1330,8 @@ struct FnTableEntry {
bool calls_or_awaits_errorable_fn;
};
-uint32_t fn_table_entry_hash(FnTableEntry*);
-bool fn_table_entry_eql(FnTableEntry *a, FnTableEntry *b);
+uint32_t fn_table_entry_hash(ZigFn*);
+bool fn_table_entry_eql(ZigFn *a, ZigFn *b);
enum BuiltinFnId {
BuiltinFnIdInvalid,
@@ -1445,11 +1452,11 @@ uint32_t fn_eval_hash(Scope*);
bool fn_eval_eql(Scope *a, Scope *b);
struct TypeId {
- TypeTableEntryId id;
+ ZigTypeId id;
union {
struct {
- TypeTableEntry *child_type;
+ ZigType *child_type;
PtrLen ptr_len;
bool is_const;
bool is_volatile;
@@ -1458,7 +1465,7 @@ struct TypeId {
uint32_t unaligned_bit_count;
} pointer;
struct {
- TypeTableEntry *child_type;
+ ZigType *child_type;
uint64_t size;
} array;
struct {
@@ -1466,8 +1473,8 @@ struct TypeId {
uint32_t bit_count;
} integer;
struct {
- TypeTableEntry *err_set_type;
- TypeTableEntry *payload_type;
+ ZigType *err_set_type;
+ ZigType *payload_type;
} error_union;
} data;
};
@@ -1563,17 +1570,17 @@ struct CodeGen {
// reminder: hash tables must be initialized before use
HashMap<Buf *, ImportTableEntry *, buf_hash, buf_eql_buf> import_table;
HashMap<Buf *, BuiltinFnEntry *, buf_hash, buf_eql_buf> builtin_fn_table;
- HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> primitive_type_table;
- HashMap<TypeId, TypeTableEntry *, type_id_hash, type_id_eql> type_table;
- HashMap<FnTypeId *, TypeTableEntry *, fn_type_id_hash, fn_type_id_eql> fn_type_table;
+ HashMap<Buf *, ZigType *, buf_hash, buf_eql_buf> primitive_type_table;
+ HashMap<TypeId, ZigType *, type_id_hash, type_id_eql> type_table;
+ HashMap<FnTypeId *, ZigType *, fn_type_id_hash, fn_type_id_eql> fn_type_table;
HashMap<Buf *, ErrorTableEntry *, buf_hash, buf_eql_buf> error_table;
- HashMap<GenericFnTypeId *, FnTableEntry *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;
+ HashMap<GenericFnTypeId *, ZigFn *, generic_fn_type_id_hash, generic_fn_type_id_eql> generic_table;
HashMap<Scope *, IrInstruction *, fn_eval_hash, fn_eval_eql> memoized_fn_eval_table;
HashMap<ZigLLVMFnKey, LLVMValueRef, zig_llvm_fn_key_hash, zig_llvm_fn_key_eql> llvm_fn_table;
HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> exported_symbol_names;
HashMap<Buf *, Tld *, buf_hash, buf_eql_buf> external_prototypes;
HashMap<Buf *, ConstExprValue *, buf_hash, buf_eql_buf> string_literals_table;
- HashMap<const TypeTableEntry *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
+ HashMap<const ZigType *, ConstExprValue *, type_ptr_hash, type_ptr_eql> type_info_cache;
ZigList<ImportTableEntry *> import_queue;
@@ -1586,38 +1593,38 @@ struct CodeGen {
uint32_t next_unresolved_index;
struct {
- TypeTableEntry *entry_bool;
- TypeTableEntry *entry_c_int[CIntTypeCount];
- TypeTableEntry *entry_c_longdouble;
- TypeTableEntry *entry_c_void;
- TypeTableEntry *entry_u8;
- TypeTableEntry *entry_u16;
- TypeTableEntry *entry_u32;
- TypeTableEntry *entry_u29;
- TypeTableEntry *entry_u64;
- TypeTableEntry *entry_i8;
- TypeTableEntry *entry_i32;
- TypeTableEntry *entry_i64;
- TypeTableEntry *entry_isize;
- TypeTableEntry *entry_usize;
- TypeTableEntry *entry_f16;
- TypeTableEntry *entry_f32;
- TypeTableEntry *entry_f64;
- TypeTableEntry *entry_f128;
- TypeTableEntry *entry_void;
- TypeTableEntry *entry_unreachable;
- TypeTableEntry *entry_type;
- TypeTableEntry *entry_invalid;
- TypeTableEntry *entry_namespace;
- TypeTableEntry *entry_block;
- TypeTableEntry *entry_num_lit_int;
- TypeTableEntry *entry_num_lit_float;
- TypeTableEntry *entry_undef;
- TypeTableEntry *entry_null;
- TypeTableEntry *entry_var;
- TypeTableEntry *entry_global_error_set;
- TypeTableEntry *entry_arg_tuple;
- TypeTableEntry *entry_promise;
+ ZigType *entry_bool;
+ ZigType *entry_c_int[CIntTypeCount];
+ ZigType *entry_c_longdouble;
+ ZigType *entry_c_void;
+ ZigType *entry_u8;
+ ZigType *entry_u16;
+ ZigType *entry_u32;
+ ZigType *entry_u29;
+ ZigType *entry_u64;
+ ZigType *entry_i8;
+ ZigType *entry_i32;
+ ZigType *entry_i64;
+ ZigType *entry_isize;
+ ZigType *entry_usize;
+ ZigType *entry_f16;
+ ZigType *entry_f32;
+ ZigType *entry_f64;
+ ZigType *entry_f128;
+ ZigType *entry_void;
+ 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;
+ ZigType *entry_undef;
+ ZigType *entry_null;
+ ZigType *entry_var;
+ ZigType *entry_global_error_set;
+ ZigType *entry_arg_tuple;
+ ZigType *entry_promise;
} builtin_types;
EmitFileType emit_file_type;
@@ -1672,14 +1679,14 @@ struct CodeGen {
const char *linker_script;
// The function definitions this module includes.
- ZigList<FnTableEntry *> fn_defs;
+ ZigList<ZigFn *> fn_defs;
size_t fn_defs_index;
ZigList<TldVar *> global_vars;
OutType out_type;
- FnTableEntry *cur_fn;
- FnTableEntry *main_fn;
- FnTableEntry *panic_fn;
+ ZigFn *cur_fn;
+ ZigFn *main_fn;
+ ZigFn *panic_fn;
LLVMValueRef cur_ret_ptr;
LLVMValueRef cur_fn_val;
LLVMValueRef cur_err_ret_trace_val_arg;
@@ -1732,12 +1739,12 @@ struct CodeGen {
const char **llvm_argv;
size_t llvm_argv_len;
- ZigList<FnTableEntry *> test_fns;
- TypeTableEntry *test_fn_type;
+ ZigList<ZigFn *> test_fns;
+ ZigType *test_fn_type;
bool each_lib_rpath;
- TypeTableEntry *err_tag_type;
+ ZigType *err_tag_type;
ZigList<ZigLLVMDIEnumerator *> err_enumerators;
ZigList<ErrorTableEntry *> errors_by_index;
bool generate_error_name_table;
@@ -1761,15 +1768,15 @@ struct CodeGen {
ZigList<TimeEvent> timing_events;
- Buf *cache_dir;
+ Buf cache_dir;
Buf *out_h_path;
- ZigList<FnTableEntry *> inline_fns;
+ ZigList<ZigFn *> inline_fns;
ZigList<AstNode *> tld_ref_source_node_stack;
- TypeTableEntry *align_amt_type;
- TypeTableEntry *stack_trace_type;
- TypeTableEntry *ptr_to_stack_trace_type;
+ ZigType *align_amt_type;
+ ZigType *stack_trace_type;
+ ZigType *ptr_to_stack_trace_type;
ZigList<ZigLLVMDIType **> error_di_types;
@@ -1784,7 +1791,7 @@ enum VarLinkage {
VarLinkageExternal,
};
-struct VariableTableEntry {
+struct ZigVar {
Buf name;
ConstExprValue *value;
LLVMValueRef value_ref;
@@ -1809,14 +1816,14 @@ struct VariableTableEntry {
// In an inline loop, multiple variables may be created,
// In this case, a reference to a variable should follow
// this pointer to the redefined variable.
- VariableTableEntry *next_var;
+ ZigVar *next_var;
};
struct ErrorTableEntry {
Buf name;
uint32_t value;
AstNode *decl_node;
- TypeTableEntry *set_with_only_this_in_it;
+ ZigType *set_with_only_this_in_it;
// If we generate a constant error name value for this error, we memoize it here.
// The type of this is array
ConstExprValue *cached_error_name_val;
@@ -1834,6 +1841,7 @@ enum ScopeId {
ScopeIdFnDef,
ScopeIdCompTime,
ScopeIdCoroPrelude,
+ ScopeIdRuntime,
};
struct Scope {
@@ -1859,7 +1867,7 @@ struct ScopeDecls {
AstNode *fast_math_set_node;
ImportTableEntry *import;
// If this is a scope from a container, this is the type entry, otherwise null
- TypeTableEntry *container_type;
+ ZigType *container_type;
};
// This scope comes from a block expression in user code.
@@ -1901,7 +1909,7 @@ struct ScopeVarDecl {
Scope base;
// The variable that creates this scope
- VariableTableEntry *var;
+ ZigVar *var;
};
// This scope is created for a @cImport
@@ -1926,6 +1934,15 @@ struct ScopeLoop {
ZigList<IrBasicBlock *> *incoming_blocks;
};
+// This scope blocks certain things from working such as comptime continue
+// inside a runtime if expression.
+// NodeTypeIfBoolExpr, NodeTypeWhileExpr, NodeTypeForExpr
+struct ScopeRuntime {
+ Scope base;
+
+ IrInstruction *is_comptime;
+};
+
// This scope is created for a suspend block in order to have labeled
// suspend for breaking out of a suspend and for detecting if a suspend
// block is inside a suspend block.
@@ -1948,7 +1965,7 @@ struct ScopeCompTime {
struct ScopeFnDef {
Scope base;
- FnTableEntry *fn_entry;
+ ZigFn *fn_entry;
};
// This scope is created to indicate that the code in the scope
@@ -2145,6 +2162,7 @@ enum IrInstructionId {
IrInstructionIdErrSetCast,
IrInstructionIdToBytes,
IrInstructionIdFromBytes,
+ IrInstructionIdCheckRuntimeScope,
};
struct IrInstruction {
@@ -2279,7 +2297,7 @@ struct IrInstructionBinOp {
struct IrInstructionDeclVar {
IrInstruction base;
- VariableTableEntry *var;
+ ZigVar *var;
IrInstruction *var_type;
IrInstruction *align_value;
IrInstruction *init_value;
@@ -2336,14 +2354,15 @@ struct IrInstructionElemPtr {
struct IrInstructionVarPtr {
IrInstruction base;
- VariableTableEntry *var;
+ ZigVar *var;
+ ScopeFnDef *crossed_fndef_scope;
};
struct IrInstructionCall {
IrInstruction base;
IrInstruction *fn_ref;
- FnTableEntry *fn_entry;
+ ZigFn *fn_entry;
size_t arg_count;
IrInstruction **args;
bool is_comptime;
@@ -2373,7 +2392,7 @@ struct IrInstructionCast {
IrInstruction base;
IrInstruction *value;
- TypeTableEntry *dest_type;
+ ZigType *dest_type;
CastOp cast_op;
LLVMValueRef tmp_ptr;
};
@@ -2410,7 +2429,7 @@ struct IrInstructionStructInitField {
struct IrInstructionStructInit {
IrInstruction base;
- TypeTableEntry *struct_type;
+ ZigType *struct_type;
size_t field_count;
IrInstructionStructInitField *fields;
LLVMValueRef tmp_ptr;
@@ -2419,7 +2438,7 @@ struct IrInstructionStructInit {
struct IrInstructionUnionInit {
IrInstruction base;
- TypeTableEntry *union_type;
+ ZigType *union_type;
TypeUnionField *field;
IrInstruction *init_value;
LLVMValueRef tmp_ptr;
@@ -2506,7 +2525,7 @@ struct IrInstructionAsm {
// Most information on inline assembly comes from the source node.
IrInstruction **input_list;
IrInstruction **output_types;
- VariableTableEntry **output_vars;
+ ZigVar **output_vars;
size_t return_count;
bool has_side_effects;
};
@@ -2648,7 +2667,7 @@ struct IrInstructionCmpxchg {
IrInstruction *failure_order_value;
// if this instruction gets to runtime then we know these values:
- TypeTableEntry *type;
+ ZigType *type;
AtomicOrder success_order;
AtomicOrder failure_order;
@@ -2818,7 +2837,7 @@ struct IrInstructionOverflowOp {
IrInstruction *op2;
IrInstruction *result_ptr;
- TypeTableEntry *result_ptr_type;
+ ZigType *result_ptr_type;
};
struct IrInstructionAlignOf {
@@ -3234,6 +3253,13 @@ struct IrInstructionSqrt {
IrInstruction *op;
};
+struct IrInstructionCheckRuntimeScope {
+ IrInstruction base;
+
+ IrInstruction *scope_is_comptime;
+ IrInstruction *is_comptime;
+};
+
static const size_t slice_ptr_index = 0;
static const size_t slice_len_index = 1;
@@ -3263,4 +3289,53 @@ enum FloatMode {
FloatModeStrict,
};
+enum FnWalkId {
+ FnWalkIdAttrs,
+ FnWalkIdCall,
+ FnWalkIdTypes,
+ FnWalkIdVars,
+ FnWalkIdInits,
+};
+
+struct FnWalkAttrs {
+ ZigFn *fn;
+ unsigned gen_i;
+};
+
+struct FnWalkCall {
+ ZigList<LLVMValueRef> *gen_param_values;
+ IrInstructionCall *inst;
+ bool is_var_args;
+};
+
+struct FnWalkTypes {
+ ZigList<ZigLLVMDIType *> *param_di_types;
+ ZigList<LLVMTypeRef> *gen_param_types;
+};
+
+struct FnWalkVars {
+ ImportTableEntry *import;
+ LLVMValueRef llvm_fn;
+ ZigFn *fn;
+ ZigVar *var;
+ unsigned gen_i;
+};
+
+struct FnWalkInits {
+ LLVMValueRef llvm_fn;
+ ZigFn *fn;
+ unsigned gen_i;
+};
+
+struct FnWalk {
+ FnWalkId id;
+ union {
+ FnWalkAttrs attrs;
+ FnWalkCall call;
+ FnWalkTypes types;
+ FnWalkVars vars;
+ FnWalkInits inits;
+ } data;
+};
+
#endif
diff --git a/src/analyze.cpp b/src/analyze.cpp
@@ -19,13 +19,13 @@
static const size_t default_backward_branch_quota = 1000;
-static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type);
-static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type);
+static Error resolve_enum_type(CodeGen *g, ZigType *enum_type);
+static Error resolve_struct_type(CodeGen *g, ZigType *struct_type);
-static Error ATTRIBUTE_MUST_USE resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type);
-static Error ATTRIBUTE_MUST_USE resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type);
-static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type);
-static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);
+static Error ATTRIBUTE_MUST_USE resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type);
+static Error ATTRIBUTE_MUST_USE resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type);
+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);
ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
if (node->owner->c_import_node != nullptr) {
@@ -70,24 +70,24 @@ ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *m
return err;
}
-TypeTableEntry *new_type_table_entry(TypeTableEntryId id) {
- TypeTableEntry *entry = allocate<TypeTableEntry>(1);
+ZigType *new_type_table_entry(ZigTypeId id) {
+ ZigType *entry = allocate<ZigType>(1);
entry->id = id;
return entry;
}
-static ScopeDecls **get_container_scope_ptr(TypeTableEntry *type_entry) {
- if (type_entry->id == TypeTableEntryIdStruct) {
+static ScopeDecls **get_container_scope_ptr(ZigType *type_entry) {
+ if (type_entry->id == ZigTypeIdStruct) {
return &type_entry->data.structure.decls_scope;
- } else if (type_entry->id == TypeTableEntryIdEnum) {
+ } else if (type_entry->id == ZigTypeIdEnum) {
return &type_entry->data.enumeration.decls_scope;
- } else if (type_entry->id == TypeTableEntryIdUnion) {
+ } else if (type_entry->id == ZigTypeIdUnion) {
return &type_entry->data.unionation.decls_scope;
}
zig_unreachable();
}
-ScopeDecls *get_container_scope(TypeTableEntry *type_entry) {
+ScopeDecls *get_container_scope(ZigType *type_entry) {
return *get_container_scope_ptr(type_entry);
}
@@ -97,7 +97,7 @@ void init_scope(Scope *dest, ScopeId id, AstNode *source_node, Scope *parent) {
dest->parent = parent;
}
-ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, TypeTableEntry *container_type, ImportTableEntry *import) {
+ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import) {
assert(node == nullptr || node->type == NodeTypeRoot || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr);
ScopeDecls *scope = allocate<ScopeDecls>(1);
init_scope(&scope->base, ScopeIdDecls, node, parent);
@@ -129,7 +129,7 @@ ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent) {
return scope;
}
-Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var) {
+Scope *create_var_scope(AstNode *node, Scope *parent, ZigVar *var) {
ScopeVarDecl *scope = allocate<ScopeVarDecl>(1);
init_scope(&scope->base, ScopeIdVarDecl, node, parent);
scope->var = var;
@@ -157,6 +157,13 @@ ScopeLoop *create_loop_scope(AstNode *node, Scope *parent) {
return scope;
}
+Scope *create_runtime_scope(AstNode *node, Scope *parent, IrInstruction *is_comptime) {
+ ScopeRuntime *scope = allocate<ScopeRuntime>(1);
+ scope->is_comptime = is_comptime;
+ init_scope(&scope->base, ScopeIdRuntime, node, parent);
+ return &scope->base;
+}
+
ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent) {
assert(node->type == NodeTypeSuspend);
ScopeSuspend *scope = allocate<ScopeSuspend>(1);
@@ -164,7 +171,7 @@ ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent) {
return scope;
}
-ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry) {
+ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, ZigFn *fn_entry) {
ScopeFnDef *scope = allocate<ScopeFnDef>(1);
init_scope(&scope->base, ScopeIdFnDef, node, parent);
scope->fn_entry = fn_entry;
@@ -196,8 +203,8 @@ ImportTableEntry *get_scope_import(Scope *scope) {
zig_unreachable();
}
-static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *source_node, Scope *parent_scope) {
- TypeTableEntry *entry = new_type_table_entry(id);
+static ZigType *new_container_type_entry(ZigTypeId id, AstNode *source_node, Scope *parent_scope) {
+ ZigType *entry = new_type_table_entry(id);
*get_container_scope_ptr(entry) = create_decls_scope(source_node, parent_scope, entry, get_scope_import(parent_scope));
return entry;
}
@@ -211,131 +218,131 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) {
return (upper >= x) ? base : (base + 1);
}
-AstNode *type_decl_node(TypeTableEntry *type_entry) {
+AstNode *type_decl_node(ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
return type_entry->data.structure.decl_node;
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
return type_entry->data.enumeration.decl_node;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
return type_entry->data.unionation.decl_node;
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdPromise:
return nullptr;
}
zig_unreachable();
}
-bool type_is_complete(TypeTableEntry *type_entry) {
+bool type_is_complete(ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
return type_entry->data.structure.complete;
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
return type_entry->data.enumeration.complete;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
return type_entry->data.unionation.complete;
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdOpaque:
return false;
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdPromise:
return true;
}
zig_unreachable();
}
-bool type_has_zero_bits_known(TypeTableEntry *type_entry) {
+bool type_has_zero_bits_known(ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
return type_entry->data.structure.zero_bits_known;
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
return type_entry->data.enumeration.zero_bits_known;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
return type_entry->data.unionation.zero_bits_known;
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdPromise:
return true;
}
zig_unreachable();
}
-uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) {
+uint64_t type_size(CodeGen *g, ZigType *type_entry) {
assert(type_is_complete(type_entry));
if (!type_has_bits(type_entry))
return 0;
- if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
+ if (type_entry->id == ZigTypeIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
uint64_t size_in_bits = type_size_bits(g, type_entry);
return (size_in_bits + 7) / 8;
- } else if (type_entry->id == TypeTableEntryIdArray) {
- TypeTableEntry *child_type = type_entry->data.array.child_type;
- if (child_type->id == TypeTableEntryIdStruct &&
+ } else if (type_entry->id == ZigTypeIdArray) {
+ ZigType *child_type = type_entry->data.array.child_type;
+ if (child_type->id == ZigTypeIdStruct &&
child_type->data.structure.layout == ContainerLayoutPacked)
{
uint64_t size_in_bits = type_size_bits(g, type_entry);
@@ -346,21 +353,21 @@ uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) {
return LLVMStoreSizeOfType(g->target_data_ref, type_entry->type_ref);
}
-uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) {
+uint64_t type_size_bits(CodeGen *g, ZigType *type_entry) {
assert(type_is_complete(type_entry));
if (!type_has_bits(type_entry))
return 0;
- if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
+ if (type_entry->id == ZigTypeIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
uint64_t result = 0;
for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
result += type_size_bits(g, type_entry->data.structure.fields[i].type_entry);
}
return result;
- } else if (type_entry->id == TypeTableEntryIdArray) {
- TypeTableEntry *child_type = type_entry->data.array.child_type;
- if (child_type->id == TypeTableEntryIdStruct &&
+ } else if (type_entry->id == ZigTypeIdArray) {
+ ZigType *child_type = type_entry->data.array.child_type;
+ if (child_type->id == ZigTypeIdStruct &&
child_type->data.structure.layout == ContainerLayoutPacked)
{
return type_entry->data.array.len * type_size_bits(g, child_type);
@@ -370,7 +377,7 @@ uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) {
return LLVMSizeOfTypeInBits(g->target_data_ref, type_entry->type_ref);
}
-Result<bool> type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) {
+Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry) {
Error err;
if ((err = type_ensure_zero_bits_known(g, type_entry)))
return err;
@@ -387,23 +394,23 @@ Result<bool> type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) {
return type_entry->is_copyable;
}
-static bool is_slice(TypeTableEntry *type) {
- return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice;
+static bool is_slice(ZigType *type) {
+ return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
}
-TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {
+ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {
return get_int_type(g, false, bits_needed_for_unsigned(x));
}
-TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) {
+ZigType *get_promise_type(CodeGen *g, ZigType *result_type) {
if (result_type != nullptr && result_type->promise_parent != nullptr) {
return result_type->promise_parent;
} else if (result_type == nullptr && g->builtin_types.entry_promise != nullptr) {
return g->builtin_types.entry_promise;
}
- TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPromise);
+ ZigType *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
+ ZigType *entry = new_type_table_entry(ZigTypeIdPromise);
entry->type_ref = u8_ptr_type->type_ref;
entry->zero_bits = false;
entry->data.promise.result_type = result_type;
@@ -421,17 +428,17 @@ TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) {
return entry;
}
-TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,
+ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const,
bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count)
{
assert(!type_is_invalid(child_type));
- assert(ptr_len == PtrLenSingle || child_type->id != TypeTableEntryIdOpaque);
+ assert(ptr_len == PtrLenSingle || child_type->id != ZigTypeIdOpaque);
TypeId type_id = {};
- TypeTableEntry **parent_pointer = nullptr;
+ ZigType **parent_pointer = nullptr;
uint32_t abi_alignment = get_abi_alignment(g, child_type);
if (unaligned_bit_count != 0 || is_volatile || byte_alignment != abi_alignment || ptr_len != PtrLenSingle) {
- type_id.id = TypeTableEntryIdPointer;
+ type_id.id = ZigTypeIdPointer;
type_id.data.pointer.child_type = child_type;
type_id.data.pointer.is_const = is_const;
type_id.data.pointer.is_volatile = is_volatile;
@@ -454,7 +461,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
assertNoError(type_ensure_zero_bits_known(g, child_type));
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPointer);
+ ZigType *entry = new_type_table_entry(ZigTypeIdPointer);
entry->is_copyable = true;
const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]";
@@ -471,7 +478,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));
}
- assert(child_type->id != TypeTableEntryIdInvalid);
+ assert(child_type->id != ZigTypeIdInvalid);
entry->zero_bits = !type_has_bits(child_type);
@@ -480,7 +487,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
if (is_const || is_volatile || unaligned_bit_count != 0 || byte_alignment != abi_alignment ||
ptr_len != PtrLenSingle)
{
- TypeTableEntry *peer_type = get_pointer_to_type(g, child_type, false);
+ ZigType *peer_type = get_pointer_to_type(g, child_type, false);
entry->type_ref = peer_type->type_ref;
entry->di_type = peer_type->di_type;
} else {
@@ -513,18 +520,18 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
return entry;
}
-TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const) {
+ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const) {
return get_pointer_to_type_extra(g, child_type, is_const, false, PtrLenSingle,
get_abi_alignment(g, child_type), 0, 0);
}
-TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type) {
+ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type) {
if (return_type->promise_frame_parent != nullptr) {
return return_type->promise_frame_parent;
}
- TypeTableEntry *atomic_state_type = g->builtin_types.entry_usize;
- TypeTableEntry *result_ptr_type = get_pointer_to_type(g, return_type, false);
+ ZigType *atomic_state_type = g->builtin_types.entry_usize;
+ ZigType *result_ptr_type = get_pointer_to_type(g, return_type, false);
ZigList<const char *> field_names = {};
field_names.append(ATOMIC_STATE_FIELD_NAME);
@@ -536,7 +543,7 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type)
field_names.append(RETURN_ADDRESSES_FIELD_NAME);
}
- ZigList<TypeTableEntry *> field_types = {};
+ ZigList<ZigType *> field_types = {};
field_types.append(atomic_state_type);
field_types.append(return_type);
field_types.append(result_ptr_type);
@@ -548,20 +555,20 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type)
assert(field_names.length == field_types.length);
Buf *name = buf_sprintf("AsyncFramePromise(%s)", buf_ptr(&return_type->name));
- TypeTableEntry *entry = get_struct_type(g, buf_ptr(name), field_names.items, field_types.items, field_names.length);
+ ZigType *entry = get_struct_type(g, buf_ptr(name), field_names.items, field_types.items, field_names.length);
return_type->promise_frame_parent = entry;
return entry;
}
-TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) {
+ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
if (child_type->optional_parent) {
- TypeTableEntry *entry = child_type->optional_parent;
+ ZigType *entry = child_type->optional_parent;
return entry;
} else {
assertNoError(ensure_complete_type(g, child_type));
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOptional);
+ ZigType *entry = new_type_table_entry(ZigTypeIdOptional);
assert(child_type->type_ref || child_type->zero_bits);
entry->is_copyable = type_is_copyable(g, child_type).unwrap();
@@ -599,7 +606,7 @@ TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) {
uint64_t val_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, child_type->type_ref);
uint64_t val_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);
- TypeTableEntry *bool_type = g->builtin_types.entry_bool;
+ ZigType *bool_type = g->builtin_types.entry_bool;
uint64_t maybe_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, bool_type->type_ref);
uint64_t maybe_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, bool_type->type_ref);
uint64_t maybe_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1);
@@ -638,12 +645,12 @@ TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) {
}
}
-TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *payload_type) {
- assert(err_set_type->id == TypeTableEntryIdErrorSet);
+ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type) {
+ assert(err_set_type->id == ZigTypeIdErrorSet);
assert(!type_is_invalid(payload_type));
TypeId type_id = {};
- type_id.id = TypeTableEntryIdErrorUnion;
+ type_id.id = ZigTypeIdErrorUnion;
type_id.data.error_union.err_set_type = err_set_type;
type_id.data.error_union.payload_type = payload_type;
@@ -652,7 +659,7 @@ TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, T
return existing_entry->value;
}
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorUnion);
+ ZigType *entry = new_type_table_entry(ZigTypeIdErrorUnion);
entry->is_copyable = true;
assert(payload_type->di_type);
assertNoError(ensure_complete_type(g, payload_type));
@@ -733,20 +740,20 @@ TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, T
return entry;
}
-TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size) {
+ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size) {
TypeId type_id = {};
- type_id.id = TypeTableEntryIdArray;
+ type_id.id = ZigTypeIdArray;
type_id.data.array.child_type = child_type;
type_id.data.array.size = array_size;
auto existing_entry = g->type_table.maybe_get(type_id);
if (existing_entry) {
- TypeTableEntry *entry = existing_entry->value;
+ ZigType *entry = existing_entry->value;
return entry;
}
assertNoError(ensure_complete_type(g, child_type));
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArray);
+ ZigType *entry = new_type_table_entry(ZigTypeIdArray);
entry->zero_bits = (array_size == 0) || child_type->zero_bits;
entry->is_copyable = false;
@@ -773,7 +780,7 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t
return entry;
}
-static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, TypeTableEntry *entry) {
+static void slice_type_common_init(CodeGen *g, ZigType *pointer_type, ZigType *entry) {
unsigned element_count = 2;
Buf *ptr_field_name = buf_create_from_str("ptr");
Buf *len_field_name = buf_create_from_str("len");
@@ -804,16 +811,16 @@ static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, Typ
}
}
-TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) {
+ assert(ptr_type->id == ZigTypeIdPointer);
assert(ptr_type->data.pointer.ptr_len == PtrLenUnknown);
- TypeTableEntry **parent_pointer = &ptr_type->data.pointer.slice_parent;
+ ZigType **parent_pointer = &ptr_type->data.pointer.slice_parent;
if (*parent_pointer) {
return *parent_pointer;
}
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdStruct);
+ ZigType *entry = new_type_table_entry(ZigTypeIdStruct);
entry->is_copyable = true;
// replace the & with [] to go from a ptr type name to a slice type name
@@ -821,14 +828,14 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
size_t name_offset = (ptr_type->data.pointer.ptr_len == PtrLenSingle) ? 1 : 3;
buf_appendf(&entry->name, "[]%s", buf_ptr(&ptr_type->name) + name_offset);
- TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
+ ZigType *child_type = ptr_type->data.pointer.child_type;
uint32_t abi_alignment = get_abi_alignment(g, child_type);
if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||
ptr_type->data.pointer.alignment != abi_alignment)
{
- TypeTableEntry *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,
+ ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,
PtrLenUnknown, abi_alignment, 0, 0);
- TypeTableEntry *peer_slice_type = get_slice_type(g, peer_ptr_type);
+ ZigType *peer_slice_type = get_slice_type(g, peer_ptr_type);
slice_type_common_init(g, ptr_type, entry);
@@ -845,18 +852,18 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
// If the child type is []const T then we need to make sure the type ref
// and debug info is the same as if the child type were []T.
if (is_slice(child_type)) {
- TypeTableEntry *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;
- assert(child_ptr_type->id == TypeTableEntryIdPointer);
- TypeTableEntry *grand_child_type = child_ptr_type->data.pointer.child_type;
+ ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry;
+ assert(child_ptr_type->id == ZigTypeIdPointer);
+ ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;
if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
child_ptr_type->data.pointer.alignment != get_abi_alignment(g, grand_child_type))
{
- TypeTableEntry *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,
+ ZigType *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,
PtrLenUnknown, get_abi_alignment(g, grand_child_type), 0, 0);
- TypeTableEntry *bland_child_slice = get_slice_type(g, bland_child_ptr_type);
- TypeTableEntry *peer_ptr_type = get_pointer_to_type_extra(g, bland_child_slice, false, false,
+ ZigType *bland_child_slice = get_slice_type(g, bland_child_ptr_type);
+ ZigType *peer_ptr_type = get_pointer_to_type_extra(g, bland_child_slice, false, false,
PtrLenUnknown, get_abi_alignment(g, bland_child_slice), 0, 0);
- TypeTableEntry *peer_slice_type = get_slice_type(g, peer_ptr_type);
+ ZigType *peer_slice_type = get_slice_type(g, peer_ptr_type);
entry->type_ref = peer_slice_type->type_ref;
entry->di_type = peer_slice_type->di_type;
@@ -882,7 +889,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
};
LLVMStructSetBody(entry->type_ref, element_types, 1, false);
- TypeTableEntry *usize_type = g->builtin_types.entry_usize;
+ ZigType *usize_type = g->builtin_types.entry_usize;
uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref);
uint64_t len_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, usize_type->type_ref);
uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);
@@ -921,7 +928,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
uint64_t ptr_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, ptr_type->type_ref);
uint64_t ptr_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0);
- TypeTableEntry *usize_type = g->builtin_types.entry_usize;
+ ZigType *usize_type = g->builtin_types.entry_usize;
uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref);
uint64_t len_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, usize_type->type_ref);
uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1);
@@ -964,8 +971,8 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) {
return entry;
}
-TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) {
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOpaque);
+ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) {
+ ZigType *entry = new_type_table_entry(ZigTypeIdOpaque);
buf_init_from_str(&entry->name, name);
@@ -984,13 +991,13 @@ TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node,
return entry;
}
-TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry) {
- TypeTableEntry *fn_type = fn_entry->type_entry;
- assert(fn_type->id == TypeTableEntryIdFn);
+ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) {
+ ZigType *fn_type = fn_entry->type_entry;
+ assert(fn_type->id == ZigTypeIdFn);
if (fn_type->data.fn.bound_fn_parent)
return fn_type->data.fn.bound_fn_parent;
- TypeTableEntry *bound_fn_type = new_type_table_entry(TypeTableEntryIdBoundFn);
+ ZigType *bound_fn_type = new_type_table_entry(ZigTypeIdBoundFn);
bound_fn_type->is_copyable = false;
bound_fn_type->data.bound_fn.fn_type = fn_type;
bound_fn_type->zero_bits = true;
@@ -1002,11 +1009,7 @@ TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry) {
return bound_fn_type;
}
-bool calling_convention_does_first_arg_return(CallingConvention cc) {
- return cc == CallingConventionUnspecified;
-}
-
-static const char *calling_convention_name(CallingConvention cc) {
+const char *calling_convention_name(CallingConvention cc) {
switch (cc) {
case CallingConventionUnspecified: return "undefined";
case CallingConventionC: return "ccc";
@@ -1030,7 +1033,7 @@ static const char *calling_convention_fn_type_str(CallingConvention cc) {
zig_unreachable();
}
-static bool calling_convention_allows_zig_types(CallingConvention cc) {
+bool calling_convention_allows_zig_types(CallingConvention cc) {
switch (cc) {
case CallingConventionUnspecified:
case CallingConventionAsync:
@@ -1044,17 +1047,38 @@ static bool calling_convention_allows_zig_types(CallingConvention cc) {
zig_unreachable();
}
-TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g) {
+ZigType *get_ptr_to_stack_trace_type(CodeGen *g) {
if (g->stack_trace_type == nullptr) {
ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace");
- assert(stack_trace_type_val->type->id == TypeTableEntryIdMetaType);
+ assert(stack_trace_type_val->type->id == ZigTypeIdMetaType);
g->stack_trace_type = stack_trace_type_val->data.x_type;
g->ptr_to_stack_trace_type = get_pointer_to_type(g, g->stack_trace_type, false);
}
return g->ptr_to_stack_trace_type;
}
-TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
+bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) {
+ if (fn_type_id->cc == CallingConventionUnspecified) {
+ return handle_is_ptr(fn_type_id->return_type);
+ }
+ if (fn_type_id->cc != CallingConventionC) {
+ return false;
+ }
+ if (type_is_c_abi_int(g, fn_type_id->return_type)) {
+ return false;
+ }
+ if (g->zig_target.arch.arch == ZigLLVM_x86_64) {
+ X64CABIClass abi_class = type_c_abi_x86_64_class(g, fn_type_id->return_type);
+ if (abi_class == X64CABIClass_MEMORY) {
+ return true;
+ }
+ zig_panic("TODO implement C ABI for x86_64 return types. type '%s'\nSee https://github.com/ziglang/zig/issues/1481",
+ buf_ptr(&fn_type_id->return_type->name));
+ }
+ zig_panic("TODO implement C ABI for this architecture. See https://github.com/ziglang/zig/issues/1481");
+}
+
+ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
Error err;
auto table_entry = g->fn_type_table.maybe_get(fn_type_id);
if (table_entry) {
@@ -1063,12 +1087,12 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
if (fn_type_id->return_type != nullptr) {
if ((err = ensure_complete_type(g, fn_type_id->return_type)))
return g->builtin_types.entry_invalid;
- assert(fn_type_id->return_type->id != TypeTableEntryIdOpaque);
+ assert(fn_type_id->return_type->id != ZigTypeIdOpaque);
} else {
zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");
}
- TypeTableEntry *fn_type = new_type_table_entry(TypeTableEntryIdFn);
+ ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
fn_type->is_copyable = true;
fn_type->data.fn.fn_type_id = *fn_type_id;
@@ -1087,7 +1111,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
- TypeTableEntry *param_type = param_info->type;
+ ZigType *param_type = param_info->type;
const char *comma = (i == 0) ? "" : ", ";
const char *noalias_str = param_info->is_noalias ? "noalias " : "";
buf_appendf(&fn_type->name, "%s%s%s", comma, noalias_str, buf_ptr(¶m_type->name));
@@ -1109,32 +1133,29 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
// next, loop over the parameters again and compute debug information
// and codegen information
if (!skip_debug_info) {
- bool first_arg_return = calling_convention_does_first_arg_return(fn_type_id->cc) &&
- handle_is_ptr(fn_type_id->return_type);
+ bool first_arg_return = want_first_arg_sret(g, fn_type_id);
bool is_async = fn_type_id->cc == CallingConventionAsync;
+ bool is_c_abi = fn_type_id->cc == CallingConventionC;
bool prefix_arg_error_return_trace = g->have_err_ret_tracing && fn_type_can_fail(fn_type_id);
// +1 for maybe making the first argument the return value
// +1 for maybe first argument the error return trace
// +2 for maybe arguments async allocator and error code pointer
- LLVMTypeRef *gen_param_types = allocate<LLVMTypeRef>(4 + fn_type_id->param_count);
+ ZigList<LLVMTypeRef> gen_param_types = {};
// +1 because 0 is the return type and
// +1 for maybe making first arg ret val and
// +1 for maybe first argument the error return trace
// +2 for maybe arguments async allocator and error code pointer
- ZigLLVMDIType **param_di_types = allocate<ZigLLVMDIType*>(5 + fn_type_id->param_count);
- param_di_types[0] = fn_type_id->return_type->di_type;
- size_t gen_param_index = 0;
- TypeTableEntry *gen_return_type;
+ ZigList<ZigLLVMDIType *> param_di_types = {};
+ param_di_types.append(fn_type_id->return_type->di_type);
+ ZigType *gen_return_type;
if (is_async) {
gen_return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
} else if (!type_has_bits(fn_type_id->return_type)) {
gen_return_type = g->builtin_types.entry_void;
} else if (first_arg_return) {
- TypeTableEntry *gen_type = get_pointer_to_type(g, fn_type_id->return_type, false);
- gen_param_types[gen_param_index] = gen_type->type_ref;
- gen_param_index += 1;
- // after the gen_param_index += 1 because 0 is the return type
- param_di_types[gen_param_index] = gen_type->di_type;
+ ZigType *gen_type = get_pointer_to_type(g, fn_type_id->return_type, false);
+ gen_param_types.append(gen_type->type_ref);
+ param_di_types.append(gen_type->di_type);
gen_return_type = g->builtin_types.entry_void;
} else {
gen_return_type = fn_type_id->return_type;
@@ -1142,36 +1163,30 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
fn_type->data.fn.gen_return_type = gen_return_type;
if (prefix_arg_error_return_trace) {
- TypeTableEntry *gen_type = get_ptr_to_stack_trace_type(g);
- gen_param_types[gen_param_index] = gen_type->type_ref;
- gen_param_index += 1;
- // after the gen_param_index += 1 because 0 is the return type
- param_di_types[gen_param_index] = gen_type->di_type;
+ ZigType *gen_type = get_ptr_to_stack_trace_type(g);
+ gen_param_types.append(gen_type->type_ref);
+ param_di_types.append(gen_type->di_type);
}
if (is_async) {
{
// async allocator param
- TypeTableEntry *gen_type = fn_type_id->async_allocator_type;
- gen_param_types[gen_param_index] = gen_type->type_ref;
- gen_param_index += 1;
- // after the gen_param_index += 1 because 0 is the return type
- param_di_types[gen_param_index] = gen_type->di_type;
+ ZigType *gen_type = fn_type_id->async_allocator_type;
+ gen_param_types.append(gen_type->type_ref);
+ param_di_types.append(gen_type->di_type);
}
{
// error code pointer
- TypeTableEntry *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
- gen_param_types[gen_param_index] = gen_type->type_ref;
- gen_param_index += 1;
- // after the gen_param_index += 1 because 0 is the return type
- param_di_types[gen_param_index] = gen_type->di_type;
+ ZigType *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
+ gen_param_types.append(gen_type->type_ref);
+ param_di_types.append(gen_type->di_type);
}
}
fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);
for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];
- TypeTableEntry *type_entry = src_param_info->type;
+ ZigType *type_entry = src_param_info->type;
FnGenParamInfo *gen_param_info = &fn_type->data.fn.gen_param_info[i];
gen_param_info->src_index = i;
@@ -1180,31 +1195,39 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
if ((err = ensure_complete_type(g, type_entry)))
return g->builtin_types.entry_invalid;
+ if (is_c_abi)
+ continue;
+
if (type_has_bits(type_entry)) {
- TypeTableEntry *gen_type;
+ ZigType *gen_type;
if (handle_is_ptr(type_entry)) {
gen_type = get_pointer_to_type(g, type_entry, true);
gen_param_info->is_byval = true;
} else {
gen_type = type_entry;
}
- gen_param_types[gen_param_index] = gen_type->type_ref;
- gen_param_info->gen_index = gen_param_index;
+ gen_param_info->gen_index = gen_param_types.length;
gen_param_info->type = gen_type;
+ gen_param_types.append(gen_type->type_ref);
- gen_param_index += 1;
-
- // after the gen_param_index += 1 because 0 is the return type
- param_di_types[gen_param_index] = gen_type->di_type;
+ param_di_types.append(gen_type->di_type);
}
}
- fn_type->data.fn.gen_param_count = gen_param_index;
+ if (is_c_abi) {
+ FnWalk fn_walk = {};
+ fn_walk.id = FnWalkIdTypes;
+ fn_walk.data.types.param_di_types = ¶m_di_types;
+ fn_walk.data.types.gen_param_types = &gen_param_types;
+ walk_function_params(g, fn_type, &fn_walk);
+ }
+
+ fn_type->data.fn.gen_param_count = gen_param_types.length;
fn_type->data.fn.raw_type_ref = LLVMFunctionType(gen_return_type->type_ref,
- gen_param_types, (unsigned int)gen_param_index, fn_type_id->is_var_args);
+ gen_param_types.items, (unsigned int)gen_param_types.length, fn_type_id->is_var_args);
fn_type->type_ref = LLVMPointerType(fn_type->data.fn.raw_type_ref, 0);
- fn_type->di_type = ZigLLVMCreateSubroutineType(g->dbuilder, param_di_types, (int)(gen_param_index + 1), 0);
+ fn_type->di_type = ZigLLVMCreateSubroutineType(g->dbuilder, param_di_types.items, (int)param_di_types.length, 0);
}
g->fn_type_table.put(&fn_type->data.fn.fn_type_id, fn_type);
@@ -1212,23 +1235,23 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
return fn_type;
}
-static TypeTableEntryId container_to_type(ContainerKind kind) {
+static ZigTypeId container_to_type(ContainerKind kind) {
switch (kind) {
case ContainerKindStruct:
- return TypeTableEntryIdStruct;
+ return ZigTypeIdStruct;
case ContainerKindEnum:
- return TypeTableEntryIdEnum;
+ return ZigTypeIdEnum;
case ContainerKindUnion:
- return TypeTableEntryIdUnion;
+ return ZigTypeIdUnion;
}
zig_unreachable();
}
-TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
+ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
AstNode *decl_node, const char *name, ContainerLayout layout)
{
- TypeTableEntryId type_id = container_to_type(kind);
- TypeTableEntry *entry = new_container_type_entry(type_id, decl_node, scope);
+ ZigTypeId type_id = container_to_type(kind);
+ ZigType *entry = new_container_type_entry(type_id, decl_node, scope);
switch (kind) {
case ContainerKindStruct:
@@ -1259,24 +1282,24 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKi
return entry;
}
-static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, TypeTableEntry *type_entry, Buf *type_name) {
+static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name) {
size_t backward_branch_count = 0;
return ir_eval_const_value(g, scope, node, type_entry,
&backward_branch_count, default_backward_branch_quota,
nullptr, nullptr, node, type_name, nullptr);
}
-TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
+ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
IrInstruction *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr);
- if (result->value.type->id == TypeTableEntryIdInvalid)
+ if (result->value.type->id == ZigTypeIdInvalid)
return g->builtin_types.entry_invalid;
assert(result->value.special != ConstValSpecialRuntime);
return result->value.data.x_type;
}
-TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
- TypeTableEntry *fn_type = new_type_table_entry(TypeTableEntryIdFn);
+ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
+ ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
fn_type->is_copyable = false;
buf_resize(&fn_type->name, 0);
if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {
@@ -1343,9 +1366,9 @@ static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_
}
static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **out_buffer) {
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
+ ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *str_type = get_slice_type(g, ptr_type);
+ ZigType *str_type = get_slice_type(g, ptr_type);
IrInstruction *instr = analyze_const_value(g, scope, node, str_type, nullptr);
if (type_is_invalid(instr->value.type))
return false;
@@ -1375,71 +1398,71 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
return true;
}
-static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {
+static bool type_allowed_in_packed_struct(ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdPromise:
return false;
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdFn:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdFn:
return true;
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
return type_entry->data.structure.layout == ContainerLayoutPacked;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
return type_entry->data.unionation.layout == ContainerLayoutPacked;
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
{
- TypeTableEntry *child_type = type_entry->data.maybe.child_type;
+ ZigType *child_type = type_entry->data.maybe.child_type;
return type_is_codegen_pointer(child_type);
}
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
return type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr;
}
zig_unreachable();
}
-static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {
+static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdPromise:
- case TypeTableEntryIdVoid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdPromise:
+ case ZigTypeIdVoid:
return false;
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdBool:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdBool:
return true;
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
switch (type_entry->data.integral.bit_count) {
case 8:
case 16:
@@ -1450,36 +1473,36 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {
default:
return false;
}
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
return true;
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
return type_allowed_in_extern(g, type_entry->data.array.child_type);
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
return type_entry->data.fn.fn_type_id.cc == CallingConventionC;
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
if (type_size(g, type_entry) == 0)
return false;
return true;
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked;
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
{
- TypeTableEntry *child_type = type_entry->data.maybe.child_type;
- if (child_type->id != TypeTableEntryIdPointer && child_type->id != TypeTableEntryIdFn) {
+ ZigType *child_type = type_entry->data.maybe.child_type;
+ if (child_type->id != ZigTypeIdPointer && child_type->id != ZigTypeIdFn) {
return false;
}
return type_allowed_in_extern(g, child_type);
}
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
return type_entry->data.enumeration.layout == ContainerLayoutExtern || type_entry->data.enumeration.layout == ContainerLayoutPacked;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
return type_entry->data.unionation.layout == ContainerLayoutExtern || type_entry->data.unionation.layout == ContainerLayoutPacked;
}
zig_unreachable();
}
-TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) {
- TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
+ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {
+ ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
buf_resize(&err_set_type->name, 0);
buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name));
err_set_type->is_copyable = true;
@@ -1494,7 +1517,7 @@ TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) {
return err_set_type;
}
-static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, FnTableEntry *fn_entry) {
+static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, ZigFn *fn_entry) {
assert(proto_node->type == NodeTypeFnProto);
AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;
Error err;
@@ -1517,7 +1540,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
return g->builtin_types.entry_invalid;
}
if (param_node->data.param_decl.type != nullptr) {
- TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
+ ZigType *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
if (type_is_invalid(type_entry)) {
return g->builtin_types.entry_invalid;
}
@@ -1550,7 +1573,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
return get_generic_fn_type(g, &fn_type_id);
}
- TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
+ ZigType *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
if (type_is_invalid(type_entry)) {
return g->builtin_types.entry_invalid;
}
@@ -1574,36 +1597,36 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
}
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
add_node_error(g, param_node->data.param_decl.type,
buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));
return g->builtin_types.entry_invalid;
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdPromise:
if ((err = type_ensure_zero_bits_known(g, type_entry)))
return g->builtin_types.entry_invalid;
if (type_requires_comptime(type_entry)) {
@@ -1638,21 +1661,21 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
//return get_generic_fn_type(g, &fn_type_id);
}
- TypeTableEntry *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);
+ ZigType *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);
if (type_is_invalid(specified_return_type)) {
fn_type_id.return_type = g->builtin_types.entry_invalid;
return g->builtin_types.entry_invalid;
}
if (fn_proto->auto_err_set) {
- TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(g, fn_entry);
+ ZigType *inferred_err_set_type = get_auto_err_set_type(g, fn_entry);
fn_type_id.return_type = get_error_union_type(g, inferred_err_set_type, specified_return_type);
} else {
fn_type_id.return_type = specified_return_type;
}
if (!calling_convention_allows_zig_types(fn_type_id.cc) &&
- fn_type_id.return_type->id != TypeTableEntryIdVoid &&
+ fn_type_id.return_type->id != ZigTypeIdVoid &&
!type_allowed_in_extern(g, fn_type_id.return_type))
{
add_node_error(g, fn_proto->return_type,
@@ -1663,38 +1686,38 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
}
switch (fn_type_id.return_type->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
add_node_error(g, fn_proto->return_type,
buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
return g->builtin_types.entry_invalid;
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdPromise:
if ((err = type_ensure_zero_bits_known(g, fn_type_id.return_type)))
return g->builtin_types.entry_invalid;
if (type_requires_comptime(fn_type_id.return_type)) {
@@ -1716,15 +1739,15 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
return get_fn_type(g, &fn_type_id);
}
-bool type_is_invalid(TypeTableEntry *type_entry) {
+bool type_is_invalid(ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
return true;
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
return type_entry->data.structure.is_invalid;
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
return type_entry->data.enumeration.is_invalid;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
return type_entry->data.unionation.is_invalid;
default:
return false;
@@ -1733,8 +1756,8 @@ bool type_is_invalid(TypeTableEntry *type_entry) {
}
-static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
- assert(enum_type->id == TypeTableEntryIdEnum);
+static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) {
+ assert(enum_type->id == ZigTypeIdEnum);
if (enum_type->data.enumeration.is_invalid)
return ErrorSemanticAnalyzeFail;
@@ -1808,7 +1831,7 @@ static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
return ErrorNone;
}
- TypeTableEntry *tag_int_type = enum_type->data.enumeration.tag_int_type;
+ ZigType *tag_int_type = enum_type->data.enumeration.tag_int_type;
// create debug type for tag
uint64_t tag_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, tag_int_type->type_ref);
@@ -1827,10 +1850,10 @@ static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
}
-TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
- TypeTableEntry *field_types[], size_t field_count)
+ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
+ ZigType *field_types[], size_t field_count)
{
- TypeTableEntry *struct_type = new_type_table_entry(TypeTableEntryIdStruct);
+ ZigType *struct_type = new_type_table_entry(ZigTypeIdStruct);
buf_init_from_str(&struct_type->name, type_name);
@@ -1874,7 +1897,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f
if (type_struct_field->gen_index == SIZE_MAX) {
continue;
}
- TypeTableEntry *field_type = type_struct_field->type_entry;
+ ZigType *field_type = type_struct_field->type_entry;
uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_type->type_ref);
uint64_t debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, field_type->type_ref);
uint64_t debug_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, struct_type->type_ref, type_struct_field->gen_index);
@@ -1906,8 +1929,8 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f
return struct_type;
}
-static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
- assert(struct_type->id == TypeTableEntryIdStruct);
+static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
+ assert(struct_type->id == ZigTypeIdStruct);
if (struct_type->data.structure.complete)
return ErrorNone;
@@ -1950,7 +1973,7 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
for (size_t i = 0; i < field_count; i += 1) {
TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
- TypeTableEntry *field_type = type_struct_field->type_entry;
+ ZigType *field_type = type_struct_field->type_entry;
if ((err = ensure_complete_type(g, field_type))) {
struct_type->data.structure.is_invalid = true;
@@ -2081,12 +2104,12 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
continue;
}
- TypeTableEntry *field_type = type_struct_field->type_entry;
+ ZigType *field_type = type_struct_field->type_entry;
// if the field is a function, actually the debug info should be a pointer.
ZigLLVMDIType *field_di_type;
- if (field_type->id == TypeTableEntryIdFn) {
- TypeTableEntry *field_ptr_type = get_pointer_to_type(g, field_type, true);
+ if (field_type->id == ZigTypeIdFn) {
+ ZigType *field_ptr_type = get_pointer_to_type(g, field_type, true);
uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_ptr_type->type_ref);
uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_ptr_type->type_ref);
field_di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, field_type->di_type,
@@ -2140,8 +2163,8 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
return ErrorNone;
}
-static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
- assert(union_type->id == TypeTableEntryIdUnion);
+static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
+ assert(union_type->id == ZigTypeIdUnion);
if (union_type->data.unionation.complete)
return ErrorNone;
@@ -2172,7 +2195,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
uint32_t gen_field_count = union_type->data.unionation.gen_field_count;
ZigLLVMDIType **union_inner_di_types = allocate<ZigLLVMDIType*>(gen_field_count);
- TypeTableEntry *most_aligned_union_member = nullptr;
+ ZigType *most_aligned_union_member = nullptr;
uint64_t size_of_most_aligned_member_in_bits = 0;
uint64_t biggest_align_in_bits = 0;
uint64_t biggest_size_in_bits = 0;
@@ -2187,7 +2210,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
for (uint32_t i = 0; i < field_count; i += 1) {
AstNode *field_node = decl_node->data.container_decl.fields.at(i);
TypeUnionField *union_field = &union_type->data.unionation.fields[i];
- TypeTableEntry *field_type = union_field->type_entry;
+ ZigType *field_type = union_field->type_entry;
if ((err = ensure_complete_type(g, field_type))) {
union_type->data.unionation.is_invalid = true;
@@ -2252,13 +2275,13 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
uint64_t padding_in_bits = biggest_size_in_bits - size_of_most_aligned_member_in_bits;
- TypeTableEntry *tag_type = union_type->data.unionation.tag_type;
+ ZigType *tag_type = union_type->data.unionation.tag_type;
if (tag_type == nullptr || tag_type->zero_bits) {
assert(most_aligned_union_member != nullptr);
if (padding_in_bits > 0) {
- TypeTableEntry *u8_type = get_int_type(g, false, 8);
- TypeTableEntry *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);
+ ZigType *u8_type = get_int_type(g, false, 8);
+ ZigType *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);
LLVMTypeRef union_element_types[] = {
most_aligned_union_member->type_ref,
padding_array->type_ref,
@@ -2288,8 +2311,8 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
LLVMTypeRef union_type_ref;
if (padding_in_bits > 0) {
- TypeTableEntry *u8_type = get_int_type(g, false, 8);
- TypeTableEntry *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);
+ ZigType *u8_type = get_int_type(g, false, 8);
+ ZigType *padding_array = get_array_type(g, u8_type, padding_in_bits / 8);
LLVMTypeRef union_element_types[] = {
most_aligned_union_member->type_ref,
padding_array->type_ref,
@@ -2312,7 +2335,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
assert(8*LLVMStoreSizeOfType(g->target_data_ref, union_type_ref) >= biggest_size_in_bits);
// create llvm type for root struct
- TypeTableEntry *tag_int_type = tag_type->data.enumeration.tag_int_type;
+ ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;
uint64_t align_of_tag_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_int_type->type_ref);
if (align_of_tag_in_bits >= biggest_align_in_bits) {
@@ -2380,8 +2403,8 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) {
return ErrorNone;
}
-static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
- assert(enum_type->id == TypeTableEntryIdEnum);
+static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
+ assert(enum_type->id == ZigTypeIdEnum);
if (enum_type->data.enumeration.zero_bits_known)
return ErrorNone;
@@ -2421,7 +2444,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> occupied_tag_values = {};
occupied_tag_values.init(field_count);
- TypeTableEntry *tag_int_type;
+ ZigType *tag_int_type;
if (enum_type->data.enumeration.layout == ContainerLayoutExtern) {
tag_int_type = get_c_int_type(g, CIntTypeInt);
} else {
@@ -2430,10 +2453,10 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
// TODO: Are extern enums allowed to have an init_arg_expr?
if (decl_node->data.container_decl.init_arg_expr != nullptr) {
- TypeTableEntry *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr);
+ ZigType *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr);
if (type_is_invalid(wanted_tag_int_type)) {
enum_type->data.enumeration.is_invalid = true;
- } else if (wanted_tag_int_type->id != TypeTableEntryIdInt) {
+ } else if (wanted_tag_int_type->id != ZigTypeIdInt) {
enum_type->data.enumeration.is_invalid = true;
add_node_error(g, decl_node->data.container_decl.init_arg_expr,
buf_sprintf("expected integer, found '%s'", buf_ptr(&wanted_tag_int_type->name)));
@@ -2482,12 +2505,12 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
// In a second pass we will fill in the unspecified ones.
if (tag_value != nullptr) {
IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);
- if (result_inst->value.type->id == TypeTableEntryIdInvalid) {
+ if (result_inst->value.type->id == ZigTypeIdInvalid) {
enum_type->data.enumeration.is_invalid = true;
continue;
}
assert(result_inst->value.special != ConstValSpecialRuntime);
- assert(result_inst->value.type->id == TypeTableEntryIdInt);
+ assert(result_inst->value.type->id == ZigTypeIdInt);
auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);
if (entry == nullptr) {
bigint_init_bigint(&type_enum_field->value, &result_inst->value.data.x_bigint);
@@ -2543,8 +2566,8 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
return ErrorNone;
}
-static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
- assert(struct_type->id == TypeTableEntryIdStruct);
+static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
+ assert(struct_type->id == ZigTypeIdStruct);
Error err;
@@ -2607,7 +2630,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
continue;
}
- TypeTableEntry *field_type = analyze_type_expr(g, scope, field_node->data.struct_field.type);
+ ZigType *field_type = analyze_type_expr(g, scope, field_node->data.struct_field.type);
type_struct_field->type_entry = field_type;
type_struct_field->src_index = i;
type_struct_field->gen_index = SIZE_MAX;
@@ -2662,8 +2685,8 @@ static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
return ErrorNone;
}
-static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
- assert(union_type->id == TypeTableEntryIdUnion);
+static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
+ assert(union_type->id == ZigTypeIdUnion);
Error err;
@@ -2727,7 +2750,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
enum_type_node != nullptr;
bool auto_layout = (union_type->data.unionation.layout == ContainerLayoutAuto);
bool want_safety = (field_count >= 2) && (auto_layout || enum_type_node != nullptr);
- TypeTableEntry *tag_type;
+ ZigType *tag_type;
bool create_enum_type = decl_node->data.container_decl.auto_enum || (enum_type_node == nullptr && want_safety);
bool *covered_enum_fields;
ZigLLVMDIEnumerator **di_enumerators;
@@ -2737,14 +2760,14 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count);
- TypeTableEntry *tag_int_type;
+ ZigType *tag_int_type;
if (enum_type_node != nullptr) {
tag_int_type = analyze_type_expr(g, scope, enum_type_node);
if (type_is_invalid(tag_int_type)) {
union_type->data.unionation.is_invalid = true;
return ErrorSemanticAnalyzeFail;
}
- if (tag_int_type->id != TypeTableEntryIdInt) {
+ if (tag_int_type->id != ZigTypeIdInt) {
add_node_error(g, enum_type_node,
buf_sprintf("expected integer tag type, found '%s'", buf_ptr(&tag_int_type->name)));
union_type->data.unionation.is_invalid = true;
@@ -2755,7 +2778,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
}
abi_alignment_so_far = get_abi_alignment(g, tag_int_type);
- tag_type = new_type_table_entry(TypeTableEntryIdEnum);
+ tag_type = new_type_table_entry(ZigTypeIdEnum);
buf_resize(&tag_type->name, 0);
buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name));
tag_type->is_copyable = true;
@@ -2772,12 +2795,12 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;
tag_type->data.enumeration.complete = true;
} else if (enum_type_node != nullptr) {
- TypeTableEntry *enum_type = analyze_type_expr(g, scope, enum_type_node);
+ ZigType *enum_type = analyze_type_expr(g, scope, enum_type_node);
if (type_is_invalid(enum_type)) {
union_type->data.unionation.is_invalid = true;
return ErrorSemanticAnalyzeFail;
}
- if (enum_type->id != TypeTableEntryIdEnum) {
+ if (enum_type->id != ZigTypeIdEnum) {
union_type->data.unionation.is_invalid = true;
add_node_error(g, enum_type_node,
buf_sprintf("expected enum tag type, found '%s'", buf_ptr(&enum_type->name)));
@@ -2809,7 +2832,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
continue;
}
- TypeTableEntry *field_type;
+ ZigType *field_type;
if (field_node->data.struct_field.type == nullptr) {
if (decl_node->data.container_decl.auto_enum || decl_node->data.container_decl.init_arg_expr != nullptr) {
field_type = g->builtin_types.entry_void;
@@ -2853,14 +2876,14 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
// In this first pass we resolve explicit tag values.
// In a second pass we will fill in the unspecified ones.
if (tag_value != nullptr) {
- TypeTableEntry *tag_int_type = tag_type->data.enumeration.tag_int_type;
+ ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;
IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);
- if (result_inst->value.type->id == TypeTableEntryIdInvalid) {
+ if (result_inst->value.type->id == ZigTypeIdInvalid) {
union_type->data.unionation.is_invalid = true;
continue;
}
assert(result_inst->value.special != ConstValSpecialRuntime);
- assert(result_inst->value.type->id == TypeTableEntryIdInt);
+ assert(result_inst->value.type->id == ZigTypeIdInt);
auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value);
if (entry == nullptr) {
bigint_init_bigint(&union_field->enum_field->value, &result_inst->value.data.x_bigint);
@@ -3031,8 +3054,8 @@ static void get_fully_qualified_decl_name(Buf *buf, Tld *tld, uint8_t sep) {
buf_append_buf(buf, tld->name);
}
-FnTableEntry *create_fn_raw(FnInline inline_value) {
- FnTableEntry *fn_entry = allocate<FnTableEntry>(1);
+ZigFn *create_fn_raw(FnInline inline_value) {
+ ZigFn *fn_entry = allocate<ZigFn>(1);
fn_entry->analyzed_executable.backward_branch_count = &fn_entry->prealloc_bbc;
fn_entry->analyzed_executable.backward_branch_quota = default_backward_branch_quota;
@@ -3043,12 +3066,12 @@ FnTableEntry *create_fn_raw(FnInline inline_value) {
return fn_entry;
}
-FnTableEntry *create_fn(AstNode *proto_node) {
+ZigFn *create_fn(AstNode *proto_node) {
assert(proto_node->type == NodeTypeFnProto);
AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;
FnInline inline_value = fn_proto->is_inline ? FnInlineAlways : FnInlineAuto;
- FnTableEntry *fn_entry = create_fn_raw(inline_value);
+ ZigFn *fn_entry = create_fn_raw(inline_value);
fn_entry->proto_node = proto_node;
fn_entry->body_node = (proto_node->data.fn_proto.fn_def_node == nullptr) ? nullptr :
@@ -3068,39 +3091,39 @@ static bool scope_is_root_decls(Scope *scope) {
zig_unreachable();
}
-static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntry *fn_type) {
+static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, ZigType *fn_type) {
add_node_error(g, proto_node,
buf_sprintf("expected 'fn([]const u8, ?*builtin.StackTrace) noreturn', found '%s'",
buf_ptr(&fn_type->name)));
}
-static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) {
+static void typecheck_panic_fn(CodeGen *g, ZigFn *panic_fn) {
AstNode *proto_node = panic_fn->proto_node;
assert(proto_node->type == NodeTypeFnProto);
- TypeTableEntry *fn_type = panic_fn->type_entry;
+ ZigType *fn_type = panic_fn->type_entry;
FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
if (fn_type_id->param_count != 2) {
return wrong_panic_prototype(g, proto_node, fn_type);
}
- TypeTableEntry *const_u8_ptr = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
+ ZigType *const_u8_ptr = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *const_u8_slice = get_slice_type(g, const_u8_ptr);
+ ZigType *const_u8_slice = get_slice_type(g, const_u8_ptr);
if (fn_type_id->param_info[0].type != const_u8_slice) {
return wrong_panic_prototype(g, proto_node, fn_type);
}
- TypeTableEntry *optional_ptr_to_stack_trace_type = get_optional_type(g, get_ptr_to_stack_trace_type(g));
+ ZigType *optional_ptr_to_stack_trace_type = get_optional_type(g, get_ptr_to_stack_trace_type(g));
if (fn_type_id->param_info[1].type != optional_ptr_to_stack_trace_type) {
return wrong_panic_prototype(g, proto_node, fn_type);
}
- TypeTableEntry *actual_return_type = fn_type_id->return_type;
+ ZigType *actual_return_type = fn_type_id->return_type;
if (actual_return_type != g->builtin_types.entry_unreachable) {
return wrong_panic_prototype(g, proto_node, fn_type);
}
}
-TypeTableEntry *get_test_fn_type(CodeGen *g) {
+ZigType *get_test_fn_type(CodeGen *g) {
if (g->test_fn_type)
return g->test_fn_type;
@@ -3111,7 +3134,7 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {
return g->test_fn_type;
}
-void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc) {
+void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc) {
if (ccc) {
if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) {
g->have_c_main = true;
@@ -3147,7 +3170,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
AstNode *fn_def_node = fn_proto->fn_def_node;
- FnTableEntry *fn_table_entry = create_fn(source_node);
+ ZigFn *fn_table_entry = create_fn(source_node);
get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');
if (fn_proto->is_export) {
@@ -3185,7 +3208,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
}
}
- if (fn_table_entry->type_entry->id == TypeTableEntryIdInvalid) {
+ if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) {
tld_fn->base.resolution = TldResolutionInvalid;
return;
}
@@ -3208,7 +3231,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
}
}
} else if (source_node->type == NodeTypeTestDecl) {
- FnTableEntry *fn_table_entry = create_fn_raw(FnInlineAuto);
+ ZigFn *fn_table_entry = create_fn_raw(FnInlineAuto);
get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');
@@ -3273,7 +3296,7 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
}
{
- TypeTableEntry *type = get_primitive_type(g, tld->name);
+ ZigType *type = get_primitive_type(g, tld->name);
if (type != nullptr) {
add_node_error(g, tld->source_node,
buf_sprintf("declaration shadows type '%s'", buf_ptr(&type->name)));
@@ -3437,17 +3460,17 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
}
static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {
- TypeTableEntry *type_entry = tld_container->type_entry;
+ ZigType *type_entry = tld_container->type_entry;
assert(type_entry);
switch (type_entry->id) {
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
resolve_struct_type(g, tld_container->type_entry);
return;
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
resolve_enum_type(g, tld_container->type_entry);
return;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
resolve_union_type(g, tld_container->type_entry);
return;
default:
@@ -3455,38 +3478,38 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {
}
}
-TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry) {
+ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
return g->builtin_types.entry_invalid;
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdBlock:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed",
buf_ptr(&type_entry->name)));
return g->builtin_types.entry_invalid;
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdPromise:
return type_entry;
}
zig_unreachable();
@@ -3494,12 +3517,12 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
// Set name to nullptr to make the variable anonymous (not visible to programmer).
// TODO merge with definition of add_local_var in ir.cpp
-VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
+ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
bool is_const, ConstExprValue *value, Tld *src_tld)
{
assert(value);
- VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
+ ZigVar *variable_entry = allocate<ZigVar>(1);
variable_entry->value = value;
variable_entry->parent_scope = parent_scope;
variable_entry->shadowable = false;
@@ -3512,14 +3535,14 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent
if (!type_is_invalid(value->type)) {
variable_entry->align_bytes = get_abi_alignment(g, value->type);
- VariableTableEntry *existing_var = find_variable(g, parent_scope, name);
+ ZigVar *existing_var = find_variable(g, parent_scope, name, nullptr);
if (existing_var && !existing_var->shadowable) {
ErrorMsg *msg = add_node_error(g, source_node,
buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
variable_entry->value->type = g->builtin_types.entry_invalid;
} else {
- TypeTableEntry *type = get_primitive_type(g, name);
+ ZigType *type = get_primitive_type(g, name);
if (type != nullptr) {
add_node_error(g, source_node,
buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
@@ -3570,9 +3593,9 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
bool is_extern = var_decl->is_extern;
bool is_export = var_decl->is_export;
- TypeTableEntry *explicit_type = nullptr;
+ ZigType *explicit_type = nullptr;
if (var_decl->type) {
- TypeTableEntry *proposed_type = analyze_type_expr(g, tld_var->base.parent_scope, var_decl->type);
+ ZigType *proposed_type = analyze_type_expr(g, tld_var->base.parent_scope, var_decl->type);
explicit_type = validate_var_type(g, var_decl->type, proposed_type);
}
@@ -3590,37 +3613,37 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
IrInstruction *init_value = nullptr;
// TODO more validation for types that can't be used for export/extern variables
- TypeTableEntry *implicit_type = nullptr;
- if (explicit_type && explicit_type->id == TypeTableEntryIdInvalid) {
+ ZigType *implicit_type = nullptr;
+ if (explicit_type && explicit_type->id == ZigTypeIdInvalid) {
implicit_type = explicit_type;
} else if (var_decl->expr) {
init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type, var_decl->symbol);
assert(init_value);
implicit_type = init_value->value.type;
- if (implicit_type->id == TypeTableEntryIdUnreachable) {
+ if (implicit_type->id == ZigTypeIdUnreachable) {
add_node_error(g, source_node, buf_sprintf("variable initialization is unreachable"));
implicit_type = g->builtin_types.entry_invalid;
} else if ((!is_const || linkage == VarLinkageExternal) &&
- (implicit_type->id == TypeTableEntryIdComptimeFloat ||
- implicit_type->id == TypeTableEntryIdComptimeInt))
+ (implicit_type->id == ZigTypeIdComptimeFloat ||
+ implicit_type->id == ZigTypeIdComptimeInt))
{
add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
implicit_type = g->builtin_types.entry_invalid;
- } else if (implicit_type->id == TypeTableEntryIdNull) {
+ } else if (implicit_type->id == ZigTypeIdNull) {
add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
implicit_type = g->builtin_types.entry_invalid;
- } else if (implicit_type->id == TypeTableEntryIdMetaType && !is_const) {
+ } else if (implicit_type->id == ZigTypeIdMetaType && !is_const) {
add_node_error(g, source_node, buf_sprintf("variable of type 'type' must be constant"));
implicit_type = g->builtin_types.entry_invalid;
}
- assert(implicit_type->id == TypeTableEntryIdInvalid || init_value->value.special != ConstValSpecialRuntime);
+ assert(implicit_type->id == ZigTypeIdInvalid || init_value->value.special != ConstValSpecialRuntime);
} else if (linkage != VarLinkageExternal) {
add_node_error(g, source_node, buf_sprintf("variables must be initialized"));
implicit_type = g->builtin_types.entry_invalid;
}
- TypeTableEntry *type = explicit_type ? explicit_type : implicit_type;
+ ZigType *type = explicit_type ? explicit_type : implicit_type;
assert(type != nullptr); // should have been caught by the parser
ConstExprValue *init_val = init_value ? &init_value->value : create_const_runtime(type);
@@ -3719,12 +3742,16 @@ Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {
return nullptr;
}
-VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {
+ZigVar *find_variable(CodeGen *g, Scope *scope, Buf *name, ScopeFnDef **crossed_fndef_scope) {
+ ScopeFnDef *my_crossed_fndef_scope = nullptr;
while (scope) {
if (scope->id == ScopeIdVarDecl) {
ScopeVarDecl *var_scope = (ScopeVarDecl *)scope;
- if (buf_eql_buf(name, &var_scope->var->name))
+ if (buf_eql_buf(name, &var_scope->var->name)) {
+ if (crossed_fndef_scope != nullptr)
+ *crossed_fndef_scope = my_crossed_fndef_scope;
return var_scope->var;
+ }
} else if (scope->id == ScopeIdDecls) {
ScopeDecls *decls_scope = (ScopeDecls *)scope;
auto entry = decls_scope->decl_table.maybe_get(name);
@@ -3732,10 +3759,15 @@ VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {
Tld *tld = entry->value;
if (tld->id == TldIdVar) {
TldVar *tld_var = (TldVar *)tld;
- if (tld_var->var)
+ if (tld_var->var) {
+ if (crossed_fndef_scope != nullptr)
+ *crossed_fndef_scope = nullptr;
return tld_var->var;
+ }
}
}
+ } else if (scope->id == ScopeIdFnDef) {
+ my_crossed_fndef_scope = (ScopeFnDef *)scope;
}
scope = scope->parent;
}
@@ -3743,7 +3775,7 @@ VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) {
return nullptr;
}
-FnTableEntry *scope_fn_entry(Scope *scope) {
+ZigFn *scope_fn_entry(Scope *scope) {
while (scope) {
if (scope->id == ScopeIdFnDef) {
ScopeFnDef *fn_scope = (ScopeFnDef *)scope;
@@ -3754,7 +3786,7 @@ FnTableEntry *scope_fn_entry(Scope *scope) {
return nullptr;
}
-FnTableEntry *scope_get_fn_if_root(Scope *scope) {
+ZigFn *scope_get_fn_if_root(Scope *scope) {
assert(scope);
scope = scope->parent;
while (scope) {
@@ -3770,6 +3802,7 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) {
case ScopeIdSuspend:
case ScopeIdCompTime:
case ScopeIdCoroPrelude:
+ case ScopeIdRuntime:
scope = scope->parent;
continue;
case ScopeIdFnDef:
@@ -3781,8 +3814,8 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) {
return nullptr;
}
-TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name) {
- assert(enum_type->id == TypeTableEntryIdEnum);
+TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) {
+ assert(enum_type->id == ZigTypeIdEnum);
if (enum_type->data.enumeration.src_field_count == 0)
return nullptr;
auto entry = enum_type->data.enumeration.fields_by_name.maybe_get(name);
@@ -3791,8 +3824,8 @@ TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name) {
return entry->value;
}
-TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) {
- assert(type_entry->id == TypeTableEntryIdStruct);
+TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name) {
+ assert(type_entry->id == ZigTypeIdStruct);
assert(type_entry->data.structure.complete);
if (type_entry->data.structure.src_field_count == 0)
return nullptr;
@@ -3802,8 +3835,8 @@ TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) {
return entry->value;
}
-TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) {
- assert(type_entry->id == TypeTableEntryIdUnion);
+TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name) {
+ assert(type_entry->id == ZigTypeIdUnion);
assert(type_entry->data.unionation.zero_bits_known);
if (type_entry->data.unionation.src_field_count == 0)
return nullptr;
@@ -3813,8 +3846,8 @@ TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) {
return entry->value;
}
-TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt *tag) {
- assert(type_entry->id == TypeTableEntryIdUnion);
+TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag) {
+ assert(type_entry->id == ZigTypeIdUnion);
assert(type_entry->data.unionation.zero_bits_known);
for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {
TypeUnionField *field = &type_entry->data.unionation.fields[i];
@@ -3825,7 +3858,7 @@ TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt
return nullptr;
}
-TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *tag) {
+TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag) {
assert(enum_type->data.enumeration.zero_bits_known);
for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) {
TypeEnumField *field = &enum_type->data.enumeration.fields[i];
@@ -3837,143 +3870,143 @@ TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *t
}
-static bool is_container(TypeTableEntry *type_entry) {
+static bool is_container(ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
+ case ZigTypeIdStruct:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
return true;
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdPointer:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdArray:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdPromise:
return false;
}
zig_unreachable();
}
-bool is_ref(TypeTableEntry *type_entry) {
- return type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle;
+bool is_ref(ZigType *type_entry) {
+ return type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle;
}
-bool is_array_ref(TypeTableEntry *type_entry) {
- TypeTableEntry *array = is_ref(type_entry) ?
+bool is_array_ref(ZigType *type_entry) {
+ ZigType *array = is_ref(type_entry) ?
type_entry->data.pointer.child_type : type_entry;
- return array->id == TypeTableEntryIdArray;
+ return array->id == ZigTypeIdArray;
}
-bool is_container_ref(TypeTableEntry *type_entry) {
+bool is_container_ref(ZigType *type_entry) {
return is_ref(type_entry) ?
is_container(type_entry->data.pointer.child_type) : is_container(type_entry);
}
-TypeTableEntry *container_ref_type(TypeTableEntry *type_entry) {
+ZigType *container_ref_type(ZigType *type_entry) {
assert(is_container_ref(type_entry));
return is_ref(type_entry) ?
type_entry->data.pointer.child_type : type_entry;
}
-void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {
+void resolve_container_type(CodeGen *g, ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
resolve_struct_type(g, type_entry);
break;
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
resolve_enum_type(g, type_entry);
break;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
resolve_union_type(g, type_entry);
break;
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdPointer:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdArray:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdPromise:
zig_unreachable();
}
}
-TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) {
- if (type->id == TypeTableEntryIdPointer) return type;
- if (type->id == TypeTableEntryIdFn) return type;
- if (type->id == TypeTableEntryIdPromise) return type;
- if (type->id == TypeTableEntryIdOptional) {
- if (type->data.maybe.child_type->id == TypeTableEntryIdPointer) return type->data.maybe.child_type;
- if (type->data.maybe.child_type->id == TypeTableEntryIdFn) return type->data.maybe.child_type;
- if (type->data.maybe.child_type->id == TypeTableEntryIdPromise) return type->data.maybe.child_type;
+ZigType *get_codegen_ptr_type(ZigType *type) {
+ if (type->id == ZigTypeIdPointer) return type;
+ if (type->id == ZigTypeIdFn) return type;
+ if (type->id == ZigTypeIdPromise) return type;
+ if (type->id == ZigTypeIdOptional) {
+ if (type->data.maybe.child_type->id == ZigTypeIdPointer) return type->data.maybe.child_type;
+ if (type->data.maybe.child_type->id == ZigTypeIdFn) return type->data.maybe.child_type;
+ if (type->data.maybe.child_type->id == ZigTypeIdPromise) return type->data.maybe.child_type;
}
return nullptr;
}
-bool type_is_codegen_pointer(TypeTableEntry *type) {
+bool type_is_codegen_pointer(ZigType *type) {
return get_codegen_ptr_type(type) == type;
}
-uint32_t get_ptr_align(TypeTableEntry *type) {
- TypeTableEntry *ptr_type = get_codegen_ptr_type(type);
- if (ptr_type->id == TypeTableEntryIdPointer) {
+uint32_t get_ptr_align(ZigType *type) {
+ ZigType *ptr_type = get_codegen_ptr_type(type);
+ if (ptr_type->id == ZigTypeIdPointer) {
return ptr_type->data.pointer.alignment;
- } else if (ptr_type->id == TypeTableEntryIdFn) {
+ } else if (ptr_type->id == ZigTypeIdFn) {
return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;
- } else if (ptr_type->id == TypeTableEntryIdPromise) {
+ } else if (ptr_type->id == ZigTypeIdPromise) {
return 1;
} else {
zig_unreachable();
}
}
-bool get_ptr_const(TypeTableEntry *type) {
- TypeTableEntry *ptr_type = get_codegen_ptr_type(type);
- if (ptr_type->id == TypeTableEntryIdPointer) {
+bool get_ptr_const(ZigType *type) {
+ ZigType *ptr_type = get_codegen_ptr_type(type);
+ if (ptr_type->id == ZigTypeIdPointer) {
return ptr_type->data.pointer.is_const;
- } else if (ptr_type->id == TypeTableEntryIdFn) {
+ } else if (ptr_type->id == ZigTypeIdFn) {
return true;
- } else if (ptr_type->id == TypeTableEntryIdPromise) {
+ } else if (ptr_type->id == ZigTypeIdPromise) {
return true;
} else {
zig_unreachable();
}
}
-AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) {
+AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index) {
if (fn_entry->param_source_nodes)
return fn_entry->param_source_nodes[index];
else if (fn_entry->proto_node)
@@ -3982,8 +4015,8 @@ AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) {
return nullptr;
}
-static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry) {
- TypeTableEntry *fn_type = fn_table_entry->type_entry;
+static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
+ ZigType *fn_type = fn_table_entry->type_entry;
assert(!fn_type->data.fn.is_generic);
FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
@@ -4000,14 +4033,14 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
continue;
}
- TypeTableEntry *param_type = param_info->type;
+ ZigType *param_type = param_info->type;
bool is_noalias = param_info->is_noalias;
if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) {
add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
}
- VariableTableEntry *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,
+ ZigVar *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,
param_name, true, create_const_runtime(param_type), nullptr);
var->src_arg_index = i;
fn_table_entry->child_scope = var->child_scope;
@@ -4023,8 +4056,8 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr
}
}
-bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node) {
- FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn;
+bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) {
+ ZigFn *infer_fn = err_set_type->data.error_set.infer_fn;
if (infer_fn != nullptr) {
if (infer_fn->anal_state == FnAnalStateInvalid) {
return false;
@@ -4044,12 +4077,12 @@ bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNod
return true;
}
-void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_type_node) {
- TypeTableEntry *fn_type = fn_table_entry->type_entry;
+void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node) {
+ ZigType *fn_type = fn_table_entry->type_entry;
assert(!fn_type->data.fn.is_generic);
FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
- TypeTableEntry *block_return_type = ir_analyze(g, &fn_table_entry->ir_executable,
+ ZigType *block_return_type = ir_analyze(g, &fn_table_entry->ir_executable,
&fn_table_entry->analyzed_executable, fn_type_id->return_type, return_type_node);
fn_table_entry->src_implicit_return_type = block_return_type;
@@ -4059,13 +4092,13 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
return;
}
- if (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion) {
- TypeTableEntry *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type;
+ if (fn_type_id->return_type->id == ZigTypeIdErrorUnion) {
+ ZigType *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type;
if (return_err_set_type->data.error_set.infer_fn != nullptr) {
- TypeTableEntry *inferred_err_set_type;
- if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorSet) {
+ ZigType *inferred_err_set_type;
+ if (fn_table_entry->src_implicit_return_type->id == ZigTypeIdErrorSet) {
inferred_err_set_type = fn_table_entry->src_implicit_return_type;
- } else if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorUnion) {
+ } else if (fn_table_entry->src_implicit_return_type->id == ZigTypeIdErrorUnion) {
inferred_err_set_type = fn_table_entry->src_implicit_return_type->data.error_union.err_set_type;
} else {
add_node_error(g, return_type_node,
@@ -4105,7 +4138,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ
fn_table_entry->anal_state = FnAnalStateComplete;
}
-static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
+static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
assert(fn_table_entry->anal_state != FnAnalStateProbing);
if (fn_table_entry->anal_state != FnAnalStateReady)
return;
@@ -4121,7 +4154,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
define_local_param_variables(g, fn_table_entry);
- TypeTableEntry *fn_type = fn_table_entry->type_entry;
+ ZigType *fn_type = fn_table_entry->type_entry;
assert(!fn_type->data.fn.is_generic);
ir_gen_fn(g, fn_table_entry);
@@ -4146,7 +4179,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode *
}
IrInstruction *use_target_value = src_use_node->data.use.value;
- if (use_target_value->value.type->id == TypeTableEntryIdInvalid) {
+ if (use_target_value->value.type->id == ZigTypeIdInvalid) {
dst_use_node->owner->any_imports_failed = true;
return;
}
@@ -4222,15 +4255,15 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base,
node->data.use.expr, g->builtin_types.entry_namespace, nullptr);
- if (result->value.type->id == TypeTableEntryIdInvalid)
+ if (result->value.type->id == ZigTypeIdInvalid)
node->owner->any_imports_failed = true;
node->data.use.value = result;
}
-ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code) {
+ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *resolved_path, Buf *source_code) {
if (g->verbose_tokenize) {
- fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(abs_full_path));
+ fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(resolved_path));
fprintf(stderr, "----------------\n");
fprintf(stderr, "%s\n", buf_ptr(source_code));
@@ -4242,7 +4275,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
tokenize(source_code, &tokenization);
if (tokenization.err) {
- ErrorMsg *err = err_msg_create_with_line(abs_full_path, tokenization.err_line, tokenization.err_column,
+ ErrorMsg *err = err_msg_create_with_line(resolved_path, tokenization.err_line, tokenization.err_column,
source_code, tokenization.line_offsets, tokenization.err);
print_err_msg(err, g->err_color);
@@ -4260,7 +4293,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
import_entry->package = package;
import_entry->source_code = source_code;
import_entry->line_offsets = tokenization.line_offsets;
- import_entry->path = abs_full_path;
+ import_entry->path = resolved_path;
import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);
assert(import_entry->root);
@@ -4270,10 +4303,10 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a
Buf *src_dirname = buf_alloc();
Buf *src_basename = buf_alloc();
- os_path_split(abs_full_path, src_dirname, src_basename);
+ os_path_split(resolved_path, src_dirname, src_basename);
import_entry->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname));
- g->import_table.put(abs_full_path, import_entry);
+ g->import_table.put(resolved_path, import_entry);
g->import_queue.append(import_entry);
import_entry->decls_scope = create_decls_scope(import_entry->root, nullptr, nullptr, import_entry);
@@ -4341,15 +4374,15 @@ void semantic_analyze(CodeGen *g) {
}
for (; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) {
- FnTableEntry *fn_entry = g->fn_defs.at(g->fn_defs_index);
+ ZigFn *fn_entry = g->fn_defs.at(g->fn_defs_index);
analyze_fn_body(g, fn_entry);
}
}
}
-TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
+ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
TypeId type_id = {};
- type_id.id = TypeTableEntryIdInt;
+ type_id.id = ZigTypeIdInt;
type_id.data.integer.is_signed = is_signed;
type_id.data.integer.bit_count = size_in_bits;
@@ -4359,53 +4392,53 @@ TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits)
return entry->value;
}
- TypeTableEntry *new_entry = make_int_type(g, is_signed, size_in_bits);
+ ZigType *new_entry = make_int_type(g, is_signed, size_in_bits);
g->type_table.put(type_id, new_entry);
return new_entry;
}
-TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type) {
+ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type) {
return &g->builtin_types.entry_c_int[c_int_type];
}
-TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type) {
+ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type) {
return *get_c_int_type_ptr(g, c_int_type);
}
-bool handle_is_ptr(TypeTableEntry *type_entry) {
+bool handle_is_ptr(ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
zig_unreachable();
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdFn:
+ case ZigTypeIdEnum:
+ case ZigTypeIdPromise:
return false;
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
return type_has_bits(type_entry);
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
return type_has_bits(type_entry->data.error_union.payload_type);
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
return type_has_bits(type_entry->data.maybe.child_type) &&
!type_is_codegen_pointer(type_entry->data.maybe.child_type);
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
assert(type_entry->data.unionation.complete);
if (type_entry->data.unionation.gen_field_count == 0)
return false;
@@ -4594,11 +4627,11 @@ static uint32_t hash_size(size_t x) {
return (uint32_t)(x % UINT32_MAX);
}
-uint32_t fn_table_entry_hash(FnTableEntry* value) {
+uint32_t fn_table_entry_hash(ZigFn* value) {
return ptr_hash(value);
}
-bool fn_table_entry_eql(FnTableEntry *a, FnTableEntry *b) {
+bool fn_table_entry_eql(ZigFn *a, ZigFn *b) {
return ptr_eq(a, b);
}
@@ -4689,16 +4722,16 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) {
static uint32_t hash_const_val(ConstExprValue *const_val) {
assert(const_val->special == ConstValSpecialStatic);
switch (const_val->type->id) {
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdOpaque:
zig_unreachable();
- case TypeTableEntryIdBool:
+ case ZigTypeIdBool:
return const_val->data.x_bool ? (uint32_t)127863866 : (uint32_t)215080464;
- case TypeTableEntryIdMetaType:
+ case ZigTypeIdMetaType:
return hash_ptr(const_val->data.x_type);
- case TypeTableEntryIdVoid:
+ case ZigTypeIdVoid:
return (uint32_t)4149439618;
- case TypeTableEntryIdInt:
- case TypeTableEntryIdComptimeInt:
+ case ZigTypeIdInt:
+ case ZigTypeIdComptimeInt:
{
uint32_t result = 1331471175;
for (size_t i = 0; i < const_val->data.x_bigint.digit_count; i += 1) {
@@ -4707,7 +4740,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
}
return result;
}
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
{
uint32_t result = 31643936;
for (size_t i = 0; i < const_val->data.x_enum_tag.digit_count; i += 1) {
@@ -4716,7 +4749,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
}
return result;
}
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
switch (const_val->type->data.floating.bit_count) {
case 16:
{
@@ -4746,39 +4779,39 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
default:
zig_unreachable();
}
- case TypeTableEntryIdComptimeFloat:
+ case ZigTypeIdComptimeFloat:
{
float128_t f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);
uint32_t ints[4];
memcpy(&ints[0], &f128, 16);
return ints[0] ^ ints[1] ^ ints[2] ^ ints[3] ^ 0xed8b3dfb;
}
- case TypeTableEntryIdArgTuple:
+ case ZigTypeIdArgTuple:
return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 +
(uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768;
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
return hash_const_val_ptr(const_val);
- case TypeTableEntryIdPromise:
+ case ZigTypeIdPromise:
// TODO better hashing algorithm
return 223048345;
- case TypeTableEntryIdUndefined:
+ case ZigTypeIdUndefined:
return 162837799;
- case TypeTableEntryIdNull:
+ case ZigTypeIdNull:
return 844854567;
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
// TODO better hashing algorithm
return 1166190605;
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
// TODO better hashing algorithm
return 1532530855;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
// TODO better hashing algorithm
return 2709806591;
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
if (get_codegen_ptr_type(const_val->type) != nullptr) {
return hash_const_val(const_val) * 1992916303;
} else {
@@ -4788,19 +4821,19 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
return 4016830364;
}
}
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
// TODO better hashing algorithm
return 3415065496;
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdErrorSet:
assert(const_val->data.x_err_set != nullptr);
return const_val->data.x_err_set->value ^ 2630160122;
- case TypeTableEntryIdNamespace:
+ case ZigTypeIdNamespace:
return hash_ptr(const_val->data.x_import);
- case TypeTableEntryIdBlock:
+ case ZigTypeIdBlock:
return hash_ptr(const_val->data.x_block);
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdUnreachable:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdUnreachable:
zig_unreachable();
}
zig_unreachable();
@@ -4843,32 +4876,32 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) {
static bool can_mutate_comptime_var_state(ConstExprValue *value) {
assert(value != nullptr);
switch (value->type->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdPromise:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdFn:
+ case ZigTypeIdBlock:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdPromise:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
return false;
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
if (value->type->data.array.len == 0)
return false;
if (value->data.x_array.special == ConstArraySpecialUndef)
@@ -4879,78 +4912,78 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
}
return false;
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) {
if (can_mutate_comptime_var_state(&value->data.x_struct.fields[i]))
return true;
}
return false;
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
if (get_codegen_ptr_type(value->type) != nullptr)
return value->data.x_ptr.mut == ConstPtrMutComptimeVar;
if (value->data.x_optional == nullptr)
return false;
return can_mutate_comptime_var_state(value->data.x_optional);
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
if (value->data.x_err_union.err != nullptr)
return false;
assert(value->data.x_err_union.payload != nullptr);
return can_mutate_comptime_var_state(value->data.x_err_union.payload);
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
return can_mutate_comptime_var_state(value->data.x_union.payload);
- case TypeTableEntryIdArgTuple:
+ case ZigTypeIdArgTuple:
zig_panic("TODO var args at comptime is currently not supported");
}
zig_unreachable();
}
-static bool return_type_is_cacheable(TypeTableEntry *return_type) {
+static bool return_type_is_cacheable(ZigType *return_type) {
switch (return_type->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdPromise:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdPointer:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdFn:
+ case ZigTypeIdBlock:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdPromise:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdPointer:
return true;
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdUnion:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdUnion:
return false;
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
return return_type_is_cacheable(return_type->data.maybe.child_type);
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
return return_type_is_cacheable(return_type->data.error_union.payload_type);
- case TypeTableEntryIdArgTuple:
+ case ZigTypeIdArgTuple:
zig_panic("TODO var args at comptime is currently not supported");
}
zig_unreachable();
}
-bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type) {
+bool fn_eval_cacheable(Scope *scope, ZigType *return_type) {
if (!return_type_is_cacheable(return_type))
return false;
while (scope) {
@@ -5019,56 +5052,56 @@ bool fn_eval_eql(Scope *a, Scope *b) {
return false;
}
-bool type_has_bits(TypeTableEntry *type_entry) {
+bool type_has_bits(ZigType *type_entry) {
assert(type_entry);
- assert(type_entry->id != TypeTableEntryIdInvalid);
+ assert(type_entry->id != ZigTypeIdInvalid);
assert(type_has_zero_bits_known(type_entry));
return !type_entry->zero_bits;
}
-bool type_requires_comptime(TypeTableEntry *type_entry) {
+bool type_requires_comptime(ZigType *type_entry) {
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdOpaque:
zig_unreachable();
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
return true;
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
return type_requires_comptime(type_entry->data.array.child_type);
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
assert(type_has_zero_bits_known(type_entry));
return type_entry->data.structure.requires_comptime;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
assert(type_has_zero_bits_known(type_entry));
return type_entry->data.unionation.requires_comptime;
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
return type_requires_comptime(type_entry->data.maybe.child_type);
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
return type_requires_comptime(type_entry->data.error_union.payload_type);
- case TypeTableEntryIdPointer:
- if (type_entry->data.pointer.child_type->id == TypeTableEntryIdOpaque) {
+ case ZigTypeIdPointer:
+ if (type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
return false;
} else {
return type_requires_comptime(type_entry->data.pointer.child_type);
}
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
return type_entry->data.fn.is_generic;
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdEnum:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdVoid:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdPromise:
return false;
}
zig_unreachable();
@@ -5135,27 +5168,27 @@ ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *str) {
return const_val;
}
-void init_const_bigint(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *bigint) {
+void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint) {
const_val->special = ConstValSpecialStatic;
const_val->type = type;
bigint_init_bigint(&const_val->data.x_bigint, bigint);
}
-ConstExprValue *create_const_bigint(TypeTableEntry *type, const BigInt *bigint) {
+ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint) {
ConstExprValue *const_val = create_const_vals(1);
init_const_bigint(const_val, type, bigint);
return const_val;
}
-void init_const_unsigned_negative(ConstExprValue *const_val, TypeTableEntry *type, uint64_t x, bool negative) {
+void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative) {
const_val->special = ConstValSpecialStatic;
const_val->type = type;
bigint_init_unsigned(&const_val->data.x_bigint, x);
const_val->data.x_bigint.is_negative = negative;
}
-ConstExprValue *create_const_unsigned_negative(TypeTableEntry *type, uint64_t x, bool negative) {
+ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {
ConstExprValue *const_val = create_const_vals(1);
init_const_unsigned_negative(const_val, type, x, negative);
return const_val;
@@ -5169,24 +5202,24 @@ ConstExprValue *create_const_usize(CodeGen *g, uint64_t x) {
return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);
}
-void init_const_signed(ConstExprValue *const_val, TypeTableEntry *type, int64_t x) {
+void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x) {
const_val->special = ConstValSpecialStatic;
const_val->type = type;
bigint_init_signed(&const_val->data.x_bigint, x);
}
-ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x) {
+ConstExprValue *create_const_signed(ZigType *type, int64_t x) {
ConstExprValue *const_val = create_const_vals(1);
init_const_signed(const_val, type, x);
return const_val;
}
-void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value) {
+void init_const_float(ConstExprValue *const_val, ZigType *type, double value) {
const_val->special = ConstValSpecialStatic;
const_val->type = type;
- if (type->id == TypeTableEntryIdComptimeFloat) {
+ if (type->id == ZigTypeIdComptimeFloat) {
bigfloat_init_64(&const_val->data.x_bigfloat, value);
- } else if (type->id == TypeTableEntryIdFloat) {
+ } else if (type->id == ZigTypeIdFloat) {
switch (type->data.floating.bit_count) {
case 16:
const_val->data.x_f16 = zig_double_to_f16(value);
@@ -5208,19 +5241,19 @@ void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double va
}
}
-ConstExprValue *create_const_float(TypeTableEntry *type, double value) {
+ConstExprValue *create_const_float(ZigType *type, double value) {
ConstExprValue *const_val = create_const_vals(1);
init_const_float(const_val, type, value);
return const_val;
}
-void init_const_enum(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *tag) {
+void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag) {
const_val->special = ConstValSpecialStatic;
const_val->type = type;
bigint_init_bigint(&const_val->data.x_enum_tag, tag);
}
-ConstExprValue *create_const_enum(TypeTableEntry *type, const BigInt *tag) {
+ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag) {
ConstExprValue *const_val = create_const_vals(1);
init_const_enum(const_val, type, tag);
return const_val;
@@ -5239,24 +5272,24 @@ ConstExprValue *create_const_bool(CodeGen *g, bool value) {
return const_val;
}
-void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type) {
+void init_const_runtime(ConstExprValue *const_val, ZigType *type) {
const_val->special = ConstValSpecialRuntime;
const_val->type = type;
}
-ConstExprValue *create_const_runtime(TypeTableEntry *type) {
+ConstExprValue *create_const_runtime(ZigType *type) {
ConstExprValue *const_val = create_const_vals(1);
init_const_runtime(const_val, type);
return const_val;
}
-void init_const_type(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *type_value) {
+void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value) {
const_val->special = ConstValSpecialStatic;
const_val->type = g->builtin_types.entry_type;
const_val->data.x_type = type_value;
}
-ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value) {
+ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) {
ConstExprValue *const_val = create_const_vals(1);
init_const_type(g, const_val, type_value);
return const_val;
@@ -5265,9 +5298,9 @@ ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value) {
void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
size_t start, size_t len, bool is_const)
{
- assert(array_val->type->id == TypeTableEntryIdArray);
+ assert(array_val->type->id == ZigTypeIdArray);
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, array_val->type->data.array.child_type,
+ ZigType *ptr_type = get_pointer_to_type_extra(g, array_val->type->data.array.child_type,
is_const, false, PtrLenUnknown, get_abi_alignment(g, array_val->type->data.array.child_type),
0, 0);
@@ -5289,8 +5322,8 @@ ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t
void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
size_t elem_index, bool is_const, PtrLen ptr_len)
{
- assert(array_val->type->id == TypeTableEntryIdArray);
- TypeTableEntry *child_type = array_val->type->data.array.child_type;
+ assert(array_val->type->id == ZigTypeIdArray);
+ ZigType *child_type = array_val->type->data.array.child_type;
const_val->special = ConstValSpecialStatic;
const_val->type = get_pointer_to_type_extra(g, child_type, is_const, false,
@@ -5321,7 +5354,7 @@ ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bo
return const_val;
}
-void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *pointee_type,
+void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type,
size_t addr, bool is_const)
{
const_val->special = ConstValSpecialStatic;
@@ -5330,7 +5363,7 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeT
const_val->data.x_ptr.data.hard_coded_addr.addr = addr;
}
-ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, TypeTableEntry *pointee_type,
+ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
size_t addr, bool is_const)
{
ConstExprValue *const_val = create_const_vals(1);
@@ -5354,11 +5387,11 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_
void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
Error err;
- TypeTableEntry *wanted_type = const_val->type;
- if (wanted_type->id == TypeTableEntryIdArray) {
+ ZigType *wanted_type = const_val->type;
+ if (wanted_type->id == ZigTypeIdArray) {
const_val->special = ConstValSpecialStatic;
const_val->data.x_array.special = ConstArraySpecialUndef;
- } else if (wanted_type->id == TypeTableEntryIdStruct) {
+ } else if (wanted_type->id == ZigTypeIdStruct) {
if ((err = ensure_complete_type(g, wanted_type))) {
return;
}
@@ -5392,36 +5425,36 @@ ConstExprValue *create_const_vals(size_t count) {
return vals;
}
-Error ensure_complete_type(CodeGen *g, TypeTableEntry *type_entry) {
+Error ensure_complete_type(CodeGen *g, ZigType *type_entry) {
if (type_is_invalid(type_entry))
return ErrorSemanticAnalyzeFail;
- if (type_entry->id == TypeTableEntryIdStruct) {
+ if (type_entry->id == ZigTypeIdStruct) {
if (!type_entry->data.structure.complete)
return resolve_struct_type(g, type_entry);
- } else if (type_entry->id == TypeTableEntryIdEnum) {
+ } else if (type_entry->id == ZigTypeIdEnum) {
if (!type_entry->data.enumeration.complete)
return resolve_enum_type(g, type_entry);
- } else if (type_entry->id == TypeTableEntryIdUnion) {
+ } else if (type_entry->id == ZigTypeIdUnion) {
if (!type_entry->data.unionation.complete)
return resolve_union_type(g, type_entry);
}
return ErrorNone;
}
-Error type_ensure_zero_bits_known(CodeGen *g, TypeTableEntry *type_entry) {
+Error type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry) {
if (type_is_invalid(type_entry))
return ErrorSemanticAnalyzeFail;
- if (type_entry->id == TypeTableEntryIdStruct) {
+ if (type_entry->id == ZigTypeIdStruct) {
return resolve_struct_zero_bits(g, type_entry);
- } else if (type_entry->id == TypeTableEntryIdEnum) {
+ } else if (type_entry->id == ZigTypeIdEnum) {
return resolve_enum_zero_bits(g, type_entry);
- } else if (type_entry->id == TypeTableEntryIdUnion) {
+ } else if (type_entry->id == ZigTypeIdUnion) {
return resolve_union_zero_bits(g, type_entry);
}
return ErrorNone;
}
-bool ir_get_var_is_comptime(VariableTableEntry *var) {
+bool ir_get_var_is_comptime(ZigVar *var) {
if (!var->is_comptime)
return false;
if (var->is_comptime->other)
@@ -5480,11 +5513,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
assert(a->special == ConstValSpecialStatic);
assert(b->special == ConstValSpecialStatic);
switch (a->type->id) {
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdOpaque:
zig_unreachable();
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
return bigint_cmp(&a->data.x_enum_tag, &b->data.x_enum_tag) == CmpEQ;
- case TypeTableEntryIdUnion: {
+ case ZigTypeIdUnion: {
ConstUnionValue *union1 = &a->data.x_union;
ConstUnionValue *union2 = &b->data.x_union;
@@ -5499,15 +5532,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
}
return false;
}
- case TypeTableEntryIdMetaType:
+ case ZigTypeIdMetaType:
return a->data.x_type == b->data.x_type;
- case TypeTableEntryIdVoid:
+ case ZigTypeIdVoid:
return true;
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdErrorSet:
return a->data.x_err_set->value == b->data.x_err_set->value;
- case TypeTableEntryIdBool:
+ case ZigTypeIdBool:
return a->data.x_bool == b->data.x_bool;
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
assert(a->type->data.floating.bit_count == b->type->data.floating.bit_count);
switch (a->type->data.floating.bit_count) {
case 16:
@@ -5521,15 +5554,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
default:
zig_unreachable();
}
- case TypeTableEntryIdComptimeFloat:
+ case ZigTypeIdComptimeFloat:
return bigfloat_cmp(&a->data.x_bigfloat, &b->data.x_bigfloat) == CmpEQ;
- case TypeTableEntryIdInt:
- case TypeTableEntryIdComptimeInt:
+ case ZigTypeIdInt:
+ case ZigTypeIdComptimeInt:
return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ;
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdFn:
+ case ZigTypeIdPointer:
+ case ZigTypeIdFn:
return const_values_equal_ptr(a, b);
- case TypeTableEntryIdArray: {
+ case ZigTypeIdArray: {
assert(a->type->data.array.len == b->type->data.array.len);
assert(a->data.x_array.special != ConstArraySpecialUndef);
assert(b->data.x_array.special != ConstArraySpecialUndef);
@@ -5545,7 +5578,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
return true;
}
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) {
ConstExprValue *field_a = &a->data.x_struct.fields[i];
ConstExprValue *field_b = &b->data.x_struct.fields[i];
@@ -5553,11 +5586,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
return false;
}
return true;
- case TypeTableEntryIdUndefined:
+ case ZigTypeIdUndefined:
zig_panic("TODO");
- case TypeTableEntryIdNull:
+ case ZigTypeIdNull:
zig_panic("TODO");
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
if (get_codegen_ptr_type(a->type) != nullptr)
return const_values_equal_ptr(a, b);
if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) {
@@ -5565,26 +5598,26 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
} else {
return const_values_equal(a->data.x_optional, b->data.x_optional);
}
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
zig_panic("TODO");
- case TypeTableEntryIdNamespace:
+ case ZigTypeIdNamespace:
return a->data.x_import == b->data.x_import;
- case TypeTableEntryIdBlock:
+ case ZigTypeIdBlock:
return a->data.x_block == b->data.x_block;
- case TypeTableEntryIdArgTuple:
+ 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;
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdPromise:
zig_unreachable();
}
zig_unreachable();
}
-void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint, bool is_max) {
- assert(int_type->id == TypeTableEntryIdInt);
+void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max) {
+ assert(int_type->id == ZigTypeIdInt);
if (int_type->data.integral.bit_count == 0) {
bigint_init_unsigned(bigint, 0);
return;
@@ -5620,21 +5653,21 @@ void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint
}
}
-void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max) {
- if (type_entry->id == TypeTableEntryIdInt) {
+void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max) {
+ if (type_entry->id == ZigTypeIdInt) {
const_val->special = ConstValSpecialStatic;
eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max);
- } else if (type_entry->id == TypeTableEntryIdBool) {
+ } else if (type_entry->id == ZigTypeIdBool) {
const_val->special = ConstValSpecialStatic;
const_val->data.x_bool = is_max;
- } else if (type_entry->id == TypeTableEntryIdVoid) {
+ } else if (type_entry->id == ZigTypeIdVoid) {
// nothing to do
} else {
zig_unreachable();
}
}
-void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, TypeTableEntry *type_entry) {
+void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) {
switch (const_val->data.x_ptr.special) {
case ConstPtrSpecialInvalid:
zig_unreachable();
@@ -5661,7 +5694,7 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, TypeT
return;
case ConstPtrSpecialFunction:
{
- FnTableEntry *fn_entry = const_val->data.x_ptr.data.fn.fn_entry;
+ ZigFn *fn_entry = const_val->data.x_ptr.data.fn.fn_entry;
buf_appendf(buf, "@ptrCast(%s, %s)", buf_ptr(&const_val->type->name), buf_ptr(&fn_entry->symbol_name));
return;
}
@@ -5682,20 +5715,20 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
}
assert(const_val->type);
- TypeTableEntry *type_entry = const_val->type;
+ ZigType *type_entry = const_val->type;
switch (type_entry->id) {
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdOpaque:
zig_unreachable();
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
buf_appendf(buf, "(invalid)");
return;
- case TypeTableEntryIdVoid:
+ case ZigTypeIdVoid:
buf_appendf(buf, "{}");
return;
- case TypeTableEntryIdComptimeFloat:
+ case ZigTypeIdComptimeFloat:
bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
return;
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
switch (type_entry->data.floating.bit_count) {
case 16:
buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16));
@@ -5723,41 +5756,41 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
default:
zig_unreachable();
}
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdInt:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdInt:
bigint_append_buf(buf, &const_val->data.x_bigint, 10);
return;
- case TypeTableEntryIdMetaType:
+ case ZigTypeIdMetaType:
buf_appendf(buf, "%s", buf_ptr(&const_val->data.x_type->name));
return;
- case TypeTableEntryIdUnreachable:
+ case ZigTypeIdUnreachable:
buf_appendf(buf, "unreachable");
return;
- case TypeTableEntryIdBool:
+ case ZigTypeIdBool:
{
const char *value = const_val->data.x_bool ? "true" : "false";
buf_appendf(buf, "%s", value);
return;
}
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
{
assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
- FnTableEntry *fn_entry = const_val->data.x_ptr.data.fn.fn_entry;
+ ZigFn *fn_entry = const_val->data.x_ptr.data.fn.fn_entry;
buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name));
return;
}
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
return render_const_val_ptr(g, buf, const_val, type_entry);
- case TypeTableEntryIdBlock:
+ case ZigTypeIdBlock:
{
AstNode *node = const_val->data.x_block->source_node;
buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1);
return;
}
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
{
- TypeTableEntry *child_type = type_entry->data.array.child_type;
+ ZigType *child_type = type_entry->data.array.child_type;
uint64_t len = type_entry->data.array.len;
if (const_val->data.x_array.special == ConstArraySpecialUndef) {
@@ -5766,7 +5799,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
}
// if it's []u8, assume UTF-8 and output a string
- if (child_type->id == TypeTableEntryIdInt &&
+ if (child_type->id == ZigTypeIdInt &&
child_type->data.integral.bit_count == 8 &&
!child_type->data.integral.is_signed)
{
@@ -5796,17 +5829,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
buf_appendf(buf, "}");
return;
}
- case TypeTableEntryIdNull:
+ case ZigTypeIdNull:
{
buf_appendf(buf, "null");
return;
}
- case TypeTableEntryIdUndefined:
+ case ZigTypeIdUndefined:
{
buf_appendf(buf, "undefined");
return;
}
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
{
if (get_codegen_ptr_type(const_val->type) != nullptr)
return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type);
@@ -5817,7 +5850,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
}
return;
}
- case TypeTableEntryIdNamespace:
+ case ZigTypeIdNamespace:
{
ImportTableEntry *import = const_val->data.x_import;
if (import->c_import_node) {
@@ -5827,51 +5860,51 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
}
return;
}
- case TypeTableEntryIdBoundFn:
+ case ZigTypeIdBoundFn:
{
- FnTableEntry *fn_entry = const_val->data.x_bound_fn.fn;
+ ZigFn *fn_entry = const_val->data.x_bound_fn.fn;
buf_appendf(buf, "(bound fn %s)", buf_ptr(&fn_entry->symbol_name));
return;
}
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
{
buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name));
return;
}
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
{
TypeEnumField *field = find_enum_field_by_tag(type_entry, &const_val->data.x_enum_tag);
buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(field->name));
return;
}
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
{
buf_appendf(buf, "(error union %s constant)", buf_ptr(&type_entry->name));
return;
}
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
{
buf_appendf(buf, "(union %s constant)", buf_ptr(&type_entry->name));
return;
}
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdErrorSet:
{
buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(&const_val->data.x_err_set->name));
return;
}
- case TypeTableEntryIdArgTuple:
+ case ZigTypeIdArgTuple:
{
buf_appendf(buf, "(args value)");
return;
}
- case TypeTableEntryIdPromise:
+ case ZigTypeIdPromise:
zig_unreachable();
}
zig_unreachable();
}
-TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
+ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) {
+ ZigType *entry = new_type_table_entry(ZigTypeIdInt);
entry->is_copyable = true;
entry->type_ref = (size_in_bits == 0) ? LLVMVoidType() : LLVMIntType(size_in_bits);
entry->zero_bits = (size_in_bits == 0);
@@ -5905,32 +5938,32 @@ TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits)
uint32_t type_id_hash(TypeId x) {
switch (x.id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdFloat:
+ case ZigTypeIdStruct:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdPromise:
zig_unreachable();
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
return hash_ptr(x.data.pointer.child_type) +
((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) +
(x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) +
@@ -5938,10 +5971,10 @@ uint32_t type_id_hash(TypeId x) {
(((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) +
(((uint32_t)x.data.pointer.bit_offset) ^ (uint32_t)2639019452) +
(((uint32_t)x.data.pointer.unaligned_bit_count) ^ (uint32_t)529908881);
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
return hash_ptr(x.data.array.child_type) +
((uint32_t)x.data.array.size ^ (uint32_t)2122979968);
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
return (x.data.integer.is_signed ? (uint32_t)2652528194 : (uint32_t)163929201) +
(((uint32_t)x.data.integer.bit_count) ^ (uint32_t)2998081557);
}
@@ -5952,34 +5985,34 @@ bool type_id_eql(TypeId a, TypeId b) {
if (a.id != b.id)
return false;
switch (a.id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdPromise:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdFloat:
+ case ZigTypeIdStruct:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdPromise:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
zig_unreachable();
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
return a.data.error_union.err_set_type == b.data.error_union.err_set_type &&
a.data.error_union.payload_type == b.data.error_union.payload_type;
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
return a.data.pointer.child_type == b.data.pointer.child_type &&
a.data.pointer.ptr_len == b.data.pointer.ptr_len &&
a.data.pointer.is_const == b.data.pointer.is_const &&
@@ -5987,10 +6020,10 @@ bool type_id_eql(TypeId a, TypeId b) {
a.data.pointer.alignment == b.data.pointer.alignment &&
a.data.pointer.bit_offset == b.data.pointer.bit_offset &&
a.data.pointer.unaligned_bit_count == b.data.pointer.unaligned_bit_count;
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
return a.data.array.child_type == b.data.array.child_type &&
a.data.array.size == b.data.array.size;
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
return a.data.integer.is_signed == b.data.integer.is_signed &&
a.data.integer.bit_count == b.data.integer.bit_count;
}
@@ -6042,7 +6075,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {
}
void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
- assert(const_val->type->id == TypeTableEntryIdArray);
+ assert(const_val->type->id == ZigTypeIdArray);
if (const_val->data.x_array.special == ConstArraySpecialUndef) {
const_val->data.x_array.special = ConstArraySpecialNone;
size_t elem_count = const_val->type->data.array.len;
@@ -6063,47 +6096,47 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) {
ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) {
assert(value->type);
- TypeTableEntry *type_entry = value->type;
- if (type_entry->id == TypeTableEntryIdArray) {
+ ZigType *type_entry = value->type;
+ if (type_entry->id == ZigTypeIdArray) {
expand_undef_array(g, value);
return &value->data.x_array.s_none.parent;
- } else if (type_entry->id == TypeTableEntryIdStruct) {
+ } else if (type_entry->id == ZigTypeIdStruct) {
return &value->data.x_struct.parent;
- } else if (type_entry->id == TypeTableEntryIdUnion) {
+ } else if (type_entry->id == ZigTypeIdUnion) {
return &value->data.x_union.parent;
}
return nullptr;
}
-static const TypeTableEntryId all_type_ids[] = {
- TypeTableEntryIdMetaType,
- TypeTableEntryIdVoid,
- TypeTableEntryIdBool,
- TypeTableEntryIdUnreachable,
- TypeTableEntryIdInt,
- TypeTableEntryIdFloat,
- TypeTableEntryIdPointer,
- TypeTableEntryIdArray,
- TypeTableEntryIdStruct,
- TypeTableEntryIdComptimeFloat,
- TypeTableEntryIdComptimeInt,
- TypeTableEntryIdUndefined,
- TypeTableEntryIdNull,
- TypeTableEntryIdOptional,
- TypeTableEntryIdErrorUnion,
- TypeTableEntryIdErrorSet,
- TypeTableEntryIdEnum,
- TypeTableEntryIdUnion,
- TypeTableEntryIdFn,
- TypeTableEntryIdNamespace,
- TypeTableEntryIdBlock,
- TypeTableEntryIdBoundFn,
- TypeTableEntryIdArgTuple,
- TypeTableEntryIdOpaque,
- TypeTableEntryIdPromise,
+static const ZigTypeId all_type_ids[] = {
+ ZigTypeIdMetaType,
+ ZigTypeIdVoid,
+ ZigTypeIdBool,
+ ZigTypeIdUnreachable,
+ ZigTypeIdInt,
+ ZigTypeIdFloat,
+ ZigTypeIdPointer,
+ ZigTypeIdArray,
+ ZigTypeIdStruct,
+ ZigTypeIdComptimeFloat,
+ ZigTypeIdComptimeInt,
+ ZigTypeIdUndefined,
+ ZigTypeIdNull,
+ ZigTypeIdOptional,
+ ZigTypeIdErrorUnion,
+ ZigTypeIdErrorSet,
+ ZigTypeIdEnum,
+ ZigTypeIdUnion,
+ ZigTypeIdFn,
+ ZigTypeIdNamespace,
+ ZigTypeIdBlock,
+ ZigTypeIdBoundFn,
+ ZigTypeIdArgTuple,
+ ZigTypeIdOpaque,
+ ZigTypeIdPromise,
};
-TypeTableEntryId type_id_at_index(size_t index) {
+ZigTypeId type_id_at_index(size_t index) {
assert(index < array_length(all_type_ids));
return all_type_ids[index];
}
@@ -6112,119 +6145,119 @@ size_t type_id_len() {
return array_length(all_type_ids);
}
-size_t type_id_index(TypeTableEntry *entry) {
+size_t type_id_index(ZigType *entry) {
switch (entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdMetaType:
+ case ZigTypeIdMetaType:
return 0;
- case TypeTableEntryIdVoid:
+ case ZigTypeIdVoid:
return 1;
- case TypeTableEntryIdBool:
+ case ZigTypeIdBool:
return 2;
- case TypeTableEntryIdUnreachable:
+ case ZigTypeIdUnreachable:
return 3;
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
return 4;
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
return 5;
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
return 6;
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
return 7;
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
if (entry->data.structure.is_slice)
return 6;
return 8;
- case TypeTableEntryIdComptimeFloat:
+ case ZigTypeIdComptimeFloat:
return 9;
- case TypeTableEntryIdComptimeInt:
+ case ZigTypeIdComptimeInt:
return 10;
- case TypeTableEntryIdUndefined:
+ case ZigTypeIdUndefined:
return 11;
- case TypeTableEntryIdNull:
+ case ZigTypeIdNull:
return 12;
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
return 13;
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
return 14;
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdErrorSet:
return 15;
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
return 16;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
return 17;
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
return 18;
- case TypeTableEntryIdNamespace:
+ case ZigTypeIdNamespace:
return 19;
- case TypeTableEntryIdBlock:
+ case ZigTypeIdBlock:
return 20;
- case TypeTableEntryIdBoundFn:
+ case ZigTypeIdBoundFn:
return 21;
- case TypeTableEntryIdArgTuple:
+ case ZigTypeIdArgTuple:
return 22;
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdOpaque:
return 23;
- case TypeTableEntryIdPromise:
+ case ZigTypeIdPromise:
return 24;
}
zig_unreachable();
}
-const char *type_id_name(TypeTableEntryId id) {
+const char *type_id_name(ZigTypeId id) {
switch (id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdMetaType:
+ case ZigTypeIdMetaType:
return "Type";
- case TypeTableEntryIdVoid:
+ case ZigTypeIdVoid:
return "Void";
- case TypeTableEntryIdBool:
+ case ZigTypeIdBool:
return "Bool";
- case TypeTableEntryIdUnreachable:
+ case ZigTypeIdUnreachable:
return "NoReturn";
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
return "Int";
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
return "Float";
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
return "Pointer";
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
return "Array";
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
return "Struct";
- case TypeTableEntryIdComptimeFloat:
+ case ZigTypeIdComptimeFloat:
return "ComptimeFloat";
- case TypeTableEntryIdComptimeInt:
+ case ZigTypeIdComptimeInt:
return "ComptimeInt";
- case TypeTableEntryIdUndefined:
+ case ZigTypeIdUndefined:
return "Undefined";
- case TypeTableEntryIdNull:
+ case ZigTypeIdNull:
return "Null";
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
return "Optional";
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
return "ErrorUnion";
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdErrorSet:
return "ErrorSet";
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
return "Enum";
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
return "Union";
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
return "Fn";
- case TypeTableEntryIdNamespace:
+ case ZigTypeIdNamespace:
return "Namespace";
- case TypeTableEntryIdBlock:
+ case ZigTypeIdBlock:
return "Block";
- case TypeTableEntryIdBoundFn:
+ case ZigTypeIdBoundFn:
return "BoundFn";
- case TypeTableEntryIdArgTuple:
+ case ZigTypeIdArgTuple:
return "ArgTuple";
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdOpaque:
return "Opaque";
- case TypeTableEntryIdPromise:
+ case ZigTypeIdPromise:
return "Promise";
}
zig_unreachable();
@@ -6258,31 +6291,31 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) {
return link_lib;
}
-uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry) {
+uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry) {
assertNoError(type_ensure_zero_bits_known(g, type_entry));
if (type_entry->zero_bits) return 0;
// We need to make this function work without requiring ensure_complete_type
// so that we can have structs with fields that are pointers to their own type.
- if (type_entry->id == TypeTableEntryIdStruct) {
+ if (type_entry->id == ZigTypeIdStruct) {
assert(type_entry->data.structure.abi_alignment != 0);
return type_entry->data.structure.abi_alignment;
- } else if (type_entry->id == TypeTableEntryIdUnion) {
+ } else if (type_entry->id == ZigTypeIdUnion) {
assert(type_entry->data.unionation.abi_alignment != 0);
return type_entry->data.unionation.abi_alignment;
- } else if (type_entry->id == TypeTableEntryIdOpaque) {
+ } else if (type_entry->id == ZigTypeIdOpaque) {
return 1;
} else {
uint32_t llvm_alignment = LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref);
// promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw
- if (type_entry->id == TypeTableEntryIdPromise && llvm_alignment < 8) {
+ if (type_entry->id == ZigTypeIdPromise && llvm_alignment < 8) {
return 8;
}
return llvm_alignment;
}
}
-TypeTableEntry *get_align_amt_type(CodeGen *g) {
+ZigType *get_align_amt_type(CodeGen *g) {
if (g->align_amt_type == nullptr) {
// according to LLVM the maximum alignment is 1 << 29.
g->align_amt_type = get_int_type(g, false, 29);
@@ -6290,11 +6323,11 @@ TypeTableEntry *get_align_amt_type(CodeGen *g) {
return g->align_amt_type;
}
-uint32_t type_ptr_hash(const TypeTableEntry *ptr) {
+uint32_t type_ptr_hash(const ZigType *ptr) {
return hash_ptr((void*)ptr);
}
-bool type_ptr_eql(const TypeTableEntry *a, const TypeTableEntry *b) {
+bool type_ptr_eql(const ZigType *a, const ZigType *b) {
return a == b;
}
@@ -6308,8 +6341,8 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) {
return var_value;
}
-bool type_is_global_error_set(TypeTableEntry *err_set_type) {
- assert(err_set_type->id == TypeTableEntryIdErrorSet);
+bool type_is_global_error_set(ZigType *err_set_type) {
+ assert(err_set_type->id == ZigTypeIdErrorSet);
assert(err_set_type->data.error_set.infer_fn == nullptr);
return err_set_type->data.error_set.err_count == UINT32_MAX;
}
@@ -6318,15 +6351,15 @@ uint32_t get_coro_frame_align_bytes(CodeGen *g) {
return g->pointer_size_bytes * 2;
}
-bool type_can_fail(TypeTableEntry *type_entry) {
- return type_entry->id == TypeTableEntryIdErrorUnion || type_entry->id == TypeTableEntryIdErrorSet;
+bool type_can_fail(ZigType *type_entry) {
+ return type_entry->id == ZigTypeIdErrorUnion || type_entry->id == ZigTypeIdErrorSet;
}
bool fn_type_can_fail(FnTypeId *fn_type_id) {
return type_can_fail(fn_type_id->return_type) || fn_type_id->cc == CallingConventionAsync;
}
-TypeTableEntry *get_primitive_type(CodeGen *g, Buf *name) {
+ZigType *get_primitive_type(CodeGen *g, Buf *name) {
if (buf_len(name) >= 2) {
uint8_t first_c = buf_ptr(name)[0];
if (first_c == 'i' || first_c == 'u') {
@@ -6350,3 +6383,85 @@ not_integer:
}
return nullptr;
}
+
+X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) {
+ size_t ty_size = type_size(g, ty);
+ if (get_codegen_ptr_type(ty) != nullptr)
+ return X64CABIClass_INTEGER;
+ switch (ty->id) {
+ case ZigTypeIdEnum:
+ case ZigTypeIdInt:
+ case ZigTypeIdBool:
+ return X64CABIClass_INTEGER;
+ case ZigTypeIdFloat:
+ return X64CABIClass_SSE;
+ case ZigTypeIdStruct: {
+ // "If the size of an object is larger than four eightbytes, or it contains unaligned
+ // fields, it has class MEMORY"
+ if (ty_size > 32)
+ return X64CABIClass_MEMORY;
+ if (ty->data.structure.layout != ContainerLayoutExtern) {
+ // TODO determine whether packed structs have any unaligned fields
+ return X64CABIClass_Unknown;
+ }
+ // "If the size of the aggregate exceeds two eightbytes and the first eight-
+ // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument
+ // is passed in memory."
+ if (ty_size > 16) {
+ // Zig doesn't support vectors and large fp registers yet, so this will always
+ // be memory.
+ return X64CABIClass_MEMORY;
+ }
+ X64CABIClass working_class = X64CABIClass_Unknown;
+ for (uint32_t i = 0; i < ty->data.structure.src_field_count; i += 1) {
+ X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.structure.fields->type_entry);
+ if (field_class == X64CABIClass_Unknown)
+ return X64CABIClass_Unknown;
+ if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) {
+ working_class = field_class;
+ }
+ }
+ return working_class;
+ }
+ case ZigTypeIdUnion: {
+ // "If the size of an object is larger than four eightbytes, or it contains unaligned
+ // fields, it has class MEMORY"
+ if (ty_size > 32)
+ return X64CABIClass_MEMORY;
+ if (ty->data.unionation.layout != ContainerLayoutExtern)
+ return X64CABIClass_MEMORY;
+ // "If the size of the aggregate exceeds two eightbytes and the first eight-
+ // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument
+ // is passed in memory."
+ if (ty_size > 16) {
+ // Zig doesn't support vectors and large fp registers yet, so this will always
+ // be memory.
+ return X64CABIClass_MEMORY;
+ }
+ X64CABIClass working_class = X64CABIClass_Unknown;
+ for (uint32_t i = 0; i < ty->data.unionation.src_field_count; i += 1) {
+ X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.unionation.fields->type_entry);
+ if (field_class == X64CABIClass_Unknown)
+ return X64CABIClass_Unknown;
+ if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) {
+ working_class = field_class;
+ }
+ }
+ return working_class;
+ }
+ default:
+ return X64CABIClass_Unknown;
+ }
+}
+
+// NOTE this does not depend on x86_64
+bool type_is_c_abi_int(CodeGen *g, ZigType *ty) {
+ return (ty->id == ZigTypeIdInt ||
+ ty->id == ZigTypeIdFloat ||
+ ty->id == ZigTypeIdBool ||
+ ty->id == ZigTypeIdEnum ||
+ ty->id == ZigTypeIdVoid ||
+ ty->id == ZigTypeIdUnreachable ||
+ get_codegen_ptr_type(ty) != nullptr);
+}
+
diff --git a/src/analyze.hpp b/src/analyze.hpp
@@ -14,103 +14,104 @@
void semantic_analyze(CodeGen *g);
ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg);
ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg);
-TypeTableEntry *new_type_table_entry(TypeTableEntryId id);
-TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const);
-TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,
+ZigType *new_type_table_entry(ZigTypeId id);
+ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const);
+ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const,
bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count);
-uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry);
-uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry);
-TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
-TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
-TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);
-TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
-TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type);
-TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size);
-TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type);
-TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind,
+uint64_t type_size(CodeGen *g, ZigType *type_entry);
+uint64_t type_size_bits(CodeGen *g, ZigType *type_entry);
+ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
+ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
+ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type);
+ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
+ZigType *get_optional_type(CodeGen *g, ZigType *child_type);
+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);
-TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
-TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *payload_type);
-TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry);
-TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name);
-TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
- TypeTableEntry *field_types[], size_t field_count);
-TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type);
-TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type);
-TypeTableEntry *get_test_fn_type(CodeGen *g);
-bool handle_is_ptr(TypeTableEntry *type_entry);
+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);
+ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name);
+ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
+ ZigType *field_types[], size_t field_count);
+ZigType *get_promise_type(CodeGen *g, ZigType *result_type);
+ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type);
+ZigType *get_test_fn_type(CodeGen *g);
+bool handle_is_ptr(ZigType *type_entry);
void find_libc_include_path(CodeGen *g);
void find_libc_lib_path(CodeGen *g);
-bool type_has_bits(TypeTableEntry *type_entry);
+bool type_has_bits(ZigType *type_entry);
ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code);
-VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name);
+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);
-bool type_is_codegen_pointer(TypeTableEntry *type);
-
-TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type);
-uint32_t get_ptr_align(TypeTableEntry *type);
-bool get_ptr_const(TypeTableEntry *type);
-TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry);
-TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);
-bool type_is_complete(TypeTableEntry *type_entry);
-bool type_is_invalid(TypeTableEntry *type_entry);
-bool type_is_global_error_set(TypeTableEntry *err_set_type);
-bool type_has_zero_bits_known(TypeTableEntry *type_entry);
-void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);
-ScopeDecls *get_container_scope(TypeTableEntry *type_entry);
-TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name);
-TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name);
-TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name);
-TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *tag);
-TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt *tag);
-
-bool is_ref(TypeTableEntry *type_entry);
-bool is_array_ref(TypeTableEntry *type_entry);
-bool is_container_ref(TypeTableEntry *type_entry);
+bool type_is_codegen_pointer(ZigType *type);
+
+ZigType *get_codegen_ptr_type(ZigType *type);
+uint32_t get_ptr_align(ZigType *type);
+bool get_ptr_const(ZigType *type);
+ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry);
+ZigType *container_ref_type(ZigType *type_entry);
+bool type_is_complete(ZigType *type_entry);
+bool type_is_invalid(ZigType *type_entry);
+bool type_is_global_error_set(ZigType *err_set_type);
+bool type_has_zero_bits_known(ZigType *type_entry);
+void resolve_container_type(CodeGen *g, ZigType *type_entry);
+ScopeDecls *get_container_scope(ZigType *type_entry);
+TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name);
+TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name);
+TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name);
+TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag);
+TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag);
+
+bool is_ref(ZigType *type_entry);
+bool is_array_ref(ZigType *type_entry);
+bool is_container_ref(ZigType *type_entry);
void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node);
void scan_import(CodeGen *g, ImportTableEntry *import);
void preview_use_decl(CodeGen *g, AstNode *node);
void resolve_use_decl(CodeGen *g, AstNode *node);
-FnTableEntry *scope_fn_entry(Scope *scope);
+ZigFn *scope_fn_entry(Scope *scope);
ImportTableEntry *get_scope_import(Scope *scope);
void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope);
-VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
+ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name,
bool is_const, ConstExprValue *init_value, Tld *src_tld);
-TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
-FnTableEntry *create_fn(AstNode *proto_node);
-FnTableEntry *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage);
+ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
+ZigFn *create_fn(AstNode *proto_node);
+ZigFn *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage);
void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc);
-AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index);
-FnTableEntry *scope_get_fn_if_root(Scope *scope);
-bool type_requires_comptime(TypeTableEntry *type_entry);
-Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, TypeTableEntry *type_entry);
-Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, TypeTableEntry *type_entry);
-void complete_enum(CodeGen *g, TypeTableEntry *enum_type);
-bool ir_get_var_is_comptime(VariableTableEntry *var);
+AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);
+ZigFn *scope_get_fn_if_root(Scope *scope);
+bool type_requires_comptime(ZigType *type_entry);
+Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry);
+Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry);
+void complete_enum(CodeGen *g, ZigType *enum_type);
+bool ir_get_var_is_comptime(ZigVar *var);
bool const_values_equal(ConstExprValue *a, ConstExprValue *b);
-void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max);
-void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint, bool is_max);
+void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max);
+void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max);
void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val);
-void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_type_node);
+void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node);
ScopeBlock *create_block_scope(AstNode *node, Scope *parent);
ScopeDefer *create_defer_scope(AstNode *node, Scope *parent);
ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent);
-Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var);
+Scope *create_var_scope(AstNode *node, Scope *parent, ZigVar *var);
ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent);
ScopeLoop *create_loop_scope(AstNode *node, Scope *parent);
ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent);
-ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry);
-ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, TypeTableEntry *container_type, ImportTableEntry *import);
+ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, ZigFn *fn_entry);
+ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import);
Scope *create_comptime_scope(AstNode *node, Scope *parent);
Scope *create_coro_prelude_scope(AstNode *node, Scope *parent);
+Scope *create_runtime_scope(AstNode *node, Scope *parent, IrInstruction *is_comptime);
void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);
ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
@@ -118,39 +119,39 @@ ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *c_str);
ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *c_str);
-void init_const_bigint(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *bigint);
-ConstExprValue *create_const_bigint(TypeTableEntry *type, const BigInt *bigint);
+void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint);
+ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint);
-void init_const_unsigned_negative(ConstExprValue *const_val, TypeTableEntry *type, uint64_t x, bool negative);
-ConstExprValue *create_const_unsigned_negative(TypeTableEntry *type, uint64_t x, bool negative);
+void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative);
+ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative);
-void init_const_signed(ConstExprValue *const_val, TypeTableEntry *type, int64_t x);
-ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x);
+void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x);
+ConstExprValue *create_const_signed(ZigType *type, int64_t x);
void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x);
ConstExprValue *create_const_usize(CodeGen *g, uint64_t x);
-void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value);
-ConstExprValue *create_const_float(TypeTableEntry *type, double value);
+void init_const_float(ConstExprValue *const_val, ZigType *type, double value);
+ConstExprValue *create_const_float(ZigType *type, double value);
-void init_const_enum(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *tag);
-ConstExprValue *create_const_enum(TypeTableEntry *type, const BigInt *tag);
+void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag);
+ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag);
void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value);
ConstExprValue *create_const_bool(CodeGen *g, bool value);
-void init_const_type(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *type_value);
-ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value);
+void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value);
+ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value);
-void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type);
-ConstExprValue *create_const_runtime(TypeTableEntry *type);
+void init_const_runtime(ConstExprValue *const_val, ZigType *type);
+ConstExprValue *create_const_runtime(ZigType *type);
void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const);
ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const);
-void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *pointee_type,
+void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type,
size_t addr, bool is_const);
-ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, TypeTableEntry *pointee_type,
+ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
size_t addr, bool is_const);
void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val,
@@ -169,41 +170,48 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val);
ConstExprValue *create_const_vals(size_t count);
-TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
+ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value);
void expand_undef_array(CodeGen *g, ConstExprValue *const_val);
void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value);
-const char *type_id_name(TypeTableEntryId id);
-TypeTableEntryId type_id_at_index(size_t index);
+const char *type_id_name(ZigTypeId id);
+ZigTypeId type_id_at_index(size_t index);
size_t type_id_len();
-size_t type_id_index(TypeTableEntry *entry);
-TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id);
-Result<bool> type_is_copyable(CodeGen *g, TypeTableEntry *type_entry);
+size_t type_id_index(ZigType *entry);
+ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id);
+Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry);
LinkLib *create_link_lib(Buf *name);
-bool calling_convention_does_first_arg_return(CallingConvention cc);
LinkLib *add_link_lib(CodeGen *codegen, Buf *lib);
-uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry);
-TypeTableEntry *get_align_amt_type(CodeGen *g);
+uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
+ZigType *get_align_amt_type(CodeGen *g);
PackageTableEntry *new_anonymous_package(void);
Buf *const_value_to_buffer(ConstExprValue *const_val);
-void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);
+void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);
ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);
-TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g);
-bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node);
+ZigType *get_ptr_to_stack_trace_type(CodeGen *g);
+bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node);
-TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry);
+ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry);
uint32_t get_coro_frame_align_bytes(CodeGen *g);
bool fn_type_can_fail(FnTypeId *fn_type_id);
-bool type_can_fail(TypeTableEntry *type_entry);
-bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type);
-AstNode *type_decl_node(TypeTableEntry *type_entry);
+bool type_can_fail(ZigType *type_entry);
+bool fn_eval_cacheable(Scope *scope, ZigType *return_type);
+AstNode *type_decl_node(ZigType *type_entry);
-TypeTableEntry *get_primitive_type(CodeGen *g, Buf *name);
+ZigType *get_primitive_type(CodeGen *g, Buf *name);
+
+bool calling_convention_allows_zig_types(CallingConvention cc);
+const char *calling_convention_name(CallingConvention cc);
+
+void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk);
+X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty);
+bool type_is_c_abi_int(CodeGen *g, ZigType *ty);
+bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id);
#endif
diff --git a/src/buffer.hpp b/src/buffer.hpp
@@ -173,4 +173,9 @@ static inline void buf_upcase(Buf *buf) {
}
}
+static inline Slice<uint8_t> buf_to_slice(Buf *buf) {
+ return Slice<uint8_t>{reinterpret_cast<uint8_t*>(buf_ptr(buf)), buf_len(buf)};
+}
+
+
#endif
diff --git a/src/codegen.cpp b/src/codegen.cpp
@@ -243,7 +243,7 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) {
g->root_out_name = out_name;
}
-void codegen_set_cache_dir(CodeGen *g, Buf *cache_dir) {
+void codegen_set_cache_dir(CodeGen *g, Buf cache_dir) {
g->cache_dir = cache_dir;
}
@@ -358,6 +358,10 @@ static void addLLVMArgAttr(LLVMValueRef fn_val, unsigned param_index, const char
return addLLVMAttr(fn_val, param_index + 1, attr_name);
}
+static void addLLVMArgAttrInt(LLVMValueRef fn_val, unsigned param_index, const char *attr_name, uint64_t attr_val) {
+ return addLLVMAttrInt(fn_val, param_index + 1, attr_name, attr_val);
+}
+
static bool is_symbol_available(CodeGen *g, Buf *name) {
return g->exported_symbol_names.maybe_get(name) == nullptr && g->external_prototypes.maybe_get(name) == nullptr;
}
@@ -430,23 +434,23 @@ static LLVMLinkage to_llvm_linkage(GlobalLinkageId id) {
zig_unreachable();
}
-static uint32_t get_err_ret_trace_arg_index(CodeGen *g, FnTableEntry *fn_table_entry) {
+static uint32_t get_err_ret_trace_arg_index(CodeGen *g, ZigFn *fn_table_entry) {
if (!g->have_err_ret_tracing) {
return UINT32_MAX;
}
if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync) {
return 0;
}
- TypeTableEntry *fn_type = fn_table_entry->type_entry;
+ ZigType *fn_type = fn_table_entry->type_entry;
if (!fn_type_can_fail(&fn_type->data.fn.fn_type_id)) {
return UINT32_MAX;
}
- TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type;
+ ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
bool first_arg_ret = type_has_bits(return_type) && handle_is_ptr(return_type);
return first_arg_ret ? 1 : 0;
}
-static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
+static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) {
if (fn_table_entry->llvm_value)
return fn_table_entry->llvm_value;
@@ -466,7 +470,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
}
bool external_linkage = linkage != GlobalLinkageIdInternal;
- if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionStdcall && external_linkage &&
+ CallingConvention cc = fn_table_entry->type_entry->data.fn.fn_type_id.cc;
+ if (cc == CallingConventionStdcall && external_linkage &&
g->zig_target.arch.arch == ZigLLVM_x86)
{
// prevent llvm name mangling
@@ -474,7 +479,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
}
- TypeTableEntry *fn_type = fn_table_entry->type_entry;
+ ZigType *fn_type = fn_table_entry->type_entry;
LLVMTypeRef fn_llvm_type = fn_type->data.fn.raw_type_ref;
if (fn_table_entry->body_node == nullptr) {
LLVMValueRef existing_llvm_fn = LLVMGetNamedFunction(g->module, buf_ptr(symbol_name));
@@ -510,17 +515,17 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
break;
}
- if (fn_type->data.fn.fn_type_id.cc == CallingConventionNaked) {
+ if (cc == CallingConventionNaked) {
addLLVMFnAttr(fn_table_entry->llvm_value, "naked");
} else {
LLVMSetFunctionCallConv(fn_table_entry->llvm_value, get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc));
}
- if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {
+ if (cc == CallingConventionAsync) {
addLLVMFnAttr(fn_table_entry->llvm_value, "optnone");
addLLVMFnAttr(fn_table_entry->llvm_value, "noinline");
}
- bool want_cold = fn_table_entry->is_cold || fn_type->data.fn.fn_type_id.cc == CallingConventionCold;
+ bool want_cold = fn_table_entry->is_cold || cc == CallingConventionCold;
if (want_cold) {
ZigLLVMAddFunctionAttrCold(fn_table_entry->llvm_value);
}
@@ -532,8 +537,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
LLVMSetUnnamedAddr(fn_table_entry->llvm_value, true);
}
- TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type;
- if (return_type->id == TypeTableEntryIdUnreachable) {
+ ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
+ if (return_type->id == ZigTypeIdUnreachable) {
addLLVMFnAttr(fn_table_entry->llvm_value, "noreturn");
}
@@ -572,41 +577,26 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
// use the ABI alignment, which is fine.
}
+ unsigned init_gen_i = 0;
if (!type_has_bits(return_type)) {
// nothing to do
} else if (type_is_codegen_pointer(return_type)) {
addLLVMAttr(fn_table_entry->llvm_value, 0, "nonnull");
- } else if (handle_is_ptr(return_type) &&
- calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc))
- {
+ } else if (want_first_arg_sret(g, &fn_type->data.fn.fn_type_id)) {
addLLVMArgAttr(fn_table_entry->llvm_value, 0, "sret");
addLLVMArgAttr(fn_table_entry->llvm_value, 0, "nonnull");
+ if (cc == CallingConventionC) {
+ addLLVMArgAttr(fn_table_entry->llvm_value, 0, "noalias");
+ }
+ init_gen_i = 1;
}
-
// set parameter attributes
- for (size_t param_i = 0; param_i < fn_type->data.fn.fn_type_id.param_count; param_i += 1) {
- FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i];
- size_t gen_index = gen_info->gen_index;
- bool is_byval = gen_info->is_byval;
-
- if (gen_index == SIZE_MAX) {
- continue;
- }
-
- FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[param_i];
-
- TypeTableEntry *param_type = gen_info->type;
- if (param_info->is_noalias) {
- addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "noalias");
- }
- if ((param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) || is_byval) {
- addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "readonly");
- }
- if (param_type->id == TypeTableEntryIdPointer) {
- addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "nonnull");
- }
- }
+ FnWalk fn_walk = {};
+ fn_walk.id = FnWalkIdAttrs;
+ fn_walk.data.attrs.fn = fn_table_entry;
+ fn_walk.data.attrs.gen_i = init_gen_i;
+ walk_function_params(g, fn_type, &fn_walk);
uint32_t err_ret_trace_arg_index = get_err_ret_trace_arg_index(g, fn_table_entry);
if (err_ret_trace_arg_index != UINT32_MAX) {
@@ -628,7 +618,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
{
assert(scope->parent);
ScopeFnDef *fn_scope = (ScopeFnDef *)scope;
- FnTableEntry *fn_table_entry = fn_scope->fn_entry;
+ ZigFn *fn_table_entry = fn_scope->fn_entry;
if (!fn_table_entry->proto_node)
return get_di_scope(g, scope->parent);
unsigned line_number = (unsigned)(fn_table_entry->proto_node->line == 0) ?
@@ -678,6 +668,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
case ScopeIdSuspend:
case ScopeIdCompTime:
case ScopeIdCoroPrelude:
+ case ScopeIdRuntime:
return get_di_scope(g, scope->parent);
}
zig_unreachable();
@@ -687,12 +678,12 @@ static void clear_debug_source_node(CodeGen *g) {
ZigLLVMClearCurrentDebugLocation(g->builder);
}
-static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
+static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry,
const char *signed_name, const char *unsigned_name)
{
char fn_name[64];
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name;
sprintf(fn_name, "llvm.%s.with.overflow.i%" PRIu32, signed_str, type_entry->data.integral.bit_count);
@@ -711,8 +702,8 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_
return fn_val;
}
-static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry, AddSubMul add_sub_mul) {
- assert(type_entry->id == TypeTableEntryIdInt);
+static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubMul add_sub_mul) {
+ assert(type_entry->id == ZigTypeIdInt);
ZigLLVMFnKey key = {};
key.id = ZigLLVMFnIdOverflowArithmetic;
@@ -741,8 +732,8 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
return fn_val;
}
-static LLVMValueRef get_float_fn(CodeGen *g, TypeTableEntry *type_entry, ZigLLVMFnId fn_id) {
- assert(type_entry->id == TypeTableEntryIdFloat);
+static LLVMValueRef get_float_fn(CodeGen *g, ZigType *type_entry, ZigLLVMFnId fn_id) {
+ assert(type_entry->id == ZigTypeIdFloat);
ZigLLVMFnKey key = {};
key.id = fn_id;
@@ -786,8 +777,8 @@ static LLVMValueRef gen_store_untyped(CodeGen *g, LLVMValueRef value, LLVMValueR
return instruction;
}
-static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, TypeTableEntry *ptr_type) {
- assert(ptr_type->id == TypeTableEntryIdPointer);
+static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, ZigType *ptr_type) {
+ assert(ptr_type->id == ZigTypeIdPointer);
return gen_store_untyped(g, value, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile);
}
@@ -804,17 +795,17 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alig
return result;
}
-static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *ptr_type, const char *name) {
- assert(ptr_type->id == TypeTableEntryIdPointer);
+static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, const char *name) {
+ assert(ptr_type->id == ZigTypeIdPointer);
return gen_load_untyped(g, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile, name);
}
-static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *type, TypeTableEntry *ptr_type) {
+static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type, ZigType *ptr_type) {
if (type_has_bits(type)) {
if (handle_is_ptr(type)) {
return ptr;
} else {
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ assert(ptr_type->id == ZigTypeIdPointer);
return gen_load(g, ptr, ptr_type, "");
}
} else {
@@ -917,9 +908,9 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
assert(val->global_refs->llvm_global);
}
- TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
+ ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
+ ZigType *str_type = get_slice_type(g, u8_ptr_type);
return LLVMConstBitCast(val->global_refs->llvm_global, LLVMPointerType(str_type->type_ref, 0));
}
@@ -928,7 +919,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace
LLVMValueRef fn_val = fn_llvm_value(g, g->panic_fn);
LLVMCallConv llvm_cc = get_llvm_cc(g, g->panic_fn->type_entry->data.fn.fn_type_id.cc);
if (stack_trace_arg == nullptr) {
- TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
+ ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
stack_trace_arg = LLVMConstNull(ptr_to_stack_trace_type->type_ref);
}
LLVMValueRef args[] = {
@@ -1166,7 +1157,7 @@ static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
if (g->return_address_fn_val)
return g->return_address_fn_val;
- TypeTableEntry *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
+ ZigType *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
LLVMTypeRef fn_type = LLVMFunctionType(return_type->type_ref,
&g->builtin_types.entry_i32->type_ref, 1, false);
@@ -1217,7 +1208,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;
LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, err_ret_trace_ptr, (unsigned)addresses_field_index, "");
- TypeTableEntry *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
+ ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, "");
size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;
@@ -1317,7 +1308,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
(unsigned)src_index_field_index, "");
LLVMValueRef src_addresses_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr,
(unsigned)src_addresses_field_index, "");
- TypeTableEntry *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
+ ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
LLVMValueRef src_ptr_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)ptr_field_index, "");
size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;
@@ -1459,7 +1450,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
LLVMSetUnnamedAddr(global_array, true);
LLVMSetAlignment(global_array, u8_align_bytes);
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
LLVMValueRef full_buf_ptr_indices[] = {
LLVMConstNull(usize->type_ref),
LLVMConstNull(usize->type_ref),
@@ -1467,9 +1458,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
LLVMValueRef full_buf_ptr = LLVMConstInBoundsGEP(global_array, full_buf_ptr_indices, 2);
- TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
+ ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
+ ZigType *str_type = get_slice_type(g, u8_ptr_type);
LLVMValueRef global_slice_fields[] = {
full_buf_ptr,
LLVMConstNull(usize->type_ref),
@@ -1575,7 +1566,7 @@ static void gen_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val, Scope *sc
LLVMValueRef safety_crash_err_fn = get_safety_crash_err_fn(g);
LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, scope);
if (err_ret_trace_val == nullptr) {
- TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
+ ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
err_ret_trace_val = LLVMConstNull(ptr_to_stack_trace_type->type_ref);
}
LLVMValueRef args[] = {
@@ -1621,24 +1612,24 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,
LLVMPositionBuilderAtEnd(g->builder, ok_block);
}
-static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, TypeTableEntry *actual_type,
- TypeTableEntry *wanted_type, LLVMValueRef expr_val)
+static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, ZigType *actual_type,
+ ZigType *wanted_type, LLVMValueRef expr_val)
{
assert(actual_type->id == wanted_type->id);
uint64_t actual_bits;
uint64_t wanted_bits;
- if (actual_type->id == TypeTableEntryIdFloat) {
+ if (actual_type->id == ZigTypeIdFloat) {
actual_bits = actual_type->data.floating.bit_count;
wanted_bits = wanted_type->data.floating.bit_count;
- } else if (actual_type->id == TypeTableEntryIdInt) {
+ } else if (actual_type->id == ZigTypeIdInt) {
actual_bits = actual_type->data.integral.bit_count;
wanted_bits = wanted_type->data.integral.bit_count;
} else {
zig_unreachable();
}
- if (actual_bits >= wanted_bits && actual_type->id == TypeTableEntryIdInt &&
+ if (actual_bits >= wanted_bits && actual_type->id == ZigTypeIdInt &&
!wanted_type->data.integral.is_signed && actual_type->data.integral.is_signed &&
want_runtime_safety)
{
@@ -1658,9 +1649,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T
if (actual_bits == wanted_bits) {
return expr_val;
} else if (actual_bits < wanted_bits) {
- if (actual_type->id == TypeTableEntryIdFloat) {
+ if (actual_type->id == ZigTypeIdFloat) {
return LLVMBuildFPExt(g->builder, expr_val, wanted_type->type_ref, "");
- } else if (actual_type->id == TypeTableEntryIdInt) {
+ } else if (actual_type->id == ZigTypeIdInt) {
if (actual_type->data.integral.is_signed) {
return LLVMBuildSExt(g->builder, expr_val, wanted_type->type_ref, "");
} else {
@@ -1670,9 +1661,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T
zig_unreachable();
}
} else if (actual_bits > wanted_bits) {
- if (actual_type->id == TypeTableEntryIdFloat) {
+ if (actual_type->id == ZigTypeIdFloat) {
return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, "");
- } else if (actual_type->id == TypeTableEntryIdInt) {
+ } else if (actual_type->id == ZigTypeIdInt) {
LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");
if (!want_runtime_safety) {
return trunc_val;
@@ -1701,7 +1692,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T
}
}
-static LLVMValueRef gen_overflow_op(CodeGen *g, TypeTableEntry *type_entry, AddSubMul op,
+static LLVMValueRef gen_overflow_op(CodeGen *g, ZigType *type_entry, AddSubMul op,
LLVMValueRef val1, LLVMValueRef val2)
{
LLVMValueRef fn_val = get_int_overflow_fn(g, type_entry, op);
@@ -1761,11 +1752,11 @@ static LLVMRealPredicate cmp_op_to_real_predicate(IrBinOp cmp_op) {
}
}
-static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *ptr_type,
+static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type,
LLVMValueRef value)
{
- assert(ptr_type->id == TypeTableEntryIdPointer);
- TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
+ assert(ptr_type->id == ZigTypeIdPointer);
+ ZigType *child_type = ptr_type->data.pointer.child_type;
if (!type_has_bits(child_type))
return nullptr;
@@ -1779,7 +1770,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry
LLVMValueRef src_ptr = LLVMBuildBitCast(g->builder, value, ptr_u8, "");
LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, ptr, ptr_u8, "");
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, child_type->type_ref);
uint64_t align_bytes = ptr_type->data.pointer.alignment;
assert(size_bytes > 0);
@@ -1819,7 +1810,8 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry
return nullptr;
}
-static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) {
+static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
+ assert(var->di_loc_var != nullptr);
AstNode *source_node = var->decl_node;
ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1,
(unsigned)source_node->column + 1, get_di_scope(g, var->parent_scope));
@@ -1838,9 +1830,9 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
// values are rendered with a type other than the one we expect
if (handle_is_ptr(instruction->value.type)) {
render_const_val_global(g, &instruction->value, "");
- TypeTableEntry *ptr_type = get_pointer_to_type(g, instruction->value.type, true);
+ ZigType *ptr_type = get_pointer_to_type(g, instruction->value.type, true);
instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_global, ptr_type->type_ref, "");
- } else if (instruction->value.type->id == TypeTableEntryIdPointer) {
+ } else if (instruction->value.type->id == ZigTypeIdPointer) {
instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value, instruction->value.type->type_ref, "");
} else {
instruction->llvm_value = instruction->value.global_refs->llvm_value;
@@ -1850,6 +1842,353 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
return instruction->llvm_value;
}
+ATTRIBUTE_NORETURN
+static void report_errors_and_exit(CodeGen *g) {
+ assert(g->errors.length != 0);
+ for (size_t i = 0; i < g->errors.length; i += 1) {
+ ErrorMsg *err = g->errors.at(i);
+ print_err_msg(err, g->err_color);
+ }
+ exit(1);
+}
+
+static void report_errors_and_maybe_exit(CodeGen *g) {
+ if (g->errors.length != 0) {
+ report_errors_and_exit(g);
+ }
+}
+
+ATTRIBUTE_NORETURN
+static void give_up_with_c_abi_error(CodeGen *g, AstNode *source_node) {
+ ErrorMsg *msg = add_node_error(g, source_node,
+ buf_sprintf("TODO: support C ABI for more targets. https://github.com/ziglang/zig/issues/1481"));
+ add_error_note(g, msg, source_node,
+ buf_sprintf("pointers, integers, floats, bools, and enums work on all targets"));
+ report_errors_and_exit(g);
+}
+
+static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) {
+ assert(alignment > 0);
+ LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name);
+ LLVMSetAlignment(result, alignment);
+ return result;
+}
+
+static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk, size_t src_i) {
+ // Initialized from the type for some walks, but because of C var args,
+ // initialized based on callsite instructions for that one.
+ FnTypeParamInfo *param_info = nullptr;
+ ZigType *ty;
+ ZigType *dest_ty = nullptr;
+ AstNode *source_node = nullptr;
+ LLVMValueRef val;
+ LLVMValueRef llvm_fn;
+ unsigned di_arg_index;
+ ZigVar *var;
+ switch (fn_walk->id) {
+ case FnWalkIdAttrs:
+ if (src_i >= fn_type->data.fn.fn_type_id.param_count)
+ return false;
+ param_info = &fn_type->data.fn.fn_type_id.param_info[src_i];
+ ty = param_info->type;
+ source_node = fn_walk->data.attrs.fn->proto_node;
+ llvm_fn = fn_walk->data.attrs.fn->llvm_value;
+ break;
+ case FnWalkIdCall: {
+ if (src_i >= fn_walk->data.call.inst->arg_count)
+ return false;
+ IrInstruction *arg = fn_walk->data.call.inst->args[src_i];
+ ty = arg->value.type;
+ source_node = arg->source_node;
+ val = ir_llvm_value(g, arg);
+ break;
+ }
+ case FnWalkIdTypes:
+ if (src_i >= fn_type->data.fn.fn_type_id.param_count)
+ return false;
+ param_info = &fn_type->data.fn.fn_type_id.param_info[src_i];
+ ty = param_info->type;
+ break;
+ case FnWalkIdVars:
+ assert(src_i < fn_type->data.fn.fn_type_id.param_count);
+ param_info = &fn_type->data.fn.fn_type_id.param_info[src_i];
+ ty = param_info->type;
+ var = fn_walk->data.vars.var;
+ source_node = var->decl_node;
+ llvm_fn = fn_walk->data.vars.llvm_fn;
+ break;
+ case FnWalkIdInits:
+ if (src_i >= fn_type->data.fn.fn_type_id.param_count)
+ return false;
+ param_info = &fn_type->data.fn.fn_type_id.param_info[src_i];
+ ty = param_info->type;
+ var = fn_walk->data.inits.fn->variable_list.at(src_i);
+ source_node = fn_walk->data.inits.fn->proto_node;
+ llvm_fn = fn_walk->data.inits.llvm_fn;
+ break;
+ }
+
+ if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat ||
+ ty->id == ZigTypeIdInt // TODO investigate if we need to change this
+ ) {
+ switch (fn_walk->id) {
+ case FnWalkIdAttrs: {
+ ZigType *ptr_type = get_codegen_ptr_type(ty);
+ if (ptr_type != nullptr) {
+ if (ty->id != ZigTypeIdOptional) {
+ addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull");
+ }
+ if (ptr_type->data.pointer.is_const) {
+ addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "readonly");
+ }
+ if (param_info->is_noalias) {
+ addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "noalias");
+ }
+ }
+ fn_walk->data.attrs.gen_i += 1;
+ break;
+ }
+ case FnWalkIdCall:
+ fn_walk->data.call.gen_param_values->append(val);
+ break;
+ case FnWalkIdTypes:
+ fn_walk->data.types.gen_param_types->append(ty->type_ref);
+ fn_walk->data.types.param_di_types->append(ty->di_type);
+ break;
+ case FnWalkIdVars: {
+ var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes);
+ di_arg_index = fn_walk->data.vars.gen_i;
+ fn_walk->data.vars.gen_i += 1;
+ dest_ty = ty;
+ goto var_ok;
+ }
+ case FnWalkIdInits:
+ clear_debug_source_node(g);
+ gen_store_untyped(g, LLVMGetParam(llvm_fn, fn_walk->data.inits.gen_i), var->value_ref, var->align_bytes, false);
+ if (var->decl_node) {
+ gen_var_debug_decl(g, var);
+ }
+ fn_walk->data.inits.gen_i += 1;
+ break;
+ }
+ return true;
+ }
+
+ // Arrays are just pointers
+ if (ty->id == ZigTypeIdArray) {
+ assert(handle_is_ptr(ty));
+ switch (fn_walk->id) {
+ case FnWalkIdAttrs:
+ addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull");
+ addLLVMArgAttrInt(llvm_fn, fn_walk->data.attrs.gen_i, "align", get_abi_alignment(g, ty));
+ fn_walk->data.attrs.gen_i += 1;
+ break;
+ case FnWalkIdCall:
+ fn_walk->data.call.gen_param_values->append(val);
+ break;
+ case FnWalkIdTypes: {
+ ZigType *gen_type = get_pointer_to_type(g, ty, true);
+ fn_walk->data.types.gen_param_types->append(gen_type->type_ref);
+ fn_walk->data.types.param_di_types->append(gen_type->di_type);
+ break;
+ }
+ case FnWalkIdVars: {
+ var->value_ref = LLVMGetParam(llvm_fn, fn_walk->data.vars.gen_i);
+ di_arg_index = fn_walk->data.vars.gen_i;
+ dest_ty = get_pointer_to_type(g, ty, false);
+ fn_walk->data.vars.gen_i += 1;
+ goto var_ok;
+ }
+ case FnWalkIdInits:
+ if (var->decl_node) {
+ gen_var_debug_decl(g, var);
+ }
+ fn_walk->data.inits.gen_i += 1;
+ break;
+ }
+ return true;
+ }
+
+ if (g->zig_target.arch.arch == ZigLLVM_x86_64) {
+ X64CABIClass abi_class = type_c_abi_x86_64_class(g, ty);
+ size_t ty_size = type_size(g, ty);
+ if (abi_class == X64CABIClass_MEMORY) {
+ assert(handle_is_ptr(ty));
+ switch (fn_walk->id) {
+ case FnWalkIdAttrs:
+ addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "byval");
+ addLLVMArgAttrInt(llvm_fn, fn_walk->data.attrs.gen_i, "align", get_abi_alignment(g, ty));
+ addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull");
+ fn_walk->data.attrs.gen_i += 1;
+ break;
+ case FnWalkIdCall:
+ fn_walk->data.call.gen_param_values->append(val);
+ break;
+ case FnWalkIdTypes: {
+ ZigType *gen_type = get_pointer_to_type(g, ty, true);
+ fn_walk->data.types.gen_param_types->append(gen_type->type_ref);
+ fn_walk->data.types.param_di_types->append(gen_type->di_type);
+ break;
+ }
+ case FnWalkIdVars: {
+ di_arg_index = fn_walk->data.vars.gen_i;
+ var->value_ref = LLVMGetParam(llvm_fn, fn_walk->data.vars.gen_i);
+ dest_ty = get_pointer_to_type(g, ty, false);
+ fn_walk->data.vars.gen_i += 1;
+ goto var_ok;
+ }
+ case FnWalkIdInits:
+ if (var->decl_node) {
+ gen_var_debug_decl(g, var);
+ }
+ fn_walk->data.inits.gen_i += 1;
+ break;
+ }
+ return true;
+ } else if (abi_class == X64CABIClass_INTEGER) {
+ switch (fn_walk->id) {
+ case FnWalkIdAttrs:
+ fn_walk->data.attrs.gen_i += 1;
+ break;
+ case FnWalkIdCall: {
+ LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0);
+ LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, val, ptr_to_int_type_ref, "");
+ LLVMValueRef loaded = LLVMBuildLoad(g->builder, bitcasted, "");
+ fn_walk->data.call.gen_param_values->append(loaded);
+ break;
+ }
+ case FnWalkIdTypes: {
+ ZigType *gen_type = get_int_type(g, false, ty_size * 8);
+ fn_walk->data.types.gen_param_types->append(gen_type->type_ref);
+ fn_walk->data.types.param_di_types->append(gen_type->di_type);
+ break;
+ }
+ case FnWalkIdVars: {
+ di_arg_index = fn_walk->data.vars.gen_i;
+ var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes);
+ fn_walk->data.vars.gen_i += 1;
+ dest_ty = ty;
+ goto var_ok;
+ }
+ case FnWalkIdInits: {
+ clear_debug_source_node(g);
+ LLVMValueRef arg = LLVMGetParam(llvm_fn, fn_walk->data.inits.gen_i);
+ LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0);
+ LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, var->value_ref, ptr_to_int_type_ref, "");
+ gen_store_untyped(g, arg, bitcasted, var->align_bytes, false);
+ if (var->decl_node) {
+ gen_var_debug_decl(g, var);
+ }
+ fn_walk->data.inits.gen_i += 1;
+ break;
+ }
+ }
+ return true;
+ }
+ }
+ if (source_node != nullptr) {
+ give_up_with_c_abi_error(g, source_node);
+ }
+ // otherwise allow codegen code to report a compile error
+ return false;
+
+var_ok:
+ 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,
+ (unsigned)(var->decl_node->line + 1),
+ dest_ty->di_type, !g->strip_debug_symbols, 0, di_arg_index + 1);
+ }
+ return true;
+}
+
+void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
+ CallingConvention cc = fn_type->data.fn.fn_type_id.cc;
+ if (cc == CallingConventionC) {
+ size_t src_i = 0;
+ for (;;) {
+ if (!iter_function_params_c_abi(g, fn_type, fn_walk, src_i))
+ break;
+ src_i += 1;
+ }
+ return;
+ }
+ if (fn_walk->id == FnWalkIdCall) {
+ IrInstructionCall *instruction = fn_walk->data.call.inst;
+ bool is_var_args = fn_walk->data.call.is_var_args;
+ for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
+ IrInstruction *param_instruction = instruction->args[call_i];
+ ZigType *param_type = param_instruction->value.type;
+ if (is_var_args || type_has_bits(param_type)) {
+ LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
+ assert(param_value);
+ fn_walk->data.call.gen_param_values->append(param_value);
+ }
+ }
+ return;
+ }
+ size_t next_var_i = 0;
+ for (size_t param_i = 0; param_i < fn_type->data.fn.fn_type_id.param_count; param_i += 1) {
+ FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i];
+ size_t gen_index = gen_info->gen_index;
+
+ if (gen_index == SIZE_MAX) {
+ continue;
+ }
+
+ switch (fn_walk->id) {
+ case FnWalkIdAttrs: {
+ LLVMValueRef llvm_fn = fn_walk->data.attrs.fn->llvm_value;
+ bool is_byval = gen_info->is_byval;
+ FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[param_i];
+
+ ZigType *param_type = gen_info->type;
+ if (param_info->is_noalias) {
+ addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "noalias");
+ }
+ if ((param_type->id == ZigTypeIdPointer && param_type->data.pointer.is_const) || is_byval) {
+ addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "readonly");
+ }
+ if (param_type->id == ZigTypeIdPointer) {
+ addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "nonnull");
+ }
+ break;
+ }
+ case FnWalkIdInits: {
+ ZigFn *fn_table_entry = fn_walk->data.inits.fn;
+ LLVMValueRef llvm_fn = fn_table_entry->llvm_value;
+ ZigVar *variable = fn_table_entry->variable_list.at(next_var_i);
+ assert(variable->src_arg_index != SIZE_MAX);
+ next_var_i += 1;
+
+ assert(variable);
+ assert(variable->value_ref);
+
+ if (!handle_is_ptr(variable->value->type)) {
+ clear_debug_source_node(g);
+ gen_store_untyped(g, LLVMGetParam(llvm_fn, (unsigned)variable->gen_arg_index), variable->value_ref,
+ variable->align_bytes, false);
+ }
+
+ if (variable->decl_node) {
+ gen_var_debug_decl(g, variable);
+ }
+ break;
+ }
+ case FnWalkIdCall:
+ // handled before for loop
+ zig_unreachable();
+ case FnWalkIdTypes:
+ // Not called for non-c-abi
+ zig_unreachable();
+ case FnWalkIdVars:
+ // iter_function_params_c_abi is called directly for this one
+ zig_unreachable();
+ }
+ }
+}
+
static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *executable,
IrInstructionSaveErrRetAddr *save_err_ret_addr_instruction)
{
@@ -1866,24 +2205,22 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut
static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *return_instruction) {
LLVMValueRef value = ir_llvm_value(g, return_instruction->value);
- TypeTableEntry *return_type = return_instruction->value->value.type;
-
- if (handle_is_ptr(return_type)) {
- if (calling_convention_does_first_arg_return(g->cur_fn->type_entry->data.fn.fn_type_id.cc)) {
- assert(g->cur_ret_ptr);
- gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);
- LLVMBuildRetVoid(g->builder);
- } else {
- LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, "");
- LLVMBuildRet(g->builder, by_val_value);
- }
+ ZigType *return_type = return_instruction->value->value.type;
+
+ if (want_first_arg_sret(g, &g->cur_fn->type_entry->data.fn.fn_type_id)) {
+ assert(g->cur_ret_ptr);
+ gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);
+ LLVMBuildRetVoid(g->builder);
+ } else if (handle_is_ptr(return_type)) {
+ LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, "");
+ LLVMBuildRet(g->builder, by_val_value);
} else {
LLVMBuildRet(g->builder, value);
}
return nullptr;
}
-static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,
+static LLVMValueRef gen_overflow_shl_op(CodeGen *g, ZigType *type_entry,
LLVMValueRef val1, LLVMValueRef val2)
{
// for unsigned left shifting, we do the lossy shift, then logically shift
@@ -1891,7 +2228,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,
// if the values don't match, we have an overflow
// for signed left shifting we do the same except arithmetic shift right
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
LLVMValueRef result = LLVMBuildShl(g->builder, val1, val2, "");
LLVMValueRef orig_val;
@@ -1913,10 +2250,10 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,
return result;
}
-static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry,
+static LLVMValueRef gen_overflow_shr_op(CodeGen *g, ZigType *type_entry,
LLVMValueRef val1, LLVMValueRef val2)
{
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
LLVMValueRef result;
if (type_entry->data.integral.is_signed) {
@@ -1938,16 +2275,16 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry,
return result;
}
-static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, TypeTableEntry *type_entry) {
- if (type_entry->id == TypeTableEntryIdInt)
+static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, ZigType *type_entry) {
+ if (type_entry->id == ZigTypeIdInt)
return val;
LLVMValueRef floor_fn = get_float_fn(g, type_entry, ZigLLVMFnIdFloor);
return LLVMBuildCall(g->builder, floor_fn, &val, 1, "");
}
-static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, TypeTableEntry *type_entry) {
- if (type_entry->id == TypeTableEntryIdInt)
+static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, ZigType *type_entry) {
+ if (type_entry->id == ZigTypeIdInt)
return val;
LLVMValueRef ceil_fn = get_float_fn(g, type_entry, ZigLLVMFnIdCeil);
@@ -1980,16 +2317,16 @@ static LLVMValueRef bigint_to_llvm_const(LLVMTypeRef type_ref, BigInt *bigint) {
static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast_math,
LLVMValueRef val1, LLVMValueRef val2,
- TypeTableEntry *type_entry, DivKind div_kind)
+ ZigType *type_entry, DivKind div_kind)
{
ZigLLVMSetFastMath(g->builder, want_fast_math);
LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
- if (want_runtime_safety && (want_fast_math || type_entry->id != TypeTableEntryIdFloat)) {
+ if (want_runtime_safety && (want_fast_math || type_entry->id != ZigTypeIdFloat)) {
LLVMValueRef is_zero_bit;
- if (type_entry->id == TypeTableEntryIdInt) {
+ if (type_entry->id == ZigTypeIdInt) {
is_zero_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, val2, zero, "");
- } else if (type_entry->id == TypeTableEntryIdFloat) {
+ } else if (type_entry->id == ZigTypeIdFloat) {
is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");
} else {
zig_unreachable();
@@ -2003,7 +2340,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
LLVMPositionBuilderAtEnd(g->builder, div_zero_ok_block);
- if (type_entry->id == TypeTableEntryIdInt && type_entry->data.integral.is_signed) {
+ if (type_entry->id == ZigTypeIdInt && type_entry->data.integral.is_signed) {
LLVMValueRef neg_1_value = LLVMConstInt(type_entry->type_ref, -1, true);
BigInt int_min_bi = {0};
eval_min_max_value_int(g, type_entry, &int_min_bi, false);
@@ -2022,7 +2359,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
}
}
- if (type_entry->id == TypeTableEntryIdFloat) {
+ if (type_entry->id == ZigTypeIdFloat) {
LLVMValueRef result = LLVMBuildFDiv(g->builder, val1, val2, "");
switch (div_kind) {
case DivKindFloat:
@@ -2073,7 +2410,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast
zig_unreachable();
}
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
switch (div_kind) {
case DivKindFloat:
@@ -2139,17 +2476,17 @@ enum RemKind {
static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast_math,
LLVMValueRef val1, LLVMValueRef val2,
- TypeTableEntry *type_entry, RemKind rem_kind)
+ ZigType *type_entry, RemKind rem_kind)
{
ZigLLVMSetFastMath(g->builder, want_fast_math);
LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
if (want_runtime_safety) {
LLVMValueRef is_zero_bit;
- if (type_entry->id == TypeTableEntryIdInt) {
+ if (type_entry->id == ZigTypeIdInt) {
LLVMIntPredicate pred = type_entry->data.integral.is_signed ? LLVMIntSLE : LLVMIntEQ;
is_zero_bit = LLVMBuildICmp(g->builder, pred, val2, zero, "");
- } else if (type_entry->id == TypeTableEntryIdFloat) {
+ } else if (type_entry->id == ZigTypeIdFloat) {
is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, "");
} else {
zig_unreachable();
@@ -2164,7 +2501,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
LLVMPositionBuilderAtEnd(g->builder, rem_zero_ok_block);
}
- if (type_entry->id == TypeTableEntryIdFloat) {
+ if (type_entry->id == ZigTypeIdFloat) {
if (rem_kind == RemKindRem) {
return LLVMBuildFRem(g->builder, val1, val2, "");
} else {
@@ -2175,7 +2512,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
return LLVMBuildSelect(g->builder, ltz, c, a, "");
}
} else {
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
if (type_entry->data.integral.is_signed) {
if (rem_kind == RemKindRem) {
return LLVMBuildSRem(g->builder, val1, val2, "");
@@ -2203,12 +2540,12 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
assert(op1->value.type == op2->value.type || op_id == IrBinOpBitShiftLeftLossy ||
op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy ||
op_id == IrBinOpBitShiftRightExact ||
- (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) ||
- (op1->value.type->id == TypeTableEntryIdPointer &&
+ (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) ||
+ (op1->value.type->id == ZigTypeIdPointer &&
(op_id == IrBinOpAdd || op_id == IrBinOpSub) &&
op1->value.type->data.pointer.ptr_len == PtrLenUnknown)
);
- TypeTableEntry *type_entry = op1->value.type;
+ ZigType *type_entry = op1->value.type;
bool want_runtime_safety = bin_op_instruction->safety_check_on &&
ir_want_runtime_safety(g, &bin_op_instruction->base);
@@ -2234,16 +2571,16 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
case IrBinOpCmpGreaterThan:
case IrBinOpCmpLessOrEq:
case IrBinOpCmpGreaterOrEq:
- if (type_entry->id == TypeTableEntryIdFloat) {
+ if (type_entry->id == ZigTypeIdFloat) {
ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id);
return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, "");
- } else if (type_entry->id == TypeTableEntryIdInt) {
+ } else if (type_entry->id == ZigTypeIdInt) {
LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, type_entry->data.integral.is_signed);
return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
- } else if (type_entry->id == TypeTableEntryIdEnum ||
- type_entry->id == TypeTableEntryIdErrorSet ||
- type_entry->id == TypeTableEntryIdBool ||
+ } else if (type_entry->id == ZigTypeIdEnum ||
+ type_entry->id == ZigTypeIdErrorSet ||
+ type_entry->id == ZigTypeIdBool ||
get_codegen_ptr_type(type_entry) != nullptr)
{
LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
@@ -2253,14 +2590,14 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
}
case IrBinOpAdd:
case IrBinOpAddWrap:
- if (type_entry->id == TypeTableEntryIdPointer) {
+ if (type_entry->id == ZigTypeIdPointer) {
assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
// TODO runtime safety
return LLVMBuildInBoundsGEP(g->builder, op1_value, &op2_value, 1, "");
- } else if (type_entry->id == TypeTableEntryIdFloat) {
+ } else if (type_entry->id == ZigTypeIdFloat) {
ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
return LLVMBuildFAdd(g->builder, op1_value, op2_value, "");
- } else if (type_entry->id == TypeTableEntryIdInt) {
+ } else if (type_entry->id == ZigTypeIdInt) {
bool is_wrapping = (op_id == IrBinOpAddWrap);
if (is_wrapping) {
return LLVMBuildAdd(g->builder, op1_value, op2_value, "");
@@ -2283,7 +2620,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
case IrBinOpBitShiftLeftLossy:
case IrBinOpBitShiftLeftExact:
{
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,
type_entry, op2_value);
bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);
@@ -2300,7 +2637,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
case IrBinOpBitShiftRightLossy:
case IrBinOpBitShiftRightExact:
{
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type,
type_entry, op2_value);
bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy);
@@ -2320,15 +2657,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
}
case IrBinOpSub:
case IrBinOpSubWrap:
- if (type_entry->id == TypeTableEntryIdPointer) {
+ if (type_entry->id == ZigTypeIdPointer) {
assert(type_entry->data.pointer.ptr_len == PtrLenUnknown);
// TODO runtime safety
LLVMValueRef subscript_value = LLVMBuildNeg(g->builder, op2_value, "");
return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, "");
- } else if (type_entry->id == TypeTableEntryIdFloat) {
+ } else if (type_entry->id == ZigTypeIdFloat) {
ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
return LLVMBuildFSub(g->builder, op1_value, op2_value, "");
- } else if (type_entry->id == TypeTableEntryIdInt) {
+ } else if (type_entry->id == ZigTypeIdInt) {
bool is_wrapping = (op_id == IrBinOpSubWrap);
if (is_wrapping) {
return LLVMBuildSub(g->builder, op1_value, op2_value, "");
@@ -2344,10 +2681,10 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
}
case IrBinOpMult:
case IrBinOpMultWrap:
- if (type_entry->id == TypeTableEntryIdFloat) {
+ if (type_entry->id == ZigTypeIdFloat) {
ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base));
return LLVMBuildFMul(g->builder, op1_value, op2_value, "");
- } else if (type_entry->id == TypeTableEntryIdInt) {
+ } else if (type_entry->id == ZigTypeIdInt) {
bool is_wrapping = (op_id == IrBinOpMultWrap);
if (is_wrapping) {
return LLVMBuildMul(g->builder, op1_value, op2_value, "");
@@ -2383,8 +2720,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
zig_unreachable();
}
-static void add_error_range_check(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *int_type, LLVMValueRef target_val) {
- assert(err_set_type->id == TypeTableEntryIdErrorSet);
+static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *int_type, LLVMValueRef target_val) {
+ assert(err_set_type->id == ZigTypeIdErrorSet);
if (type_is_global_error_set(err_set_type)) {
LLVMValueRef zero = LLVMConstNull(int_type->type_ref);
@@ -2434,8 +2771,8 @@ static void add_error_range_check(CodeGen *g, TypeTableEntry *err_set_type, Type
static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
IrInstructionCast *cast_instruction)
{
- TypeTableEntry *actual_type = cast_instruction->value->value.type;
- TypeTableEntry *wanted_type = cast_instruction->base.value.type;
+ ZigType *actual_type = cast_instruction->value->value.type;
+ ZigType *wanted_type = cast_instruction->base.value.type;
LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value);
assert(expr_val);
@@ -2448,15 +2785,15 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
case CastOpResizeSlice:
{
assert(cast_instruction->tmp_ptr);
- assert(wanted_type->id == TypeTableEntryIdStruct);
+ assert(wanted_type->id == ZigTypeIdStruct);
assert(wanted_type->data.structure.is_slice);
- assert(actual_type->id == TypeTableEntryIdStruct);
+ assert(actual_type->id == ZigTypeIdStruct);
assert(actual_type->data.structure.is_slice);
- TypeTableEntry *actual_pointer_type = actual_type->data.structure.fields[0].type_entry;
- TypeTableEntry *actual_child_type = actual_pointer_type->data.pointer.child_type;
- TypeTableEntry *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry;
- TypeTableEntry *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
+ ZigType *actual_pointer_type = actual_type->data.structure.fields[0].type_entry;
+ ZigType *actual_child_type = actual_pointer_type->data.pointer.child_type;
+ ZigType *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry;
+ ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
size_t actual_ptr_index = actual_type->data.structure.fields[slice_ptr_index].gen_index;
@@ -2511,12 +2848,12 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
case CastOpBytesToSlice:
{
assert(cast_instruction->tmp_ptr);
- assert(wanted_type->id == TypeTableEntryIdStruct);
+ assert(wanted_type->id == ZigTypeIdStruct);
assert(wanted_type->data.structure.is_slice);
- assert(actual_type->id == TypeTableEntryIdArray);
+ assert(actual_type->id == ZigTypeIdArray);
- TypeTableEntry *wanted_pointer_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
- TypeTableEntry *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
+ ZigType *wanted_pointer_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
+ ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type;
size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index;
@@ -2535,14 +2872,14 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
return cast_instruction->tmp_ptr;
}
case CastOpIntToFloat:
- assert(actual_type->id == TypeTableEntryIdInt);
+ assert(actual_type->id == ZigTypeIdInt);
if (actual_type->data.integral.is_signed) {
return LLVMBuildSIToFP(g->builder, expr_val, wanted_type->type_ref, "");
} else {
return LLVMBuildUIToFP(g->builder, expr_val, wanted_type->type_ref, "");
}
case CastOpFloatToInt: {
- assert(wanted_type->id == TypeTableEntryIdInt);
+ assert(wanted_type->id == ZigTypeIdInt);
ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &cast_instruction->base));
bool want_safety = ir_want_runtime_safety(g, &cast_instruction->base);
@@ -2577,8 +2914,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
return result;
}
case CastOpBoolToInt:
- assert(wanted_type->id == TypeTableEntryIdInt);
- assert(actual_type->id == TypeTableEntryIdBool);
+ assert(wanted_type->id == ZigTypeIdInt);
+ assert(actual_type->id == ZigTypeIdBool);
return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, "");
case CastOpErrSet:
if (ir_want_runtime_safety(g, &cast_instruction->base)) {
@@ -2589,9 +2926,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
return LLVMBuildBitCast(g->builder, expr_val, wanted_type->type_ref, "");
case CastOpPtrOfArrayToSlice: {
assert(cast_instruction->tmp_ptr);
- assert(actual_type->id == TypeTableEntryIdPointer);
- TypeTableEntry *array_type = actual_type->data.pointer.child_type;
- assert(array_type->id == TypeTableEntryIdArray);
+ assert(actual_type->id == ZigTypeIdPointer);
+ ZigType *array_type = actual_type->data.pointer.child_type;
+ assert(array_type->id == ZigTypeIdArray);
LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr,
slice_ptr_index, "");
@@ -2617,7 +2954,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
IrInstructionPtrCast *instruction)
{
- TypeTableEntry *wanted_type = instruction->base.value.type;
+ ZigType *wanted_type = instruction->base.value.type;
if (!type_has_bits(wanted_type)) {
return nullptr;
}
@@ -2628,7 +2965,7 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
IrInstructionBitCast *instruction)
{
- TypeTableEntry *wanted_type = instruction->base.value.type;
+ ZigType *wanted_type = instruction->base.value.type;
LLVMValueRef value = ir_llvm_value(g, instruction->value);
return LLVMBuildBitCast(g->builder, value, wanted_type->type_ref, "");
}
@@ -2636,11 +2973,11 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,
IrInstructionWidenOrShorten *instruction)
{
- TypeTableEntry *actual_type = instruction->target->value.type;
+ ZigType *actual_type = instruction->target->value.type;
// TODO instead of this logic, use the Noop instruction to change the type from
// enum_tag to the underlying int type
- TypeTableEntry *int_type;
- if (actual_type->id == TypeTableEntryIdEnum) {
+ ZigType *int_type;
+ if (actual_type->id == ZigTypeIdEnum) {
int_type = actual_type->data.enumeration.tag_int_type;
} else {
int_type = actual_type;
@@ -2651,21 +2988,21 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
}
static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) {
- TypeTableEntry *wanted_type = instruction->base.value.type;
+ ZigType *wanted_type = instruction->base.value.type;
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
return LLVMBuildIntToPtr(g->builder, target_val, wanted_type->type_ref, "");
}
static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) {
- TypeTableEntry *wanted_type = instruction->base.value.type;
+ ZigType *wanted_type = instruction->base.value.type;
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
return LLVMBuildPtrToInt(g->builder, target_val, wanted_type->type_ref, "");
}
static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {
- TypeTableEntry *wanted_type = instruction->base.value.type;
- assert(wanted_type->id == TypeTableEntryIdEnum);
- TypeTableEntry *tag_int_type = wanted_type->data.enumeration.tag_int_type;
+ ZigType *wanted_type = instruction->base.value.type;
+ assert(wanted_type->id == ZigTypeIdEnum);
+ ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
LLVMValueRef tag_int_value = gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
@@ -2690,11 +3027,11 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
}
static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {
- TypeTableEntry *wanted_type = instruction->base.value.type;
- assert(wanted_type->id == TypeTableEntryIdErrorSet);
+ ZigType *wanted_type = instruction->base.value.type;
+ assert(wanted_type->id == ZigTypeIdErrorSet);
- TypeTableEntry *actual_type = instruction->target->value.type;
- assert(actual_type->id == TypeTableEntryIdInt);
+ ZigType *actual_type = instruction->target->value.type;
+ assert(actual_type->id == ZigTypeIdInt);
assert(!actual_type->data.integral.is_signed);
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
@@ -2707,17 +3044,17 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
}
static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {
- TypeTableEntry *wanted_type = instruction->base.value.type;
- assert(wanted_type->id == TypeTableEntryIdInt);
+ ZigType *wanted_type = instruction->base.value.type;
+ assert(wanted_type->id == ZigTypeIdInt);
assert(!wanted_type->data.integral.is_signed);
- TypeTableEntry *actual_type = instruction->target->value.type;
+ ZigType *actual_type = instruction->target->value.type;
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
- if (actual_type->id == TypeTableEntryIdErrorSet) {
+ if (actual_type->id == ZigTypeIdErrorSet) {
return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
g->err_tag_type, wanted_type, target_val);
- } else if (actual_type->id == TypeTableEntryIdErrorUnion) {
+ } else if (actual_type->id == ZigTypeIdErrorUnion) {
// this should have been a compile time constant
assert(type_has_bits(actual_type->data.error_union.err_set_type));
@@ -2761,7 +3098,7 @@ static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstruc
static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {
IrUnOp op_id = un_op_instruction->op_id;
LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value);
- TypeTableEntry *expr_type = un_op_instruction->value->value.type;
+ ZigType *expr_type = un_op_instruction->value->value.type;
switch (op_id) {
case IrUnOpInvalid:
@@ -2771,10 +3108,10 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst
case IrUnOpNegation:
case IrUnOpNegationWrap:
{
- if (expr_type->id == TypeTableEntryIdFloat) {
+ if (expr_type->id == ZigTypeIdFloat) {
ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base));
return LLVMBuildFNeg(g->builder, expr, "");
- } else if (expr_type->id == TypeTableEntryIdInt) {
+ } else if (expr_type->id == ZigTypeIdInt) {
if (op_id == IrUnOpNegationWrap) {
return LLVMBuildNeg(g->builder, expr, "");
} else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {
@@ -2805,7 +3142,7 @@ static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutable *executable, IrI
static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
IrInstructionDeclVar *decl_var_instruction)
{
- VariableTableEntry *var = decl_var_instruction->var;
+ ZigVar *var = decl_var_instruction->var;
if (!type_has_bits(var->value->type))
return nullptr;
@@ -2823,13 +3160,13 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
if (have_init_expr) {
assert(var->value->type == init_value->value.type);
- TypeTableEntry *var_ptr_type = get_pointer_to_type_extra(g, var->value->type, false, false,
+ ZigType *var_ptr_type = get_pointer_to_type_extra(g, var->value->type, false, false,
PtrLenSingle, var->align_bytes, 0, 0);
gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value));
} else {
bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base);
if (want_safe) {
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value->type->type_ref);
assert(size_bytes > 0);
@@ -2849,13 +3186,13 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
}
static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrInstructionLoadPtr *instruction) {
- TypeTableEntry *child_type = instruction->base.value.type;
+ ZigType *child_type = instruction->base.value.type;
if (!type_has_bits(child_type))
return nullptr;
LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
- TypeTableEntry *ptr_type = instruction->ptr->value.type;
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ ZigType *ptr_type = instruction->ptr->value.type;
+ assert(ptr_type->id == ZigTypeIdPointer);
uint32_t unaligned_bit_count = ptr_type->data.pointer.unaligned_bit_count;
if (unaligned_bit_count == 0)
@@ -2880,8 +3217,8 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
LLVMValueRef value = ir_llvm_value(g, instruction->value);
- assert(instruction->ptr->value.type->id == TypeTableEntryIdPointer);
- TypeTableEntry *ptr_type = instruction->ptr->value.type;
+ assert(instruction->ptr->value.type->id == ZigTypeIdPointer);
+ ZigType *ptr_type = instruction->ptr->value.type;
gen_assign_raw(g, ptr, ptr_type, value);
@@ -2889,7 +3226,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
}
static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {
- VariableTableEntry *var = instruction->var;
+ ZigVar *var = instruction->var;
if (type_has_bits(var->value->type)) {
assert(var->value_ref);
return var->value_ref;
@@ -2900,9 +3237,9 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {
LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
- TypeTableEntry *array_ptr_type = instruction->array_ptr->value.type;
- assert(array_ptr_type->id == TypeTableEntryIdPointer);
- TypeTableEntry *array_type = array_ptr_type->data.pointer.child_type;
+ ZigType *array_ptr_type = instruction->array_ptr->value.type;
+ assert(array_ptr_type->id == ZigTypeIdPointer);
+ ZigType *array_type = array_ptr_type->data.pointer.child_type;
LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);
LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);
assert(subscript_value);
@@ -2912,11 +3249,11 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on;
- if (array_type->id == TypeTableEntryIdArray ||
- (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
+ if (array_type->id == ZigTypeIdArray ||
+ (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
{
- if (array_type->id == TypeTableEntryIdPointer) {
- assert(array_type->data.pointer.child_type->id == TypeTableEntryIdArray);
+ if (array_type->id == ZigTypeIdPointer) {
+ assert(array_type->data.pointer.child_type->id == ZigTypeIdArray);
array_type = array_type->data.pointer.child_type;
}
if (safety_check_on) {
@@ -2927,8 +3264,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
if (array_ptr_type->data.pointer.unaligned_bit_count != 0) {
return array_ptr_ptr;
}
- TypeTableEntry *child_type = array_type->data.array.child_type;
- if (child_type->id == TypeTableEntryIdStruct &&
+ ZigType *child_type = array_type->data.array.child_type;
+ if (child_type->id == ZigTypeIdStruct &&
child_type->data.structure.layout == ContainerLayoutPacked)
{
size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count;
@@ -2951,13 +3288,13 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
subscript_value
};
return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, "");
- } else if (array_type->id == TypeTableEntryIdPointer) {
+ } else if (array_type->id == ZigTypeIdPointer) {
assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
LLVMValueRef indices[] = {
subscript_value
};
return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, "");
- } else if (array_type->id == TypeTableEntryIdStruct) {
+ } else if (array_type->id == ZigTypeIdStruct) {
assert(array_type->data.structure.is_slice);
if (!type_has_bits(instruction->base.value.type)) {
if (safety_check_on) {
@@ -2990,8 +3327,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
static bool get_prefix_arg_err_ret_stack(CodeGen *g, FnTypeId *fn_type_id) {
return g->have_err_ret_tracing &&
- (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion ||
- fn_type_id->return_type->id == TypeTableEntryIdErrorSet ||
+ (fn_type_id->return_type->id == ZigTypeIdErrorUnion ||
+ fn_type_id->return_type->id == ZigTypeIdErrorSet ||
fn_type_id->cc == CallingConventionAsync);
}
@@ -3047,7 +3384,7 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) {
static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) {
LLVMValueRef fn_val;
- TypeTableEntry *fn_type;
+ ZigType *fn_type;
if (instruction->fn_entry) {
fn_val = fn_llvm_value(g, instruction->fn_entry);
fn_type = instruction->fn_entry->type_entry;
@@ -3059,43 +3396,33 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
- TypeTableEntry *src_return_type = fn_type_id->return_type;
+ ZigType *src_return_type = fn_type_id->return_type;
bool ret_has_bits = type_has_bits(src_return_type);
- bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type) &&
- calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc);
+ CallingConvention cc = fn_type->data.fn.fn_type_id.cc;
+
+ bool first_arg_ret = ret_has_bits && want_first_arg_sret(g, fn_type_id);
bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, fn_type_id);
- // +2 for the async args
- size_t actual_param_count = instruction->arg_count + (first_arg_ret ? 1 : 0) + (prefix_arg_err_ret_stack ? 1 : 0) + 2;
bool is_var_args = fn_type_id->is_var_args;
- LLVMValueRef *gen_param_values = allocate<LLVMValueRef>(actual_param_count);
- size_t gen_param_index = 0;
+ ZigList<LLVMValueRef> gen_param_values = {};
if (first_arg_ret) {
- gen_param_values[gen_param_index] = instruction->tmp_ptr;
- gen_param_index += 1;
+ gen_param_values.append(instruction->tmp_ptr);
}
if (prefix_arg_err_ret_stack) {
- gen_param_values[gen_param_index] = get_cur_err_ret_trace_val(g, instruction->base.scope);
- gen_param_index += 1;
+ gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope));
}
if (instruction->is_async) {
- gen_param_values[gen_param_index] = ir_llvm_value(g, instruction->async_allocator);
- gen_param_index += 1;
+ gen_param_values.append(ir_llvm_value(g, instruction->async_allocator));
LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, err_union_err_index, "");
- gen_param_values[gen_param_index] = err_val_ptr;
- gen_param_index += 1;
- }
- for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
- IrInstruction *param_instruction = instruction->args[call_i];
- TypeTableEntry *param_type = param_instruction->value.type;
- if (is_var_args || type_has_bits(param_type)) {
- LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
- assert(param_value);
- gen_param_values[gen_param_index] = param_value;
- gen_param_index += 1;
- }
+ gen_param_values.append(err_val_ptr);
}
+ FnWalk fn_walk = {};
+ fn_walk.id = FnWalkIdCall;
+ fn_walk.data.call.inst = instruction;
+ fn_walk.data.call.is_var_args = is_var_args;
+ fn_walk.data.call.gen_param_values = &gen_param_values;
+ walk_function_params(g, fn_type, &fn_walk);
ZigLLVM_FnInline fn_inline;
switch (instruction->fn_inline) {
@@ -3110,12 +3437,12 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
break;
}
- LLVMCallConv llvm_cc = get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc);
+ LLVMCallConv llvm_cc = get_llvm_cc(g, cc);
LLVMValueRef result;
if (instruction->new_stack == nullptr) {
result = ZigLLVMBuildCall(g->builder, fn_val,
- gen_param_values, (unsigned)gen_param_index, llvm_cc, fn_inline, "");
+ gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, fn_inline, "");
} else {
LLVMValueRef stacksave_fn_val = get_stacksave_fn_val(g);
LLVMValueRef stackrestore_fn_val = get_stackrestore_fn_val(g);
@@ -3124,7 +3451,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
LLVMValueRef old_stack_ref = LLVMBuildCall(g->builder, stacksave_fn_val, nullptr, 0, "");
gen_set_stack_pointer(g, new_stack_addr);
result = ZigLLVMBuildCall(g->builder, fn_val,
- gen_param_values, (unsigned)gen_param_index, llvm_cc, fn_inline, "");
+ gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, fn_inline, "");
LLVMBuildCall(g->builder, stackrestore_fn_val, &old_stack_ref, 1, "");
}
@@ -3135,7 +3462,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
return instruction->tmp_ptr;
}
- if (src_return_type->id == TypeTableEntryIdUnreachable) {
+ if (src_return_type->id == ZigTypeIdUnreachable) {
return LLVMBuildUnreachable(g->builder);
} else if (!ret_has_bits) {
return nullptr;
@@ -3155,14 +3482,14 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
IrInstructionStructFieldPtr *instruction)
{
LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr);
- // not necessarily a pointer. could be TypeTableEntryIdStruct
- TypeTableEntry *struct_ptr_type = instruction->struct_ptr->value.type;
+ // not necessarily a pointer. could be ZigTypeIdStruct
+ ZigType *struct_ptr_type = instruction->struct_ptr->value.type;
TypeStructField *field = instruction->field;
if (!type_has_bits(field->type_entry))
return nullptr;
- if (struct_ptr_type->id == TypeTableEntryIdPointer &&
+ if (struct_ptr_type->id == ZigTypeIdPointer &&
struct_ptr_type->data.pointer.unaligned_bit_count != 0)
{
return struct_ptr;
@@ -3175,10 +3502,10 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,
IrInstructionUnionFieldPtr *instruction)
{
- TypeTableEntry *union_ptr_type = instruction->union_ptr->value.type;
- assert(union_ptr_type->id == TypeTableEntryIdPointer);
- TypeTableEntry *union_type = union_ptr_type->data.pointer.child_type;
- assert(union_type->id == TypeTableEntryIdUnion);
+ ZigType *union_ptr_type = instruction->union_ptr->value.type;
+ assert(union_ptr_type->id == ZigTypeIdPointer);
+ ZigType *union_type = union_ptr_type->data.pointer.child_type;
+ assert(union_type->id == ZigTypeIdUnion);
TypeUnionField *field = instruction->field;
@@ -3304,7 +3631,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
}
if (!is_return) {
- VariableTableEntry *variable = instruction->output_vars[i];
+ ZigVar *variable = instruction->output_vars[i];
assert(variable);
param_types[param_index] = LLVMTypeOf(variable->value_ref);
param_values[param_index] = variable->value_ref;
@@ -3345,9 +3672,9 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, "");
}
-static LLVMValueRef gen_non_null_bit(CodeGen *g, TypeTableEntry *maybe_type, LLVMValueRef maybe_handle) {
- assert(maybe_type->id == TypeTableEntryIdOptional);
- TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
+static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) {
+ assert(maybe_type->id == ZigTypeIdOptional);
+ ZigType *child_type = maybe_type->data.maybe.child_type;
if (child_type->zero_bits) {
return maybe_handle;
} else {
@@ -3370,11 +3697,11 @@ static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable
static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
IrInstructionUnwrapOptional *instruction)
{
- TypeTableEntry *ptr_type = instruction->value->value.type;
- assert(ptr_type->id == TypeTableEntryIdPointer);
- TypeTableEntry *maybe_type = ptr_type->data.pointer.child_type;
- assert(maybe_type->id == TypeTableEntryIdOptional);
- TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
+ ZigType *ptr_type = instruction->value->value.type;
+ assert(ptr_type->id == ZigTypeIdPointer);
+ ZigType *maybe_type = ptr_type->data.pointer.child_type;
+ assert(maybe_type->id == ZigTypeIdOptional);
+ ZigType *child_type = maybe_type->data.maybe.child_type;
LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);
LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);
if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on) {
@@ -3401,7 +3728,7 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
}
}
-static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, BuiltinFnId fn_id) {
+static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *int_type, BuiltinFnId fn_id) {
ZigLLVMFnKey key = {};
const char *fn_name;
uint32_t n_args;
@@ -3444,7 +3771,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, Bui
}
static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) {
- TypeTableEntry *int_type = instruction->value->value.type;
+ ZigType *int_type = instruction->value->value.type;
LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
LLVMValueRef operand = ir_llvm_value(g, instruction->value);
LLVMValueRef params[] {
@@ -3456,7 +3783,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru
}
static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) {
- TypeTableEntry *int_type = instruction->value->value.type;
+ ZigType *int_type = instruction->value->value.type;
LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
LLVMValueRef operand = ir_llvm_value(g, instruction->value);
LLVMValueRef params[] {
@@ -3468,7 +3795,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru
}
static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, IrInstructionPopCount *instruction) {
- TypeTableEntry *int_type = instruction->value->value.type;
+ ZigType *int_type = instruction->value->value.type;
LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);
LLVMValueRef operand = ir_llvm_value(g, instruction->value);
LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, &operand, 1, "");
@@ -3545,15 +3872,15 @@ static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrI
return LLVMBuildInBoundsGEP(g->builder, g->err_name_table, indices, 2, "");
}
-static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_type) {
- assert(enum_type->id == TypeTableEntryIdEnum);
+static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
+ assert(enum_type->id == ZigTypeIdEnum);
if (enum_type->data.enumeration.name_function)
return enum_type->data.enumeration.name_function;
- TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
+ ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *u8_slice_type = get_slice_type(g, u8_ptr_type);
- TypeTableEntry *tag_int_type = enum_type->data.enumeration.tag_int_type;
+ ZigType *u8_slice_type = get_slice_type(g, u8_ptr_type);
+ ZigType *tag_int_type = enum_type->data.enumeration.tag_int_type;
LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMPointerType(u8_slice_type->type_ref, 0),
&tag_int_type->type_ref, 1, false);
@@ -3571,7 +3898,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_
LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);
LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder);
- FnTableEntry *prev_cur_fn = g->cur_fn;
+ ZigFn *prev_cur_fn = g->cur_fn;
LLVMValueRef prev_cur_fn_val = g->cur_fn_val;
LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");
@@ -3586,7 +3913,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_
LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, tag_int_value, bad_value_block, field_count);
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
LLVMValueRef array_ptr_indices[] = {
LLVMConstNull(usize->type_ref),
LLVMConstNull(usize->type_ref),
@@ -3643,8 +3970,8 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_
static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,
IrInstructionTagName *instruction)
{
- TypeTableEntry *enum_type = instruction->target->value.type;
- assert(enum_type->id == TypeTableEntryIdEnum);
+ ZigType *enum_type = instruction->target->value.type;
+ assert(enum_type->id == ZigTypeIdEnum);
LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type);
@@ -3656,10 +3983,10 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable
static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,
IrInstructionFieldParentPtr *instruction)
{
- TypeTableEntry *container_ptr_type = instruction->base.value.type;
- assert(container_ptr_type->id == TypeTableEntryIdPointer);
+ ZigType *container_ptr_type = instruction->base.value.type;
+ assert(container_ptr_type->id == ZigTypeIdPointer);
- TypeTableEntry *container_type = container_ptr_type->data.pointer.child_type;
+ ZigType *container_type = container_ptr_type->data.pointer.child_type;
size_t byte_offset = LLVMOffsetOfElement(g->target_data_ref,
container_type->type_ref, instruction->field->gen_index);
@@ -3669,7 +3996,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa
if (byte_offset == 0) {
return LLVMBuildBitCast(g->builder, field_ptr_val, container_ptr_type->type_ref, "");
} else {
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
LLVMValueRef field_ptr_int = LLVMBuildPtrToInt(g->builder, field_ptr_val,
usize->type_ref, "");
@@ -3690,32 +4017,32 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
return target_val;
}
- TypeTableEntry *target_type = instruction->base.value.type;
+ ZigType *target_type = instruction->base.value.type;
uint32_t align_bytes;
LLVMValueRef ptr_val;
- if (target_type->id == TypeTableEntryIdPointer) {
+ if (target_type->id == ZigTypeIdPointer) {
align_bytes = target_type->data.pointer.alignment;
ptr_val = target_val;
- } else if (target_type->id == TypeTableEntryIdFn) {
+ } else if (target_type->id == ZigTypeIdFn) {
align_bytes = target_type->data.fn.fn_type_id.alignment;
ptr_val = target_val;
- } else if (target_type->id == TypeTableEntryIdOptional &&
- target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
+ } else if (target_type->id == ZigTypeIdOptional &&
+ target_type->data.maybe.child_type->id == ZigTypeIdPointer)
{
align_bytes = target_type->data.maybe.child_type->data.pointer.alignment;
ptr_val = target_val;
- } else if (target_type->id == TypeTableEntryIdOptional &&
- target_type->data.maybe.child_type->id == TypeTableEntryIdFn)
+ } else if (target_type->id == ZigTypeIdOptional &&
+ target_type->data.maybe.child_type->id == ZigTypeIdFn)
{
align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;
ptr_val = target_val;
- } else if (target_type->id == TypeTableEntryIdOptional &&
- target_type->data.maybe.child_type->id == TypeTableEntryIdPromise)
+ } else if (target_type->id == ZigTypeIdOptional &&
+ target_type->data.maybe.child_type->id == ZigTypeIdPromise)
{
zig_panic("TODO audit this function");
- } else if (target_type->id == TypeTableEntryIdStruct && target_type->data.structure.is_slice) {
- TypeTableEntry *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
+ } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) {
+ ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
align_bytes = slice_ptr_type->data.pointer.alignment;
size_t ptr_index = target_type->data.structure.fields[slice_ptr_index].gen_index;
@@ -3727,7 +4054,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
assert(align_bytes != 1);
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
LLVMValueRef ptr_as_int_val = LLVMBuildPtrToInt(g->builder, ptr_val, usize->type_ref, "");
LLVMValueRef alignment_minus_1 = LLVMConstInt(usize->type_ref, align_bytes - 1, false);
LLVMValueRef anded_val = LLVMBuildAnd(g->builder, ptr_as_int_val, alignment_minus_1, "");
@@ -3751,7 +4078,7 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu
{
LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope);
if (cur_err_ret_trace_val == nullptr) {
- TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
+ ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g);
return LLVMConstNull(ptr_to_stack_trace_type->type_ref);
}
return cur_err_ret_trace_val;
@@ -3811,9 +4138,9 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
LLVMValueRef result_val = ZigLLVMBuildCmpXchg(g->builder, ptr_val, cmp_val, new_val,
success_order, failure_order, instruction->is_weak);
- TypeTableEntry *maybe_type = instruction->base.value.type;
- assert(maybe_type->id == TypeTableEntryIdOptional);
- TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
+ ZigType *maybe_type = instruction->base.value.type;
+ assert(maybe_type->id == ZigTypeIdOptional);
+ ZigType *child_type = maybe_type->data.maybe.child_type;
if (type_is_codegen_pointer(child_type)) {
LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, "");
@@ -3843,8 +4170,8 @@ static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInst
static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
- TypeTableEntry *dest_type = instruction->base.value.type;
- TypeTableEntry *src_type = instruction->target->value.type;
+ ZigType *dest_type = instruction->base.value.type;
+ ZigType *src_type = instruction->target->value.type;
if (dest_type == src_type) {
// no-op
return target_val;
@@ -3865,8 +4192,8 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
- TypeTableEntry *ptr_type = instruction->dest_ptr->value.type;
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ ZigType *ptr_type = instruction->dest_ptr->value.type;
+ assert(ptr_type->id == ZigTypeIdPointer);
ZigLLVMBuildMemSet(g->builder, dest_ptr_casted, char_val, len_val, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile);
return nullptr;
@@ -3882,11 +4209,11 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, "");
- TypeTableEntry *dest_ptr_type = instruction->dest_ptr->value.type;
- TypeTableEntry *src_ptr_type = instruction->src_ptr->value.type;
+ ZigType *dest_ptr_type = instruction->dest_ptr->value.type;
+ ZigType *src_ptr_type = instruction->src_ptr->value.type;
- assert(dest_ptr_type->id == TypeTableEntryIdPointer);
- assert(src_ptr_type->id == TypeTableEntryIdPointer);
+ assert(dest_ptr_type->id == ZigTypeIdPointer);
+ assert(src_ptr_type->id == ZigTypeIdPointer);
bool is_volatile = (dest_ptr_type->data.pointer.is_volatile || src_ptr_type->data.pointer.is_volatile);
@@ -3899,19 +4226,19 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
assert(instruction->tmp_ptr);
LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);
- TypeTableEntry *array_ptr_type = instruction->ptr->value.type;
- assert(array_ptr_type->id == TypeTableEntryIdPointer);
- TypeTableEntry *array_type = array_ptr_type->data.pointer.child_type;
+ ZigType *array_ptr_type = instruction->ptr->value.type;
+ assert(array_ptr_type->id == ZigTypeIdPointer);
+ ZigType *array_type = array_ptr_type->data.pointer.child_type;
LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type);
LLVMValueRef tmp_struct_ptr = instruction->tmp_ptr;
bool want_runtime_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base);
- if (array_type->id == TypeTableEntryIdArray ||
- (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
+ if (array_type->id == ZigTypeIdArray ||
+ (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
{
- if (array_type->id == TypeTableEntryIdPointer) {
+ if (array_type->id == ZigTypeIdPointer) {
array_type = array_type->data.pointer.child_type;
}
LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
@@ -3952,7 +4279,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
gen_store_untyped(g, len_value, len_field_ptr, 0, false);
return tmp_struct_ptr;
- } else if (array_type->id == TypeTableEntryIdPointer) {
+ } else if (array_type->id == ZigTypeIdPointer) {
assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
LLVMValueRef end_val = ir_llvm_value(g, instruction->end);
@@ -3974,7 +4301,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
gen_store_untyped(g, len_value, len_field_ptr, 0, false);
return tmp_struct_ptr;
- } else if (array_type->id == TypeTableEntryIdStruct) {
+ } else if (array_type->id == ZigTypeIdStruct) {
assert(array_type->data.structure.is_slice);
assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
@@ -4050,7 +4377,7 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {
if (g->frame_address_fn_val)
return g->frame_address_fn_val;
- TypeTableEntry *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
+ ZigType *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true);
LLVMTypeRef fn_type = LLVMFunctionType(return_type->type_ref,
&g->builtin_types.entry_i32->type_ref, 1, false);
@@ -4088,8 +4415,8 @@ static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,
}
static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {
- TypeTableEntry *int_type = instruction->result_ptr_type;
- assert(int_type->id == TypeTableEntryIdInt);
+ ZigType *int_type = instruction->result_ptr_type;
+ assert(int_type->id == ZigTypeIdInt);
LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
@@ -4128,8 +4455,8 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
return render_shl_with_overflow(g, instruction);
}
- TypeTableEntry *int_type = instruction->result_ptr_type;
- assert(int_type->id == TypeTableEntryIdInt);
+ ZigType *int_type = instruction->result_ptr_type;
+ assert(int_type->id == ZigTypeIdInt);
LLVMValueRef fn_val = get_int_overflow_fn(g, int_type, add_sub_mul);
@@ -4151,8 +4478,8 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
}
static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErr *instruction) {
- TypeTableEntry *err_union_type = instruction->value->value.type;
- TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type;
+ ZigType *err_union_type = instruction->value->value.type;
+ ZigType *payload_type = err_union_type->data.error_union.payload_type;
LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->value);
LLVMValueRef err_val;
@@ -4168,10 +4495,10 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
}
static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) {
- TypeTableEntry *ptr_type = instruction->value->value.type;
- assert(ptr_type->id == TypeTableEntryIdPointer);
- TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type;
- TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type;
+ ZigType *ptr_type = instruction->value->value.type;
+ assert(ptr_type->id == ZigTypeIdPointer);
+ ZigType *err_union_type = ptr_type->data.pointer.child_type;
+ ZigType *payload_type = err_union_type->data.error_union.payload_type;
LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);
@@ -4184,10 +4511,10 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
}
static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) {
- TypeTableEntry *ptr_type = instruction->value->value.type;
- assert(ptr_type->id == TypeTableEntryIdPointer);
- TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type;
- TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type;
+ ZigType *ptr_type = instruction->value->value.type;
+ assert(ptr_type->id == ZigTypeIdPointer);
+ ZigType *err_union_type = ptr_type->data.pointer.child_type;
+ ZigType *payload_type = err_union_type->data.error_union.payload_type;
LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);
@@ -4223,11 +4550,11 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
}
static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {
- TypeTableEntry *wanted_type = instruction->base.value.type;
+ ZigType *wanted_type = instruction->base.value.type;
- assert(wanted_type->id == TypeTableEntryIdOptional);
+ assert(wanted_type->id == ZigTypeIdOptional);
- TypeTableEntry *child_type = wanted_type->data.maybe.child_type;
+ ZigType *child_type = wanted_type->data.maybe.child_type;
if (child_type->zero_bits) {
return LLVMConstInt(LLVMInt1Type(), 1, false);
@@ -4250,12 +4577,12 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
}
static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {
- TypeTableEntry *wanted_type = instruction->base.value.type;
+ ZigType *wanted_type = instruction->base.value.type;
- assert(wanted_type->id == TypeTableEntryIdErrorUnion);
+ assert(wanted_type->id == ZigTypeIdErrorUnion);
- TypeTableEntry *payload_type = wanted_type->data.error_union.payload_type;
- TypeTableEntry *err_set_type = wanted_type->data.error_union.err_set_type;
+ ZigType *payload_type = wanted_type->data.error_union.payload_type;
+ ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
LLVMValueRef err_val = ir_llvm_value(g, instruction->value);
@@ -4271,12 +4598,12 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
}
static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {
- TypeTableEntry *wanted_type = instruction->base.value.type;
+ ZigType *wanted_type = instruction->base.value.type;
- assert(wanted_type->id == TypeTableEntryIdErrorUnion);
+ assert(wanted_type->id == ZigTypeIdErrorUnion);
- TypeTableEntry *payload_type = wanted_type->data.error_union.payload_type;
- TypeTableEntry *err_set_type = wanted_type->data.error_union.err_set_type;
+ ZigType *payload_type = wanted_type->data.error_union.payload_type;
+ ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
if (!type_has_bits(err_set_type)) {
return ir_llvm_value(g, instruction->value);
@@ -4301,10 +4628,10 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
}
static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {
- TypeTableEntry *union_type = instruction->value->value.type;
+ ZigType *union_type = instruction->value->value.type;
assert(union_type->data.unionation.gen_tag_index != SIZE_MAX);
- TypeTableEntry *tag_type = union_type->data.unionation.tag_type;
+ ZigType *tag_type = union_type->data.unionation.tag_type;
if (!type_has_bits(tag_type))
return nullptr;
@@ -4314,7 +4641,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_val,
union_type->data.unionation.gen_tag_index, "");
- TypeTableEntry *ptr_type = get_pointer_to_type(g, tag_type, false);
+ ZigType *ptr_type = get_pointer_to_type(g, tag_type, false);
return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);
}
@@ -4331,7 +4658,7 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable,
uint32_t field_align_bytes = get_abi_alignment(g, type_struct_field->type_entry);
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_struct_field->type_entry,
+ ZigType *ptr_type = get_pointer_to_type_extra(g, type_struct_field->type_entry,
false, false, PtrLenSingle, field_align_bytes,
(uint32_t)type_struct_field->packed_bits_offset, (uint32_t)type_struct_field->unaligned_bit_count);
@@ -4347,14 +4674,14 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I
return nullptr;
uint32_t field_align_bytes = get_abi_alignment(g, type_union_field->type_entry);
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_union_field->type_entry,
+ ZigType *ptr_type = get_pointer_to_type_extra(g, type_union_field->type_entry,
false, false, PtrLenSingle, field_align_bytes,
0, 0);
LLVMValueRef uncasted_union_ptr;
// Even if safety is off in this block, if the union type has the safety field, we have to populate it
// correctly. Otherwise safety code somewhere other than here could fail.
- TypeTableEntry *union_type = instruction->union_type;
+ ZigType *union_type = instruction->union_type;
if (union_type->data.unionation.gen_tag_index != SIZE_MAX) {
LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr,
union_type->data.unionation.gen_tag_index, "");
@@ -4380,14 +4707,14 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I
static LLVMValueRef ir_render_container_init_list(CodeGen *g, IrExecutable *executable,
IrInstructionContainerInitList *instruction)
{
- TypeTableEntry *array_type = instruction->base.value.type;
- assert(array_type->id == TypeTableEntryIdArray);
+ ZigType *array_type = instruction->base.value.type;
+ assert(array_type->id == ZigTypeIdArray);
LLVMValueRef tmp_array_ptr = instruction->tmp_ptr;
assert(tmp_array_ptr);
size_t field_count = instruction->item_count;
- TypeTableEntry *child_type = array_type->data.array.child_type;
+ ZigType *child_type = array_type->data.array.child_type;
for (size_t i = 0; i < field_count; i += 1) {
LLVMValueRef elem_val = ir_llvm_value(g, instruction->items[i]);
LLVMValueRef indices[] = {
@@ -4511,13 +4838,13 @@ static LLVMValueRef ir_render_coro_promise(CodeGen *g, IrExecutable *executable,
return LLVMBuildBitCast(g->builder, uncasted_result, instruction->base.value.type->type_ref, "");
}
-static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_fn_type_ref, TypeTableEntry *fn_type) {
+static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_fn_type_ref, ZigType *fn_type) {
if (g->coro_alloc_helper_fn_val != nullptr)
return g->coro_alloc_helper_fn_val;
- assert(fn_type->id == TypeTableEntryIdFn);
+ assert(fn_type->id == ZigTypeIdFn);
- TypeTableEntry *ptr_to_err_code_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
+ ZigType *ptr_to_err_code_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
LLVMTypeRef alloc_raw_fn_type_ref = LLVMGetElementType(alloc_fn_type_ref);
LLVMTypeRef *alloc_fn_arg_types = allocate<LLVMTypeRef>(LLVMCountParamTypes(alloc_raw_fn_type_ref));
@@ -4545,7 +4872,7 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);
LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder);
- FnTableEntry *prev_cur_fn = g->cur_fn;
+ ZigFn *prev_cur_fn = g->cur_fn;
LLVMValueRef prev_cur_fn_val = g->cur_fn_val;
LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");
@@ -4596,9 +4923,9 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
LLVMPositionBuilderAtEnd(g->builder, ok_block);
LLVMValueRef payload_ptr = LLVMBuildStructGEP(g->builder, sret_ptr, err_union_payload_index, "");
- TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
+ ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *slice_type = get_slice_type(g, u8_ptr_type);
+ ZigType *slice_type = get_slice_type(g, u8_ptr_type);
size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, payload_ptr, ptr_field_index, "");
LLVMValueRef ptr_val = LLVMBuildLoad(g->builder, ptr_field_ptr, "");
@@ -4643,8 +4970,8 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
IrInstructionAtomicRmw *instruction)
{
bool is_signed;
- TypeTableEntry *operand_type = instruction->operand->value.type;
- if (operand_type->id == TypeTableEntryIdInt) {
+ ZigType *operand_type = instruction->operand->value.type;
+ if (operand_type->id == ZigTypeIdInt) {
is_signed = operand_type->data.integral.is_signed;
} else {
is_signed = false;
@@ -4699,7 +5026,7 @@ static LLVMValueRef ir_render_mark_err_ret_trace_ptr(CodeGen *g, IrExecutable *e
static LLVMValueRef ir_render_sqrt(CodeGen *g, IrExecutable *executable, IrInstructionSqrt *instruction) {
LLVMValueRef op = ir_llvm_value(g, instruction->op);
- assert(instruction->base.value.type->id == TypeTableEntryIdFloat);
+ assert(instruction->base.value.type->id == ZigTypeIdFloat);
LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdSqrt);
return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
}
@@ -4780,6 +5107,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
case IrInstructionIdFromBytes:
case IrInstructionIdToBytes:
case IrInstructionIdEnumToInt:
+ case IrInstructionIdCheckRuntimeScope:
zig_unreachable();
case IrInstructionIdReturn:
@@ -4946,7 +5274,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
zig_unreachable();
}
-static void ir_render(CodeGen *g, FnTableEntry *fn_entry) {
+static void ir_render(CodeGen *g, ZigFn *fn_entry) {
assert(fn_entry);
IrExecutable *executable = &fn_entry->analyzed_executable;
@@ -4999,14 +5327,14 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar
LLVMTypeKind el_type = LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(base_ptr)));
if (el_type == LLVMArrayTypeKind) {
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
LLVMValueRef indices[] = {
LLVMConstNull(usize->type_ref),
LLVMConstInt(usize->type_ref, index, false),
};
return LLVMConstInBoundsGEP(base_ptr, indices, 2);
} else if (el_type == LLVMStructTypeKind) {
- TypeTableEntry *u32 = g->builtin_types.entry_u32;
+ ZigType *u32 = g->builtin_types.entry_u32;
LLVMValueRef indices[] = {
LLVMConstNull(u32->type_ref),
LLVMConstInt(u32->type_ref, index, false),
@@ -5022,7 +5350,7 @@ static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *s
ConstParent *parent = &struct_const_val->data.x_struct.parent;
LLVMValueRef base_ptr = gen_parent_ptr(g, struct_const_val, parent);
- TypeTableEntry *u32 = g->builtin_types.entry_u32;
+ ZigType *u32 = g->builtin_types.entry_u32;
LLVMValueRef indices[] = {
LLVMConstNull(u32->type_ref),
LLVMConstInt(u32->type_ref, field_index, false),
@@ -5034,7 +5362,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un
ConstParent *parent = &union_const_val->data.x_union.parent;
LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent);
- TypeTableEntry *u32 = g->builtin_types.entry_u32;
+ ZigType *u32 = g->builtin_types.entry_u32;
LLVMValueRef indices[] = {
LLVMConstNull(u32->type_ref),
LLVMConstInt(u32->type_ref, 0, false), // TODO test const union with more aligned tag type than payload
@@ -5052,59 +5380,59 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
break;
}
- TypeTableEntry *type_entry = const_val->type;
+ ZigType *type_entry = const_val->type;
assert(!type_entry->zero_bits);
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdVoid:
+ case ZigTypeIdOpaque:
zig_unreachable();
- case TypeTableEntryIdBool:
+ case ZigTypeIdBool:
return LLVMConstInt(big_int_type_ref, const_val->data.x_bool ? 1 : 0, false);
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
{
assert(type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr);
LLVMValueRef int_val = gen_const_val(g, const_val, "");
return LLVMConstZExt(int_val, big_int_type_ref);
}
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
{
LLVMValueRef int_val = gen_const_val(g, const_val, "");
return LLVMConstZExt(int_val, big_int_type_ref);
}
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
{
LLVMValueRef float_val = gen_const_val(g, const_val, "");
LLVMValueRef int_val = LLVMConstFPToUI(float_val,
LLVMIntType((unsigned)type_entry->data.floating.bit_count));
return LLVMConstZExt(int_val, big_int_type_ref);
}
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdPointer:
+ case ZigTypeIdFn:
+ case ZigTypeIdOptional:
+ case ZigTypeIdPromise:
{
LLVMValueRef ptr_val = gen_const_val(g, const_val, "");
LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->type_ref);
return LLVMConstZExt(ptr_size_int_val, big_int_type_ref);
}
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
zig_panic("TODO bit pack an array");
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
zig_panic("TODO bit pack a union");
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
{
assert(type_entry->data.structure.layout == ContainerLayoutPacked);
bool is_big_endian = g->is_big_endian; // TODO get endianness from struct type
@@ -5137,7 +5465,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
// We have this because union constants can't be represented by the official union type,
// and this property bubbles up in whatever aggregate type contains a union constant
-static bool is_llvm_value_unnamed_type(TypeTableEntry *type_entry, LLVMValueRef val) {
+static bool is_llvm_value_unnamed_type(ZigType *type_entry, LLVMValueRef val) {
return LLVMTypeOf(val) != type_entry->type_ref;
}
@@ -5162,10 +5490,10 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
render_const_val_global(g, const_val, name);
ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;
- assert(array_const_val->type->id == TypeTableEntryIdArray);
+ assert(array_const_val->type->id == ZigTypeIdArray);
if (array_const_val->type->zero_bits) {
// make this a null pointer
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),
const_val->type->type_ref);
render_const_val_global(g, const_val, "");
@@ -5182,10 +5510,10 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
{
render_const_val_global(g, const_val, name);
ConstExprValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;
- assert(struct_const_val->type->id == TypeTableEntryIdStruct);
+ assert(struct_const_val->type->id == ZigTypeIdStruct);
if (struct_const_val->type->zero_bits) {
// make this a null pointer
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref),
const_val->type->type_ref);
render_const_val_global(g, const_val, "");
@@ -5205,7 +5533,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
{
render_const_val_global(g, const_val, name);
uint64_t addr_value = const_val->data.x_ptr.data.hard_coded_addr.addr;
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstInt(usize->type_ref, addr_value, false),
const_val->type->type_ref);
render_const_val_global(g, const_val, "");
@@ -5218,7 +5546,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
}
static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) {
- TypeTableEntry *type_entry = const_val->type;
+ ZigType *type_entry = const_val->type;
assert(!type_entry->zero_bits);
switch (const_val->special) {
@@ -5231,13 +5559,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
}
switch (type_entry->id) {
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_bigint);
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdErrorSet:
assert(const_val->data.x_err_set != nullptr);
return LLVMConstInt(g->builtin_types.entry_global_error_set->type_ref,
const_val->data.x_err_set->value, false);
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
switch (type_entry->data.floating.bit_count) {
case 16:
return LLVMConstReal(type_entry->type_ref, zig_f16_to_double(const_val->data.x_f16));
@@ -5257,15 +5585,15 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
default:
zig_unreachable();
}
- case TypeTableEntryIdBool:
+ case ZigTypeIdBool:
if (const_val->data.x_bool) {
return LLVMConstAllOnes(LLVMInt1Type());
} else {
return LLVMConstNull(LLVMInt1Type());
}
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
{
- TypeTableEntry *child_type = type_entry->data.maybe.child_type;
+ ZigType *child_type = type_entry->data.maybe.child_type;
if (child_type->zero_bits) {
return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false);
} else if (type_is_codegen_pointer(child_type)) {
@@ -5296,7 +5624,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
}
}
}
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
{
LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
size_t src_field_count = type_entry->data.structure.src_field_count;
@@ -5372,7 +5700,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
return LLVMConstNamedStruct(type_entry->type_ref, fields, type_entry->data.structure.gen_field_count);
}
}
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
{
uint64_t len = type_entry->data.array.len;
if (const_val->data.x_array.special == ConstArraySpecialUndef) {
@@ -5394,12 +5722,12 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
return LLVMConstArray(element_type_ref, values, (unsigned)len);
}
}
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
{
LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref;
if (type_entry->data.unionation.gen_field_count == 0) {
- if (type_entry->data.unionation.gen_tag_index == SIZE_MAX) {
+ if (type_entry->data.unionation.tag_type == nullptr) {
return nullptr;
} else {
return bigint_to_llvm_const(type_entry->data.unionation.tag_type->type_ref,
@@ -5458,18 +5786,18 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
}
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_enum_tag);
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry);
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
return gen_const_val_ptr(g, const_val, name);
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
{
- TypeTableEntry *payload_type = type_entry->data.error_union.payload_type;
- TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type;
+ ZigType *payload_type = type_entry->data.error_union.payload_type;
+ ZigType *err_set_type = type_entry->data.error_union.err_set_type;
if (!type_has_bits(payload_type)) {
assert(type_has_bits(err_set_type));
uint64_t value = const_val->data.x_err_union.err ? const_val->data.x_err_union.err->value : 0;
@@ -5502,21 +5830,21 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
}
}
}
- case TypeTableEntryIdVoid:
+ case ZigTypeIdVoid:
return nullptr;
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdPromise:
zig_unreachable();
}
@@ -5559,9 +5887,9 @@ static void generate_error_name_table(CodeGen *g) {
assert(g->errors_by_index.length > 0);
- TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
+ ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
+ ZigType *str_type = get_slice_type(g, u8_ptr_type);
LLVMValueRef *values = allocate<LLVMValueRef>(g->errors_by_index.length);
values[0] = LLVMGetUndef(str_type->type_ref);
@@ -5597,7 +5925,7 @@ static void generate_error_name_table(CodeGen *g) {
LLVMSetAlignment(g->err_name_table, LLVMABIAlignmentOfType(g->target_data_ref, LLVMTypeOf(err_name_table_init)));
}
-static void build_all_basic_blocks(CodeGen *g, FnTableEntry *fn) {
+static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
IrExecutable *executable = &fn->analyzed_executable;
assert(executable->basic_block_list.length > 0);
for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {
@@ -5608,8 +5936,8 @@ static void build_all_basic_blocks(CodeGen *g, FnTableEntry *fn) {
LLVMPositionBuilderAtEnd(g->builder, entry_bb->llvm_block);
}
-static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef init_val,
- TypeTableEntry *type_entry)
+static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val,
+ ZigType *type_entry)
{
if (g->strip_debug_symbols) {
return;
@@ -5630,33 +5958,16 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini
// TODO ^^ make an actual global variable
}
-static LLVMValueRef build_alloca(CodeGen *g, TypeTableEntry *type_entry, const char *name, uint32_t alignment) {
- assert(alignment > 0);
- LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name);
- LLVMSetAlignment(result, alignment);
- return result;
-}
-
static void ensure_cache_dir(CodeGen *g) {
int err;
- if ((err = os_make_path(g->cache_dir))) {
+ if ((err = os_make_path(&g->cache_dir))) {
zig_panic("unable to make cache dir: %s", err_str(err));
}
}
-static void report_errors_and_maybe_exit(CodeGen *g) {
- if (g->errors.length != 0) {
- for (size_t i = 0; i < g->errors.length; i += 1) {
- ErrorMsg *err = g->errors.at(i);
- print_err_msg(err, g->err_color);
- }
- exit(1);
- }
-}
-
static void validate_inline_fns(CodeGen *g) {
for (size_t i = 0; i < g->inline_fns.length; i += 1) {
- FnTableEntry *fn_entry = g->inline_fns.at(i);
+ ZigFn *fn_entry = g->inline_fns.at(i);
LLVMValueRef fn_val = LLVMGetNamedFunction(g->module, fn_entry->llvm_name);
if (fn_val != nullptr) {
add_node_error(g, fn_entry->proto_node, buf_sprintf("unable to inline function"));
@@ -5697,13 +6008,13 @@ static void do_code_gen(CodeGen *g) {
// Generate module level variables
for (size_t i = 0; i < g->global_vars.length; i += 1) {
TldVar *tld_var = g->global_vars.at(i);
- VariableTableEntry *var = tld_var->var;
+ ZigVar *var = tld_var->var;
- if (var->value->type->id == TypeTableEntryIdComptimeFloat) {
+ if (var->value->type->id == ZigTypeIdComptimeFloat) {
// Generate debug info for it but that's it.
ConstExprValue *const_val = var->value;
assert(const_val->special != ConstValSpecialRuntime);
- TypeTableEntry *var_type = g->builtin_types.entry_f128;
+ ZigType *var_type = g->builtin_types.entry_f128;
ConstExprValue coerced_value;
coerced_value.special = ConstValSpecialStatic;
coerced_value.type = var_type;
@@ -5713,7 +6024,7 @@ static void do_code_gen(CodeGen *g) {
continue;
}
- if (var->value->type->id == TypeTableEntryIdComptimeInt) {
+ if (var->value->type->id == ZigTypeIdComptimeInt) {
// Generate debug info for it but that's it.
ConstExprValue *const_val = var->value;
assert(const_val->special != ConstValSpecialRuntime);
@@ -5721,7 +6032,7 @@ static void do_code_gen(CodeGen *g) {
if (bits_needed < 8) {
bits_needed = 8;
}
- TypeTableEntry *var_type = get_int_type(g, const_val->data.x_bigint.is_negative, bits_needed);
+ ZigType *var_type = get_int_type(g, const_val->data.x_bigint.is_negative, bits_needed);
LLVMValueRef init_val = bigint_to_llvm_const(var_type->type_ref, &const_val->data.x_bigint);
gen_global_var(g, var, init_val, var_type);
continue;
@@ -5761,7 +6072,7 @@ static void do_code_gen(CodeGen *g) {
LLVMSetAlignment(global_value, var->align_bytes);
// TODO debug info for function pointers
- if (var->gen_is_const && var->value->type->id != TypeTableEntryIdFn) {
+ if (var->gen_is_const && var->value->type->id != ZigTypeIdFn) {
gen_global_var(g, var, var->value->global_refs->llvm_value, var->value->type);
}
@@ -5773,12 +6084,15 @@ static void do_code_gen(CodeGen *g) {
// Generate function definitions.
for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) {
- FnTableEntry *fn_table_entry = g->fn_defs.at(fn_i);
+ ZigFn *fn_table_entry = g->fn_defs.at(fn_i);
+ FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id;
+ CallingConvention cc = fn_type_id->cc;
+ bool is_c_abi = cc == CallingConventionC;
LLVMValueRef fn = fn_llvm_value(g, fn_table_entry);
g->cur_fn = fn_table_entry;
g->cur_fn_val = fn;
- TypeTableEntry *return_type = fn_table_entry->type_entry->data.fn.fn_type_id.return_type;
+ ZigType *return_type = fn_type_id->return_type;
if (handle_is_ptr(return_type)) {
g->cur_ret_ptr = LLVMGetParam(fn, 0);
} else {
@@ -5797,11 +6111,11 @@ static void do_code_gen(CodeGen *g) {
}
// error return tracing setup
- bool is_async = fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
+ bool is_async = cc == CallingConventionAsync;
bool have_err_ret_trace_stack = g->have_err_ret_tracing && fn_table_entry->calls_or_awaits_errorable_fn && !is_async && !have_err_ret_trace_arg;
LLVMValueRef err_ret_array_val = nullptr;
if (have_err_ret_trace_stack) {
- TypeTableEntry *array_type = get_array_type(g, g->builtin_types.entry_usize, stack_trace_ptr_count);
+ ZigType *array_type = get_array_type(g, g->builtin_types.entry_usize, stack_trace_ptr_count);
err_ret_array_val = build_alloca(g, array_type, "error_return_trace_addresses", get_abi_alignment(g, array_type));
g->cur_err_ret_trace_val_stack = build_alloca(g, g->stack_trace_type, "error_return_trace", get_abi_alignment(g, g->stack_trace_type));
} else {
@@ -5812,14 +6126,14 @@ static void do_code_gen(CodeGen *g) {
for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_list.length; alloca_i += 1) {
IrInstruction *instruction = fn_table_entry->alloca_list.at(alloca_i);
LLVMValueRef *slot;
- TypeTableEntry *slot_type = instruction->value.type;
+ ZigType *slot_type = instruction->value.type;
if (instruction->id == IrInstructionIdCast) {
IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction;
slot = &cast_instruction->tmp_ptr;
} else if (instruction->id == IrInstructionIdRef) {
IrInstructionRef *ref_instruction = (IrInstructionRef *)instruction;
slot = &ref_instruction->tmp_ptr;
- assert(instruction->value.type->id == TypeTableEntryIdPointer);
+ assert(instruction->value.type->id == ZigTypeIdPointer);
slot_type = instruction->value.type->data.pointer.child_type;
} else if (instruction->id == IrInstructionIdContainerInitList) {
IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction;
@@ -5856,9 +6170,17 @@ static void do_code_gen(CodeGen *g) {
ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base);
+ unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0;
+
// create debug variable declarations for variables and allocate all local variables
+ FnWalk fn_walk_var = {};
+ fn_walk_var.id = FnWalkIdVars;
+ fn_walk_var.data.vars.import = import;
+ fn_walk_var.data.vars.fn = fn_table_entry;
+ fn_walk_var.data.vars.llvm_fn = fn;
+ fn_walk_var.data.vars.gen_i = gen_i_init;
for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) {
- VariableTableEntry *var = fn_table_entry->variable_list.at(var_i);
+ ZigVar *var = fn_table_entry->variable_list.at(var_i);
if (!type_has_bits(var->value->type)) {
continue;
@@ -5875,9 +6197,12 @@ static void do_code_gen(CodeGen *g) {
buf_ptr(&var->name), import->di_file, (unsigned)(var->decl_node->line + 1),
var->value->type->di_type, !g->strip_debug_symbols, 0);
+ } else if (is_c_abi) {
+ fn_walk_var.data.vars.var = var;
+ iter_function_params_c_abi(g, fn_table_entry->type_entry, &fn_walk_var, var->src_arg_index);
} else {
assert(var->gen_arg_index != SIZE_MAX);
- TypeTableEntry *gen_type;
+ ZigType *gen_type;
FnGenParamInfo *gen_info = &fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index];
if (handle_is_ptr(var->value->type)) {
@@ -5903,7 +6228,7 @@ static void do_code_gen(CodeGen *g) {
// finishing error return trace setup. we have to do this after all the allocas.
if (have_err_ret_trace_stack) {
- TypeTableEntry *usize = g->builtin_types.entry_usize;
+ ZigType *usize = g->builtin_types.entry_usize;
size_t index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index;
LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)index_field_index, "");
gen_store_untyped(g, LLVMConstNull(usize->type_ref), index_field_ptr, 0, false);
@@ -5911,14 +6236,14 @@ static void do_code_gen(CodeGen *g) {
size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;
LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)addresses_field_index, "");
- TypeTableEntry *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
+ ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, "");
LLVMValueRef zero = LLVMConstNull(usize->type_ref);
LLVMValueRef indices[] = {zero, zero};
LLVMValueRef err_ret_array_val_elem0_ptr = LLVMBuildInBoundsGEP(g->builder, err_ret_array_val,
indices, 2, "");
- TypeTableEntry *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false);
+ ZigType *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false);
gen_store(g, err_ret_array_val_elem0_ptr, ptr_field_ptr, ptr_ptr_usize_type);
size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;
@@ -5926,33 +6251,14 @@ static void do_code_gen(CodeGen *g) {
gen_store(g, LLVMConstInt(usize->type_ref, stack_trace_ptr_count, false), len_field_ptr, get_pointer_to_type(g, usize, false));
}
- FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id;
-
// create debug variable declarations for parameters
// rely on the first variables in the variable_list being parameters.
- size_t next_var_i = 0;
- for (size_t param_i = 0; param_i < fn_type_id->param_count; param_i += 1) {
- FnGenParamInfo *info = &fn_table_entry->type_entry->data.fn.gen_param_info[param_i];
- if (info->gen_index == SIZE_MAX)
- continue;
-
- VariableTableEntry *variable = fn_table_entry->variable_list.at(next_var_i);
- assert(variable->src_arg_index != SIZE_MAX);
- next_var_i += 1;
-
- assert(variable);
- assert(variable->value_ref);
-
- if (!handle_is_ptr(variable->value->type)) {
- clear_debug_source_node(g);
- gen_store_untyped(g, LLVMGetParam(fn, (unsigned)variable->gen_arg_index), variable->value_ref,
- variable->align_bytes, false);
- }
-
- if (variable->decl_node) {
- gen_var_debug_decl(g, variable);
- }
- }
+ FnWalk fn_walk_init = {};
+ fn_walk_init.id = FnWalkIdInits;
+ fn_walk_init.data.inits.fn = fn_table_entry;
+ fn_walk_init.data.inits.llvm_fn = fn;
+ fn_walk_init.data.inits.gen_i = gen_i_init;
+ walk_function_params(g, fn_table_entry->type_entry, &fn_walk_init);
ir_render(g, fn_table_entry);
@@ -6007,7 +6313,7 @@ static void do_code_gen(CodeGen *g) {
}
Buf *output_path = buf_alloc();
- os_path_join(g->cache_dir, o_basename, output_path);
+ os_path_join(&g->cache_dir, o_basename, output_path);
ensure_cache_dir(g);
bool is_small = g->build_mode == BuildModeSmallRelease;
@@ -6030,6 +6336,7 @@ static void do_code_gen(CodeGen *g) {
zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg);
}
validate_inline_fns(g);
+ g->link_objects.append(output_path);
break;
case EmitFileTypeLLVMIr:
@@ -6039,6 +6346,7 @@ static void do_code_gen(CodeGen *g) {
zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg);
}
validate_inline_fns(g);
+ g->link_objects.append(output_path);
break;
default:
@@ -6080,51 +6388,51 @@ static const GlobalLinkageValue global_linkage_values[] = {
static void define_builtin_types(CodeGen *g) {
{
// if this type is anywhere in the AST, we should never hit codegen.
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInvalid);
+ ZigType *entry = new_type_table_entry(ZigTypeIdInvalid);
buf_init_from_str(&entry->name, "(invalid)");
entry->zero_bits = true;
g->builtin_types.entry_invalid = entry;
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNamespace);
+ ZigType *entry = new_type_table_entry(ZigTypeIdNamespace);
buf_init_from_str(&entry->name, "(namespace)");
entry->zero_bits = true;
g->builtin_types.entry_namespace = entry;
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdBlock);
+ ZigType *entry = new_type_table_entry(ZigTypeIdBlock);
buf_init_from_str(&entry->name, "(block)");
entry->zero_bits = true;
g->builtin_types.entry_block = entry;
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdComptimeFloat);
+ ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat);
buf_init_from_str(&entry->name, "comptime_float");
entry->zero_bits = true;
g->builtin_types.entry_num_lit_float = entry;
g->primitive_type_table.put(&entry->name, entry);
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdComptimeInt);
+ ZigType *entry = new_type_table_entry(ZigTypeIdComptimeInt);
buf_init_from_str(&entry->name, "comptime_int");
entry->zero_bits = true;
g->builtin_types.entry_num_lit_int = entry;
g->primitive_type_table.put(&entry->name, entry);
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUndefined);
+ ZigType *entry = new_type_table_entry(ZigTypeIdUndefined);
buf_init_from_str(&entry->name, "(undefined)");
entry->zero_bits = true;
g->builtin_types.entry_undef = entry;
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNull);
+ ZigType *entry = new_type_table_entry(ZigTypeIdNull);
buf_init_from_str(&entry->name, "(null)");
entry->zero_bits = true;
g->builtin_types.entry_null = entry;
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArgTuple);
+ ZigType *entry = new_type_table_entry(ZigTypeIdArgTuple);
buf_init_from_str(&entry->name, "(args)");
entry->zero_bits = true;
g->builtin_types.entry_arg_tuple = entry;
@@ -6135,7 +6443,7 @@ static void define_builtin_types(CodeGen *g) {
uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id);
bool is_signed = info->is_signed;
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
+ ZigType *entry = new_type_table_entry(ZigTypeIdInt);
entry->type_ref = LLVMIntType(size_in_bits);
buf_init_from_str(&entry->name, info->name);
@@ -6152,7 +6460,7 @@ static void define_builtin_types(CodeGen *g) {
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdBool);
+ ZigType *entry = new_type_table_entry(ZigTypeIdBool);
entry->type_ref = LLVMInt1Type();
buf_init_from_str(&entry->name, "bool");
uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref);
@@ -6166,7 +6474,7 @@ static void define_builtin_types(CodeGen *g) {
for (size_t sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) {
bool is_signed = is_signed_list[sign_i];
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt);
+ ZigType *entry = new_type_table_entry(ZigTypeIdInt);
entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8);
const char u_or_i = is_signed ? 'i' : 'u';
@@ -6193,8 +6501,8 @@ static void define_builtin_types(CodeGen *g) {
const char *name,
uint32_t bit_count,
LLVMTypeRef type_ref,
- TypeTableEntry **field) {
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdFloat);
+ ZigType **field) {
+ ZigType *entry = new_type_table_entry(ZigTypeIdFloat);
entry->type_ref = type_ref;
buf_init_from_str(&entry->name, name);
entry->data.floating.bit_count = bit_count;
@@ -6213,7 +6521,7 @@ static void define_builtin_types(CodeGen *g) {
add_fp_entry(g, "c_longdouble", 80, LLVMX86FP80Type(), &g->builtin_types.entry_c_longdouble);
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdVoid);
+ ZigType *entry = new_type_table_entry(ZigTypeIdVoid);
entry->type_ref = LLVMVoidType();
entry->zero_bits = true;
buf_init_from_str(&entry->name, "void");
@@ -6224,7 +6532,7 @@ static void define_builtin_types(CodeGen *g) {
g->primitive_type_table.put(&entry->name, entry);
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUnreachable);
+ ZigType *entry = new_type_table_entry(ZigTypeIdUnreachable);
entry->type_ref = LLVMVoidType();
entry->zero_bits = true;
buf_init_from_str(&entry->name, "noreturn");
@@ -6233,7 +6541,7 @@ static void define_builtin_types(CodeGen *g) {
g->primitive_type_table.put(&entry->name, entry);
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdMetaType);
+ ZigType *entry = new_type_table_entry(ZigTypeIdMetaType);
buf_init_from_str(&entry->name, "type");
entry->zero_bits = true;
g->builtin_types.entry_type = entry;
@@ -6255,7 +6563,7 @@ static void define_builtin_types(CodeGen *g) {
}
{
- TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorSet);
+ ZigType *entry = new_type_table_entry(ZigTypeIdErrorSet);
buf_init_from_str(&entry->name, "error");
entry->data.error_set.err_count = UINT32_MAX;
@@ -6277,7 +6585,7 @@ static void define_builtin_types(CodeGen *g) {
g->primitive_type_table.put(&entry->name, entry);
}
{
- TypeTableEntry *entry = get_promise_type(g, nullptr);
+ ZigType *entry = get_promise_type(g, nullptr);
g->primitive_type_table.put(&entry->name, entry);
}
@@ -6530,7 +6838,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
buf_appendf(contents, "pub const TypeId = enum {\n");
size_t field_count = type_id_len();
for (size_t i = 0; i < field_count; i += 1) {
- const TypeTableEntryId id = type_id_at_index(i);
+ const ZigTypeId id = type_id_at_index(i);
buf_appendf(contents, " %s,\n", type_id_name(id));
}
buf_appendf(contents, "};\n\n");
@@ -6769,25 +7077,22 @@ static void define_builtin_compile_vars(CodeGen *g) {
const char *builtin_zig_basename = "builtin.zig";
Buf *builtin_zig_path = buf_alloc();
- os_path_join(g->cache_dir, buf_create_from_str(builtin_zig_basename), builtin_zig_path);
+ os_path_join(&g->cache_dir, buf_create_from_str(builtin_zig_basename), builtin_zig_path);
Buf *contents = codegen_generate_builtin_source(g);
ensure_cache_dir(g);
os_write_file(builtin_zig_path, contents);
- int err;
- Buf *abs_full_path = buf_alloc();
- if ((err = os_path_real(builtin_zig_path, abs_full_path))) {
- fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(builtin_zig_path), err_str(err));
- exit(1);
- }
+ Buf *resolved_path = buf_alloc();
+ Buf *resolve_paths[] = {builtin_zig_path};
+ *resolved_path = os_path_resolve(resolve_paths, 1);
assert(g->root_package);
assert(g->std_package);
- g->compile_var_package = new_package(buf_ptr(g->cache_dir), builtin_zig_basename);
+ g->compile_var_package = new_package(buf_ptr(&g->cache_dir), builtin_zig_basename);
g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
- g->compile_var_import = add_source_file(g, g->compile_var_package, abs_full_path, contents);
+ g->compile_var_import = add_source_file(g, g->compile_var_package, resolved_path, contents);
scan_import(g, g->compile_var_import);
}
@@ -6943,17 +7248,17 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package
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);
- Buf *abs_full_path = buf_alloc();
- int err;
- if ((err = os_path_real(&path_to_code_src, abs_full_path))) {
- zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err));
- }
+
+ Buf *resolve_paths[] = {&path_to_code_src};
+ Buf *resolved_path = buf_alloc();
+ *resolved_path = os_path_resolve(resolve_paths, 1);
Buf *import_code = buf_alloc();
- if ((err = os_fetch_file_path(abs_full_path, import_code, false))) {
+ int err;
+ if ((err = os_fetch_file_path(resolved_path, import_code, false))) {
zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err));
}
- return add_source_file(g, package, abs_full_path, import_code);
+ return add_source_file(g, package, resolved_path, import_code);
}
static PackageTableEntry *create_bootstrap_pkg(CodeGen *g, PackageTableEntry *pkg_with_main) {
@@ -6978,14 +7283,14 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
exit(0);
}
- TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
+ ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type);
- TypeTableEntry *fn_type = get_test_fn_type(g);
+ ZigType *str_type = get_slice_type(g, u8_ptr_type);
+ ZigType *fn_type = get_test_fn_type(g);
const char *field_names[] = { "name", "func", };
- TypeTableEntry *field_types[] = { str_type, fn_type, };
- TypeTableEntry *struct_type = get_struct_type(g, "ZigTestFn", field_names, field_types, 2);
+ ZigType *field_types[] = { str_type, fn_type, };
+ ZigType *struct_type = get_struct_type(g, "ZigTestFn", field_names, field_types, 2);
ConstExprValue *test_fn_array = create_const_vals(1);
test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length);
@@ -6993,7 +7298,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
test_fn_array->data.x_array.s_none.elements = create_const_vals(g->test_fns.length);
for (size_t i = 0; i < g->test_fns.length; i += 1) {
- FnTableEntry *test_fn_entry = g->test_fns.at(i);
+ ZigFn *test_fn_entry = g->test_fns.at(i);
ConstExprValue *this_val = &test_fn_array->data.x_array.s_none.elements[i];
this_val->special = ConstValSpecialStatic;
@@ -7031,20 +7336,18 @@ static void gen_root_source(CodeGen *g) {
Buf *rel_full_path = buf_alloc();
os_path_join(&g->root_package->root_src_dir, &g->root_package->root_src_path, rel_full_path);
- Buf *abs_full_path = buf_alloc();
- int err;
- if ((err = os_path_real(rel_full_path, abs_full_path))) {
- fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(rel_full_path), err_str(err));
- exit(1);
- }
+ Buf *resolved_path = buf_alloc();
+ Buf *resolve_paths[] = {rel_full_path};
+ *resolved_path = os_path_resolve(resolve_paths, 1);
Buf *source_code = buf_alloc();
+ int err;
if ((err = os_fetch_file_path(rel_full_path, source_code, true))) {
fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(rel_full_path), err_str(err));
exit(1);
}
- g->root_import = add_source_file(g, g->root_package, abs_full_path, source_code);
+ g->root_import = add_source_file(g, g->root_package, resolved_path, source_code);
assert(g->root_out_name);
assert(g->out_type != OutTypeUnknown);
@@ -7129,66 +7432,66 @@ static const char *c_int_type_names[] = {
};
struct GenH {
- ZigList<TypeTableEntry *> types_to_declare;
+ ZigList<ZigType *> types_to_declare;
};
-static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry) {
+static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_entry) {
if (type_entry->gen_h_loop_flag)
return;
type_entry->gen_h_loop_flag = true;
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdPromise:
zig_unreachable();
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
+ case ZigTypeIdVoid:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
return;
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdOpaque:
gen_h->types_to_declare.append(type_entry);
return;
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
TypeStructField *field = &type_entry->data.structure.fields[i];
prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
}
gen_h->types_to_declare.append(type_entry);
return;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {
TypeUnionField *field = &type_entry->data.unionation.fields[i];
prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
}
gen_h->types_to_declare.append(type_entry);
return;
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
prepend_c_type_to_decl_list(g, gen_h, type_entry->data.enumeration.tag_int_type);
gen_h->types_to_declare.append(type_entry);
return;
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
prepend_c_type_to_decl_list(g, gen_h, type_entry->data.pointer.child_type);
return;
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);
return;
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);
return;
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
for (size_t i = 0; i < type_entry->data.fn.fn_type_id.param_count; i += 1) {
prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.param_info[i].type);
}
@@ -7197,7 +7500,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry
}
}
-static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf *out_buf) {
+static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_buf) {
assert(type_entry);
for (size_t i = 0; i < array_length(c_int_type_names); i += 1) {
@@ -7228,17 +7531,17 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
prepend_c_type_to_decl_list(g, gen_h, type_entry);
switch (type_entry->id) {
- case TypeTableEntryIdVoid:
+ case ZigTypeIdVoid:
buf_init_from_str(out_buf, "void");
break;
- case TypeTableEntryIdBool:
+ case ZigTypeIdBool:
buf_init_from_str(out_buf, "bool");
g->c_want_stdbool = true;
break;
- case TypeTableEntryIdUnreachable:
+ case ZigTypeIdUnreachable:
buf_init_from_str(out_buf, "__attribute__((__noreturn__)) void");
break;
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
switch (type_entry->data.floating.bit_count) {
case 32:
buf_init_from_str(out_buf, "float");
@@ -7256,17 +7559,17 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
zig_unreachable();
}
break;
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
g->c_want_stdint = true;
buf_resize(out_buf, 0);
buf_appendf(out_buf, "%sint%" PRIu32 "_t",
type_entry->data.integral.is_signed ? "" : "u",
type_entry->data.integral.bit_count);
break;
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
{
Buf child_buf = BUF_INIT;
- TypeTableEntry *child_type = type_entry->data.pointer.child_type;
+ ZigType *child_type = type_entry->data.pointer.child_type;
get_c_type(g, gen_h, child_type, &child_buf);
const char *const_str = type_entry->data.pointer.is_const ? "const " : "";
@@ -7274,9 +7577,9 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf));
break;
}
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
{
- TypeTableEntry *child_type = type_entry->data.maybe.child_type;
+ ZigType *child_type = type_entry->data.maybe.child_type;
if (child_type->zero_bits) {
buf_init_from_str(out_buf, "bool");
return;
@@ -7286,28 +7589,28 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
zig_unreachable();
}
}
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdStruct:
+ case ZigTypeIdOpaque:
{
buf_init_from_str(out_buf, "struct ");
buf_append_buf(out_buf, &type_entry->name);
return;
}
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
{
buf_init_from_str(out_buf, "union ");
buf_append_buf(out_buf, &type_entry->name);
return;
}
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
{
buf_init_from_str(out_buf, "enum ");
buf_append_buf(out_buf, &type_entry->name);
return;
}
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
{
- TypeTableEntryArray *array_data = &type_entry->data.array;
+ ZigTypeArray *array_data = &type_entry->data.array;
Buf *child_buf = buf_alloc();
get_c_type(g, gen_h, array_data->child_type, child_buf);
@@ -7316,21 +7619,21 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
buf_appendf(out_buf, "%s", buf_ptr(child_buf));
return;
}
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdFn:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdFn:
zig_panic("TODO implement get_c_type for more types");
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdPromise:
zig_unreachable();
}
}
@@ -7395,7 +7698,7 @@ static void gen_h_file(CodeGen *g) {
Buf h_buf = BUF_INIT;
buf_resize(&h_buf, 0);
for (size_t fn_def_i = 0; fn_def_i < g->fn_defs.length; fn_def_i += 1) {
- FnTableEntry *fn_table_entry = g->fn_defs.at(fn_def_i);
+ ZigFn *fn_table_entry = g->fn_defs.at(fn_def_i);
if (fn_table_entry->export_list.length == 0)
continue;
@@ -7421,7 +7724,7 @@ static void gen_h_file(CodeGen *g) {
const char *restrict_str = param_info->is_noalias ? "restrict" : "";
get_c_type(g, gen_h, param_info->type, ¶m_type_c);
- if (param_info->type->id == TypeTableEntryIdArray) {
+ if (param_info->type->id == ZigTypeIdArray) {
// Arrays decay to pointers
buf_appendf(&h_buf, "%s%s%s %s[]", comma_str, buf_ptr(¶m_type_c),
restrict_str, buf_ptr(param_name));
@@ -7467,32 +7770,32 @@ static void gen_h_file(CodeGen *g) {
fprintf(out_h, "\n");
for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) {
- TypeTableEntry *type_entry = gen_h->types_to_declare.at(type_i);
+ ZigType *type_entry = gen_h->types_to_declare.at(type_i);
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdArray:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOptional:
+ case ZigTypeIdFn:
+ case ZigTypeIdPromise:
zig_unreachable();
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {
fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name));
for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {
@@ -7510,7 +7813,7 @@ static void gen_h_file(CodeGen *g) {
fprintf(out_h, "enum %s;\n", buf_ptr(&type_entry->name));
}
break;
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
if (type_entry->data.structure.layout == ContainerLayoutExtern) {
fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name));
for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {
@@ -7519,7 +7822,7 @@ static void gen_h_file(CodeGen *g) {
Buf *type_name_buf = buf_alloc();
get_c_type(g, gen_h, struct_field->type_entry, type_name_buf);
- if (struct_field->type_entry->id == TypeTableEntryIdArray) {
+ if (struct_field->type_entry->id == ZigTypeIdArray) {
fprintf(out_h, " %s %s[%" ZIG_PRI_u64 "];\n", buf_ptr(type_name_buf),
buf_ptr(struct_field->name),
struct_field->type_entry->data.array.len);
@@ -7533,7 +7836,7 @@ static void gen_h_file(CodeGen *g) {
fprintf(out_h, "struct %s;\n", buf_ptr(&type_entry->name));
}
break;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
if (type_entry->data.unionation.layout == ContainerLayoutExtern) {
fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name));
for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {
@@ -7548,7 +7851,7 @@ static void gen_h_file(CodeGen *g) {
fprintf(out_h, "union %s;\n", buf_ptr(&type_entry->name));
}
break;
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdOpaque:
fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name));
break;
}
diff --git a/src/codegen.hpp b/src/codegen.hpp
@@ -47,7 +47,7 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script);
void codegen_set_test_filter(CodeGen *g, Buf *filter);
void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix);
void codegen_set_lib_version(CodeGen *g, size_t major, size_t minor, size_t patch);
-void codegen_set_cache_dir(CodeGen *g, Buf *cache_dir);
+void codegen_set_cache_dir(CodeGen *g, Buf cache_dir);
void codegen_set_output_h_path(CodeGen *g, Buf *h_path);
void codegen_add_time_event(CodeGen *g, const char *name);
void codegen_print_timing_report(CodeGen *g, FILE *f);
@@ -61,5 +61,4 @@ void codegen_translate_c(CodeGen *g, Buf *path);
Buf *codegen_generate_builtin_source(CodeGen *g);
-
#endif
diff --git a/src/ir.cpp b/src/ir.cpp
@@ -33,7 +33,7 @@ struct IrAnalyze {
IrExecContext exec_context;
size_t old_bb_index;
size_t instruction_index;
- TypeTableEntry *explicit_return_type;
+ ZigType *explicit_return_type;
ZigList<IrInstruction *> src_implicit_return_type_list;
IrBasicBlock *const_predecessor_bb;
};
@@ -99,38 +99,38 @@ struct ConstCastOnly {
};
struct ConstCastTypeMismatch {
- TypeTableEntry *wanted_type;
- TypeTableEntry *actual_type;
+ ZigType *wanted_type;
+ ZigType *actual_type;
};
struct ConstCastOptionalMismatch {
ConstCastOnly child;
- TypeTableEntry *wanted_child;
- TypeTableEntry *actual_child;
+ ZigType *wanted_child;
+ ZigType *actual_child;
};
struct ConstCastPointerMismatch {
ConstCastOnly child;
- TypeTableEntry *wanted_child;
- TypeTableEntry *actual_child;
+ ZigType *wanted_child;
+ ZigType *actual_child;
};
struct ConstCastSliceMismatch {
ConstCastOnly child;
- TypeTableEntry *wanted_child;
- TypeTableEntry *actual_child;
+ ZigType *wanted_child;
+ ZigType *actual_child;
};
struct ConstCastErrUnionErrSetMismatch {
ConstCastOnly child;
- TypeTableEntry *wanted_err_set;
- TypeTableEntry *actual_err_set;
+ ZigType *wanted_err_set;
+ ZigType *actual_err_set;
};
struct ConstCastErrUnionPayloadMismatch {
ConstCastOnly child;
- TypeTableEntry *wanted_payload;
- TypeTableEntry *actual_payload;
+ ZigType *wanted_payload;
+ ZigType *actual_payload;
};
struct ConstCastErrSetMismatch {
@@ -139,19 +139,21 @@ struct ConstCastErrSetMismatch {
static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval);
-static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
-static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type);
+static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction);
+static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type);
static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr);
static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);
static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
- IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type);
-static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var);
-static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
+ IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);
+static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var);
+static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);
static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);
-static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align);
-static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type, uint32_t new_align);
+static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
+static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);
+static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val);
+static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val);
-ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
+static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) {
assert(get_codegen_ptr_type(const_val->type) != nullptr);
assert(const_val->special == ConstValSpecialStatic);
ConstExprValue *result;
@@ -181,6 +183,27 @@ ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
return result;
}
+static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
+ if (a == b)
+ return true;
+
+ if (a->id == b->id)
+ return true;
+
+ if (get_codegen_ptr_type(a) != nullptr && get_codegen_ptr_type(b) != nullptr)
+ return true;
+
+ return false;
+}
+
+ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) {
+ ConstExprValue *result = const_ptr_pointee_unchecked(g, const_val);
+ if (const_val->type->id == ZigTypeIdPointer) {
+ assert(types_have_same_zig_comptime_repr(const_val->type->data.pointer.child_type, result->type));
+ }
+ return result;
+}
+
static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
if (exec->is_inline)
return true;
@@ -213,7 +236,7 @@ static size_t exec_next_mem_slot(IrExecutable *exec) {
return result;
}
-static FnTableEntry *exec_fn_entry(IrExecutable *exec) {
+static ZigFn *exec_fn_entry(IrExecutable *exec) {
return exec->fn_entry;
}
@@ -230,7 +253,7 @@ static bool instr_is_comptime(IrInstruction *instruction) {
}
static bool instr_is_unreachable(IrInstruction *instruction) {
- return instruction->value.type && instruction->value.type->id == TypeTableEntryIdUnreachable;
+ return instruction->value.type && instruction->value.type->id == ZigTypeIdUnreachable;
}
static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) {
@@ -254,7 +277,7 @@ static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb)
ir_ref_bb(instruction->owner_bb);
}
-static void ir_ref_var(VariableTableEntry *var) {
+static void ir_ref_var(ZigVar *var) {
var->ref_count += 1;
}
@@ -832,6 +855,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSqrt *) {
return IrInstructionIdSqrt;
}
+static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) {
+ return IrInstructionIdCheckRuntimeScope;
+}
+
template<typename T>
static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {
T *special_instruction = allocate<T>(1);
@@ -851,7 +878,7 @@ static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_nod
return special_instruction;
}
-static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, TypeTableEntry *dest_type,
+static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *dest_type,
IrInstruction *value, CastOp cast_op)
{
IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node);
@@ -904,7 +931,7 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou
}
static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node,
- TypeTableEntry *type_entry)
+ ZigType *type_entry)
{
assert(type_entry);
IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
@@ -975,7 +1002,7 @@ static IrInstruction *ir_build_const_u8(IrBuilder *irb, Scope *scope, AstNode *s
}
static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
- TypeTableEntry *type_entry)
+ ZigType *type_entry)
{
IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
const_instruction->base.value.type = irb->codegen->builtin_types.entry_type;
@@ -985,14 +1012,14 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode
}
static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
- TypeTableEntry *type_entry)
+ ZigType *type_entry)
{
IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry);
ir_instruction_append(irb->current_basic_block, instruction);
return instruction;
}
-static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) {
+static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);
const_instruction->base.value.type = fn_entry->type_entry;
const_instruction->base.value.special = ConstValSpecialStatic;
@@ -1002,7 +1029,7 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *
return &const_instruction->base;
}
-static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) {
+static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {
IrInstruction *instruction = ir_create_const_fn(irb, scope, source_node, fn_entry);
ir_instruction_append(irb->current_basic_block, instruction);
return instruction;
@@ -1035,7 +1062,7 @@ static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode
}
static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node,
- FnTableEntry *fn_entry, IrInstruction *first_arg)
+ ZigFn *fn_entry, IrInstruction *first_arg)
{
IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry);
@@ -1087,15 +1114,22 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in
return new_instruction;
}
-static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) {
+static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,
+ ScopeFnDef *crossed_fndef_scope)
+{
IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);
instruction->var = var;
+ instruction->crossed_fndef_scope = crossed_fndef_scope;
ir_ref_var(var);
return &instruction->base;
}
+static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var) {
+ return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);
+}
+
static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *array_ptr,
IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len)
{
@@ -1172,7 +1206,7 @@ static IrInstruction *ir_build_union_field_ptr_from(IrBuilder *irb, IrInstructio
}
static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node,
- FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
+ ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,
IrInstruction *new_stack)
{
@@ -1200,7 +1234,7 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc
}
static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction,
- FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
+ ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,
IrInstruction *new_stack)
{
@@ -1349,7 +1383,7 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop
}
static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode *source_node,
- TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields)
+ ZigType *struct_type, size_t field_count, IrInstructionStructInitField *fields)
{
IrInstructionStructInit *struct_init_instruction = ir_build_instruction<IrInstructionStructInit>(irb, scope, source_node);
struct_init_instruction->struct_type = struct_type;
@@ -1363,7 +1397,7 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode
}
static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *old_instruction,
- TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields)
+ ZigType *struct_type, size_t field_count, IrInstructionStructInitField *fields)
{
IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->scope,
old_instruction->source_node, struct_type, field_count, fields);
@@ -1372,7 +1406,7 @@ static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *o
}
static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node,
- TypeTableEntry *union_type, TypeUnionField *field, IrInstruction *init_value)
+ ZigType *union_type, TypeUnionField *field, IrInstruction *init_value)
{
IrInstructionUnionInit *union_init_instruction = ir_build_instruction<IrInstructionUnionInit>(irb, scope, source_node);
union_init_instruction->union_type = union_type;
@@ -1385,7 +1419,7 @@ static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode
}
static IrInstruction *ir_build_union_init_from(IrBuilder *irb, IrInstruction *old_instruction,
- TypeTableEntry *union_type, TypeUnionField *field, IrInstruction *init_value)
+ ZigType *union_type, TypeUnionField *field, IrInstruction *init_value)
{
IrInstruction *new_instruction = ir_build_union_init(irb, old_instruction->scope,
old_instruction->source_node, union_type, field, init_value);
@@ -1432,7 +1466,7 @@ static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old
}
static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *source_node,
- VariableTableEntry *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)
+ ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)
{
IrInstructionDeclVar *decl_var_instruction = ir_build_instruction<IrInstructionDeclVar>(irb, scope, source_node);
decl_var_instruction->base.value.special = ConstValSpecialStatic;
@@ -1450,7 +1484,7 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s
}
static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction,
- VariableTableEntry *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)
+ ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value)
{
IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope,
old_instruction->source_node, var, var_type, align_value, init_value);
@@ -1595,7 +1629,7 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode
}
static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction **input_list,
- IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects)
+ IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects)
{
IrInstructionAsm *instruction = ir_build_instruction<IrInstructionAsm>(irb, scope, source_node);
instruction->input_list = input_list;
@@ -1619,7 +1653,7 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source
}
static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list,
- IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects)
+ IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects)
{
IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope,
old_instruction->source_node, input_list, output_types, output_vars, return_count, has_side_effects);
@@ -1946,7 +1980,7 @@ static IrInstruction *ir_build_cmpxchg(IrBuilder *irb, Scope *scope, AstNode *so
IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,
IrInstruction *success_order_value, IrInstruction *failure_order_value,
bool is_weak,
- TypeTableEntry *type, AtomicOrder success_order, AtomicOrder failure_order)
+ ZigType *type, AtomicOrder success_order, AtomicOrder failure_order)
{
IrInstructionCmpxchg *instruction = ir_build_instruction<IrInstructionCmpxchg>(irb, scope, source_node);
instruction->type_value = type_value;
@@ -2259,7 +2293,7 @@ static IrInstruction *ir_build_handle_from(IrBuilder *irb, IrInstruction *old_in
static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node,
IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2,
- IrInstruction *result_ptr, TypeTableEntry *result_ptr_type)
+ IrInstruction *result_ptr, ZigType *result_ptr_type)
{
IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node);
instruction->op = op;
@@ -2279,7 +2313,7 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode
static IrInstruction *ir_build_overflow_op_from(IrBuilder *irb, IrInstruction *old_instruction,
IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2,
- IrInstruction *result_ptr, TypeTableEntry *result_ptr_type)
+ IrInstruction *result_ptr, ZigType *result_ptr_type)
{
IrInstruction *new_instruction = ir_build_overflow_op(irb, old_instruction->scope, old_instruction->source_node,
op, type_value, op1, op2, result_ptr, result_ptr_type);
@@ -2974,6 +3008,17 @@ static IrInstruction *ir_build_sqrt(IrBuilder *irb, Scope *scope, AstNode *sourc
return &instruction->base;
}
+static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *scope_is_comptime, IrInstruction *is_comptime) {
+ IrInstructionCheckRuntimeScope *instruction = ir_build_instruction<IrInstructionCheckRuntimeScope>(irb, scope, source_node);
+ instruction->scope_is_comptime = scope_is_comptime;
+ instruction->is_comptime = is_comptime;
+
+ ir_ref_instruction(scope_is_comptime, irb->current_basic_block);
+ ir_ref_instruction(is_comptime, irb->current_basic_block);
+
+ return &instruction->base;
+}
+
static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
results[ReturnKindUnconditional] = 0;
results[ReturnKindError] = 0;
@@ -2999,6 +3044,7 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco
case ScopeIdLoop:
case ScopeIdSuspend:
case ScopeIdCompTime:
+ case ScopeIdRuntime:
scope = scope->parent;
continue;
case ScopeIdDeferExpr:
@@ -3033,7 +3079,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
if (defer_expr_value != irb->codegen->invalid_instruction) {
- if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == TypeTableEntryIdUnreachable) {
+ if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == ZigTypeIdUnreachable) {
is_noreturn = true;
} else {
ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value));
@@ -3051,6 +3097,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
case ScopeIdLoop:
case ScopeIdSuspend:
case ScopeIdCompTime:
+ case ScopeIdRuntime:
scope = scope->parent;
continue;
case ScopeIdDeferExpr:
@@ -3098,7 +3145,7 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {
}
static bool exec_is_async(IrExecutable *exec) {
- FnTableEntry *fn_entry = exec_fn_entry(exec);
+ ZigFn *fn_entry = exec_fn_entry(exec);
return fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
}
@@ -3160,7 +3207,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode
static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) {
assert(node->type == NodeTypeReturnExpr);
- FnTableEntry *fn_entry = exec_fn_entry(irb->exec);
+ ZigFn *fn_entry = exec_fn_entry(irb->exec);
if (!fn_entry) {
add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition"));
return irb->codegen->invalid_instruction;
@@ -3184,7 +3231,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
IrInstruction *return_value;
if (expr_node) {
// Temporarily set this so that if we return a type it gets the name of the function
- FnTableEntry *prev_name_fn = irb->exec->name_fn;
+ ZigFn *prev_name_fn = irb->exec->name_fn;
irb->exec->name_fn = exec_fn_entry(irb->exec);
return_value = ir_gen_node(irb, expr_node, scope);
irb->exec->name_fn = prev_name_fn;
@@ -3280,11 +3327,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
zig_unreachable();
}
-static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
+static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime,
bool skip_name_check)
{
- VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1);
+ ZigVar *variable_entry = allocate<ZigVar>(1);
variable_entry->parent_scope = parent_scope;
variable_entry->shadowable = is_shadowable;
variable_entry->mem_slot_index = SIZE_MAX;
@@ -3296,14 +3343,14 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
buf_init_from_buf(&variable_entry->name, name);
if (!skip_name_check) {
- VariableTableEntry *existing_var = find_variable(codegen, parent_scope, name);
+ ZigVar *existing_var = find_variable(codegen, parent_scope, name, nullptr);
if (existing_var && !existing_var->shadowable) {
ErrorMsg *msg = add_node_error(codegen, node,
buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here"));
variable_entry->value->type = codegen->builtin_types.entry_invalid;
} else {
- TypeTableEntry *type = get_primitive_type(codegen, name);
+ ZigType *type = get_primitive_type(codegen, name);
if (type != nullptr) {
add_node_error(codegen, node,
buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
@@ -3337,11 +3384,11 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
// Set name to nullptr to make the variable anonymous (not visible to programmer).
// After you call this function var->child_scope has the variable in scope
-static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name,
+static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name,
bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime)
{
bool is_underscored = name ? buf_eql_str(name, "_") : false;
- VariableTableEntry *var = create_local_var(irb->codegen, node, scope,
+ ZigVar *var = create_local_var(irb->codegen, node, scope,
(is_underscored ? nullptr : name), src_is_const, gen_is_const,
(is_underscored ? true : is_shadowable), is_comptime, false);
if (is_comptime != nullptr || gen_is_const) {
@@ -3363,7 +3410,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
Scope *outer_block_scope = &scope_block->base;
Scope *child_scope = outer_block_scope;
- FnTableEntry *fn_entry = scope_fn_entry(parent_scope);
+ ZigFn *fn_entry = scope_fn_entry(parent_scope);
if (fn_entry && fn_entry->child_scope == parent_scope) {
fn_entry->def_scope = scope_block;
}
@@ -3749,7 +3796,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
return &const_instruction->base;
}
- TypeTableEntry *primitive_type = get_primitive_type(irb->codegen, variable_name);
+ ZigType *primitive_type = get_primitive_type(irb->codegen, variable_name);
if (primitive_type != nullptr) {
IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type);
if (lval == LValPtr) {
@@ -3759,9 +3806,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
}
}
- VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
+ ScopeFnDef *crossed_fndef_scope;
+ ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope);
if (var) {
- IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var);
+ IrInstruction *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope);
if (lval == LValPtr)
return var_ptr;
else
@@ -4980,7 +5028,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
ir_set_cursor_at_end_and_append_block(irb, then_block);
- IrInstruction *then_expr_result = ir_gen_node(irb, then_node, scope);
+ Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
+ IrInstruction *then_expr_result = ir_gen_node(irb, then_node, subexpr_scope);
if (then_expr_result == irb->codegen->invalid_instruction)
return then_expr_result;
IrBasicBlock *after_then_block = irb->current_basic_block;
@@ -4990,7 +5039,7 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
ir_set_cursor_at_end_and_append_block(irb, else_block);
IrInstruction *else_expr_result;
if (else_node) {
- else_expr_result = ir_gen_node(irb, else_node, scope);
+ else_expr_result = ir_gen_node(irb, else_node, subexpr_scope);
if (else_expr_result == irb->codegen->invalid_instruction)
return else_expr_result;
} else {
@@ -5217,7 +5266,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,
ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime);
- VariableTableEntry *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
+ ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
is_const, is_const, is_shadowable, is_comptime);
// we detect IrInstructionIdDeclVar in gen_block to make sure the next node
// is inside var->child_scope
@@ -5271,6 +5320,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);
ir_build_br(irb, scope, node, cond_block, is_comptime);
+ Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
Buf *var_symbol = node->data.while_expr.var_symbol;
Buf *err_symbol = node->data.while_expr.err_symbol;
if (err_symbol != nullptr) {
@@ -5278,16 +5328,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
Scope *payload_scope;
AstNode *symbol_node = node; // TODO make more accurate
- VariableTableEntry *payload_var;
+ ZigVar *payload_var;
if (var_symbol) {
// TODO make it an error to write to payload variable
- payload_var = ir_create_var(irb, symbol_node, scope, var_symbol,
+ payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
true, false, false, is_comptime);
payload_scope = payload_var->child_scope;
} else {
- payload_scope = scope;
+ payload_scope = subexpr_scope;
}
- IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, scope, LValPtr);
+ IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr);
if (err_val_ptr == irb->codegen->invalid_instruction)
return err_val_ptr;
IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr);
@@ -5342,7 +5392,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
// TODO make it an error to write to error variable
AstNode *err_symbol_node = else_node; // TODO make more accurate
- VariableTableEntry *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,
+ ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,
true, false, false, is_comptime);
Scope *err_scope = err_var->child_scope;
IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr);
@@ -5367,12 +5417,14 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
} else if (var_symbol != nullptr) {
ir_set_cursor_at_end_and_append_block(irb, cond_block);
+ Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
// TODO make it an error to write to payload variable
AstNode *symbol_node = node; // TODO make more accurate
- VariableTableEntry *payload_var = ir_create_var(irb, symbol_node, scope, var_symbol,
+
+ ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
true, false, false, is_comptime);
Scope *child_scope = payload_var->child_scope;
- IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, scope, LValPtr);
+ IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr);
if (maybe_val_ptr == irb->codegen->invalid_instruction)
return maybe_val_ptr;
IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);
@@ -5456,7 +5508,9 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
ZigList<IrInstruction *> incoming_values = {0};
ZigList<IrBasicBlock *> incoming_blocks = {0};
- ScopeLoop *loop_scope = create_loop_scope(node, scope);
+ Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
+
+ ScopeLoop *loop_scope = create_loop_scope(node, subexpr_scope);
loop_scope->break_block = end_block;
loop_scope->continue_block = continue_block;
loop_scope->is_comptime = is_comptime;
@@ -5474,7 +5528,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
if (continue_expr_node) {
ir_set_cursor_at_end_and_append_block(irb, continue_block);
- IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, scope);
+ IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
if (expr_result == irb->codegen->invalid_instruction)
return expr_result;
if (!instr_is_unreachable(expr_result))
@@ -5485,7 +5539,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
if (else_node) {
ir_set_cursor_at_end_and_append_block(irb, else_block);
- else_result = ir_gen_node(irb, else_node, scope);
+ else_result = ir_gen_node(irb, else_node, subexpr_scope);
if (else_result == irb->codegen->invalid_instruction)
return else_result;
if (!instr_is_unreachable(else_result))
@@ -5539,7 +5593,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
// TODO make it an error to write to element variable or i variable.
Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
- VariableTableEntry *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
+ ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
Scope *child_scope = elem_var->child_scope;
IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node);
@@ -5547,7 +5601,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var);
AstNode *index_var_source_node;
- VariableTableEntry *index_var;
+ ZigVar *index_var;
if (index_node) {
index_var_source_node = index_node;
Buf *index_var_name = index_node->data.symbol_expr.symbol;
@@ -5640,7 +5694,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode
if (!scope->parent)
return ir_build_const_import(irb, scope, node, node->owner);
- FnTableEntry *fn_entry = scope_get_fn_if_root(scope);
+ ZigFn *fn_entry = scope_get_fn_if_root(scope);
if (fn_entry)
return ir_build_const_fn(irb, scope, node, fn_entry);
@@ -5650,7 +5704,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode
if (scope->id == ScopeIdDecls) {
ScopeDecls *decls_scope = (ScopeDecls *)scope;
- TypeTableEntry *container_type = decls_scope->container_type;
+ ZigType *container_type = decls_scope->container_type;
assert(container_type);
return ir_build_const_type(irb, scope, node, container_type);
}
@@ -5752,7 +5806,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
IrInstruction **input_list = allocate<IrInstruction *>(node->data.asm_expr.input_list.length);
IrInstruction **output_types = allocate<IrInstruction *>(node->data.asm_expr.output_list.length);
- VariableTableEntry **output_vars = allocate<VariableTableEntry *>(node->data.asm_expr.output_list.length);
+ ZigVar **output_vars = allocate<ZigVar *>(node->data.asm_expr.output_list.length);
size_t return_count = 0;
bool is_volatile = node->data.asm_expr.is_volatile;
if (!is_volatile && node->data.asm_expr.output_list.length == 0) {
@@ -5776,7 +5830,9 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
output_types[i] = return_type;
} else {
Buf *variable_name = asm_output->variable_name;
- VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name);
+ // TODO there is some duplication here with ir_gen_symbol. I need to do a full audit of how
+ // inline assembly works. https://github.com/ziglang/zig/issues/215
+ ZigVar *var = find_variable(irb->codegen, scope, variable_name, nullptr);
if (var) {
output_vars[i] = var;
} else {
@@ -5828,20 +5884,21 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
ir_set_cursor_at_end_and_append_block(irb, then_block);
+ Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
Scope *var_scope;
if (var_symbol) {
IrInstruction *var_type = nullptr;
bool is_shadowable = false;
bool is_const = true;
- VariableTableEntry *var = ir_create_var(irb, node, scope,
+ ZigVar *var = ir_create_var(irb, node, subexpr_scope,
var_symbol, is_const, is_const, is_shadowable, is_comptime);
- IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, scope, node, maybe_val_ptr, false);
- IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, node, var_ptr_value);
- ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value);
+ IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, subexpr_scope, node, maybe_val_ptr, false);
+ IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value);
+ ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value);
var_scope = var->child_scope;
} else {
- var_scope = scope;
+ var_scope = subexpr_scope;
}
IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope);
if (then_expr_result == irb->codegen->invalid_instruction)
@@ -5853,7 +5910,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
ir_set_cursor_at_end_and_append_block(irb, else_block);
IrInstruction *else_expr_result;
if (else_node) {
- else_expr_result = ir_gen_node(irb, else_node, scope);
+ else_expr_result = ir_gen_node(irb, else_node, subexpr_scope);
if (else_expr_result == irb->codegen->invalid_instruction)
return else_expr_result;
} else {
@@ -5902,20 +5959,21 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
ir_set_cursor_at_end_and_append_block(irb, ok_block);
+ Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
Scope *var_scope;
if (var_symbol) {
IrInstruction *var_type = nullptr;
bool is_shadowable = false;
- IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, err_val);
- VariableTableEntry *var = ir_create_var(irb, node, scope,
+ IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);
+ ZigVar *var = ir_create_var(irb, node, subexpr_scope,
var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);
- IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, scope, node, err_val_ptr, false);
- IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, node, var_ptr_value);
- ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value);
+ IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false);
+ IrInstruction *var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, subexpr_scope, node, var_ptr_value);
+ ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value);
var_scope = var->child_scope;
} else {
- var_scope = scope;
+ var_scope = subexpr_scope;
}
IrInstruction *then_expr_result = ir_gen_node(irb, then_node, var_scope);
if (then_expr_result == irb->codegen->invalid_instruction)
@@ -5933,14 +5991,14 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
IrInstruction *var_type = nullptr;
bool is_shadowable = false;
bool is_const = true;
- VariableTableEntry *var = ir_create_var(irb, node, scope,
+ ZigVar *var = ir_create_var(irb, node, subexpr_scope,
err_symbol, is_const, is_const, is_shadowable, is_comptime);
- IrInstruction *var_value = ir_build_unwrap_err_code(irb, scope, node, err_val_ptr);
- ir_build_var_decl(irb, scope, node, var, var_type, nullptr, var_value);
+ IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr);
+ ir_build_var_decl(irb, subexpr_scope, node, var, var_type, nullptr, var_value);
err_var_scope = var->child_scope;
} else {
- err_var_scope = scope;
+ err_var_scope = subexpr_scope;
}
else_expr_result = ir_gen_node(irb, else_node, err_var_scope);
if (else_expr_result == irb->codegen->invalid_instruction)
@@ -5981,7 +6039,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
bool is_shadowable = false;
bool is_const = true;
- VariableTableEntry *var = ir_create_var(irb, var_symbol_node, scope,
+ ZigVar *var = ir_create_var(irb, var_symbol_node, scope,
var_name, is_const, is_const, is_shadowable, var_is_comptime);
child_scope = var->child_scope;
IrInstruction *var_value;
@@ -6037,6 +6095,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0};
// First do the else and the ranges
+ Scope *subexpr_scope = create_runtime_scope(node, scope, is_comptime);
Scope *comptime_scope = create_comptime_scope(node, scope);
AstNode *else_prong = nullptr;
for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {
@@ -6054,7 +6113,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
IrBasicBlock *prev_block = irb->current_basic_block;
ir_set_cursor_at_end_and_append_block(irb, else_block);
- if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block,
+ if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values))
{
return irb->codegen->invalid_instruction;
@@ -6121,7 +6180,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
range_block_no, is_comptime));
ir_set_cursor_at_end_and_append_block(irb, range_block_yes);
- if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block,
+ if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
is_comptime, var_is_comptime, target_value_ptr, nullptr, &incoming_blocks, &incoming_values))
{
return irb->codegen->invalid_instruction;
@@ -6165,7 +6224,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
IrBasicBlock *prev_block = irb->current_basic_block;
ir_set_cursor_at_end_and_append_block(irb, prong_block);
- if (!ir_gen_switch_prong_expr(irb, scope, node, prong_node, end_block,
+ if (!ir_gen_switch_prong_expr(irb, subexpr_scope, node, prong_node, end_block,
is_comptime, var_is_comptime, target_value_ptr, only_item_value, &incoming_blocks, &incoming_values))
{
return irb->codegen->invalid_instruction;
@@ -6308,6 +6367,8 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
// * defer expression scope => error, cannot break out of defer expression
// * loop scope => OK
+ ZigList<ScopeRuntime *> runtime_scopes = {};
+
Scope *search_scope = continue_scope;
ScopeLoop *loop_scope;
for (;;) {
@@ -6330,6 +6391,9 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
loop_scope = this_loop_scope;
break;
}
+ } else if (search_scope->id == ScopeIdRuntime) {
+ ScopeRuntime *scope_runtime = (ScopeRuntime *)search_scope;
+ runtime_scopes.append(scope_runtime);
}
search_scope = search_scope->parent;
}
@@ -6341,6 +6405,11 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
is_comptime = loop_scope->is_comptime;
}
+ for (size_t i = 0; i < runtime_scopes.length; i += 1) {
+ ScopeRuntime *scope_runtime = runtime_scopes.at(i);
+ ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));
+ }
+
IrBasicBlock *dest_block = loop_scope->continue_block;
ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);
return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));
@@ -6435,7 +6504,7 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN
Buf *var_name = var_node->data.symbol_expr.symbol;
bool is_const = true;
bool is_shadowable = false;
- VariableTableEntry *var = ir_create_var(irb, node, parent_scope, var_name,
+ ZigVar *var = ir_create_var(irb, node, parent_scope, var_name,
is_const, is_const, is_shadowable, is_comptime);
err_scope = var->child_scope;
IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);
@@ -6507,7 +6576,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
init_tld(&tld_container->base, TldIdContainer, name, visib_mod, node, parent_scope);
ContainerLayout layout = node->data.container_decl.layout;
- TypeTableEntry *container_type = get_partial_container_type(irb->codegen, parent_scope,
+ ZigType *container_type = get_partial_container_type(irb->codegen, parent_scope,
kind, node, buf_ptr(name), layout);
ScopeDecls *child_scope = get_container_scope(container_type);
@@ -6527,11 +6596,11 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope,
}
// errors should be populated with set1's values
-static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, TypeTableEntry *set1, TypeTableEntry *set2) {
- assert(set1->id == TypeTableEntryIdErrorSet);
- assert(set2->id == TypeTableEntryIdErrorSet);
+static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2) {
+ assert(set1->id == ZigTypeIdErrorSet);
+ assert(set2->id == ZigTypeIdErrorSet);
- TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
+ ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
buf_resize(&err_set_type->name, 0);
buf_appendf(&err_set_type->name, "error{");
@@ -6580,10 +6649,10 @@ static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors,
}
-static TypeTableEntry *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node,
+static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node,
ErrorTableEntry *err_entry)
{
- TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
+ ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
buf_resize(&err_set_type->name, 0);
buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name));
err_set_type->is_copyable = true;
@@ -6605,7 +6674,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
uint32_t err_count = node->data.err_set_decl.decls.length;
Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node);
- TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
+ ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
buf_init_from_buf(&err_set_type->name, type_name);
err_set_type->is_copyable = true;
err_set_type->data.error_set.err_count = err_count;
@@ -6854,7 +6923,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
if (target_inst == irb->codegen->invalid_instruction)
return irb->codegen->invalid_instruction;
- FnTableEntry *fn_entry = exec_fn_entry(irb->exec);
+ ZigFn *fn_entry = exec_fn_entry(irb->exec);
if (!fn_entry) {
add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));
return irb->codegen->invalid_instruction;
@@ -6917,7 +6986,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001
IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010
- VariableTableEntry *result_var = ir_create_var(irb, node, scope, nullptr,
+ ZigVar *result_var = ir_create_var(irb, node, scope, nullptr,
false, false, true, const_bool_false);
IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst);
IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);
@@ -7031,7 +7100,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
assert(node->type == NodeTypeSuspend);
- FnTableEntry *fn_entry = exec_fn_entry(irb->exec);
+ ZigFn *fn_entry = exec_fn_entry(irb->exec);
if (!fn_entry) {
add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));
return irb->codegen->invalid_instruction;
@@ -7320,31 +7389,31 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
// Entry block gets a reference because we enter it to begin.
ir_ref_bb(irb->current_basic_block);
- FnTableEntry *fn_entry = exec_fn_entry(irb->exec);
+ ZigFn *fn_entry = exec_fn_entry(irb->exec);
bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
IrInstruction *coro_id;
IrInstruction *u8_ptr_type;
IrInstruction *const_bool_false;
IrInstruction *coro_promise_ptr;
IrInstruction *err_ret_trace_ptr;
- TypeTableEntry *return_type;
+ ZigType *return_type;
Buf *result_ptr_field_name;
- VariableTableEntry *coro_size_var;
+ ZigVar *coro_size_var;
if (is_async) {
// create the coro promise
Scope *coro_scope = create_coro_prelude_scope(node, scope);
const_bool_false = ir_build_const_bool(irb, coro_scope, node, false);
- VariableTableEntry *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
+ ZigVar *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node);
- TypeTableEntry *coro_frame_type = get_promise_frame_type(irb->codegen, return_type);
+ ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type);
IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
// TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa
ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef);
coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
- VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
+ ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);
IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
@@ -7531,7 +7600,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
return true;
}
-bool ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) {
+bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
assert(fn_entry);
IrExecutable *ir_executable = &fn_entry->ir_executable;
@@ -7566,6 +7635,19 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction,
return ir_add_error_node(ira, source_instruction->source_node, msg);
}
+static ConstExprValue *ir_const_ptr_pointee(IrAnalyze *ira, ConstExprValue *const_val, AstNode *source_node) {
+ ConstExprValue *val = const_ptr_pointee_unchecked(ira->codegen, const_val);
+ assert(val != nullptr);
+ assert(const_val->type->id == ZigTypeIdPointer);
+ ZigType *expected_type = const_val->type->data.pointer.child_type;
+ if (!types_have_same_zig_comptime_repr(val->type, expected_type)) {
+ ir_add_error_node(ira, source_node,
+ buf_sprintf("TODO handle comptime reinterpreted pointer. See https://github.com/ziglang/zig/issues/955"));
+ return nullptr;
+ }
+ return val;
+}
+
static IrInstruction *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
IrBasicBlock *bb = exec->basic_block_list.at(0);
for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
@@ -7596,17 +7678,17 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
return true;
}
-static bool const_val_fits_in_num_lit(ConstExprValue *const_val, TypeTableEntry *num_lit_type) {
- return ((num_lit_type->id == TypeTableEntryIdComptimeFloat &&
- (const_val->type->id == TypeTableEntryIdFloat || const_val->type->id == TypeTableEntryIdComptimeFloat)) ||
- (num_lit_type->id == TypeTableEntryIdComptimeInt &&
- (const_val->type->id == TypeTableEntryIdInt || const_val->type->id == TypeTableEntryIdComptimeInt)));
+static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) {
+ return ((num_lit_type->id == ZigTypeIdComptimeFloat &&
+ (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) ||
+ (num_lit_type->id == ZigTypeIdComptimeInt &&
+ (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt)));
}
static bool float_has_fraction(ConstExprValue *const_val) {
- if (const_val->type->id == TypeTableEntryIdComptimeFloat) {
+ if (const_val->type->id == ZigTypeIdComptimeFloat) {
return bigfloat_has_fraction(&const_val->data.x_bigfloat);
- } else if (const_val->type->id == TypeTableEntryIdFloat) {
+ } else if (const_val->type->id == ZigTypeIdFloat) {
switch (const_val->type->data.floating.bit_count) {
case 16:
{
@@ -7632,9 +7714,9 @@ static bool float_has_fraction(ConstExprValue *const_val) {
}
static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
- if (const_val->type->id == TypeTableEntryIdComptimeFloat) {
+ if (const_val->type->id == ZigTypeIdComptimeFloat) {
bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
- } else if (const_val->type->id == TypeTableEntryIdFloat) {
+ } else if (const_val->type->id == ZigTypeIdFloat) {
switch (const_val->type->data.floating.bit_count) {
case 16:
buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16));
@@ -7670,9 +7752,9 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
}
static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
- if (const_val->type->id == TypeTableEntryIdComptimeFloat) {
+ if (const_val->type->id == ZigTypeIdComptimeFloat) {
bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);
- } else if (const_val->type->id == TypeTableEntryIdFloat) {
+ } else if (const_val->type->id == ZigTypeIdFloat) {
switch (const_val->type->data.floating.bit_count) {
case 16:
{
@@ -7717,9 +7799,9 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
}
static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
- if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
+ if (dest_val->type->id == ZigTypeIdComptimeFloat) {
bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);
- } else if (dest_val->type->id == TypeTableEntryIdFloat) {
+ } else if (dest_val->type->id == ZigTypeIdFloat) {
switch (dest_val->type->data.floating.bit_count) {
case 16:
dest_val->data.x_f16 = bigfloat_to_f16(bigfloat);
@@ -7742,9 +7824,9 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
}
static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
- if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
+ if (dest_val->type->id == ZigTypeIdComptimeFloat) {
bigfloat_init_16(&dest_val->data.x_bigfloat, x);
- } else if (dest_val->type->id == TypeTableEntryIdFloat) {
+ } else if (dest_val->type->id == ZigTypeIdFloat) {
switch (dest_val->type->data.floating.bit_count) {
case 16:
dest_val->data.x_f16 = x;
@@ -7767,9 +7849,9 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) {
}
static void float_init_f32(ConstExprValue *dest_val, float x) {
- if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
+ if (dest_val->type->id == ZigTypeIdComptimeFloat) {
bigfloat_init_32(&dest_val->data.x_bigfloat, x);
- } else if (dest_val->type->id == TypeTableEntryIdFloat) {
+ } else if (dest_val->type->id == ZigTypeIdFloat) {
switch (dest_val->type->data.floating.bit_count) {
case 16:
dest_val->data.x_f16 = zig_double_to_f16(x);
@@ -7796,9 +7878,9 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {
}
static void float_init_f64(ConstExprValue *dest_val, double x) {
- if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
+ if (dest_val->type->id == ZigTypeIdComptimeFloat) {
bigfloat_init_64(&dest_val->data.x_bigfloat, x);
- } else if (dest_val->type->id == TypeTableEntryIdFloat) {
+ } else if (dest_val->type->id == ZigTypeIdFloat) {
switch (dest_val->type->data.floating.bit_count) {
case 16:
dest_val->data.x_f16 = zig_double_to_f16(x);
@@ -7825,9 +7907,9 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {
}
static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
- if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
+ if (dest_val->type->id == ZigTypeIdComptimeFloat) {
bigfloat_init_128(&dest_val->data.x_bigfloat, x);
- } else if (dest_val->type->id == TypeTableEntryIdFloat) {
+ } else if (dest_val->type->id == ZigTypeIdFloat) {
switch (dest_val->type->data.floating.bit_count) {
case 16:
dest_val->data.x_f16 = f128M_to_f16(&x);
@@ -7858,9 +7940,9 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
}
static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) {
- if (src_val->type->id == TypeTableEntryIdComptimeFloat) {
+ if (src_val->type->id == ZigTypeIdComptimeFloat) {
float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);
- } else if (src_val->type->id == TypeTableEntryIdFloat) {
+ } else if (src_val->type->id == ZigTypeIdFloat) {
switch (src_val->type->data.floating.bit_count) {
case 16:
float_init_f16(dest_val, src_val->data.x_f16);
@@ -7884,9 +7966,9 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)
static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type);
- if (op1->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op1->type->id == ZigTypeIdComptimeFloat) {
return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);
- } else if (op1->type->id == TypeTableEntryIdFloat) {
+ } else if (op1->type->id == ZigTypeIdFloat) {
switch (op1->type->data.floating.bit_count) {
case 16:
if (f16_lt(op1->data.x_f16, op2->data.x_f16)) {
@@ -7929,9 +8011,9 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
}
static Cmp float_cmp_zero(ConstExprValue *op) {
- if (op->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op->type->id == ZigTypeIdComptimeFloat) {
return bigfloat_cmp_zero(&op->data.x_bigfloat);
- } else if (op->type->id == TypeTableEntryIdFloat) {
+ } else if (op->type->id == ZigTypeIdFloat) {
switch (op->type->data.floating.bit_count) {
case 16:
{
@@ -7981,9 +8063,9 @@ static Cmp float_cmp_zero(ConstExprValue *op) {
static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type);
out_val->type = op1->type;
- if (op1->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op1->type->id == ZigTypeIdComptimeFloat) {
bigfloat_add(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
- } else if (op1->type->id == TypeTableEntryIdFloat) {
+ } else if (op1->type->id == ZigTypeIdFloat) {
switch (op1->type->data.floating.bit_count) {
case 16:
out_val->data.x_f16 = f16_add(op1->data.x_f16, op2->data.x_f16);
@@ -8008,9 +8090,9 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type);
out_val->type = op1->type;
- if (op1->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op1->type->id == ZigTypeIdComptimeFloat) {
bigfloat_sub(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
- } else if (op1->type->id == TypeTableEntryIdFloat) {
+ } else if (op1->type->id == ZigTypeIdFloat) {
switch (op1->type->data.floating.bit_count) {
case 16:
out_val->data.x_f16 = f16_sub(op1->data.x_f16, op2->data.x_f16);
@@ -8035,9 +8117,9 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type);
out_val->type = op1->type;
- if (op1->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op1->type->id == ZigTypeIdComptimeFloat) {
bigfloat_mul(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
- } else if (op1->type->id == TypeTableEntryIdFloat) {
+ } else if (op1->type->id == ZigTypeIdFloat) {
switch (op1->type->data.floating.bit_count) {
case 16:
out_val->data.x_f16 = f16_mul(op1->data.x_f16, op2->data.x_f16);
@@ -8062,9 +8144,9 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type);
out_val->type = op1->type;
- if (op1->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op1->type->id == ZigTypeIdComptimeFloat) {
bigfloat_div(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
- } else if (op1->type->id == TypeTableEntryIdFloat) {
+ } else if (op1->type->id == ZigTypeIdFloat) {
switch (op1->type->data.floating.bit_count) {
case 16:
out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);
@@ -8089,9 +8171,9 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type);
out_val->type = op1->type;
- if (op1->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op1->type->id == ZigTypeIdComptimeFloat) {
bigfloat_div_trunc(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
- } else if (op1->type->id == TypeTableEntryIdFloat) {
+ } else if (op1->type->id == ZigTypeIdFloat) {
switch (op1->type->data.floating.bit_count) {
case 16:
out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);
@@ -8118,9 +8200,9 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE
static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type);
out_val->type = op1->type;
- if (op1->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op1->type->id == ZigTypeIdComptimeFloat) {
bigfloat_div_floor(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
- } else if (op1->type->id == TypeTableEntryIdFloat) {
+ } else if (op1->type->id == ZigTypeIdFloat) {
switch (op1->type->data.floating.bit_count) {
case 16:
out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16);
@@ -8147,9 +8229,9 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE
static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type);
out_val->type = op1->type;
- if (op1->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op1->type->id == ZigTypeIdComptimeFloat) {
bigfloat_rem(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
- } else if (op1->type->id == TypeTableEntryIdFloat) {
+ } else if (op1->type->id == ZigTypeIdFloat) {
switch (op1->type->data.floating.bit_count) {
case 16:
out_val->data.x_f16 = f16_rem(op1->data.x_f16, op2->data.x_f16);
@@ -8192,9 +8274,9 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t*
static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type);
out_val->type = op1->type;
- if (op1->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op1->type->id == ZigTypeIdComptimeFloat) {
bigfloat_mod(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
- } else if (op1->type->id == TypeTableEntryIdFloat) {
+ } else if (op1->type->id == ZigTypeIdFloat) {
switch (op1->type->data.floating.bit_count) {
case 16:
out_val->data.x_f16 = zig_f16_mod(op1->data.x_f16, op2->data.x_f16);
@@ -8218,9 +8300,9 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
out_val->type = op->type;
- if (op->type->id == TypeTableEntryIdComptimeFloat) {
+ if (op->type->id == ZigTypeIdComptimeFloat) {
bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);
- } else if (op->type->id == TypeTableEntryIdFloat) {
+ } else if (op->type->id == ZigTypeIdFloat) {
switch (op->type->data.floating.bit_count) {
case 16:
{
@@ -8248,7 +8330,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
}
void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
- if (op->type->id == TypeTableEntryIdFloat) {
+ if (op->type->id == ZigTypeIdFloat) {
switch (op->type->data.floating.bit_count) {
case 16:
memcpy(buf, &op->data.x_f16, 2); // TODO wrong when compiler is big endian
@@ -8271,7 +8353,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) {
}
void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {
- if (val->type->id == TypeTableEntryIdFloat) {
+ if (val->type->id == ZigTypeIdFloat) {
switch (val->type->data.floating.bit_count) {
case 16:
memcpy(&val->data.x_f16, buf, 2); // TODO wrong when compiler is big endian
@@ -8293,7 +8375,7 @@ void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) {
}
}
-static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *other_type,
+static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, ZigType *other_type,
bool explicit_cast)
{
if (type_is_invalid(other_type)) {
@@ -8303,13 +8385,13 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
ConstExprValue *const_val = &instruction->value;
assert(const_val->special != ConstValSpecialRuntime);
- bool const_val_is_int = (const_val->type->id == TypeTableEntryIdInt ||
- const_val->type->id == TypeTableEntryIdComptimeInt);
- bool const_val_is_float = (const_val->type->id == TypeTableEntryIdFloat ||
- const_val->type->id == TypeTableEntryIdComptimeFloat);
- if (other_type->id == TypeTableEntryIdFloat) {
+ bool const_val_is_int = (const_val->type->id == ZigTypeIdInt ||
+ const_val->type->id == ZigTypeIdComptimeInt);
+ bool const_val_is_float = (const_val->type->id == ZigTypeIdFloat ||
+ const_val->type->id == ZigTypeIdComptimeFloat);
+ if (other_type->id == ZigTypeIdFloat) {
return true;
- } else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) {
+ } else if (other_type->id == ZigTypeIdInt && const_val_is_int) {
if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
Buf *val_buf = buf_alloc();
bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
@@ -8326,11 +8408,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
}
} else if (const_val_fits_in_num_lit(const_val, other_type)) {
return true;
- } else if (other_type->id == TypeTableEntryIdOptional) {
- TypeTableEntry *child_type = other_type->data.maybe.child_type;
+ } else if (other_type->id == ZigTypeIdOptional) {
+ ZigType *child_type = other_type->data.maybe.child_type;
if (const_val_fits_in_num_lit(const_val, child_type)) {
return true;
- } else if (child_type->id == TypeTableEntryIdInt && const_val_is_int) {
+ } else if (child_type->id == ZigTypeIdInt && const_val_is_int) {
if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
Buf *val_buf = buf_alloc();
bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
@@ -8346,11 +8428,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
{
return true;
}
- } else if (child_type->id == TypeTableEntryIdFloat && const_val_is_float) {
+ } else if (child_type->id == ZigTypeIdFloat && const_val_is_float) {
return true;
}
}
- if (explicit_cast && (other_type->id == TypeTableEntryIdInt || other_type->id == TypeTableEntryIdComptimeInt) &&
+ if (explicit_cast && (other_type->id == ZigTypeIdInt || other_type->id == ZigTypeIdComptimeInt) &&
const_val_is_float)
{
if (float_has_fraction(const_val)) {
@@ -8363,7 +8445,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
buf_ptr(&other_type->name)));
return false;
} else {
- if (other_type->id == TypeTableEntryIdComptimeInt) {
+ if (other_type->id == ZigTypeIdComptimeInt) {
return true;
} else {
BigInt bigint;
@@ -8395,20 +8477,20 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
return false;
}
-static bool is_slice(TypeTableEntry *type) {
- return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice;
+static bool is_slice(ZigType *type) {
+ return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
}
-static bool slice_is_const(TypeTableEntry *type) {
+static bool slice_is_const(ZigType *type) {
assert(is_slice(type));
return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
}
-static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry *set1, TypeTableEntry *set2,
+static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigType *set2,
AstNode *source_node)
{
- assert(set1->id == TypeTableEntryIdErrorSet);
- assert(set2->id == TypeTableEntryIdErrorSet);
+ assert(set1->id == ZigTypeIdErrorSet);
+ assert(set2->id == ZigTypeIdErrorSet);
if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) {
return ira->codegen->builtin_types.entry_invalid;
@@ -8430,7 +8512,7 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry
}
ZigList<ErrorTableEntry *> intersection_list = {};
- TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
+ ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
buf_resize(&err_set_type->name, 0);
buf_appendf(&err_set_type->name, "error{");
@@ -8459,8 +8541,8 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry
}
-static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry *wanted_type,
- TypeTableEntry *actual_type, AstNode *source_node, bool wanted_is_mutable)
+static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted_type,
+ ZigType *actual_type, AstNode *source_node, bool wanted_is_mutable)
{
CodeGen *g = ira->codegen;
ConstCastOnly result = {};
@@ -8472,9 +8554,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
// *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively
// but not if we want a mutable pointer
// and not if the actual pointer has zero bits
- if (!wanted_is_mutable && wanted_type->id == TypeTableEntryIdOptional &&
- wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer &&
- actual_type->id == TypeTableEntryIdPointer && type_has_bits(actual_type))
+ if (!wanted_is_mutable && wanted_type->id == ZigTypeIdOptional &&
+ wanted_type->data.maybe.child_type->id == ZigTypeIdPointer &&
+ actual_type->id == ZigTypeIdPointer && type_has_bits(actual_type))
{
ConstCastOnly child = types_match_const_cast_only(ira,
wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable);
@@ -8487,10 +8569,10 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
}
// *T and [*]T can always cast to *c_void
- if (wanted_type->id == TypeTableEntryIdPointer &&
+ if (wanted_type->id == ZigTypeIdPointer &&
wanted_type->data.pointer.ptr_len == PtrLenSingle &&
wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void &&
- actual_type->id == TypeTableEntryIdPointer &&
+ actual_type->id == ZigTypeIdPointer &&
(!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&
(!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))
{
@@ -8499,7 +8581,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
}
// pointer const
- if (wanted_type->id == TypeTableEntryIdPointer && actual_type->id == TypeTableEntryIdPointer) {
+ if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) {
ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const);
if (child.id != ConstCastResultIdOk) {
@@ -8523,8 +8605,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
// slice const
if (is_slice(wanted_type) && is_slice(actual_type)) {
- TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;
- TypeTableEntry *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
+ ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;
+ ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) &&
(!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) &&
actual_ptr_type->data.pointer.bit_offset == wanted_ptr_type->data.pointer.bit_offset &&
@@ -8545,7 +8627,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
}
// maybe
- if (wanted_type->id == TypeTableEntryIdOptional && actual_type->id == TypeTableEntryIdOptional) {
+ if (wanted_type->id == ZigTypeIdOptional && actual_type->id == ZigTypeIdOptional) {
ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type,
actual_type->data.maybe.child_type, source_node, wanted_is_mutable);
if (child.id != ConstCastResultIdOk) {
@@ -8559,7 +8641,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
}
// error union
- if (wanted_type->id == TypeTableEntryIdErrorUnion && actual_type->id == TypeTableEntryIdErrorUnion) {
+ if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorUnion) {
ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type,
actual_type->data.error_union.payload_type, source_node, wanted_is_mutable);
if (payload_child.id != ConstCastResultIdOk) {
@@ -8584,9 +8666,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
}
// error set
- if (wanted_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) {
- TypeTableEntry *contained_set = actual_type;
- TypeTableEntry *container_set = wanted_type;
+ if (wanted_type->id == ZigTypeIdErrorSet && actual_type->id == ZigTypeIdErrorSet) {
+ ZigType *contained_set = actual_type;
+ ZigType *container_set = wanted_type;
// if the container set is inferred, then this will always work.
if (container_set->data.error_set.infer_fn != nullptr) {
@@ -8629,14 +8711,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
}
if (wanted_type == ira->codegen->builtin_types.entry_promise &&
- actual_type->id == TypeTableEntryIdPromise)
+ actual_type->id == ZigTypeIdPromise)
{
return result;
}
// fn
- if (wanted_type->id == TypeTableEntryIdFn &&
- actual_type->id == TypeTableEntryIdFn)
+ if (wanted_type->id == ZigTypeIdFn &&
+ actual_type->id == ZigTypeIdFn)
{
if (wanted_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) {
result.id = ConstCastResultIdFnAlign;
@@ -8655,7 +8737,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
return result;
}
if (!wanted_type->data.fn.is_generic &&
- actual_type->data.fn.fn_type_id.return_type->id != TypeTableEntryIdUnreachable)
+ actual_type->data.fn.fn_type_id.return_type->id != ZigTypeIdUnreachable)
{
ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type,
actual_type->data.fn.fn_type_id.return_type, source_node, false);
@@ -8725,7 +8807,7 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *
*errors = reallocate(*errors, old_errors_count, *errors_count);
}
-static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, TypeTableEntry *expected_type, IrInstruction **instructions, size_t instruction_count) {
+static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type, IrInstruction **instructions, size_t instruction_count) {
Error err;
assert(instruction_count >= 1);
IrInstruction *prev_inst = instructions[0];
@@ -8734,8 +8816,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
}
ErrorTableEntry **errors = nullptr;
size_t errors_count = 0;
- TypeTableEntry *err_set_type = nullptr;
- if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {
+ ZigType *err_set_type = nullptr;
+ if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
if (type_is_global_error_set(prev_inst->value.type)) {
err_set_type = ira->codegen->builtin_types.entry_global_error_set;
} else {
@@ -8753,29 +8835,29 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
}
}
- bool any_are_null = (prev_inst->value.type->id == TypeTableEntryIdNull);
+ bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull);
bool convert_to_const_slice = false;
for (size_t i = 1; i < instruction_count; i += 1) {
IrInstruction *cur_inst = instructions[i];
- TypeTableEntry *cur_type = cur_inst->value.type;
- TypeTableEntry *prev_type = prev_inst->value.type;
+ ZigType *cur_type = cur_inst->value.type;
+ ZigType *prev_type = prev_inst->value.type;
if (type_is_invalid(cur_type)) {
return cur_type;
}
- if (prev_type->id == TypeTableEntryIdUnreachable) {
+ if (prev_type->id == ZigTypeIdUnreachable) {
prev_inst = cur_inst;
continue;
}
- if (cur_type->id == TypeTableEntryIdUnreachable) {
+ if (cur_type->id == ZigTypeIdUnreachable) {
continue;
}
- if (prev_type->id == TypeTableEntryIdErrorSet) {
+ if (prev_type->id == ZigTypeIdErrorSet) {
assert(err_set_type != nullptr);
- if (cur_type->id == TypeTableEntryIdErrorSet) {
+ if (cur_type->id == ZigTypeIdErrorSet) {
if (type_is_global_error_set(err_set_type)) {
continue;
}
@@ -8839,12 +8921,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type);
assert(errors != nullptr);
continue;
- } else if (cur_type->id == TypeTableEntryIdErrorUnion) {
+ } else if (cur_type->id == ZigTypeIdErrorUnion) {
if (type_is_global_error_set(err_set_type)) {
prev_inst = cur_inst;
continue;
}
- TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
+ ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
return ira->codegen->builtin_types.entry_invalid;
}
@@ -8897,8 +8979,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
}
}
- if (cur_type->id == TypeTableEntryIdErrorSet) {
- if (prev_type->id == TypeTableEntryIdArray) {
+ if (cur_type->id == ZigTypeIdErrorSet) {
+ if (prev_type->id == ZigTypeIdArray) {
convert_to_const_slice = true;
}
if (type_is_global_error_set(cur_type)) {
@@ -8915,7 +8997,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
update_errors_helper(ira->codegen, &errors, &errors_count);
if (err_set_type == nullptr) {
- if (prev_type->id == TypeTableEntryIdErrorUnion) {
+ if (prev_type->id == ZigTypeIdErrorUnion) {
err_set_type = prev_type->data.error_union.err_set_type;
} else {
err_set_type = cur_type;
@@ -8948,9 +9030,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
continue;
}
- if (prev_type->id == TypeTableEntryIdErrorUnion && cur_type->id == TypeTableEntryIdErrorUnion) {
- TypeTableEntry *prev_payload_type = prev_type->data.error_union.payload_type;
- TypeTableEntry *cur_payload_type = cur_type->data.error_union.payload_type;
+ if (prev_type->id == ZigTypeIdErrorUnion && cur_type->id == ZigTypeIdErrorUnion) {
+ ZigType *prev_payload_type = prev_type->data.error_union.payload_type;
+ ZigType *cur_payload_type = cur_type->data.error_union.payload_type;
bool const_cast_prev = types_match_const_cast_only(ira, prev_payload_type, cur_payload_type,
source_node, false).id == ConstCastResultIdOk;
@@ -8962,8 +9044,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
prev_inst = cur_inst;
}
- TypeTableEntry *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type;
- TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
+ ZigType *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type;
+ ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) {
return ira->codegen->builtin_types.entry_invalid;
@@ -9032,12 +9114,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
}
}
- if (prev_type->id == TypeTableEntryIdNull) {
+ if (prev_type->id == ZigTypeIdNull) {
prev_inst = cur_inst;
continue;
}
- if (cur_type->id == TypeTableEntryIdNull) {
+ if (cur_type->id == ZigTypeIdNull) {
any_are_null = true;
continue;
}
@@ -9051,8 +9133,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
continue;
}
- if (prev_type->id == TypeTableEntryIdInt &&
- cur_type->id == TypeTableEntryIdInt &&
+ if (prev_type->id == ZigTypeIdInt &&
+ cur_type->id == ZigTypeIdInt &&
prev_type->data.integral.is_signed == cur_type->data.integral.is_signed)
{
if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) {
@@ -9061,26 +9143,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
continue;
}
- if (prev_type->id == TypeTableEntryIdFloat && cur_type->id == TypeTableEntryIdFloat) {
+ if (prev_type->id == ZigTypeIdFloat && cur_type->id == ZigTypeIdFloat) {
if (cur_type->data.floating.bit_count > prev_type->data.floating.bit_count) {
prev_inst = cur_inst;
}
continue;
}
- if (prev_type->id == TypeTableEntryIdErrorUnion &&
+ if (prev_type->id == ZigTypeIdErrorUnion &&
types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type,
source_node, false).id == ConstCastResultIdOk)
{
continue;
}
- if (cur_type->id == TypeTableEntryIdErrorUnion &&
+ if (cur_type->id == ZigTypeIdErrorUnion &&
types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type,
source_node, false).id == ConstCastResultIdOk)
{
if (err_set_type != nullptr) {
- TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type;
+ ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
return ira->codegen->builtin_types.entry_invalid;
}
@@ -9098,14 +9180,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
continue;
}
- if (prev_type->id == TypeTableEntryIdOptional &&
+ if (prev_type->id == ZigTypeIdOptional &&
types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type,
source_node, false).id == ConstCastResultIdOk)
{
continue;
}
- if (cur_type->id == TypeTableEntryIdOptional &&
+ if (cur_type->id == ZigTypeIdOptional &&
types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type,
source_node, false).id == ConstCastResultIdOk)
{
@@ -9113,17 +9195,17 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
continue;
}
- if (cur_type->id == TypeTableEntryIdUndefined) {
+ if (cur_type->id == ZigTypeIdUndefined) {
continue;
}
- if (prev_type->id == TypeTableEntryIdUndefined) {
+ if (prev_type->id == ZigTypeIdUndefined) {
prev_inst = cur_inst;
continue;
}
- if (prev_type->id == TypeTableEntryIdComptimeInt ||
- prev_type->id == TypeTableEntryIdComptimeFloat)
+ if (prev_type->id == ZigTypeIdComptimeInt ||
+ prev_type->id == ZigTypeIdComptimeFloat)
{
if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) {
prev_inst = cur_inst;
@@ -9133,8 +9215,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
}
}
- if (cur_type->id == TypeTableEntryIdComptimeInt ||
- cur_type->id == TypeTableEntryIdComptimeFloat)
+ if (cur_type->id == ZigTypeIdComptimeInt ||
+ cur_type->id == ZigTypeIdComptimeFloat)
{
if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) {
continue;
@@ -9143,7 +9225,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
}
}
- if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&
+ if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
cur_type->data.array.len != prev_type->data.array.len &&
types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type,
source_node, false).id == ConstCastResultIdOk)
@@ -9153,7 +9235,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
continue;
}
- if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&
+ if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
cur_type->data.array.len != prev_type->data.array.len &&
types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type,
source_node, false).id == ConstCastResultIdOk)
@@ -9162,7 +9244,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
continue;
}
- if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) &&
+ if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) &&
(prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
cur_type->data.array.len == 0) &&
types_match_const_cast_only(ira,
@@ -9173,7 +9255,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
continue;
}
- if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) &&
+ if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&
(cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
prev_type->data.array.len == 0) &&
types_match_const_cast_only(ira,
@@ -9185,7 +9267,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
continue;
}
- if (prev_type->id == TypeTableEntryIdEnum && cur_type->id == TypeTableEntryIdUnion &&
+ if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&
(cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
{
if ((err = type_ensure_zero_bits_known(ira->codegen, cur_type)))
@@ -9195,7 +9277,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
}
}
- if (cur_type->id == TypeTableEntryIdEnum && prev_type->id == TypeTableEntryIdUnion &&
+ if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdUnion &&
(prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
{
if ((err = type_ensure_zero_bits_known(ira->codegen, prev_type)))
@@ -9220,33 +9302,33 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
free(errors);
if (convert_to_const_slice) {
- assert(prev_inst->value.type->id == TypeTableEntryIdArray);
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(
+ assert(prev_inst->value.type->id == ZigTypeIdArray);
+ ZigType *ptr_type = get_pointer_to_type_extra(
ira->codegen, prev_inst->value.type->data.array.child_type,
true, false, PtrLenUnknown,
get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type),
0, 0);
- TypeTableEntry *slice_type = get_slice_type(ira->codegen, ptr_type);
+ ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
if (err_set_type != nullptr) {
return get_error_union_type(ira->codegen, err_set_type, slice_type);
} else {
return slice_type;
}
} else if (err_set_type != nullptr) {
- if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) {
+ if (prev_inst->value.type->id == ZigTypeIdErrorSet) {
return err_set_type;
- } else if (prev_inst->value.type->id == TypeTableEntryIdErrorUnion) {
+ } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) {
return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type->data.error_union.payload_type);
- } else if (expected_type != nullptr && expected_type->id == TypeTableEntryIdErrorUnion) {
+ } else if (expected_type != nullptr && expected_type->id == ZigTypeIdErrorUnion) {
return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type);
} else {
- if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt ||
- prev_inst->value.type->id == TypeTableEntryIdComptimeFloat)
+ if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||
+ prev_inst->value.type->id == ZigTypeIdComptimeFloat)
{
ir_add_error_node(ira, source_node,
buf_sprintf("unable to make error union out of number literal"));
return ira->codegen->builtin_types.entry_invalid;
- } else if (prev_inst->value.type->id == TypeTableEntryIdNull) {
+ } else if (prev_inst->value.type->id == ZigTypeIdNull) {
ir_add_error_node(ira, source_node,
buf_sprintf("unable to make error union out of null literal"));
return ira->codegen->builtin_types.entry_invalid;
@@ -9254,14 +9336,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type);
}
}
- } else if (any_are_null && prev_inst->value.type->id != TypeTableEntryIdNull) {
- if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt ||
- prev_inst->value.type->id == TypeTableEntryIdComptimeFloat)
+ } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) {
+ if (prev_inst->value.type->id == ZigTypeIdComptimeInt ||
+ prev_inst->value.type->id == ZigTypeIdComptimeFloat)
{
ir_add_error_node(ira, source_node,
buf_sprintf("unable to make maybe out of number literal"));
return ira->codegen->builtin_types.entry_invalid;
- } else if (prev_inst->value.type->id == TypeTableEntryIdOptional) {
+ } else if (prev_inst->value.type->id == ZigTypeIdOptional) {
return prev_inst->value.type;
} else {
return get_optional_type(ira->codegen, prev_inst->value.type);
@@ -9271,9 +9353,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
}
}
-static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *type_entry) {
+static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, ZigType *type_entry) {
if (type_has_bits(type_entry) && handle_is_ptr(type_entry)) {
- FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
if (fn_entry != nullptr) {
fn_entry->alloca_list.append(instruction);
}
@@ -9285,7 +9367,7 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
*dest = *src;
if (!same_global_refs) {
dest->global_refs = global_refs;
- if (dest->type->id == TypeTableEntryIdStruct) {
+ if (dest->type->id == ZigTypeIdStruct) {
dest->data.x_struct.fields = allocate_nonzero<ConstExprValue>(dest->type->data.structure.src_field_count);
memcpy(dest->data.x_struct.fields, src->data.x_struct.fields, sizeof(ConstExprValue) * dest->type->data.structure.src_field_count);
}
@@ -9294,8 +9376,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_
static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,
CastOp cast_op,
- ConstExprValue *other_val, TypeTableEntry *other_type,
- ConstExprValue *const_val, TypeTableEntry *new_type)
+ ConstExprValue *other_val, ZigType *other_type,
+ ConstExprValue *const_val, ZigType *new_type)
{
const_val->special = other_val->special;
@@ -9315,8 +9397,8 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
break;
}
case CastOpNumLitToConcrete:
- if (other_val->type->id == TypeTableEntryIdComptimeFloat) {
- assert(new_type->id == TypeTableEntryIdFloat);
+ if (other_val->type->id == ZigTypeIdComptimeFloat) {
+ assert(new_type->id == ZigTypeIdFloat);
switch (new_type->data.floating.bit_count) {
case 16:
const_val->data.x_f16 = bigfloat_to_f16(&other_val->data.x_bigfloat);
@@ -9333,7 +9415,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
default:
zig_unreachable();
}
- } else if (other_val->type->id == TypeTableEntryIdComptimeInt) {
+ } else if (other_val->type->id == ZigTypeIdComptimeInt) {
bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint);
} else {
zig_unreachable();
@@ -9346,7 +9428,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
zig_unreachable();
case CastOpIntToFloat:
{
- assert(new_type->id == TypeTableEntryIdFloat);
+ assert(new_type->id == ZigTypeIdFloat);
BigFloat bigfloat;
bigfloat_init_bigint(&bigfloat, &other_val->data.x_bigint);
@@ -9371,7 +9453,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
}
case CastOpFloatToInt:
float_init_bigint(&const_val->data.x_bigint, other_val);
- if (new_type->id == TypeTableEntryIdInt) {
+ if (new_type->id == ZigTypeIdInt) {
if (!bigint_fits_in_bits(&const_val->data.x_bigint, new_type->data.integral.bit_count,
new_type->data.integral.is_signed))
{
@@ -9395,7 +9477,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
return true;
}
static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
- TypeTableEntry *wanted_type, CastOp cast_op, bool need_alloca)
+ ZigType *wanted_type, CastOp cast_op, bool need_alloca)
{
if ((instr_is_comptime(value) || !type_has_bits(wanted_type)) &&
cast_op != CastOpResizeSlice && cast_op != CastOpBytesToSlice)
@@ -9419,13 +9501,15 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst
}
static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *value, TypeTableEntry *wanted_type)
+ IrInstruction *value, ZigType *wanted_type)
{
- assert(value->value.type->id == TypeTableEntryIdPointer);
+ assert(value->value.type->id == ZigTypeIdPointer);
wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment);
if (instr_is_comptime(value)) {
- ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &value->value);
+ ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node);
+ if (pointee == nullptr)
+ return ira->codegen->invalid_instruction;
if (pointee->special != ConstValSpecialRuntime) {
IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
source_instr->source_node, wanted_type);
@@ -9446,15 +9530,17 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
}
static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *value, TypeTableEntry *wanted_type)
+ IrInstruction *value, ZigType *wanted_type)
{
wanted_type = adjust_slice_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment);
if (instr_is_comptime(value)) {
- ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &value->value);
+ ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node);
+ if (pointee == nullptr)
+ return ira->codegen->invalid_instruction;
if (pointee->special != ConstValSpecialRuntime) {
- assert(value->value.type->id == TypeTableEntryIdPointer);
- TypeTableEntry *array_type = value->value.type->data.pointer.child_type;
+ assert(value->value.type->id == ZigTypeIdPointer);
+ ZigType *array_type = value->value.type->data.pointer.child_type;
assert(is_slice(wanted_type));
bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
@@ -9475,10 +9561,10 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
return result;
}
-static bool is_container(TypeTableEntry *type) {
- return type->id == TypeTableEntryIdStruct ||
- type->id == TypeTableEntryIdEnum ||
- type->id == TypeTableEntryIdUnion;
+static bool is_container(ZigType *type) {
+ return type->id == ZigTypeIdStruct ||
+ type->id == ZigTypeIdEnum ||
+ type->id == ZigTypeIdUnion;
}
static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {
@@ -9496,6 +9582,19 @@ static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstr
return new_bb;
}
+static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {
+ assert(ref_old_instruction != nullptr);
+ IrBasicBlock *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);
+ if (new_bb->must_be_comptime_source_instr) {
+ ErrorMsg *msg = ir_add_error(ira, ref_old_instruction,
+ buf_sprintf("control flow attempts to use compile-time variable at runtime"));
+ add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node,
+ buf_sprintf("compile-time variable assigned here"));
+ return nullptr;
+ }
+ return new_bb;
+}
+
static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) {
ira->instruction_index = 0;
ira->old_irb.current_basic_block = old_bb;
@@ -9541,7 +9640,7 @@ static void ir_finish_bb(IrAnalyze *ira) {
}
}
-static TypeTableEntry *ir_unreach_error(IrAnalyze *ira) {
+static ZigType *ir_unreach_error(IrAnalyze *ira) {
ira->old_bb_index = SIZE_MAX;
ira->new_irb.exec->invalid = true;
return ira->codegen->builtin_types.entry_unreachable;
@@ -9564,7 +9663,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru
return true;
}
-static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) {
+static ZigType *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) {
if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) {
if (!ir_emit_backward_branch(ira, source_instruction))
return ir_unreach_error(ira);
@@ -9575,8 +9674,8 @@ static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instru
return ira->codegen->builtin_types.entry_unreachable;
}
-static TypeTableEntry *ir_finish_anal(IrAnalyze *ira, TypeTableEntry *result_type) {
- if (result_type->id == TypeTableEntryIdUnreachable)
+static ZigType *ir_finish_anal(IrAnalyze *ira, ZigType *result_type) {
+ if (result_type->id == ZigTypeIdUnreachable)
ir_finish_bb(ira);
return result_type;
}
@@ -9595,16 +9694,16 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in
return &new_instruction->value;
}
-static TypeTableEntry *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) {
+static ZigType *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) {
ir_build_const_from(ira, instruction);
return ira->codegen->builtin_types.entry_void;
}
static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
- ConstExprValue *pointee, TypeTableEntry *pointee_type,
+ ConstExprValue *pointee, ZigType *pointee_type,
ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
{
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0);
IrInstruction *const_instr = ir_get_const(ira, instruction);
ConstExprValue *const_val = &const_instr->value;
@@ -9615,8 +9714,8 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
return const_instr;
}
-static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
- ConstExprValue *pointee, TypeTableEntry *pointee_type,
+static ZigType *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction,
+ ConstExprValue *pointee, ZigType *pointee_type,
ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile)
{
IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee,
@@ -9626,7 +9725,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr
return const_instr->value.type;
}
-static TypeTableEntry *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value) {
+static ZigType *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value) {
ConstExprValue *const_val = ir_build_const_from(ira, instruction);
bigint_init_unsigned(&const_val->data.x_bigint, value);
return ira->codegen->builtin_types.entry_usize;
@@ -9659,8 +9758,8 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un
}
IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
- TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,
- FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
+ ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,
+ ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
IrExecutable *parent_exec)
{
if (expected_type != nullptr && type_is_invalid(expected_type))
@@ -9697,7 +9796,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
analyzed_executable->backward_branch_count = backward_branch_count;
analyzed_executable->backward_branch_quota = backward_branch_quota;
analyzed_executable->begin_scope = scope;
- TypeTableEntry *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, node);
+ ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, node);
if (type_is_invalid(result_type))
return codegen->invalid_instruction;
@@ -9710,11 +9809,11 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
return ir_exec_const_result(codegen, analyzed_executable);
}
-static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
+static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
if (type_is_invalid(type_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (type_value->value.type->id != TypeTableEntryIdMetaType) {
+ if (type_value->value.type->id != ZigTypeIdMetaType) {
ir_add_error(ira, type_value,
buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -9727,14 +9826,14 @@ static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value
return const_val->data.x_type;
}
-static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
+static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
if (fn_value == ira->codegen->invalid_instruction)
return nullptr;
if (type_is_invalid(fn_value->value.type))
return nullptr;
- if (fn_value->value.type->id != TypeTableEntryIdFn) {
+ if (fn_value->value.type->id != ZigTypeIdFn) {
ir_add_error_node(ira, fn_value->source_node,
buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name)));
return nullptr;
@@ -9748,11 +9847,11 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
return const_val->data.x_ptr.data.fn.fn_entry;
}
-static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {
- assert(wanted_type->id == TypeTableEntryIdOptional);
+static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
+ assert(wanted_type->id == ZigTypeIdOptional);
if (instr_is_comptime(value)) {
- TypeTableEntry *payload_type = wanted_type->data.maybe.child_type;
+ ZigType *payload_type = wanted_type->data.maybe.child_type;
IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
if (type_is_invalid(casted_payload->value.type))
return ira->codegen->invalid_instruction;
@@ -9781,12 +9880,12 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
}
static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *value, TypeTableEntry *wanted_type)
+ IrInstruction *value, ZigType *wanted_type)
{
- assert(wanted_type->id == TypeTableEntryIdErrorUnion);
+ assert(wanted_type->id == ZigTypeIdErrorUnion);
if (instr_is_comptime(value)) {
- TypeTableEntry *payload_type = wanted_type->data.error_union.payload_type;
+ ZigType *payload_type = wanted_type->data.error_union.payload_type;
IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
if (type_is_invalid(casted_payload->value.type))
return ira->codegen->invalid_instruction;
@@ -9812,10 +9911,10 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
}
static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
- TypeTableEntry *wanted_type)
+ ZigType *wanted_type)
{
- assert(value->value.type->id == TypeTableEntryIdErrorSet);
- assert(wanted_type->id == TypeTableEntryIdErrorSet);
+ assert(value->value.type->id == ZigTypeIdErrorSet);
+ assert(wanted_type->id == ZigTypeIdErrorSet);
if (instr_is_comptime(value)) {
ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
@@ -9854,8 +9953,8 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
return result;
}
-static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {
- assert(wanted_type->id == TypeTableEntryIdErrorUnion);
+static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
+ assert(wanted_type->id == ZigTypeIdErrorUnion);
IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
@@ -9881,7 +9980,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
}
static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *value, TypeTableEntry *wanted_type)
+ IrInstruction *value, ZigType *wanted_type)
{
if (instr_is_comptime(value)) {
ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
@@ -9905,9 +10004,9 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
source_instr->source_node, value, true, false);
new_instruction->value.type = wanted_type;
- TypeTableEntry *child_type = wanted_type->data.pointer.child_type;
+ ZigType *child_type = wanted_type->data.pointer.child_type;
if (type_has_bits(child_type)) {
- FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
assert(fn_entry);
fn_entry->alloca_list.append(new_instruction);
}
@@ -9916,8 +10015,8 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_
}
}
-static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) {
- assert(wanted_type->id == TypeTableEntryIdOptional);
+static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {
+ assert(wanted_type->id == ZigTypeIdOptional);
assert(instr_is_comptime(value));
ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
@@ -9950,14 +10049,14 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
get_abi_alignment(ira->codegen, value->value.type));
}
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type,
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type,
is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0);
IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope,
source_instruction->source_node, value, is_const, is_volatile);
new_instruction->value.type = ptr_type;
new_instruction->value.data.rh_ptr = RuntimeHintPtrStack;
if (type_has_bits(ptr_type)) {
- FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
assert(fn_entry);
fn_entry->alloca_list.append(new_instruction);
}
@@ -9965,7 +10064,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
}
static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *array_arg, TypeTableEntry *wanted_type)
+ IrInstruction *array_arg, ZigType *wanted_type)
{
assert(is_slice(wanted_type));
// In this function we honor the const-ness of wanted_type, because
@@ -9973,14 +10072,14 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
IrInstruction *array_ptr = nullptr;
IrInstruction *array;
- if (array_arg->value.type->id == TypeTableEntryIdPointer) {
+ if (array_arg->value.type->id == ZigTypeIdPointer) {
array = ir_get_deref(ira, source_instr, array_arg);
array_ptr = array_arg;
} else {
array = array_arg;
}
- TypeTableEntry *array_type = array->value.type;
- assert(array_type->id == TypeTableEntryIdArray);
+ ZigType *array_type = array->value.type;
+ assert(array_type->id == ZigTypeIdArray);
if (instr_is_comptime(array)) {
IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
@@ -10011,12 +10110,12 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
}
static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *target, TypeTableEntry *wanted_type)
+ IrInstruction *target, ZigType *wanted_type)
{
Error err;
- assert(wanted_type->id == TypeTableEntryIdInt);
+ assert(wanted_type->id == ZigTypeIdInt);
- TypeTableEntry *actual_type = target->value.type;
+ ZigType *actual_type = target->value.type;
if ((err = ensure_complete_type(ira->codegen, actual_type)))
return ira->codegen->invalid_instruction;
@@ -10028,7 +10127,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
return ira->codegen->invalid_instruction;
}
- assert(actual_type->id == TypeTableEntryIdEnum);
+ assert(actual_type->id == ZigTypeIdEnum);
if (instr_is_comptime(target)) {
ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
@@ -10047,10 +10146,10 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
}
static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *target, TypeTableEntry *wanted_type)
+ IrInstruction *target, ZigType *wanted_type)
{
- assert(target->value.type->id == TypeTableEntryIdUnion);
- assert(wanted_type->id == TypeTableEntryIdEnum);
+ assert(target->value.type->id == ZigTypeIdUnion);
+ assert(wanted_type->id == ZigTypeIdEnum);
assert(wanted_type == target->value.type->data.unionation.tag_type);
if (instr_is_comptime(target)) {
@@ -10072,7 +10171,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
}
static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *target, TypeTableEntry *wanted_type)
+ IrInstruction *target, ZigType *wanted_type)
{
IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
source_instr->source_node, wanted_type);
@@ -10081,11 +10180,11 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc
}
static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *target, TypeTableEntry *wanted_type)
+ IrInstruction *target, ZigType *wanted_type)
{
Error err;
- assert(wanted_type->id == TypeTableEntryIdUnion);
- assert(target->value.type->id == TypeTableEntryIdEnum);
+ assert(wanted_type->id == ZigTypeIdUnion);
+ assert(target->value.type->id == ZigTypeIdEnum);
if (instr_is_comptime(target)) {
ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
@@ -10140,15 +10239,15 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
}
static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *target, TypeTableEntry *wanted_type)
+ IrInstruction *target, ZigType *wanted_type)
{
- assert(wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdFloat);
+ assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
if (instr_is_comptime(target)) {
ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
if (!val)
return ira->codegen->invalid_instruction;
- if (wanted_type->id == TypeTableEntryIdInt) {
+ if (wanted_type->id == ZigTypeIdInt) {
if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {
ir_add_error(ira, source_instr,
buf_sprintf("attempt to cast negative value to unsigned integer"));
@@ -10166,7 +10265,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
source_instr->source_node, wanted_type);
result->value.type = wanted_type;
- if (wanted_type->id == TypeTableEntryIdInt) {
+ if (wanted_type->id == ZigTypeIdInt) {
bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);
} else {
float_init_float(&result->value, val);
@@ -10181,12 +10280,12 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
}
static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *target, TypeTableEntry *wanted_type)
+ IrInstruction *target, ZigType *wanted_type)
{
Error err;
- assert(wanted_type->id == TypeTableEntryIdEnum);
+ assert(wanted_type->id == ZigTypeIdEnum);
- TypeTableEntry *actual_type = target->value.type;
+ ZigType *actual_type = target->value.type;
if ((err = ensure_complete_type(ira->codegen, wanted_type)))
return ira->codegen->invalid_instruction;
@@ -10199,7 +10298,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
return ira->codegen->invalid_instruction;
}
- assert(actual_type->id == TypeTableEntryIdInt);
+ assert(actual_type->id == ZigTypeIdInt);
if (instr_is_comptime(target)) {
ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
@@ -10231,7 +10330,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
}
static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *target, TypeTableEntry *wanted_type)
+ IrInstruction *target, ZigType *wanted_type)
{
ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
if (!val)
@@ -10239,9 +10338,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
source_instr->source_node, wanted_type);
- if (wanted_type->id == TypeTableEntryIdComptimeFloat) {
+ if (wanted_type->id == ZigTypeIdComptimeFloat) {
float_init_float(&result->value, val);
- } else if (wanted_type->id == TypeTableEntryIdComptimeInt) {
+ } else if (wanted_type->id == ZigTypeIdComptimeInt) {
bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);
} else {
zig_unreachable();
@@ -10250,11 +10349,11 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
}
static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
- TypeTableEntry *wanted_type)
+ ZigType *wanted_type)
{
- assert(target->value.type->id == TypeTableEntryIdInt);
+ assert(target->value.type->id == ZigTypeIdInt);
assert(!target->value.type->data.integral.is_signed);
- assert(wanted_type->id == TypeTableEntryIdErrorSet);
+ assert(wanted_type->id == ZigTypeIdErrorSet);
if (instr_is_comptime(target)) {
ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
@@ -10315,11 +10414,11 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
}
static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
- TypeTableEntry *wanted_type)
+ ZigType *wanted_type)
{
- assert(wanted_type->id == TypeTableEntryIdInt);
+ assert(wanted_type->id == ZigTypeIdInt);
- TypeTableEntry *err_type = target->value.type;
+ ZigType *err_type = target->value.type;
if (instr_is_comptime(target)) {
ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
@@ -10330,9 +10429,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
source_instr->source_node, wanted_type);
ErrorTableEntry *err;
- if (err_type->id == TypeTableEntryIdErrorUnion) {
+ if (err_type->id == ZigTypeIdErrorUnion) {
err = val->data.x_err_union.err;
- } else if (err_type->id == TypeTableEntryIdErrorSet) {
+ } else if (err_type->id == ZigTypeIdErrorSet) {
err = val->data.x_err_set;
} else {
zig_unreachable();
@@ -10353,10 +10452,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
return result;
}
- TypeTableEntry *err_set_type;
- if (err_type->id == TypeTableEntryIdErrorUnion) {
+ ZigType *err_set_type;
+ if (err_type->id == ZigTypeIdErrorUnion) {
err_set_type = err_type->data.error_union.err_set_type;
- } else if (err_type->id == TypeTableEntryIdErrorSet) {
+ } else if (err_type->id == ZigTypeIdErrorSet) {
err_set_type = err_type;
} else {
zig_unreachable();
@@ -10395,12 +10494,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
}
static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
- TypeTableEntry *wanted_type)
+ ZigType *wanted_type)
{
- assert(wanted_type->id == TypeTableEntryIdPointer);
+ assert(wanted_type->id == ZigTypeIdPointer);
wanted_type = adjust_ptr_align(ira->codegen, wanted_type, target->value.type->data.pointer.alignment);
- TypeTableEntry *array_type = wanted_type->data.pointer.child_type;
- assert(array_type->id == TypeTableEntryIdArray);
+ ZigType *array_type = wanted_type->data.pointer.child_type;
+ assert(array_type->id == ZigTypeIdArray);
assert(array_type->data.array.len == 1);
if (instr_is_comptime(target)) {
@@ -10408,8 +10507,10 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
if (!val)
return ira->codegen->invalid_instruction;
- assert(val->type->id == TypeTableEntryIdPointer);
- ConstExprValue *pointee = const_ptr_pointee(ira->codegen, val);
+ assert(val->type->id == ZigTypeIdPointer);
+ ConstExprValue *pointee = ir_const_ptr_pointee(ira, val, source_instr->source_node);
+ if (pointee == nullptr)
+ return ira->codegen->invalid_instruction;
if (pointee->special != ConstValSpecialRuntime) {
ConstExprValue *array_val = create_const_vals(1);
array_val->special = ConstValSpecialStatic;
@@ -10529,10 +10630,10 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
}
static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,
- TypeTableEntry *wanted_type, IrInstruction *value)
+ ZigType *wanted_type, IrInstruction *value)
{
Error err;
- TypeTableEntry *actual_type = value->value.type;
+ ZigType *actual_type = value->value.type;
AstNode *source_node = source_instr->source_node;
if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
@@ -10547,8 +10648,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// widening conversion
- if (wanted_type->id == TypeTableEntryIdInt &&
- actual_type->id == TypeTableEntryIdInt &&
+ if (wanted_type->id == ZigTypeIdInt &&
+ actual_type->id == ZigTypeIdInt &&
wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed &&
wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count)
{
@@ -10556,16 +10657,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// small enough unsigned ints can get casted to large enough signed ints
- if (wanted_type->id == TypeTableEntryIdInt && wanted_type->data.integral.is_signed &&
- actual_type->id == TypeTableEntryIdInt && !actual_type->data.integral.is_signed &&
+ if (wanted_type->id == ZigTypeIdInt && wanted_type->data.integral.is_signed &&
+ actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed &&
wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count)
{
return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
}
// float widening conversion
- if (wanted_type->id == TypeTableEntryIdFloat &&
- actual_type->id == TypeTableEntryIdFloat &&
+ if (wanted_type->id == ZigTypeIdFloat &&
+ actual_type->id == ZigTypeIdFloat &&
wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count)
{
return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
@@ -10573,9 +10674,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// cast from [N]T to []const T
- if (is_slice(wanted_type) && actual_type->id == TypeTableEntryIdArray) {
- TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {
+ ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
+ assert(ptr_type->id == ZigTypeIdPointer);
if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
source_node, false).id == ConstCastResultIdOk)
@@ -10586,14 +10687,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// cast from *const [N]T to []const T
if (is_slice(wanted_type) &&
- actual_type->id == TypeTableEntryIdPointer &&
+ actual_type->id == ZigTypeIdPointer &&
actual_type->data.pointer.is_const &&
- actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)
+ actual_type->data.pointer.child_type->id == ZigTypeIdArray)
{
- TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
+ assert(ptr_type->id == ZigTypeIdPointer);
- TypeTableEntry *array_type = actual_type->data.pointer.child_type;
+ ZigType *array_type = actual_type->data.pointer.child_type;
if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&
types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, array_type->data.array.child_type,
@@ -10604,14 +10705,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// cast from [N]T to *const []const T
- if (wanted_type->id == TypeTableEntryIdPointer &&
+ if (wanted_type->id == ZigTypeIdPointer &&
wanted_type->data.pointer.is_const &&
is_slice(wanted_type->data.pointer.child_type) &&
- actual_type->id == TypeTableEntryIdArray)
+ actual_type->id == ZigTypeIdArray)
{
- TypeTableEntry *ptr_type =
+ ZigType *ptr_type =
wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ assert(ptr_type->id == ZigTypeIdPointer);
if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
source_node, false).id == ConstCastResultIdOk)
@@ -10629,13 +10730,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// cast from [N]T to ?[]const T
- if (wanted_type->id == TypeTableEntryIdOptional &&
+ if (wanted_type->id == ZigTypeIdOptional &&
is_slice(wanted_type->data.maybe.child_type) &&
- actual_type->id == TypeTableEntryIdArray)
+ actual_type->id == ZigTypeIdArray)
{
- TypeTableEntry *ptr_type =
+ ZigType *ptr_type =
wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ assert(ptr_type->id == ZigTypeIdPointer);
if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
source_node, false).id == ConstCastResultIdOk)
@@ -10653,11 +10754,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// *[N]T to [*]T
- if (wanted_type->id == TypeTableEntryIdPointer &&
+ if (wanted_type->id == ZigTypeIdPointer &&
wanted_type->data.pointer.ptr_len == PtrLenUnknown &&
- actual_type->id == TypeTableEntryIdPointer &&
+ actual_type->id == ZigTypeIdPointer &&
actual_type->data.pointer.ptr_len == PtrLenSingle &&
- actual_type->data.pointer.child_type->id == TypeTableEntryIdArray &&
+ actual_type->data.pointer.child_type->id == ZigTypeIdArray &&
actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment &&
types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
actual_type->data.pointer.child_type->data.array.child_type, source_node,
@@ -10668,12 +10769,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// *[N]T to []T
if (is_slice(wanted_type) &&
- actual_type->id == TypeTableEntryIdPointer &&
+ actual_type->id == ZigTypeIdPointer &&
actual_type->data.pointer.ptr_len == PtrLenSingle &&
- actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)
+ actual_type->data.pointer.child_type->id == ZigTypeIdArray)
{
- TypeTableEntry *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
- assert(slice_ptr_type->id == TypeTableEntryIdPointer);
+ ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
+ assert(slice_ptr_type->id == ZigTypeIdPointer);
if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type,
actual_type->data.pointer.child_type->data.array.child_type, source_node,
!slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk)
@@ -10685,23 +10786,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// cast from T to ?T
// note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism
- if (wanted_type->id == TypeTableEntryIdOptional) {
- TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type;
+ if (wanted_type->id == ZigTypeIdOptional) {
+ ZigType *wanted_child_type = wanted_type->data.maybe.child_type;
if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node,
false).id == ConstCastResultIdOk)
{
return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
- } else if (actual_type->id == TypeTableEntryIdComptimeInt ||
- actual_type->id == TypeTableEntryIdComptimeFloat)
+ } else if (actual_type->id == ZigTypeIdComptimeInt ||
+ actual_type->id == ZigTypeIdComptimeFloat)
{
if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
} else {
return ira->codegen->invalid_instruction;
}
- } else if (wanted_child_type->id == TypeTableEntryIdPointer &&
+ } else if (wanted_child_type->id == ZigTypeIdPointer &&
wanted_child_type->data.pointer.is_const &&
- (actual_type->id == TypeTableEntryIdPointer || is_container(actual_type)))
+ (actual_type->id == ZigTypeIdPointer || is_container(actual_type)))
{
IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_child_type, value);
if (type_is_invalid(cast1->value.type))
@@ -10713,36 +10814,38 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
return cast2;
} else if (
- wanted_child_type->id == TypeTableEntryIdPointer &&
+ wanted_child_type->id == ZigTypeIdPointer &&
wanted_child_type->data.pointer.ptr_len == PtrLenUnknown &&
- actual_type->id == TypeTableEntryIdPointer &&
+ actual_type->id == ZigTypeIdPointer &&
actual_type->data.pointer.ptr_len == PtrLenSingle &&
- actual_type->data.pointer.child_type->id == TypeTableEntryIdArray &&
+ actual_type->data.pointer.child_type->id == ZigTypeIdArray &&
actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment &&
types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,
actual_type->data.pointer.child_type->data.array.child_type, source_node,
!wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)
{
IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_child_type);
+ if (type_is_invalid(cast1->value.type))
+ return ira->codegen->invalid_instruction;
return ir_analyze_maybe_wrap(ira, source_instr, cast1, wanted_type);
}
}
// cast from null literal to maybe type
- if (wanted_type->id == TypeTableEntryIdOptional &&
- actual_type->id == TypeTableEntryIdNull)
+ if (wanted_type->id == ZigTypeIdOptional &&
+ actual_type->id == ZigTypeIdNull)
{
return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);
}
// cast from child type of error type to error type
- if (wanted_type->id == TypeTableEntryIdErrorUnion) {
+ if (wanted_type->id == ZigTypeIdErrorUnion) {
if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type,
source_node, false).id == ConstCastResultIdOk)
{
return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
- } else if (actual_type->id == TypeTableEntryIdComptimeInt ||
- actual_type->id == TypeTableEntryIdComptimeFloat)
+ } else if (actual_type->id == ZigTypeIdComptimeInt ||
+ actual_type->id == ZigTypeIdComptimeFloat)
{
if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
@@ -10753,13 +10856,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// cast from [N]T to E![]const T
- if (wanted_type->id == TypeTableEntryIdErrorUnion &&
+ if (wanted_type->id == ZigTypeIdErrorUnion &&
is_slice(wanted_type->data.error_union.payload_type) &&
- actual_type->id == TypeTableEntryIdArray)
+ actual_type->id == ZigTypeIdArray)
{
- TypeTableEntry *ptr_type =
+ ZigType *ptr_type =
wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry;
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ assert(ptr_type->id == ZigTypeIdPointer);
if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
source_node, false).id == ConstCastResultIdOk)
@@ -10777,22 +10880,22 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// cast from error set to error union type
- if (wanted_type->id == TypeTableEntryIdErrorUnion &&
- actual_type->id == TypeTableEntryIdErrorSet)
+ if (wanted_type->id == ZigTypeIdErrorUnion &&
+ actual_type->id == ZigTypeIdErrorSet)
{
return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type);
}
// cast from T to E!?T
- if (wanted_type->id == TypeTableEntryIdErrorUnion &&
- wanted_type->data.error_union.payload_type->id == TypeTableEntryIdOptional &&
- actual_type->id != TypeTableEntryIdOptional)
+ if (wanted_type->id == ZigTypeIdErrorUnion &&
+ wanted_type->data.error_union.payload_type->id == ZigTypeIdOptional &&
+ actual_type->id != ZigTypeIdOptional)
{
- TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;
+ ZigType *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;
if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk ||
- actual_type->id == TypeTableEntryIdNull ||
- actual_type->id == TypeTableEntryIdComptimeInt ||
- actual_type->id == TypeTableEntryIdComptimeFloat)
+ actual_type->id == ZigTypeIdNull ||
+ actual_type->id == ZigTypeIdComptimeInt ||
+ actual_type->id == ZigTypeIdComptimeFloat)
{
IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
if (type_is_invalid(cast1->value.type))
@@ -10808,12 +10911,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// cast from number literal to another type
// cast from number literal to *const integer
- if (actual_type->id == TypeTableEntryIdComptimeFloat ||
- actual_type->id == TypeTableEntryIdComptimeInt)
+ if (actual_type->id == ZigTypeIdComptimeFloat ||
+ actual_type->id == ZigTypeIdComptimeInt)
{
if ((err = ensure_complete_type(ira->codegen, wanted_type)))
return ira->codegen->invalid_instruction;
- if (wanted_type->id == TypeTableEntryIdEnum) {
+ if (wanted_type->id == ZigTypeIdEnum) {
IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);
if (type_is_invalid(cast1->value.type))
return ira->codegen->invalid_instruction;
@@ -10823,7 +10926,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
return ira->codegen->invalid_instruction;
return cast2;
- } else if (wanted_type->id == TypeTableEntryIdPointer &&
+ } else if (wanted_type->id == ZigTypeIdPointer &&
wanted_type->data.pointer.is_const)
{
IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);
@@ -10837,15 +10940,15 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
return cast2;
} else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
CastOp op;
- if ((actual_type->id == TypeTableEntryIdComptimeFloat &&
- wanted_type->id == TypeTableEntryIdFloat) ||
- (actual_type->id == TypeTableEntryIdComptimeInt &&
- wanted_type->id == TypeTableEntryIdInt))
+ if ((actual_type->id == ZigTypeIdComptimeFloat &&
+ wanted_type->id == ZigTypeIdFloat) ||
+ (actual_type->id == ZigTypeIdComptimeInt &&
+ wanted_type->id == ZigTypeIdInt))
{
op = CastOpNumLitToConcrete;
- } else if (wanted_type->id == TypeTableEntryIdInt) {
+ } else if (wanted_type->id == ZigTypeIdInt) {
op = CastOpFloatToInt;
- } else if (wanted_type->id == TypeTableEntryIdFloat) {
+ } else if (wanted_type->id == ZigTypeIdFloat) {
op = CastOpIntToFloat;
} else {
zig_unreachable();
@@ -10859,14 +10962,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// cast from typed number to integer or float literal.
// works when the number is known at compile time
if (instr_is_comptime(value) &&
- ((actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdComptimeInt) ||
- (actual_type->id == TypeTableEntryIdFloat && wanted_type->id == TypeTableEntryIdComptimeFloat)))
+ ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) ||
+ (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat)))
{
return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type);
}
// cast from union to the enum type of the union
- if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) {
+ if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) {
if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type)))
return ira->codegen->invalid_instruction;
@@ -10876,7 +10979,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// enum to union which has the enum as the tag type
- if (wanted_type->id == TypeTableEntryIdUnion && actual_type->id == TypeTableEntryIdEnum &&
+ if (wanted_type->id == ZigTypeIdUnion && actual_type->id == ZigTypeIdEnum &&
(wanted_type->data.unionation.decl_node->data.container_decl.auto_enum ||
wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
{
@@ -10889,8 +10992,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// enum to &const union which has the enum as the tag type
- if (actual_type->id == TypeTableEntryIdEnum && wanted_type->id == TypeTableEntryIdPointer) {
- TypeTableEntry *union_type = wanted_type->data.pointer.child_type;
+ if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) {
+ ZigType *union_type = wanted_type->data.pointer.child_type;
if (union_type->data.unionation.decl_node->data.container_decl.auto_enum ||
union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)
{
@@ -10912,11 +11015,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// cast from *T to *[1]T
- if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
- actual_type->id == TypeTableEntryIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)
+ if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
+ actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)
{
- TypeTableEntry *array_type = wanted_type->data.pointer.child_type;
- if (array_type->id == TypeTableEntryIdArray && array_type->data.array.len == 1 &&
+ ZigType *array_type = wanted_type->data.pointer.child_type;
+ if (array_type->id == ZigTypeIdArray && array_type->data.array.len == 1 &&
types_match_const_cast_only(ira, array_type->data.array.child_type,
actual_type->data.pointer.child_type, source_node,
!wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
@@ -10936,7 +11039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// cast from T to *T where T is zero bits
- if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
+ if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle &&
types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
{
@@ -10950,13 +11053,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// cast from undefined to anything
- if (actual_type->id == TypeTableEntryIdUndefined) {
+ if (actual_type->id == ZigTypeIdUndefined) {
return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
}
// cast from something to const pointer of it
if (!type_requires_comptime(actual_type)) {
- TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);
+ ZigType *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);
if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node, false).id == ConstCastResultIdOk) {
return ir_analyze_cast_ref(ira, source_instr, value, wanted_type);
}
@@ -10970,7 +11073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
return ira->codegen->invalid_instruction;
}
-static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type) {
+static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {
assert(value);
assert(value != ira->codegen->invalid_instruction);
assert(!expected_type || !type_is_invalid(expected_type));
@@ -10980,23 +11083,25 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ
return value; // anything will do
if (expected_type == value->value.type)
return value; // match
- if (value->value.type->id == TypeTableEntryIdUnreachable)
+ if (value->value.type->id == ZigTypeIdUnreachable)
return value;
return ir_analyze_cast(ira, value, expected_type, value);
}
static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) {
- TypeTableEntry *type_entry = ptr->value.type;
+ ZigType *type_entry = ptr->value.type;
if (type_is_invalid(type_entry)) {
return ira->codegen->invalid_instruction;
- } else if (type_entry->id == TypeTableEntryIdPointer) {
- TypeTableEntry *child_type = type_entry->data.pointer.child_type;
+ } else if (type_entry->id == ZigTypeIdPointer) {
+ ZigType *child_type = type_entry->data.pointer.child_type;
if (instr_is_comptime(ptr)) {
if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst ||
ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar)
{
- ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &ptr->value);
+ ConstExprValue *pointee = ir_const_ptr_pointee(ira, &ptr->value, source_instruction->source_node);
+ if (pointee == nullptr)
+ return ira->codegen->invalid_instruction;
if (pointee->special != ConstValSpecialRuntime) {
IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,
source_instruction->source_node, child_type);
@@ -11019,7 +11124,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
}
}
-static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,
+static ZigType *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,
bool is_const, bool is_volatile)
{
IrInstruction *result = ir_get_ref(ira, source_instruction, value, is_const, is_volatile);
@@ -11054,7 +11159,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out
return true;
}
-static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *int_type, uint64_t *out) {
+static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) {
if (type_is_invalid(value->value.type))
return false;
@@ -11103,8 +11208,8 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
return false;
ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder");
- assert(atomic_order_val->type->id == TypeTableEntryIdMetaType);
- TypeTableEntry *atomic_order_type = atomic_order_val->data.x_type;
+ assert(atomic_order_val->type->id == ZigTypeIdMetaType);
+ ZigType *atomic_order_type = atomic_order_val->data.x_type;
IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
if (type_is_invalid(casted_value->value.type))
@@ -11123,8 +11228,8 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
return false;
ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp");
- assert(atomic_rmw_op_val->type->id == TypeTableEntryIdMetaType);
- TypeTableEntry *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;
+ assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType);
+ ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type;
IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);
if (type_is_invalid(casted_value->value.type))
@@ -11143,8 +11248,8 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
return false;
ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage");
- assert(global_linkage_val->type->id == TypeTableEntryIdMetaType);
- TypeTableEntry *global_linkage_type = global_linkage_val->data.x_type;
+ assert(global_linkage_val->type->id == ZigTypeIdMetaType);
+ ZigType *global_linkage_type = global_linkage_val->data.x_type;
IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
if (type_is_invalid(casted_value->value.type))
@@ -11163,8 +11268,8 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
return false;
ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode");
- assert(float_mode_val->type->id == TypeTableEntryIdMetaType);
- TypeTableEntry *float_mode_type = float_mode_val->data.x_type;
+ assert(float_mode_val->type->id == ZigTypeIdMetaType);
+ ZigType *float_mode_type = float_mode_val->data.x_type;
IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);
if (type_is_invalid(casted_value->value.type))
@@ -11183,10 +11288,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
if (type_is_invalid(value->value.type))
return nullptr;
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
true, false, PtrLenUnknown,
get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *str_type = get_slice_type(ira->codegen, ptr_type);
+ ZigType *str_type = get_slice_type(ira->codegen, ptr_type);
IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
if (type_is_invalid(casted_value->value.type))
return nullptr;
@@ -11219,7 +11324,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
return result;
}
-static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
IrInstructionAddImplicitReturnType *instruction)
{
IrInstruction *value = instruction->value->other;
@@ -11233,7 +11338,7 @@ static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
return out_val->type;
}
-static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_return(IrAnalyze *ira,
IrInstructionReturn *return_instruction)
{
IrInstruction *value = return_instruction->value->other;
@@ -11245,7 +11350,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
return ir_unreach_error(ira);
if (casted_value->value.special == ConstValSpecialRuntime &&
- casted_value->value.type->id == TypeTableEntryIdPointer &&
+ casted_value->value.type->id == ZigTypeIdPointer &&
casted_value->value.data.rh_ptr == RuntimeHintPtrStack)
{
ir_add_error(ira, casted_value, buf_sprintf("function returns address of local variable"));
@@ -11258,13 +11363,13 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
return ir_finish_anal(ira, result->value.type);
}
-static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {
+static ZigType *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) {
ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base);
*out_val = const_instruction->base.value;
return const_instruction->base.value.type;
}
-static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
+static ZigType *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
IrInstruction *op1 = bin_op_instruction->op1->other;
if (type_is_invalid(op1->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -11273,7 +11378,7 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
if (type_is_invalid(op2->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
+ ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type);
if (casted_op1 == ira->codegen->invalid_instruction)
@@ -11293,8 +11398,8 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
if (op2_val == nullptr)
return ira->codegen->builtin_types.entry_invalid;
- assert(casted_op1->value.type->id == TypeTableEntryIdBool);
- assert(casted_op2->value.type->id == TypeTableEntryIdBool);
+ assert(casted_op1->value.type->id == ZigTypeIdBool);
+ assert(casted_op2->value.type->id == ZigTypeIdBool);
if (bin_op_instruction->op_id == IrBinOpBoolOr) {
out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool;
} else if (bin_op_instruction->op_id == IrBinOpBoolAnd) {
@@ -11338,7 +11443,7 @@ static bool optional_value_is_null(ConstExprValue *val) {
}
}
-static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
+static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
Error err;
IrInstruction *op1 = bin_op_instruction->op1->other;
IrInstruction *op2 = bin_op_instruction->op2->other;
@@ -11347,19 +11452,19 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
IrBinOp op_id = bin_op_instruction->op_id;
bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
if (is_equality_cmp &&
- ((op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdOptional) ||
- (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdOptional) ||
- (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull)))
+ ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) ||
+ (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional) ||
+ (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull)))
{
- if (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull) {
+ if (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) {
ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
out_val->data.x_bool = (op_id == IrBinOpCmpEq);
return ira->codegen->builtin_types.entry_bool;
}
IrInstruction *maybe_op;
- if (op1->value.type->id == TypeTableEntryIdNull) {
+ if (op1->value.type->id == ZigTypeIdNull) {
maybe_op = op2;
- } else if (op2->value.type->id == TypeTableEntryIdNull) {
+ } else if (op2->value.type->id == ZigTypeIdNull) {
maybe_op = op1;
} else {
zig_unreachable();
@@ -11386,12 +11491,12 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
return ira->codegen->builtin_types.entry_bool;
}
- if (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) {
+ if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) {
if (!is_equality_cmp) {
ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node);
+ ZigType *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node);
if (type_is_invalid(intersect_type)) {
return ira->codegen->builtin_types.entry_invalid;
}
@@ -11472,7 +11577,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
}
IrInstruction *instructions[] = {op1, op2};
- TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2);
+ ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2);
if (type_is_invalid(resolved_type))
return resolved_type;
if ((err = type_ensure_zero_bits_known(ira->codegen, resolved_type)))
@@ -11480,42 +11585,42 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
bool operator_allowed;
switch (resolved_type->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable(); // handled above
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
operator_allowed = true;
break;
- case TypeTableEntryIdBool:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdPromise:
- case TypeTableEntryIdEnum:
+ case ZigTypeIdBool:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdPointer:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdFn:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdPromise:
+ case ZigTypeIdEnum:
operator_allowed = is_equality_cmp;
break;
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdUnion:
operator_allowed = false;
break;
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr;
break;
}
@@ -11543,10 +11648,10 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
return ira->codegen->builtin_types.entry_invalid;
bool answer;
- if (resolved_type->id == TypeTableEntryIdComptimeFloat || resolved_type->id == TypeTableEntryIdFloat) {
+ if (resolved_type->id == ZigTypeIdComptimeFloat || resolved_type->id == ZigTypeIdFloat) {
Cmp cmp_result = float_cmp(op1_val, op2_val);
answer = resolve_cmp_op_id(op_id, cmp_result);
- } else if (resolved_type->id == TypeTableEntryIdComptimeInt || resolved_type->id == TypeTableEntryIdInt) {
+ } else if (resolved_type->id == ZigTypeIdComptimeInt || resolved_type->id == ZigTypeIdInt) {
Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint);
answer = resolve_cmp_op_id(op_id, cmp_result);
} else {
@@ -11566,7 +11671,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
}
// some comparisons with unsigned numbers can be evaluated
- if (resolved_type->id == TypeTableEntryIdInt && !resolved_type->data.integral.is_signed) {
+ if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) {
ConstExprValue *known_left_val;
IrBinOp flipped_op_id;
if (instr_is_comptime(casted_op1)) {
@@ -11610,18 +11715,18 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
return ira->codegen->builtin_types.entry_bool;
}
-static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
+static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val,
IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val)
{
bool is_int;
bool is_float;
Cmp op2_zcmp;
- if (type_entry->id == TypeTableEntryIdInt || type_entry->id == TypeTableEntryIdComptimeInt) {
+ if (type_entry->id == ZigTypeIdInt || type_entry->id == ZigTypeIdComptimeInt) {
is_int = true;
is_float = false;
op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint);
- } else if (type_entry->id == TypeTableEntryIdFloat ||
- type_entry->id == TypeTableEntryIdComptimeFloat)
+ } else if (type_entry->id == ZigTypeIdFloat ||
+ type_entry->id == ZigTypeIdComptimeFloat)
{
is_int = false;
is_float = true;
@@ -11671,7 +11776,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
bigint_shl(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint);
break;
case IrBinOpBitShiftLeftLossy:
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
bigint_shl_trunc(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
break;
@@ -11698,7 +11803,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
}
break;
case IrBinOpAddWrap:
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
bigint_add_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
break;
@@ -11710,7 +11815,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
}
break;
case IrBinOpSubWrap:
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
bigint_sub_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
break;
@@ -11722,7 +11827,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
}
break;
case IrBinOpMultWrap:
- assert(type_entry->id == TypeTableEntryIdInt);
+ assert(type_entry->id == ZigTypeIdInt);
bigint_mul_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint,
type_entry->data.integral.bit_count, type_entry->data.integral.is_signed);
break;
@@ -11777,7 +11882,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
break;
}
- if (type_entry->id == TypeTableEntryIdInt) {
+ if (type_entry->id == ZigTypeIdInt) {
if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count,
type_entry->data.integral.is_signed))
{
@@ -11790,12 +11895,12 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
return 0;
}
-static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
+static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
IrInstruction *op1 = bin_op_instruction->op1->other;
if (type_is_invalid(op1->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (op1->value.type->id != TypeTableEntryIdInt && op1->value.type->id != TypeTableEntryIdComptimeInt) {
+ if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) {
ir_add_error(ira, &bin_op_instruction->base,
buf_sprintf("bit shifting operation expected integer type, found '%s'",
buf_ptr(&op1->value.type->name)));
@@ -11808,7 +11913,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
IrInstruction *casted_op2;
IrBinOp op_id = bin_op_instruction->op_id;
- if (op1->value.type->id == TypeTableEntryIdComptimeInt) {
+ if (op1->value.type->id == ZigTypeIdComptimeInt) {
casted_op2 = op2;
if (op_id == IrBinOpBitShiftLeftLossy) {
@@ -11822,10 +11927,10 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
return ira->codegen->builtin_types.entry_invalid;
}
} else {
- TypeTableEntry *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
+ ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
op1->value.type->data.integral.bit_count - 1);
if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy &&
- op2->value.type->id == TypeTableEntryIdComptimeInt) {
+ op2->value.type->id == ZigTypeIdComptimeInt) {
if (!bigint_fits_in_bits(&op2->value.data.x_bigint,
shift_amt_type->data.integral.bit_count,
op2->value.data.x_bigint.is_negative)) {
@@ -11879,7 +11984,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false);
return op1->value.type;
- } else if (op1->value.type->id == TypeTableEntryIdComptimeInt) {
+ } else if (op1->value.type->id == ZigTypeIdComptimeInt) {
ir_add_error(ira, &bin_op_instruction->base,
buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
return ira->codegen->builtin_types.entry_invalid;
@@ -11890,7 +11995,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
return op1->value.type;
}
-static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
+static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
IrInstruction *op1 = bin_op_instruction->op1->other;
if (type_is_invalid(op1->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -11902,7 +12007,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
IrBinOp op_id = bin_op_instruction->op_id;
// look for pointer math
- if (op1->value.type->id == TypeTableEntryIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown &&
+ if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown &&
(op_id == IrBinOpAdd || op_id == IrBinOpSub))
{
IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
@@ -11917,19 +12022,19 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
}
IrInstruction *instructions[] = {op1, op2};
- TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2);
+ ZigType *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2);
if (type_is_invalid(resolved_type))
return resolved_type;
- bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdComptimeInt;
- bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdComptimeFloat;
+ bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt;
+ bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat;
bool is_signed_div = (
- (resolved_type->id == TypeTableEntryIdInt && resolved_type->data.integral.is_signed) ||
- resolved_type->id == TypeTableEntryIdFloat ||
- (resolved_type->id == TypeTableEntryIdComptimeFloat &&
+ (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) ||
+ resolved_type->id == ZigTypeIdFloat ||
+ (resolved_type->id == ZigTypeIdComptimeFloat &&
((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) !=
(bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) ||
- (resolved_type->id == TypeTableEntryIdComptimeInt &&
+ (resolved_type->id == ZigTypeIdComptimeInt &&
((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) !=
(bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT)))
);
@@ -12051,7 +12156,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
return ira->codegen->builtin_types.entry_invalid;
}
- if (resolved_type->id == TypeTableEntryIdComptimeInt) {
+ if (resolved_type->id == ZigTypeIdComptimeInt) {
if (op_id == IrBinOpAddWrap) {
op_id = IrBinOpAdd;
} else if (op_id == IrBinOpSubWrap) {
@@ -12111,14 +12216,14 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
}
-static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
+static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
IrInstruction *op1 = instruction->op1->other;
- TypeTableEntry *op1_type = op1->value.type;
+ ZigType *op1_type = op1->value.type;
if (type_is_invalid(op1_type))
return ira->codegen->builtin_types.entry_invalid;
IrInstruction *op2 = instruction->op2->other;
- TypeTableEntry *op2_type = op2->value.type;
+ ZigType *op2_type = op2->value.type;
if (type_is_invalid(op2_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -12133,13 +12238,13 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
ConstExprValue *op1_array_val;
size_t op1_array_index;
size_t op1_array_end;
- TypeTableEntry *child_type;
- if (op1_type->id == TypeTableEntryIdArray) {
+ ZigType *child_type;
+ if (op1_type->id == ZigTypeIdArray) {
child_type = op1_type->data.array.child_type;
op1_array_val = op1_val;
op1_array_index = 0;
op1_array_end = op1_type->data.array.len;
- } else if (op1_type->id == TypeTableEntryIdPointer &&
+ } else if (op1_type->id == ZigTypeIdPointer &&
op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
op1_val->data.x_ptr.data.base_array.is_cstr)
@@ -12149,7 +12254,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index;
op1_array_end = op1_array_val->type->data.array.len - 1;
} else if (is_slice(op1_type)) {
- TypeTableEntry *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry;
+ ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry;
child_type = ptr_type->data.pointer.child_type;
ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index];
assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
@@ -12165,7 +12270,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
ConstExprValue *op2_array_val;
size_t op2_array_index;
size_t op2_array_end;
- if (op2_type->id == TypeTableEntryIdArray) {
+ if (op2_type->id == ZigTypeIdArray) {
if (op2_type->data.array.child_type != child_type) {
ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
buf_ptr(&child_type->name),
@@ -12175,7 +12280,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
op2_array_val = op2_val;
op2_array_index = 0;
op2_array_end = op2_array_val->type->data.array.len;
- } else if (op2_type->id == TypeTableEntryIdPointer &&
+ } else if (op2_type->id == ZigTypeIdPointer &&
op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
op2_val->data.x_ptr.data.base_array.is_cstr)
@@ -12190,7 +12295,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index;
op2_array_end = op2_array_val->type->data.array.len - 1;
} else if (is_slice(op2_type)) {
- TypeTableEntry *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;
+ ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;
if (ptr_type->data.pointer.child_type != child_type) {
ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
buf_ptr(&child_type->name),
@@ -12210,15 +12315,15 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
- TypeTableEntry *result_type;
+ ZigType *result_type;
ConstExprValue *out_array_val;
size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
- if (op1_type->id == TypeTableEntryIdArray || op2_type->id == TypeTableEntryIdArray) {
+ if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
result_type = get_array_type(ira->codegen, child_type, new_len);
out_array_val = out_val;
} else if (is_slice(op1_type) || is_slice(op2_type)) {
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0);
result_type = get_slice_type(ira->codegen, ptr_type);
out_array_val = create_const_vals(1);
@@ -12279,7 +12384,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
return result_type;
}
-static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
+static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
IrInstruction *op1 = instruction->op1->other;
if (type_is_invalid(op1->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -12296,8 +12401,8 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
if (!ir_resolve_usize(ira, op2, &mult_amt))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *array_type = op1->value.type;
- if (array_type->id != TypeTableEntryIdArray) {
+ ZigType *array_type = op1->value.type;
+ if (array_type->id != ZigTypeIdArray) {
ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
}
@@ -12315,7 +12420,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
if (array_val->data.x_array.special == ConstArraySpecialUndef) {
out_val->data.x_array.special = ConstArraySpecialUndef;
- TypeTableEntry *child_type = array_type->data.array.child_type;
+ ZigType *child_type = array_type->data.array.child_type;
return get_array_type(ira->codegen, child_type, new_array_len);
}
@@ -12330,16 +12435,16 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
}
assert(i == new_array_len);
- TypeTableEntry *child_type = array_type->data.array.child_type;
+ ZigType *child_type = array_type->data.array.child_type;
return get_array_type(ira->codegen, child_type, new_array_len);
}
-static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) {
- TypeTableEntry *op1_type = ir_resolve_type(ira, instruction->op1->other);
+static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) {
+ ZigType *op1_type = ir_resolve_type(ira, instruction->op1->other);
if (type_is_invalid(op1_type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *op2_type = ir_resolve_type(ira, instruction->op2->other);
+ ZigType *op2_type = ir_resolve_type(ira, instruction->op2->other);
if (type_is_invalid(op2_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -12365,7 +12470,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction
assert(errors[error_entry->value] == nullptr);
errors[error_entry->value] = error_entry;
}
- TypeTableEntry *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type);
+ ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type);
free(errors);
@@ -12374,7 +12479,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction
return ira->codegen->builtin_types.entry_type;
}
-static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
+static ZigType *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
IrBinOp op_id = bin_op_instruction->op_id;
switch (op_id) {
case IrBinOpInvalid:
@@ -12421,9 +12526,9 @@ static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructi
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) {
+static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) {
Error err;
- VariableTableEntry *var = decl_var_instruction->var;
+ ZigVar *var = decl_var_instruction->var;
IrInstruction *init_value = decl_var_instruction->init_value->other;
if (type_is_invalid(init_value->value.type)) {
@@ -12431,11 +12536,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
return var->value->type;
}
- TypeTableEntry *explicit_type = nullptr;
+ ZigType *explicit_type = nullptr;
IrInstruction *var_type = nullptr;
if (decl_var_instruction->var_type != nullptr) {
var_type = decl_var_instruction->var_type->other;
- TypeTableEntry *proposed_type = ir_resolve_type(ira, var_type);
+ ZigType *proposed_type = ir_resolve_type(ira, var_type);
explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);
if (type_is_invalid(explicit_type)) {
var->value->type = ira->codegen->builtin_types.entry_invalid;
@@ -12450,7 +12555,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
bool var_class_requires_const = false;
- TypeTableEntry *result_type = casted_init_value->value.type;
+ ZigType *result_type = casted_init_value->value.type;
if (type_is_invalid(result_type)) {
result_type = ira->codegen->builtin_types.entry_invalid;
} else {
@@ -12460,8 +12565,8 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
}
if (!type_is_invalid(result_type)) {
- if (result_type->id == TypeTableEntryIdUnreachable ||
- result_type->id == TypeTableEntryIdOpaque)
+ if (result_type->id == ZigTypeIdUnreachable ||
+ result_type->id == ZigTypeIdOpaque)
{
ir_add_error_node(ira, source_node,
buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name)));
@@ -12476,7 +12581,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
}
} else {
if (casted_init_value->value.special == ConstValSpecialStatic &&
- casted_init_value->value.type->id == TypeTableEntryIdFn &&
+ casted_init_value->value.type->id == ZigTypeIdFn &&
casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)
{
var_class_requires_const = true;
@@ -12496,7 +12601,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
// This means that this is actually a different variable due to, e.g. an inline while loop.
// We make a new variable so that it can hold a different type, and so the debug info can
// be distinct.
- VariableTableEntry *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
+ ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
&var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true);
new_var->owner_exec = var->owner_exec;
new_var->align_bytes = var->align_bytes;
@@ -12549,14 +12654,14 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, nullptr, casted_init_value);
- FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
if (fn_entry)
fn_entry->variable_list.append(var);
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {
+static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {
IrInstruction *name = instruction->name->other;
Buf *symbol_name = ir_resolve_str(ira, name);
if (symbol_name == nullptr) {
@@ -12585,12 +12690,12 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
}
switch (target->value.type->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdUnreachable:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdUnreachable:
zig_unreachable();
- case TypeTableEntryIdFn: {
+ case ZigTypeIdFn: {
assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction);
- FnTableEntry *fn_entry = target->value.data.x_ptr.data.fn.fn_entry;
+ ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry;
CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
switch (cc) {
case CallingConventionUnspecified: {
@@ -12611,7 +12716,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
break;
}
} break;
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
if (is_slice(target->value.type)) {
ir_add_error(ira, target,
buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name)));
@@ -12621,26 +12726,26 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here"));
}
break;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
if (target->value.type->data.unionation.layout != ContainerLayoutExtern) {
ErrorMsg *msg = ir_add_error(ira, target,
buf_sprintf("exported union value must be declared extern"));
add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here"));
}
break;
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) {
ErrorMsg *msg = ir_add_error(ira, target,
buf_sprintf("exported enum value must be declared extern"));
add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here"));
}
break;
- case TypeTableEntryIdMetaType: {
- TypeTableEntry *type_value = target->value.data.x_type;
+ case ZigTypeIdMetaType: {
+ ZigType *type_value = target->value.data.x_type;
switch (type_value->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
if (is_slice(type_value)) {
ir_add_error(ira, target,
buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));
@@ -12650,73 +12755,73 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));
}
break;
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
if (type_value->data.unionation.layout != ContainerLayoutExtern) {
ErrorMsg *msg = ir_add_error(ira, target,
buf_sprintf("exported union must be declared extern"));
add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));
}
break;
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
if (type_value->data.enumeration.layout != ContainerLayoutExtern) {
ErrorMsg *msg = ir_add_error(ira, target,
buf_sprintf("exported enum must be declared extern"));
add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));
}
break;
- case TypeTableEntryIdFn: {
+ case ZigTypeIdFn: {
if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
ir_add_error(ira, target,
buf_sprintf("exported function type must specify calling convention"));
}
} break;
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdBool:
break;
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdPromise:
ir_add_error(ira, target,
buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
break;
}
} break;
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name));
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdPromise:
ir_add_error(ira, target,
buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));
break;
@@ -12727,16 +12832,16 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
}
static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) {
- FnTableEntry *fn_entry = exec_fn_entry(exec);
+ ZigFn *fn_entry = exec_fn_entry(exec);
return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing;
}
-static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
IrInstructionErrorReturnTrace *instruction)
{
if (instruction->optional == IrInstructionErrorReturnTrace::Null) {
- TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen);
- TypeTableEntry *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
+ ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen);
+ ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
assert(get_codegen_ptr_type(optional_type) != nullptr);
@@ -12757,25 +12862,25 @@ static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
}
}
-static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_error_union(IrAnalyze *ira,
IrInstructionErrorUnion *instruction)
{
- TypeTableEntry *err_set_type = ir_resolve_type(ira, instruction->err_set->other);
+ ZigType *err_set_type = ir_resolve_type(ira, instruction->err_set->other);
if (type_is_invalid(err_set_type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *payload_type = ir_resolve_type(ira, instruction->payload->other);
+ ZigType *payload_type = ir_resolve_type(ira, instruction->payload->other);
if (type_is_invalid(payload_type))
return ira->codegen->builtin_types.entry_invalid;
- if (err_set_type->id != TypeTableEntryIdErrorSet) {
+ if (err_set_type->id != ZigTypeIdErrorSet) {
ir_add_error(ira, instruction->err_set->other,
buf_sprintf("expected error set type, found type '%s'",
buf_ptr(&err_set_type->name)));
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type);
+ ZigType *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type);
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
out_val->data.x_type = result_type;
@@ -12783,7 +12888,7 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira,
}
IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, ImplicitAllocatorId id) {
- FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
if (parent_fn_entry == nullptr) {
ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available"));
return ira->codegen->invalid_instruction;
@@ -12807,7 +12912,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
}
case ImplicitAllocatorIdLocalVar:
{
- VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
+ ZigVar *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
assert(coro_allocator_var != nullptr);
IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var);
IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst);
@@ -12818,38 +12923,38 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i
zig_unreachable();
}
-static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, FnTableEntry *fn_entry, TypeTableEntry *fn_type,
+static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, ZigFn *fn_entry, ZigType *fn_type,
IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst)
{
Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME);
//Buf *free_field_name = buf_create_from_str("freeFn");
- assert(async_allocator_inst->value.type->id == TypeTableEntryIdPointer);
- TypeTableEntry *container_type = async_allocator_inst->value.type->data.pointer.child_type;
+ assert(async_allocator_inst->value.type->id == ZigTypeIdPointer);
+ ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type;
IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base,
async_allocator_inst, container_type);
if (type_is_invalid(field_ptr_inst->value.type)) {
return ira->codegen->invalid_instruction;
}
- TypeTableEntry *ptr_to_alloc_fn_type = field_ptr_inst->value.type;
- assert(ptr_to_alloc_fn_type->id == TypeTableEntryIdPointer);
+ ZigType *ptr_to_alloc_fn_type = field_ptr_inst->value.type;
+ assert(ptr_to_alloc_fn_type->id == ZigTypeIdPointer);
- TypeTableEntry *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;
- if (alloc_fn_type->id != TypeTableEntryIdFn) {
+ ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type;
+ if (alloc_fn_type->id != ZigTypeIdFn) {
ir_add_error(ira, &call_instruction->base,
buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name)));
return ira->codegen->invalid_instruction;
}
- TypeTableEntry *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type;
- if (alloc_fn_return_type->id != TypeTableEntryIdErrorUnion) {
+ ZigType *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type;
+ if (alloc_fn_return_type->id != ZigTypeIdErrorUnion) {
ir_add_error(ira, fn_ref,
buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name)));
return ira->codegen->invalid_instruction;
}
- TypeTableEntry *alloc_fn_error_set_type = alloc_fn_return_type->data.error_union.err_set_type;
- TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type;
- TypeTableEntry *promise_type = get_promise_type(ira->codegen, return_type);
- TypeTableEntry *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type);
+ ZigType *alloc_fn_error_set_type = alloc_fn_return_type->data.error_union.err_set_type;
+ ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
+ ZigType *promise_type = get_promise_type(ira->codegen, return_type);
+ ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type);
IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node,
fn_entry, fn_ref, arg_count, casted_args, false, FnInlineAuto, true, async_allocator_inst, nullptr);
@@ -12866,7 +12971,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
IrInstruction *casted_arg;
if (param_decl_node->data.param_decl.var_token == nullptr) {
AstNode *param_type_node = param_decl_node->data.param_decl.type;
- TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node);
+ ZigType *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node);
if (type_is_invalid(param_type))
return false;
@@ -12882,7 +12987,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
return false;
Buf *param_name = param_decl_node->data.param_decl.name;
- VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
+ ZigVar *var = add_variable(ira->codegen, param_decl_node,
*exec_scope, param_name, true, arg_val, nullptr);
*exec_scope = var->child_scope;
*next_proto_i += 1;
@@ -12893,7 +12998,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,
IrInstruction *arg, Scope **child_scope, size_t *next_proto_i,
GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args,
- FnTableEntry *impl_fn)
+ ZigFn *impl_fn)
{
AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
assert(param_decl_node->type == NodeTypeParamDecl);
@@ -12906,7 +13011,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
} else {
if (param_decl_node->data.param_decl.var_token == nullptr) {
AstNode *param_type_node = param_decl_node->data.param_decl.type;
- TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node);
+ ZigType *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node);
if (type_is_invalid(param_type))
return false;
@@ -12920,7 +13025,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
}
bool comptime_arg = param_decl_node->data.param_decl.is_inline ||
- casted_arg->value.type->id == TypeTableEntryIdComptimeInt || casted_arg->value.type->id == TypeTableEntryIdComptimeFloat;
+ casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat;
ConstExprValue *arg_val;
@@ -12940,14 +13045,14 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
Buf *param_name = param_decl_node->data.param_decl.name;
if (!param_name) return false;
if (!is_var_args) {
- VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
+ ZigVar *var = add_variable(ira->codegen, param_decl_node,
*child_scope, param_name, true, arg_val, nullptr);
*child_scope = var->child_scope;
var->shadowable = !comptime_arg;
*next_proto_i += 1;
- } else if (casted_arg->value.type->id == TypeTableEntryIdComptimeInt ||
- casted_arg->value.type->id == TypeTableEntryIdComptimeFloat)
+ } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt ||
+ casted_arg->value.type->id == ZigTypeIdComptimeFloat)
{
ir_add_error(ira, casted_arg,
buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
@@ -12972,7 +13077,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
return true;
}
-static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t index) {
+static ZigVar *get_fn_var_by_index(ZigFn *fn_entry, size_t index) {
size_t next_var_i = 0;
FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info;
assert(gen_param_info != nullptr);
@@ -12991,7 +13096,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in
}
static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
- VariableTableEntry *var)
+ ZigVar *var)
{
Error err;
while (var->next_var != nullptr) {
@@ -13002,8 +13107,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
assert(ira->codegen->errors.length != 0);
return ira->codegen->invalid_instruction;
}
- assert(var->value->type);
- if (type_is_invalid(var->value->type))
+ if (var->value->type == nullptr || type_is_invalid(var->value->type))
return ira->codegen->invalid_instruction;
bool comptime_var_mem = ir_get_var_is_comptime(var);
@@ -13061,8 +13165,8 @@ no_mem_slot:
return var_ptr_instruction;
}
-static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction,
- FnTableEntry *fn_entry, TypeTableEntry *fn_type, IrInstruction *fn_ref,
+static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction,
+ ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,
IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline)
{
Error err;
@@ -13082,7 +13186,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0;
for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
ConstExprValue *arg_tuple_value = &call_instruction->args[i]->other->value;
- if (arg_tuple_value->type->id == TypeTableEntryIdArgTuple) {
+ if (arg_tuple_value->type->id == ZigTypeIdArgTuple) {
call_param_count -= 1;
call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -
arg_tuple_value->data.x_arg_tuple.start_index;
@@ -13150,14 +13254,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
size_t next_proto_i = 0;
if (first_arg_ptr) {
- assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
+ assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
bool first_arg_known_bare = false;
if (fn_type_id->next_param_index >= 1) {
- TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type;
+ ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
if (type_is_invalid(param_type))
return ira->codegen->builtin_types.entry_invalid;
- first_arg_known_bare = param_type->id != TypeTableEntryIdPointer;
+ first_arg_known_bare = param_type->id != ZigTypeIdPointer;
}
IrInstruction *first_arg;
@@ -13190,11 +13294,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
}
AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
- TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node);
+ ZigType *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node);
if (type_is_invalid(specified_return_type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *return_type;
- TypeTableEntry *inferred_err_set_type = nullptr;
+ ZigType *return_type;
+ ZigType *inferred_err_set_type = nullptr;
if (fn_proto_node->data.fn_proto.auto_err_set) {
inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry);
return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
@@ -13219,16 +13323,16 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
if (inferred_err_set_type != nullptr) {
inferred_err_set_type->data.error_set.infer_fn = nullptr;
- if (result->value.type->id == TypeTableEntryIdErrorUnion) {
+ if (result->value.type->id == ZigTypeIdErrorUnion) {
if (result->value.data.x_err_union.err != nullptr) {
inferred_err_set_type->data.error_set.err_count = 1;
inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);
inferred_err_set_type->data.error_set.errors[0] = result->value.data.x_err_union.err;
}
- TypeTableEntry *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type;
+ ZigType *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type;
inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count;
inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors;
- } else if (result->value.type->id == TypeTableEntryIdErrorSet) {
+ } else if (result->value.type->id == ZigTypeIdErrorSet) {
inferred_err_set_type->data.error_set.err_count = result->value.type->data.error_set.err_count;
inferred_err_set_type->data.error_set.errors = result->value.type->data.error_set.errors;
}
@@ -13249,10 +13353,10 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
IrInstruction *casted_new_stack = nullptr;
if (call_instruction->new_stack != nullptr) {
- TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
+ ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
false, false, PtrLenUnknown,
get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *u8_slice = get_slice_type(ira->codegen, u8_ptr);
+ ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
IrInstruction *new_stack = call_instruction->new_stack->other;
if (type_is_invalid(new_stack->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -13276,7 +13380,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
if (type_is_invalid(arg->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (arg->value.type->id == TypeTableEntryIdArgTuple) {
+ if (arg->value.type->id == ZigTypeIdArgTuple) {
new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index;
} else {
new_fn_arg_count += 1;
@@ -13287,7 +13391,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
// Fork a scope of the function with known values for the parameters.
Scope *parent_scope = fn_entry->fndef_scope->base.parent;
- FnTableEntry *impl_fn = create_fn(fn_proto_node);
+ ZigFn *impl_fn = create_fn(fn_proto_node);
impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count);
buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name);
impl_fn->fndef_scope = create_fndef_scope(impl_fn->body_node, parent_scope, impl_fn);
@@ -13306,14 +13410,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
size_t next_proto_i = 0;
if (first_arg_ptr) {
- assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
+ assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
bool first_arg_known_bare = false;
if (fn_type_id->next_param_index >= 1) {
- TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type;
+ ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
if (type_is_invalid(param_type))
return ira->codegen->builtin_types.entry_invalid;
- first_arg_known_bare = param_type->id != TypeTableEntryIdPointer;
+ first_arg_known_bare = param_type->id != ZigTypeIdPointer;
}
IrInstruction *first_arg;
@@ -13335,14 +13439,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
bool found_first_var_arg = false;
size_t first_var_arg;
- FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
assert(parent_fn_entry);
for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
IrInstruction *arg = call_instruction->args[call_i]->other;
if (type_is_invalid(arg->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (arg->value.type->id == TypeTableEntryIdArgTuple) {
+ if (arg->value.type->id == ZigTypeIdArgTuple) {
for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index;
arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1)
{
@@ -13354,7 +13458,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
found_first_var_arg = true;
}
- VariableTableEntry *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
+ ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
if (arg_var == nullptr) {
ir_add_error(ira, arg,
buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
@@ -13401,7 +13505,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen,
first_var_arg, inst_fn_type_id.param_count);
- VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
+ ZigVar *var = add_variable(ira->codegen, param_decl_node,
impl_fn->child_scope, param_name, true, var_args_val, nullptr);
impl_fn->child_scope = var->child_scope;
}
@@ -13420,11 +13524,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
if (fn_proto_node->data.fn_proto.return_var_token == nullptr) {
AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
- TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
+ ZigType *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
if (type_is_invalid(specified_return_type))
return ira->codegen->builtin_types.entry_invalid;
if (fn_proto_node->data.fn_proto.auto_err_set) {
- TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);
+ ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);
inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
} else {
inst_fn_type_id.return_type = specified_return_type;
@@ -13442,7 +13546,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
if (call_instruction->is_async) {
AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type;
if (async_allocator_type_node != nullptr) {
- TypeTableEntry *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node);
+ ZigType *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node);
if (type_is_invalid(async_allocator_type))
return ira->codegen->builtin_types.entry_invalid;
inst_fn_type_id.async_allocator_type = async_allocator_type;
@@ -13486,7 +13590,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
ira->codegen->fn_defs.append(impl_fn);
}
- TypeTableEntry *return_type = impl_fn->type_entry->data.fn.fn_type_id.return_type;
+ ZigType *return_type = impl_fn->type_entry->data.fn.fn_type_id.return_type;
if (fn_type_can_fail(&impl_fn->type_entry->data.fn.fn_type_id)) {
parent_fn_entry->calls_or_awaits_errorable_fn = true;
}
@@ -13510,7 +13614,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
return ir_finish_anal(ira, return_type);
}
- FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
assert(fn_type_id->return_type != nullptr);
assert(parent_fn_entry != nullptr);
if (fn_type_can_fail(fn_type_id)) {
@@ -13521,14 +13625,14 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);
size_t next_arg_index = 0;
if (first_arg_ptr) {
- assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer);
+ assert(first_arg_ptr->value.type->id == ZigTypeIdPointer);
- TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
+ ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
if (type_is_invalid(param_type))
return ira->codegen->builtin_types.entry_invalid;
IrInstruction *first_arg;
- if (param_type->id == TypeTableEntryIdPointer &&
+ if (param_type->id == ZigTypeIdPointer &&
handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type))
{
first_arg = first_arg_ptr;
@@ -13551,7 +13655,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
return ira->codegen->builtin_types.entry_invalid;
IrInstruction *casted_arg;
if (next_arg_index < src_param_count) {
- TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
+ ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
if (type_is_invalid(param_type))
return ira->codegen->builtin_types.entry_invalid;
casted_arg = ir_implicit_cast(ira, old_arg, param_type);
@@ -13567,7 +13671,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
assert(next_arg_index == call_param_count);
- TypeTableEntry *return_type = fn_type_id->return_type;
+ ZigType *return_type = fn_type_id->return_type;
if (type_is_invalid(return_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -13595,6 +13699,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
return ir_finish_anal(ira, result->value.type);
}
+ if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && fn_inline == FnInlineNever) {
+ ir_add_error(ira, &call_instruction->base,
+ buf_sprintf("no-inline call of inline function"));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base,
fn_entry, fn_ref, call_param_count, casted_args, false, fn_inline, false, nullptr, casted_new_stack);
@@ -13603,7 +13712,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
return ir_finish_anal(ira, return_type);
}
-static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {
+static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {
IrInstruction *fn_ref = call_instruction->fn_ref->other;
if (type_is_invalid(fn_ref->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -13612,8 +13721,8 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);
if (is_comptime || instr_is_comptime(fn_ref)) {
- if (fn_ref->value.type->id == TypeTableEntryIdMetaType) {
- TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref);
+ if (fn_ref->value.type->id == ZigTypeIdMetaType) {
+ ZigType *dest_type = ir_resolve_type(ira, fn_ref);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -13633,15 +13742,15 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
ir_link_new_instruction(cast_instruction, &call_instruction->base);
return ir_finish_anal(ira, cast_instruction->value.type);
- } else if (fn_ref->value.type->id == TypeTableEntryIdFn) {
- FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref);
+ } else if (fn_ref->value.type->id == ZigTypeIdFn) {
+ ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
if (fn_table_entry == nullptr)
return ira->codegen->builtin_types.entry_invalid;
return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
fn_ref, nullptr, is_comptime, call_instruction->fn_inline);
- } else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) {
+ } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) {
assert(fn_ref->value.special == ConstValSpecialStatic);
- FnTableEntry *fn_table_entry = fn_ref->value.data.x_bound_fn.fn;
+ ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn;
IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg;
return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline);
@@ -13652,7 +13761,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
}
}
- if (fn_ref->value.type->id == TypeTableEntryIdFn) {
+ if (fn_ref->value.type->id == ZigTypeIdFn) {
return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type,
fn_ref, nullptr, false, FnInlineAuto);
} else {
@@ -13662,14 +13771,46 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
}
}
-static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
+// out_val->type must be the type to read the pointer as
+// if the type is different than the actual type then it does a comptime byte reinterpretation
+static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,
+ ConstExprValue *out_val, ConstExprValue *ptr_val)
+{
+ assert(out_val->type != nullptr);
+
+ ConstExprValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr_val);
+
+ size_t src_size = type_size(ira->codegen, pointee->type);
+ size_t dst_size = type_size(ira->codegen, out_val->type);
+
+ if (src_size == dst_size && types_have_same_zig_comptime_repr(pointee->type, out_val->type)) {
+ copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
+ return ErrorNone;
+ }
+
+ if (dst_size > src_size) {
+ ir_add_error_node(ira, source_node,
+ buf_sprintf("attempt to read %zu bytes from pointer to %s which is %zu bytes",
+ dst_size, buf_ptr(&pointee->type->name), src_size));
+ return ErrorSemanticAnalyzeFail;
+ }
+
+ Buf buf = BUF_INIT;
+ buf_resize(&buf, src_size);
+ buf_write_value_bytes(ira->codegen, (uint8_t*)buf_ptr(&buf), pointee);
+ buf_read_value_bytes(ira->codegen, (uint8_t*)buf_ptr(&buf), out_val);
+ return ErrorNone;
+}
+
+static ZigType *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
+ Error err;
IrInstruction *value = un_op_instruction->value->other;
- TypeTableEntry *ptr_type = value->value.type;
- TypeTableEntry *child_type;
+ ZigType *ptr_type = value->value.type;
+ ZigType *child_type;
if (type_is_invalid(ptr_type)) {
return ira->codegen->builtin_types.entry_invalid;
- } else if (ptr_type->id == TypeTableEntryIdPointer) {
+ } else if (ptr_type->id == ZigTypeIdPointer) {
if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
ir_add_error_node(ira, un_op_instruction->base.source_node,
buf_sprintf("index syntax required for unknown-length pointer type '%s'",
@@ -13692,60 +13833,59 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
if (comptime_value == nullptr)
return ira->codegen->builtin_types.entry_invalid;
- ConstExprValue *pointee = const_ptr_pointee(ira->codegen, comptime_value);
- if (pointee->type == child_type) {
- ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
- copy_const_val(out_val, pointee, value->value.data.x_ptr.mut == ConstPtrMutComptimeConst);
- return child_type;
- }
+ ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
+ out_val->type = child_type;
+ if ((err = ir_read_const_ptr(ira, un_op_instruction->base.source_node, out_val, comptime_value)))
+ return ira->codegen->builtin_types.entry_invalid;
+ return child_type;
}
ir_build_load_ptr_from(&ira->new_irb, &un_op_instruction->base, value);
return child_type;
}
-static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
+static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
Error err;
IrInstruction *value = un_op_instruction->value->other;
- TypeTableEntry *type_entry = ir_resolve_type(ira, value);
+ ZigType *type_entry = ir_resolve_type(ira, value);
if (type_is_invalid(type_entry))
return ira->codegen->builtin_types.entry_invalid;
if ((err = ensure_complete_type(ira->codegen, type_entry)))
return ira->codegen->builtin_types.entry_invalid;
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdPromise:
{
ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
out_val->data.x_type = get_optional_type(ira->codegen, type_entry);
return ira->codegen->builtin_types.entry_type;
}
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdOpaque:
ir_add_error_node(ira, un_op_instruction->base.source_node,
buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -13753,18 +13893,18 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
+static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
IrInstruction *value = un_op_instruction->value->other;
- TypeTableEntry *expr_type = value->value.type;
+ ZigType *expr_type = value->value.type;
if (type_is_invalid(expr_type))
return ira->codegen->builtin_types.entry_invalid;
bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap);
- bool is_float = (expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdComptimeFloat);
+ bool is_float = (expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat);
- if ((expr_type->id == TypeTableEntryIdInt && expr_type->data.integral.is_signed) ||
- expr_type->id == TypeTableEntryIdComptimeInt || (is_float && !is_wrap_op))
+ if ((expr_type->id == ZigTypeIdInt && expr_type->data.integral.is_signed) ||
+ expr_type->id == ZigTypeIdComptimeInt || (is_float && !is_wrap_op))
{
if (instr_is_comptime(value)) {
ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
@@ -13780,7 +13920,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
} else {
bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint);
}
- if (is_wrap_op || is_float || expr_type->id == TypeTableEntryIdComptimeInt) {
+ if (is_wrap_op || is_float || expr_type->id == ZigTypeIdComptimeInt) {
return expr_type;
}
@@ -13800,13 +13940,13 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
return ira->codegen->builtin_types.entry_invalid;
}
-static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
+static ZigType *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
IrInstruction *value = instruction->value->other;
- TypeTableEntry *expr_type = value->value.type;
+ ZigType *expr_type = value->value.type;
if (type_is_invalid(expr_type))
return ira->codegen->builtin_types.entry_invalid;
- if (expr_type->id == TypeTableEntryIdInt) {
+ if (expr_type->id == ZigTypeIdInt) {
if (instr_is_comptime(value)) {
ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
if (target_const_val == nullptr)
@@ -13827,7 +13967,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins
return ira->codegen->builtin_types.entry_invalid;
}
-static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
+static ZigType *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
IrUnOp op_id = un_op_instruction->op_id;
switch (op_id) {
case IrUnOpInvalid:
@@ -13845,7 +13985,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {
+static ZigType *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {
IrBasicBlock *old_dest_block = br_instruction->dest_block;
bool is_comptime;
@@ -13855,21 +13995,15 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
if (is_comptime || old_dest_block->ref_count == 1)
return ir_inline_bb(ira, &br_instruction->base, old_dest_block);
- IrBasicBlock *new_bb = ir_get_new_bb(ira, old_dest_block, &br_instruction->base);
-
- if (new_bb->must_be_comptime_source_instr) {
- ErrorMsg *msg = ir_add_error(ira, &br_instruction->base,
- buf_sprintf("control flow attempts to use compile-time variable at runtime"));
- add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node,
- buf_sprintf("compile-time variable assigned here"));
+ IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base);
+ if (new_bb == nullptr)
return ir_unreach_error(ira);
- }
ir_build_br_from(&ira->new_irb, &br_instruction->base, new_bb);
return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
}
-static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
+static ZigType *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
IrInstruction *condition = cond_br_instruction->condition->other;
if (type_is_invalid(condition->value.type))
return ir_unreach_error(ira);
@@ -13889,32 +14023,41 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct
if (is_comptime || old_dest_block->ref_count == 1)
return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block);
- IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block, &cond_br_instruction->base);
+ IrBasicBlock *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base);
+ if (new_dest_block == nullptr)
+ return ir_unreach_error(ira);
+
ir_build_br_from(&ira->new_irb, &cond_br_instruction->base, new_dest_block);
return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
}
- TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
+ ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);
if (casted_condition == ira->codegen->invalid_instruction)
return ir_unreach_error(ira);
assert(cond_br_instruction->then_block != cond_br_instruction->else_block);
- IrBasicBlock *new_then_block = ir_get_new_bb(ira, cond_br_instruction->then_block, &cond_br_instruction->base);
- IrBasicBlock *new_else_block = ir_get_new_bb(ira, cond_br_instruction->else_block, &cond_br_instruction->base);
+ IrBasicBlock *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base);
+ if (new_then_block == nullptr)
+ return ir_unreach_error(ira);
+
+ IrBasicBlock *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base);
+ if (new_else_block == nullptr)
+ return ir_unreach_error(ira);
+
ir_build_cond_br_from(&ira->new_irb, &cond_br_instruction->base,
casted_condition, new_then_block, new_else_block, nullptr);
return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
}
-static TypeTableEntry *ir_analyze_instruction_unreachable(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_unreachable(IrAnalyze *ira,
IrInstructionUnreachable *unreachable_instruction)
{
ir_build_unreachable_from(&ira->new_irb, &unreachable_instruction->base);
return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
}
-static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {
+static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {
if (ira->const_predecessor_bb) {
for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];
@@ -13948,7 +14091,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
IrInstruction *old_value = phi_instruction->incoming_values[i];
assert(old_value);
IrInstruction *new_value = old_value->other;
- if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable || predecessor->other == nullptr)
+ if (!new_value || new_value->value.type->id == ZigTypeIdUnreachable || predecessor->other == nullptr)
continue;
if (type_is_invalid(new_value->value.type))
@@ -13971,22 +14114,22 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
return first_value->value.type;
}
- TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
+ ZigType *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
new_incoming_values.items, new_incoming_values.length);
if (type_is_invalid(resolved_type))
return resolved_type;
- if (resolved_type->id == TypeTableEntryIdComptimeFloat ||
- resolved_type->id == TypeTableEntryIdComptimeInt ||
- resolved_type->id == TypeTableEntryIdNull ||
- resolved_type->id == TypeTableEntryIdUndefined)
+ if (resolved_type->id == ZigTypeIdComptimeFloat ||
+ resolved_type->id == ZigTypeIdComptimeInt ||
+ resolved_type->id == ZigTypeIdNull ||
+ resolved_type->id == ZigTypeIdUndefined)
{
ir_add_error_node(ira, phi_instruction->base.source_node,
buf_sprintf("unable to infer expression type"));
return ira->codegen->builtin_types.entry_invalid;
}
- bool all_stack_ptrs = (resolved_type->id == TypeTableEntryIdPointer);
+ bool all_stack_ptrs = (resolved_type->id == ZigTypeIdPointer);
// cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.
// so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and
@@ -14023,21 +14166,30 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
return resolved_type;
}
-static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
- VariableTableEntry *var)
-{
+static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) {
IrInstruction *result = ir_get_var_ptr(ira, instruction, var);
ir_link_new_instruction(result, instruction);
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) {
- VariableTableEntry *var = var_ptr_instruction->var;
- return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var);
+static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) {
+ ZigVar *var = instruction->var;
+ IrInstruction *result = ir_get_var_ptr(ira, &instruction->base, var);
+ if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {
+ ErrorMsg *msg = ir_add_error(ira, &instruction->base,
+ buf_sprintf("'%s' not accessible from inner function", buf_ptr(&var->name)));
+ add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,
+ buf_sprintf("crossed function definition here"));
+ add_error_note(ira->codegen, msg, var->decl_node,
+ buf_sprintf("declared here"));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
+ ir_link_new_instruction(result, &instruction->base);
+ return result->value.type;
}
-static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) {
- assert(ptr_type->id == TypeTableEntryIdPointer);
+static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align) {
+ assert(ptr_type->id == ZigTypeIdPointer);
return get_pointer_to_type_extra(g,
ptr_type->data.pointer.child_type,
ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
@@ -14046,15 +14198,15 @@ static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, ui
ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);
}
-static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type, uint32_t new_align) {
+static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align) {
assert(is_slice(slice_type));
- TypeTableEntry *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index].type_entry,
+ ZigType *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index].type_entry,
new_align);
return get_slice_type(g, ptr_type);
}
-static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrLen ptr_len) {
- assert(ptr_type->id == TypeTableEntryIdPointer);
+static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
+ assert(ptr_type->id == ZigTypeIdPointer);
return get_pointer_to_type_extra(g,
ptr_type->data.pointer.child_type,
ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
@@ -14063,7 +14215,7 @@ static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrL
ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count);
}
-static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
+static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
Error err;
IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other;
if (type_is_invalid(array_ptr->value.type))
@@ -14075,27 +14227,30 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
if (type_is_invalid(elem_index->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *ptr_type = orig_array_ptr_val->type;
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ ZigType *ptr_type = orig_array_ptr_val->type;
+ assert(ptr_type->id == ZigTypeIdPointer);
- TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
+ ZigType *array_type = ptr_type->data.pointer.child_type;
// At first return_type will be the pointer type we want to return, except with an optimistic alignment.
// We will adjust return_type's alignment before returning it.
- TypeTableEntry *return_type;
+ ZigType *return_type;
if (type_is_invalid(array_type)) {
return array_type;
- } else if (array_type->id == TypeTableEntryIdArray ||
- (array_type->id == TypeTableEntryIdPointer &&
+ } else if (array_type->id == ZigTypeIdArray ||
+ (array_type->id == ZigTypeIdPointer &&
array_type->data.pointer.ptr_len == PtrLenSingle &&
- array_type->data.pointer.child_type->id == TypeTableEntryIdArray))
+ array_type->data.pointer.child_type->id == ZigTypeIdArray))
{
- if (array_type->id == TypeTableEntryIdPointer) {
+ if (array_type->id == ZigTypeIdPointer) {
array_type = array_type->data.pointer.child_type;
ptr_type = ptr_type->data.pointer.child_type;
if (orig_array_ptr_val->special != ConstValSpecialRuntime) {
- orig_array_ptr_val = const_ptr_pointee(ira->codegen, orig_array_ptr_val);
+ orig_array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val,
+ elem_ptr_instruction->base.source_node);
+ if (orig_array_ptr_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
}
}
if (array_type->data.array.len == 0) {
@@ -14103,7 +14258,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
buf_sprintf("index 0 outside array of size 0"));
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *child_type = array_type->data.array.child_type;
+ ZigType *child_type = array_type->data.array.child_type;
if (ptr_type->data.pointer.unaligned_bit_count == 0) {
return_type = get_pointer_to_type_extra(ira->codegen, child_type,
ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
@@ -14122,7 +14277,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
elem_ptr_instruction->ptr_len,
1, (uint32_t)bit_offset, (uint32_t)bit_width);
}
- } else if (array_type->id == TypeTableEntryIdPointer) {
+ } else if (array_type->id == ZigTypeIdPointer) {
if (array_type->data.pointer.ptr_len == PtrLenSingle) {
ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
buf_sprintf("index of single-item pointer"));
@@ -14132,11 +14287,13 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
} else if (is_slice(array_type)) {
return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry,
elem_ptr_instruction->ptr_len);
- } else if (array_type->id == TypeTableEntryIdArgTuple) {
+ } else if (array_type->id == ZigTypeIdArgTuple) {
ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
if (!ptr_val)
return ira->codegen->builtin_types.entry_invalid;
- ConstExprValue *args_val = const_ptr_pointee(ira->codegen, ptr_val);
+ ConstExprValue *args_val = ir_const_ptr_pointee(ira, ptr_val, elem_ptr_instruction->base.source_node);
+ if (args_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
size_t start = args_val->data.x_arg_tuple.start_index;
size_t end = args_val->data.x_arg_tuple.end_index;
uint64_t elem_index_val;
@@ -14150,9 +14307,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_invalid;
}
size_t abs_index = start + index;
- FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
assert(fn_entry);
- VariableTableEntry *var = get_fn_var_by_index(fn_entry, abs_index);
+ ZigVar *var = get_fn_var_by_index(fn_entry, abs_index);
bool is_const = true;
bool is_volatile = false;
if (var) {
@@ -14167,7 +14324,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
+ ZigType *usize = ira->codegen->builtin_types.entry_usize;
IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
if (casted_elem_index == ira->codegen->invalid_instruction)
return ira->codegen->builtin_types.entry_invalid;
@@ -14181,7 +14338,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
uint64_t ptr_align = return_type->data.pointer.alignment;
if (instr_is_comptime(casted_elem_index)) {
uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint);
- if (array_type->id == TypeTableEntryIdArray) {
+ if (array_type->id == ZigTypeIdArray) {
uint64_t array_len = array_type->data.array.len;
if (index >= array_len) {
ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
@@ -14212,120 +14369,126 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align);
}
- ConstExprValue *array_ptr_val;
if (orig_array_ptr_val->special != ConstValSpecialRuntime &&
- (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == TypeTableEntryIdArray) &&
- (array_ptr_val = const_ptr_pointee(ira->codegen, orig_array_ptr_val)) &&
- array_ptr_val->special != ConstValSpecialRuntime &&
- (array_type->id != TypeTableEntryIdPointer ||
- array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
+ (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||
+ array_type->id == ZigTypeIdArray))
{
- if (array_type->id == TypeTableEntryIdPointer) {
- ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
- out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
- size_t new_index;
- size_t mem_size;
- size_t old_size;
- switch (array_ptr_val->data.x_ptr.special) {
- case ConstPtrSpecialInvalid:
- case ConstPtrSpecialDiscard:
- zig_unreachable();
- case ConstPtrSpecialRef:
- mem_size = 1;
- old_size = 1;
- new_index = index;
-
- out_val->data.x_ptr.special = ConstPtrSpecialRef;
- out_val->data.x_ptr.data.ref.pointee = array_ptr_val->data.x_ptr.data.ref.pointee;
- break;
- case ConstPtrSpecialBaseArray:
- {
- size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index;
- new_index = offset + index;
- mem_size = array_ptr_val->data.x_ptr.data.base_array.array_val->type->data.array.len;
- old_size = mem_size - offset;
-
- assert(array_ptr_val->data.x_ptr.data.base_array.array_val);
-
- out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
- out_val->data.x_ptr.data.base_array.array_val =
- array_ptr_val->data.x_ptr.data.base_array.array_val;
- out_val->data.x_ptr.data.base_array.elem_index = new_index;
- out_val->data.x_ptr.data.base_array.is_cstr =
- array_ptr_val->data.x_ptr.data.base_array.is_cstr;
+ ConstExprValue *array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val,
+ elem_ptr_instruction->base.source_node);
+ if (array_ptr_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
+ if (array_ptr_val->special != ConstValSpecialRuntime &&
+ (array_type->id != ZigTypeIdPointer ||
+ array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
+ {
+ if (array_type->id == ZigTypeIdPointer) {
+ ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
+ out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
+ size_t new_index;
+ size_t mem_size;
+ size_t old_size;
+ switch (array_ptr_val->data.x_ptr.special) {
+ case ConstPtrSpecialInvalid:
+ case ConstPtrSpecialDiscard:
+ zig_unreachable();
+ case ConstPtrSpecialRef:
+ mem_size = 1;
+ old_size = 1;
+ new_index = index;
+
+ out_val->data.x_ptr.special = ConstPtrSpecialRef;
+ out_val->data.x_ptr.data.ref.pointee = array_ptr_val->data.x_ptr.data.ref.pointee;
break;
- }
- case ConstPtrSpecialBaseStruct:
- zig_panic("TODO elem ptr on a const inner struct");
- case ConstPtrSpecialHardCodedAddr:
- zig_unreachable();
- case ConstPtrSpecialFunction:
- zig_panic("TODO element ptr of a function casted to a ptr");
- }
- if (new_index >= mem_size) {
- ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
- buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));
- return ira->codegen->builtin_types.entry_invalid;
- }
- return return_type;
- } else if (is_slice(array_type)) {
- ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];
- if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
- IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
- array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len);
- result->value.type = return_type;
- ir_link_new_instruction(result, &elem_ptr_instruction->base);
+ case ConstPtrSpecialBaseArray:
+ {
+ size_t offset = array_ptr_val->data.x_ptr.data.base_array.elem_index;
+ new_index = offset + index;
+ mem_size = array_ptr_val->data.x_ptr.data.base_array.array_val->type->data.array.len;
+ old_size = mem_size - offset;
+
+ assert(array_ptr_val->data.x_ptr.data.base_array.array_val);
+
+ out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
+ out_val->data.x_ptr.data.base_array.array_val =
+ array_ptr_val->data.x_ptr.data.base_array.array_val;
+ out_val->data.x_ptr.data.base_array.elem_index = new_index;
+ out_val->data.x_ptr.data.base_array.is_cstr =
+ array_ptr_val->data.x_ptr.data.base_array.is_cstr;
+
+ break;
+ }
+ case ConstPtrSpecialBaseStruct:
+ zig_panic("TODO elem ptr on a const inner struct");
+ case ConstPtrSpecialHardCodedAddr:
+ zig_unreachable();
+ case ConstPtrSpecialFunction:
+ zig_panic("TODO element ptr of a function casted to a ptr");
+ }
+ if (new_index >= mem_size) {
+ ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
+ buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
return return_type;
- }
- ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
- ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
- uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint);
- if (index >= slice_len) {
- ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
- buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
- index, slice_len));
- return ira->codegen->builtin_types.entry_invalid;
- }
- out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;
- switch (ptr_field->data.x_ptr.special) {
- case ConstPtrSpecialInvalid:
- case ConstPtrSpecialDiscard:
- zig_unreachable();
- case ConstPtrSpecialRef:
- out_val->data.x_ptr.special = ConstPtrSpecialRef;
- out_val->data.x_ptr.data.ref.pointee = ptr_field->data.x_ptr.data.ref.pointee;
- break;
- case ConstPtrSpecialBaseArray:
- {
- size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index;
- uint64_t new_index = offset + index;
- assert(new_index < ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len);
- out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
- out_val->data.x_ptr.data.base_array.array_val =
- ptr_field->data.x_ptr.data.base_array.array_val;
- out_val->data.x_ptr.data.base_array.elem_index = new_index;
- out_val->data.x_ptr.data.base_array.is_cstr =
- ptr_field->data.x_ptr.data.base_array.is_cstr;
+ } else if (is_slice(array_type)) {
+ ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];
+ if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
+ IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node,
+ array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len);
+ result->value.type = return_type;
+ ir_link_new_instruction(result, &elem_ptr_instruction->base);
+ return return_type;
+ }
+ ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index];
+ ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
+ uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint);
+ if (index >= slice_len) {
+ ir_add_error_node(ira, elem_ptr_instruction->base.source_node,
+ buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
+ index, slice_len));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
+ out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;
+ switch (ptr_field->data.x_ptr.special) {
+ case ConstPtrSpecialInvalid:
+ case ConstPtrSpecialDiscard:
+ zig_unreachable();
+ case ConstPtrSpecialRef:
+ out_val->data.x_ptr.special = ConstPtrSpecialRef;
+ out_val->data.x_ptr.data.ref.pointee = ptr_field->data.x_ptr.data.ref.pointee;
break;
- }
- case ConstPtrSpecialBaseStruct:
- zig_panic("TODO elem ptr on a slice backed by const inner struct");
- case ConstPtrSpecialHardCodedAddr:
- zig_unreachable();
- case ConstPtrSpecialFunction:
- zig_panic("TODO elem ptr on a slice that was ptrcast from a function");
+ case ConstPtrSpecialBaseArray:
+ {
+ size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index;
+ uint64_t new_index = offset + index;
+ assert(new_index < ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len);
+ out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
+ out_val->data.x_ptr.data.base_array.array_val =
+ ptr_field->data.x_ptr.data.base_array.array_val;
+ out_val->data.x_ptr.data.base_array.elem_index = new_index;
+ out_val->data.x_ptr.data.base_array.is_cstr =
+ ptr_field->data.x_ptr.data.base_array.is_cstr;
+ break;
+ }
+ case ConstPtrSpecialBaseStruct:
+ zig_panic("TODO elem ptr on a slice backed by const inner struct");
+ case ConstPtrSpecialHardCodedAddr:
+ zig_unreachable();
+ case ConstPtrSpecialFunction:
+ zig_panic("TODO elem ptr on a slice that was ptrcast from a function");
+ }
+ return return_type;
+ } else if (array_type->id == ZigTypeIdArray) {
+ ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
+ out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
+ out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;
+ out_val->data.x_ptr.data.base_array.array_val = array_ptr_val;
+ out_val->data.x_ptr.data.base_array.elem_index = index;
+ return return_type;
+ } else {
+ zig_unreachable();
}
- return return_type;
- } else if (array_type->id == TypeTableEntryIdArray) {
- ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base);
- out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
- out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut;
- out_val->data.x_ptr.data.base_array.array_val = array_ptr_val;
- out_val->data.x_ptr.data.base_array.elem_index = index;
- return return_type;
- } else {
- zig_unreachable();
}
}
@@ -14351,8 +14514,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
}
static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
- TypeTableEntry *bare_struct_type, Buf *field_name, IrInstruction *source_instr,
- IrInstruction *container_ptr, TypeTableEntry *container_type)
+ ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr,
+ IrInstruction *container_ptr, ZigType *container_type)
{
if (!is_slice(bare_struct_type)) {
ScopeDecls *container_scope = get_container_scope(bare_struct_type);
@@ -14364,7 +14527,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
if (tld->resolution == TldResolutionInvalid)
return ira->codegen->invalid_instruction;
TldFn *tld_fn = (TldFn *)tld;
- FnTableEntry *fn_entry = tld_fn->fn_entry;
+ ZigFn *fn_entry = tld_fn->fn_entry;
if (type_is_invalid(fn_entry->type_entry))
return ira->codegen->invalid_instruction;
@@ -14376,11 +14539,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
const char *prefix_name;
if (is_slice(bare_struct_type)) {
prefix_name = "";
- } else if (bare_struct_type->id == TypeTableEntryIdStruct) {
+ } else if (bare_struct_type->id == ZigTypeIdStruct) {
prefix_name = "struct ";
- } else if (bare_struct_type->id == TypeTableEntryIdEnum) {
+ } else if (bare_struct_type->id == ZigTypeIdEnum) {
prefix_name = "enum ";
- } else if (bare_struct_type->id == TypeTableEntryIdUnion) {
+ } else if (bare_struct_type->id == ZigTypeIdUnion) {
prefix_name = "union ";
} else {
prefix_name = "";
@@ -14391,18 +14554,18 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
}
static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
- IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type)
+ IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type)
{
Error err;
- TypeTableEntry *bare_type = container_ref_type(container_type);
+ ZigType *bare_type = container_ref_type(container_type);
if ((err = ensure_complete_type(ira->codegen, bare_type)))
return ira->codegen->invalid_instruction;
- assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
+ assert(container_ptr->value.type->id == ZigTypeIdPointer);
bool is_const = container_ptr->value.type->data.pointer.is_const;
bool is_volatile = container_ptr->value.type->data.pointer.is_volatile;
- if (bare_type->id == TypeTableEntryIdStruct) {
+ if (bare_type->id == ZigTypeIdStruct) {
TypeStructField *field = find_struct_type_field(bare_type, field_name);
if (field) {
bool is_packed = (bare_type->data.structure.layout == ContainerLayoutPacked);
@@ -14417,11 +14580,13 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
return ira->codegen->invalid_instruction;
if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
- ConstExprValue *struct_val = const_ptr_pointee(ira->codegen, ptr_val);
+ ConstExprValue *struct_val = ir_const_ptr_pointee(ira, ptr_val, source_instr->source_node);
+ if (struct_val == nullptr)
+ return ira->codegen->invalid_instruction;
if (type_is_invalid(struct_val->type))
return ira->codegen->invalid_instruction;
ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index];
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type,
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type,
is_const, is_volatile, PtrLenSingle, align_bytes,
(uint32_t)(ptr_bit_offset + field->packed_bits_offset),
(uint32_t)unaligned_bit_count_for_result_type);
@@ -14447,10 +14612,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
source_instr, container_ptr, container_type);
}
- } else if (bare_type->id == TypeTableEntryIdEnum) {
+ } else if (bare_type->id == ZigTypeIdEnum) {
return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
source_instr, container_ptr, container_type);
- } else if (bare_type->id == TypeTableEntryIdUnion) {
+ } else if (bare_type->id == ZigTypeIdUnion) {
TypeUnionField *field = find_union_type_field(bare_type, field_name);
if (field) {
if (instr_is_comptime(container_ptr)) {
@@ -14459,7 +14624,9 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
return ira->codegen->invalid_instruction;
if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
- ConstExprValue *union_val = const_ptr_pointee(ira->codegen, ptr_val);
+ ConstExprValue *union_val = ir_const_ptr_pointee(ira, ptr_val, source_instr->source_node);
+ if (union_val == nullptr)
+ return ira->codegen->invalid_instruction;
if (type_is_invalid(union_val->type))
return ira->codegen->invalid_instruction;
@@ -14476,15 +14643,15 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
ConstExprValue *payload_val = union_val->data.x_union.payload;
- TypeTableEntry *field_type = field->type_entry;
- if (field_type->id == TypeTableEntryIdVoid) {
+ ZigType *field_type = field->type_entry;
+ if (field_type->id == ZigTypeIdVoid) {
assert(payload_val == nullptr);
payload_val = create_const_vals(1);
payload_val->special = ConstValSpecialStatic;
payload_val->type = field_type;
}
- TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
is_const, is_volatile,
PtrLenSingle,
get_abi_alignment(ira->codegen, field_type), 0, 0);
@@ -14531,7 +14698,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
}
-static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {
+static ZigType *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);
if (tld->resolution == TldResolutionInvalid)
@@ -14544,7 +14711,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
case TldIdVar:
{
TldVar *tld_var = (TldVar *)tld;
- VariableTableEntry *var = tld_var->var;
+ ZigVar *var = tld_var->var;
if (tld_var->extern_lib_name != nullptr) {
add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);
}
@@ -14554,7 +14721,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
case TldIdFn:
{
TldFn *tld_fn = (TldFn *)tld;
- FnTableEntry *fn_entry = tld_fn->fn_entry;
+ ZigFn *fn_entry = tld_fn->fn_entry;
assert(fn_entry->type_entry);
if (type_is_invalid(fn_entry->type_entry))
@@ -14582,8 +14749,8 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
zig_unreachable();
}
-static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf *field_name) {
- assert(err_set_type->id == TypeTableEntryIdErrorSet);
+static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_name) {
+ assert(err_set_type->id == ZigTypeIdErrorSet);
for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) {
ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i];
if (buf_eql_buf(&err_table_entry->name, field_name)) {
@@ -14593,14 +14760,14 @@ static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf *
return nullptr;
}
-static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
+static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
Error err;
IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other;
if (type_is_invalid(container_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type;
- assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
+ ZigType *container_type = container_ptr->value.type->data.pointer.child_type;
+ assert(container_ptr->value.type->id == ZigTypeIdPointer);
Buf *field_name = field_ptr_instruction->field_name_buffer;
if (!field_name) {
@@ -14616,9 +14783,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
if (type_is_invalid(container_type)) {
return container_type;
} else if (is_container_ref(container_type)) {
- assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
- if (container_type->id == TypeTableEntryIdPointer) {
- TypeTableEntry *bare_type = container_ref_type(container_type);
+ assert(container_ptr->value.type->id == ZigTypeIdPointer);
+ if (container_type->id == ZigTypeIdPointer) {
+ ZigType *bare_type = container_ref_type(container_type);
IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr);
IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type);
ir_link_new_instruction(result, &field_ptr_instruction->base);
@@ -14631,13 +14798,13 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
} else if (is_array_ref(container_type)) {
if (buf_eql_str(field_name, "len")) {
ConstExprValue *len_val = create_const_vals(1);
- if (container_type->id == TypeTableEntryIdPointer) {
+ if (container_type->id == ZigTypeIdPointer) {
init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);
} else {
init_const_usize(ira->codegen, len_val, container_type->data.array.len);
}
- TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
+ ZigType *usize = ira->codegen->builtin_types.entry_usize;
bool ptr_is_const = true;
bool ptr_is_volatile = false;
return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,
@@ -14648,20 +14815,22 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_ptr(&container_type->name)));
return ira->codegen->builtin_types.entry_invalid;
}
- } else if (container_type->id == TypeTableEntryIdArgTuple) {
+ } else if (container_type->id == ZigTypeIdArgTuple) {
ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
if (!container_ptr_val)
return ira->codegen->builtin_types.entry_invalid;
- assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
- ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
+ assert(container_ptr->value.type->id == ZigTypeIdPointer);
+ ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);
+ if (child_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
if (buf_eql_str(field_name, "len")) {
ConstExprValue *len_val = create_const_vals(1);
size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index;
init_const_usize(ira->codegen, len_val, len);
- TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
+ ZigType *usize = ira->codegen->builtin_types.entry_usize;
bool ptr_is_const = true;
bool ptr_is_volatile = false;
return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val,
@@ -14672,14 +14841,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_ptr(&container_type->name)));
return ira->codegen->builtin_types.entry_invalid;
}
- } else if (container_type->id == TypeTableEntryIdMetaType) {
+ } else if (container_type->id == ZigTypeIdMetaType) {
ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
if (!container_ptr_val)
return ira->codegen->builtin_types.entry_invalid;
- assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
- ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val);
- TypeTableEntry *child_type = child_val->data.x_type;
+ assert(container_ptr->value.type->id == ZigTypeIdPointer);
+ ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);
+ if (child_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
+ ZigType *child_type = child_val->data.x_type;
if (type_is_invalid(child_type)) {
return ira->codegen->builtin_types.entry_invalid;
@@ -14688,14 +14859,14 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
bool ptr_is_const = true;
bool ptr_is_volatile = false;
TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index];
- assert(ptr_field->type_entry->id == TypeTableEntryIdPointer);
- TypeTableEntry *child_type = ptr_field->type_entry->data.pointer.child_type;
+ assert(ptr_field->type_entry->id == ZigTypeIdPointer);
+ ZigType *child_type = ptr_field->type_entry->data.pointer.child_type;
return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
create_const_type(ira->codegen, child_type),
ira->codegen->builtin_types.entry_type,
ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
}
- if (child_type->id == TypeTableEntryIdEnum) {
+ if (child_type->id == ZigTypeIdEnum) {
if ((err = ensure_complete_type(ira->codegen, child_type)))
return ira->codegen->builtin_types.entry_invalid;
@@ -14716,7 +14887,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);
}
}
- if (child_type->id == TypeTableEntryIdUnion &&
+ if (child_type->id == ZigTypeIdUnion &&
(child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
child_type->data.unionation.decl_node->data.container_decl.auto_enum))
{
@@ -14724,7 +14895,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
return ira->codegen->builtin_types.entry_invalid;
TypeUnionField *field = find_union_type_field(child_type, field_name);
if (field) {
- TypeTableEntry *enum_type = child_type->data.unionation.tag_type;
+ ZigType *enum_type = child_type->data.unionation.tag_type;
bool ptr_is_const = true;
bool ptr_is_volatile = false;
return ir_analyze_const_ptr(ira, &field_ptr_instruction->base,
@@ -14736,9 +14907,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_sprintf("container '%s' has no member called '%s'",
buf_ptr(&child_type->name), buf_ptr(field_name)));
return ira->codegen->builtin_types.entry_invalid;
- } else if (child_type->id == TypeTableEntryIdErrorSet) {
+ } else if (child_type->id == ZigTypeIdErrorSet) {
ErrorTableEntry *err_entry;
- TypeTableEntry *err_set_type;
+ ZigType *err_set_type;
if (type_is_global_error_set(child_type)) {
auto existing_entry = ira->codegen->error_table.maybe_get(field_name);
if (existing_entry) {
@@ -14782,7 +14953,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
bool ptr_is_volatile = false;
return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val,
err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
- } else if (child_type->id == TypeTableEntryIdInt) {
+ } else if (child_type->id == ZigTypeIdInt) {
if (buf_eql_str(field_name, "bit_count")) {
bool ptr_is_const = true;
bool ptr_is_volatile = false;
@@ -14804,7 +14975,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_ptr(&child_type->name), buf_ptr(field_name)));
return ira->codegen->builtin_types.entry_invalid;
}
- } else if (child_type->id == TypeTableEntryIdFloat) {
+ } else if (child_type->id == ZigTypeIdFloat) {
if (buf_eql_str(field_name, "bit_count")) {
bool ptr_is_const = true;
bool ptr_is_volatile = false;
@@ -14819,7 +14990,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_ptr(&child_type->name), buf_ptr(field_name)));
return ira->codegen->builtin_types.entry_invalid;
}
- } else if (child_type->id == TypeTableEntryIdPointer) {
+ } else if (child_type->id == ZigTypeIdPointer) {
if (buf_eql_str(field_name, "Child")) {
bool ptr_is_const = true;
bool ptr_is_volatile = false;
@@ -14841,7 +15012,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_ptr(&child_type->name), buf_ptr(field_name)));
return ira->codegen->builtin_types.entry_invalid;
}
- } else if (child_type->id == TypeTableEntryIdArray) {
+ } else if (child_type->id == ZigTypeIdArray) {
if (buf_eql_str(field_name, "Child")) {
bool ptr_is_const = true;
bool ptr_is_volatile = false;
@@ -14863,7 +15034,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_ptr(&child_type->name), buf_ptr(field_name)));
return ira->codegen->builtin_types.entry_invalid;
}
- } else if (child_type->id == TypeTableEntryIdErrorUnion) {
+ } else if (child_type->id == ZigTypeIdErrorUnion) {
if (buf_eql_str(field_name, "Payload")) {
bool ptr_is_const = true;
bool ptr_is_volatile = false;
@@ -14884,7 +15055,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_ptr(&child_type->name), buf_ptr(field_name)));
return ira->codegen->builtin_types.entry_invalid;
}
- } else if (child_type->id == TypeTableEntryIdOptional) {
+ } else if (child_type->id == ZigTypeIdOptional) {
if (buf_eql_str(field_name, "Child")) {
bool ptr_is_const = true;
bool ptr_is_volatile = false;
@@ -14898,7 +15069,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_ptr(&child_type->name), buf_ptr(field_name)));
return ira->codegen->builtin_types.entry_invalid;
}
- } else if (child_type->id == TypeTableEntryIdFn) {
+ } else if (child_type->id == ZigTypeIdFn) {
if (buf_eql_str(field_name, "ReturnType")) {
if (child_type->data.fn.fn_type_id.return_type == nullptr) {
// Return type can only ever be null, if the function is generic
@@ -14940,13 +15111,16 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
return ira->codegen->builtin_types.entry_invalid;
}
- } else if (container_type->id == TypeTableEntryIdNamespace) {
- assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
+ } 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->builtin_types.entry_invalid;
- ConstExprValue *namespace_val = const_ptr_pointee(ira->codegen, container_ptr_val);
+ ConstExprValue *namespace_val = ir_const_ptr_pointee(ira, container_ptr_val,
+ field_ptr_instruction->base.source_node);
+ if (namespace_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
assert(namespace_val->special == ConstValSpecialStatic);
ImportTableEntry *namespace_import = namespace_val->data.x_import;
@@ -14975,7 +15149,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
}
}
-static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *load_ptr_instruction) {
+static ZigType *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *load_ptr_instruction) {
IrInstruction *ptr = load_ptr_instruction->ptr->other;
if (type_is_invalid(ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -14986,7 +15160,7 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) {
+static ZigType *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) {
IrInstruction *ptr = store_ptr_instruction->ptr->other;
if (type_is_invalid(ptr->value.type))
return ptr->value.type;
@@ -14995,7 +15169,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
if (type_is_invalid(value->value.type))
return value->value.type;
- if (ptr->value.type->id != TypeTableEntryIdPointer) {
+ if (ptr->value.type->id != ZigTypeIdPointer) {
ir_add_error(ira, ptr,
buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -15010,7 +15184,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;
+ ZigType *child_type = ptr->value.type->data.pointer.child_type;
IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type);
if (casted_value == ira->codegen->invalid_instruction)
return ira->codegen->builtin_types.entry_invalid;
@@ -15022,7 +15196,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
}
if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) {
if (instr_is_comptime(casted_value)) {
- ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value);
+ ConstExprValue *dest_val = ir_const_ptr_pointee(ira, &ptr->value, store_ptr_instruction->base.source_node);
+ if (dest_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
if (dest_val->special != ConstValSpecialRuntime) {
*dest_val = casted_value->value;
if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) {
@@ -15033,7 +15209,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
}
ir_add_error(ira, &store_ptr_instruction->base,
buf_sprintf("cannot store runtime value in compile time variable"));
- ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value);
+ ConstExprValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, &ptr->value);
dest_val->type = ira->codegen->builtin_types.entry_invalid;
return ira->codegen->builtin_types.entry_invalid;
@@ -15044,39 +15220,39 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
+static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
IrInstruction *expr_value = typeof_instruction->value->other;
- TypeTableEntry *type_entry = expr_value->value.type;
+ ZigType *type_entry = expr_value->value.type;
if (type_is_invalid(type_entry))
return ira->codegen->builtin_types.entry_invalid;
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable(); // handled above
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdPromise:
{
ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base);
out_val->data.x_type = type_entry;
@@ -15088,20 +15264,20 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
IrInstructionToPtrType *to_ptr_type_instruction)
{
IrInstruction *value = to_ptr_type_instruction->value->other;
- TypeTableEntry *type_entry = value->value.type;
+ ZigType *type_entry = value->value.type;
if (type_is_invalid(type_entry))
return type_entry;
- TypeTableEntry *ptr_type;
- if (type_entry->id == TypeTableEntryIdArray) {
+ ZigType *ptr_type;
+ if (type_entry->id == ZigTypeIdArray) {
ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false);
} else if (is_slice(type_entry)) {
ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle);
- } else if (type_entry->id == TypeTableEntryIdArgTuple) {
+ } else if (type_entry->id == ZigTypeIdArgTuple) {
ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad);
if (!arg_tuple_val)
return ira->codegen->builtin_types.entry_invalid;
@@ -15117,15 +15293,15 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_type;
}
-static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
IrInstructionPtrTypeChild *ptr_type_child_instruction)
{
IrInstruction *type_value = ptr_type_child_instruction->value->other;
- TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value);
if (type_is_invalid(type_entry))
return type_entry;
- if (type_entry->id != TypeTableEntryIdPointer) {
+ if (type_entry->id != ZigTypeIdPointer) {
ir_add_error_node(ira, ptr_type_child_instruction->base.source_node,
buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -15136,7 +15312,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_type;
}
-static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) {
+static ZigType *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) {
if (ira->new_irb.exec->is_inline) {
// ignore setCold when running functions at compile time
ir_build_const_from(ira, &instruction->base);
@@ -15148,7 +15324,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc
if (!ir_resolve_bool(ira, is_cold_value, &want_cold))
return ira->codegen->builtin_types.entry_invalid;
- FnTableEntry *fn_entry = scope_fn_entry(instruction->base.scope);
+ ZigFn *fn_entry = scope_fn_entry(instruction->base.scope);
if (fn_entry == nullptr) {
ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function"));
return ira->codegen->builtin_types.entry_invalid;
@@ -15166,7 +15342,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc
ir_build_const_from(ira, &instruction->base);
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)
{
if (ira->new_irb.exec->is_inline) {
@@ -15187,7 +15363,7 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
break;
} else if (scope->id == ScopeIdFnDef) {
ScopeFnDef *def_scope = (ScopeFnDef *)scope;
- FnTableEntry *target_fn = def_scope->fn_entry;
+ ZigFn *target_fn = def_scope->fn_entry;
assert(target_fn->def_scope != nullptr);
safety_off_ptr = &target_fn->def_scope->safety_off;
safety_set_node_ptr = &target_fn->def_scope->safety_set_node;
@@ -15223,11 +15399,11 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
IrInstructionSetFloatMode *instruction)
{
IrInstruction *target_instruction = instruction->scope_value->other;
- TypeTableEntry *target_type = target_instruction->value.type;
+ ZigType *target_type = target_instruction->value.type;
if (type_is_invalid(target_type))
return ira->codegen->builtin_types.entry_invalid;
ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);
@@ -15242,24 +15418,24 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
bool *fast_math_on_ptr;
AstNode **fast_math_set_node_ptr;
- if (target_type->id == TypeTableEntryIdBlock) {
+ if (target_type->id == ZigTypeIdBlock) {
ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block;
fast_math_on_ptr = &block_scope->fast_math_on;
fast_math_set_node_ptr = &block_scope->fast_math_set_node;
- } else if (target_type->id == TypeTableEntryIdFn) {
+ } else if (target_type->id == ZigTypeIdFn) {
assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction);
- FnTableEntry *target_fn = target_val->data.x_ptr.data.fn.fn_entry;
+ ZigFn *target_fn = target_val->data.x_ptr.data.fn.fn_entry;
assert(target_fn->def_scope);
fast_math_on_ptr = &target_fn->def_scope->fast_math_on;
fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node;
- } else if (target_type->id == TypeTableEntryIdMetaType) {
+ } else if (target_type->id == ZigTypeIdMetaType) {
ScopeDecls *decls_scope;
- TypeTableEntry *type_arg = target_val->data.x_type;
- if (type_arg->id == TypeTableEntryIdStruct) {
+ ZigType *type_arg = target_val->data.x_type;
+ if (type_arg->id == ZigTypeIdStruct) {
decls_scope = type_arg->data.structure.decls_scope;
- } else if (type_arg->id == TypeTableEntryIdEnum) {
+ } else if (type_arg->id == ZigTypeIdEnum) {
decls_scope = type_arg->data.enumeration.decls_scope;
- } else if (type_arg->id == TypeTableEntryIdUnion) {
+ } else if (type_arg->id == ZigTypeIdUnion) {
decls_scope = type_arg->data.unionation.decls_scope;
} else {
ir_add_error_node(ira, target_instruction->source_node,
@@ -15294,7 +15470,7 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira,
IrInstructionSliceType *slice_type_instruction)
{
Error err;
@@ -15304,7 +15480,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->other);
+ ZigType *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->other);
if (type_is_invalid(child_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -15318,42 +15494,42 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
bool is_volatile = slice_type_instruction->is_volatile;
switch (child_type->id) {
- case TypeTableEntryIdInvalid: // handled above
+ case ZigTypeIdInvalid: // handled above
zig_unreachable();
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdBlock:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
ir_add_error_node(ira, slice_type_instruction->base.source_node,
buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name)));
return ira->codegen->builtin_types.entry_invalid;
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdPromise:
{
if ((err = type_ensure_zero_bits_known(ira->codegen, child_type)))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
+ ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0);
- TypeTableEntry *result_type = get_slice_type(ira->codegen, slice_ptr_type);
+ ZigType *result_type = get_slice_type(ira->codegen, slice_ptr_type);
ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base);
out_val->data.x_type = result_type;
return ira->codegen->builtin_types.entry_type;
@@ -15362,7 +15538,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) {
+static ZigType *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) {
assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr);
AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr;
@@ -15392,7 +15568,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);
IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);
- TypeTableEntry *return_type = ira->codegen->builtin_types.entry_void;
+ ZigType *return_type = ira->codegen->builtin_types.entry_void;
for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
AsmOutput *asm_output = asm_expr->output_list.at(i);
if (asm_output->return_type) {
@@ -15414,51 +15590,55 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
return return_type;
}
-static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira,
IrInstructionArrayType *array_type_instruction)
{
+ Error err;
+
IrInstruction *size_value = array_type_instruction->size->other;
uint64_t size;
if (!ir_resolve_usize(ira, size_value, &size))
return ira->codegen->builtin_types.entry_invalid;
IrInstruction *child_type_value = array_type_instruction->child_type->other;
- TypeTableEntry *child_type = ir_resolve_type(ira, child_type_value);
+ ZigType *child_type = ir_resolve_type(ira, child_type_value);
if (type_is_invalid(child_type))
return ira->codegen->builtin_types.entry_invalid;
switch (child_type->id) {
- case TypeTableEntryIdInvalid: // handled above
+ case ZigTypeIdInvalid: // handled above
zig_unreachable();
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdBlock:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
ir_add_error_node(ira, array_type_instruction->base.source_node,
buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name)));
return ira->codegen->builtin_types.entry_invalid;
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdPromise:
{
- TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size);
+ if ((err = ensure_complete_type(ira->codegen, child_type)))
+ return ira->codegen->builtin_types.entry_invalid;
+ ZigType *result_type = get_array_type(ira->codegen, child_type, size);
ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base);
out_val->data.x_type = result_type;
return ira->codegen->builtin_types.entry_type;
@@ -15467,13 +15647,13 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) {
- TypeTableEntry *promise_type;
+static ZigType *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) {
+ ZigType *promise_type;
if (instruction->payload_type == nullptr) {
promise_type = ira->codegen->builtin_types.entry_promise;
} else {
- TypeTableEntry *payload_type = ir_resolve_type(ira, instruction->payload_type->other);
+ ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->other);
if (type_is_invalid(payload_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -15485,47 +15665,47 @@ static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrIns
return ira->codegen->builtin_types.entry_type;
}
-static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira,
IrInstructionSizeOf *size_of_instruction)
{
Error err;
IrInstruction *type_value = size_of_instruction->type_value->other;
- TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value);
if ((err = ensure_complete_type(ira->codegen, type_entry)))
return ira->codegen->builtin_types.entry_invalid;
switch (type_entry->id) {
- case TypeTableEntryIdInvalid: // handled above
+ case ZigTypeIdInvalid: // handled above
zig_unreachable();
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdBlock:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
ir_add_error_node(ira, size_of_instruction->base.source_node,
buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name)));
return ira->codegen->builtin_types.entry_invalid;
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdPromise:
{
uint64_t size_in_bytes = type_size(ira->codegen, type_entry);
ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base);
@@ -15536,14 +15716,14 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
+static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
IrInstruction *value = instruction->value->other;
if (type_is_invalid(value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *type_entry = value->value.type;
+ ZigType *type_entry = value->value.type;
- if (type_entry->id == TypeTableEntryIdOptional) {
+ if (type_entry->id == ZigTypeIdOptional) {
if (instr_is_comptime(value)) {
ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad);
if (!maybe_val)
@@ -15556,7 +15736,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value);
return ira->codegen->builtin_types.entry_bool;
- } else if (type_entry->id == TypeTableEntryIdNull) {
+ } else if (type_entry->id == ZigTypeIdNull) {
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
out_val->data.x_bool = false;
return ira->codegen->builtin_types.entry_bool;
@@ -15567,26 +15747,26 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
}
}
-static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
IrInstructionUnwrapOptional *unwrap_maybe_instruction)
{
IrInstruction *value = unwrap_maybe_instruction->value->other;
if (type_is_invalid(value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *ptr_type = value->value.type;
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ ZigType *ptr_type = value->value.type;
+ assert(ptr_type->id == ZigTypeIdPointer);
- TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
+ ZigType *type_entry = ptr_type->data.pointer.child_type;
if (type_is_invalid(type_entry)) {
return ira->codegen->builtin_types.entry_invalid;
- } else if (type_entry->id != TypeTableEntryIdOptional) {
+ } else if (type_entry->id != ZigTypeIdOptional) {
ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *child_type = type_entry->data.maybe.child_type;
- TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
+ ZigType *child_type = type_entry->data.maybe.child_type;
+ ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
PtrLenSingle,
get_abi_alignment(ira->codegen, child_type), 0, 0);
@@ -15595,7 +15775,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
if (!val)
return ira->codegen->builtin_types.entry_invalid;
- ConstExprValue *maybe_val = const_ptr_pointee(ira->codegen, val);
+ ConstExprValue *maybe_val = ir_const_ptr_pointee(ira, val, unwrap_maybe_instruction->base.source_node);
+ if (maybe_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
if (optional_value_is_null(maybe_val)) {
@@ -15619,12 +15801,12 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
return result_type;
}
-static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) {
+static ZigType *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) {
IrInstruction *value = ctz_instruction->value->other;
if (type_is_invalid(value->value.type)) {
return ira->codegen->builtin_types.entry_invalid;
- } else if (value->value.type->id == TypeTableEntryIdInt) {
- TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen,
+ } else if (value->value.type->id == ZigTypeIdInt) {
+ ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen,
value->value.type->data.integral.bit_count);
if (value->value.special != ConstValSpecialRuntime) {
size_t result = bigint_ctz(&value->value.data.x_bigint,
@@ -15643,12 +15825,12 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC
}
}
-static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) {
+static ZigType *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) {
IrInstruction *value = clz_instruction->value->other;
if (type_is_invalid(value->value.type)) {
return ira->codegen->builtin_types.entry_invalid;
- } else if (value->value.type->id == TypeTableEntryIdInt) {
- TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen,
+ } else if (value->value.type->id == ZigTypeIdInt) {
+ ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen,
value->value.type->data.integral.bit_count);
if (value->value.special != ConstValSpecialRuntime) {
size_t result = bigint_clz(&value->value.data.x_bigint,
@@ -15667,12 +15849,12 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC
}
}
-static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) {
+static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) {
IrInstruction *value = instruction->value->other;
if (type_is_invalid(value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (value->value.type->id != TypeTableEntryIdInt && value->value.type->id != TypeTableEntryIdComptimeInt) {
+ if (value->value.type->id != ZigTypeIdInt && value->value.type->id != ZigTypeIdComptimeInt) {
ir_add_error(ira, value,
buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -15688,7 +15870,7 @@ static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstru
bigint_init_unsigned(&out_val->data.x_bigint, result);
return ira->codegen->builtin_types.entry_num_lit_int;
}
- if (value->value.type->id == TypeTableEntryIdComptimeInt) {
+ if (value->value.type->id == ZigTypeIdComptimeInt) {
Buf *val_buf = buf_alloc();
bigint_append_buf(val_buf, &val->data.x_bigint, 10);
ir_add_error(ira, &instruction->base,
@@ -15713,11 +15895,11 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
if (type_is_invalid(value->value.type))
return ira->codegen->invalid_instruction;
- if (value->value.type->id == TypeTableEntryIdEnum) {
+ if (value->value.type->id == ZigTypeIdEnum) {
return value;
}
- if (value->value.type->id != TypeTableEntryIdUnion) {
+ if (value->value.type->id != ZigTypeIdUnion) {
ir_add_error(ira, value,
buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name)));
return ira->codegen->invalid_instruction;
@@ -15731,8 +15913,8 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
return ira->codegen->invalid_instruction;
}
- TypeTableEntry *tag_type = value->value.type->data.unionation.tag_type;
- assert(tag_type->id == TypeTableEntryIdEnum);
+ ZigType *tag_type = value->value.type->data.unionation.tag_type;
+ assert(tag_type->id == ZigTypeIdEnum);
if (instr_is_comptime(value)) {
ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
@@ -15752,7 +15934,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
return result;
}
-static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira,
IrInstructionSwitchBr *switch_br_instruction)
{
IrInstruction *target_value = switch_br_instruction->target_value->other;
@@ -15784,7 +15966,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
if (type_is_invalid(case_value->value.type))
return ir_unreach_error(ira);
- if (case_value->value.type->id == TypeTableEntryIdEnum) {
+ if (case_value->value.type->id == ZigTypeIdEnum) {
case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value);
if (type_is_invalid(case_value->value.type))
return ir_unreach_error(ira);
@@ -15831,7 +16013,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
if (type_is_invalid(new_value->value.type))
continue;
- if (new_value->value.type->id == TypeTableEntryIdEnum) {
+ if (new_value->value.type->id == ZigTypeIdEnum) {
new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value);
if (type_is_invalid(new_value->value.type))
continue;
@@ -15860,7 +16042,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
}
-static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira,
IrInstructionSwitchTarget *switch_target_instruction)
{
Error err;
@@ -15868,25 +16050,28 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
if (type_is_invalid(target_value_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (target_value_ptr->value.type->id == TypeTableEntryIdMetaType) {
+ if (target_value_ptr->value.type->id == ZigTypeIdMetaType) {
assert(instr_is_comptime(target_value_ptr));
- TypeTableEntry *ptr_type = target_value_ptr->value.data.x_type;
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ ZigType *ptr_type = target_value_ptr->value.data.x_type;
+ assert(ptr_type->id == ZigTypeIdPointer);
ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
out_val->type = ira->codegen->builtin_types.entry_type;
out_val->data.x_type = ptr_type->data.pointer.child_type;
return out_val->type;
}
- if (target_value_ptr->value.type->id != TypeTableEntryIdPointer) {
+ if (target_value_ptr->value.type->id != ZigTypeIdPointer) {
ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target"));
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
+ ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;
ConstExprValue *pointee_val = nullptr;
if (instr_is_comptime(target_value_ptr)) {
- pointee_val = const_ptr_pointee(ira->codegen, &target_value_ptr->value);
+ pointee_val = ir_const_ptr_pointee(ira, &target_value_ptr->value, target_value_ptr->source_node);
+ if (pointee_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
+
if (pointee_val->special == ConstValSpecialRuntime)
pointee_val = nullptr;
}
@@ -15894,20 +16079,20 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_invalid;
switch (target_type->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdPromise:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdPointer:
+ case ZigTypeIdPromise:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdErrorSet:
if (pointee_val) {
ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
copy_const_val(out_val, pointee_val, true);
@@ -15917,7 +16102,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr);
return target_type;
- case TypeTableEntryIdUnion: {
+ case ZigTypeIdUnion: {
AstNode *decl_node = target_type->data.unionation.decl_node;
if (!decl_node->data.container_decl.auto_enum &&
decl_node->data.container_decl.init_arg_expr == nullptr)
@@ -15928,9 +16113,9 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
buf_sprintf("consider 'union(enum)' here"));
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *tag_type = target_type->data.unionation.tag_type;
+ ZigType *tag_type = target_type->data.unionation.tag_type;
assert(tag_type != nullptr);
- assert(tag_type->id == TypeTableEntryIdEnum);
+ assert(tag_type->id == ZigTypeIdEnum);
if (pointee_val) {
ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_union.tag);
@@ -15953,7 +16138,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base);
return tag_type;
}
- case TypeTableEntryIdEnum: {
+ case ZigTypeIdEnum: {
if ((err = type_ensure_zero_bits_known(ira->codegen, target_type)))
return ira->codegen->builtin_types.entry_invalid;
if (target_type->data.enumeration.src_field_count < 2) {
@@ -15975,17 +16160,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
ir_link_new_instruction(enum_value, &switch_target_instruction->base);
return target_type;
}
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
ir_add_error(ira, &switch_target_instruction->base,
buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -15993,7 +16178,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
+static ZigType *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
IrInstruction *target_value_ptr = instruction->target_value_ptr->other;
if (type_is_invalid(target_value_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -16002,14 +16187,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
if (type_is_invalid(prong_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
- TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
- if (target_type->id == TypeTableEntryIdUnion) {
+ assert(target_value_ptr->value.type->id == ZigTypeIdPointer);
+ ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;
+ if (target_type->id == ZigTypeIdUnion) {
ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad);
if (!prong_val)
return ira->codegen->builtin_types.entry_invalid;
- assert(prong_value->value.type->id == TypeTableEntryIdEnum);
+ assert(prong_value->value.type->id == ZigTypeIdEnum);
TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag);
if (instr_is_comptime(target_value_ptr)) {
@@ -16017,7 +16202,10 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
if (!target_value_ptr)
return ira->codegen->builtin_types.entry_invalid;
- ConstExprValue *pointee_val = const_ptr_pointee(ira->codegen, target_val_ptr);
+ ConstExprValue *pointee_val = ir_const_ptr_pointee(ira, target_val_ptr, instruction->base.source_node);
+ if (pointee_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
+
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
out_val->data.x_ptr.special = ConstPtrSpecialRef;
out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut;
@@ -16035,14 +16223,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
}
}
-static TypeTableEntry *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) {
+static ZigType *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) {
IrInstruction *value = instruction->value->other;
IrInstruction *new_instruction = ir_analyze_union_tag(ira, &instruction->base, value);
ir_link_new_instruction(new_instruction, &instruction->base);
return new_instruction->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) {
+static ZigType *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) {
IrInstruction *name_value = import_instruction->name->other;
Buf *import_target_str = ir_resolve_str(ira, name_value);
if (!import_target_str)
@@ -16074,29 +16262,20 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
os_path_join(search_dir, import_target_path, &full_path);
Buf *import_code = buf_alloc();
- Buf *abs_full_path = buf_alloc();
- int err;
- if ((err = os_path_real(&full_path, abs_full_path))) {
- if (err == ErrorFileNotFound) {
- ir_add_error_node(ira, source_node,
- buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
- return ira->codegen->builtin_types.entry_invalid;
- } else {
- ira->codegen->error_during_imports = true;
- ir_add_error_node(ira, source_node,
- buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));
- return ira->codegen->builtin_types.entry_invalid;
- }
- }
+ Buf *resolved_path = buf_alloc();
- auto import_entry = ira->codegen->import_table.maybe_get(abs_full_path);
+ Buf *resolve_paths[] = { &full_path, };
+ *resolved_path = os_path_resolve(resolve_paths, 1);
+
+ auto import_entry = ira->codegen->import_table.maybe_get(resolved_path);
if (import_entry) {
ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base);
out_val->data.x_import = import_entry->value;
return ira->codegen->builtin_types.entry_namespace;
}
- if ((err = os_fetch_file_path(abs_full_path, import_code, true))) {
+ int err;
+ if ((err = os_fetch_file_path(resolved_path, import_code, true))) {
if (err == ErrorFileNotFound) {
ir_add_error_node(ira, source_node,
buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
@@ -16107,7 +16286,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
return ira->codegen->builtin_types.entry_invalid;
}
}
- ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, abs_full_path, import_code);
+ ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code);
scan_import(ira->codegen, target_import);
@@ -16117,14 +16296,14 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
}
-static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_array_len(IrAnalyze *ira,
IrInstructionArrayLen *array_len_instruction)
{
IrInstruction *array_value = array_len_instruction->array_value->other;
- TypeTableEntry *type_entry = array_value->value.type;
+ ZigType *type_entry = array_value->value.type;
if (type_is_invalid(type_entry)) {
return ira->codegen->builtin_types.entry_invalid;
- } else if (type_entry->id == TypeTableEntryIdArray) {
+ } else if (type_entry->id == ZigTypeIdArray) {
return ir_analyze_const_usize(ira, &array_len_instruction->base,
type_entry->data.array.len);
} else if (is_slice(type_entry)) {
@@ -16148,16 +16327,16 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
}
}
-static TypeTableEntry *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
+static ZigType *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {
IrInstruction *value = ref_instruction->value->other;
return ir_analyze_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);
}
-static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction,
- TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
+static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction,
+ ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
{
Error err;
- assert(container_type->id == TypeTableEntryIdUnion);
+ assert(container_type->id == ZigTypeIdUnion);
if ((err = ensure_complete_type(ira->codegen, container_type)))
return ira->codegen->builtin_types.entry_invalid;
@@ -16219,14 +16398,14 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir
return container_type;
}
-static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,
- TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
+static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,
+ ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields)
{
Error err;
- if (container_type->id == TypeTableEntryIdUnion) {
+ if (container_type->id == ZigTypeIdUnion) {
return ir_analyze_container_init_fields_union(ira, instruction, container_type, instr_field_count, fields);
}
- if (container_type->id != TypeTableEntryIdStruct || is_slice(container_type)) {
+ if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {
ir_add_error(ira, instruction,
buf_sprintf("type '%s' does not support struct initialization syntax",
buf_ptr(&container_type->name)));
@@ -16339,7 +16518,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
return container_type;
}
-static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
IrInstructionContainerInitList *instruction)
{
IrInstruction *container_type_value = instruction->container_type->other;
@@ -16347,21 +16526,21 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
return ira->codegen->builtin_types.entry_invalid;
size_t elem_count = instruction->item_count;
- if (container_type_value->value.type->id == TypeTableEntryIdMetaType) {
- TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
+ if (container_type_value->value.type->id == ZigTypeIdMetaType) {
+ ZigType *container_type = ir_resolve_type(ira, container_type_value);
if (type_is_invalid(container_type))
return ira->codegen->builtin_types.entry_invalid;
- if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) {
+ if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) {
return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
0, nullptr);
- } else if (is_slice(container_type) || container_type->id == TypeTableEntryIdArray) {
+ } else if (is_slice(container_type) || container_type->id == ZigTypeIdArray) {
// array is same as slice init but we make a compile error if the length is wrong
- TypeTableEntry *child_type;
- if (container_type->id == TypeTableEntryIdArray) {
+ ZigType *child_type;
+ if (container_type->id == ZigTypeIdArray) {
child_type = container_type->data.array.child_type;
if (container_type->data.array.len != elem_count) {
- TypeTableEntry *literal_type = get_array_type(ira->codegen, child_type, elem_count);
+ ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count);
ir_add_error(ira, &instruction->base,
buf_sprintf("expected %s literal, found %s literal",
@@ -16369,12 +16548,12 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
return ira->codegen->builtin_types.entry_invalid;
}
} else {
- TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;
- assert(pointer_type->id == TypeTableEntryIdPointer);
+ ZigType *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry;
+ assert(pointer_type->id == ZigTypeIdPointer);
child_type = pointer_type->data.pointer.child_type;
}
- TypeTableEntry *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count);
+ ZigType *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count);
ConstExprValue const_val = {};
const_val.special = ConstValSpecialStatic;
@@ -16437,7 +16616,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
container_type_value, elem_count, new_items);
ir_add_alloca(ira, new_instruction, fixed_size_array_type);
return fixed_size_array_type;
- } else if (container_type->id == TypeTableEntryIdVoid) {
+ } else if (container_type->id == ZigTypeIdVoid) {
if (elem_count != 0) {
ir_add_error_node(ira, instruction->base.source_node,
buf_sprintf("void expression expects no arguments"));
@@ -16457,9 +16636,9 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
}
}
-static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) {
+static ZigType *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) {
IrInstruction *container_type_value = instruction->container_type->other;
- TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
+ ZigType *container_type = ir_resolve_type(ira, container_type_value);
if (type_is_invalid(container_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -16467,50 +16646,50 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i
instruction->field_count, instruction->fields);
}
-static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction,
+static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction,
IrInstruction *target_type_value, bool is_max)
{
- TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value);
+ ZigType *target_type = ir_resolve_type(ira, target_type_value);
if (type_is_invalid(target_type))
return ira->codegen->builtin_types.entry_invalid;
switch (target_type->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
{
ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
eval_min_max_value(ira->codegen, target_type, out_val, is_max);
return ira->codegen->builtin_types.entry_num_lit_int;
}
- case TypeTableEntryIdBool:
- case TypeTableEntryIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdVoid:
{
ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
eval_min_max_value(ira->codegen, target_type, out_val, is_max);
return target_type;
}
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdPromise:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdEnum:
+ case ZigTypeIdFloat:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdPointer:
+ case ZigTypeIdPromise:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
{
const char *err_format = is_max ?
"no max value available for type '%s'" :
@@ -16523,19 +16702,19 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_min_value(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_min_value(IrAnalyze *ira,
IrInstructionMinValue *instruction)
{
return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, false);
}
-static TypeTableEntry *ir_analyze_instruction_max_value(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_max_value(IrAnalyze *ira,
IrInstructionMaxValue *instruction)
{
return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, true);
}
-static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_compile_err(IrAnalyze *ira,
IrInstructionCompileErr *instruction)
{
IrInstruction *msg_value = instruction->msg->other;
@@ -16559,7 +16738,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_invalid;
}
-static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) {
+static ZigType *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) {
Buf buf = BUF_INIT;
fprintf(stderr, "| ");
for (size_t i = 0; i < instruction->msg_count; i += 1) {
@@ -16579,7 +16758,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
+static ZigType *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
IrInstruction *value = instruction->value->other;
if (type_is_invalid(value->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -16588,9 +16767,9 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
if (type_is_invalid(casted_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
+ ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
+ ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
if (casted_value->value.special == ConstValSpecialStatic) {
ErrorTableEntry *err = casted_value->value.data.x_err_set;
if (!err->cached_error_name_val) {
@@ -16607,13 +16786,13 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
return str_type;
}
-static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) {
+static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) {
Error err;
IrInstruction *target = instruction->target->other;
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
- assert(target->value.type->id == TypeTableEntryIdEnum);
+ assert(target->value.type->id == ZigTypeIdEnum);
if (instr_is_comptime(target)) {
if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type)))
@@ -16628,7 +16807,7 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn
IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope,
instruction->base.source_node, target);
ir_link_new_instruction(result, &instruction->base);
- TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(
+ ZigType *u8_ptr_type = get_pointer_to_type_extra(
ira->codegen, ira->codegen->builtin_types.entry_u8,
true, false, PtrLenUnknown,
get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8),
@@ -16637,12 +16816,12 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
IrInstructionFieldParentPtr *instruction)
{
Error err;
IrInstruction *type_value = instruction->type_value->other;
- TypeTableEntry *container_type = ir_resolve_type(ira, type_value);
+ ZigType *container_type = ir_resolve_type(ira, type_value);
if (type_is_invalid(container_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -16655,7 +16834,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
if (type_is_invalid(field_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (container_type->id != TypeTableEntryIdStruct) {
+ if (container_type->id != ZigTypeIdStruct) {
ir_add_error(ira, type_value,
buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -16672,7 +16851,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_invalid;
}
- if (field_ptr->value.type->id != TypeTableEntryIdPointer) {
+ if (field_ptr->value.type->id != ZigTypeIdPointer) {
ir_add_error(ira, field_ptr,
buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -16682,7 +16861,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
uint32_t field_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, field->type_entry);
uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type);
- TypeTableEntry *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,
+ ZigType *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,
field_ptr->value.type->data.pointer.is_const,
field_ptr->value.type->data.pointer.is_volatile,
PtrLenSingle,
@@ -16691,7 +16870,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
if (type_is_invalid(casted_field_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
+ ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
casted_field_ptr->value.type->data.pointer.is_const,
casted_field_ptr->value.type->data.pointer.is_volatile,
PtrLenSingle,
@@ -16730,12 +16909,12 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
return result_type;
}
-static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_offset_of(IrAnalyze *ira,
IrInstructionOffsetOf *instruction)
{
Error err;
IrInstruction *type_value = instruction->type_value->other;
- TypeTableEntry *container_type = ir_resolve_type(ira, type_value);
+ ZigType *container_type = ir_resolve_type(ira, type_value);
if (type_is_invalid(container_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -16747,7 +16926,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
if (!field_name)
return ira->codegen->builtin_types.entry_invalid;
- if (container_type->id != TypeTableEntryIdStruct) {
+ if (container_type->id != ZigTypeIdStruct) {
ir_add_error(ira, type_value,
buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -16773,7 +16952,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
return ira->codegen->builtin_types.entry_num_lit_int;
}
-static void ensure_field_index(TypeTableEntry *type, const char *field_name, size_t index)
+static void ensure_field_index(ZigType *type, const char *field_name, size_t index)
{
Buf *field_name_buf;
@@ -16784,17 +16963,17 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz
(buf_deinit(field_name_buf), true));
}
-static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, TypeTableEntry *root) {
+static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) {
Error err;
static ConstExprValue *type_info_var = nullptr;
- static TypeTableEntry *type_info_type = nullptr;
+ static ZigType *type_info_type = nullptr;
if (type_info_var == nullptr) {
type_info_var = get_builtin_value(ira->codegen, "TypeInfo");
- assert(type_info_var->type->id == TypeTableEntryIdMetaType);
+ assert(type_info_var->type->id == ZigTypeIdMetaType);
assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type));
type_info_type = type_info_var->data.x_type;
- assert(type_info_type->id == TypeTableEntryIdUnion);
+ assert(type_info_type->id == ZigTypeIdUnion);
}
if (type_name == nullptr && root == nullptr)
@@ -16802,7 +16981,7 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
else if (type_name == nullptr)
return root;
- TypeTableEntry *root_type = (root == nullptr) ? type_info_type : root;
+ ZigType *root_type = (root == nullptr) ? type_info_type : root;
ScopeDecls *type_info_scope = get_container_scope(root_type);
assert(type_info_scope != nullptr);
@@ -16815,17 +16994,17 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
TldVar *tld = (TldVar *)entry;
assert(tld->base.id == TldIdVar);
- VariableTableEntry *var = tld->var;
+ ZigVar *var = tld->var;
if ((err = ensure_complete_type(ira->codegen, var->value->type)))
return ira->codegen->builtin_types.entry_invalid;
- assert(var->value->type->id == TypeTableEntryIdMetaType);
+ assert(var->value->type->id == ZigTypeIdMetaType);
return var->value->data.x_type;
}
static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) {
Error err;
- TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr);
+ ZigType *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr);
if ((err = ensure_complete_type(ira->codegen, type_info_definition_type)))
return err;
@@ -16833,15 +17012,15 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
ensure_field_index(type_info_definition_type, "is_pub", 1);
ensure_field_index(type_info_definition_type, "data", 2);
- TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);
+ ZigType *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);
if ((err = ensure_complete_type(ira->codegen, type_info_definition_data_type)))
return err;
- TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);
+ ZigType *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);
if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_type)))
return err;
- TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);
+ ZigType *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);
if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_inline_type)))
return err;
@@ -16862,7 +17041,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
// Skip comptime blocks and test functions.
if (curr_entry->value->id != TldIdCompTime) {
if (curr_entry->value->id == TldIdFn) {
- FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
+ ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
if (fn_entry->is_test)
continue;
}
@@ -16888,7 +17067,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
if (curr_entry->value->id == TldIdCompTime) {
continue;
} else if (curr_entry->value->id == TldIdFn) {
- FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
+ ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
if (fn_entry->is_test)
continue;
}
@@ -16913,11 +17092,11 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
switch (curr_entry->value->id) {
case TldIdVar:
{
- VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;
+ ZigVar *var = ((TldVar *)curr_entry->value)->var;
if ((err = ensure_complete_type(ira->codegen, var->value->type)))
return ErrorSemanticAnalyzeFail;
- if (var->value->type->id == TypeTableEntryIdMetaType)
+ if (var->value->type->id == ZigTypeIdMetaType)
{
// We have a variable of type 'type', so it's actually a type definition.
// 0: Data.Type: type
@@ -16944,7 +17123,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
// 2: Data.Fn: Data.FnDef
bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 2);
- FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
+ ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
assert(!fn_entry->is_test);
AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node);
@@ -16992,7 +17171,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
// lib_name: ?[]const u8
ensure_field_index(fn_def_val->type, "lib_name", 6);
fn_def_fields[6].special = ConstValSpecialStatic;
- TypeTableEntry *u8_ptr = get_pointer_to_type_extra(
+ ZigType *u8_ptr = get_pointer_to_type_extra(
ira->codegen, ira->codegen->builtin_types.entry_u8,
true, false, PtrLenUnknown,
get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8),
@@ -17030,7 +17209,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++)
{
- VariableTableEntry *arg_var = fn_entry->variable_list.at(fn_arg_index);
+ ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index];
ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name);
init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, buf_len(&arg_var->name), true);
@@ -17044,7 +17223,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
}
case TldIdContainer:
{
- TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry;
+ ZigType *type_entry = ((TldContainer *)curr_entry->value)->type_entry;
if ((err = ensure_complete_type(ira->codegen, type_entry)))
return ErrorSemanticAnalyzeFail;
@@ -17071,20 +17250,20 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco
return ErrorNone;
}
-static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry *ptr_type_entry) {
- TypeTableEntry *attrs_type;
+static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) {
+ ZigType *attrs_type;
uint32_t size_enum_index;
if (is_slice(ptr_type_entry)) {
attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry;
size_enum_index = 2;
- } else if (ptr_type_entry->id == TypeTableEntryIdPointer) {
+ } else if (ptr_type_entry->id == ZigTypeIdPointer) {
attrs_type = ptr_type_entry;
size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1;
} else {
zig_unreachable();
}
- TypeTableEntry *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
+ ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_type));
ConstExprValue *result = create_const_vals(1);
@@ -17096,7 +17275,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry
// size: Size
ensure_field_index(result->type, "size", 0);
- TypeTableEntry *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type);
+ ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type);
assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_size_type));
fields[0].special = ConstValSpecialStatic;
fields[0].type = type_info_pointer_size_type;
@@ -17127,7 +17306,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry
};
static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field,
- TypeTableEntry *type_info_enum_field_type)
+ ZigType *type_info_enum_field_type)
{
enum_field_val->special = ConstValSpecialStatic;
enum_field_val->type = type_info_enum_field_type;
@@ -17144,7 +17323,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
enum_field_val->data.x_struct.fields = inner_fields;
}
-static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, ConstExprValue **out) {
+static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstExprValue **out) {
Error err;
assert(type_entry != nullptr);
assert(!type_is_invalid(type_entry));
@@ -17159,20 +17338,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
ConstExprValue *result = nullptr;
switch (type_entry->id)
{
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdBool:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdVoid:
+ case ZigTypeIdBool:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdOpaque:
*out = nullptr;
return ErrorNone;
default:
@@ -17186,7 +17365,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
// Fallthrough if we don't find one.
}
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
{
result = create_const_vals(1);
result->special = ConstValSpecialStatic;
@@ -17208,7 +17387,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
{
result = create_const_vals(1);
result->special = ConstValSpecialStatic;
@@ -17225,12 +17404,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
{
result = create_ptr_like_type_info(ira, type_entry);
break;
}
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
{
result = create_const_vals(1);
result->special = ConstValSpecialStatic;
@@ -17252,7 +17431,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
{
result = create_const_vals(1);
result->special = ConstValSpecialStatic;
@@ -17269,7 +17448,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdPromise:
+ case ZigTypeIdPromise:
{
result = create_const_vals(1);
result->special = ConstValSpecialStatic;
@@ -17295,7 +17474,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
{
result = create_const_vals(1);
result->special = ConstValSpecialStatic;
@@ -17317,7 +17496,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
// fields: []TypeInfo.EnumField
ensure_field_index(result->type, "fields", 2);
- TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
+ ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;
ConstExprValue *enum_field_array = create_const_vals(1);
@@ -17345,7 +17524,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdErrorSet:
{
result = create_const_vals(1);
result->special = ConstValSpecialStatic;
@@ -17357,7 +17536,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
// errors: []TypeInfo.Error
ensure_field_index(result->type, "errors", 0);
- TypeTableEntry *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
+ ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr);
uint32_t error_count = type_entry->data.error_set.err_count;
ConstExprValue *error_array = create_const_vals(1);
error_array->special = ConstValSpecialStatic;
@@ -17394,7 +17573,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
{
result = create_const_vals(1);
result->special = ConstValSpecialStatic;
@@ -17417,7 +17596,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
{
result = create_const_vals(1);
result->special = ConstValSpecialStatic;
@@ -17451,7 +17630,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
// fields: []TypeInfo.UnionField
ensure_field_index(result->type, "fields", 2);
- TypeTableEntry *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr);
+ ZigType *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr);
uint32_t union_field_count = type_entry->data.unionation.src_field_count;
ConstExprValue *union_field_array = create_const_vals(1);
@@ -17463,7 +17642,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
init_const_slice(ira->codegen, &fields[2], union_field_array, 0, union_field_count, false);
- TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
+ ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr);
for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) {
TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index];
@@ -17502,7 +17681,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
{
if (type_entry->data.structure.is_slice) {
result = create_ptr_like_type_info(ira, type_entry);
@@ -17524,7 +17703,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
// fields: []TypeInfo.StructField
ensure_field_index(result->type, "fields", 1);
- TypeTableEntry *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr);
+ ZigType *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr);
uint32_t struct_field_count = type_entry->data.structure.src_field_count;
ConstExprValue *struct_field_array = create_const_vals(1);
@@ -17576,7 +17755,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
{
result = create_const_vals(1);
result->special = ConstValSpecialStatic;
@@ -17629,7 +17808,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
fields[4].data.x_optional = async_alloc_type;
}
// args: []TypeInfo.FnArg
- TypeTableEntry *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
+ ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -
(is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC);
@@ -17681,10 +17860,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
break;
}
- case TypeTableEntryIdBoundFn:
+ case ZigTypeIdBoundFn:
{
- TypeTableEntry *fn_type = type_entry->data.bound_fn.fn_type;
- assert(fn_type->id == TypeTableEntryIdFn);
+ ZigType *fn_type = type_entry->data.bound_fn.fn_type;
+ assert(fn_type->id == ZigTypeIdFn);
if ((err = ir_make_type_info_value(ira, fn_type, &result)))
return err;
@@ -17698,16 +17877,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry,
return ErrorNone;
}
-static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_type_info(IrAnalyze *ira,
IrInstructionTypeInfo *instruction)
{
Error err;
IrInstruction *type_value = instruction->type_value->other;
- TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value);
if (type_is_invalid(type_entry))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
+ ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
ConstExprValue *payload;
if ((err = ir_make_type_info_value(ira, type_entry, &payload)))
@@ -17719,7 +17898,7 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
out_val->data.x_union.payload = payload;
if (payload != nullptr) {
- assert(payload->type->id == TypeTableEntryIdStruct);
+ assert(payload->type->id == ZigTypeIdStruct);
payload->data.x_struct.parent.id = ConstParentIdUnion;
payload->data.x_struct.parent.data.p_union.union_val = out_val;
}
@@ -17727,24 +17906,24 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira,
return result_type;
}
-static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_type_id(IrAnalyze *ira,
IrInstructionTypeId *instruction)
{
IrInstruction *type_value = instruction->type_value->other;
- TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value);
if (type_is_invalid(type_entry))
return ira->codegen->builtin_types.entry_invalid;
ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId");
- assert(var_value->type->id == TypeTableEntryIdMetaType);
- TypeTableEntry *result_type = var_value->data.x_type;
+ assert(var_value->type->id == ZigTypeIdMetaType);
+ ZigType *result_type = var_value->data.x_type;
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry));
return result_type;
}
-static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
IrInstructionSetEvalBranchQuota *instruction)
{
if (ira->new_irb.exec->parent_exec != nullptr && !ira->new_irb.exec->is_generic_instantiation) {
@@ -17765,9 +17944,9 @@ static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *i
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
+static ZigType *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
IrInstruction *type_value = instruction->type_value->other;
- TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value);
if (type_is_invalid(type_entry))
return ira->codegen->builtin_types.entry_invalid;
@@ -17779,7 +17958,7 @@ static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstru
return out_val->type;
}
-static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) {
+static ZigType *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) {
AstNode *node = instruction->base.source_node;
assert(node->type == NodeTypeFnCallExpr);
AstNode *block_node = node->data.fn_call_expr.params.at(0);
@@ -17787,7 +17966,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
ScopeCImport *cimport_scope = create_cimport_scope(node, instruction->base.scope);
// Execute the C import block like an inline function
- TypeTableEntry *void_type = ira->codegen->builtin_types.entry_void;
+ ZigType *void_type = ira->codegen->builtin_types.entry_void;
IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,
ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
&cimport_scope->buf, block_node, nullptr, nullptr);
@@ -17838,7 +18017,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_namespace;
}
-static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
+static ZigType *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
IrInstruction *name_value = instruction->name->other;
if (type_is_invalid(name_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -17857,7 +18036,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
+static ZigType *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
IrInstruction *name = instruction->name->other;
if (type_is_invalid(name->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -17884,7 +18063,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
+static ZigType *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
IrInstruction *name = instruction->name->other;
if (type_is_invalid(name->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -17903,7 +18082,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
+static ZigType *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
IrInstruction *name = instruction->name->other;
if (type_is_invalid(name->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -17917,8 +18096,11 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr
Buf source_dir_path = BUF_INIT;
os_path_dirname(import->path, &source_dir_path);
- Buf file_path = BUF_INIT;
- os_path_resolve(&source_dir_path, rel_file_path, &file_path);
+ Buf *resolve_paths[] = {
+ &source_dir_path,
+ rel_file_path,
+ };
+ Buf file_path = os_path_resolve(resolve_paths, 2);
// load from file system into const expr
Buf *file_contents = buf_alloc();
@@ -17942,8 +18124,8 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr
return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(file_contents));
}
-static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) {
- TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other);
+static ZigType *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) {
+ ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other);
if (type_is_invalid(operand_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -17952,7 +18134,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
return ira->codegen->builtin_types.entry_invalid;
// TODO let this be volatile
- TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
+ ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);
if (type_is_invalid(casted_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18023,7 +18205,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
+static ZigType *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
IrInstruction *order_value = instruction->order_value->other;
if (type_is_invalid(order_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18036,26 +18218,26 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {
+static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {
IrInstruction *dest_type_value = instruction->dest_type->other;
- TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
+ ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
- if (dest_type->id != TypeTableEntryIdInt &&
- dest_type->id != TypeTableEntryIdComptimeInt)
+ if (dest_type->id != ZigTypeIdInt &&
+ dest_type->id != ZigTypeIdComptimeInt)
{
ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->builtin_types.entry_invalid;
}
IrInstruction *target = instruction->target->other;
- TypeTableEntry *src_type = target->value.type;
+ ZigType *src_type = target->value.type;
if (type_is_invalid(src_type))
return ira->codegen->builtin_types.entry_invalid;
- if (src_type->id != TypeTableEntryIdInt &&
- src_type->id != TypeTableEntryIdComptimeInt)
+ if (src_type->id != ZigTypeIdInt &&
+ src_type->id != ZigTypeIdComptimeInt)
{
ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -18084,12 +18266,12 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
return dest_type;
}
-static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {
- TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
+static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
- if (dest_type->id != TypeTableEntryIdInt) {
+ if (dest_type->id != ZigTypeIdInt) {
ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->builtin_types.entry_invalid;
}
@@ -18098,7 +18280,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (target->value.type->id == TypeTableEntryIdComptimeInt) {
+ if (target->value.type->id == ZigTypeIdComptimeInt) {
if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type,
CastOpNumLitToConcrete, false);
@@ -18111,7 +18293,7 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc
}
}
- if (target->value.type->id != TypeTableEntryIdInt) {
+ if (target->value.type->id != ZigTypeIdInt) {
ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",
buf_ptr(&target->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -18125,12 +18307,12 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc
return dest_type;
}
-static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {
- TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
+static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
- if (dest_type->id != TypeTableEntryIdFloat) {
+ if (dest_type->id != ZigTypeIdFloat) {
ir_add_error(ira, instruction->dest_type,
buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -18140,12 +18322,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (target->value.type->id == TypeTableEntryIdComptimeInt ||
- target->value.type->id == TypeTableEntryIdComptimeFloat)
+ if (target->value.type->id == ZigTypeIdComptimeInt ||
+ target->value.type->id == ZigTypeIdComptimeFloat)
{
if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) {
CastOp op;
- if (target->value.type->id == TypeTableEntryIdComptimeInt) {
+ if (target->value.type->id == ZigTypeIdComptimeInt) {
op = CastOpIntToFloat;
} else {
op = CastOpNumLitToConcrete;
@@ -18160,7 +18342,7 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr
}
}
- if (target->value.type->id != TypeTableEntryIdFloat) {
+ if (target->value.type->id != ZigTypeIdFloat) {
ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
buf_ptr(&target->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -18173,12 +18355,12 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr
return dest_type;
}
-static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {
- TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
+static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
- if (dest_type->id != TypeTableEntryIdErrorSet) {
+ if (dest_type->id != ZigTypeIdErrorSet) {
ir_add_error(ira, instruction->dest_type,
buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -18188,7 +18370,7 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (target->value.type->id != TypeTableEntryIdErrorSet) {
+ if (target->value.type->id != ZigTypeIdErrorSet) {
ir_add_error(ira, instruction->target,
buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -18201,8 +18383,8 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns
return dest_type;
}
-static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {
- TypeTableEntry *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other);
+static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {
+ ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other);
if (type_is_invalid(dest_child_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18213,12 +18395,12 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr
bool src_ptr_const;
bool src_ptr_volatile;
uint32_t src_ptr_align;
- if (target->value.type->id == TypeTableEntryIdPointer) {
+ if (target->value.type->id == ZigTypeIdPointer) {
src_ptr_const = target->value.type->data.pointer.is_const;
src_ptr_volatile = target->value.type->data.pointer.is_volatile;
src_ptr_align = target->value.type->data.pointer.alignment;
} else if (is_slice(target->value.type)) {
- TypeTableEntry *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
+ ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
src_ptr_const = src_ptr_type->data.pointer.is_const;
src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;
src_ptr_align = src_ptr_type->data.pointer.alignment;
@@ -18228,15 +18410,15 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr
src_ptr_align = get_abi_alignment(ira->codegen, target->value.type);
}
- TypeTableEntry *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type,
+ ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type,
src_ptr_const, src_ptr_volatile, PtrLenUnknown,
src_ptr_align, 0, 0);
- TypeTableEntry *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
+ ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
- TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
+ ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
src_ptr_const, src_ptr_volatile, PtrLenUnknown,
src_ptr_align, 0, 0);
- TypeTableEntry *u8_slice = get_slice_type(ira->codegen, u8_ptr);
+ ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice);
if (type_is_invalid(casted_value->value.type))
@@ -18281,7 +18463,7 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr
return dest_slice_type;
}
-static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) {
+static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) {
IrInstruction *target = instruction->target->other;
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18292,20 +18474,20 @@ static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
+ ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry;
- TypeTableEntry *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
+ ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown,
src_ptr_type->data.pointer.alignment, 0, 0);
- TypeTableEntry *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
+ ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true);
ir_link_new_instruction(result, &instruction->base);
return dest_slice_type;
}
-static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {
- TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
+static ZigType *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18313,7 +18495,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (target->value.type->id != TypeTableEntryIdInt && target->value.type->id != TypeTableEntryIdComptimeInt) {
+ if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) {
ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",
buf_ptr(&target->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -18324,8 +18506,8 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns
return dest_type;
}
-static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
- TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
+static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {
+ ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18333,18 +18515,32 @@ static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrIns
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
+ if (target->value.type->id == ZigTypeIdComptimeInt) {
+ IrInstruction *casted_value = ir_implicit_cast(ira, target, dest_type);
+ if (type_is_invalid(casted_value->value.type))
+ return ira->codegen->builtin_types.entry_invalid;
+ ir_link_new_instruction(casted_value, &instruction->base);
+ return casted_value->value.type;
+ }
+
+ if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) {
+ ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",
+ buf_ptr(&target->value.type->name)));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
+
IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false);
ir_link_new_instruction(result, &instruction->base);
return dest_type;
}
-static TypeTableEntry *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {
+static ZigType *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {
IrInstruction *target = instruction->target->other;
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
IrInstruction *casted_target;
- if (target->value.type->id == TypeTableEntryIdErrorSet) {
+ if (target->value.type->id == ZigTypeIdErrorSet) {
casted_target = target;
} else {
casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);
@@ -18357,7 +18553,7 @@ static TypeTableEntry *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstr
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {
+static ZigType *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {
IrInstruction *target = instruction->target->other;
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18371,12 +18567,12 @@ static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstr
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {
+static ZigType *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {
IrInstruction *target = instruction->target->other;
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (target->value.type->id != TypeTableEntryIdBool) {
+ if (target->value.type->id != ZigTypeIdBool) {
ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",
buf_ptr(&target->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -18392,13 +18588,13 @@ static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInst
return ira->codegen->builtin_types.entry_num_lit_int;
}
- TypeTableEntry *u1_type = get_int_type(ira->codegen, false, 1);
+ ZigType *u1_type = get_int_type(ira->codegen, false, 1);
IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false);
ir_link_new_instruction(result, &instruction->base);
return u1_type;
}
-static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {
+static ZigType *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {
IrInstruction *is_signed_value = instruction->is_signed->other;
bool is_signed;
if (!ir_resolve_bool(ira, is_signed_value, &is_signed))
@@ -18414,12 +18610,12 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_type;
}
-static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
+static ZigType *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
IrInstruction *value = instruction->value->other;
if (type_is_invalid(value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
+ ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);
if (type_is_invalid(casted_value->value.type))
@@ -18439,7 +18635,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc
return bool_type;
}
-static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {
+static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {
IrInstruction *dest_ptr = instruction->dest_ptr->other;
if (type_is_invalid(dest_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18452,15 +18648,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
if (type_is_invalid(count_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *dest_uncasted_type = dest_ptr->value.type;
- bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) &&
+ ZigType *dest_uncasted_type = dest_ptr->value.type;
+ bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
dest_uncasted_type->data.pointer.is_volatile;
- TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
- TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;
- uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ?
+ ZigType *usize = ira->codegen->builtin_types.entry_usize;
+ ZigType *u8 = ira->codegen->builtin_types.entry_u8;
+ uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ?
dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
- TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
+ ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
PtrLenUnknown, dest_align, 0, 0);
IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
@@ -18531,7 +18727,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {
+static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {
IrInstruction *dest_ptr = instruction->dest_ptr->other;
if (type_is_invalid(dest_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18544,22 +18740,22 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
if (type_is_invalid(count_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;
- TypeTableEntry *dest_uncasted_type = dest_ptr->value.type;
- TypeTableEntry *src_uncasted_type = src_ptr->value.type;
- bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) &&
+ ZigType *u8 = ira->codegen->builtin_types.entry_u8;
+ ZigType *dest_uncasted_type = dest_ptr->value.type;
+ ZigType *src_uncasted_type = src_ptr->value.type;
+ bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
dest_uncasted_type->data.pointer.is_volatile;
- bool src_is_volatile = (src_uncasted_type->id == TypeTableEntryIdPointer) &&
+ bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) &&
src_uncasted_type->data.pointer.is_volatile;
- uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ?
+ uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ?
dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
- uint32_t src_align = (src_uncasted_type->id == TypeTableEntryIdPointer) ?
+ uint32_t src_align = (src_uncasted_type->id == ZigTypeIdPointer) ?
src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8);
- TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
- TypeTableEntry *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
+ ZigType *usize = ira->codegen->builtin_types.entry_usize;
+ ZigType *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
PtrLenUnknown, dest_align, 0, 0);
- TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
+ ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
PtrLenUnknown, src_align, 0, 0);
IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
@@ -18666,20 +18862,20 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) {
+static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) {
IrInstruction *ptr_ptr = instruction->ptr->other;
if (type_is_invalid(ptr_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *ptr_type = ptr_ptr->value.type;
- assert(ptr_type->id == TypeTableEntryIdPointer);
- TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
+ ZigType *ptr_type = ptr_ptr->value.type;
+ assert(ptr_type->id == ZigTypeIdPointer);
+ ZigType *array_type = ptr_type->data.pointer.child_type;
IrInstruction *start = instruction->start->other;
if (type_is_invalid(start->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
+ ZigType *usize = ira->codegen->builtin_types.entry_usize;
IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);
if (type_is_invalid(casted_start->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18696,26 +18892,26 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
end = nullptr;
}
- TypeTableEntry *return_type;
+ ZigType *return_type;
- if (array_type->id == TypeTableEntryIdArray) {
+ if (array_type->id == ZigTypeIdArray) {
uint32_t byte_alignment = ptr_type->data.pointer.alignment;
if (array_type->data.array.len == 0 && byte_alignment == 0) {
byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type);
}
bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic &&
ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst;
- TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
+ ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type,
ptr_type->data.pointer.is_const || is_comptime_const,
ptr_type->data.pointer.is_volatile,
PtrLenUnknown,
byte_alignment, 0, 0);
return_type = get_slice_type(ira->codegen, slice_ptr_type);
- } else if (array_type->id == TypeTableEntryIdPointer) {
+ } else if (array_type->id == ZigTypeIdPointer) {
if (array_type->data.pointer.ptr_len == PtrLenSingle) {
- TypeTableEntry *main_type = array_type->data.pointer.child_type;
- if (main_type->id == TypeTableEntryIdArray) {
- TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen,
+ ZigType *main_type = array_type->data.pointer.child_type;
+ if (main_type->id == ZigTypeIdArray) {
+ ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen,
main_type->data.pointer.child_type,
array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,
PtrLenUnknown,
@@ -18726,7 +18922,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
return ira->codegen->builtin_types.entry_invalid;
}
} else {
- TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type,
+ ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type,
array_type->data.pointer.is_const, array_type->data.pointer.is_volatile,
PtrLenUnknown,
array_type->data.pointer.alignment, 0, 0);
@@ -18737,7 +18933,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
}
}
} else if (is_slice(array_type)) {
- TypeTableEntry *ptr_type = array_type->data.structure.fields[slice_ptr_index].type_entry;
+ ZigType *ptr_type = array_type->data.structure.fields[slice_ptr_index].type_entry;
return_type = get_slice_type(ira->codegen, ptr_type);
} else {
ir_add_error(ira, &instruction->base,
@@ -18754,25 +18950,36 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
size_t abs_offset;
size_t rel_end;
bool ptr_is_undef = false;
- if (array_type->id == TypeTableEntryIdArray ||
- (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
+ if (array_type->id == ZigTypeIdArray ||
+ (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle))
{
- if (array_type->id == TypeTableEntryIdPointer) {
- TypeTableEntry *child_array_type = array_type->data.pointer.child_type;
- assert(child_array_type->id == TypeTableEntryIdArray);
- parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
- array_val = const_ptr_pointee(ira->codegen, parent_ptr);
+ if (array_type->id == ZigTypeIdPointer) {
+ ZigType *child_array_type = array_type->data.pointer.child_type;
+ assert(child_array_type->id == ZigTypeIdArray);
+ parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
+ if (parent_ptr == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
+
+ array_val = ir_const_ptr_pointee(ira, parent_ptr, instruction->base.source_node);
+ if (array_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
+
rel_end = child_array_type->data.array.len;
abs_offset = 0;
} else {
- array_val = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
+ array_val = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
+ if (array_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
rel_end = array_type->data.array.len;
parent_ptr = nullptr;
abs_offset = 0;
}
- } else if (array_type->id == TypeTableEntryIdPointer) {
+ } else if (array_type->id == ZigTypeIdPointer) {
assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
- parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
+ parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
+ if (parent_ptr == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
+
if (parent_ptr->special == ConstValSpecialUndef) {
array_val = nullptr;
abs_offset = 0;
@@ -18803,7 +19010,10 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
zig_panic("TODO slice of ptr cast from function");
}
} else if (is_slice(array_type)) {
- ConstExprValue *slice_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value);
+ ConstExprValue *slice_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);
+ if (slice_ptr == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
+
parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index];
ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index];
@@ -18871,11 +19081,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
size_t index = abs_offset + start_scalar;
bool is_const = slice_is_const(return_type);
init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown);
- if (array_type->id == TypeTableEntryIdArray) {
+ if (array_type->id == ZigTypeIdArray) {
ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut;
} else if (is_slice(array_type)) {
ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
- } else if (array_type->id == TypeTableEntryIdPointer) {
+ } else if (array_type->id == ZigTypeIdPointer) {
ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut;
}
} else if (ptr_is_undef) {
@@ -18917,12 +19127,12 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
return return_type;
}
-static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
+static ZigType *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
Error err;
IrInstruction *container = instruction->container->other;
if (type_is_invalid(container->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *container_type = ir_resolve_type(ira, container);
+ ZigType *container_type = ir_resolve_type(ira, container);
if ((err = ensure_complete_type(ira->codegen, container_type)))
return ira->codegen->builtin_types.entry_invalid;
@@ -18930,13 +19140,13 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
uint64_t result;
if (type_is_invalid(container_type)) {
return ira->codegen->builtin_types.entry_invalid;
- } else if (container_type->id == TypeTableEntryIdEnum) {
+ } else if (container_type->id == ZigTypeIdEnum) {
result = container_type->data.enumeration.src_field_count;
- } else if (container_type->id == TypeTableEntryIdStruct) {
+ } else if (container_type->id == ZigTypeIdStruct) {
result = container_type->data.structure.src_field_count;
- } else if (container_type->id == TypeTableEntryIdUnion) {
+ } else if (container_type->id == ZigTypeIdUnion) {
result = container_type->data.unionation.src_field_count;
- } else if (container_type->id == TypeTableEntryIdErrorSet) {
+ } else if (container_type->id == ZigTypeIdErrorSet) {
if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {
return ira->codegen->builtin_types.entry_invalid;
}
@@ -18955,10 +19165,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
return ira->codegen->builtin_types.entry_num_lit_int;
}
-static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {
+static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {
Error err;
IrInstruction *container_type_value = instruction->container_type->other;
- TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
+ ZigType *container_type = ir_resolve_type(ira, container_type_value);
if (type_is_invalid(container_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -18971,7 +19181,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
if (!ir_resolve_usize(ira, index_value, &member_index))
return ira->codegen->builtin_types.entry_invalid;
- if (container_type->id == TypeTableEntryIdStruct) {
+ if (container_type->id == ZigTypeIdStruct) {
if (member_index >= container_type->data.structure.src_field_count) {
ir_add_error(ira, index_value,
buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
@@ -18983,7 +19193,7 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
out_val->data.x_type = field->type_entry;
return ira->codegen->builtin_types.entry_type;
- } else if (container_type->id == TypeTableEntryIdUnion) {
+ } else if (container_type->id == ZigTypeIdUnion) {
if (member_index >= container_type->data.unionation.src_field_count) {
ir_add_error(ira, index_value,
buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
@@ -19002,10 +19212,10 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
}
}
-static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {
+static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {
Error err;
IrInstruction *container_type_value = instruction->container_type->other;
- TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
+ ZigType *container_type = ir_resolve_type(ira, container_type_value);
if (type_is_invalid(container_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -19017,7 +19227,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
if (!ir_resolve_usize(ira, index_value, &member_index))
return ira->codegen->builtin_types.entry_invalid;
- if (container_type->id == TypeTableEntryIdStruct) {
+ if (container_type->id == ZigTypeIdStruct) {
if (member_index >= container_type->data.structure.src_field_count) {
ir_add_error(ira, index_value,
buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
@@ -19029,7 +19239,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
init_const_str_lit(ira->codegen, out_val, field->name);
return out_val->type;
- } else if (container_type->id == TypeTableEntryIdEnum) {
+ } else if (container_type->id == ZigTypeIdEnum) {
if (member_index >= container_type->data.enumeration.src_field_count) {
ir_add_error(ira, index_value,
buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
@@ -19041,7 +19251,7 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
init_const_str_lit(ira->codegen, out_val, field->name);
return out_val->type;
- } else if (container_type->id == TypeTableEntryIdUnion) {
+ } else if (container_type->id == ZigTypeIdUnion) {
if (member_index >= container_type->data.unionation.src_field_count) {
ir_add_error(ira, index_value,
buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
@@ -19060,76 +19270,76 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
}
}
-static TypeTableEntry *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {
+static ZigType *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {
ir_build_breakpoint_from(&ira->new_irb, &instruction->base);
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
+static ZigType *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {
ir_build_return_address_from(&ira->new_irb, &instruction->base);
- TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;
- TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
+ ZigType *u8 = ira->codegen->builtin_types.entry_u8;
+ ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
return u8_ptr_const;
}
-static TypeTableEntry *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
+static ZigType *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {
ir_build_frame_address_from(&ira->new_irb, &instruction->base);
- TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8;
- TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
+ ZigType *u8 = ira->codegen->builtin_types.entry_u8;
+ ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true);
return u8_ptr_const;
}
-static TypeTableEntry *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) {
+static ZigType *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) {
ir_build_handle_from(&ira->new_irb, &instruction->base);
- FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
assert(fn_entry != nullptr);
return get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type);
}
-static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
+static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
Error err;
IrInstruction *type_value = instruction->type_value->other;
if (type_is_invalid(type_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
+ ZigType *type_entry = ir_resolve_type(ira, type_value);
if ((err = type_ensure_zero_bits_known(ira->codegen, type_entry)))
return ira->codegen->builtin_types.entry_invalid;
switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
+ case ZigTypeIdInvalid:
zig_unreachable();
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdOpaque:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdVoid:
+ case ZigTypeIdOpaque:
ir_add_error(ira, instruction->type_value,
buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name)));
return ira->codegen->builtin_types.entry_invalid;
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdPromise:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdOptional:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdErrorSet:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
+ case ZigTypeIdBool:
+ case ZigTypeIdInt:
+ case ZigTypeIdFloat:
+ case ZigTypeIdPointer:
+ case ZigTypeIdPromise:
+ case ZigTypeIdArray:
+ case ZigTypeIdStruct:
+ case ZigTypeIdOptional:
+ case ZigTypeIdErrorUnion:
+ case ZigTypeIdErrorSet:
+ case ZigTypeIdEnum:
+ case ZigTypeIdUnion:
+ case ZigTypeIdFn:
{
uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry);
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
@@ -19140,16 +19350,16 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {
+static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {
IrInstruction *type_value = instruction->type_value->other;
if (type_is_invalid(type_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *dest_type = ir_resolve_type(ira, type_value);
+ ZigType *dest_type = ir_resolve_type(ira, type_value);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
- if (dest_type->id != TypeTableEntryIdInt) {
+ if (dest_type->id != ZigTypeIdInt) {
ir_add_error(ira, type_value,
buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -19169,7 +19379,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
IrInstruction *casted_op2;
if (instruction->op == IrOverflowOpShl) {
- TypeTableEntry *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
+ ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
dest_type->data.integral.bit_count - 1);
casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);
} else {
@@ -19182,8 +19392,8 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
if (type_is_invalid(result_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *expected_ptr_type;
- if (result_ptr->value.type->id == TypeTableEntryIdPointer) {
+ ZigType *expected_ptr_type;
+ if (result_ptr->value.type->id == ZigTypeIdPointer) {
expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
false, result_ptr->value.type->data.pointer.is_volatile,
PtrLenSingle,
@@ -19203,7 +19413,9 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
BigInt *op1_bigint = &casted_op1->value.data.x_bigint;
BigInt *op2_bigint = &casted_op2->value.data.x_bigint;
- ConstExprValue *pointee_val = const_ptr_pointee(ira->codegen, &casted_result_ptr->value);
+ ConstExprValue *pointee_val = ir_const_ptr_pointee(ira, &casted_result_ptr->value, casted_result_ptr->source_node);
+ if (pointee_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
BigInt *dest_bigint = &pointee_val->data.x_bigint;
switch (instruction->op) {
case IrOverflowOpAdd:
@@ -19237,15 +19449,15 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
return ira->codegen->builtin_types.entry_bool;
}
-static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {
+static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {
IrInstruction *value = instruction->value->other;
if (type_is_invalid(value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *type_entry = value->value.type;
+ ZigType *type_entry = value->value.type;
if (type_is_invalid(type_entry)) {
return ira->codegen->builtin_types.entry_invalid;
- } else if (type_entry->id == TypeTableEntryIdErrorUnion) {
+ } else if (type_entry->id == ZigTypeIdErrorUnion) {
if (instr_is_comptime(value)) {
ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
if (!err_union_val)
@@ -19258,7 +19470,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
}
}
- TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type;
+ ZigType *err_set_type = type_entry->data.error_union.err_set_type;
if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {
return ira->codegen->builtin_types.entry_invalid;
}
@@ -19273,7 +19485,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
ir_build_test_err_from(&ira->new_irb, &instruction->base, value);
return ira->codegen->builtin_types.entry_bool;
- } else if (type_entry->id == TypeTableEntryIdErrorSet) {
+ } else if (type_entry->id == ZigTypeIdErrorSet) {
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
out_val->data.x_bool = true;
return ira->codegen->builtin_types.entry_bool;
@@ -19284,26 +19496,28 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
}
}
-static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
IrInstructionUnwrapErrCode *instruction)
{
IrInstruction *value = instruction->value->other;
if (type_is_invalid(value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *ptr_type = value->value.type;
+ ZigType *ptr_type = value->value.type;
// This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ assert(ptr_type->id == ZigTypeIdPointer);
- TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
+ ZigType *type_entry = ptr_type->data.pointer.child_type;
if (type_is_invalid(type_entry)) {
return ira->codegen->builtin_types.entry_invalid;
- } else if (type_entry->id == TypeTableEntryIdErrorUnion) {
+ } else if (type_entry->id == ZigTypeIdErrorUnion) {
if (instr_is_comptime(value)) {
ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
if (!ptr_val)
return ira->codegen->builtin_types.entry_invalid;
- ConstExprValue *err_union_val = const_ptr_pointee(ira->codegen, ptr_val);
+ ConstExprValue *err_union_val = ir_const_ptr_pointee(ira, ptr_val, instruction->base.source_node);
+ if (err_union_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
if (err_union_val->special != ConstValSpecialRuntime) {
ErrorTableEntry *err = err_union_val->data.x_err_union.err;
assert(err);
@@ -19323,27 +19537,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
}
}
-static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
IrInstructionUnwrapErrPayload *instruction)
{
assert(instruction->value->other);
IrInstruction *value = instruction->value->other;
if (type_is_invalid(value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *ptr_type = value->value.type;
+ ZigType *ptr_type = value->value.type;
// This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
- assert(ptr_type->id == TypeTableEntryIdPointer);
+ assert(ptr_type->id == ZigTypeIdPointer);
- TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
+ ZigType *type_entry = ptr_type->data.pointer.child_type;
if (type_is_invalid(type_entry)) {
return ira->codegen->builtin_types.entry_invalid;
- } else if (type_entry->id == TypeTableEntryIdErrorUnion) {
- TypeTableEntry *payload_type = type_entry->data.error_union.payload_type;
+ } else if (type_entry->id == ZigTypeIdErrorUnion) {
+ ZigType *payload_type = type_entry->data.error_union.payload_type;
if (type_is_invalid(payload_type)) {
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,
+ ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,
ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
PtrLenSingle,
get_abi_alignment(ira->codegen, payload_type), 0, 0);
@@ -19351,7 +19565,9 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
if (!ptr_val)
return ira->codegen->builtin_types.entry_invalid;
- ConstExprValue *err_union_val = const_ptr_pointee(ira->codegen, ptr_val);
+ ConstExprValue *err_union_val = ir_const_ptr_pointee(ira, ptr_val, instruction->base.source_node);
+ if (err_union_val == nullptr)
+ return ira->codegen->builtin_types.entry_invalid;
if (err_union_val->special != ConstValSpecialRuntime) {
ErrorTableEntry *err = err_union_val->data.x_err_union.err;
if (err != nullptr) {
@@ -19377,7 +19593,8 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
}
-static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) {
+static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) {
+ Error err;
AstNode *proto_node = instruction->base.source_node;
assert(proto_node->type == NodeTypeFnProto);
@@ -19419,9 +19636,25 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other;
if (type_is_invalid(param_type_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- param_info->type = ir_resolve_type(ira, param_type_value);
- if (type_is_invalid(param_info->type))
+ ZigType *param_type = ir_resolve_type(ira, param_type_value);
+ if (type_is_invalid(param_type))
+ return ira->codegen->builtin_types.entry_invalid;
+ if ((err = type_ensure_zero_bits_known(ira->codegen, param_type)))
return ira->codegen->builtin_types.entry_invalid;
+ if (type_requires_comptime(param_type)) {
+ if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
+ ir_add_error(ira, &instruction->base,
+ buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",
+ buf_ptr(¶m_type->name), calling_convention_name(fn_type_id.cc)));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
+ param_info->type = param_type;
+ fn_type_id.next_param_index += 1;
+ ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
+ out_val->data.x_type = get_generic_fn_type(ira->codegen, &fn_type_id);
+ return ira->codegen->builtin_types.entry_type;
+ }
+ param_info->type = param_type;
}
}
@@ -19435,7 +19668,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
if (type_is_invalid(fn_type_id.return_type))
return ira->codegen->builtin_types.entry_invalid;
- if (fn_type_id.return_type->id == TypeTableEntryIdOpaque) {
+ if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
ir_add_error(ira, instruction->return_type,
buf_sprintf("return type cannot be opaque"));
return ira->codegen->builtin_types.entry_invalid;
@@ -19458,7 +19691,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_type;
}
-static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
+static ZigType *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
IrInstruction *value = instruction->value->other;
if (type_is_invalid(value->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -19468,15 +19701,15 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn
return ira->codegen->builtin_types.entry_bool;
}
-static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
IrInstructionCheckSwitchProngs *instruction)
{
IrInstruction *target_value = instruction->target_value->other;
- TypeTableEntry *switch_type = target_value->value.type;
+ ZigType *switch_type = target_value->value.type;
if (type_is_invalid(switch_type))
return ira->codegen->builtin_types.entry_invalid;
- if (switch_type->id == TypeTableEntryIdEnum) {
+ if (switch_type->id == ZigTypeIdEnum) {
HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};
field_prev_uses.init(switch_type->data.enumeration.src_field_count);
@@ -19491,7 +19724,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
if (type_is_invalid(end_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (start_value->value.type->id != TypeTableEntryIdEnum) {
+ if (start_value->value.type->id != ZigTypeIdEnum) {
ir_add_error(ira, range->start, buf_sprintf("not an enum type"));
return ira->codegen->builtin_types.entry_invalid;
}
@@ -19499,7 +19732,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
BigInt start_index;
bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag);
- assert(end_value->value.type->id == TypeTableEntryIdEnum);
+ assert(end_value->value.type->id == ZigTypeIdEnum);
BigInt end_index;
bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag);
@@ -19535,7 +19768,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
}
}
}
- } else if (switch_type->id == TypeTableEntryIdErrorSet) {
+ } else if (switch_type->id == ZigTypeIdErrorSet) {
if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {
return ira->codegen->builtin_types.entry_invalid;
}
@@ -19553,10 +19786,10 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
if (type_is_invalid(end_value->value.type))
return ira->codegen->builtin_types.entry_invalid;
- assert(start_value->value.type->id == TypeTableEntryIdErrorSet);
+ assert(start_value->value.type->id == ZigTypeIdErrorSet);
uint32_t start_index = start_value->value.data.x_err_set->value;
- assert(end_value->value.type->id == TypeTableEntryIdErrorSet);
+ assert(end_value->value.type->id == ZigTypeIdErrorSet);
uint32_t end_index = end_value->value.data.x_err_set->value;
if (start_index != end_index) {
@@ -19592,7 +19825,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
}
free(field_prev_uses);
- } else if (switch_type->id == TypeTableEntryIdInt) {
+ } else if (switch_type->id == ZigTypeIdInt) {
RangeSet rs = {0};
for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
@@ -19619,8 +19852,8 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
if (!end_val)
return ira->codegen->builtin_types.entry_invalid;
- assert(start_val->type->id == TypeTableEntryIdInt || start_val->type->id == TypeTableEntryIdComptimeInt);
- assert(end_val->type->id == TypeTableEntryIdInt || end_val->type->id == TypeTableEntryIdComptimeInt);
+ assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);
+ assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
start_value->source_node);
if (prev_node != nullptr) {
@@ -19648,15 +19881,15 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
IrInstructionCheckStatementIsVoid *instruction)
{
IrInstruction *statement_value = instruction->statement_value->other;
- TypeTableEntry *statement_type = statement_value->value.type;
+ ZigType *statement_type = statement_value->value.type;
if (type_is_invalid(statement_type))
return ira->codegen->builtin_types.entry_invalid;
- if (statement_type->id != TypeTableEntryIdVoid) {
+ if (statement_type->id != ZigTypeIdVoid) {
ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored"));
}
@@ -19664,7 +19897,7 @@ static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
+static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
IrInstruction *msg = instruction->msg->other;
if (type_is_invalid(msg->value.type))
return ir_unreach_error(ira);
@@ -19674,9 +19907,9 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio
return ir_unreach_error(ira);
}
- TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
+ ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0);
- TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type);
+ ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);
if (type_is_invalid(casted_msg->value.type))
return ir_unreach_error(ira);
@@ -19688,40 +19921,40 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio
}
static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) {
- TypeTableEntry *target_type = target->value.type;
+ ZigType *target_type = target->value.type;
assert(!type_is_invalid(target_type));
- TypeTableEntry *result_type;
+ ZigType *result_type;
uint32_t old_align_bytes;
- if (target_type->id == TypeTableEntryIdPointer) {
+ if (target_type->id == ZigTypeIdPointer) {
result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);
old_align_bytes = target_type->data.pointer.alignment;
- } else if (target_type->id == TypeTableEntryIdFn) {
+ } else if (target_type->id == ZigTypeIdFn) {
FnTypeId fn_type_id = target_type->data.fn.fn_type_id;
old_align_bytes = fn_type_id.alignment;
fn_type_id.alignment = align_bytes;
result_type = get_fn_type(ira->codegen, &fn_type_id);
- } else if (target_type->id == TypeTableEntryIdOptional &&
- target_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
+ } else if (target_type->id == ZigTypeIdOptional &&
+ target_type->data.maybe.child_type->id == ZigTypeIdPointer)
{
- TypeTableEntry *ptr_type = target_type->data.maybe.child_type;
+ ZigType *ptr_type = target_type->data.maybe.child_type;
old_align_bytes = ptr_type->data.pointer.alignment;
- TypeTableEntry *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
+ ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
result_type = get_optional_type(ira->codegen, better_ptr_type);
- } else if (target_type->id == TypeTableEntryIdOptional &&
- target_type->data.maybe.child_type->id == TypeTableEntryIdFn)
+ } else if (target_type->id == ZigTypeIdOptional &&
+ target_type->data.maybe.child_type->id == ZigTypeIdFn)
{
FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id;
old_align_bytes = fn_type_id.alignment;
fn_type_id.alignment = align_bytes;
- TypeTableEntry *fn_type = get_fn_type(ira->codegen, &fn_type_id);
+ ZigType *fn_type = get_fn_type(ira->codegen, &fn_type_id);
result_type = get_optional_type(ira->codegen, fn_type);
} else if (is_slice(target_type)) {
- TypeTableEntry *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
+ ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
old_align_bytes = slice_ptr_type->data.pointer.alignment;
- TypeTableEntry *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
+ ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
result_type = get_slice_type(ira->codegen, result_ptr_type);
} else {
ir_add_error(ira, target,
@@ -19759,16 +19992,16 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
return result;
}
-static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) {
+static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) {
Error err;
IrInstruction *dest_type_value = instruction->dest_type->other;
- TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
+ ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
IrInstruction *ptr = instruction->ptr->other;
- TypeTableEntry *src_type = ptr->value.type;
+ ZigType *src_type = ptr->value.type;
if (type_is_invalid(src_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -19835,33 +20068,33 @@ static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruc
static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {
assert(val->special == ConstValSpecialStatic);
switch (val->type->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdPromise:
zig_unreachable();
- case TypeTableEntryIdVoid:
+ case ZigTypeIdVoid:
return;
- case TypeTableEntryIdBool:
+ case ZigTypeIdBool:
buf[0] = val->data.x_bool ? 1 : 0;
return;
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
codegen->is_big_endian);
return;
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
float_write_ieee597(val, buf, codegen->is_big_endian);
return;
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
BigInt bn;
bigint_init_unsigned(&bn, val->data.x_ptr.data.hard_coded_addr.addr);
@@ -19870,7 +20103,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
} else {
zig_unreachable();
}
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
{
size_t buf_i = 0;
expand_undef_array(codegen, val);
@@ -19881,19 +20114,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
}
}
return;
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
zig_panic("TODO buf_write_value_bytes struct type");
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
zig_panic("TODO buf_write_value_bytes maybe type");
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
zig_panic("TODO buf_write_value_bytes error union");
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdErrorSet:
zig_panic("TODO buf_write_value_bytes pure error type");
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
zig_panic("TODO buf_write_value_bytes enum type");
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
zig_panic("TODO buf_write_value_bytes fn type");
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
zig_panic("TODO buf_write_value_bytes union type");
}
zig_unreachable();
@@ -19902,33 +20135,33 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) {
assert(val->special == ConstValSpecialStatic);
switch (val->type->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
- case TypeTableEntryIdPromise:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdPromise:
zig_unreachable();
- case TypeTableEntryIdVoid:
+ case ZigTypeIdVoid:
return;
- case TypeTableEntryIdBool:
+ case ZigTypeIdBool:
val->data.x_bool = (buf[0] != 0);
return;
- case TypeTableEntryIdInt:
+ case ZigTypeIdInt:
bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
codegen->is_big_endian, val->type->data.integral.is_signed);
return;
- case TypeTableEntryIdFloat:
+ case ZigTypeIdFloat:
float_read_ieee597(val, buf, codegen->is_big_endian);
return;
- case TypeTableEntryIdPointer:
+ case ZigTypeIdPointer:
{
val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
BigInt bn;
@@ -19937,35 +20170,35 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn);
return;
}
- case TypeTableEntryIdArray:
+ case ZigTypeIdArray:
zig_panic("TODO buf_read_value_bytes array type");
- case TypeTableEntryIdStruct:
+ case ZigTypeIdStruct:
zig_panic("TODO buf_read_value_bytes struct type");
- case TypeTableEntryIdOptional:
+ case ZigTypeIdOptional:
zig_panic("TODO buf_read_value_bytes maybe type");
- case TypeTableEntryIdErrorUnion:
+ case ZigTypeIdErrorUnion:
zig_panic("TODO buf_read_value_bytes error union");
- case TypeTableEntryIdErrorSet:
+ case ZigTypeIdErrorSet:
zig_panic("TODO buf_read_value_bytes pure error type");
- case TypeTableEntryIdEnum:
+ case ZigTypeIdEnum:
zig_panic("TODO buf_read_value_bytes enum type");
- case TypeTableEntryIdFn:
+ case ZigTypeIdFn:
zig_panic("TODO buf_read_value_bytes fn type");
- case TypeTableEntryIdUnion:
+ case ZigTypeIdUnion:
zig_panic("TODO buf_read_value_bytes union type");
}
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) {
+static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) {
Error err;
IrInstruction *dest_type_value = instruction->dest_type->other;
- TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
+ ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
IrInstruction *value = instruction->value->other;
- TypeTableEntry *src_type = value->value.type;
+ ZigType *src_type = value->value.type;
if (type_is_invalid(src_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -19982,18 +20215,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
}
switch (src_type->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
ir_add_error(ira, dest_type_value,
buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -20008,18 +20241,18 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
}
switch (dest_type->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdOpaque:
- case TypeTableEntryIdBoundFn:
- case TypeTableEntryIdArgTuple:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdComptimeFloat:
- case TypeTableEntryIdComptimeInt:
- case TypeTableEntryIdUndefined:
- case TypeTableEntryIdNull:
+ case ZigTypeIdInvalid:
+ case ZigTypeIdMetaType:
+ case ZigTypeIdOpaque:
+ case ZigTypeIdBoundFn:
+ case ZigTypeIdArgTuple:
+ case ZigTypeIdNamespace:
+ case ZigTypeIdBlock:
+ case ZigTypeIdUnreachable:
+ case ZigTypeIdComptimeFloat:
+ case ZigTypeIdComptimeInt:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
ir_add_error(ira, dest_type_value,
buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -20057,10 +20290,10 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
return dest_type;
}
-static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) {
+static ZigType *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) {
Error err;
IrInstruction *dest_type_value = instruction->dest_type->other;
- TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
+ ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20102,7 +20335,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr
return dest_type;
}
-static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
IrInstructionDeclRef *instruction)
{
Tld *tld = instruction->tld;
@@ -20119,7 +20352,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
case TldIdVar:
{
TldVar *tld_var = (TldVar *)tld;
- VariableTableEntry *var = tld_var->var;
+ ZigVar *var = tld_var->var;
IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var);
if (type_is_invalid(var_ptr->value.type))
@@ -20141,7 +20374,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
case TldIdFn:
{
TldFn *tld_fn = (TldFn *)tld;
- FnTableEntry *fn_entry = tld_fn->fn_entry;
+ ZigFn *fn_entry = tld_fn->fn_entry;
assert(fn_entry->type_entry);
if (tld_fn->extern_lib_name != nullptr) {
@@ -20163,12 +20396,12 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {
+static ZigType *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {
IrInstruction *target = instruction->target->other;
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
+ ZigType *usize = ira->codegen->builtin_types.entry_usize;
if (get_codegen_ptr_type(target->value.type) == nullptr) {
ir_add_error(ira, target,
@@ -20186,7 +20419,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
ConstExprValue *val = ir_resolve_const(ira, target, UndefBad);
if (!val)
return ira->codegen->builtin_types.entry_invalid;
- if (val->type->id == TypeTableEntryIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
+ if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope,
instruction->base.source_node, usize);
bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
@@ -20202,16 +20435,16 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr
return usize;
}
-static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
+static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {
Error err;
- TypeTableEntry *child_type = ir_resolve_type(ira, instruction->child_type->other);
+ ZigType *child_type = ir_resolve_type(ira, instruction->child_type->other);
if (type_is_invalid(child_type))
return ira->codegen->builtin_types.entry_invalid;
- if (child_type->id == TypeTableEntryIdUnreachable) {
+ if (child_type->id == ZigTypeIdUnreachable) {
ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed"));
return ira->codegen->builtin_types.entry_invalid;
- } else if (child_type->id == TypeTableEntryIdOpaque && instruction->ptr_len == PtrLenUnknown) {
+ } else if (child_type->id == ZigTypeIdOpaque && instruction->ptr_len == PtrLenUnknown) {
ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque"));
return ira->codegen->builtin_types.entry_invalid;
}
@@ -20235,7 +20468,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_type;
}
-static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {
+static ZigType *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {
uint32_t align_bytes;
IrInstruction *align_bytes_inst = instruction->align_bytes->other;
if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes))
@@ -20253,7 +20486,7 @@ static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstr
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {
+static ZigType *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {
Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node);
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
out_val->data.x_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node,
@@ -20261,7 +20494,7 @@ static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInst
return ira->codegen->builtin_types.entry_type;
}
-static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) {
+static ZigType *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) {
uint32_t align_bytes;
IrInstruction *align_bytes_inst = instruction->align_bytes->other;
if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes))
@@ -20272,7 +20505,7 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir
return ira->codegen->builtin_types.entry_invalid;
}
- FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
if (fn_entry == nullptr) {
ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function"));
return ira->codegen->builtin_types.entry_invalid;
@@ -20301,9 +20534,9 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {
+static ZigType *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {
IrInstruction *fn_type_inst = instruction->fn_type->other;
- TypeTableEntry *fn_type = ir_resolve_type(ira, fn_type_inst);
+ ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);
if (type_is_invalid(fn_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20312,7 +20545,7 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc
if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
return ira->codegen->builtin_types.entry_invalid;
- if (fn_type->id != TypeTableEntryIdFn) {
+ if (fn_type->id != ZigTypeIdFn) {
ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
return ira->codegen->builtin_types.entry_invalid;
}
@@ -20340,21 +20573,21 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_type;
}
-static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {
+static ZigType *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {
Error err;
IrInstruction *target_inst = instruction->target->other;
- TypeTableEntry *enum_type = ir_resolve_type(ira, target_inst);
+ ZigType *enum_type = ir_resolve_type(ira, target_inst);
if (type_is_invalid(enum_type))
return ira->codegen->builtin_types.entry_invalid;
- if (enum_type->id == TypeTableEntryIdEnum) {
+ if (enum_type->id == ZigTypeIdEnum) {
if ((err = ensure_complete_type(ira->codegen, enum_type)))
return ira->codegen->builtin_types.entry_invalid;
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
out_val->data.x_type = enum_type->data.enumeration.tag_int_type;
return ira->codegen->builtin_types.entry_type;
- } else if (enum_type->id == TypeTableEntryIdUnion) {
+ } else if (enum_type->id == ZigTypeIdUnion) {
if ((err = ensure_complete_type(ira->codegen, enum_type)))
return ira->codegen->builtin_types.entry_invalid;
@@ -20378,7 +20611,7 @@ static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruc
}
}
-static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {
+static ZigType *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {
IrInstruction *target_inst = instruction->target->other;
if (type_is_invalid(target_inst->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20393,7 +20626,7 @@ static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructi
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) {
+static ZigType *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) {
IrInstruction *promise_ptr = instruction->promise_ptr->other;
if (type_is_invalid(promise_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20405,7 +20638,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstruct
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) {
+static ZigType *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) {
IrInstruction *coro_id = instruction->coro_id->other;
if (type_is_invalid(coro_id->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20417,14 +20650,14 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstr
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) {
+static ZigType *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) {
IrInstruction *result = ir_build_coro_size(&ira->new_irb, instruction->base.scope, instruction->base.source_node);
ir_link_new_instruction(result, &instruction->base);
result->value.type = ira->codegen->builtin_types.entry_usize;
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) {
+static ZigType *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) {
IrInstruction *coro_id = instruction->coro_id->other;
if (type_is_invalid(coro_id->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20433,7 +20666,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr
if (type_is_invalid(coro_mem_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
- FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
assert(fn_entry != nullptr);
IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
coro_id, coro_mem_ptr);
@@ -20442,13 +20675,13 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) {
+static ZigType *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) {
IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base, instruction->id);
ir_link_new_instruction(result, &instruction->base);
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) {
+static ZigType *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) {
IrInstruction *err_val = instruction->err_val->other;
if (type_is_invalid(err_val->value.type))
return ir_unreach_error(ira);
@@ -20459,7 +20692,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, Ir
return ir_finish_anal(ira, result->value.type);
}
-static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) {
+static ZigType *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) {
IrInstruction *save_point = nullptr;
if (instruction->save_point != nullptr) {
save_point = instruction->save_point->other;
@@ -20478,7 +20711,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrIns
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) {
+static ZigType *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) {
IrInstruction *result = ir_build_coro_end(&ira->new_irb, instruction->base.scope,
instruction->base.source_node);
ir_link_new_instruction(result, &instruction->base);
@@ -20486,7 +20719,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstruc
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) {
+static ZigType *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) {
IrInstruction *coro_id = instruction->coro_id->other;
if (type_is_invalid(coro_id->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20498,12 +20731,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstru
IrInstruction *result = ir_build_coro_free(&ira->new_irb, instruction->base.scope,
instruction->base.source_node, coro_id, coro_handle);
ir_link_new_instruction(result, &instruction->base);
- TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
+ ZigType *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
result->value.type = get_optional_type(ira->codegen, ptr_type);
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) {
+static ZigType *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) {
IrInstruction *awaiter_handle = instruction->awaiter_handle->other;
if (type_is_invalid(awaiter_handle->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20519,7 +20752,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInst
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) {
+static ZigType *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) {
IrInstruction *coro_handle = instruction->coro_handle->other;
if (type_is_invalid(coro_handle->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20531,12 +20764,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstru
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) {
+static ZigType *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) {
IrInstruction *coro_handle = instruction->coro_handle->other;
if (type_is_invalid(coro_handle->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (coro_handle->value.type->id != TypeTableEntryIdPromise ||
+ if (coro_handle->value.type->id != ZigTypeIdPromise ||
coro_handle->value.type->data.promise.result_type == nullptr)
{
ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
@@ -20544,7 +20777,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns
return ira->codegen->builtin_types.entry_invalid;
}
- TypeTableEntry *coro_frame_type = get_promise_frame_type(ira->codegen,
+ ZigType *coro_frame_type = get_promise_frame_type(ira->codegen,
coro_handle->value.type->data.promise.result_type);
IrInstruction *result = ir_build_coro_promise(&ira->new_irb, instruction->base.scope,
@@ -20554,7 +20787,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) {
+static ZigType *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) {
IrInstruction *alloc_fn = instruction->alloc_fn->other;
if (type_is_invalid(alloc_fn->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20566,17 +20799,17 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira,
IrInstruction *result = ir_build_coro_alloc_helper(&ira->new_irb, instruction->base.scope,
instruction->base.source_node, alloc_fn, coro_size);
ir_link_new_instruction(result, &instruction->base);
- TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
+ ZigType *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
result->value.type = get_optional_type(ira->codegen, u8_ptr_type);
return result->value.type;
}
-static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
- TypeTableEntry *operand_type = ir_resolve_type(ira, op);
+static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
+ ZigType *operand_type = ir_resolve_type(ira, op);
if (type_is_invalid(operand_type))
return ira->codegen->builtin_types.entry_invalid;
- if (operand_type->id == TypeTableEntryIdInt) {
+ if (operand_type->id == ZigTypeIdInt) {
if (operand_type->data.integral.bit_count < 8) {
ir_add_error(ira, op,
buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",
@@ -20603,8 +20836,8 @@ static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruct
return operand_type;
}
-static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) {
- TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);
+static ZigType *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) {
+ ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);
if (type_is_invalid(operand_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20613,7 +20846,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr
return ira->codegen->builtin_types.entry_invalid;
// TODO let this be volatile
- TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
+ ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
if (type_is_invalid(casted_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20661,8 +20894,8 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) {
- TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);
+static ZigType *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) {
+ ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other);
if (type_is_invalid(operand_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20670,7 +20903,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst
if (type_is_invalid(ptr_inst->value.type))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
+ ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
if (type_is_invalid(casted_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20704,12 +20937,12 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) {
- TypeTableEntry *promise_type = ir_resolve_type(ira, instruction->promise_type->other);
+static ZigType *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) {
+ ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->other);
if (type_is_invalid(promise_type))
return ira->codegen->builtin_types.entry_invalid;
- if (promise_type->id != TypeTableEntryIdPromise || promise_type->data.promise.result_type == nullptr) {
+ if (promise_type->id != ZigTypeIdPromise || promise_type->data.promise.result_type == nullptr) {
ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
buf_ptr(&promise_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -20720,12 +20953,12 @@ static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira
return ira->codegen->builtin_types.entry_type;
}
-static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) {
- TypeTableEntry *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other);
+static ZigType *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) {
+ ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other);
if (type_is_invalid(promise_result_type))
return ira->codegen->builtin_types.entry_invalid;
- FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec);
+ ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
assert(fn_entry != nullptr);
if (type_can_fail(promise_result_type)) {
@@ -20737,17 +20970,17 @@ static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira,
return out_val->type;
}
-static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira,
+static ZigType *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira,
IrInstructionMergeErrRetTraces *instruction)
{
IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->other;
if (type_is_invalid(coro_promise_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
- assert(coro_promise_ptr->value.type->id == TypeTableEntryIdPointer);
- TypeTableEntry *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type;
- assert(promise_frame_type->id == TypeTableEntryIdStruct);
- TypeTableEntry *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry;
+ assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer);
+ ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type;
+ assert(promise_frame_type->id == ZigTypeIdStruct);
+ ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry;
if (!type_can_fail(promise_result_type)) {
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
@@ -20770,7 +21003,7 @@ static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ir
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
+static ZigType *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,
instruction->base.source_node);
ir_link_new_instruction(result, &instruction->base);
@@ -20778,7 +21011,7 @@ static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira,
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *ira, IrInstructionMarkErrRetTracePtr *instruction) {
+static ZigType *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *ira, IrInstructionMarkErrRetTracePtr *instruction) {
IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->other;
if (type_is_invalid(err_ret_trace_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20790,8 +21023,8 @@ static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) {
- TypeTableEntry *float_type = ir_resolve_type(ira, instruction->type->other);
+static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) {
+ ZigType *float_type = ir_resolve_type(ira, instruction->type->other);
if (type_is_invalid(float_type))
return ira->codegen->builtin_types.entry_invalid;
@@ -20799,7 +21032,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
if (type_is_invalid(op->value.type))
return ira->codegen->builtin_types.entry_invalid;
- bool ok_type = float_type->id == TypeTableEntryIdComptimeFloat || float_type->id == TypeTableEntryIdFloat;
+ bool ok_type = float_type->id == ZigTypeIdComptimeFloat || float_type->id == ZigTypeIdFloat;
if (!ok_type) {
ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -20816,9 +21049,9 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
- if (float_type->id == TypeTableEntryIdComptimeFloat) {
+ if (float_type->id == ZigTypeIdComptimeFloat) {
bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat);
- } else if (float_type->id == TypeTableEntryIdFloat) {
+ } else if (float_type->id == ZigTypeIdFloat) {
switch (float_type->data.floating.bit_count) {
case 16:
out_val->data.x_f16 = f16_sqrt(val->data.x_f16);
@@ -20842,7 +21075,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
return float_type;
}
- assert(float_type->id == TypeTableEntryIdFloat);
+ assert(float_type->id == ZigTypeIdFloat);
if (float_type->data.floating.bit_count != 16 &&
float_type->data.floating.bit_count != 32 &&
float_type->data.floating.bit_count != 64) {
@@ -20857,13 +21090,13 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {
+static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {
Error err;
IrInstruction *target = instruction->target->other;
if (type_is_invalid(target->value.type))
return ira->codegen->builtin_types.entry_invalid;
- if (target->value.type->id != TypeTableEntryIdEnum) {
+ if (target->value.type->id != ZigTypeIdEnum) {
ir_add_error(ira, instruction->target,
buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -20872,21 +21105,21 @@ static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInst
if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type)))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *tag_type = target->value.type->data.enumeration.tag_int_type;
+ ZigType *tag_type = target->value.type->data.enumeration.tag_int_type;
IrInstruction *result = ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type);
ir_link_new_instruction(result, &instruction->base);
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {
+static ZigType *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {
Error err;
IrInstruction *dest_type_value = instruction->dest_type->other;
- TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
+ ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
if (type_is_invalid(dest_type))
return ira->codegen->builtin_types.entry_invalid;
- if (dest_type->id != TypeTableEntryIdEnum) {
+ if (dest_type->id != ZigTypeIdEnum) {
ir_add_error(ira, instruction->dest_type,
buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->builtin_types.entry_invalid;
@@ -20895,7 +21128,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst
if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type)))
return ira->codegen->builtin_types.entry_invalid;
- TypeTableEntry *tag_type = dest_type->data.enumeration.tag_int_type;
+ ZigType *tag_type = dest_type->data.enumeration.tag_int_type;
IrInstruction *target = instruction->target->other;
if (type_is_invalid(target->value.type))
@@ -20910,7 +21143,30 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst
return result->value.type;
}
-static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
+static ZigType *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) {
+ IrInstruction *block_comptime_inst = instruction->scope_is_comptime->other;
+ bool scope_is_comptime;
+ if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime))
+ return ira->codegen->builtin_types.entry_invalid;
+
+ IrInstruction *is_comptime_inst = instruction->is_comptime->other;
+ bool is_comptime;
+ if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime))
+ return ira->codegen->builtin_types.entry_invalid;
+
+ if (!scope_is_comptime && is_comptime) {
+ ErrorMsg *msg = ir_add_error(ira, &instruction->base,
+ buf_sprintf("comptime control flow inside runtime block"));
+ add_error_note(ira->codegen, msg, block_comptime_inst->source_node,
+ buf_sprintf("runtime block created here"));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
+
+ ir_build_const_from(ira, &instruction->base);
+ return ira->codegen->builtin_types.entry_void;
+}
+
+static ZigType *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
switch (instruction->id) {
case IrInstructionIdInvalid:
case IrInstructionIdWidenOrShorten:
@@ -21186,19 +21442,21 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction);
case IrInstructionIdEnumToInt:
return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction);
+ case IrInstructionIdCheckRuntimeScope:
+ return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction);
}
zig_unreachable();
}
-static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) {
- TypeTableEntry *instruction_type = ir_analyze_instruction_nocast(ira, instruction);
+static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) {
+ ZigType *instruction_type = ir_analyze_instruction_nocast(ira, instruction);
instruction->value.type = instruction_type;
if (instruction->other) {
instruction->other->value.type = instruction_type;
} else {
- assert(instruction_type->id == TypeTableEntryIdInvalid ||
- instruction_type->id == TypeTableEntryIdUnreachable);
+ assert(instruction_type->id == ZigTypeIdInvalid ||
+ instruction_type->id == ZigTypeIdUnreachable);
instruction->other = instruction;
}
@@ -21207,8 +21465,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins
// This function attempts to evaluate IR code while doing type checking and other analysis.
// It emits a new IrExecutable which is partially evaluated IR code.
-TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,
- TypeTableEntry *expected_type, AstNode *expected_type_source_node)
+ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,
+ ZigType *expected_type, AstNode *expected_type_source_node)
{
assert(!old_exec->invalid);
assert(expected_type == nullptr || !type_is_invalid(expected_type));
@@ -21217,7 +21475,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl
old_exec->analysis = ira;
ira->codegen = codegen;
- FnTableEntry *fn_entry = exec_fn_entry(old_exec);
+ ZigFn *fn_entry = exec_fn_entry(old_exec);
bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
ira->explicit_return_type = is_async ? get_promise_type(codegen, expected_type) : expected_type;
@@ -21249,13 +21507,13 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl
continue;
}
- TypeTableEntry *return_type = ir_analyze_instruction(ira, old_instruction);
+ ZigType *return_type = ir_analyze_instruction(ira, old_instruction);
if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) {
return ira->codegen->builtin_types.entry_invalid;
}
// unreachable instructions do their own control flow.
- if (return_type->id == TypeTableEntryIdUnreachable)
+ if (return_type->id == ZigTypeIdUnreachable)
continue;
ira->instruction_index += 1;
@@ -21301,6 +21559,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free
case IrInstructionIdCheckSwitchProngs:
case IrInstructionIdCheckStatementIsVoid:
+ case IrInstructionIdCheckRuntimeScope:
case IrInstructionIdPanic:
case IrInstructionIdSetEvalBranchQuota:
case IrInstructionIdPtrType:
diff --git a/src/ir.hpp b/src/ir.hpp
@@ -11,15 +11,15 @@
#include "all_types.hpp"
bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
-bool ir_gen_fn(CodeGen *g, FnTableEntry *fn_entry);
+bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);
IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
- TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,
- FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
+ ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota,
+ ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
IrExecutable *parent_exec);
-TypeTableEntry *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
- TypeTableEntry *expected_type, AstNode *expected_type_source_node);
+ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,
+ ZigType *expected_type, AstNode *expected_type_source_node);
bool ir_has_side_effects(IrInstruction *instruction);
ConstExprValue *const_ptr_pointee(CodeGen *codegen, ConstExprValue *const_val);
diff --git a/src/ir_print.cpp b/src/ir_print.cpp
@@ -957,6 +957,14 @@ static void ir_print_enum_to_int(IrPrint *irp, IrInstructionEnumToInt *instructi
fprintf(irp->f, ")");
}
+static void ir_print_check_runtime_scope(IrPrint *irp, IrInstructionCheckRuntimeScope *instruction) {
+ fprintf(irp->f, "@checkRuntimeScope(");
+ ir_print_other_instruction(irp, instruction->scope_is_comptime);
+ fprintf(irp->f, ",");
+ ir_print_other_instruction(irp, instruction->is_comptime);
+ fprintf(irp->f, ")");
+}
+
static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {
fprintf(irp->f, "inttoerr ");
ir_print_other_instruction(irp, instruction->target);
@@ -1749,6 +1757,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
case IrInstructionIdEnumToInt:
ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);
break;
+ case IrInstructionIdCheckRuntimeScope:
+ ir_print_check_runtime_scope(irp, (IrInstructionCheckRuntimeScope *)instruction);
+ break;
}
fprintf(irp->f, "\n");
}
diff --git a/src/link.cpp b/src/link.cpp
@@ -66,7 +66,7 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path)
const char *o_ext = target_o_file_ext(&child_gen->zig_target);
Buf *o_out_name = buf_sprintf("%s%s", oname, o_ext);
Buf *output_path = buf_alloc();
- os_path_join(parent_gen->cache_dir, o_out_name, output_path);
+ os_path_join(&parent_gen->cache_dir, o_out_name, output_path);
codegen_link(child_gen, buf_ptr(output_path));
codegen_destroy(child_gen);
@@ -587,11 +587,11 @@ static void construct_linker_job_coff(LinkJob *lj) {
buf_appendf(def_contents, "\n");
Buf *def_path = buf_alloc();
- os_path_join(g->cache_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path);
+ os_path_join(&g->cache_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path);
os_write_file(def_path, def_contents);
Buf *generated_lib_path = buf_alloc();
- os_path_join(g->cache_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path);
+ os_path_join(&g->cache_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path);
gen_lib_args.resize(0);
gen_lib_args.append("link");
diff --git a/src/main.cpp b/src/main.cpp
@@ -374,25 +374,26 @@ int main(int argc, char **argv) {
CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf);
codegen_set_out_name(g, buf_create_from_str("build"));
- Buf build_file_abs = BUF_INIT;
- os_path_resolve(buf_create_from_str("."), buf_create_from_str(build_file), &build_file_abs);
+ Buf *build_file_buf = buf_create_from_str(build_file);
+ Buf build_file_abs = os_path_resolve(&build_file_buf, 1);
Buf build_file_basename = BUF_INIT;
Buf build_file_dirname = BUF_INIT;
os_path_split(&build_file_abs, &build_file_dirname, &build_file_basename);
- Buf *full_cache_dir = buf_alloc();
+ Buf full_cache_dir = BUF_INIT;
if (cache_dir == nullptr) {
- os_path_join(&build_file_dirname, buf_create_from_str(default_zig_cache_name), full_cache_dir);
+ os_path_join(&build_file_dirname, buf_create_from_str(default_zig_cache_name), &full_cache_dir);
} else {
- os_path_resolve(buf_create_from_str("."), buf_create_from_str(cache_dir), full_cache_dir);
+ Buf *cache_dir_buf = buf_create_from_str(cache_dir);
+ full_cache_dir = os_path_resolve(&cache_dir_buf, 1);
}
Buf *path_to_build_exe = buf_alloc();
- os_path_join(full_cache_dir, buf_create_from_str("build"), path_to_build_exe);
+ os_path_join(&full_cache_dir, buf_create_from_str("build"), path_to_build_exe);
codegen_set_cache_dir(g, full_cache_dir);
args.items[1] = buf_ptr(&build_file_dirname);
- args.items[2] = buf_ptr(full_cache_dir);
+ args.items[2] = buf_ptr(&full_cache_dir);
bool build_file_exists;
if ((err = os_file_exists(&build_file_abs, &build_file_exists))) {
@@ -789,7 +790,7 @@ int main(int argc, char **argv) {
Buf *zig_root_source_file = (cmd == CmdTranslateC) ? nullptr : in_file_buf;
- Buf *full_cache_dir = buf_alloc();
+ Buf full_cache_dir = BUF_INIT;
Buf *run_exec_path = buf_alloc();
if (cmd == CmdRun) {
if (buf_out_name == nullptr) {
@@ -799,13 +800,12 @@ int main(int argc, char **argv) {
Buf *global_cache_dir = buf_alloc();
os_get_global_cache_directory(global_cache_dir);
os_path_join(global_cache_dir, buf_out_name, run_exec_path);
- os_path_resolve(buf_create_from_str("."), global_cache_dir, full_cache_dir);
+ full_cache_dir = os_path_resolve(&global_cache_dir, 1);
out_file = buf_ptr(run_exec_path);
} else {
- os_path_resolve(buf_create_from_str("."),
- buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir),
- full_cache_dir);
+ Buf *resolve_paths = buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir);
+ full_cache_dir = os_path_resolve(&resolve_paths, 1);
}
Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
@@ -937,7 +937,7 @@ int main(int argc, char **argv) {
Buf *test_exe_name = buf_sprintf("test%s", target_exe_file_ext(non_null_target));
Buf *test_exe_path = buf_alloc();
- os_path_join(full_cache_dir, test_exe_name, test_exe_path);
+ os_path_join(&full_cache_dir, test_exe_name, test_exe_path);
for (size_t i = 0; i < test_exec_args.length; i += 1) {
if (test_exec_args.items[i] == nullptr) {
diff --git a/src/os.cpp b/src/os.cpp
@@ -57,6 +57,54 @@ static clock_serv_t cclock;
#include <errno.h>
#include <time.h>
+// Ported from std/mem.zig.
+// Coordinate struct fields with memSplit function
+struct SplitIterator {
+ size_t index;
+ Slice<uint8_t> buffer;
+ Slice<uint8_t> split_bytes;
+};
+
+// Ported from std/mem.zig.
+static bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte) {
+ for (size_t i = 0; i < self->split_bytes.len; i += 1) {
+ if (byte == self->split_bytes.ptr[i]) {
+ return true;
+ }
+ }
+ return false;
+}
+
+// Ported from std/mem.zig.
+static Optional<Slice<uint8_t>> SplitIterator_next(SplitIterator *self) {
+ // move to beginning of token
+ while (self->index < self->buffer.len &&
+ SplitIterator_isSplitByte(self, self->buffer.ptr[self->index]))
+ {
+ self->index += 1;
+ }
+ size_t start = self->index;
+ if (start == self->buffer.len) {
+ return {};
+ }
+
+ // move to end of token
+ while (self->index < self->buffer.len &&
+ !SplitIterator_isSplitByte(self, self->buffer.ptr[self->index]))
+ {
+ self->index += 1;
+ }
+ size_t end = self->index;
+
+ return Optional<Slice<uint8_t>>::some(self->buffer.slice(start, end));
+}
+
+// Ported from std/mem.zig
+static SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes) {
+ return SplitIterator{0, buffer, split_bytes};
+}
+
+
#if defined(ZIG_OS_POSIX)
static void populate_termination(Termination *term, int status) {
if (WIFEXITED(status)) {
@@ -266,15 +314,31 @@ int os_path_real(Buf *rel_path, Buf *out_abs_path) {
#endif
}
-bool os_path_is_absolute(Buf *path) {
#if defined(ZIG_OS_WINDOWS)
- if (buf_starts_with_str(path, "/") || buf_starts_with_str(path, "\\"))
+// Ported from std/os/path.zig
+static bool isAbsoluteWindows(Slice<uint8_t> path) {
+ if (path.ptr[0] == '/')
return true;
- if (buf_len(path) >= 3 && buf_ptr(path)[1] == ':')
+ if (path.ptr[0] == '\\') {
return true;
-
+ }
+ if (path.len < 3) {
+ return false;
+ }
+ if (path.ptr[1] == ':') {
+ if (path.ptr[2] == '/')
+ return true;
+ if (path.ptr[2] == '\\')
+ return true;
+ }
return false;
+}
+#endif
+
+bool os_path_is_absolute(Buf *path) {
+#if defined(ZIG_OS_WINDOWS)
+ return isAbsoluteWindows(buf_to_slice(path));
#elif defined(ZIG_OS_POSIX)
return buf_ptr(path)[0] == '/';
#else
@@ -282,14 +346,423 @@ bool os_path_is_absolute(Buf *path) {
#endif
}
-void os_path_resolve(Buf *ref_path, Buf *target_path, Buf *out_abs_path) {
- if (os_path_is_absolute(target_path)) {
- buf_init_from_buf(out_abs_path, target_path);
- return;
+#if defined(ZIG_OS_WINDOWS)
+
+enum WindowsPathKind {
+ WindowsPathKindNone,
+ WindowsPathKindDrive,
+ WindowsPathKindNetworkShare,
+};
+
+struct WindowsPath {
+ Slice<uint8_t> disk_designator;
+ WindowsPathKind kind;
+ bool is_abs;
+};
+
+
+// Ported from std/os/path.zig
+static WindowsPath windowsParsePath(Slice<uint8_t> path) {
+ if (path.len >= 2 && path.ptr[1] == ':') {
+ return WindowsPath{
+ path.slice(0, 2),
+ WindowsPathKindDrive,
+ isAbsoluteWindows(path),
+ };
+ }
+ if (path.len >= 1 && (path.ptr[0] == '/' || path.ptr[0] == '\\') &&
+ (path.len == 1 || (path.ptr[1] != '/' && path.ptr[1] != '\\')))
+ {
+ return WindowsPath{
+ path.slice(0, 0),
+ WindowsPathKindNone,
+ true,
+ };
+ }
+ WindowsPath relative_path = {
+ str(""),
+ WindowsPathKindNone,
+ false,
+ };
+ if (path.len < strlen("//a/b")) {
+ return relative_path;
}
- os_path_join(ref_path, target_path, out_abs_path);
- return;
+ {
+ if (memStartsWith(path, str("//"))) {
+ if (path.ptr[2] == '/') {
+ return relative_path;
+ }
+
+ SplitIterator it = memSplit(path, str("/"));
+ {
+ Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
+ if (!opt_component.is_some) return relative_path;
+ }
+ {
+ Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
+ if (!opt_component.is_some) return relative_path;
+ }
+ return WindowsPath{
+ path.slice(0, it.index),
+ WindowsPathKindNetworkShare,
+ isAbsoluteWindows(path),
+ };
+ }
+ }
+ {
+ if (memStartsWith(path, str("\\\\"))) {
+ if (path.ptr[2] == '\\') {
+ return relative_path;
+ }
+
+ SplitIterator it = memSplit(path, str("\\"));
+ {
+ Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
+ if (!opt_component.is_some) return relative_path;
+ }
+ {
+ Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
+ if (!opt_component.is_some) return relative_path;
+ }
+ return WindowsPath{
+ path.slice(0, it.index),
+ WindowsPathKindNetworkShare,
+ isAbsoluteWindows(path),
+ };
+ }
+ }
+ return relative_path;
+}
+
+// Ported from std/os/path.zig
+static uint8_t asciiUpper(uint8_t byte) {
+ if (byte >= 'a' && byte <= 'z') {
+ return 'A' + (byte - 'a');
+ }
+ return byte;
+}
+
+// Ported from std/os/path.zig
+static bool asciiEqlIgnoreCase(Slice<uint8_t> s1, Slice<uint8_t> s2) {
+ if (s1.len != s2.len)
+ return false;
+ for (size_t i = 0; i < s1.len; i += 1) {
+ if (asciiUpper(s1.ptr[i]) != asciiUpper(s2.ptr[i]))
+ return false;
+ }
+ return true;
+}
+
+// Ported from std/os/path.zig
+static bool compareDiskDesignators(WindowsPathKind kind, Slice<uint8_t> p1, Slice<uint8_t> p2) {
+ switch (kind) {
+ case WindowsPathKindNone:
+ assert(p1.len == 0);
+ assert(p2.len == 0);
+ return true;
+ case WindowsPathKindDrive:
+ return asciiUpper(p1.ptr[0]) == asciiUpper(p2.ptr[0]);
+ case WindowsPathKindNetworkShare:
+ uint8_t sep1 = p1.ptr[0];
+ uint8_t sep2 = p2.ptr[0];
+
+ SplitIterator it1 = memSplit(p1, {&sep1, 1});
+ SplitIterator it2 = memSplit(p2, {&sep2, 1});
+
+ // TODO ASCII is wrong, we actually need full unicode support to compare paths.
+ return asciiEqlIgnoreCase(SplitIterator_next(&it1).value, SplitIterator_next(&it2).value) &&
+ asciiEqlIgnoreCase(SplitIterator_next(&it1).value, SplitIterator_next(&it2).value);
+ }
+ zig_unreachable();
+}
+
+// Ported from std/os/path.zig
+static Buf os_path_resolve_windows(Buf **paths_ptr, size_t paths_len) {
+ if (paths_len == 0) {
+ Buf cwd = BUF_INIT;
+ int err;
+ if ((err = os_get_cwd(&cwd))) {
+ zig_panic("get cwd failed");
+ }
+ return cwd;
+ }
+
+ // determine which disk designator we will result with, if any
+ char result_drive_buf[3] = {'_', ':', '\0'}; // 0 needed for strlen later
+ Slice<uint8_t> result_disk_designator = str("");
+ WindowsPathKind have_drive_kind = WindowsPathKindNone;
+ bool have_abs_path = false;
+ size_t first_index = 0;
+ size_t max_size = 0;
+ for (size_t i = 0; i < paths_len; i += 1) {
+ Slice<uint8_t> p = buf_to_slice(paths_ptr[i]);
+ WindowsPath parsed = windowsParsePath(p);
+ if (parsed.is_abs) {
+ have_abs_path = true;
+ first_index = i;
+ max_size = result_disk_designator.len;
+ }
+ switch (parsed.kind) {
+ case WindowsPathKindDrive:
+ result_drive_buf[0] = asciiUpper(parsed.disk_designator.ptr[0]);
+ result_disk_designator = str(result_drive_buf);
+ have_drive_kind = WindowsPathKindDrive;
+ break;
+ case WindowsPathKindNetworkShare:
+ result_disk_designator = parsed.disk_designator;
+ have_drive_kind = WindowsPathKindNetworkShare;
+ break;
+ case WindowsPathKindNone:
+ break;
+ }
+ max_size += p.len + 1;
+ }
+
+ // if we will result with a disk designator, loop again to determine
+ // which is the last time the disk designator is absolutely specified, if any
+ // and count up the max bytes for paths related to this disk designator
+ if (have_drive_kind != WindowsPathKindNone) {
+ have_abs_path = false;
+ first_index = 0;
+ max_size = result_disk_designator.len;
+ bool correct_disk_designator = false;
+
+ for (size_t i = 0; i < paths_len; i += 1) {
+ Slice<uint8_t> p = buf_to_slice(paths_ptr[i]);
+ WindowsPath parsed = windowsParsePath(p);
+ if (parsed.kind != WindowsPathKindNone) {
+ if (parsed.kind == have_drive_kind) {
+ correct_disk_designator = compareDiskDesignators(have_drive_kind, result_disk_designator, parsed.disk_designator);
+ } else {
+ continue;
+ }
+ }
+ if (!correct_disk_designator) {
+ continue;
+ }
+ if (parsed.is_abs) {
+ first_index = i;
+ max_size = result_disk_designator.len;
+ have_abs_path = true;
+ }
+ max_size += p.len + 1;
+ }
+ }
+
+ // Allocate result and fill in the disk designator, calling getCwd if we have to.
+ Slice<uint8_t> result;
+ size_t result_index = 0;
+
+ if (have_abs_path) {
+ switch (have_drive_kind) {
+ case WindowsPathKindDrive: {
+ result = Slice<uint8_t>::alloc(max_size);
+
+ memCopy(result, result_disk_designator);
+ result_index += result_disk_designator.len;
+ break;
+ }
+ case WindowsPathKindNetworkShare: {
+ result = Slice<uint8_t>::alloc(max_size);
+ SplitIterator it = memSplit(buf_to_slice(paths_ptr[first_index]), str("/\\"));
+ Slice<uint8_t> server_name = SplitIterator_next(&it).value;
+ Slice<uint8_t> other_name = SplitIterator_next(&it).value;
+
+ result.ptr[result_index] = '\\';
+ result_index += 1;
+ result.ptr[result_index] = '\\';
+ result_index += 1;
+ memCopy(result.sliceFrom(result_index), server_name);
+ result_index += server_name.len;
+ result.ptr[result_index] = '\\';
+ result_index += 1;
+ memCopy(result.sliceFrom(result_index), other_name);
+ result_index += other_name.len;
+
+ result_disk_designator = result.slice(0, result_index);
+ break;
+ }
+ case WindowsPathKindNone: {
+ Buf cwd = BUF_INIT;
+ int err;
+ if ((err = os_get_cwd(&cwd))) {
+ zig_panic("get cwd failed");
+ }
+ WindowsPath parsed_cwd = windowsParsePath(buf_to_slice(&cwd));
+ result = Slice<uint8_t>::alloc(max_size + parsed_cwd.disk_designator.len + 1);
+ memCopy(result, parsed_cwd.disk_designator);
+ result_index += parsed_cwd.disk_designator.len;
+ result_disk_designator = result.slice(0, parsed_cwd.disk_designator.len);
+ if (parsed_cwd.kind == WindowsPathKindDrive) {
+ result.ptr[0] = asciiUpper(result.ptr[0]);
+ }
+ have_drive_kind = parsed_cwd.kind;
+ break;
+ }
+ }
+ } else {
+ // TODO call get cwd for the result_disk_designator instead of the global one
+ Buf cwd = BUF_INIT;
+ int err;
+ if ((err = os_get_cwd(&cwd))) {
+ zig_panic("get cwd failed");
+ }
+ result = Slice<uint8_t>::alloc(max_size + buf_len(&cwd) + 1);
+
+ memCopy(result, buf_to_slice(&cwd));
+ result_index += buf_len(&cwd);
+ WindowsPath parsed_cwd = windowsParsePath(result.slice(0, result_index));
+ result_disk_designator = parsed_cwd.disk_designator;
+ if (parsed_cwd.kind == WindowsPathKindDrive) {
+ result.ptr[0] = asciiUpper(result.ptr[0]);
+ }
+ have_drive_kind = parsed_cwd.kind;
+ }
+
+ // Now we know the disk designator to use, if any, and what kind it is. And our result
+ // is big enough to append all the paths to.
+ bool correct_disk_designator = true;
+ for (size_t i = 0; i < paths_len; i += 1) {
+ Slice<uint8_t> p = buf_to_slice(paths_ptr[i]);
+ WindowsPath parsed = windowsParsePath(p);
+
+ if (parsed.kind != WindowsPathKindNone) {
+ if (parsed.kind == have_drive_kind) {
+ correct_disk_designator = compareDiskDesignators(have_drive_kind, result_disk_designator, parsed.disk_designator);
+ } else {
+ continue;
+ }
+ }
+ if (!correct_disk_designator) {
+ continue;
+ }
+ SplitIterator it = memSplit(p.sliceFrom(parsed.disk_designator.len), str("/\\"));
+ while (true) {
+ Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
+ if (!opt_component.is_some) break;
+ Slice<uint8_t> component = opt_component.value;
+ if (memEql(component, str("."))) {
+ continue;
+ } else if (memEql(component, str(".."))) {
+ while (true) {
+ if (result_index == 0 || result_index == result_disk_designator.len)
+ break;
+ result_index -= 1;
+ if (result.ptr[result_index] == '\\' || result.ptr[result_index] == '/')
+ break;
+ }
+ } else {
+ result.ptr[result_index] = '\\';
+ result_index += 1;
+ memCopy(result.sliceFrom(result_index), component);
+ result_index += component.len;
+ }
+ }
+ }
+
+ if (result_index == result_disk_designator.len) {
+ result.ptr[result_index] = '\\';
+ result_index += 1;
+ }
+
+ Buf return_value = BUF_INIT;
+ buf_init_from_mem(&return_value, (char *)result.ptr, result_index);
+ return return_value;
+}
+#endif
+
+#if defined(ZIG_OS_POSIX)
+// Ported from std/os/path.zig
+static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
+ if (paths_len == 0) {
+ Buf cwd = BUF_INIT;
+ int err;
+ if ((err = os_get_cwd(&cwd))) {
+ zig_panic("get cwd failed");
+ }
+ return cwd;
+ }
+
+ size_t first_index = 0;
+ bool have_abs = false;
+ size_t max_size = 0;
+ for (size_t i = 0; i < paths_len; i += 1) {
+ Buf *p = paths_ptr[i];
+ if (os_path_is_absolute(p)) {
+ first_index = i;
+ have_abs = true;
+ max_size = 0;
+ }
+ max_size += buf_len(p) + 1;
+ }
+
+ uint8_t *result_ptr;
+ size_t result_len;
+ size_t result_index = 0;
+
+ if (have_abs) {
+ result_len = max_size;
+ result_ptr = allocate_nonzero<uint8_t>(result_len);
+ } else {
+ Buf cwd = BUF_INIT;
+ int err;
+ if ((err = os_get_cwd(&cwd))) {
+ zig_panic("get cwd failed");
+ }
+ result_len = max_size + buf_len(&cwd) + 1;
+ result_ptr = allocate_nonzero<uint8_t>(result_len);
+ memcpy(result_ptr, buf_ptr(&cwd), buf_len(&cwd));
+ result_index += buf_len(&cwd);
+ }
+
+ for (size_t i = first_index; i < paths_len; i += 1) {
+ Buf *p = paths_ptr[i];
+ SplitIterator it = memSplit(buf_to_slice(p), str("/"));
+ while (true) {
+ Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
+ if (!opt_component.is_some) break;
+ Slice<uint8_t> component = opt_component.value;
+
+ if (memEql<uint8_t>(component, str("."))) {
+ continue;
+ } else if (memEql<uint8_t>(component, str(".."))) {
+ while (true) {
+ if (result_index == 0)
+ break;
+ result_index -= 1;
+ if (result_ptr[result_index] == '/')
+ break;
+ }
+ } else {
+ result_ptr[result_index] = '/';
+ result_index += 1;
+ memcpy(result_ptr + result_index, component.ptr, component.len);
+ result_index += component.len;
+ }
+ }
+ }
+
+ if (result_index == 0) {
+ result_ptr[0] = '/';
+ result_index += 1;
+ }
+
+ Buf return_value = BUF_INIT;
+ buf_init_from_mem(&return_value, (char *)result_ptr, result_index);
+ return return_value;
+}
+#endif
+
+// Ported from std/os/path.zig
+Buf os_path_resolve(Buf **paths_ptr, size_t paths_len) {
+#if defined(ZIG_OS_WINDOWS)
+ return os_path_resolve_windows(paths_ptr, paths_len);
+#elif defined(ZIG_OS_POSIX)
+ return os_path_resolve_posix(paths_ptr, paths_len);
+#else
+#error "missing os_path_resolve implementation"
+#endif
}
int os_fetch_file(FILE *f, Buf *out_buf, bool skip_shebang) {
@@ -558,7 +1031,7 @@ int os_exec_process(const char *exe, ZigList<const char *> &args,
void os_write_file(Buf *full_path, Buf *contents) {
FILE *f = fopen(buf_ptr(full_path), "wb");
if (!f) {
- zig_panic("open failed");
+ zig_panic("os_write_file failed for %s", buf_ptr(full_path));
}
size_t amt_written = fwrite(buf_ptr(contents), 1, buf_len(contents), f);
if (amt_written != (size_t)buf_len(contents))
@@ -645,21 +1118,19 @@ int os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang) {
int os_get_cwd(Buf *out_cwd) {
#if defined(ZIG_OS_WINDOWS)
- buf_resize(out_cwd, 4096);
- if (GetCurrentDirectory(buf_len(out_cwd), buf_ptr(out_cwd)) == 0) {
+ char buf[4096];
+ if (GetCurrentDirectory(4096, buf) == 0) {
zig_panic("GetCurrentDirectory failed");
}
+ buf_init_from_str(out_cwd, buf);
return 0;
#elif defined(ZIG_OS_POSIX)
- int err = ERANGE;
- buf_resize(out_cwd, 512);
- while (err == ERANGE) {
- buf_resize(out_cwd, buf_len(out_cwd) * 2);
- err = getcwd(buf_ptr(out_cwd), buf_len(out_cwd)) ? 0 : errno;
+ char buf[PATH_MAX];
+ char *res = getcwd(buf, PATH_MAX);
+ if (res == nullptr) {
+ zig_panic("unable to get cwd: %s", strerror(errno));
}
- if (err)
- zig_panic("unable to get cwd: %s", strerror(err));
-
+ buf_init_from_str(out_cwd, res);
return 0;
#else
#error "missing os_get_cwd implementation"
@@ -898,21 +1369,20 @@ double os_get_time(void) {
}
int os_make_path(Buf *path) {
- Buf *resolved_path = buf_alloc();
- os_path_resolve(buf_create_from_str("."), path, resolved_path);
+ Buf resolved_path = os_path_resolve(&path, 1);
- size_t end_index = buf_len(resolved_path);
+ size_t end_index = buf_len(&resolved_path);
int err;
while (true) {
- if ((err = os_make_dir(buf_slice(resolved_path, 0, end_index)))) {
+ if ((err = os_make_dir(buf_slice(&resolved_path, 0, end_index)))) {
if (err == ErrorPathAlreadyExists) {
- if (end_index == buf_len(resolved_path))
+ if (end_index == buf_len(&resolved_path))
return 0;
} else if (err == ErrorFileNotFound) {
// march end_index backward until next path component
while (true) {
end_index -= 1;
- if (os_is_sep(buf_ptr(resolved_path)[end_index]))
+ if (os_is_sep(buf_ptr(&resolved_path)[end_index]))
break;
}
continue;
@@ -920,12 +1390,12 @@ int os_make_path(Buf *path) {
return err;
}
}
- if (end_index == buf_len(resolved_path))
+ if (end_index == buf_len(&resolved_path))
return 0;
// march end_index forward until next path component
while (true) {
end_index += 1;
- if (end_index == buf_len(resolved_path) || os_is_sep(buf_ptr(resolved_path)[end_index]))
+ if (end_index == buf_len(&resolved_path) || os_is_sep(buf_ptr(&resolved_path)[end_index]))
break;
}
}
diff --git a/src/os.hpp b/src/os.hpp
@@ -49,7 +49,7 @@ void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename);
void os_path_extname(Buf *full_path, Buf *out_basename, Buf *out_extname);
void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path);
int os_path_real(Buf *rel_path, Buf *out_abs_path);
-void os_path_resolve(Buf *ref_path, Buf *target_path, Buf *out_abs_path);
+Buf os_path_resolve(Buf **paths_ptr, size_t paths_len);
bool os_path_is_absolute(Buf *path);
int os_get_global_cache_directory(Buf *out_tmp_path);
diff --git a/src/util.hpp b/src/util.hpp
@@ -186,4 +186,72 @@ static inline double zig_f16_to_double(float16_t x) {
return z;
}
+template<typename T>
+struct Optional {
+ T value;
+ bool is_some;
+
+ static inline Optional<T> some(T x) {
+ return {x, true};
+ }
+};
+
+template<typename T>
+struct Slice {
+ T *ptr;
+ size_t len;
+
+ inline Slice<T> slice(size_t start, size_t end) {
+ assert(end <= len);
+ assert(end >= start);
+ return {
+ ptr + start,
+ end - start,
+ };
+ }
+
+ inline Slice<T> sliceFrom(size_t start) {
+ assert(start <= len);
+ return {
+ ptr + start,
+ len - start,
+ };
+ }
+
+ static inline Slice<T> alloc(size_t n) {
+ return {allocate_nonzero<T>(n), n};
+ }
+};
+
+static inline Slice<uint8_t> str(const char *literal) {
+ return {(uint8_t*)(literal), strlen(literal)};
+}
+
+// Ported from std/mem.zig
+template<typename T>
+static inline bool memEql(Slice<T> a, Slice<T> b) {
+ if (a.len != b.len)
+ return false;
+ for (size_t i = 0; i < a.len; i += 1) {
+ if (a.ptr[i] != b.ptr[i])
+ return false;
+ }
+ return true;
+}
+
+// Ported from std/mem.zig
+template<typename T>
+static inline bool memStartsWith(Slice<T> haystack, Slice<T> needle) {
+ if (needle.len > haystack.len)
+ return false;
+ return memEql(haystack.slice(0, needle.len), needle);
+}
+
+// Ported from std/mem.zig
+template<typename T>
+static inline void memCopy(Slice<T> dest, Slice<T> src) {
+ assert(dest.len >= src.len);
+ memcpy(dest.ptr, src.ptr, src.len * sizeof(T));
+}
+
#endif
diff --git a/std/array_list.zig b/std/array_list.zig
@@ -62,6 +62,10 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
return self.len;
}
+ pub fn capacity(self: Self) usize {
+ return self.items.len;
+ }
+
/// ArrayList takes ownership of the passed in slice. The slice must have been
/// allocated with `allocator`.
/// Deinitialize with `deinit` or use `toOwnedSlice`.
@@ -102,6 +106,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
new_item_ptr.* = item;
}
+ pub fn appendAssumeCapacity(self: *Self, item: T) void {
+ const new_item_ptr = self.addOneAssumeCapacity();
+ new_item_ptr.* = item;
+ }
+
/// Removes the element at the specified index and returns it.
/// The empty slot is filled from the end of the list.
pub fn swapRemove(self: *Self, i: usize) T {
@@ -138,7 +147,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
}
pub fn ensureCapacity(self: *Self, new_capacity: usize) !void {
- var better_capacity = self.items.len;
+ var better_capacity = self.capacity();
if (better_capacity >= new_capacity) return;
while (true) {
better_capacity += better_capacity / 2 + 8;
@@ -150,8 +159,13 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
pub fn addOne(self: *Self) !*T {
const new_length = self.len + 1;
try self.ensureCapacity(new_length);
+ return self.addOneAssumeCapacity();
+ }
+
+ pub fn addOneAssumeCapacity(self: *Self) *T {
+ assert(self.count() < self.capacity());
const result = &self.items[self.len];
- self.len = new_length;
+ self.len += 1;
return result;
}
@@ -191,6 +205,17 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
};
}
+test "std.ArrayList.init" {
+ var bytes: [1024]u8 = undefined;
+ const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
+
+ var list = ArrayList(i32).init(allocator);
+ defer list.deinit();
+
+ assert(list.count() == 0);
+ assert(list.capacity() == 0);
+}
+
test "std.ArrayList.basic" {
var bytes: [1024]u8 = undefined;
const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
diff --git a/std/build.zig b/std/build.zig
@@ -48,6 +48,12 @@ pub const Builder = struct {
cache_root: []const u8,
release_mode: ?builtin.Mode,
+ pub const CStd = enum {
+ C89,
+ C99,
+ C11,
+ };
+
const UserInputOptionsMap = HashMap([]const u8, UserInputOption, mem.hash_slice_u8, mem.eql_slice_u8);
const AvailableOptionsMap = HashMap([]const u8, AvailableOption, mem.hash_slice_u8, mem.eql_slice_u8);
@@ -817,6 +823,7 @@ pub const LibExeObjStep = struct {
frameworks: BufSet,
verbose_link: bool,
no_rosegment: bool,
+ c_std: Builder.CStd,
// zig only stuff
root_src: ?[]const u8,
@@ -918,6 +925,7 @@ pub const LibExeObjStep = struct {
.object_src = undefined,
.disable_libc = true,
.build_options_contents = std.Buffer.initSize(builder.allocator, 0) catch unreachable,
+ .c_std = Builder.CStd.C99,
};
self.computeOutFileNames();
return self;
@@ -952,6 +960,7 @@ pub const LibExeObjStep = struct {
.disable_libc = false,
.is_zig = false,
.linker_script = null,
+ .c_std = Builder.CStd.C99,
.root_src = undefined,
.verbose_link = false,
@@ -1392,6 +1401,13 @@ pub const LibExeObjStep = struct {
const is_darwin = self.target.isDarwin();
+ const c_std_arg = switch (self.c_std) {
+ Builder.CStd.C89 => "-std=c89",
+ Builder.CStd.C99 => "-std=c99",
+ Builder.CStd.C11 => "-std=c11",
+ };
+ try cc_args.append(c_std_arg);
+
switch (self.kind) {
Kind.Obj => {
cc_args.append("-c") catch unreachable;
@@ -1678,6 +1694,17 @@ pub const TestStep = struct {
self.filter = text;
}
+ pub fn addObject(self: *TestStep, obj: *LibExeObjStep) void {
+ assert(obj.kind == LibExeObjStep.Kind.Obj);
+
+ self.step.dependOn(&obj.step);
+
+ self.object_files.append(obj.getOutputPath()) catch unreachable;
+
+ // TODO should be some kind of isolated directory that only has this header in it
+ self.include_dirs.append(self.builder.cache_root) catch unreachable;
+ }
+
pub fn addObjectFile(self: *TestStep, path: []const u8) void {
self.object_files.append(path) catch unreachable;
}
diff --git a/std/crypto/throughput_test.zig b/std/crypto/throughput_test.zig
@@ -130,7 +130,7 @@ fn printPad(stdout: var, s: []const u8) !void {
pub fn main() !void {
var stdout_file = try std.io.getStdOut();
- var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);
+ var stdout_out_stream = std.io.FileOutStream.init(stdout_file);
const stdout = &stdout_out_stream.stream;
var buffer: [1024]u8 = undefined;
diff --git a/std/crypto/x25519.zig b/std/crypto/x25519.zig
@@ -4,6 +4,7 @@
const std = @import("../index.zig");
const builtin = @import("builtin");
+const fmt = std.fmt;
const Endian = builtin.Endian;
const readInt = std.mem.readInt;
@@ -114,7 +115,7 @@ pub const X25519 = struct {
return !zerocmp(u8, out);
}
- pub fn createPublicKey(public_key: []const u8, private_key: []const u8) bool {
+ pub fn createPublicKey(public_key: [] u8, private_key: []const u8) bool {
var base_point = []u8{9} ++ []u8{0} ** 31;
return create(public_key, private_key, base_point);
}
@@ -573,6 +574,16 @@ const Fe = struct {
}
};
+test "x25519 public key calculation from secret key" {
+ var sk: [32]u8 = undefined;
+ var pk_expected: [32]u8 = undefined;
+ var pk_calculated: [32]u8 = undefined;
+ try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
+ try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
+ std.debug.assert(X25519.createPublicKey(pk_calculated[0..], sk));
+ std.debug.assert(std.mem.eql(u8, pk_calculated, pk_expected));
+}
+
test "x25519 rfc7748 vector1" {
const secret_key = "\xa5\x46\xe3\x6b\xf0\x52\x7c\x9d\x3b\x16\x15\x4b\x82\x46\x5e\xdd\x62\x14\x4c\x0a\xc1\xfc\x5a\x18\x50\x6a\x22\x44\xba\x44\x9a\xc4";
const public_key = "\xe6\xdb\x68\x67\x58\x30\x30\xdb\x35\x94\xc1\xa4\x24\xb1\x5f\x7c\x72\x66\x24\xec\x26\xb3\x35\x3b\x10\xa9\x03\xa6\xd0\xab\x1c\x4c";
diff --git a/test/behavior.zig b/test/behavior.zig
@@ -9,12 +9,12 @@ comptime {
_ = @import("cases/bitcast.zig");
_ = @import("cases/bool.zig");
_ = @import("cases/bugs/1111.zig");
- _ = @import("cases/bugs/1230.zig");
_ = @import("cases/bugs/1277.zig");
_ = @import("cases/bugs/1421.zig");
_ = @import("cases/bugs/394.zig");
_ = @import("cases/bugs/655.zig");
_ = @import("cases/bugs/656.zig");
+ _ = @import("cases/bugs/726.zig");
_ = @import("cases/bugs/828.zig");
_ = @import("cases/bugs/920.zig");
_ = @import("cases/byval_arg_var.zig");
diff --git a/test/build_examples.zig b/test/build_examples.zig
@@ -28,4 +28,10 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void {
// TODO figure out how to make this work on darwin - probably libSystem has dlopen/dlsym in it
cases.addBuildFile("test/standalone/load_dynamic_library/build.zig");
}
+
+ if (!is_windows // TODO support compiling C files on windows with zig build system
+ and builtin.arch == builtin.Arch.x86_64 // TODO add C ABI support for other architectures
+ ) {
+ cases.addBuildFile("test/stage1/c_abi/build.zig");
+ }
}
diff --git a/test/cases/bugs/1230.zig b/test/cases/bugs/1230.zig
@@ -1,14 +0,0 @@
-const assert = @import("std").debug.assert;
-
-const S = extern struct {
- x: i32,
-};
-
-extern fn ret_struct() S {
- return S{ .x = 42 };
-}
-
-test "extern return small struct (bug 1230)" {
- const s = ret_struct();
- assert(s.x == 42);
-}
diff --git a/test/cases/bugs/726.zig b/test/cases/bugs/726.zig
@@ -0,0 +1,16 @@
+const assert = @import("std").debug.assert;
+
+test "@ptrCast from const to nullable" {
+ const c: u8 = 4;
+ var x: ?*const u8 = @ptrCast(?*const u8, &c);
+ assert(x.?.* == 4);
+}
+
+test "@ptrCast from var in empty struct to nullable" {
+ const container = struct {
+ var c: u8 = 4;
+ };
+ var x: ?*const u8 = @ptrCast(?*const u8, &container.c);
+ assert(x.?.* == 4);
+}
+
diff --git a/test/cases/cast.zig b/test/cases/cast.zig
@@ -356,6 +356,7 @@ fn testFloatToInts() void {
expectFloatToInt(f32, 255.1, u8, 255);
expectFloatToInt(f32, 127.2, i8, 127);
expectFloatToInt(f32, -128.2, i8, -128);
+ expectFloatToInt(comptime_int, 1234, i16, 1234);
}
fn expectFloatToInt(comptime F: type, f: F, comptime I: type, i: I) void {
diff --git a/test/cases/eval.zig b/test/cases/eval.zig
@@ -674,3 +674,11 @@ test "inline for with same type but different values" {
}
assert(res == 5);
}
+
+test "refer to the type of a generic function" {
+ const Func = fn (type) void;
+ const f: Func = doNothingWithType;
+ f(i32);
+}
+
+fn doNothingWithType(comptime T: type) void {}
diff --git a/test/cases/fn.zig b/test/cases/fn.zig
@@ -176,3 +176,18 @@ test "pass by non-copying value as method, at comptime" {
assert(pt.addPointCoords() == 3);
}
}
+
+fn outer(y: u32) fn (u32) u32 {
+ const Y = @typeOf(y);
+ const st = struct {
+ fn get(z: u32) u32 {
+ return z + @sizeOf(Y);
+ }
+ };
+ return st.get;
+}
+
+test "return inner function which references comptime variable of outer function" {
+ var func = outer(10);
+ assert(func(3) == 7);
+}
diff --git a/test/cases/union.zig b/test/cases/union.zig
@@ -311,3 +311,16 @@ fn testTaggedUnionInit(x: var) bool {
const y = TaggedUnionWithAVoid{ .A = x };
return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A;
}
+
+pub const UnionEnumNoPayloads = union(enum) {
+ A,
+ B,
+};
+
+test "tagged union with no payloads" {
+ const a = UnionEnumNoPayloads{ .B = {} };
+ switch (a) {
+ @TagType(UnionEnumNoPayloads).A => @panic("wrong"),
+ @TagType(UnionEnumNoPayloads).B => {},
+ }
+}
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
@@ -2,6 +2,228 @@ const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
+ "variable initialization compile error then referenced",
+ \\fn Undeclared() type {
+ \\ return T;
+ \\}
+ \\fn Gen() type {
+ \\ const X = Undeclared();
+ \\ return struct {
+ \\ x: X,
+ \\ };
+ \\}
+ \\export fn entry() void {
+ \\ const S = Gen();
+ \\}
+ ,
+ ".tmp_source.zig:2:12: error: use of undeclared identifier 'T'",
+ );
+
+ cases.add(
+ "refer to the type of a generic function",
+ \\export fn entry() void {
+ \\ const Func = fn (type) void;
+ \\ const f: Func = undefined;
+ \\ f(i32);
+ \\}
+ ,
+ ".tmp_source.zig:4:5: error: use of undefined value",
+ );
+
+ cases.add(
+ "accessing runtime parameter from outer function",
+ \\fn outer(y: u32) fn (u32) u32 {
+ \\ const st = struct {
+ \\ fn get(z: u32) u32 {
+ \\ return z + y;
+ \\ }
+ \\ };
+ \\ return st.get;
+ \\}
+ \\export fn entry() void {
+ \\ var func = outer(10);
+ \\ var x = func(3);
+ \\}
+ ,
+ ".tmp_source.zig:4:24: error: 'y' not accessible from inner function",
+ ".tmp_source.zig:3:28: note: crossed function definition here",
+ ".tmp_source.zig:1:10: note: declared here",
+ );
+
+ cases.add(
+ "non int passed to @intToFloat",
+ \\export fn entry() void {
+ \\ const x = @intToFloat(f32, 1.1);
+ \\}
+ ,
+ ".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'",
+ );
+
+ cases.add(
+ "non float passed to @floatToInt",
+ \\export fn entry() void {
+ \\ const x = @floatToInt(i32, i32(54));
+ \\}
+ ,
+ ".tmp_source.zig:2:35: error: expected float type, found 'i32'",
+ );
+
+ cases.add(
+ "out of range comptime_int passed to @floatToInt",
+ \\export fn entry() void {
+ \\ const x = @floatToInt(i8, 200);
+ \\}
+ ,
+ ".tmp_source.zig:2:31: error: integer value 200 cannot be implicitly casted to type 'i8'",
+ );
+
+ cases.add(
+ "load too many bytes from comptime reinterpreted pointer",
+ \\export fn entry() void {
+ \\ const float: f32 = 5.99999999999994648725e-01;
+ \\ const float_ptr = &float;
+ \\ const int_ptr = @ptrCast(*const i64, float_ptr);
+ \\ const int_val = int_ptr.*;
+ \\}
+ ,
+ ".tmp_source.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes",
+ );
+
+ cases.add(
+ "invalid type used in array type",
+ \\const Item = struct {
+ \\ field: SomeNonexistentType,
+ \\};
+ \\var items: [100]Item = undefined;
+ \\export fn entry() void {
+ \\ const a = items[0];
+ \\}
+ ,
+ ".tmp_source.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'",
+ );
+
+ cases.add(
+ "@noInlineCall on an inline function",
+ \\inline fn foo() void {}
+ \\
+ \\export fn entry() void {
+ \\ @noInlineCall(foo);
+ \\}
+ ,
+ ".tmp_source.zig:4:5: error: no-inline call of inline function",
+ );
+
+ cases.add(
+ "comptime continue inside runtime switch",
+ \\export fn entry() void {
+ \\ var p: i32 = undefined;
+ \\ comptime var q = true;
+ \\ inline while (q) {
+ \\ switch (p) {
+ \\ 11 => continue,
+ \\ else => {},
+ \\ }
+ \\ q = false;
+ \\ }
+ \\}
+ ,
+ ".tmp_source.zig:6:19: error: comptime control flow inside runtime block",
+ ".tmp_source.zig:5:9: note: runtime block created here",
+ );
+
+ cases.add(
+ "comptime continue inside runtime while error",
+ \\export fn entry() void {
+ \\ var p: error!usize = undefined;
+ \\ comptime var q = true;
+ \\ outer: inline while (q) {
+ \\ while (p) |_| {
+ \\ continue :outer;
+ \\ } else |_| {}
+ \\ q = false;
+ \\ }
+ \\}
+ ,
+ ".tmp_source.zig:6:13: error: comptime control flow inside runtime block",
+ ".tmp_source.zig:5:9: note: runtime block created here",
+ );
+
+ cases.add(
+ "comptime continue inside runtime while optional",
+ \\export fn entry() void {
+ \\ var p: ?usize = undefined;
+ \\ comptime var q = true;
+ \\ outer: inline while (q) {
+ \\ while (p) |_| continue :outer;
+ \\ q = false;
+ \\ }
+ \\}
+ ,
+ ".tmp_source.zig:5:23: error: comptime control flow inside runtime block",
+ ".tmp_source.zig:5:9: note: runtime block created here",
+ );
+
+ cases.add(
+ "comptime continue inside runtime while bool",
+ \\export fn entry() void {
+ \\ var p: usize = undefined;
+ \\ comptime var q = true;
+ \\ outer: inline while (q) {
+ \\ while (p == 11) continue :outer;
+ \\ q = false;
+ \\ }
+ \\}
+ ,
+ ".tmp_source.zig:5:25: error: comptime control flow inside runtime block",
+ ".tmp_source.zig:5:9: note: runtime block created here",
+ );
+
+ cases.add(
+ "comptime continue inside runtime if error",
+ \\export fn entry() void {
+ \\ var p: error!i32 = undefined;
+ \\ comptime var q = true;
+ \\ inline while (q) {
+ \\ if (p) |_| continue else |_| {}
+ \\ q = false;
+ \\ }
+ \\}
+ ,
+ ".tmp_source.zig:5:20: error: comptime control flow inside runtime block",
+ ".tmp_source.zig:5:9: note: runtime block created here",
+ );
+
+ cases.add(
+ "comptime continue inside runtime if optional",
+ \\export fn entry() void {
+ \\ var p: ?i32 = undefined;
+ \\ comptime var q = true;
+ \\ inline while (q) {
+ \\ if (p) |_| continue;
+ \\ q = false;
+ \\ }
+ \\}
+ ,
+ ".tmp_source.zig:5:20: error: comptime control flow inside runtime block",
+ ".tmp_source.zig:5:9: note: runtime block created here",
+ );
+
+ cases.add(
+ "comptime continue inside runtime if bool",
+ \\export fn entry() void {
+ \\ var p: usize = undefined;
+ \\ comptime var q = true;
+ \\ inline while (q) {
+ \\ if (p == 11) continue;
+ \\ q = false;
+ \\ }
+ \\}
+ ,
+ ".tmp_source.zig:5:22: error: comptime control flow inside runtime block",
+ ".tmp_source.zig:5:9: note: runtime block created here",
+ );
+
+ cases.add(
"switch with invalid expression parameter",
\\export fn entry() void {
\\ Test(i32);
@@ -341,15 +563,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
);
cases.add(
- "non int passed to @intToFloat",
- \\export fn entry() void {
- \\ const x = @intToFloat(f32, 1.1);
- \\}
- ,
- ".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'",
- );
-
- cases.add(
"use implicit casts to assign null to non-nullable pointer",
\\export fn entry() void {
\\ var x: i32 = 1234;
diff --git a/test/gen_h.zig b/test/gen_h.zig
@@ -20,6 +20,9 @@ pub fn addCases(cases: *tests.GenHContext) void {
\\ A: i32,
\\ B: f32,
\\ C: bool,
+ \\ D: u64,
+ \\ E: u64,
+ \\ F: u64,
\\};
\\export fn entry(foo: Foo) void { }
,
@@ -27,6 +30,9 @@ pub fn addCases(cases: *tests.GenHContext) void {
\\ int32_t A;
\\ float B;
\\ bool C;
+ \\ uint64_t D;
+ \\ uint64_t E;
+ \\ uint64_t F;
\\};
\\
\\TEST_EXPORT void entry(struct Foo foo);
@@ -34,17 +40,34 @@ pub fn addCases(cases: *tests.GenHContext) void {
);
cases.add("declare union",
+ \\const Big = extern struct {
+ \\ A: u64,
+ \\ B: u64,
+ \\ C: u64,
+ \\ D: u64,
+ \\ E: u64,
+ \\};
\\const Foo = extern union {
\\ A: i32,
\\ B: f32,
\\ C: bool,
+ \\ D: Big,
\\};
- \\export fn entry(foo: Foo) void { }
+ \\export fn entry(foo: Foo) void {}
,
+ \\struct Big {
+ \\ uint64_t A;
+ \\ uint64_t B;
+ \\ uint64_t C;
+ \\ uint64_t D;
+ \\ uint64_t E;
+ \\};
+ \\
\\union Foo {
\\ int32_t A;
\\ float B;
\\ bool C;
+ \\ struct Big D;
\\};
\\
\\TEST_EXPORT void entry(union Foo foo);
@@ -85,7 +108,6 @@ pub fn addCases(cases: *tests.GenHContext) void {
\\export fn a(s: *S) u8 {
\\ return s.a;
\\}
-
,
\\struct S;
\\TEST_EXPORT uint8_t a(struct S * s);
@@ -101,7 +123,6 @@ pub fn addCases(cases: *tests.GenHContext) void {
\\export fn a(s: *U) u8 {
\\ return s.A;
\\}
-
,
\\union U;
\\TEST_EXPORT uint8_t a(union U * s);
@@ -117,7 +138,6 @@ pub fn addCases(cases: *tests.GenHContext) void {
\\export fn a(s: *E) u8 {
\\ return @enumToInt(s.*);
\\}
-
,
\\enum E;
\\TEST_EXPORT uint8_t a(enum E * s);
diff --git a/test/stage1/c_abi/build.zig b/test/stage1/c_abi/build.zig
@@ -0,0 +1,18 @@
+const Builder = @import("std").build.Builder;
+
+pub fn build(b: *Builder) void {
+ const rel_opts = b.standardReleaseOptions();
+
+ const c_obj = b.addCObject("cfuncs", "cfuncs.c");
+ c_obj.setBuildMode(rel_opts);
+ c_obj.setNoStdLib(true);
+
+ const main = b.addTest("main.zig");
+ main.setBuildMode(rel_opts);
+ main.addObject(c_obj);
+
+ const test_step = b.step("test", "Test the program");
+ test_step.dependOn(&main.step);
+
+ b.default_step.dependOn(test_step);
+}
diff --git a/test/stage1/c_abi/cfuncs.c b/test/stage1/c_abi/cfuncs.c
@@ -0,0 +1,208 @@
+#include <inttypes.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+void zig_panic();
+
+static void assert_or_panic(bool ok) {
+ if (!ok) {
+ zig_panic();
+ }
+}
+
+void zig_u8(uint8_t);
+void zig_u16(uint16_t);
+void zig_u32(uint32_t);
+void zig_u64(uint64_t);
+void zig_i8(int8_t);
+void zig_i16(int16_t);
+void zig_i32(int32_t);
+void zig_i64(int64_t);
+
+void zig_f32(float);
+void zig_f64(double);
+
+void zig_ptr(void *);
+
+void zig_bool(bool);
+
+void zig_array(uint8_t[10]);
+
+struct BigStruct {
+ uint64_t a;
+ uint64_t b;
+ uint64_t c;
+ uint64_t d;
+ uint8_t e;
+};
+
+void zig_big_struct(struct BigStruct);
+
+union BigUnion {
+ struct BigStruct a;
+};
+
+void zig_big_union(union BigUnion);
+
+struct SmallStructInts {
+ uint8_t a;
+ uint8_t b;
+ uint8_t c;
+ uint8_t d;
+};
+void zig_small_struct_ints(struct SmallStructInts);
+
+struct SplitStructInts {
+ uint64_t a;
+ uint8_t b;
+ uint32_t c;
+};
+void zig_split_struct_ints(struct SplitStructInts);
+
+struct BigStruct zig_big_struct_both(struct BigStruct);
+
+void run_c_tests(void) {
+ zig_u8(0xff);
+ zig_u16(0xfffe);
+ zig_u32(0xfffffffd);
+ zig_u64(0xfffffffffffffffc);
+
+ zig_i8(-1);
+ zig_i16(-2);
+ zig_i32(-3);
+ zig_i64(-4);
+
+ zig_f32(12.34f);
+ zig_f64(56.78);
+
+ zig_ptr((void*)0xdeadbeefL);
+
+ zig_bool(true);
+
+ uint8_t array[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
+ zig_array(array);
+
+ {
+ struct BigStruct s = {1, 2, 3, 4, 5};
+ zig_big_struct(s);
+ }
+
+ {
+ struct SmallStructInts s = {1, 2, 3, 4};
+ zig_small_struct_ints(s);
+ }
+
+ {
+ struct SplitStructInts s = {1234, 100, 1337};
+ zig_split_struct_ints(s);
+ }
+
+ {
+ struct BigStruct s = {30, 31, 32, 33, 34};
+ struct BigStruct res = zig_big_struct_both(s);
+ assert_or_panic(res.a == 20);
+ assert_or_panic(res.b == 21);
+ assert_or_panic(res.c == 22);
+ assert_or_panic(res.d == 23);
+ assert_or_panic(res.e == 24);
+ }
+}
+
+void c_u8(uint8_t x) {
+ assert_or_panic(x == 0xff);
+}
+
+void c_u16(uint16_t x) {
+ assert_or_panic(x == 0xfffe);
+}
+
+void c_u32(uint32_t x) {
+ assert_or_panic(x == 0xfffffffd);
+}
+
+void c_u64(uint64_t x) {
+ assert_or_panic(x == 0xfffffffffffffffcULL);
+}
+
+void c_i8(int8_t x) {
+ assert_or_panic(x == -1);
+}
+
+void c_i16(int16_t x) {
+ assert_or_panic(x == -2);
+}
+
+void c_i32(int32_t x) {
+ assert_or_panic(x == -3);
+}
+
+void c_i64(int64_t x) {
+ assert_or_panic(x == -4);
+}
+
+void c_f32(float x) {
+ assert_or_panic(x == 12.34f);
+}
+
+void c_f64(double x) {
+ assert_or_panic(x == 56.78);
+}
+
+void c_ptr(void *x) {
+ assert_or_panic(x == (void*)0xdeadbeefL);
+}
+
+void c_bool(bool x) {
+ assert_or_panic(x);
+}
+
+void c_array(uint8_t x[10]) {
+ assert_or_panic(x[0] == '1');
+ assert_or_panic(x[1] == '2');
+ assert_or_panic(x[2] == '3');
+ assert_or_panic(x[3] == '4');
+ assert_or_panic(x[4] == '5');
+ assert_or_panic(x[5] == '6');
+ assert_or_panic(x[6] == '7');
+ assert_or_panic(x[7] == '8');
+ assert_or_panic(x[8] == '9');
+ assert_or_panic(x[9] == '0');
+}
+
+void c_big_struct(struct BigStruct x) {
+ assert_or_panic(x.a == 1);
+ assert_or_panic(x.b == 2);
+ assert_or_panic(x.c == 3);
+ assert_or_panic(x.d == 4);
+ assert_or_panic(x.e == 5);
+}
+
+void c_big_union(union BigUnion x) {
+ assert_or_panic(x.a.a == 1);
+ assert_or_panic(x.a.b == 2);
+ assert_or_panic(x.a.c == 3);
+ assert_or_panic(x.a.d == 4);
+}
+
+void c_small_struct_ints(struct SmallStructInts x) {
+ assert_or_panic(x.a == 1);
+ assert_or_panic(x.b == 2);
+ assert_or_panic(x.c == 3);
+ assert_or_panic(x.d == 4);
+}
+
+void c_split_struct_ints(struct SplitStructInts x) {
+ assert_or_panic(x.a == 1234);
+ assert_or_panic(x.b == 100);
+ assert_or_panic(x.c == 1337);
+}
+
+struct BigStruct c_big_struct_both(struct BigStruct x) {
+ assert_or_panic(x.a == 1);
+ assert_or_panic(x.b == 2);
+ assert_or_panic(x.c == 3);
+ assert_or_panic(x.d == 4);
+ assert_or_panic(x.e == 5);
+ struct BigStruct y = {10, 11, 12, 13, 14};
+ return y;
+}
diff --git a/test/stage1/c_abi/main.zig b/test/stage1/c_abi/main.zig
@@ -0,0 +1,239 @@
+const std = @import("std");
+const assertOrPanic = std.debug.assertOrPanic;
+
+extern fn run_c_tests() void;
+
+export fn zig_panic() noreturn {
+ @panic("zig_panic called from C");
+}
+
+test "C importing Zig ABI Tests" {
+ run_c_tests();
+}
+
+extern fn c_u8(u8) void;
+extern fn c_u16(u16) void;
+extern fn c_u32(u32) void;
+extern fn c_u64(u64) void;
+extern fn c_i8(i8) void;
+extern fn c_i16(i16) void;
+extern fn c_i32(i32) void;
+extern fn c_i64(i64) void;
+
+test "C ABI integers" {
+ c_u8(0xff);
+ c_u16(0xfffe);
+ c_u32(0xfffffffd);
+ c_u64(0xfffffffffffffffc);
+
+ c_i8(-1);
+ c_i16(-2);
+ c_i32(-3);
+ c_i64(-4);
+}
+
+export fn zig_u8(x: u8) void {
+ assertOrPanic(x == 0xff);
+}
+export fn zig_u16(x: u16) void {
+ assertOrPanic(x == 0xfffe);
+}
+export fn zig_u32(x: u32) void {
+ assertOrPanic(x == 0xfffffffd);
+}
+export fn zig_u64(x: u64) void {
+ assertOrPanic(x == 0xfffffffffffffffc);
+}
+export fn zig_i8(x: i8) void {
+ assertOrPanic(x == -1);
+}
+export fn zig_i16(x: i16) void {
+ assertOrPanic(x == -2);
+}
+export fn zig_i32(x: i32) void {
+ assertOrPanic(x == -3);
+}
+export fn zig_i64(x: i64) void {
+ assertOrPanic(x == -4);
+}
+
+extern fn c_f32(f32) void;
+extern fn c_f64(f64) void;
+
+test "C ABI floats" {
+ c_f32(12.34);
+ c_f64(56.78);
+}
+
+export fn zig_f32(x: f32) void {
+ assertOrPanic(x == 12.34);
+}
+export fn zig_f64(x: f64) void {
+ assertOrPanic(x == 56.78);
+}
+
+extern fn c_ptr(*c_void) void;
+
+test "C ABI pointer" {
+ c_ptr(@intToPtr(*c_void, 0xdeadbeef));
+}
+
+export fn zig_ptr(x: *c_void) void {
+ assertOrPanic(@ptrToInt(x) == 0xdeadbeef);
+}
+
+extern fn c_bool(bool) void;
+
+test "C ABI bool" {
+ c_bool(true);
+}
+
+export fn zig_bool(x: bool) void {
+ assertOrPanic(x);
+}
+
+extern fn c_array([10]u8) void;
+
+test "C ABI array" {
+ var array: [10]u8 = "1234567890";
+ c_array(array);
+}
+
+export fn zig_array(x: [10]u8) void {
+ assertOrPanic(std.mem.eql(u8, x, "1234567890"));
+}
+
+const BigStruct = extern struct {
+ a: u64,
+ b: u64,
+ c: u64,
+ d: u64,
+ e: u8,
+};
+extern fn c_big_struct(BigStruct) void;
+
+test "C ABI big struct" {
+ var s = BigStruct{
+ .a = 1,
+ .b = 2,
+ .c = 3,
+ .d = 4,
+ .e = 5,
+ };
+ c_big_struct(s);
+}
+
+export fn zig_big_struct(x: BigStruct) void {
+ assertOrPanic(x.a == 1);
+ assertOrPanic(x.b == 2);
+ assertOrPanic(x.c == 3);
+ assertOrPanic(x.d == 4);
+ assertOrPanic(x.e == 5);
+}
+
+const BigUnion = extern union {
+ a: BigStruct,
+};
+extern fn c_big_union(BigUnion) void;
+
+test "C ABI big union" {
+ var x = BigUnion{
+ .a = BigStruct{
+ .a = 1,
+ .b = 2,
+ .c = 3,
+ .d = 4,
+ .e = 5,
+ },
+ };
+ c_big_union(x);
+}
+
+export fn zig_big_union(x: BigUnion) void {
+ assertOrPanic(x.a.a == 1);
+ assertOrPanic(x.a.b == 2);
+ assertOrPanic(x.a.c == 3);
+ assertOrPanic(x.a.d == 4);
+ assertOrPanic(x.a.e == 5);
+}
+
+const SmallStructInts = extern struct {
+ a: u8,
+ b: u8,
+ c: u8,
+ d: u8,
+};
+extern fn c_small_struct_ints(SmallStructInts) void;
+
+test "C ABI small struct of ints" {
+ var s = SmallStructInts{
+ .a = 1,
+ .b = 2,
+ .c = 3,
+ .d = 4,
+ };
+ c_small_struct_ints(s);
+}
+
+export fn zig_small_struct_ints(x: SmallStructInts) void {
+ assertOrPanic(x.a == 1);
+ assertOrPanic(x.b == 2);
+ assertOrPanic(x.c == 3);
+ assertOrPanic(x.d == 4);
+}
+
+const SplitStructInt = extern struct {
+ a: u64,
+ b: u8,
+ c: u32,
+};
+extern fn c_split_struct_ints(SplitStructInt) void;
+
+test "C ABI split struct of ints" {
+ var s = SplitStructInt{
+ .a = 1234,
+ .b = 100,
+ .c = 1337,
+ };
+ c_split_struct_ints(s);
+}
+
+export fn zig_split_struct_ints(x: SplitStructInt) void {
+ assertOrPanic(x.a == 1234);
+ assertOrPanic(x.b == 100);
+ assertOrPanic(x.c == 1337);
+}
+
+extern fn c_big_struct_both(BigStruct) BigStruct;
+
+test "C ABI sret and byval together" {
+ var s = BigStruct{
+ .a = 1,
+ .b = 2,
+ .c = 3,
+ .d = 4,
+ .e = 5,
+ };
+ var y = c_big_struct_both(s);
+ assertOrPanic(y.a == 10);
+ assertOrPanic(y.b == 11);
+ assertOrPanic(y.c == 12);
+ assertOrPanic(y.d == 13);
+ assertOrPanic(y.e == 14);
+}
+
+export fn zig_big_struct_both(x: BigStruct) BigStruct {
+ assertOrPanic(x.a == 30);
+ assertOrPanic(x.b == 31);
+ assertOrPanic(x.c == 32);
+ assertOrPanic(x.d == 33);
+ assertOrPanic(x.e == 34);
+ var s = BigStruct{
+ .a = 20,
+ .b = 21,
+ .c = 22,
+ .d = 23,
+ .e = 24,
+ };
+ return s;
+}