aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-02-25 16:30:40 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-02-25 16:30:40 -0500
commitf33bf48af7d9c99d532864f8a6c3f695ad5bbd21 (patch)
treefa39bd6b654178e653d06e1c79f22ad1d29cd526 /src/ir.cpp
parent64365bc5d7b1e2c507806ee8976acc3479ad7862 (diff)
parent416a547cdb8dbbf3d2e7ce32132f0a25f2a8607e (diff)
downloadzig-f33bf48af7d9c99d532864f8a6c3f695ad5bbd21.tar.gz
zig-f33bf48af7d9c99d532864f8a6c3f695ad5bbd21.zip
Merge remote-tracking branch 'origin/master' into llvm10
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp832
1 files changed, 166 insertions, 666 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index da02313089..0e276a8cc7 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -14,6 +14,7 @@
#include "range_set.hpp"
#include "softfloat.hpp"
#include "util.hpp"
+#include "mem_list.hpp"
#include <errno.h>
@@ -28,6 +29,9 @@ struct IrBuilderGen {
CodeGen *codegen;
IrExecutableGen *exec;
IrBasicBlockGen *current_basic_block;
+
+ // track for immediate post-analysis destruction
+ mem::List<IrInstGenConst *> constants;
};
struct IrAnalyze {
@@ -383,18 +387,12 @@ static void destroy_instruction_src(IrInstSrc *inst) {
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst));
case IrInstSrcIdErrSetCast:
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst));
- case IrInstSrcIdFromBytes:
- return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst));
- case IrInstSrcIdToBytes:
- return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcToBytes *>(inst));
case IrInstSrcIdIntToFloat:
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst));
case IrInstSrcIdFloatToInt:
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst));
case IrInstSrcIdBoolToInt:
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst));
- case IrInstSrcIdIntType:
- return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntType *>(inst));
case IrInstSrcIdVectorType:
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVectorType *>(inst));
case IrInstSrcIdShuffleVector:
@@ -409,12 +407,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst));
case IrInstSrcIdSlice:
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSlice *>(inst));
- case IrInstSrcIdMemberCount:
- return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst));
- case IrInstSrcIdMemberType:
- return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberType *>(inst));
- case IrInstSrcIdMemberName:
- return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberName *>(inst));
case IrInstSrcIdBreakpoint:
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst));
case IrInstSrcIdReturnAddress:
@@ -481,8 +473,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcType *>(inst));
case IrInstSrcIdHasField:
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasField *>(inst));
- case IrInstSrcIdTypeId:
- return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeId *>(inst));
case IrInstSrcIdSetEvalBranchQuota:
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst));
case IrInstSrcIdAlignCast:
@@ -707,8 +697,6 @@ void destroy_instruction_gen(IrInstGen *inst) {
return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertZero *>(inst));
case IrInstGenIdAssertNonNull:
return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst));
- case IrInstGenIdResizeSlice:
- return heap::c_allocator.destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst));
case IrInstGenIdAlloca:
return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAlloca *>(inst));
case IrInstGenIdSuspendBegin:
@@ -741,6 +729,10 @@ static void ira_ref(IrAnalyze *ira) {
static void ira_deref(IrAnalyze *ira) {
if (ira->ref_count > 1) {
ira->ref_count -= 1;
+
+ // immediate destruction of dangling IrInstGenConst is not possible
+ // free tracking memory because it will never be used
+ ira->new_irb.constants.deinit(&heap::c_allocator);
return;
}
assert(ira->ref_count != 0);
@@ -758,6 +750,15 @@ static void ira_deref(IrAnalyze *ira) {
heap::c_allocator.destroy(ira->old_irb.exec);
ira->src_implicit_return_type_list.deinit();
ira->resume_stack.deinit();
+
+ // destroy dangling IrInstGenConst
+ for (size_t i = 0; i < ira->new_irb.constants.length; i += 1) {
+ auto constant = ira->new_irb.constants.items[i];
+ if (constant->base.base.ref_count == 0 && !ir_inst_gen_has_side_effects(&constant->base))
+ destroy_instruction_gen(&constant->base);
+ }
+ ira->new_irb.constants.deinit(&heap::c_allocator);
+
heap::c_allocator.destroy(ira);
}
@@ -1299,10 +1300,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolToInt *) {
return IrInstSrcIdBoolToInt;
}
-static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntType *) {
- return IrInstSrcIdIntType;
-}
-
static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) {
return IrInstSrcIdVectorType;
}
@@ -1331,18 +1328,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) {
return IrInstSrcIdSlice;
}
-static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberCount *) {
- return IrInstSrcIdMemberCount;
-}
-
-static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberType *) {
- return IrInstSrcIdMemberType;
-}
-
-static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberName *) {
- return IrInstSrcIdMemberName;
-}
-
static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) {
return IrInstSrcIdBreakpoint;
}
@@ -1487,10 +1472,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) {
return IrInstSrcIdHasField;
}
-static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) {
- return IrInstSrcIdTypeId;
-}
-
static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) {
return IrInstSrcIdSetEvalBranchQuota;
}
@@ -1563,14 +1544,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrSetCast *) {
return IrInstSrcIdErrSetCast;
}
-static constexpr IrInstSrcId ir_inst_id(IrInstSrcToBytes *) {
- return IrInstSrcIdToBytes;
-}
-
-static constexpr IrInstSrcId ir_inst_id(IrInstSrcFromBytes *) {
- return IrInstSrcIdFromBytes;
-}
-
static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckRuntimeScope *) {
return IrInstSrcIdCheckRuntimeScope;
}
@@ -1700,10 +1673,6 @@ static constexpr IrInstGenId ir_inst_id(IrInstGenCast *) {
return IrInstGenIdCast;
}
-static constexpr IrInstGenId ir_inst_id(IrInstGenResizeSlice *) {
- return IrInstGenIdResizeSlice;
-}
-
static constexpr IrInstGenId ir_inst_id(IrInstGenUnreachable *) {
return IrInstGenIdUnreachable;
}
@@ -2759,21 +2728,6 @@ static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instructi
return &inst->base;
}
-static IrInstGen *ir_build_resize_slice(IrAnalyze *ira, IrInst *source_instruction,
- IrInstGen *operand, ZigType *ty, IrInstGen *result_loc)
-{
- IrInstGenResizeSlice *instruction = ir_build_inst_gen<IrInstGenResizeSlice>(&ira->new_irb,
- source_instruction->scope, source_instruction->source_node);
- instruction->base.value->type = ty;
- instruction->operand = operand;
- instruction->result_loc = result_loc;
-
- ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
- if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
-
- return &instruction->base;
-}
-
static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
IrInstSrc *target, IrInstSrc *options)
{
@@ -3540,32 +3494,6 @@ static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode
return &instruction->base;
}
-static IrInstSrc *ir_build_to_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target,
- ResultLoc *result_loc)
-{
- IrInstSrcToBytes *instruction = ir_build_instruction<IrInstSrcToBytes>(irb, scope, source_node);
- instruction->target = target;
- instruction->result_loc = result_loc;
-
- ir_ref_instruction(target, irb->current_basic_block);
-
- return &instruction->base;
-}
-
-static IrInstSrc *ir_build_from_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
- IrInstSrc *dest_child_type, IrInstSrc *target, ResultLoc *result_loc)
-{
- IrInstSrcFromBytes *instruction = ir_build_instruction<IrInstSrcFromBytes>(irb, scope, source_node);
- instruction->dest_child_type = dest_child_type;
- instruction->target = target;
- instruction->result_loc = result_loc;
-
- ir_ref_instruction(dest_child_type, irb->current_basic_block);
- ir_ref_instruction(target, irb->current_basic_block);
-
- return &instruction->base;
-}
-
static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
IrInstSrc *dest_type, IrInstSrc *target)
{
@@ -3601,19 +3529,6 @@ static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode
return &instruction->base;
}
-static IrInstSrc *ir_build_int_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_signed,
- IrInstSrc *bit_count)
-{
- IrInstSrcIntType *instruction = ir_build_instruction<IrInstSrcIntType>(irb, scope, source_node);
- instruction->is_signed = is_signed;
- instruction->bit_count = bit_count;
-
- ir_ref_instruction(is_signed, irb->current_basic_block);
- ir_ref_instruction(bit_count, irb->current_basic_block);
-
- return &instruction->base;
-}
-
static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len,
IrInstSrc *elem_type)
{
@@ -3808,41 +3723,6 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction,
return &instruction->base;
}
-static IrInstSrc *ir_build_member_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *container) {
- IrInstSrcMemberCount *instruction = ir_build_instruction<IrInstSrcMemberCount>(irb, scope, source_node);
- instruction->container = container;
-
- ir_ref_instruction(container, irb->current_basic_block);
-
- return &instruction->base;
-}
-
-static IrInstSrc *ir_build_member_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
- IrInstSrc *container_type, IrInstSrc *member_index)
-{
- IrInstSrcMemberType *instruction = ir_build_instruction<IrInstSrcMemberType>(irb, scope, source_node);
- instruction->container_type = container_type;
- instruction->member_index = member_index;
-
- ir_ref_instruction(container_type, irb->current_basic_block);
- ir_ref_instruction(member_index, irb->current_basic_block);
-
- return &instruction->base;
-}
-
-static IrInstSrc *ir_build_member_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
- IrInstSrc *container_type, IrInstSrc *member_index)
-{
- IrInstSrcMemberName *instruction = ir_build_instruction<IrInstSrcMemberName>(irb, scope, source_node);
- instruction->container_type = container_type;
- instruction->member_index = member_index;
-
- ir_ref_instruction(container_type, irb->current_basic_block);
- ir_ref_instruction(member_index, irb->current_basic_block);
-
- return &instruction->base;
-}
-
static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);
return &instruction->base;
@@ -4517,15 +4397,6 @@ static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source
return &instruction->base;
}
-static IrInstSrc *ir_build_type_id(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
- IrInstSrcTypeId *instruction = ir_build_instruction<IrInstSrcTypeId>(irb, scope, source_node);
- instruction->type_value = type_value;
-
- ir_ref_instruction(type_value, irb->current_basic_block);
-
- return &instruction->base;
-}
-
static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
IrInstSrc *new_quota)
{
@@ -4956,11 +4827,12 @@ static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_ins
}
static IrInstSrc *ir_build_await_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
- IrInstSrc *frame, ResultLoc *result_loc)
+ IrInstSrc *frame, ResultLoc *result_loc, bool is_noasync)
{
IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(irb, scope, source_node);
instruction->frame = frame;
instruction->result_loc = result_loc;
+ instruction->is_noasync = is_noasync;
ir_ref_instruction(frame, irb->current_basic_block);
@@ -4968,13 +4840,14 @@ static IrInstSrc *ir_build_await_src(IrBuilderSrc *irb, Scope *scope, AstNode *s
}
static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruction,
- IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc)
+ IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc, bool is_noasync)
{
IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb,
source_instruction->scope, source_instruction->source_node);
instruction->base.value->type = result_type;
instruction->frame = frame;
instruction->result_loc = result_loc;
+ instruction->is_noasync = is_noasync;
ir_ref_inst_gen(frame, ira->new_irb.current_basic_block);
if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
@@ -6595,31 +6468,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);
return ir_lval_wrap(irb, scope, result, lval, result_loc);
}
- case BuiltinFnIdFromBytes:
- {
- AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
- IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
- if (arg0_value == irb->codegen->invalid_inst_src)
- return arg0_value;
-
- AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
- IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
- if (arg1_value == irb->codegen->invalid_inst_src)
- return arg1_value;
-
- IrInstSrc *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc);
- return ir_lval_wrap(irb, scope, result, lval, result_loc);
- }
- case BuiltinFnIdToBytes:
- {
- AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
- IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
- if (arg0_value == irb->codegen->invalid_inst_src)
- return arg0_value;
-
- IrInstSrc *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc);
- return ir_lval_wrap(irb, scope, result, lval, result_loc);
- }
case BuiltinFnIdIntToFloat:
{
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
@@ -6680,21 +6528,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value);
return ir_lval_wrap(irb, scope, result, lval, result_loc);
}
- case BuiltinFnIdIntType:
- {
- AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
- IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
- if (arg0_value == irb->codegen->invalid_inst_src)
- return arg0_value;
-
- AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
- IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
- if (arg1_value == irb->codegen->invalid_inst_src)
- return arg1_value;
-
- IrInstSrc *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value);
- return ir_lval_wrap(irb, scope, int_type, lval, result_loc);
- }
case BuiltinFnIdVectorType:
{
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
@@ -6792,48 +6625,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);
}
- case BuiltinFnIdMemberCount:
- {
- AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
- IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
- if (arg0_value == irb->codegen->invalid_inst_src)
- return arg0_value;
-
- IrInstSrc *member_count = ir_build_member_count(irb, scope, node, arg0_value);
- return ir_lval_wrap(irb, scope, member_count, lval, result_loc);
- }
- case BuiltinFnIdMemberType:
- {
- AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
- IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
- if (arg0_value == irb->codegen->invalid_inst_src)
- return arg0_value;
-
- AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
- IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
- if (arg1_value == irb->codegen->invalid_inst_src)
- return arg1_value;
-
-
- IrInstSrc *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value);
- return ir_lval_wrap(irb, scope, member_type, lval, result_loc);
- }
- case BuiltinFnIdMemberName:
- {
- AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
- IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
- if (arg0_value == irb->codegen->invalid_inst_src)
- return arg0_value;
-
- AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
- IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
- if (arg1_value == irb->codegen->invalid_inst_src)
- return arg1_value;
-
-
- IrInstSrc *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value);
- return ir_lval_wrap(irb, scope, member_name, lval, result_loc);
- }
case BuiltinFnIdField:
{
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
@@ -7158,16 +6949,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
}
case BuiltinFnIdAsyncCall:
return ir_gen_async_call(irb, scope, nullptr, node, lval, result_loc);
- case BuiltinFnIdTypeId:
- {
- AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
- IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
- if (arg0_value == irb->codegen->invalid_inst_src)
- return arg0_value;
-
- IrInstSrc *type_id = ir_build_type_id(irb, scope, node, arg0_value);
- return ir_lval_wrap(irb, scope, type_id, lval, result_loc);
- }
case BuiltinFnIdShlExact:
{
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
@@ -7243,21 +7024,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);
return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);
}
- case BuiltinFnIdArgType:
- {
- AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
- IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
- if (arg0_value == irb->codegen->invalid_inst_src)
- return arg0_value;
-
- AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
- IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
- if (arg1_value == irb->codegen->invalid_inst_src)
- return arg1_value;
-
- IrInstSrc *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false);
- return ir_lval_wrap(irb, scope, arg_type, lval, result_loc);
- }
case BuiltinFnIdExport:
{
// Cast the options parameter to the options type
@@ -8073,9 +7839,9 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
if (var_symbol) {
IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, &spill_scope->base, symbol_node,
err_val_ptr, false, false);
- IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ?
- ir_build_ref_src(irb, &spill_scope->base, symbol_node, payload_ptr, true, false) : payload_ptr;
- ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_ptr);
+ IrInstSrc *var_value = node->data.while_expr.var_is_ptr ?
+ payload_ptr : ir_build_load_ptr(irb, &spill_scope->base, symbol_node, payload_ptr);
+ build_decl_var_and_init(irb, payload_scope, symbol_node, payload_var, var_value, buf_ptr(var_symbol), is_comptime);
}
ZigList<IrInstSrc *> incoming_values = {0};
@@ -8123,7 +7889,8 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
true, false, false, is_comptime);
Scope *err_scope = err_var->child_scope;
IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, err_symbol_node, err_val_ptr);
- ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_ptr);
+ IrInstSrc *err_value = ir_build_load_ptr(irb, err_scope, err_symbol_node, err_ptr);
+ build_decl_var_and_init(irb, err_scope, err_symbol_node, err_var, err_value, buf_ptr(err_symbol), is_comptime);
if (peer_parent->peers.length != 0) {
peer_parent->peers.last()->next_bb = else_block;
@@ -8184,9 +7951,9 @@ static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
ir_set_cursor_at_end_and_append_block(irb, body_block);
IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, &spill_scope->base, symbol_node, maybe_val_ptr, false, false);
- IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ?
- ir_build_ref_src(irb, &spill_scope->base, symbol_node, payload_ptr, true, false) : payload_ptr;
- ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_ptr);
+ IrInstSrc *var_value = node->data.while_expr.var_is_ptr ?
+ payload_ptr : ir_build_load_ptr(irb, &spill_scope->base, symbol_node, payload_ptr);
+ build_decl_var_and_init(irb, child_scope, symbol_node, payload_var, var_value, buf_ptr(var_symbol), is_comptime);
ZigList<IrInstSrc *> incoming_values = {0};
ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
@@ -8425,9 +8192,9 @@ static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNod
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;
- IrInstSrc *var_ptr = node->data.for_expr.elem_is_ptr ?
- ir_build_ref_src(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr;
- ir_build_var_decl_src(irb, parent_scope, elem_node, elem_var, nullptr, var_ptr);
+ IrInstSrc *elem_value = node->data.for_expr.elem_is_ptr ?
+ elem_ptr : ir_build_load_ptr(irb, &spill_scope->base, elem_node, elem_ptr);
+ build_decl_var_and_init(irb, parent_scope, elem_node, elem_var, elem_value, buf_ptr(elem_var_name), is_comptime);
ZigList<IrInstSrc *> incoming_values = {0};
ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
@@ -8847,8 +8614,9 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo
var_symbol, is_const, is_const, is_shadowable, is_comptime);
IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false, false);
- IrInstSrc *var_ptr = var_is_ptr ? ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
- ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);
+ IrInstSrc *var_value = var_is_ptr ?
+ payload_ptr : ir_build_load_ptr(irb, &spill_scope->base, node, payload_ptr);
+ build_decl_var_and_init(irb, subexpr_scope, node, var, var_value, buf_ptr(var_symbol), is_comptime);
var_scope = var->child_scope;
} else {
var_scope = subexpr_scope;
@@ -8929,9 +8697,9 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);
IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, subexpr_scope, node, err_val_ptr, false, false);
- IrInstSrc *var_ptr = var_is_ptr ?
- ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
- ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);
+ IrInstSrc *var_value = var_is_ptr ?
+ payload_ptr : ir_build_load_ptr(irb, subexpr_scope, node, payload_ptr);
+ build_decl_var_and_init(irb, subexpr_scope, node, var, var_value, buf_ptr(var_symbol), var_is_comptime);
var_scope = var->child_scope;
} else {
var_scope = subexpr_scope;
@@ -8956,7 +8724,8 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
err_symbol, is_const, is_const, is_shadowable, is_comptime);
IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, subexpr_scope, node, err_val_ptr);
- ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, err_ptr);
+ IrInstSrc *err_value = ir_build_load_ptr(irb, subexpr_scope, node, err_ptr);
+ build_decl_var_and_init(irb, subexpr_scope, node, var, err_value, buf_ptr(err_symbol), is_comptime);
err_var_scope = var->child_scope;
} else {
err_var_scope = subexpr_scope;
@@ -9006,22 +8775,24 @@ static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *s
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;
- IrInstSrc *var_ptr;
+ IrInstSrc *var_value;
if (out_switch_else_var != nullptr) {
IrInstSrcSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node,
target_value_ptr);
*out_switch_else_var = switch_else_var;
IrInstSrc *payload_ptr = &switch_else_var->base;
- var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
+ var_value = var_is_ptr ?
+ payload_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, payload_ptr);
} else if (prong_values != nullptr) {
IrInstSrc *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr,
prong_values, prong_values_len);
- var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
+ var_value = var_is_ptr ?
+ payload_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, payload_ptr);
} else {
- var_ptr = var_is_ptr ?
- ir_build_ref_src(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr;
+ var_value = var_is_ptr ?
+ target_value_ptr : ir_build_load_ptr(irb, scope, var_symbol_node, target_value_ptr);
}
- ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_ptr);
+ build_decl_var_and_init(irb, scope, var_symbol_node, var, var_value, buf_ptr(var_name), var_is_comptime);
} else {
child_scope = scope;
}
@@ -9594,7 +9365,8 @@ static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
is_const, is_const, is_shadowable, is_comptime);
err_scope = var->child_scope;
IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, node, err_union_ptr);
- ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr);
+ IrInstSrc *err_value = ir_build_load_ptr(irb, err_scope, var_node, err_ptr);
+ build_decl_var_and_init(irb, err_scope, var_node, var, err_value, buf_ptr(var_name), is_comptime);
} else {
err_scope = subexpr_scope;
}
@@ -9914,6 +9686,8 @@ static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
{
assert(node->type == NodeTypeAwaitExpr);
+ bool is_noasync = node->data.await_expr.noasync_token != nullptr;
+
AstNode *expr_node = node->data.await_expr.expr;
if (expr_node->type == NodeTypeFnCallExpr && expr_node->data.fn_call_expr.modifier == CallModifierBuiltin) {
AstNode *fn_ref_expr = expr_node->data.fn_call_expr.fn_ref_expr;
@@ -9946,7 +9720,7 @@ static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *no
if (target_inst == irb->codegen->invalid_inst_src)
return irb->codegen->invalid_inst_src;
- IrInstSrc *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc);
+ IrInstSrc *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc, is_noasync);
return ir_lval_wrap(irb, scope, await_inst, lval, result_loc);
}
@@ -12703,12 +12477,14 @@ static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) {
IrInstGen *new_instruction = &const_instruction->base;
new_instruction->value->type = ty;
new_instruction->value->special = ConstValSpecialStatic;
+ ira->new_irb.constants.append(&heap::c_allocator, const_instruction);
return new_instruction;
}
static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) {
IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
old_instruction->scope, old_instruction->source_node);
+ ira->new_irb.constants.append(&heap::c_allocator, const_instruction);
return &const_instruction->base;
}
@@ -20599,12 +20375,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
if (type_is_invalid(array_ptr->value->type))
return ira->codegen->invalid_inst_gen;
- ZigValue *orig_array_ptr_val = array_ptr->value;
-
IrInstGen *elem_index = elem_ptr_instruction->elem_index->child;
if (type_is_invalid(elem_index->value->type))
return ira->codegen->invalid_inst_gen;
+ ZigValue *orig_array_ptr_val = array_ptr->value;
+
ZigType *ptr_type = orig_array_ptr_val->type;
assert(ptr_type->id == ZigTypeIdPointer);
@@ -20614,23 +20390,25 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
// We will adjust return_type's alignment before returning it.
ZigType *return_type;
- if (type_is_invalid(array_type)) {
+ if (type_is_invalid(array_type))
return ira->codegen->invalid_inst_gen;
- } else if (array_type->id == ZigTypeIdArray ||
- (array_type->id == ZigTypeIdPointer &&
- array_type->data.pointer.ptr_len == PtrLenSingle &&
- array_type->data.pointer.child_type->id == ZigTypeIdArray))
+
+ if (array_type->id == ZigTypeIdPointer &&
+ array_type->data.pointer.ptr_len == PtrLenSingle &&
+ array_type->data.pointer.child_type->id == ZigTypeIdArray)
{
- 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, ira->codegen, orig_array_ptr_val,
- elem_ptr_instruction->base.base.source_node);
- if (orig_array_ptr_val == nullptr)
- return ira->codegen->invalid_inst_gen;
- }
- }
+ IrInstGen *ptr_value = ir_get_deref(ira, &elem_ptr_instruction->base.base,
+ array_ptr, nullptr);
+ if (type_is_invalid(ptr_value->value->type))
+ return ira->codegen->invalid_inst_gen;
+
+ array_type = array_type->data.pointer.child_type;
+ ptr_type = ptr_type->data.pointer.child_type;
+
+ orig_array_ptr_val = ptr_value->value;
+ }
+
+ if (array_type->id == ZigTypeIdArray) {
if (array_type->data.array.len == 0) {
ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
buf_sprintf("index 0 outside array of size 0"));
@@ -20768,8 +20546,14 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
(orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray))
{
+ if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
+ elem_ptr_instruction->base.base.source_node, orig_array_ptr_val, UndefBad)))
+ {
+ return ira->codegen->invalid_inst_gen;
+ }
+
ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
- elem_ptr_instruction->base.base.source_node);
+ elem_ptr_instruction->base.base.source_node);
if (array_ptr_val == nullptr)
return ira->codegen->invalid_inst_gen;
@@ -21178,6 +20962,13 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
return ira->codegen->invalid_inst_gen;
if (type_is_invalid(struct_val->type))
return ira->codegen->invalid_inst_gen;
+
+ // This to allow lazy values to be resolved.
+ if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
+ source_instr->source_node, struct_val, UndefOk)))
+ {
+ return ira->codegen->invalid_inst_gen;
+ }
if (initializing && struct_val->special == ConstValSpecialUndef) {
struct_val->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, struct_type->data.structure.src_field_count);
struct_val->special = ConstValSpecialStatic;
@@ -23583,7 +23374,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
}
static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val,
- ScopeDecls *decls_scope)
+ ScopeDecls *decls_scope, bool resolve_types)
{
Error err;
ZigType *type_info_declaration_type = ir_type_info_get_type(ira, "Declaration", nullptr);
@@ -23594,6 +23385,24 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
ensure_field_index(type_info_declaration_type, "is_pub", 1);
ensure_field_index(type_info_declaration_type, "data", 2);
+ if (!resolve_types) {
+ ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, type_info_declaration_type,
+ false, false, PtrLenUnknown, 0, 0, 0, false);
+
+ out_val->special = ConstValSpecialLazy;
+ out_val->type = get_slice_type(ira->codegen, ptr_type);
+
+ LazyValueTypeInfoDecls *lazy_type_info_decls = heap::c_allocator.create<LazyValueTypeInfoDecls>();
+ lazy_type_info_decls->ira = ira; ira_ref(ira);
+ out_val->data.x_lazy = &lazy_type_info_decls->base;
+ lazy_type_info_decls->base.id = LazyValueIdTypeInfoDecls;
+
+ lazy_type_info_decls->source_instr = source_instr;
+ lazy_type_info_decls->decls_scope = decls_scope;
+
+ return ErrorNone;
+ }
+
ZigType *type_info_declaration_data_type = ir_type_info_get_type(ira, "Data", type_info_declaration_type);
if ((err = type_resolve(ira->codegen, type_info_declaration_data_type, ResolveStatusSizeKnown)))
return err;
@@ -23606,14 +23415,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
if ((err = type_resolve(ira->codegen, type_info_fn_decl_inline_type, ResolveStatusSizeKnown)))
return err;
- // Loop through our declarations once to figure out how many declarations we will generate info for.
+ // The unresolved declarations are collected in a separate queue to avoid
+ // modifying decl_table while iterating over it
+ ZigList<Tld*> resolve_decl_queue{};
+
auto decl_it = decls_scope->decl_table.entry_iterator();
decltype(decls_scope->decl_table)::Entry *curr_entry = nullptr;
- int declaration_count = 0;
-
while ((curr_entry = decl_it.next()) != nullptr) {
- // If the declaration is unresolved, force it to be resolved again.
- resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node, false);
if (curr_entry->value->resolution == TldResolutionInvalid) {
return ErrorSemanticAnalyzeFail;
}
@@ -23623,16 +23431,36 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
return ErrorSemanticAnalyzeFail;
}
+ // If the declaration is unresolved, force it to be resolved again.
+ if (curr_entry->value->resolution == TldResolutionUnresolved)
+ resolve_decl_queue.append(curr_entry->value);
+ }
+
+ for (size_t i = 0; i < resolve_decl_queue.length; i++) {
+ Tld *decl = resolve_decl_queue.at(i);
+ resolve_top_level_decl(ira->codegen, decl, decl->source_node, false);
+ if (decl->resolution == TldResolutionInvalid) {
+ return ErrorSemanticAnalyzeFail;
+ }
+ }
+
+ resolve_decl_queue.deinit();
+
+ // Loop through our declarations once to figure out how many declarations we will generate info for.
+ int declaration_count = 0;
+ decl_it = decls_scope->decl_table.entry_iterator();
+ while ((curr_entry = decl_it.next()) != nullptr) {
// Skip comptime blocks and test functions.
- if (curr_entry->value->id != TldIdCompTime) {
- if (curr_entry->value->id == TldIdFn) {
- ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
- if (fn_entry->is_test)
- continue;
- }
+ if (curr_entry->value->id == TldIdCompTime)
+ continue;
- declaration_count += 1;
+ if (curr_entry->value->id == TldIdFn) {
+ ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
+ if (fn_entry->is_test)
+ continue;
}
+
+ declaration_count += 1;
}
ZigValue *declaration_array = ira->codegen->pass1_arena->create<ZigValue>();
@@ -24146,7 +23974,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
// decls: []TypeInfo.Declaration
ensure_field_index(result->type, "decls", 3);
if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
- type_entry->data.enumeration.decls_scope)))
+ type_entry->data.enumeration.decls_scope, false)))
{
return err;
}
@@ -24318,7 +24146,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
// decls: []TypeInfo.Declaration
ensure_field_index(result->type, "decls", 3);
if ((err = ir_make_type_info_decls(ira, source_instr, fields[3],
- type_entry->data.unionation.decls_scope)))
+ type_entry->data.unionation.decls_scope, false)))
{
return err;
}
@@ -24410,7 +24238,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
// decls: []TypeInfo.Declaration
ensure_field_index(result->type, "decls", 2);
if ((err = ir_make_type_info_decls(ira, source_instr, fields[2],
- type_entry->data.structure.decls_scope)))
+ type_entry->data.structure.decls_scope, false)))
{
return err;
}
@@ -24784,19 +24612,6 @@ static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *ins
return ir_const_type(ira, &instruction->base.base, type);
}
-static IrInstGen *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstSrcTypeId *instruction) {
- IrInstGen *type_value = instruction->type_value->child;
- ZigType *type_entry = ir_resolve_type(ira, type_value);
- if (type_is_invalid(type_entry))
- return ira->codegen->invalid_inst_gen;
-
- ZigType *result_type = get_builtin_type(ira->codegen, "TypeId");
-
- IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
- bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));
- return result;
-}
-
static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
IrInstSrcSetEvalBranchQuota *instruction)
{
@@ -25394,171 +25209,6 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE
return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type);
}
-static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFromBytes *instruction) {
- Error err;
-
- ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child);
- if (type_is_invalid(dest_child_type))
- return ira->codegen->invalid_inst_gen;
-
- IrInstGen *target = instruction->target->child;
- if (type_is_invalid(target->value->type))
- return ira->codegen->invalid_inst_gen;
-
- bool src_ptr_const;
- bool src_ptr_volatile;
- uint32_t src_ptr_align;
- 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;
-
- if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align)))
- return ira->codegen->invalid_inst_gen;
- } else if (is_slice(target->value->type)) {
- 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;
-
- if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align)))
- return ira->codegen->invalid_inst_gen;
- } else {
- src_ptr_const = true;
- src_ptr_volatile = false;
-
- if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown)))
- return ira->codegen->invalid_inst_gen;
-
- src_ptr_align = get_abi_alignment(ira->codegen, target->value->type);
- }
-
- if (src_ptr_align != 0) {
- if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusAlignmentKnown)))
- return ira->codegen->invalid_inst_gen;
- }
-
- 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, false);
- ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
-
- 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, false);
- ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
-
- IrInstGen *casted_value = ir_implicit_cast2(ira, &instruction->target->base, target, u8_slice);
- if (type_is_invalid(casted_value->value->type))
- return ira->codegen->invalid_inst_gen;
-
- bool have_known_len = false;
- uint64_t known_len;
-
- if (instr_is_comptime(casted_value)) {
- ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
- if (!val)
- return ira->codegen->invalid_inst_gen;
-
- ZigValue *len_val = val->data.x_struct.fields[slice_len_index];
- if (value_is_comptime(len_val)) {
- known_len = bigint_as_u64(&len_val->data.x_bigint);
- have_known_len = true;
- }
- }
-
- IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
- dest_slice_type, nullptr, true, true);
- if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) {
- return result_loc;
- }
-
- if (target->value->type->id == ZigTypeIdPointer &&
- target->value->type->data.pointer.ptr_len == PtrLenSingle &&
- target->value->type->data.pointer.child_type->id == ZigTypeIdArray)
- {
- known_len = target->value->type->data.pointer.child_type->data.array.len;
- have_known_len = true;
- } else if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) {
- known_len = casted_value->value->data.rh_slice.len;
- have_known_len = true;
- }
-
- if (have_known_len) {
- if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown)))
- return ira->codegen->invalid_inst_gen;
- uint64_t child_type_size = type_size(ira->codegen, dest_child_type);
- uint64_t remainder = known_len % child_type_size;
- if (remainder != 0) {
- ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
- buf_sprintf("unable to convert [%" ZIG_PRI_u64 "]u8 to %s: size mismatch",
- known_len, buf_ptr(&dest_slice_type->name)));
- add_error_note(ira->codegen, msg, instruction->dest_child_type->base.source_node,
- buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64,
- buf_ptr(&dest_child_type->name), child_type_size, remainder));
- return ira->codegen->invalid_inst_gen;
- }
- }
-
- return ir_build_resize_slice(ira, &instruction->base.base, casted_value, dest_slice_type, result_loc);
-}
-
-static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToBytes *instruction) {
- Error err;
-
- IrInstGen *target = instruction->target->child;
- if (type_is_invalid(target->value->type))
- return ira->codegen->invalid_inst_gen;
-
- if (!is_slice(target->value->type)) {
- ir_add_error(ira, &instruction->target->base,
- buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name)));
- return ira->codegen->invalid_inst_gen;
- }
-
- ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
-
- uint32_t alignment;
- if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))
- return ira->codegen->invalid_inst_gen;
-
- 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,
- alignment, 0, 0, false);
- ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type);
-
- if (instr_is_comptime(target)) {
- ZigValue *target_val = ir_resolve_const(ira, target, UndefBad);
- if (target_val == nullptr)
- return ira->codegen->invalid_inst_gen;
-
- IrInstGen *result = ir_const(ira, &instruction->base.base, dest_slice_type);
- result->value->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, 2);
-
- ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
- ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
- copy_const_val(ira->codegen, ptr_val, target_ptr_val);
- ptr_val->type = dest_ptr_type;
-
- ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index];
- len_val->special = ConstValSpecialStatic;
- len_val->type = ira->codegen->builtin_types.entry_usize;
- ZigValue *target_len_val = target_val->data.x_struct.fields[slice_len_index];
- ZigType *elem_type = src_ptr_type->data.pointer.child_type;
- BigInt elem_size_bigint;
- bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type));
- bigint_mul(&len_val->data.x_bigint, &target_len_val->data.x_bigint, &elem_size_bigint);
-
- return result;
- }
-
- IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
- dest_slice_type, nullptr, true, true);
- if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
- return result_loc;
- }
-
- return ir_build_resize_slice(ira, &instruction->base.base, target, dest_slice_type, result_loc);
-}
-
static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {
Error err;
@@ -25672,20 +25322,6 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo
return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt);
}
-static IrInstGen *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstSrcIntType *instruction) {
- IrInstGen *is_signed_value = instruction->is_signed->child;
- bool is_signed;
- if (!ir_resolve_bool(ira, is_signed_value, &is_signed))
- return ira->codegen->invalid_inst_gen;
-
- IrInstGen *bit_count_value = instruction->bit_count->child;
- uint64_t bit_count;
- if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count))
- return ira->codegen->invalid_inst_gen;
-
- return ir_const_type(ira, &instruction->base.base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count));
-}
-
static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {
uint64_t len;
if (!ir_resolve_unsigned(ira, instruction->len->child, ira->codegen->builtin_types.entry_u32, &len))
@@ -26582,148 +26218,21 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
return_type, nullptr, true, true);
- if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
- return result_loc;
- }
- return ir_build_slice_gen(ira, &instruction->base.base, return_type,
- ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
-}
-
-static IrInstGen *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstSrcMemberCount *instruction) {
- Error err;
- IrInstGen *container = instruction->container->child;
- if (type_is_invalid(container->value->type))
- return ira->codegen->invalid_inst_gen;
- ZigType *container_type = ir_resolve_type(ira, container);
-
- if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
- return ira->codegen->invalid_inst_gen;
-
- uint64_t result;
- if (type_is_invalid(container_type)) {
- return ira->codegen->invalid_inst_gen;
- } else if (container_type->id == ZigTypeIdEnum) {
- result = container_type->data.enumeration.src_field_count;
- } else if (container_type->id == ZigTypeIdStruct) {
- result = container_type->data.structure.src_field_count;
- } else if (container_type->id == ZigTypeIdUnion) {
- result = container_type->data.unionation.src_field_count;
- } else if (container_type->id == ZigTypeIdErrorSet) {
- if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.base.source_node)) {
- return ira->codegen->invalid_inst_gen;
- }
- if (type_is_global_error_set(container_type)) {
- ir_add_error(ira, &instruction->base.base, buf_sprintf("global error set member count not available at comptime"));
- return ira->codegen->invalid_inst_gen;
- }
- result = container_type->data.error_set.err_count;
- } else {
- ir_add_error(ira, &instruction->base.base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
- return ira->codegen->invalid_inst_gen;
- }
-
- return ir_const_unsigned(ira, &instruction->base.base, result);
-}
-
-static IrInstGen *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstSrcMemberType *instruction) {
- Error err;
- IrInstGen *container_type_value = instruction->container_type->child;
- ZigType *container_type = ir_resolve_type(ira, container_type_value);
- if (type_is_invalid(container_type))
- return ira->codegen->invalid_inst_gen;
-
- if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
- return ira->codegen->invalid_inst_gen;
-
-
- uint64_t member_index;
- IrInstGen *index_value = instruction->member_index->child;
- if (!ir_resolve_usize(ira, index_value, &member_index))
- return ira->codegen->invalid_inst_gen;
- if (container_type->id == ZigTypeIdStruct) {
- if (member_index >= container_type->data.structure.src_field_count) {
- ir_add_error(ira, &index_value->base,
- buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
- member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
- return ira->codegen->invalid_inst_gen;
+ if (result_loc != nullptr) {
+ if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
+ return result_loc;
}
- TypeStructField *field = container_type->data.structure.fields[member_index];
-
- return ir_const_type(ira, &instruction->base.base, field->type_entry);
- } else if (container_type->id == ZigTypeIdUnion) {
- if (member_index >= container_type->data.unionation.src_field_count) {
- ir_add_error(ira, &index_value->base,
- buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
- member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
+ IrInstGen *dummy_value = ir_const(ira, &instruction->base.base, return_type);
+ dummy_value->value->special = ConstValSpecialRuntime;
+ IrInstGen *dummy_result = ir_implicit_cast2(ira, &instruction->base.base,
+ dummy_value, result_loc->value->type->data.pointer.child_type);
+ if (type_is_invalid(dummy_result->value->type))
return ira->codegen->invalid_inst_gen;
- }
- TypeUnionField *field = &container_type->data.unionation.fields[member_index];
-
- return ir_const_type(ira, &instruction->base.base, field->type_entry);
- } else {
- ir_add_error(ira, &container_type_value->base,
- buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name)));
- return ira->codegen->invalid_inst_gen;
}
-}
-
-static IrInstGen *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstSrcMemberName *instruction) {
- Error err;
- IrInstGen *container_type_value = instruction->container_type->child;
- ZigType *container_type = ir_resolve_type(ira, container_type_value);
- if (type_is_invalid(container_type))
- return ira->codegen->invalid_inst_gen;
- if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
- return ira->codegen->invalid_inst_gen;
-
- uint64_t member_index;
- IrInstGen *index_value = instruction->member_index->child;
- if (!ir_resolve_usize(ira, index_value, &member_index))
- return ira->codegen->invalid_inst_gen;
-
- if (container_type->id == ZigTypeIdStruct) {
- if (member_index >= container_type->data.structure.src_field_count) {
- ir_add_error(ira, &index_value->base,
- buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
- member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
- return ira->codegen->invalid_inst_gen;
- }
- TypeStructField *field = container_type->data.structure.fields[member_index];
-
- IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
- init_const_str_lit(ira->codegen, result->value, field->name);
- return result;
- } else if (container_type->id == ZigTypeIdEnum) {
- if (member_index >= container_type->data.enumeration.src_field_count) {
- ir_add_error(ira, &index_value->base,
- buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
- member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count));
- return ira->codegen->invalid_inst_gen;
- }
- TypeEnumField *field = &container_type->data.enumeration.fields[member_index];
-
- IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
- init_const_str_lit(ira->codegen, result->value, field->name);
- return result;
- } else if (container_type->id == ZigTypeIdUnion) {
- if (member_index >= container_type->data.unionation.src_field_count) {
- ir_add_error(ira, &index_value->base,
- buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
- member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
- return ira->codegen->invalid_inst_gen;
- }
- TypeUnionField *field = &container_type->data.unionation.fields[member_index];
-
- IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
- init_const_str_lit(ira->codegen, result->value, field->name);
- return result;
- } else {
- ir_add_error(ira, &container_type_value->base,
- buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name)));
- return ira->codegen->invalid_inst_gen;
- }
+ return ir_build_slice_gen(ira, &instruction->base.base, return_type,
+ ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
}
static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {
@@ -29466,7 +28975,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i
ir_assert(fn_entry != nullptr, &instruction->base.base);
// If it's not @Frame(func) then it's definitely a suspend point
- if (target_fn == nullptr) {
+ if (target_fn == nullptr && !instruction->is_noasync) {
if (fn_entry->inferred_async_node == nullptr) {
fn_entry->inferred_async_node = instruction->base.base.source_node;
}
@@ -29489,7 +28998,8 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i
result_loc = nullptr;
}
- IrInstGenAwait *result = ir_build_await_gen(ira, &instruction->base.base, frame, result_type, result_loc);
+ IrInstGenAwait *result = ir_build_await_gen(ira, &instruction->base.base, frame, result_type, result_loc,
+ instruction->is_noasync);
result->target_fn = target_fn;
fn_entry->await_list.append(result);
return ir_finish_anal(ira, &result->base);
@@ -29677,18 +29187,12 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
return ir_analyze_instruction_float_cast(ira, (IrInstSrcFloatCast *)instruction);
case IrInstSrcIdErrSetCast:
return ir_analyze_instruction_err_set_cast(ira, (IrInstSrcErrSetCast *)instruction);
- case IrInstSrcIdFromBytes:
- return ir_analyze_instruction_from_bytes(ira, (IrInstSrcFromBytes *)instruction);
- case IrInstSrcIdToBytes:
- return ir_analyze_instruction_to_bytes(ira, (IrInstSrcToBytes *)instruction);
case IrInstSrcIdIntToFloat:
return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction);
case IrInstSrcIdFloatToInt:
return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction);
case IrInstSrcIdBoolToInt:
return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction);
- case IrInstSrcIdIntType:
- return ir_analyze_instruction_int_type(ira, (IrInstSrcIntType *)instruction);
case IrInstSrcIdVectorType:
return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction);
case IrInstSrcIdShuffleVector:
@@ -29703,12 +29207,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction);
case IrInstSrcIdSlice:
return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction);
- case IrInstSrcIdMemberCount:
- return ir_analyze_instruction_member_count(ira, (IrInstSrcMemberCount *)instruction);
- case IrInstSrcIdMemberType:
- return ir_analyze_instruction_member_type(ira, (IrInstSrcMemberType *)instruction);
- case IrInstSrcIdMemberName:
- return ir_analyze_instruction_member_name(ira, (IrInstSrcMemberName *)instruction);
case IrInstSrcIdBreakpoint:
return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction);
case IrInstSrcIdReturnAddress:
@@ -29763,8 +29261,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction);
case IrInstSrcIdHasField:
return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction);
- case IrInstSrcIdTypeId:
- return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction);
case IrInstSrcIdSetEvalBranchQuota:
return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction);
case IrInstSrcIdPtrType:
@@ -30007,7 +29503,6 @@ bool ir_inst_gen_has_side_effects(IrInstGen *instruction) {
case IrInstGenIdCmpxchg:
case IrInstGenIdAssertZero:
case IrInstGenIdAssertNonNull:
- case IrInstGenIdResizeSlice:
case IrInstGenIdPtrOfArrayToSlice:
case IrInstGenIdSlice:
case IrInstGenIdOptionalWrap:
@@ -30180,15 +29675,11 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
case IrInstSrcIdRef:
case IrInstSrcIdEmbedFile:
case IrInstSrcIdTruncate:
- case IrInstSrcIdIntType:
case IrInstSrcIdVectorType:
case IrInstSrcIdShuffleVector:
case IrInstSrcIdSplat:
case IrInstSrcIdBoolNot:
case IrInstSrcIdSlice:
- case IrInstSrcIdMemberCount:
- case IrInstSrcIdMemberType:
- case IrInstSrcIdMemberName:
case IrInstSrcIdAlignOf:
case IrInstSrcIdReturnAddress:
case IrInstSrcIdFrameAddress:
@@ -30215,7 +29706,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
case IrInstSrcIdTypeInfo:
case IrInstSrcIdType:
case IrInstSrcIdHasField:
- case IrInstSrcIdTypeId:
case IrInstSrcIdAlignCast:
case IrInstSrcIdImplicitCast:
case IrInstSrcIdResolveResult:
@@ -30233,8 +29723,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
case IrInstSrcIdIntToFloat:
case IrInstSrcIdFloatToInt:
case IrInstSrcIdBoolToInt:
- case IrInstSrcIdFromBytes:
- case IrInstSrcIdToBytes:
case IrInstSrcIdEnumToInt:
case IrInstSrcIdHasDecl:
case IrInstSrcIdAlloca:
@@ -30347,6 +29835,18 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
switch (val->data.x_lazy->id) {
case LazyValueIdInvalid:
zig_unreachable();
+ case LazyValueIdTypeInfoDecls: {
+ LazyValueTypeInfoDecls *type_info_decls = reinterpret_cast<LazyValueTypeInfoDecls *>(val->data.x_lazy);
+ IrAnalyze *ira = type_info_decls->ira;
+
+ if ((err = ir_make_type_info_decls(ira, type_info_decls->source_instr, val, type_info_decls->decls_scope, true)))
+ {
+ return err;
+ };
+
+ // We can't free the lazy value here, because multiple other ZigValues might be pointing to it.
+ return ErrorNone;
+ }
case LazyValueIdAlignOf: {
LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy);
IrAnalyze *ira = lazy_align_of->ira;