aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-09-10 12:30:57 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-09-10 12:30:57 -0400
commitc9474faa4e6cfd6480c1bd24216c26f4320e3c29 (patch)
tree4bf022698f229cd276b598ed95aa30a61e882674 /src/ir.cpp
parentf27d82fe90e1d0007bf2d3ef52eac8cdbc381e0d (diff)
parent7c9f7b72c59e7c6de38038f512ae332fc164e8d7 (diff)
downloadzig-c9474faa4e6cfd6480c1bd24216c26f4320e3c29.tar.gz
zig-c9474faa4e6cfd6480c1bd24216c26f4320e3c29.zip
Merge remote-tracking branch 'origin/master' into llvm7
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp3711
1 files changed, 1985 insertions, 1726 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 5ac321c0f3..30f40b3a1e 100644
--- 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(&param_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: