authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-27 23:40:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-19 18:18:44-04:00
log54e716afdcb0609cfc42229ad925e6dc9b07a66f
tree8a9442a1ebc5a77a9005f457c417cdd2fdf3254e
parentf429f4dcabec2324b76b900f5785204897ea7685
signature Commit is signed but in an unrecognized format.

remove coroutines implementation and promise type


17 files changed, 62 insertions(+), 2814 deletions(-)

src-self-hosted/main.zig+8-8
...@@ -466,7 +466,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co...@@ -466,7 +466,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
466 comp.link_objects = link_objects;466 comp.link_objects = link_objects;
467467
468 comp.start();468 comp.start();
469 const process_build_events_handle = try async<loop.allocator> processBuildEvents(comp, color);469 // TODO const process_build_events_handle = try async<loop.allocator> processBuildEvents(comp, color);
470 defer cancel process_build_events_handle;470 defer cancel process_build_events_handle;
471 loop.run();471 loop.run();
472}472}
...@@ -578,7 +578,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {...@@ -578,7 +578,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
578 var zig_compiler = try ZigCompiler.init(&loop);578 var zig_compiler = try ZigCompiler.init(&loop);
579 defer zig_compiler.deinit();579 defer zig_compiler.deinit();
580580
581 const handle = try async<loop.allocator> findLibCAsync(&zig_compiler);581 // TODO const handle = try async<loop.allocator> findLibCAsync(&zig_compiler);
582 defer cancel handle;582 defer cancel handle;
583583
584 loop.run();584 loop.run();
...@@ -663,12 +663,12 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {...@@ -663,12 +663,12 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
663 defer loop.deinit();663 defer loop.deinit();
664664
665 var result: FmtError!void = undefined;665 var result: FmtError!void = undefined;
666 const main_handle = try async<allocator> asyncFmtMainChecked(666 // TODO const main_handle = try async<allocator> asyncFmtMainChecked(
667 &result,667 // TODO &result,
668 &loop,668 // TODO &loop,
669 &flags,669 // TODO &flags,
670 color,670 // TODO color,
671 );671 // TODO );
672 defer cancel main_handle;672 defer cancel main_handle;
673 loop.run();673 loop.run();
674 return result;674 return result;
src/all_types.hpp-191
...@@ -70,17 +70,6 @@ struct IrExecutable {...@@ -70,17 +70,6 @@ struct IrExecutable {
70 Scope *begin_scope;70 Scope *begin_scope;
71 ZigList<Tld *> tld_list;71 ZigList<Tld *> tld_list;
7272
73 IrInstruction *coro_handle;
74 IrInstruction *atomic_state_field_ptr; // this one is shared and in the promise
75 IrInstruction *coro_result_ptr_field_ptr;
76 IrInstruction *coro_result_field_ptr;
77 IrInstruction *await_handle_var_ptr; // this one is where we put the one we extracted from the promise
78 IrBasicBlock *coro_early_final;
79 IrBasicBlock *coro_normal_final;
80 IrBasicBlock *coro_suspend_block;
81 IrBasicBlock *coro_final_cleanup_block;
82 ZigVar *coro_allocator_var;
83
84 bool invalid;73 bool invalid;
85 bool is_inline;74 bool is_inline;
86 bool is_generic_instantiation;75 bool is_generic_instantiation;
...@@ -489,7 +478,6 @@ enum NodeType {...@@ -489,7 +478,6 @@ enum NodeType {
489 NodeTypeResume,478 NodeTypeResume,
490 NodeTypeAwaitExpr,479 NodeTypeAwaitExpr,
491 NodeTypeSuspend,480 NodeTypeSuspend,
492 NodeTypePromiseType,
493 NodeTypeEnumLiteral,481 NodeTypeEnumLiteral,
494};482};
495483
...@@ -522,7 +510,6 @@ struct AstNodeFnProto {...@@ -522,7 +510,6 @@ struct AstNodeFnProto {
522 AstNode *section_expr;510 AstNode *section_expr;
523511
524 bool auto_err_set;512 bool auto_err_set;
525 AstNode *async_allocator_type;
526};513};
527514
528struct AstNodeFnDef {515struct AstNodeFnDef {
...@@ -657,7 +644,6 @@ struct AstNodeFnCallExpr {...@@ -657,7 +644,6 @@ struct AstNodeFnCallExpr {
657 bool is_builtin;644 bool is_builtin;
658 bool is_async;645 bool is_async;
659 bool seen; // used by @compileLog646 bool seen; // used by @compileLog
660 AstNode *async_allocator;
661};647};
662648
663struct AstNodeArrayAccessExpr {649struct AstNodeArrayAccessExpr {
...@@ -949,10 +935,6 @@ struct AstNodeSuspend {...@@ -949,10 +935,6 @@ struct AstNodeSuspend {
949 AstNode *block;935 AstNode *block;
950};936};
951937
952struct AstNodePromiseType {
953 AstNode *payload_type; // can be NULL
954};
955
956struct AstNodeEnumLiteral {938struct AstNodeEnumLiteral {
957 Token *period;939 Token *period;
958 Token *identifier;940 Token *identifier;
...@@ -1018,7 +1000,6 @@ struct AstNode {...@@ -1018,7 +1000,6 @@ struct AstNode {
1018 AstNodeResumeExpr resume_expr;1000 AstNodeResumeExpr resume_expr;
1019 AstNodeAwaitExpr await_expr;1001 AstNodeAwaitExpr await_expr;
1020 AstNodeSuspend suspend;1002 AstNodeSuspend suspend;
1021 AstNodePromiseType promise_type;
1022 AstNodeEnumLiteral enum_literal;1003 AstNodeEnumLiteral enum_literal;
1023 } data;1004 } data;
1024};1005};
...@@ -1047,7 +1028,6 @@ struct FnTypeId {...@@ -1047,7 +1028,6 @@ struct FnTypeId {
1047 bool is_var_args;1028 bool is_var_args;
1048 CallingConvention cc;1029 CallingConvention cc;
1049 uint32_t alignment;1030 uint32_t alignment;
1050 ZigType *async_allocator_type;
1051};1031};
10521032
1053uint32_t fn_type_id_hash(FnTypeId*);1033uint32_t fn_type_id_hash(FnTypeId*);
...@@ -1241,11 +1221,6 @@ struct ZigTypeBoundFn {...@@ -1241,11 +1221,6 @@ struct ZigTypeBoundFn {
1241 ZigType *fn_type;1221 ZigType *fn_type;
1242};1222};
12431223
1244struct ZigTypePromise {
1245 // null if `promise` instead of `promise->T`
1246 ZigType *result_type;
1247};
1248
1249struct ZigTypeVector {1224struct ZigTypeVector {
1250 // The type must be a pointer, integer, or float1225 // The type must be a pointer, integer, or float
1251 ZigType *elem_type;1226 ZigType *elem_type;
...@@ -1276,7 +1251,6 @@ enum ZigTypeId {...@@ -1276,7 +1251,6 @@ enum ZigTypeId {
1276 ZigTypeIdBoundFn,1251 ZigTypeIdBoundFn,
1277 ZigTypeIdArgTuple,1252 ZigTypeIdArgTuple,
1278 ZigTypeIdOpaque,1253 ZigTypeIdOpaque,
1279 ZigTypeIdPromise,
1280 ZigTypeIdVector,1254 ZigTypeIdVector,
1281 ZigTypeIdEnumLiteral,1255 ZigTypeIdEnumLiteral,
1282};1256};
...@@ -1314,7 +1288,6 @@ struct ZigType {...@@ -1314,7 +1288,6 @@ struct ZigType {
1314 ZigTypeUnion unionation;1288 ZigTypeUnion unionation;
1315 ZigTypeFn fn;1289 ZigTypeFn fn;
1316 ZigTypeBoundFn bound_fn;1290 ZigTypeBoundFn bound_fn;
1317 ZigTypePromise promise;
1318 ZigTypeVector vector;1291 ZigTypeVector vector;
1319 ZigTypeOpaque opaque;1292 ZigTypeOpaque opaque;
1320 } data;1293 } data;
...@@ -1322,8 +1295,6 @@ struct ZigType {...@@ -1322,8 +1295,6 @@ struct ZigType {
1322 // use these fields to make sure we don't duplicate type table entries for the same type1295 // use these fields to make sure we don't duplicate type table entries for the same type
1323 ZigType *pointer_parent[2]; // [0 - mut, 1 - const]1296 ZigType *pointer_parent[2]; // [0 - mut, 1 - const]
1324 ZigType *optional_parent;1297 ZigType *optional_parent;
1325 ZigType *promise_parent;
1326 ZigType *promise_frame_parent;
1327 // If we generate a constant name value for this type, we memoize it here.1298 // If we generate a constant name value for this type, we memoize it here.
1328 // The type of this is array1299 // The type of this is array
1329 ConstExprValue *cached_const_name_val;1300 ConstExprValue *cached_const_name_val;
...@@ -1709,20 +1680,6 @@ struct CodeGen {...@@ -1709,20 +1680,6 @@ struct CodeGen {
1709 LLVMValueRef trap_fn_val;1680 LLVMValueRef trap_fn_val;
1710 LLVMValueRef return_address_fn_val;1681 LLVMValueRef return_address_fn_val;
1711 LLVMValueRef frame_address_fn_val;1682 LLVMValueRef frame_address_fn_val;
1712 LLVMValueRef coro_destroy_fn_val;
1713 LLVMValueRef coro_id_fn_val;
1714 LLVMValueRef coro_alloc_fn_val;
1715 LLVMValueRef coro_size_fn_val;
1716 LLVMValueRef coro_begin_fn_val;
1717 LLVMValueRef coro_suspend_fn_val;
1718 LLVMValueRef coro_end_fn_val;
1719 LLVMValueRef coro_free_fn_val;
1720 LLVMValueRef coro_resume_fn_val;
1721 LLVMValueRef coro_save_fn_val;
1722 LLVMValueRef coro_promise_fn_val;
1723 LLVMValueRef coro_alloc_helper_fn_val;
1724 LLVMValueRef coro_frame_fn_val;
1725 LLVMValueRef merge_err_ret_traces_fn_val;
1726 LLVMValueRef add_error_return_trace_addr_fn_val;1683 LLVMValueRef add_error_return_trace_addr_fn_val;
1727 LLVMValueRef stacksave_fn_val;1684 LLVMValueRef stacksave_fn_val;
1728 LLVMValueRef stackrestore_fn_val;1685 LLVMValueRef stackrestore_fn_val;
...@@ -1797,7 +1754,6 @@ struct CodeGen {...@@ -1797,7 +1754,6 @@ struct CodeGen {
1797 ZigType *entry_var;1754 ZigType *entry_var;
1798 ZigType *entry_global_error_set;1755 ZigType *entry_global_error_set;
1799 ZigType *entry_arg_tuple;1756 ZigType *entry_arg_tuple;
1800 ZigType *entry_promise;
1801 ZigType *entry_enum_literal;1757 ZigType *entry_enum_literal;
1802 } builtin_types;1758 } builtin_types;
1803 ZigType *align_amt_type;1759 ZigType *align_amt_type;
...@@ -1985,7 +1941,6 @@ enum ScopeId {...@@ -1985,7 +1941,6 @@ enum ScopeId {
1985 ScopeIdSuspend,1941 ScopeIdSuspend,
1986 ScopeIdFnDef,1942 ScopeIdFnDef,
1987 ScopeIdCompTime,1943 ScopeIdCompTime,
1988 ScopeIdCoroPrelude,
1989 ScopeIdRuntime,1944 ScopeIdRuntime,
1990};1945};
19911946
...@@ -2128,12 +2083,6 @@ struct ScopeFnDef {...@@ -2128,12 +2083,6 @@ struct ScopeFnDef {
2128 ZigFn *fn_entry;2083 ZigFn *fn_entry;
2129};2084};
21302085
2131// This scope is created to indicate that the code in the scope
2132// is auto-generated coroutine prelude stuff.
2133struct ScopeCoroPrelude {
2134 Scope base;
2135};
2136
2137// synchronized with code in define_builtin_compile_vars2086// synchronized with code in define_builtin_compile_vars
2138enum AtomicOrder {2087enum AtomicOrder {
2139 AtomicOrderUnordered,2088 AtomicOrderUnordered,
...@@ -2231,7 +2180,6 @@ enum IrInstructionId {...@@ -2231,7 +2180,6 @@ enum IrInstructionId {
2231 IrInstructionIdSetRuntimeSafety,2180 IrInstructionIdSetRuntimeSafety,
2232 IrInstructionIdSetFloatMode,2181 IrInstructionIdSetFloatMode,
2233 IrInstructionIdArrayType,2182 IrInstructionIdArrayType,
2234 IrInstructionIdPromiseType,
2235 IrInstructionIdSliceType,2183 IrInstructionIdSliceType,
2236 IrInstructionIdGlobalAsm,2184 IrInstructionIdGlobalAsm,
2237 IrInstructionIdAsm,2185 IrInstructionIdAsm,
...@@ -2329,26 +2277,10 @@ enum IrInstructionId {...@@ -2329,26 +2277,10 @@ enum IrInstructionId {
2329 IrInstructionIdErrorReturnTrace,2277 IrInstructionIdErrorReturnTrace,
2330 IrInstructionIdErrorUnion,2278 IrInstructionIdErrorUnion,
2331 IrInstructionIdCancel,2279 IrInstructionIdCancel,
2332 IrInstructionIdGetImplicitAllocator,
2333 IrInstructionIdCoroId,
2334 IrInstructionIdCoroAlloc,
2335 IrInstructionIdCoroSize,
2336 IrInstructionIdCoroBegin,
2337 IrInstructionIdCoroAllocFail,
2338 IrInstructionIdCoroSuspend,
2339 IrInstructionIdCoroEnd,
2340 IrInstructionIdCoroFree,
2341 IrInstructionIdCoroResume,
2342 IrInstructionIdCoroSave,
2343 IrInstructionIdCoroPromise,
2344 IrInstructionIdCoroAllocHelper,
2345 IrInstructionIdAtomicRmw,2280 IrInstructionIdAtomicRmw,
2346 IrInstructionIdAtomicLoad,2281 IrInstructionIdAtomicLoad,
2347 IrInstructionIdPromiseResultType,
2348 IrInstructionIdAwaitBookkeeping,
2349 IrInstructionIdSaveErrRetAddr,2282 IrInstructionIdSaveErrRetAddr,
2350 IrInstructionIdAddImplicitReturnType,2283 IrInstructionIdAddImplicitReturnType,
2351 IrInstructionIdMergeErrRetTraces,
2352 IrInstructionIdMarkErrRetTracePtr,2284 IrInstructionIdMarkErrRetTracePtr,
2353 IrInstructionIdErrSetCast,2285 IrInstructionIdErrSetCast,
2354 IrInstructionIdToBytes,2286 IrInstructionIdToBytes,
...@@ -2606,7 +2538,6 @@ struct IrInstructionCallSrc {...@@ -2606,7 +2538,6 @@ struct IrInstructionCallSrc {
2606 IrInstruction **args;2538 IrInstruction **args;
2607 ResultLoc *result_loc;2539 ResultLoc *result_loc;
26082540
2609 IrInstruction *async_allocator;
2610 IrInstruction *new_stack;2541 IrInstruction *new_stack;
2611 FnInline fn_inline;2542 FnInline fn_inline;
2612 bool is_async;2543 bool is_async;
...@@ -2622,7 +2553,6 @@ struct IrInstructionCallGen {...@@ -2622,7 +2553,6 @@ struct IrInstructionCallGen {
2622 IrInstruction **args;2553 IrInstruction **args;
2623 IrInstruction *result_loc;2554 IrInstruction *result_loc;
26242555
2625 IrInstruction *async_allocator;
2626 IrInstruction *new_stack;2556 IrInstruction *new_stack;
2627 FnInline fn_inline;2557 FnInline fn_inline;
2628 bool is_async;2558 bool is_async;
...@@ -2743,12 +2673,6 @@ struct IrInstructionPtrType {...@@ -2743,12 +2673,6 @@ struct IrInstructionPtrType {
2743 bool is_allow_zero;2673 bool is_allow_zero;
2744};2674};
27452675
2746struct IrInstructionPromiseType {
2747 IrInstruction base;
2748
2749 IrInstruction *payload_type;
2750};
2751
2752struct IrInstructionSliceType {2676struct IrInstructionSliceType {
2753 IrInstruction base;2677 IrInstruction base;
27542678
...@@ -3178,7 +3102,6 @@ struct IrInstructionFnProto {...@@ -3178,7 +3102,6 @@ struct IrInstructionFnProto {
3178 IrInstruction **param_types;3102 IrInstruction **param_types;
3179 IrInstruction *align_value;3103 IrInstruction *align_value;
3180 IrInstruction *return_type;3104 IrInstruction *return_type;
3181 IrInstruction *async_allocator_type_value;
3182 bool is_var_args;3105 bool is_var_args;
3183};3106};
31843107
...@@ -3414,89 +3337,6 @@ struct IrInstructionCancel {...@@ -3414,89 +3337,6 @@ struct IrInstructionCancel {
3414 IrInstruction *target;3337 IrInstruction *target;
3415};3338};
34163339
3417enum ImplicitAllocatorId {
3418 ImplicitAllocatorIdArg,
3419 ImplicitAllocatorIdLocalVar,
3420};
3421
3422struct IrInstructionGetImplicitAllocator {
3423 IrInstruction base;
3424
3425 ImplicitAllocatorId id;
3426};
3427
3428struct IrInstructionCoroId {
3429 IrInstruction base;
3430
3431 IrInstruction *promise_ptr;
3432};
3433
3434struct IrInstructionCoroAlloc {
3435 IrInstruction base;
3436
3437 IrInstruction *coro_id;
3438};
3439
3440struct IrInstructionCoroSize {
3441 IrInstruction base;
3442};
3443
3444struct IrInstructionCoroBegin {
3445 IrInstruction base;
3446
3447 IrInstruction *coro_id;
3448 IrInstruction *coro_mem_ptr;
3449};
3450
3451struct IrInstructionCoroAllocFail {
3452 IrInstruction base;
3453
3454 IrInstruction *err_val;
3455};
3456
3457struct IrInstructionCoroSuspend {
3458 IrInstruction base;
3459
3460 IrInstruction *save_point;
3461 IrInstruction *is_final;
3462};
3463
3464struct IrInstructionCoroEnd {
3465 IrInstruction base;
3466};
3467
3468struct IrInstructionCoroFree {
3469 IrInstruction base;
3470
3471 IrInstruction *coro_id;
3472 IrInstruction *coro_handle;
3473};
3474
3475struct IrInstructionCoroResume {
3476 IrInstruction base;
3477
3478 IrInstruction *awaiter_handle;
3479};
3480
3481struct IrInstructionCoroSave {
3482 IrInstruction base;
3483
3484 IrInstruction *coro_handle;
3485};
3486
3487struct IrInstructionCoroPromise {
3488 IrInstruction base;
3489
3490 IrInstruction *coro_handle;
3491};
3492
3493struct IrInstructionCoroAllocHelper {
3494 IrInstruction base;
3495
3496 IrInstruction *realloc_fn;
3497 IrInstruction *coro_size;
3498};
3499
3500struct IrInstructionAtomicRmw {3340struct IrInstructionAtomicRmw {
3501 IrInstruction base;3341 IrInstruction base;
35023342
...@@ -3518,18 +3358,6 @@ struct IrInstructionAtomicLoad {...@@ -3518,18 +3358,6 @@ struct IrInstructionAtomicLoad {
3518 AtomicOrder resolved_ordering;3358 AtomicOrder resolved_ordering;
3519};3359};
35203360
3521struct IrInstructionPromiseResultType {
3522 IrInstruction base;
3523
3524 IrInstruction *promise_type;
3525};
3526
3527struct IrInstructionAwaitBookkeeping {
3528 IrInstruction base;
3529
3530 IrInstruction *promise_result_type;
3531};
3532
3533struct IrInstructionSaveErrRetAddr {3361struct IrInstructionSaveErrRetAddr {
3534 IrInstruction base;3362 IrInstruction base;
3535};3363};
...@@ -3540,14 +3368,6 @@ struct IrInstructionAddImplicitReturnType {...@@ -3540,14 +3368,6 @@ struct IrInstructionAddImplicitReturnType {
3540 IrInstruction *value;3368 IrInstruction *value;
3541};3369};
35423370
3543struct IrInstructionMergeErrRetTraces {
3544 IrInstruction base;
3545
3546 IrInstruction *coro_promise_ptr;
3547 IrInstruction *src_err_ret_trace_ptr;
3548 IrInstruction *dest_err_ret_trace_ptr;
3549};
3550
3551struct IrInstructionMarkErrRetTracePtr {3371struct IrInstructionMarkErrRetTracePtr {
3552 IrInstruction base;3372 IrInstruction base;
35533373
...@@ -3777,17 +3597,6 @@ static const size_t err_union_payload_index = 1;...@@ -3777,17 +3597,6 @@ static const size_t err_union_payload_index = 1;
3777// MUST BE A POWER OF TWO.3597// MUST BE A POWER OF TWO.
3778static const size_t stack_trace_ptr_count = 32;3598static const size_t stack_trace_ptr_count = 32;
37793599
3780// these belong to the async function
3781#define RETURN_ADDRESSES_FIELD_NAME "return_addresses"
3782#define ERR_RET_TRACE_FIELD_NAME "err_ret_trace"
3783#define RESULT_FIELD_NAME "result"
3784#define ASYNC_REALLOC_FIELD_NAME "reallocFn"
3785#define ASYNC_SHRINK_FIELD_NAME "shrinkFn"
3786#define ATOMIC_STATE_FIELD_NAME "atomic_state"
3787// these point to data belonging to the awaiter
3788#define ERR_RET_TRACE_PTR_FIELD_NAME "err_ret_trace_ptr"
3789#define RESULT_PTR_FIELD_NAME "result_ptr"
3790
3791#define NAMESPACE_SEP_CHAR '.'3600#define NAMESPACE_SEP_CHAR '.'
3792#define NAMESPACE_SEP_STR "."3601#define NAMESPACE_SEP_STR "."
37933602
src/analyze.cpp+14-158
...@@ -188,12 +188,6 @@ Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent) {...@@ -188,12 +188,6 @@ Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent) {
188 return &scope->base;188 return &scope->base;
189}189}
190190
191Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent) {
192 ScopeCoroPrelude *scope = allocate<ScopeCoroPrelude>(1);
193 init_scope(g, &scope->base, ScopeIdCoroPrelude, node, parent);
194 return &scope->base;
195}
196
197ZigType *get_scope_import(Scope *scope) {191ZigType *get_scope_import(Scope *scope) {
198 while (scope) {192 while (scope) {
199 if (scope->id == ScopeIdDecls) {193 if (scope->id == ScopeIdDecls) {
...@@ -254,7 +248,6 @@ AstNode *type_decl_node(ZigType *type_entry) {...@@ -254,7 +248,6 @@ AstNode *type_decl_node(ZigType *type_entry) {
254 case ZigTypeIdFn:248 case ZigTypeIdFn:
255 case ZigTypeIdBoundFn:249 case ZigTypeIdBoundFn:
256 case ZigTypeIdArgTuple:250 case ZigTypeIdArgTuple:
257 case ZigTypeIdPromise:
258 case ZigTypeIdVector:251 case ZigTypeIdVector:
259 return nullptr;252 return nullptr;
260 }253 }
...@@ -307,7 +300,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {...@@ -307,7 +300,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
307 case ZigTypeIdFn:300 case ZigTypeIdFn:
308 case ZigTypeIdBoundFn:301 case ZigTypeIdBoundFn:
309 case ZigTypeIdArgTuple:302 case ZigTypeIdArgTuple:
310 case ZigTypeIdPromise:
311 case ZigTypeIdVector:303 case ZigTypeIdVector:
312 return true;304 return true;
313 }305 }
...@@ -341,31 +333,6 @@ ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {...@@ -341,31 +333,6 @@ ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {
341 return get_int_type(g, false, bits_needed_for_unsigned(x));333 return get_int_type(g, false, bits_needed_for_unsigned(x));
342}334}
343335
344ZigType *get_promise_type(CodeGen *g, ZigType *result_type) {
345 if (result_type != nullptr && result_type->promise_parent != nullptr) {
346 return result_type->promise_parent;
347 } else if (result_type == nullptr && g->builtin_types.entry_promise != nullptr) {
348 return g->builtin_types.entry_promise;
349 }
350
351 ZigType *entry = new_type_table_entry(ZigTypeIdPromise);
352 entry->abi_size = g->builtin_types.entry_usize->abi_size;
353 entry->size_in_bits = g->builtin_types.entry_usize->size_in_bits;
354 entry->abi_align = g->builtin_types.entry_usize->abi_align;
355 entry->data.promise.result_type = result_type;
356 buf_init_from_str(&entry->name, "promise");
357 if (result_type != nullptr) {
358 buf_appendf(&entry->name, "->%s", buf_ptr(&result_type->name));
359 }
360
361 if (result_type != nullptr) {
362 result_type->promise_parent = entry;
363 } else if (result_type == nullptr) {
364 g->builtin_types.entry_promise = entry;
365 }
366 return entry;
367}
368
369static const char *ptr_len_to_star_str(PtrLen ptr_len) {336static const char *ptr_len_to_star_str(PtrLen ptr_len) {
370 switch (ptr_len) {337 switch (ptr_len) {
371 case PtrLenSingle:338 case PtrLenSingle:
...@@ -490,42 +457,6 @@ ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const) {...@@ -490,42 +457,6 @@ ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const) {
490 return get_pointer_to_type_extra(g, child_type, is_const, false, PtrLenSingle, 0, 0, 0, false);457 return get_pointer_to_type_extra(g, child_type, is_const, false, PtrLenSingle, 0, 0, 0, false);
491}458}
492459
493ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type) {
494 if (return_type->promise_frame_parent != nullptr) {
495 return return_type->promise_frame_parent;
496 }
497
498 ZigType *atomic_state_type = g->builtin_types.entry_usize;
499 ZigType *result_ptr_type = get_pointer_to_type(g, return_type, false);
500
501 ZigList<const char *> field_names = {};
502 field_names.append(ATOMIC_STATE_FIELD_NAME);
503 field_names.append(RESULT_FIELD_NAME);
504 field_names.append(RESULT_PTR_FIELD_NAME);
505 if (g->have_err_ret_tracing) {
506 field_names.append(ERR_RET_TRACE_PTR_FIELD_NAME);
507 field_names.append(ERR_RET_TRACE_FIELD_NAME);
508 field_names.append(RETURN_ADDRESSES_FIELD_NAME);
509 }
510
511 ZigList<ZigType *> field_types = {};
512 field_types.append(atomic_state_type);
513 field_types.append(return_type);
514 field_types.append(result_ptr_type);
515 if (g->have_err_ret_tracing) {
516 field_types.append(get_ptr_to_stack_trace_type(g));
517 field_types.append(g->stack_trace_type);
518 field_types.append(get_array_type(g, g->builtin_types.entry_usize, stack_trace_ptr_count));
519 }
520
521 assert(field_names.length == field_types.length);
522 Buf *name = buf_sprintf("AsyncFramePromise(%s)", buf_ptr(&return_type->name));
523 ZigType *entry = get_struct_type(g, buf_ptr(name), field_names.items, field_types.items, field_names.length);
524
525 return_type->promise_frame_parent = entry;
526 return entry;
527}
528
529ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {460ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
530 if (child_type->optional_parent != nullptr) {461 if (child_type->optional_parent != nullptr) {
531 return child_type->optional_parent;462 return child_type->optional_parent;
...@@ -879,13 +810,8 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -879,13 +810,8 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
879810
880 // populate the name of the type811 // populate the name of the type
881 buf_resize(&fn_type->name, 0);812 buf_resize(&fn_type->name, 0);
882 if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {813 const char *cc_str = calling_convention_fn_type_str(fn_type->data.fn.fn_type_id.cc);
883 assert(fn_type_id->async_allocator_type != nullptr);814 buf_appendf(&fn_type->name, "%s", cc_str);
884 buf_appendf(&fn_type->name, "async<%s> ", buf_ptr(&fn_type_id->async_allocator_type->name));
885 } else {
886 const char *cc_str = calling_convention_fn_type_str(fn_type->data.fn.fn_type_id.cc);
887 buf_appendf(&fn_type->name, "%s", cc_str);
888 }
889 buf_appendf(&fn_type->name, "fn(");815 buf_appendf(&fn_type->name, "fn(");
890 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {816 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
891 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];817 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
...@@ -998,14 +924,8 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {...@@ -998,14 +924,8 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
998ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {924ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
999 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);925 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
1000 buf_resize(&fn_type->name, 0);926 buf_resize(&fn_type->name, 0);
1001 if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {927 const char *cc_str = calling_convention_fn_type_str(fn_type->data.fn.fn_type_id.cc);
1002 const char *async_allocator_type_str = (fn_type->data.fn.fn_type_id.async_allocator_type == nullptr) ?928 buf_appendf(&fn_type->name, "%s", cc_str);
1003 "var" : buf_ptr(&fn_type_id->async_allocator_type->name);
1004 buf_appendf(&fn_type->name, "async(%s) ", async_allocator_type_str);
1005 } else {
1006 const char *cc_str = calling_convention_fn_type_str(fn_type->data.fn.fn_type_id.cc);
1007 buf_appendf(&fn_type->name, "%s", cc_str);
1008 }
1009 buf_appendf(&fn_type->name, "fn(");929 buf_appendf(&fn_type->name, "fn(");
1010 size_t i = 0;930 size_t i = 0;
1011 for (; i < fn_type_id->next_param_index; i += 1) {931 for (; i < fn_type_id->next_param_index; i += 1) {
...@@ -1119,7 +1039,6 @@ static Error emit_error_unless_type_allowed_in_packed_struct(CodeGen *g, ZigType...@@ -1119,7 +1039,6 @@ static Error emit_error_unless_type_allowed_in_packed_struct(CodeGen *g, ZigType
1119 case ZigTypeIdBoundFn:1039 case ZigTypeIdBoundFn:
1120 case ZigTypeIdArgTuple:1040 case ZigTypeIdArgTuple:
1121 case ZigTypeIdOpaque:1041 case ZigTypeIdOpaque:
1122 case ZigTypeIdPromise:
1123 add_node_error(g, source_node,1042 add_node_error(g, source_node,
1124 buf_sprintf("type '%s' not allowed in packed struct; no guaranteed in-memory representation",1043 buf_sprintf("type '%s' not allowed in packed struct; no guaranteed in-memory representation",
1125 buf_ptr(&type_entry->name)));1044 buf_ptr(&type_entry->name)));
...@@ -1207,7 +1126,6 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {...@@ -1207,7 +1126,6 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
1207 case ZigTypeIdErrorSet:1126 case ZigTypeIdErrorSet:
1208 case ZigTypeIdBoundFn:1127 case ZigTypeIdBoundFn:
1209 case ZigTypeIdArgTuple:1128 case ZigTypeIdArgTuple:
1210 case ZigTypeIdPromise:
1211 case ZigTypeIdVoid:1129 case ZigTypeIdVoid:
1212 return false;1130 return false;
1213 case ZigTypeIdOpaque:1131 case ZigTypeIdOpaque:
...@@ -1378,7 +1296,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1378,7 +1296,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1378 case ZigTypeIdEnum:1296 case ZigTypeIdEnum:
1379 case ZigTypeIdUnion:1297 case ZigTypeIdUnion:
1380 case ZigTypeIdFn:1298 case ZigTypeIdFn:
1381 case ZigTypeIdPromise:
1382 case ZigTypeIdVector:1299 case ZigTypeIdVector:
1383 switch (type_requires_comptime(g, type_entry)) {1300 switch (type_requires_comptime(g, type_entry)) {
1384 case ReqCompTimeNo:1301 case ReqCompTimeNo:
...@@ -1474,7 +1391,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1474,7 +1391,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1474 case ZigTypeIdEnum:1391 case ZigTypeIdEnum:
1475 case ZigTypeIdUnion:1392 case ZigTypeIdUnion:
1476 case ZigTypeIdFn:1393 case ZigTypeIdFn:
1477 case ZigTypeIdPromise:
1478 case ZigTypeIdVector:1394 case ZigTypeIdVector:
1479 switch (type_requires_comptime(g, fn_type_id.return_type)) {1395 switch (type_requires_comptime(g, fn_type_id.return_type)) {
1480 case ReqCompTimeInvalid:1396 case ReqCompTimeInvalid:
...@@ -1487,16 +1403,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -1487,16 +1403,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
1487 break;1403 break;
1488 }1404 }
14891405
1490 if (fn_type_id.cc == CallingConventionAsync) {
1491 if (fn_proto->async_allocator_type == nullptr) {
1492 return get_generic_fn_type(g, &fn_type_id);
1493 }
1494 fn_type_id.async_allocator_type = analyze_type_expr(g, child_scope, fn_proto->async_allocator_type);
1495 if (type_is_invalid(fn_type_id.async_allocator_type)) {
1496 return g->builtin_types.entry_invalid;
1497 }
1498 }
1499
1500 return get_fn_type(g, &fn_type_id);1406 return get_fn_type(g, &fn_type_id);
1501}1407}
15021408
...@@ -3039,7 +2945,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -3039,7 +2945,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
3039 case NodeTypeResume:2945 case NodeTypeResume:
3040 case NodeTypeAwaitExpr:2946 case NodeTypeAwaitExpr:
3041 case NodeTypeSuspend:2947 case NodeTypeSuspend:
3042 case NodeTypePromiseType:
3043 case NodeTypeEnumLiteral:2948 case NodeTypeEnumLiteral:
3044 zig_unreachable();2949 zig_unreachable();
3045 }2950 }
...@@ -3091,7 +2996,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry...@@ -3091,7 +2996,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
3091 case ZigTypeIdUnion:2996 case ZigTypeIdUnion:
3092 case ZigTypeIdFn:2997 case ZigTypeIdFn:
3093 case ZigTypeIdBoundFn:2998 case ZigTypeIdBoundFn:
3094 case ZigTypeIdPromise:
3095 case ZigTypeIdVector:2999 case ZigTypeIdVector:
3096 return type_entry;3000 return type_entry;
3097 }3001 }
...@@ -3591,7 +3495,6 @@ bool is_container(ZigType *type_entry) {...@@ -3591,7 +3495,6 @@ bool is_container(ZigType *type_entry) {
3591 case ZigTypeIdBoundFn:3495 case ZigTypeIdBoundFn:
3592 case ZigTypeIdArgTuple:3496 case ZigTypeIdArgTuple:
3593 case ZigTypeIdOpaque:3497 case ZigTypeIdOpaque:
3594 case ZigTypeIdPromise:
3595 case ZigTypeIdVector:3498 case ZigTypeIdVector:
3596 return false;3499 return false;
3597 }3500 }
...@@ -3648,7 +3551,6 @@ Error resolve_container_type(CodeGen *g, ZigType *type_entry) {...@@ -3648,7 +3551,6 @@ Error resolve_container_type(CodeGen *g, ZigType *type_entry) {
3648 case ZigTypeIdInvalid:3551 case ZigTypeIdInvalid:
3649 case ZigTypeIdArgTuple:3552 case ZigTypeIdArgTuple:
3650 case ZigTypeIdOpaque:3553 case ZigTypeIdOpaque:
3651 case ZigTypeIdPromise:
3652 case ZigTypeIdVector:3554 case ZigTypeIdVector:
3653 zig_unreachable();3555 zig_unreachable();
3654 }3556 }
...@@ -3658,13 +3560,11 @@ Error resolve_container_type(CodeGen *g, ZigType *type_entry) {...@@ -3658,13 +3560,11 @@ Error resolve_container_type(CodeGen *g, ZigType *type_entry) {
3658ZigType *get_src_ptr_type(ZigType *type) {3560ZigType *get_src_ptr_type(ZigType *type) {
3659 if (type->id == ZigTypeIdPointer) return type;3561 if (type->id == ZigTypeIdPointer) return type;
3660 if (type->id == ZigTypeIdFn) return type;3562 if (type->id == ZigTypeIdFn) return type;
3661 if (type->id == ZigTypeIdPromise) return type;
3662 if (type->id == ZigTypeIdOptional) {3563 if (type->id == ZigTypeIdOptional) {
3663 if (type->data.maybe.child_type->id == ZigTypeIdPointer) {3564 if (type->data.maybe.child_type->id == ZigTypeIdPointer) {
3664 return type->data.maybe.child_type->data.pointer.allow_zero ? nullptr : type->data.maybe.child_type;3565 return type->data.maybe.child_type->data.pointer.allow_zero ? nullptr : type->data.maybe.child_type;
3665 }3566 }
3666 if (type->data.maybe.child_type->id == ZigTypeIdFn) return type->data.maybe.child_type;3567 if (type->data.maybe.child_type->id == ZigTypeIdFn) return type->data.maybe.child_type;
3667 if (type->data.maybe.child_type->id == ZigTypeIdPromise) return type->data.maybe.child_type;
3668 }3568 }
3669 return nullptr;3569 return nullptr;
3670}3570}
...@@ -3691,8 +3591,6 @@ uint32_t get_ptr_align(CodeGen *g, ZigType *type) {...@@ -3691,8 +3591,6 @@ uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
3691 // when getting the alignment of `?extern fn() void`.3591 // when getting the alignment of `?extern fn() void`.
3692 // See http://lists.llvm.org/pipermail/llvm-dev/2018-September/126142.html3592 // See http://lists.llvm.org/pipermail/llvm-dev/2018-September/126142.html
3693 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;3593 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;
3694 } else if (ptr_type->id == ZigTypeIdPromise) {
3695 return get_coro_frame_align_bytes(g);
3696 } else {3594 } else {
3697 zig_unreachable();3595 zig_unreachable();
3698 }3596 }
...@@ -3704,8 +3602,6 @@ bool get_ptr_const(ZigType *type) {...@@ -3704,8 +3602,6 @@ bool get_ptr_const(ZigType *type) {
3704 return ptr_type->data.pointer.is_const;3602 return ptr_type->data.pointer.is_const;
3705 } else if (ptr_type->id == ZigTypeIdFn) {3603 } else if (ptr_type->id == ZigTypeIdFn) {
3706 return true;3604 return true;
3707 } else if (ptr_type->id == ZigTypeIdPromise) {
3708 return true;
3709 } else {3605 } else {
3710 zig_unreachable();3606 zig_unreachable();
3711 }3607 }
...@@ -4102,7 +3998,6 @@ bool handle_is_ptr(ZigType *type_entry) {...@@ -4102,7 +3998,6 @@ bool handle_is_ptr(ZigType *type_entry) {
4102 case ZigTypeIdErrorSet:3998 case ZigTypeIdErrorSet:
4103 case ZigTypeIdFn:3999 case ZigTypeIdFn:
4104 case ZigTypeIdEnum:4000 case ZigTypeIdEnum:
4105 case ZigTypeIdPromise:
4106 case ZigTypeIdVector:4001 case ZigTypeIdVector:
4107 return false;4002 return false;
4108 case ZigTypeIdArray:4003 case ZigTypeIdArray:
...@@ -4142,7 +4037,6 @@ uint32_t fn_type_id_hash(FnTypeId *id) {...@@ -4142,7 +4037,6 @@ uint32_t fn_type_id_hash(FnTypeId *id) {
4142 result += ((uint32_t)(id->cc)) * (uint32_t)3349388391;4037 result += ((uint32_t)(id->cc)) * (uint32_t)3349388391;
4143 result += id->is_var_args ? (uint32_t)1931444534 : 0;4038 result += id->is_var_args ? (uint32_t)1931444534 : 0;
4144 result += hash_ptr(id->return_type);4039 result += hash_ptr(id->return_type);
4145 result += hash_ptr(id->async_allocator_type);
4146 result += id->alignment * 0xd3b3f3e2;4040 result += id->alignment * 0xd3b3f3e2;
4147 for (size_t i = 0; i < id->param_count; i += 1) {4041 for (size_t i = 0; i < id->param_count; i += 1) {
4148 FnTypeParamInfo *info = &id->param_info[i];4042 FnTypeParamInfo *info = &id->param_info[i];
...@@ -4157,8 +4051,7 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {...@@ -4157,8 +4051,7 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {
4157 a->return_type != b->return_type ||4051 a->return_type != b->return_type ||
4158 a->is_var_args != b->is_var_args ||4052 a->is_var_args != b->is_var_args ||
4159 a->param_count != b->param_count ||4053 a->param_count != b->param_count ||
4160 a->alignment != b->alignment ||4054 a->alignment != b->alignment)
4161 a->async_allocator_type != b->async_allocator_type)
4162 {4055 {
4163 return false;4056 return false;
4164 }4057 }
...@@ -4320,9 +4213,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4320,9 +4213,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4320 return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);4213 return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);
4321 case ZigTypeIdPointer:4214 case ZigTypeIdPointer:
4322 return hash_const_val_ptr(const_val);4215 return hash_const_val_ptr(const_val);
4323 case ZigTypeIdPromise:
4324 // TODO better hashing algorithm
4325 return 223048345;
4326 case ZigTypeIdUndefined:4216 case ZigTypeIdUndefined:
4327 return 162837799;4217 return 162837799;
4328 case ZigTypeIdNull:4218 case ZigTypeIdNull:
...@@ -4418,7 +4308,6 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {...@@ -4418,7 +4308,6 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
4418 case ZigTypeIdBoundFn:4308 case ZigTypeIdBoundFn:
4419 case ZigTypeIdFn:4309 case ZigTypeIdFn:
4420 case ZigTypeIdOpaque:4310 case ZigTypeIdOpaque:
4421 case ZigTypeIdPromise:
4422 case ZigTypeIdErrorSet:4311 case ZigTypeIdErrorSet:
4423 case ZigTypeIdEnum:4312 case ZigTypeIdEnum:
4424 return false;4313 return false;
...@@ -4488,7 +4377,6 @@ static bool return_type_is_cacheable(ZigType *return_type) {...@@ -4488,7 +4377,6 @@ static bool return_type_is_cacheable(ZigType *return_type) {
4488 case ZigTypeIdBoundFn:4377 case ZigTypeIdBoundFn:
4489 case ZigTypeIdFn:4378 case ZigTypeIdFn:
4490 case ZigTypeIdOpaque:4379 case ZigTypeIdOpaque:
4491 case ZigTypeIdPromise:
4492 case ZigTypeIdErrorSet:4380 case ZigTypeIdErrorSet:
4493 case ZigTypeIdEnum:4381 case ZigTypeIdEnum:
4494 case ZigTypeIdPointer:4382 case ZigTypeIdPointer:
...@@ -4623,7 +4511,6 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -4623,7 +4511,6 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
4623 case ZigTypeIdFn:4511 case ZigTypeIdFn:
4624 case ZigTypeIdBool:4512 case ZigTypeIdBool:
4625 case ZigTypeIdFloat:4513 case ZigTypeIdFloat:
4626 case ZigTypeIdPromise:
4627 case ZigTypeIdErrorUnion:4514 case ZigTypeIdErrorUnion:
4628 return OnePossibleValueNo;4515 return OnePossibleValueNo;
4629 case ZigTypeIdUndefined:4516 case ZigTypeIdUndefined:
...@@ -4712,7 +4599,6 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry) {...@@ -4712,7 +4599,6 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry) {
4712 case ZigTypeIdFloat:4599 case ZigTypeIdFloat:
4713 case ZigTypeIdVoid:4600 case ZigTypeIdVoid:
4714 case ZigTypeIdUnreachable:4601 case ZigTypeIdUnreachable:
4715 case ZigTypeIdPromise:
4716 return ReqCompTimeNo;4602 return ReqCompTimeNo;
4717 }4603 }
4718 zig_unreachable();4604 zig_unreachable();
...@@ -5278,7 +5164,6 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {...@@ -5278,7 +5164,6 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
5278 case ZigTypeIdBoundFn:5164 case ZigTypeIdBoundFn:
5279 case ZigTypeIdInvalid:5165 case ZigTypeIdInvalid:
5280 case ZigTypeIdUnreachable:5166 case ZigTypeIdUnreachable:
5281 case ZigTypeIdPromise:
5282 zig_unreachable();5167 zig_unreachable();
5283 }5168 }
5284 zig_unreachable();5169 zig_unreachable();
...@@ -5611,8 +5496,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5611,8 +5496,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5611 buf_appendf(buf, "(args value)");5496 buf_appendf(buf, "(args value)");
5612 return;5497 return;
5613 }5498 }
5614 case ZigTypeIdPromise:
5615 zig_unreachable();
5616 }5499 }
5617 zig_unreachable();5500 zig_unreachable();
5618}5501}
...@@ -5659,7 +5542,6 @@ uint32_t type_id_hash(TypeId x) {...@@ -5659,7 +5542,6 @@ uint32_t type_id_hash(TypeId x) {
5659 case ZigTypeIdFn:5542 case ZigTypeIdFn:
5660 case ZigTypeIdBoundFn:5543 case ZigTypeIdBoundFn:
5661 case ZigTypeIdArgTuple:5544 case ZigTypeIdArgTuple:
5662 case ZigTypeIdPromise:
5663 zig_unreachable();5545 zig_unreachable();
5664 case ZigTypeIdErrorUnion:5546 case ZigTypeIdErrorUnion:
5665 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);5547 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);
...@@ -5701,7 +5583,6 @@ bool type_id_eql(TypeId a, TypeId b) {...@@ -5701,7 +5583,6 @@ bool type_id_eql(TypeId a, TypeId b) {
5701 case ZigTypeIdUndefined:5583 case ZigTypeIdUndefined:
5702 case ZigTypeIdNull:5584 case ZigTypeIdNull:
5703 case ZigTypeIdOptional:5585 case ZigTypeIdOptional:
5704 case ZigTypeIdPromise:
5705 case ZigTypeIdErrorSet:5586 case ZigTypeIdErrorSet:
5706 case ZigTypeIdEnum:5587 case ZigTypeIdEnum:
5707 case ZigTypeIdUnion:5588 case ZigTypeIdUnion:
...@@ -5874,7 +5755,6 @@ static const ZigTypeId all_type_ids[] = {...@@ -5874,7 +5755,6 @@ static const ZigTypeId all_type_ids[] = {
5874 ZigTypeIdBoundFn,5755 ZigTypeIdBoundFn,
5875 ZigTypeIdArgTuple,5756 ZigTypeIdArgTuple,
5876 ZigTypeIdOpaque,5757 ZigTypeIdOpaque,
5877 ZigTypeIdPromise,
5878 ZigTypeIdVector,5758 ZigTypeIdVector,
5879 ZigTypeIdEnumLiteral,5759 ZigTypeIdEnumLiteral,
5880};5760};
...@@ -5938,12 +5818,10 @@ size_t type_id_index(ZigType *entry) {...@@ -5938,12 +5818,10 @@ size_t type_id_index(ZigType *entry) {
5938 return 20;5818 return 20;
5939 case ZigTypeIdOpaque:5819 case ZigTypeIdOpaque:
5940 return 21;5820 return 21;
5941 case ZigTypeIdPromise:
5942 return 22;
5943 case ZigTypeIdVector:5821 case ZigTypeIdVector:
5944 return 23;5822 return 22;
5945 case ZigTypeIdEnumLiteral:5823 case ZigTypeIdEnumLiteral:
5946 return 24;5824 return 23;
5947 }5825 }
5948 zig_unreachable();5826 zig_unreachable();
5949}5827}
...@@ -5998,8 +5876,6 @@ const char *type_id_name(ZigTypeId id) {...@@ -5998,8 +5876,6 @@ const char *type_id_name(ZigTypeId id) {
5998 return "ArgTuple";5876 return "ArgTuple";
5999 case ZigTypeIdOpaque:5877 case ZigTypeIdOpaque:
6000 return "Opaque";5878 return "Opaque";
6001 case ZigTypeIdPromise:
6002 return "Promise";
6003 case ZigTypeIdVector:5879 case ZigTypeIdVector:
6004 return "Vector";5880 return "Vector";
6005 }5881 }
...@@ -6066,13 +5942,6 @@ bool type_is_global_error_set(ZigType *err_set_type) {...@@ -6066,13 +5942,6 @@ bool type_is_global_error_set(ZigType *err_set_type) {
6066 return err_set_type->data.error_set.err_count == UINT32_MAX;5942 return err_set_type->data.error_set.err_count == UINT32_MAX;
6067}5943}
60685944
6069uint32_t get_coro_frame_align_bytes(CodeGen *g) {
6070 uint32_t a = g->pointer_size_bytes * 2;
6071 // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw
6072 if (a < 8) a = 8;
6073 return a;
6074}
6075
6076bool type_can_fail(ZigType *type_entry) {5945bool type_can_fail(ZigType *type_entry) {
6077 return type_entry->id == ZigTypeIdErrorUnion || type_entry->id == ZigTypeIdErrorSet;5946 return type_entry->id == ZigTypeIdErrorUnion || type_entry->id == ZigTypeIdErrorSet;
6078}5947}
...@@ -7105,19 +6974,13 @@ static void resolve_llvm_types_fn(CodeGen *g, ZigType *fn_type) {...@@ -7105,19 +6974,13 @@ static void resolve_llvm_types_fn(CodeGen *g, ZigType *fn_type) {
7105 param_di_types.append(get_llvm_di_type(g, gen_type));6974 param_di_types.append(get_llvm_di_type(g, gen_type));
7106 }6975 }
7107 if (is_async) {6976 if (is_async) {
7108 {6977 // coroutine frame pointer
7109 // async allocator param6978 // TODO if we can make this typed a little more it will be better for
7110 ZigType *gen_type = fn_type_id->async_allocator_type;6979 // debug symbols.
7111 gen_param_types.append(get_llvm_type(g, gen_type));6980 // TODO do we need to make this aligned more?
7112 param_di_types.append(get_llvm_di_type(g, gen_type));6981 ZigType *void_star = get_pointer_to_type(g, g->builtin_types.entry_c_void, false);
7113 }6982 gen_param_types.append(get_llvm_type(g, void_star));
71146983 param_di_types.append(get_llvm_di_type(g, void_star));
7115 {
7116 // error code pointer
7117 ZigType *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
7118 gen_param_types.append(get_llvm_type(g, gen_type));
7119 param_di_types.append(get_llvm_di_type(g, gen_type));
7120 }
7121 }6984 }
71226985
7123 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);6986 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);
...@@ -7224,13 +7087,6 @@ static void resolve_llvm_types(CodeGen *g, ZigType *type, ResolveStatus wanted_r...@@ -7224,13 +7087,6 @@ static void resolve_llvm_types(CodeGen *g, ZigType *type, ResolveStatus wanted_r
7224 return resolve_llvm_types_union(g, type, wanted_resolve_status);7087 return resolve_llvm_types_union(g, type, wanted_resolve_status);
7225 case ZigTypeIdPointer:7088 case ZigTypeIdPointer:
7226 return resolve_llvm_types_pointer(g, type);7089 return resolve_llvm_types_pointer(g, type);
7227 case ZigTypeIdPromise: {
7228 if (type->llvm_di_type != nullptr) return;
7229 ZigType *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
7230 type->llvm_type = get_llvm_type(g, u8_ptr_type);
7231 type->llvm_di_type = get_llvm_di_type(g, u8_ptr_type);
7232 return;
7233 }
7234 case ZigTypeIdInt:7090 case ZigTypeIdInt:
7235 return resolve_llvm_types_integer(g, type);7091 return resolve_llvm_types_integer(g, type);
7236 case ZigTypeIdOptional:7092 case ZigTypeIdOptional:
src/analyze.hpp-4
...@@ -39,8 +39,6 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);...@@ -39,8 +39,6 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);
39ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *full_name, Buf *bare_name);39ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *full_name, Buf *bare_name);
40ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],40ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
41 ZigType *field_types[], size_t field_count);41 ZigType *field_types[], size_t field_count);
42ZigType *get_promise_type(CodeGen *g, ZigType *result_type);
43ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type);
44ZigType *get_test_fn_type(CodeGen *g);42ZigType *get_test_fn_type(CodeGen *g);
45bool handle_is_ptr(ZigType *type_entry);43bool handle_is_ptr(ZigType *type_entry);
4644
...@@ -117,7 +115,6 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);...@@ -117,7 +115,6 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);
117ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);115ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);
118ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);116ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);
119Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);117Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);
120Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent);
121Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime);118Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime);
122119
123void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);120void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);
...@@ -204,7 +201,6 @@ bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *sour...@@ -204,7 +201,6 @@ bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *sour
204201
205ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry);202ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry);
206203
207uint32_t get_coro_frame_align_bytes(CodeGen *g);
208bool fn_type_can_fail(FnTypeId *fn_type_id);204bool fn_type_can_fail(FnTypeId *fn_type_id);
209bool type_can_fail(ZigType *type_entry);205bool type_can_fail(ZigType *type_entry);
210bool fn_eval_cacheable(Scope *scope, ZigType *return_type);206bool fn_eval_cacheable(Scope *scope, ZigType *return_type);
src/ast_render.cpp+1-18
...@@ -257,8 +257,6 @@ static const char *node_type_str(NodeType node_type) {...@@ -257,8 +257,6 @@ static const char *node_type_str(NodeType node_type) {
257 return "AwaitExpr";257 return "AwaitExpr";
258 case NodeTypeSuspend:258 case NodeTypeSuspend:
259 return "Suspend";259 return "Suspend";
260 case NodeTypePromiseType:
261 return "PromiseType";
262 case NodeTypePointerType:260 case NodeTypePointerType:
263 return "PointerType";261 return "PointerType";
264 case NodeTypeEnumLiteral:262 case NodeTypeEnumLiteral:
...@@ -692,13 +690,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -692,13 +690,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
692 fprintf(ar->f, "@");690 fprintf(ar->f, "@");
693 }691 }
694 if (node->data.fn_call_expr.is_async) {692 if (node->data.fn_call_expr.is_async) {
695 fprintf(ar->f, "async");693 fprintf(ar->f, "async ");
696 if (node->data.fn_call_expr.async_allocator != nullptr) {
697 fprintf(ar->f, "<");
698 render_node_extra(ar, node->data.fn_call_expr.async_allocator, true);
699 fprintf(ar->f, ">");
700 }
701 fprintf(ar->f, " ");
702 }694 }
703 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;695 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;
704 bool grouped = (fn_ref_node->type != NodeTypePrefixOpExpr && fn_ref_node->type != NodeTypePointerType);696 bool grouped = (fn_ref_node->type != NodeTypePrefixOpExpr && fn_ref_node->type != NodeTypePointerType);
...@@ -855,15 +847,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -855,15 +847,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
855 render_node_ungrouped(ar, node->data.inferred_array_type.child_type);847 render_node_ungrouped(ar, node->data.inferred_array_type.child_type);
856 break;848 break;
857 }849 }
858 case NodeTypePromiseType:
859 {
860 fprintf(ar->f, "promise");
861 if (node->data.promise_type.payload_type != nullptr) {
862 fprintf(ar->f, "->");
863 render_node_grouped(ar, node->data.promise_type.payload_type);
864 }
865 break;
866 }
867 case NodeTypeErrorType:850 case NodeTypeErrorType:
868 fprintf(ar->f, "anyerror");851 fprintf(ar->f, "anyerror");
869 break;852 break;
src/codegen.cpp+4-670
...@@ -721,7 +721,6 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {...@@ -721,7 +721,6 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
721 case ScopeIdLoop:721 case ScopeIdLoop:
722 case ScopeIdSuspend:722 case ScopeIdSuspend:
723 case ScopeIdCompTime:723 case ScopeIdCompTime:
724 case ScopeIdCoroPrelude:
725 case ScopeIdRuntime:724 case ScopeIdRuntime:
726 return get_di_scope(g, scope->parent);725 return get_di_scope(g, scope->parent);
727 }726 }
...@@ -1083,177 +1082,6 @@ static LLVMValueRef get_write_register_fn_val(CodeGen *g) {...@@ -1083,177 +1082,6 @@ static LLVMValueRef get_write_register_fn_val(CodeGen *g) {
1083 return g->write_register_fn_val;1082 return g->write_register_fn_val;
1084}1083}
10851084
1086static LLVMValueRef get_coro_destroy_fn_val(CodeGen *g) {
1087 if (g->coro_destroy_fn_val)
1088 return g->coro_destroy_fn_val;
1089
1090 LLVMTypeRef param_types[] = {
1091 LLVMPointerType(LLVMInt8Type(), 0),
1092 };
1093 LLVMTypeRef fn_type = LLVMFunctionType(LLVMVoidType(), param_types, 1, false);
1094 Buf *name = buf_sprintf("llvm.coro.destroy");
1095 g->coro_destroy_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1096 assert(LLVMGetIntrinsicID(g->coro_destroy_fn_val));
1097
1098 return g->coro_destroy_fn_val;
1099}
1100
1101static LLVMValueRef get_coro_id_fn_val(CodeGen *g) {
1102 if (g->coro_id_fn_val)
1103 return g->coro_id_fn_val;
1104
1105 LLVMTypeRef param_types[] = {
1106 LLVMInt32Type(),
1107 LLVMPointerType(LLVMInt8Type(), 0),
1108 LLVMPointerType(LLVMInt8Type(), 0),
1109 LLVMPointerType(LLVMInt8Type(), 0),
1110 };
1111 LLVMTypeRef fn_type = LLVMFunctionType(ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()), param_types, 4, false);
1112 Buf *name = buf_sprintf("llvm.coro.id");
1113 g->coro_id_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1114 assert(LLVMGetIntrinsicID(g->coro_id_fn_val));
1115
1116 return g->coro_id_fn_val;
1117}
1118
1119static LLVMValueRef get_coro_alloc_fn_val(CodeGen *g) {
1120 if (g->coro_alloc_fn_val)
1121 return g->coro_alloc_fn_val;
1122
1123 LLVMTypeRef param_types[] = {
1124 ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()),
1125 };
1126 LLVMTypeRef fn_type = LLVMFunctionType(LLVMInt1Type(), param_types, 1, false);
1127 Buf *name = buf_sprintf("llvm.coro.alloc");
1128 g->coro_alloc_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1129 assert(LLVMGetIntrinsicID(g->coro_alloc_fn_val));
1130
1131 return g->coro_alloc_fn_val;
1132}
1133
1134static LLVMValueRef get_coro_size_fn_val(CodeGen *g) {
1135 if (g->coro_size_fn_val)
1136 return g->coro_size_fn_val;
1137
1138 LLVMTypeRef fn_type = LLVMFunctionType(g->builtin_types.entry_usize->llvm_type, nullptr, 0, false);
1139 Buf *name = buf_sprintf("llvm.coro.size.i%d", g->pointer_size_bytes * 8);
1140 g->coro_size_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1141 assert(LLVMGetIntrinsicID(g->coro_size_fn_val));
1142
1143 return g->coro_size_fn_val;
1144}
1145
1146static LLVMValueRef get_coro_begin_fn_val(CodeGen *g) {
1147 if (g->coro_begin_fn_val)
1148 return g->coro_begin_fn_val;
1149
1150 LLVMTypeRef param_types[] = {
1151 ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()),
1152 LLVMPointerType(LLVMInt8Type(), 0),
1153 };
1154 LLVMTypeRef fn_type = LLVMFunctionType(LLVMPointerType(LLVMInt8Type(), 0), param_types, 2, false);
1155 Buf *name = buf_sprintf("llvm.coro.begin");
1156 g->coro_begin_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1157 assert(LLVMGetIntrinsicID(g->coro_begin_fn_val));
1158
1159 return g->coro_begin_fn_val;
1160}
1161
1162static LLVMValueRef get_coro_suspend_fn_val(CodeGen *g) {
1163 if (g->coro_suspend_fn_val)
1164 return g->coro_suspend_fn_val;
1165
1166 LLVMTypeRef param_types[] = {
1167 ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()),
1168 LLVMInt1Type(),
1169 };
1170 LLVMTypeRef fn_type = LLVMFunctionType(LLVMInt8Type(), param_types, 2, false);
1171 Buf *name = buf_sprintf("llvm.coro.suspend");
1172 g->coro_suspend_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1173 assert(LLVMGetIntrinsicID(g->coro_suspend_fn_val));
1174
1175 return g->coro_suspend_fn_val;
1176}
1177
1178static LLVMValueRef get_coro_end_fn_val(CodeGen *g) {
1179 if (g->coro_end_fn_val)
1180 return g->coro_end_fn_val;
1181
1182 LLVMTypeRef param_types[] = {
1183 LLVMPointerType(LLVMInt8Type(), 0),
1184 LLVMInt1Type(),
1185 };
1186 LLVMTypeRef fn_type = LLVMFunctionType(LLVMInt1Type(), param_types, 2, false);
1187 Buf *name = buf_sprintf("llvm.coro.end");
1188 g->coro_end_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1189 assert(LLVMGetIntrinsicID(g->coro_end_fn_val));
1190
1191 return g->coro_end_fn_val;
1192}
1193
1194static LLVMValueRef get_coro_free_fn_val(CodeGen *g) {
1195 if (g->coro_free_fn_val)
1196 return g->coro_free_fn_val;
1197
1198 LLVMTypeRef param_types[] = {
1199 ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()),
1200 LLVMPointerType(LLVMInt8Type(), 0),
1201 };
1202 LLVMTypeRef fn_type = LLVMFunctionType(LLVMPointerType(LLVMInt8Type(), 0), param_types, 2, false);
1203 Buf *name = buf_sprintf("llvm.coro.free");
1204 g->coro_free_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1205 assert(LLVMGetIntrinsicID(g->coro_free_fn_val));
1206
1207 return g->coro_free_fn_val;
1208}
1209
1210static LLVMValueRef get_coro_resume_fn_val(CodeGen *g) {
1211 if (g->coro_resume_fn_val)
1212 return g->coro_resume_fn_val;
1213
1214 LLVMTypeRef param_types[] = {
1215 LLVMPointerType(LLVMInt8Type(), 0),
1216 };
1217 LLVMTypeRef fn_type = LLVMFunctionType(LLVMVoidType(), param_types, 1, false);
1218 Buf *name = buf_sprintf("llvm.coro.resume");
1219 g->coro_resume_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1220 assert(LLVMGetIntrinsicID(g->coro_resume_fn_val));
1221
1222 return g->coro_resume_fn_val;
1223}
1224
1225static LLVMValueRef get_coro_save_fn_val(CodeGen *g) {
1226 if (g->coro_save_fn_val)
1227 return g->coro_save_fn_val;
1228
1229 LLVMTypeRef param_types[] = {
1230 LLVMPointerType(LLVMInt8Type(), 0),
1231 };
1232 LLVMTypeRef fn_type = LLVMFunctionType(ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()), param_types, 1, false);
1233 Buf *name = buf_sprintf("llvm.coro.save");
1234 g->coro_save_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1235 assert(LLVMGetIntrinsicID(g->coro_save_fn_val));
1236
1237 return g->coro_save_fn_val;
1238}
1239
1240static LLVMValueRef get_coro_promise_fn_val(CodeGen *g) {
1241 if (g->coro_promise_fn_val)
1242 return g->coro_promise_fn_val;
1243
1244 LLVMTypeRef param_types[] = {
1245 LLVMPointerType(LLVMInt8Type(), 0),
1246 LLVMInt32Type(),
1247 LLVMInt1Type(),
1248 };
1249 LLVMTypeRef fn_type = LLVMFunctionType(LLVMPointerType(LLVMInt8Type(), 0), param_types, 3, false);
1250 Buf *name = buf_sprintf("llvm.coro.promise");
1251 g->coro_promise_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1252 assert(LLVMGetIntrinsicID(g->coro_promise_fn_val));
1253
1254 return g->coro_promise_fn_val;
1255}
1256
1257static LLVMValueRef get_return_address_fn_val(CodeGen *g) {1085static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
1258 if (g->return_address_fn_val)1086 if (g->return_address_fn_val)
1259 return g->return_address_fn_val;1087 return g->return_address_fn_val;
...@@ -1346,140 +1174,6 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {...@@ -1346,140 +1174,6 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
1346 return fn_val;1174 return fn_val;
1347}1175}
13481176
1349static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
1350 if (g->merge_err_ret_traces_fn_val)
1351 return g->merge_err_ret_traces_fn_val;
1352
1353 assert(g->stack_trace_type != nullptr);
1354
1355 LLVMTypeRef param_types[] = {
1356 get_llvm_type(g, get_ptr_to_stack_trace_type(g)),
1357 get_llvm_type(g, get_ptr_to_stack_trace_type(g)),
1358 };
1359 LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMVoidType(), param_types, 2, false);
1360
1361 Buf *fn_name = get_mangled_name(g, buf_create_from_str("__zig_merge_error_return_traces"), false);
1362 LLVMValueRef fn_val = LLVMAddFunction(g->module, buf_ptr(fn_name), fn_type_ref);
1363 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
1364 LLVMSetFunctionCallConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
1365 addLLVMFnAttr(fn_val, "nounwind");
1366 add_uwtable_attr(g, fn_val);
1367 // Error return trace memory is in the stack, which is impossible to be at address 0
1368 // on any architecture.
1369 addLLVMArgAttr(fn_val, (unsigned)0, "nonnull");
1370 addLLVMArgAttr(fn_val, (unsigned)0, "noalias");
1371 addLLVMArgAttr(fn_val, (unsigned)0, "writeonly");
1372 // Error return trace memory is in the stack, which is impossible to be at address 0
1373 // on any architecture.
1374 addLLVMArgAttr(fn_val, (unsigned)1, "nonnull");
1375 addLLVMArgAttr(fn_val, (unsigned)1, "noalias");
1376 addLLVMArgAttr(fn_val, (unsigned)1, "readonly");
1377 if (g->build_mode == BuildModeDebug) {
1378 ZigLLVMAddFunctionAttr(fn_val, "no-frame-pointer-elim", "true");
1379 ZigLLVMAddFunctionAttr(fn_val, "no-frame-pointer-elim-non-leaf", nullptr);
1380 }
1381
1382 // this is above the ZigLLVMClearCurrentDebugLocation
1383 LLVMValueRef add_error_return_trace_addr_fn_val = get_add_error_return_trace_addr_fn(g);
1384
1385 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");
1386 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);
1387 LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder);
1388 LLVMPositionBuilderAtEnd(g->builder, entry_block);
1389 ZigLLVMClearCurrentDebugLocation(g->builder);
1390
1391 // var frame_index: usize = undefined;
1392 // var frames_left: usize = undefined;
1393 // if (src_stack_trace.index < src_stack_trace.instruction_addresses.len) {
1394 // frame_index = 0;
1395 // frames_left = src_stack_trace.index;
1396 // if (frames_left == 0) return;
1397 // } else {
1398 // frame_index = (src_stack_trace.index + 1) % src_stack_trace.instruction_addresses.len;
1399 // frames_left = src_stack_trace.instruction_addresses.len;
1400 // }
1401 // while (true) {
1402 // __zig_add_err_ret_trace_addr(dest_stack_trace, src_stack_trace.instruction_addresses[frame_index]);
1403 // frames_left -= 1;
1404 // if (frames_left == 0) return;
1405 // frame_index = (frame_index + 1) % src_stack_trace.instruction_addresses.len;
1406 // }
1407 LLVMBasicBlockRef return_block = LLVMAppendBasicBlock(fn_val, "Return");
1408
1409 LLVMValueRef frame_index_ptr = LLVMBuildAlloca(g->builder, g->builtin_types.entry_usize->llvm_type, "frame_index");
1410 LLVMValueRef frames_left_ptr = LLVMBuildAlloca(g->builder, g->builtin_types.entry_usize->llvm_type, "frames_left");
1411
1412 LLVMValueRef dest_stack_trace_ptr = LLVMGetParam(fn_val, 0);
1413 LLVMValueRef src_stack_trace_ptr = LLVMGetParam(fn_val, 1);
1414
1415 size_t src_index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index;
1416 size_t src_addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index;
1417 LLVMValueRef src_index_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr,
1418 (unsigned)src_index_field_index, "");
1419 LLVMValueRef src_addresses_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr,
1420 (unsigned)src_addresses_field_index, "");
1421 ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry;
1422 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
1423 LLVMValueRef src_ptr_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)ptr_field_index, "");
1424 size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index;
1425 LLVMValueRef src_len_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)len_field_index, "");
1426 LLVMValueRef src_index_val = LLVMBuildLoad(g->builder, src_index_field_ptr, "");
1427 LLVMValueRef src_ptr_val = LLVMBuildLoad(g->builder, src_ptr_field_ptr, "");
1428 LLVMValueRef src_len_val = LLVMBuildLoad(g->builder, src_len_field_ptr, "");
1429 LLVMValueRef no_wrap_bit = LLVMBuildICmp(g->builder, LLVMIntULT, src_index_val, src_len_val, "");
1430 LLVMBasicBlockRef no_wrap_block = LLVMAppendBasicBlock(fn_val, "NoWrap");
1431 LLVMBasicBlockRef yes_wrap_block = LLVMAppendBasicBlock(fn_val, "YesWrap");
1432 LLVMBasicBlockRef loop_block = LLVMAppendBasicBlock(fn_val, "Loop");
1433 LLVMBuildCondBr(g->builder, no_wrap_bit, no_wrap_block, yes_wrap_block);
1434
1435 LLVMPositionBuilderAtEnd(g->builder, no_wrap_block);
1436 LLVMValueRef usize_zero = LLVMConstNull(g->builtin_types.entry_usize->llvm_type);
1437 LLVMBuildStore(g->builder, usize_zero, frame_index_ptr);
1438 LLVMBuildStore(g->builder, src_index_val, frames_left_ptr);
1439 LLVMValueRef frames_left_eq_zero_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, src_index_val, usize_zero, "");
1440 LLVMBuildCondBr(g->builder, frames_left_eq_zero_bit, return_block, loop_block);
1441
1442 LLVMPositionBuilderAtEnd(g->builder, yes_wrap_block);
1443 LLVMValueRef usize_one = LLVMConstInt(g->builtin_types.entry_usize->llvm_type, 1, false);
1444 LLVMValueRef plus_one = LLVMBuildNUWAdd(g->builder, src_index_val, usize_one, "");
1445 LLVMValueRef mod_len = LLVMBuildURem(g->builder, plus_one, src_len_val, "");
1446 LLVMBuildStore(g->builder, mod_len, frame_index_ptr);
1447 LLVMBuildStore(g->builder, src_len_val, frames_left_ptr);
1448 LLVMBuildBr(g->builder, loop_block);
1449
1450 LLVMPositionBuilderAtEnd(g->builder, loop_block);
1451 LLVMValueRef ptr_index = LLVMBuildLoad(g->builder, frame_index_ptr, "");
1452 LLVMValueRef addr_ptr = LLVMBuildInBoundsGEP(g->builder, src_ptr_val, &ptr_index, 1, "");
1453 LLVMValueRef this_addr_val = LLVMBuildLoad(g->builder, addr_ptr, "");
1454 LLVMValueRef args[] = {dest_stack_trace_ptr, this_addr_val};
1455 ZigLLVMBuildCall(g->builder, add_error_return_trace_addr_fn_val, args, 2, get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_FnInlineAlways, "");
1456 LLVMValueRef prev_frames_left = LLVMBuildLoad(g->builder, frames_left_ptr, "");
1457 LLVMValueRef new_frames_left = LLVMBuildNUWSub(g->builder, prev_frames_left, usize_one, "");
1458 LLVMValueRef done_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, new_frames_left, usize_zero, "");
1459 LLVMBasicBlockRef continue_block = LLVMAppendBasicBlock(fn_val, "Continue");
1460 LLVMBuildCondBr(g->builder, done_bit, return_block, continue_block);
1461
1462 LLVMPositionBuilderAtEnd(g->builder, return_block);
1463 LLVMBuildRetVoid(g->builder);
1464
1465 LLVMPositionBuilderAtEnd(g->builder, continue_block);
1466 LLVMBuildStore(g->builder, new_frames_left, frames_left_ptr);
1467 LLVMValueRef prev_index = LLVMBuildLoad(g->builder, frame_index_ptr, "");
1468 LLVMValueRef index_plus_one = LLVMBuildNUWAdd(g->builder, prev_index, usize_one, "");
1469 LLVMValueRef index_mod_len = LLVMBuildURem(g->builder, index_plus_one, src_len_val, "");
1470 LLVMBuildStore(g->builder, index_mod_len, frame_index_ptr);
1471 LLVMBuildBr(g->builder, loop_block);
1472
1473 LLVMPositionBuilderAtEnd(g->builder, prev_block);
1474 if (!g->strip_debug_symbols) {
1475 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);
1476 }
1477
1478 g->merge_err_ret_traces_fn_val = fn_val;
1479 return fn_val;
1480
1481}
1482
1483static LLVMValueRef get_return_err_fn(CodeGen *g) {1177static LLVMValueRef get_return_err_fn(CodeGen *g) {
1484 if (g->return_err_fn != nullptr)1178 if (g->return_err_fn != nullptr)
1485 return g->return_err_fn;1179 return g->return_err_fn;
...@@ -1667,24 +1361,12 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {...@@ -1667,24 +1361,12 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
1667 return fn_val;1361 return fn_val;
1668}1362}
16691363
1670static bool is_coro_prelude_scope(Scope *scope) {
1671 while (scope != nullptr) {
1672 if (scope->id == ScopeIdCoroPrelude) {
1673 return true;
1674 } else if (scope->id == ScopeIdFnDef) {
1675 break;
1676 }
1677 scope = scope->parent;
1678 }
1679 return false;
1680}
1681
1682static LLVMValueRef get_cur_err_ret_trace_val(CodeGen *g, Scope *scope) {1364static LLVMValueRef get_cur_err_ret_trace_val(CodeGen *g, Scope *scope) {
1683 if (!g->have_err_ret_tracing) {1365 if (!g->have_err_ret_tracing) {
1684 return nullptr;1366 return nullptr;
1685 }1367 }
1686 if (g->cur_fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync) {1368 if (g->cur_fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync) {
1687 return is_coro_prelude_scope(scope) ? g->cur_err_ret_trace_val_arg : g->cur_err_ret_trace_val_stack;1369 return g->cur_err_ret_trace_val_stack;
1688 }1370 }
1689 if (g->cur_err_ret_trace_val_stack != nullptr) {1371 if (g->cur_err_ret_trace_val_stack != nullptr) {
1690 return g->cur_err_ret_trace_val_stack;1372 return g->cur_err_ret_trace_val_stack;
...@@ -3697,19 +3379,6 @@ static bool get_prefix_arg_err_ret_stack(CodeGen *g, FnTypeId *fn_type_id) {...@@ -3697,19 +3379,6 @@ static bool get_prefix_arg_err_ret_stack(CodeGen *g, FnTypeId *fn_type_id) {
3697 fn_type_id->cc == CallingConventionAsync);3379 fn_type_id->cc == CallingConventionAsync);
3698}3380}
36993381
3700static size_t get_async_allocator_arg_index(CodeGen *g, FnTypeId *fn_type_id) {
3701 // 0 1 2 3
3702 // err_ret_stack allocator_ptr err_code other_args...
3703 return get_prefix_arg_err_ret_stack(g, fn_type_id) ? 1 : 0;
3704}
3705
3706static size_t get_async_err_code_arg_index(CodeGen *g, FnTypeId *fn_type_id) {
3707 // 0 1 2 3
3708 // err_ret_stack allocator_ptr err_code other_args...
3709 return 1 + get_async_allocator_arg_index(g, fn_type_id);
3710}
3711
3712
3713static LLVMValueRef get_new_stack_addr(CodeGen *g, LLVMValueRef new_stack) {3382static LLVMValueRef get_new_stack_addr(CodeGen *g, LLVMValueRef new_stack) {
3714 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, new_stack, (unsigned)slice_ptr_index, "");3383 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, new_stack, (unsigned)slice_ptr_index, "");
3715 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, new_stack, (unsigned)slice_len_index, "");3384 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, new_stack, (unsigned)slice_len_index, "");
...@@ -3778,10 +3447,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3778,10 +3447,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
3778 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope));3447 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope));
3779 }3448 }
3780 if (instruction->is_async) {3449 if (instruction->is_async) {
3781 gen_param_values.append(ir_llvm_value(g, instruction->async_allocator));3450 zig_panic("TODO codegen async call");
3782
3783 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, result_loc, err_union_err_index, "");
3784 gen_param_values.append(err_val_ptr);
3785 }3451 }
3786 FnWalk fn_walk = {};3452 FnWalk fn_walk = {};
3787 fn_walk.id = FnWalkIdCall;3453 fn_walk.id = FnWalkIdCall;
...@@ -4471,10 +4137,6 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I...@@ -4471,10 +4137,6 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
4471 {4137 {
4472 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;4138 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;
4473 ptr_val = target_val;4139 ptr_val = target_val;
4474 } else if (target_type->id == ZigTypeIdOptional &&
4475 target_type->data.maybe.child_type->id == ZigTypeIdPromise)
4476 {
4477 zig_panic("TODO audit this function");
4478 } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) {4140 } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) {
4479 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;4141 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
4480 align_bytes = get_ptr_align(g, slice_ptr_type);4142 align_bytes = get_ptr_align(g, slice_ptr_type);
...@@ -4519,17 +4181,7 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu...@@ -4519,17 +4181,7 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu
4519}4181}
45204182
4521static LLVMValueRef ir_render_cancel(CodeGen *g, IrExecutable *executable, IrInstructionCancel *instruction) {4183static LLVMValueRef ir_render_cancel(CodeGen *g, IrExecutable *executable, IrInstructionCancel *instruction) {
4522 LLVMValueRef target_handle = ir_llvm_value(g, instruction->target);4184 zig_panic("TODO cancel");
4523 LLVMBuildCall(g->builder, get_coro_destroy_fn_val(g), &target_handle, 1, "");
4524 return nullptr;
4525}
4526
4527static LLVMValueRef ir_render_get_implicit_allocator(CodeGen *g, IrExecutable *executable,
4528 IrInstructionGetImplicitAllocator *instruction)
4529{
4530 assert(instruction->id == ImplicitAllocatorIdArg);
4531 size_t allocator_arg_index = get_async_allocator_arg_index(g, &g->cur_fn->type_entry->data.fn.fn_type_id);
4532 return LLVMGetParam(g->cur_fn_val, allocator_arg_index);
4533}4185}
45344186
4535static LLVMAtomicOrdering to_LLVMAtomicOrdering(AtomicOrder atomic_order) {4187static LLVMAtomicOrdering to_LLVMAtomicOrdering(AtomicOrder atomic_order) {
...@@ -4840,24 +4492,10 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable...@@ -4840,24 +4492,10 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable
4840 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");4492 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");
4841}4493}
48424494
4843static LLVMValueRef get_handle_fn_val(CodeGen *g) {
4844 if (g->coro_frame_fn_val)
4845 return g->coro_frame_fn_val;
4846
4847 LLVMTypeRef fn_type = LLVMFunctionType( LLVMPointerType(LLVMInt8Type(), 0)
4848 , nullptr, 0, false);
4849 Buf *name = buf_sprintf("llvm.coro.frame");
4850 g->coro_frame_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
4851 assert(LLVMGetIntrinsicID(g->coro_frame_fn_val));
4852
4853 return g->coro_frame_fn_val;
4854}
4855
4856static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,4495static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,
4857 IrInstructionHandle *instruction)4496 IrInstructionHandle *instruction)
4858{4497{
4859 LLVMValueRef zero = LLVMConstNull(get_llvm_type(g, g->builtin_types.entry_promise));4498 zig_panic("TODO @handle() codegen");
4860 return LLVMBuildCall(g->builder, get_handle_fn_val(g), &zero, 0, "");
4861}4499}
48624500
4863static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {4501static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {
...@@ -5123,248 +4761,6 @@ static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutable *executable, IrInst...@@ -5123,248 +4761,6 @@ static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutable *executable, IrInst
5123 return nullptr;4761 return nullptr;
5124}4762}
51254763
5126static LLVMValueRef ir_render_coro_id(CodeGen *g, IrExecutable *executable, IrInstructionCoroId *instruction) {
5127 LLVMValueRef promise_ptr = ir_llvm_value(g, instruction->promise_ptr);
5128 LLVMValueRef align_val = LLVMConstInt(LLVMInt32Type(), get_coro_frame_align_bytes(g), false);
5129 LLVMValueRef null = LLVMConstIntToPtr(LLVMConstNull(g->builtin_types.entry_usize->llvm_type),
5130 LLVMPointerType(LLVMInt8Type(), 0));
5131 LLVMValueRef params[] = {
5132 align_val,
5133 promise_ptr,
5134 null,
5135 null,
5136 };
5137 return LLVMBuildCall(g->builder, get_coro_id_fn_val(g), params, 4, "");
5138}
5139
5140static LLVMValueRef ir_render_coro_alloc(CodeGen *g, IrExecutable *executable, IrInstructionCoroAlloc *instruction) {
5141 LLVMValueRef token = ir_llvm_value(g, instruction->coro_id);
5142 return LLVMBuildCall(g->builder, get_coro_alloc_fn_val(g), &token, 1, "");
5143}
5144
5145static LLVMValueRef ir_render_coro_size(CodeGen *g, IrExecutable *executable, IrInstructionCoroSize *instruction) {
5146 return LLVMBuildCall(g->builder, get_coro_size_fn_val(g), nullptr, 0, "");
5147}
5148
5149static LLVMValueRef ir_render_coro_begin(CodeGen *g, IrExecutable *executable, IrInstructionCoroBegin *instruction) {
5150 LLVMValueRef coro_id = ir_llvm_value(g, instruction->coro_id);
5151 LLVMValueRef coro_mem_ptr = ir_llvm_value(g, instruction->coro_mem_ptr);
5152 LLVMValueRef params[] = {
5153 coro_id,
5154 coro_mem_ptr,
5155 };
5156 return LLVMBuildCall(g->builder, get_coro_begin_fn_val(g), params, 2, "");
5157}
5158
5159static LLVMValueRef ir_render_coro_alloc_fail(CodeGen *g, IrExecutable *executable,
5160 IrInstructionCoroAllocFail *instruction)
5161{
5162 size_t err_code_ptr_arg_index = get_async_err_code_arg_index(g, &g->cur_fn->type_entry->data.fn.fn_type_id);
5163 LLVMValueRef err_code_ptr_val = LLVMGetParam(g->cur_fn_val, err_code_ptr_arg_index);
5164 LLVMValueRef err_code = ir_llvm_value(g, instruction->err_val);
5165 LLVMBuildStore(g->builder, err_code, err_code_ptr_val);
5166
5167 LLVMValueRef return_value;
5168 if (ir_want_runtime_safety(g, &instruction->base)) {
5169 return_value = LLVMConstNull(LLVMPointerType(LLVMInt8Type(), 0));
5170 } else {
5171 return_value = LLVMGetUndef(LLVMPointerType(LLVMInt8Type(), 0));
5172 }
5173 LLVMBuildRet(g->builder, return_value);
5174 return nullptr;
5175}
5176
5177static LLVMValueRef ir_render_coro_suspend(CodeGen *g, IrExecutable *executable, IrInstructionCoroSuspend *instruction) {
5178 LLVMValueRef save_point;
5179 if (instruction->save_point == nullptr) {
5180 save_point = LLVMConstNull(ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()));
5181 } else {
5182 save_point = ir_llvm_value(g, instruction->save_point);
5183 }
5184 LLVMValueRef is_final = ir_llvm_value(g, instruction->is_final);
5185 LLVMValueRef params[] = {
5186 save_point,
5187 is_final,
5188 };
5189 return LLVMBuildCall(g->builder, get_coro_suspend_fn_val(g), params, 2, "");
5190}
5191
5192static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrInstructionCoroEnd *instruction) {
5193 LLVMValueRef params[] = {
5194 LLVMConstNull(LLVMPointerType(LLVMInt8Type(), 0)),
5195 LLVMConstNull(LLVMInt1Type()),
5196 };
5197 return LLVMBuildCall(g->builder, get_coro_end_fn_val(g), params, 2, "");
5198}
5199
5200static LLVMValueRef ir_render_coro_free(CodeGen *g, IrExecutable *executable, IrInstructionCoroFree *instruction) {
5201 LLVMValueRef coro_id = ir_llvm_value(g, instruction->coro_id);
5202 LLVMValueRef coro_handle = ir_llvm_value(g, instruction->coro_handle);
5203 LLVMValueRef params[] = {
5204 coro_id,
5205 coro_handle,
5206 };
5207 return LLVMBuildCall(g->builder, get_coro_free_fn_val(g), params, 2, "");
5208}
5209
5210static LLVMValueRef ir_render_coro_resume(CodeGen *g, IrExecutable *executable, IrInstructionCoroResume *instruction) {
5211 LLVMValueRef awaiter_handle = ir_llvm_value(g, instruction->awaiter_handle);
5212 return LLVMBuildCall(g->builder, get_coro_resume_fn_val(g), &awaiter_handle, 1, "");
5213}
5214
5215static LLVMValueRef ir_render_coro_save(CodeGen *g, IrExecutable *executable, IrInstructionCoroSave *instruction) {
5216 LLVMValueRef coro_handle = ir_llvm_value(g, instruction->coro_handle);
5217 return LLVMBuildCall(g->builder, get_coro_save_fn_val(g), &coro_handle, 1, "");
5218}
5219
5220static LLVMValueRef ir_render_coro_promise(CodeGen *g, IrExecutable *executable, IrInstructionCoroPromise *instruction) {
5221 LLVMValueRef coro_handle = ir_llvm_value(g, instruction->coro_handle);
5222 LLVMValueRef params[] = {
5223 coro_handle,
5224 LLVMConstInt(LLVMInt32Type(), get_coro_frame_align_bytes(g), false),
5225 LLVMConstNull(LLVMInt1Type()),
5226 };
5227 LLVMValueRef uncasted_result = LLVMBuildCall(g->builder, get_coro_promise_fn_val(g), params, 3, "");
5228 return LLVMBuildBitCast(g->builder, uncasted_result, get_llvm_type(g, instruction->base.value.type), "");
5229}
5230
5231static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_fn_type_ref, ZigType *fn_type) {
5232 if (g->coro_alloc_helper_fn_val != nullptr)
5233 return g->coro_alloc_helper_fn_val;
5234
5235 assert(fn_type->id == ZigTypeIdFn);
5236
5237 ZigType *ptr_to_err_code_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
5238
5239 LLVMTypeRef alloc_raw_fn_type_ref = LLVMGetElementType(alloc_fn_type_ref);
5240 LLVMTypeRef *alloc_fn_arg_types = allocate<LLVMTypeRef>(LLVMCountParamTypes(alloc_raw_fn_type_ref));
5241 LLVMGetParamTypes(alloc_raw_fn_type_ref, alloc_fn_arg_types);
5242
5243 ZigList<LLVMTypeRef> arg_types = {};
5244 arg_types.append(alloc_fn_type_ref);
5245 if (g->have_err_ret_tracing) {
5246 arg_types.append(alloc_fn_arg_types[1]);
5247 }
5248 arg_types.append(alloc_fn_arg_types[g->have_err_ret_tracing ? 2 : 1]);
5249 arg_types.append(get_llvm_type(g, ptr_to_err_code_type));
5250 arg_types.append(g->builtin_types.entry_usize->llvm_type);
5251
5252 LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMPointerType(LLVMInt8Type(), 0),
5253 arg_types.items, arg_types.length, false);
5254
5255 Buf *fn_name = get_mangled_name(g, buf_create_from_str("__zig_coro_alloc_helper"), false);
5256 LLVMValueRef fn_val = LLVMAddFunction(g->module, buf_ptr(fn_name), fn_type_ref);
5257 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
5258 LLVMSetFunctionCallConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
5259 addLLVMFnAttr(fn_val, "nounwind");
5260 addLLVMArgAttr(fn_val, (unsigned)0, "nonnull");
5261 addLLVMArgAttr(fn_val, (unsigned)1, "nonnull");
5262
5263 LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder);
5264 LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder);
5265 ZigFn *prev_cur_fn = g->cur_fn;
5266 LLVMValueRef prev_cur_fn_val = g->cur_fn_val;
5267
5268 LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry");
5269 LLVMPositionBuilderAtEnd(g->builder, entry_block);
5270 ZigLLVMClearCurrentDebugLocation(g->builder);
5271 g->cur_fn = nullptr;
5272 g->cur_fn_val = fn_val;
5273
5274 LLVMValueRef sret_ptr = LLVMBuildAlloca(g->builder, LLVMGetElementType(alloc_fn_arg_types[0]), "");
5275
5276 size_t next_arg = 0;
5277 LLVMValueRef realloc_fn_val = LLVMGetParam(fn_val, next_arg);
5278 next_arg += 1;
5279
5280 LLVMValueRef stack_trace_val;
5281 if (g->have_err_ret_tracing) {
5282 stack_trace_val = LLVMGetParam(fn_val, next_arg);
5283 next_arg += 1;
5284 }
5285
5286 LLVMValueRef allocator_val = LLVMGetParam(fn_val, next_arg);
5287 next_arg += 1;
5288 LLVMValueRef err_code_ptr = LLVMGetParam(fn_val, next_arg);
5289 next_arg += 1;
5290 LLVMValueRef coro_size = LLVMGetParam(fn_val, next_arg);
5291 next_arg += 1;
5292 LLVMValueRef alignment_val = LLVMConstInt(g->builtin_types.entry_u29->llvm_type,
5293 get_coro_frame_align_bytes(g), false);
5294
5295 ConstExprValue *zero_array = create_const_str_lit(g, buf_create_from_str(""));
5296 ConstExprValue *undef_slice_zero = create_const_slice(g, zero_array, 0, 0, false);
5297 render_const_val(g, undef_slice_zero, "");
5298 render_const_val_global(g, undef_slice_zero, "");
5299
5300 ZigList<LLVMValueRef> args = {};
5301 args.append(sret_ptr);
5302 if (g->have_err_ret_tracing) {
5303 args.append(stack_trace_val);
5304 }
5305 args.append(allocator_val);
5306 args.append(undef_slice_zero->global_refs->llvm_global);
5307 args.append(LLVMGetUndef(g->builtin_types.entry_u29->llvm_type));
5308 args.append(coro_size);
5309 args.append(alignment_val);
5310 LLVMValueRef call_instruction = ZigLLVMBuildCall(g->builder, realloc_fn_val, args.items, args.length,
5311 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_FnInlineAuto, "");
5312 set_call_instr_sret(g, call_instruction);
5313 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, sret_ptr, err_union_err_index, "");
5314 LLVMValueRef err_val = LLVMBuildLoad(g->builder, err_val_ptr, "");
5315 LLVMBuildStore(g->builder, err_val, err_code_ptr);
5316 LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, err_val, LLVMConstNull(LLVMTypeOf(err_val)), "");
5317 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(fn_val, "AllocOk");
5318 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(fn_val, "AllocFail");
5319 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
5320
5321 LLVMPositionBuilderAtEnd(g->builder, ok_block);
5322 LLVMValueRef payload_ptr = LLVMBuildStructGEP(g->builder, sret_ptr, err_union_payload_index, "");
5323 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false,
5324 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0, false);
5325 ZigType *slice_type = get_slice_type(g, u8_ptr_type);
5326 size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index;
5327 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, payload_ptr, ptr_field_index, "");
5328 LLVMValueRef ptr_val = LLVMBuildLoad(g->builder, ptr_field_ptr, "");
5329 LLVMBuildRet(g->builder, ptr_val);
5330
5331 LLVMPositionBuilderAtEnd(g->builder, fail_block);
5332 LLVMBuildRet(g->builder, LLVMConstNull(LLVMPointerType(LLVMInt8Type(), 0)));
5333
5334 g->cur_fn = prev_cur_fn;
5335 g->cur_fn_val = prev_cur_fn_val;
5336 LLVMPositionBuilderAtEnd(g->builder, prev_block);
5337 if (!g->strip_debug_symbols) {
5338 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);
5339 }
5340
5341 g->coro_alloc_helper_fn_val = fn_val;
5342 return fn_val;
5343}
5344
5345static LLVMValueRef ir_render_coro_alloc_helper(CodeGen *g, IrExecutable *executable,
5346 IrInstructionCoroAllocHelper *instruction)
5347{
5348 LLVMValueRef realloc_fn = ir_llvm_value(g, instruction->realloc_fn);
5349 LLVMValueRef coro_size = ir_llvm_value(g, instruction->coro_size);
5350 LLVMValueRef fn_val = get_coro_alloc_helper_fn_val(g, LLVMTypeOf(realloc_fn), instruction->realloc_fn->value.type);
5351 size_t err_code_ptr_arg_index = get_async_err_code_arg_index(g, &g->cur_fn->type_entry->data.fn.fn_type_id);
5352 size_t allocator_arg_index = get_async_allocator_arg_index(g, &g->cur_fn->type_entry->data.fn.fn_type_id);
5353
5354 ZigList<LLVMValueRef> params = {};
5355 params.append(realloc_fn);
5356 uint32_t err_ret_trace_arg_index = get_err_ret_trace_arg_index(g, g->cur_fn);
5357 if (err_ret_trace_arg_index != UINT32_MAX) {
5358 params.append(LLVMGetParam(g->cur_fn_val, err_ret_trace_arg_index));
5359 }
5360 params.append(LLVMGetParam(g->cur_fn_val, allocator_arg_index));
5361 params.append(LLVMGetParam(g->cur_fn_val, err_code_ptr_arg_index));
5362 params.append(coro_size);
5363
5364 return ZigLLVMBuildCall(g->builder, fn_val, params.items, params.length,
5365 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_FnInlineAuto, "");
5366}
5367
5368static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,4764static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
5369 IrInstructionAtomicRmw *instruction)4765 IrInstructionAtomicRmw *instruction)
5370{4766{
...@@ -5402,19 +4798,6 @@ static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,...@@ -5402,19 +4798,6 @@ static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,
5402 return load_inst;4798 return load_inst;
5403}4799}
54044800
5405static LLVMValueRef ir_render_merge_err_ret_traces(CodeGen *g, IrExecutable *executable,
5406 IrInstructionMergeErrRetTraces *instruction)
5407{
5408 assert(g->have_err_ret_tracing);
5409
5410 LLVMValueRef src_trace_ptr = ir_llvm_value(g, instruction->src_err_ret_trace_ptr);
5411 LLVMValueRef dest_trace_ptr = ir_llvm_value(g, instruction->dest_err_ret_trace_ptr);
5412
5413 LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr };
5414 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2, get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_FnInlineAuto, "");
5415 return nullptr;
5416}
5417
5418static LLVMValueRef ir_render_mark_err_ret_trace_ptr(CodeGen *g, IrExecutable *executable,4801static LLVMValueRef ir_render_mark_err_ret_trace_ptr(CodeGen *g, IrExecutable *executable,
5419 IrInstructionMarkErrRetTracePtr *instruction)4802 IrInstructionMarkErrRetTracePtr *instruction)
5420{4803{
...@@ -5559,7 +4942,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5559,7 +4942,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5559 case IrInstructionIdSetRuntimeSafety:4942 case IrInstructionIdSetRuntimeSafety:
5560 case IrInstructionIdSetFloatMode:4943 case IrInstructionIdSetFloatMode:
5561 case IrInstructionIdArrayType:4944 case IrInstructionIdArrayType:
5562 case IrInstructionIdPromiseType:
5563 case IrInstructionIdSliceType:4945 case IrInstructionIdSliceType:
5564 case IrInstructionIdSizeOf:4946 case IrInstructionIdSizeOf:
5565 case IrInstructionIdSwitchTarget:4947 case IrInstructionIdSwitchTarget:
...@@ -5599,8 +4981,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5599,8 +4981,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5599 case IrInstructionIdTagType:4981 case IrInstructionIdTagType:
5600 case IrInstructionIdExport:4982 case IrInstructionIdExport:
5601 case IrInstructionIdErrorUnion:4983 case IrInstructionIdErrorUnion:
5602 case IrInstructionIdPromiseResultType:
5603 case IrInstructionIdAwaitBookkeeping:
5604 case IrInstructionIdAddImplicitReturnType:4984 case IrInstructionIdAddImplicitReturnType:
5605 case IrInstructionIdIntCast:4985 case IrInstructionIdIntCast:
5606 case IrInstructionIdFloatCast:4986 case IrInstructionIdFloatCast:
...@@ -5757,40 +5137,12 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5757,40 +5137,12 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5757 return ir_render_error_return_trace(g, executable, (IrInstructionErrorReturnTrace *)instruction);5137 return ir_render_error_return_trace(g, executable, (IrInstructionErrorReturnTrace *)instruction);
5758 case IrInstructionIdCancel:5138 case IrInstructionIdCancel:
5759 return ir_render_cancel(g, executable, (IrInstructionCancel *)instruction);5139 return ir_render_cancel(g, executable, (IrInstructionCancel *)instruction);
5760 case IrInstructionIdGetImplicitAllocator:
5761 return ir_render_get_implicit_allocator(g, executable, (IrInstructionGetImplicitAllocator *)instruction);
5762 case IrInstructionIdCoroId:
5763 return ir_render_coro_id(g, executable, (IrInstructionCoroId *)instruction);
5764 case IrInstructionIdCoroAlloc:
5765 return ir_render_coro_alloc(g, executable, (IrInstructionCoroAlloc *)instruction);
5766 case IrInstructionIdCoroSize:
5767 return ir_render_coro_size(g, executable, (IrInstructionCoroSize *)instruction);
5768 case IrInstructionIdCoroBegin:
5769 return ir_render_coro_begin(g, executable, (IrInstructionCoroBegin *)instruction);
5770 case IrInstructionIdCoroAllocFail:
5771 return ir_render_coro_alloc_fail(g, executable, (IrInstructionCoroAllocFail *)instruction);
5772 case IrInstructionIdCoroSuspend:
5773 return ir_render_coro_suspend(g, executable, (IrInstructionCoroSuspend *)instruction);
5774 case IrInstructionIdCoroEnd:
5775 return ir_render_coro_end(g, executable, (IrInstructionCoroEnd *)instruction);
5776 case IrInstructionIdCoroFree:
5777 return ir_render_coro_free(g, executable, (IrInstructionCoroFree *)instruction);
5778 case IrInstructionIdCoroResume:
5779 return ir_render_coro_resume(g, executable, (IrInstructionCoroResume *)instruction);
5780 case IrInstructionIdCoroSave:
5781 return ir_render_coro_save(g, executable, (IrInstructionCoroSave *)instruction);
5782 case IrInstructionIdCoroPromise:
5783 return ir_render_coro_promise(g, executable, (IrInstructionCoroPromise *)instruction);
5784 case IrInstructionIdCoroAllocHelper:
5785 return ir_render_coro_alloc_helper(g, executable, (IrInstructionCoroAllocHelper *)instruction);
5786 case IrInstructionIdAtomicRmw:5140 case IrInstructionIdAtomicRmw:
5787 return ir_render_atomic_rmw(g, executable, (IrInstructionAtomicRmw *)instruction);5141 return ir_render_atomic_rmw(g, executable, (IrInstructionAtomicRmw *)instruction);
5788 case IrInstructionIdAtomicLoad:5142 case IrInstructionIdAtomicLoad:
5789 return ir_render_atomic_load(g, executable, (IrInstructionAtomicLoad *)instruction);5143 return ir_render_atomic_load(g, executable, (IrInstructionAtomicLoad *)instruction);
5790 case IrInstructionIdSaveErrRetAddr:5144 case IrInstructionIdSaveErrRetAddr:
5791 return ir_render_save_err_ret_addr(g, executable, (IrInstructionSaveErrRetAddr *)instruction);5145 return ir_render_save_err_ret_addr(g, executable, (IrInstructionSaveErrRetAddr *)instruction);
5792 case IrInstructionIdMergeErrRetTraces:
5793 return ir_render_merge_err_ret_traces(g, executable, (IrInstructionMergeErrRetTraces *)instruction);
5794 case IrInstructionIdMarkErrRetTracePtr:5146 case IrInstructionIdMarkErrRetTracePtr:
5795 return ir_render_mark_err_ret_trace_ptr(g, executable, (IrInstructionMarkErrRetTracePtr *)instruction);5147 return ir_render_mark_err_ret_trace_ptr(g, executable, (IrInstructionMarkErrRetTracePtr *)instruction);
5796 case IrInstructionIdFloatOp:5148 case IrInstructionIdFloatOp:
...@@ -6008,7 +5360,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con...@@ -6008,7 +5360,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
6008 case ZigTypeIdPointer:5360 case ZigTypeIdPointer:
6009 case ZigTypeIdFn:5361 case ZigTypeIdFn:
6010 case ZigTypeIdOptional:5362 case ZigTypeIdOptional:
6011 case ZigTypeIdPromise:
6012 {5363 {
6013 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");5364 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");
6014 LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->llvm_type);5365 LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->llvm_type);
...@@ -6591,7 +5942,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -6591,7 +5942,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
6591 case ZigTypeIdBoundFn:5942 case ZigTypeIdBoundFn:
6592 case ZigTypeIdArgTuple:5943 case ZigTypeIdArgTuple:
6593 case ZigTypeIdOpaque:5944 case ZigTypeIdOpaque:
6594 case ZigTypeIdPromise:
6595 zig_unreachable();5945 zig_unreachable();
65965946
6597 }5947 }
...@@ -7294,13 +6644,6 @@ static void define_builtin_types(CodeGen *g) {...@@ -7294,13 +6644,6 @@ static void define_builtin_types(CodeGen *g) {
72946644
7295 g->primitive_type_table.put(&entry->name, entry);6645 g->primitive_type_table.put(&entry->name, entry);
7296 }6646 }
7297 {
7298 ZigType *entry = get_promise_type(g, nullptr);
7299 g->primitive_type_table.put(&entry->name, entry);
7300 entry->size_in_bits = g->builtin_types.entry_usize->size_in_bits;
7301 entry->abi_align = g->builtin_types.entry_usize->abi_align;
7302 entry->abi_size = g->builtin_types.entry_usize->abi_size;
7303 }
7304}6647}
73056648
73066649
...@@ -7729,7 +7072,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7729,7 +7072,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7729 " BoundFn: Fn,\n"7072 " BoundFn: Fn,\n"
7730 " ArgTuple: void,\n"7073 " ArgTuple: void,\n"
7731 " Opaque: void,\n"7074 " Opaque: void,\n"
7732 " Promise: Promise,\n"
7733 " Vector: Vector,\n"7075 " Vector: Vector,\n"
7734 " EnumLiteral: void,\n"7076 " EnumLiteral: void,\n"
7735 "\n\n"7077 "\n\n"
...@@ -7842,14 +7184,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7842,14 +7184,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7842 " is_generic: bool,\n"7184 " is_generic: bool,\n"
7843 " is_var_args: bool,\n"7185 " is_var_args: bool,\n"
7844 " return_type: ?type,\n"7186 " return_type: ?type,\n"
7845 " async_allocator_type: ?type,\n"
7846 " args: []FnArg,\n"7187 " args: []FnArg,\n"
7847 " };\n"7188 " };\n"
7848 "\n"7189 "\n"
7849 " pub const Promise = struct {\n"
7850 " child: ?type,\n"
7851 " };\n"
7852 "\n"
7853 " pub const Vector = struct {\n"7190 " pub const Vector = struct {\n"
7854 " len: comptime_int,\n"7191 " len: comptime_int,\n"
7855 " child: type,\n"7192 " child: type,\n"
...@@ -8998,7 +8335,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e...@@ -8998,7 +8335,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
8998 case ZigTypeIdArgTuple:8335 case ZigTypeIdArgTuple:
8999 case ZigTypeIdErrorUnion:8336 case ZigTypeIdErrorUnion:
9000 case ZigTypeIdErrorSet:8337 case ZigTypeIdErrorSet:
9001 case ZigTypeIdPromise:
9002 zig_unreachable();8338 zig_unreachable();
9003 case ZigTypeIdVoid:8339 case ZigTypeIdVoid:
9004 case ZigTypeIdUnreachable:8340 case ZigTypeIdUnreachable:
...@@ -9182,7 +8518,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu...@@ -9182,7 +8518,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
9182 case ZigTypeIdUndefined:8518 case ZigTypeIdUndefined:
9183 case ZigTypeIdNull:8519 case ZigTypeIdNull:
9184 case ZigTypeIdArgTuple:8520 case ZigTypeIdArgTuple:
9185 case ZigTypeIdPromise:
9186 zig_unreachable();8521 zig_unreachable();
9187 }8522 }
9188}8523}
...@@ -9349,7 +8684,6 @@ static void gen_h_file(CodeGen *g) {...@@ -9349,7 +8684,6 @@ static void gen_h_file(CodeGen *g) {
9349 case ZigTypeIdArgTuple:8684 case ZigTypeIdArgTuple:
9350 case ZigTypeIdOptional:8685 case ZigTypeIdOptional:
9351 case ZigTypeIdFn:8686 case ZigTypeIdFn:
9352 case ZigTypeIdPromise:
9353 case ZigTypeIdVector:8687 case ZigTypeIdVector:
9354 zig_unreachable();8688 zig_unreachable();
9355 case ZigTypeIdEnum:8689 case ZigTypeIdEnum:
src/ir.cpp+26-1513
...@@ -99,7 +99,6 @@ struct ConstCastOnly {...@@ -99,7 +99,6 @@ struct ConstCastOnly {
99 ConstCastErrUnionErrSetMismatch *error_union_error_set;99 ConstCastErrUnionErrSetMismatch *error_union_error_set;
100 ConstCastTypeMismatch *type_mismatch;100 ConstCastTypeMismatch *type_mismatch;
101 ConstCastOnly *return_type;101 ConstCastOnly *return_type;
102 ConstCastOnly *async_allocator_type;
103 ConstCastOnly *null_wrap_ptr_child;102 ConstCastOnly *null_wrap_ptr_child;
104 ConstCastArg fn_arg;103 ConstCastArg fn_arg;
105 ConstCastArgNoAlias arg_no_alias;104 ConstCastArgNoAlias arg_no_alias;
...@@ -318,7 +317,6 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {...@@ -318,7 +317,6 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
318 case ZigTypeIdUnion:317 case ZigTypeIdUnion:
319 case ZigTypeIdFn:318 case ZigTypeIdFn:
320 case ZigTypeIdArgTuple:319 case ZigTypeIdArgTuple:
321 case ZigTypeIdPromise:
322 case ZigTypeIdVector:320 case ZigTypeIdVector:
323 return false;321 return false;
324 }322 }
...@@ -564,10 +562,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayType *) {...@@ -564,10 +562,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayType *) {
564 return IrInstructionIdArrayType;562 return IrInstructionIdArrayType;
565}563}
566564
567static constexpr IrInstructionId ir_instruction_id(IrInstructionPromiseType *) {
568 return IrInstructionIdPromiseType;
569}
570
571static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceType *) {565static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceType *) {
572 return IrInstructionIdSliceType;566 return IrInstructionIdSliceType;
573}567}
...@@ -964,58 +958,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionCancel *) {...@@ -964,58 +958,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionCancel *) {
964 return IrInstructionIdCancel;958 return IrInstructionIdCancel;
965}959}
966960
967static constexpr IrInstructionId ir_instruction_id(IrInstructionGetImplicitAllocator *) {
968 return IrInstructionIdGetImplicitAllocator;
969}
970
971static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroId *) {
972 return IrInstructionIdCoroId;
973}
974
975static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroAlloc *) {
976 return IrInstructionIdCoroAlloc;
977}
978
979static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroSize *) {
980 return IrInstructionIdCoroSize;
981}
982
983static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroBegin *) {
984 return IrInstructionIdCoroBegin;
985}
986
987static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroAllocFail *) {
988 return IrInstructionIdCoroAllocFail;
989}
990
991static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroSuspend *) {
992 return IrInstructionIdCoroSuspend;
993}
994
995static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroEnd *) {
996 return IrInstructionIdCoroEnd;
997}
998
999static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroFree *) {
1000 return IrInstructionIdCoroFree;
1001}
1002
1003static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroResume *) {
1004 return IrInstructionIdCoroResume;
1005}
1006
1007static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroSave *) {
1008 return IrInstructionIdCoroSave;
1009}
1010
1011static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroPromise *) {
1012 return IrInstructionIdCoroPromise;
1013}
1014
1015static constexpr IrInstructionId ir_instruction_id(IrInstructionCoroAllocHelper *) {
1016 return IrInstructionIdCoroAllocHelper;
1017}
1018
1019static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicRmw *) {961static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicRmw *) {
1020 return IrInstructionIdAtomicRmw;962 return IrInstructionIdAtomicRmw;
1021}963}
...@@ -1024,14 +966,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicLoad *) {...@@ -1024,14 +966,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicLoad *) {
1024 return IrInstructionIdAtomicLoad;966 return IrInstructionIdAtomicLoad;
1025}967}
1026968
1027static constexpr IrInstructionId ir_instruction_id(IrInstructionPromiseResultType *) {
1028 return IrInstructionIdPromiseResultType;
1029}
1030
1031static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitBookkeeping *) {
1032 return IrInstructionIdAwaitBookkeeping;
1033}
1034
1035static constexpr IrInstructionId ir_instruction_id(IrInstructionSaveErrRetAddr *) {969static constexpr IrInstructionId ir_instruction_id(IrInstructionSaveErrRetAddr *) {
1036 return IrInstructionIdSaveErrRetAddr;970 return IrInstructionIdSaveErrRetAddr;
1037}971}
...@@ -1040,10 +974,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAddImplicitRetur...@@ -1040,10 +974,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAddImplicitRetur
1040 return IrInstructionIdAddImplicitReturnType;974 return IrInstructionIdAddImplicitReturnType;
1041}975}
1042976
1043static constexpr IrInstructionId ir_instruction_id(IrInstructionMergeErrRetTraces *) {
1044 return IrInstructionIdMergeErrRetTraces;
1045}
1046
1047static constexpr IrInstructionId ir_instruction_id(IrInstructionMarkErrRetTracePtr *) {977static constexpr IrInstructionId ir_instruction_id(IrInstructionMarkErrRetTracePtr *) {
1048 return IrInstructionIdMarkErrRetTracePtr;978 return IrInstructionIdMarkErrRetTracePtr;
1049}979}
...@@ -1213,14 +1143,6 @@ static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode...@@ -1213,14 +1143,6 @@ static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode
1213 return &const_instruction->base;1143 return &const_instruction->base;
1214}1144}
12151145
1216static IrInstruction *ir_build_const_u8(IrBuilder *irb, Scope *scope, AstNode *source_node, uint8_t value) {
1217 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1218 const_instruction->base.value.type = irb->codegen->builtin_types.entry_u8;
1219 const_instruction->base.value.special = ConstValSpecialStatic;
1220 bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value);
1221 return &const_instruction->base;
1222}
1223
1224static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,1146static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
1225 ZigType *type_entry)1147 ZigType *type_entry)
1226{1148{
...@@ -1428,7 +1350,7 @@ static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, Ast...@@ -1428,7 +1350,7 @@ static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, Ast
14281350
1429static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *source_node,1351static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
1430 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,1352 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1431 bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator,1353 bool is_comptime, FnInline fn_inline, bool is_async,
1432 IrInstruction *new_stack, ResultLoc *result_loc)1354 IrInstruction *new_stack, ResultLoc *result_loc)
1433{1355{
1434 IrInstructionCallSrc *call_instruction = ir_build_instruction<IrInstructionCallSrc>(irb, scope, source_node);1356 IrInstructionCallSrc *call_instruction = ir_build_instruction<IrInstructionCallSrc>(irb, scope, source_node);
...@@ -1439,14 +1361,12 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1439,14 +1361,12 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s
1439 call_instruction->args = args;1361 call_instruction->args = args;
1440 call_instruction->arg_count = arg_count;1362 call_instruction->arg_count = arg_count;
1441 call_instruction->is_async = is_async;1363 call_instruction->is_async = is_async;
1442 call_instruction->async_allocator = async_allocator;
1443 call_instruction->new_stack = new_stack;1364 call_instruction->new_stack = new_stack;
1444 call_instruction->result_loc = result_loc;1365 call_instruction->result_loc = result_loc;
14451366
1446 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, irb->current_basic_block);1367 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, irb->current_basic_block);
1447 for (size_t i = 0; i < arg_count; i += 1)1368 for (size_t i = 0; i < arg_count; i += 1)
1448 ir_ref_instruction(args[i], irb->current_basic_block);1369 ir_ref_instruction(args[i], irb->current_basic_block);
1449 if (async_allocator != nullptr) ir_ref_instruction(async_allocator, irb->current_basic_block);
1450 if (new_stack != nullptr) ir_ref_instruction(new_stack, irb->current_basic_block);1370 if (new_stack != nullptr) ir_ref_instruction(new_stack, irb->current_basic_block);
14511371
1452 return &call_instruction->base;1372 return &call_instruction->base;
...@@ -1454,7 +1374,7 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1454,7 +1374,7 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s
14541374
1455static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction,1375static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction,
1456 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,1376 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1457 FnInline fn_inline, bool is_async, IrInstruction *async_allocator, IrInstruction *new_stack,1377 FnInline fn_inline, bool is_async, IrInstruction *new_stack,
1458 IrInstruction *result_loc, ZigType *return_type)1378 IrInstruction *result_loc, ZigType *return_type)
1459{1379{
1460 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,1380 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,
...@@ -1466,14 +1386,12 @@ static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_in...@@ -1466,14 +1386,12 @@ static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_in
1466 call_instruction->args = args;1386 call_instruction->args = args;
1467 call_instruction->arg_count = arg_count;1387 call_instruction->arg_count = arg_count;
1468 call_instruction->is_async = is_async;1388 call_instruction->is_async = is_async;
1469 call_instruction->async_allocator = async_allocator;
1470 call_instruction->new_stack = new_stack;1389 call_instruction->new_stack = new_stack;
1471 call_instruction->result_loc = result_loc;1390 call_instruction->result_loc = result_loc;
14721391
1473 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block);1392 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block);
1474 for (size_t i = 0; i < arg_count; i += 1)1393 for (size_t i = 0; i < arg_count; i += 1)
1475 ir_ref_instruction(args[i], ira->new_irb.current_basic_block);1394 ir_ref_instruction(args[i], ira->new_irb.current_basic_block);
1476 if (async_allocator != nullptr) ir_ref_instruction(async_allocator, ira->new_irb.current_basic_block);
1477 if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block);1395 if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block);
1478 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);1396 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
14791397
...@@ -1753,17 +1671,6 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode...@@ -1753,17 +1671,6 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode
1753 return &instruction->base;1671 return &instruction->base;
1754}1672}
17551673
1756static IrInstruction *ir_build_promise_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
1757 IrInstruction *payload_type)
1758{
1759 IrInstructionPromiseType *instruction = ir_build_instruction<IrInstructionPromiseType>(irb, scope, source_node);
1760 instruction->payload_type = payload_type;
1761
1762 if (payload_type != nullptr) ir_ref_instruction(payload_type, irb->current_basic_block);
1763
1764 return &instruction->base;
1765}
1766
1767static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node,1674static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
1768 IrInstruction *child_type, bool is_const, bool is_volatile, IrInstruction *align_value, bool is_allow_zero)1675 IrInstruction *child_type, bool is_const, bool is_volatile, IrInstruction *align_value, bool is_allow_zero)
1769{1676{
...@@ -2595,13 +2502,12 @@ static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope,...@@ -2595,13 +2502,12 @@ static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope,
25952502
2596static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node,2503static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node,
2597 IrInstruction **param_types, IrInstruction *align_value, IrInstruction *return_type,2504 IrInstruction **param_types, IrInstruction *align_value, IrInstruction *return_type,
2598 IrInstruction *async_allocator_type_value, bool is_var_args)2505 bool is_var_args)
2599{2506{
2600 IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node);2507 IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node);
2601 instruction->param_types = param_types;2508 instruction->param_types = param_types;
2602 instruction->align_value = align_value;2509 instruction->align_value = align_value;
2603 instruction->return_type = return_type;2510 instruction->return_type = return_type;
2604 instruction->async_allocator_type_value = async_allocator_type_value;
2605 instruction->is_var_args = is_var_args;2511 instruction->is_var_args = is_var_args;
26062512
2607 assert(source_node->type == NodeTypeFnProto);2513 assert(source_node->type == NodeTypeFnProto);
...@@ -2611,7 +2517,6 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2611,7 +2517,6 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s
2611 if (param_types[i] != nullptr) ir_ref_instruction(param_types[i], irb->current_basic_block);2517 if (param_types[i] != nullptr) ir_ref_instruction(param_types[i], irb->current_basic_block);
2612 }2518 }
2613 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);2519 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
2614 if (async_allocator_type_value != nullptr) ir_ref_instruction(async_allocator_type_value, irb->current_basic_block);
2615 ir_ref_instruction(return_type, irb->current_basic_block);2520 ir_ref_instruction(return_type, irb->current_basic_block);
26162521
2617 return &instruction->base;2522 return &instruction->base;
...@@ -3055,149 +2960,6 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode...@@ -3055,149 +2960,6 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode
3055 return &instruction->base;2960 return &instruction->base;
3056}2961}
30572962
3058static IrInstruction *ir_build_cancel(IrBuilder *irb, Scope *scope, AstNode *source_node,
3059 IrInstruction *target)
3060{
3061 IrInstructionCancel *instruction = ir_build_instruction<IrInstructionCancel>(irb, scope, source_node);
3062 instruction->target = target;
3063
3064 ir_ref_instruction(target, irb->current_basic_block);
3065
3066 return &instruction->base;
3067}
3068
3069static IrInstruction *ir_build_get_implicit_allocator(IrBuilder *irb, Scope *scope, AstNode *source_node,
3070 ImplicitAllocatorId id)
3071{
3072 IrInstructionGetImplicitAllocator *instruction = ir_build_instruction<IrInstructionGetImplicitAllocator>(irb, scope, source_node);
3073 instruction->id = id;
3074
3075 return &instruction->base;
3076}
3077
3078static IrInstruction *ir_build_coro_id(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *promise_ptr) {
3079 IrInstructionCoroId *instruction = ir_build_instruction<IrInstructionCoroId>(irb, scope, source_node);
3080 instruction->promise_ptr = promise_ptr;
3081
3082 ir_ref_instruction(promise_ptr, irb->current_basic_block);
3083
3084 return &instruction->base;
3085}
3086
3087static IrInstruction *ir_build_coro_alloc(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *coro_id) {
3088 IrInstructionCoroAlloc *instruction = ir_build_instruction<IrInstructionCoroAlloc>(irb, scope, source_node);
3089 instruction->coro_id = coro_id;
3090
3091 ir_ref_instruction(coro_id, irb->current_basic_block);
3092
3093 return &instruction->base;
3094}
3095
3096static IrInstruction *ir_build_coro_size(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3097 IrInstructionCoroSize *instruction = ir_build_instruction<IrInstructionCoroSize>(irb, scope, source_node);
3098
3099 return &instruction->base;
3100}
3101
3102static IrInstruction *ir_build_coro_begin(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *coro_id, IrInstruction *coro_mem_ptr) {
3103 IrInstructionCoroBegin *instruction = ir_build_instruction<IrInstructionCoroBegin>(irb, scope, source_node);
3104 instruction->coro_id = coro_id;
3105 instruction->coro_mem_ptr = coro_mem_ptr;
3106
3107 ir_ref_instruction(coro_id, irb->current_basic_block);
3108 ir_ref_instruction(coro_mem_ptr, irb->current_basic_block);
3109
3110 return &instruction->base;
3111}
3112
3113static IrInstruction *ir_build_coro_alloc_fail(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *err_val) {
3114 IrInstructionCoroAllocFail *instruction = ir_build_instruction<IrInstructionCoroAllocFail>(irb, scope, source_node);
3115 instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable;
3116 instruction->base.value.special = ConstValSpecialStatic;
3117 instruction->err_val = err_val;
3118
3119 ir_ref_instruction(err_val, irb->current_basic_block);
3120
3121 return &instruction->base;
3122}
3123
3124static IrInstruction *ir_build_coro_suspend(IrBuilder *irb, Scope *scope, AstNode *source_node,
3125 IrInstruction *save_point, IrInstruction *is_final)
3126{
3127 IrInstructionCoroSuspend *instruction = ir_build_instruction<IrInstructionCoroSuspend>(irb, scope, source_node);
3128 instruction->save_point = save_point;
3129 instruction->is_final = is_final;
3130
3131 if (save_point != nullptr) ir_ref_instruction(save_point, irb->current_basic_block);
3132 ir_ref_instruction(is_final, irb->current_basic_block);
3133
3134 return &instruction->base;
3135}
3136
3137static IrInstruction *ir_build_coro_end(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3138 IrInstructionCoroEnd *instruction = ir_build_instruction<IrInstructionCoroEnd>(irb, scope, source_node);
3139 return &instruction->base;
3140}
3141
3142static IrInstruction *ir_build_coro_free(IrBuilder *irb, Scope *scope, AstNode *source_node,
3143 IrInstruction *coro_id, IrInstruction *coro_handle)
3144{
3145 IrInstructionCoroFree *instruction = ir_build_instruction<IrInstructionCoroFree>(irb, scope, source_node);
3146 instruction->coro_id = coro_id;
3147 instruction->coro_handle = coro_handle;
3148
3149 ir_ref_instruction(coro_id, irb->current_basic_block);
3150 ir_ref_instruction(coro_handle, irb->current_basic_block);
3151
3152 return &instruction->base;
3153}
3154
3155static IrInstruction *ir_build_coro_resume(IrBuilder *irb, Scope *scope, AstNode *source_node,
3156 IrInstruction *awaiter_handle)
3157{
3158 IrInstructionCoroResume *instruction = ir_build_instruction<IrInstructionCoroResume>(irb, scope, source_node);
3159 instruction->awaiter_handle = awaiter_handle;
3160
3161 ir_ref_instruction(awaiter_handle, irb->current_basic_block);
3162
3163 return &instruction->base;
3164}
3165
3166static IrInstruction *ir_build_coro_save(IrBuilder *irb, Scope *scope, AstNode *source_node,
3167 IrInstruction *coro_handle)
3168{
3169 IrInstructionCoroSave *instruction = ir_build_instruction<IrInstructionCoroSave>(irb, scope, source_node);
3170 instruction->coro_handle = coro_handle;
3171
3172 ir_ref_instruction(coro_handle, irb->current_basic_block);
3173
3174 return &instruction->base;
3175}
3176
3177static IrInstruction *ir_build_coro_promise(IrBuilder *irb, Scope *scope, AstNode *source_node,
3178 IrInstruction *coro_handle)
3179{
3180 IrInstructionCoroPromise *instruction = ir_build_instruction<IrInstructionCoroPromise>(irb, scope, source_node);
3181 instruction->coro_handle = coro_handle;
3182
3183 ir_ref_instruction(coro_handle, irb->current_basic_block);
3184
3185 return &instruction->base;
3186}
3187
3188static IrInstruction *ir_build_coro_alloc_helper(IrBuilder *irb, Scope *scope, AstNode *source_node,
3189 IrInstruction *realloc_fn, IrInstruction *coro_size)
3190{
3191 IrInstructionCoroAllocHelper *instruction = ir_build_instruction<IrInstructionCoroAllocHelper>(irb, scope, source_node);
3192 instruction->realloc_fn = realloc_fn;
3193 instruction->coro_size = coro_size;
3194
3195 ir_ref_instruction(realloc_fn, irb->current_basic_block);
3196 ir_ref_instruction(coro_size, irb->current_basic_block);
3197
3198 return &instruction->base;
3199}
3200
3201static IrInstruction *ir_build_atomic_rmw(IrBuilder *irb, Scope *scope, AstNode *source_node,2963static IrInstruction *ir_build_atomic_rmw(IrBuilder *irb, Scope *scope, AstNode *source_node,
3202 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *op, IrInstruction *operand,2964 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *op, IrInstruction *operand,
3203 IrInstruction *ordering, AtomicRmwOp resolved_op, AtomicOrder resolved_ordering)2965 IrInstruction *ordering, AtomicRmwOp resolved_op, AtomicOrder resolved_ordering)
...@@ -3237,28 +2999,6 @@ static IrInstruction *ir_build_atomic_load(IrBuilder *irb, Scope *scope, AstNode...@@ -3237,28 +2999,6 @@ static IrInstruction *ir_build_atomic_load(IrBuilder *irb, Scope *scope, AstNode
3237 return &instruction->base;2999 return &instruction->base;
3238}3000}
32393001
3240static IrInstruction *ir_build_promise_result_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3241 IrInstruction *promise_type)
3242{
3243 IrInstructionPromiseResultType *instruction = ir_build_instruction<IrInstructionPromiseResultType>(irb, scope, source_node);
3244 instruction->promise_type = promise_type;
3245
3246 ir_ref_instruction(promise_type, irb->current_basic_block);
3247
3248 return &instruction->base;
3249}
3250
3251static IrInstruction *ir_build_await_bookkeeping(IrBuilder *irb, Scope *scope, AstNode *source_node,
3252 IrInstruction *promise_result_type)
3253{
3254 IrInstructionAwaitBookkeeping *instruction = ir_build_instruction<IrInstructionAwaitBookkeeping>(irb, scope, source_node);
3255 instruction->promise_result_type = promise_result_type;
3256
3257 ir_ref_instruction(promise_result_type, irb->current_basic_block);
3258
3259 return &instruction->base;
3260}
3261
3262static IrInstruction *ir_build_save_err_ret_addr(IrBuilder *irb, Scope *scope, AstNode *source_node) {3002static IrInstruction *ir_build_save_err_ret_addr(IrBuilder *irb, Scope *scope, AstNode *source_node) {
3263 IrInstructionSaveErrRetAddr *instruction = ir_build_instruction<IrInstructionSaveErrRetAddr>(irb, scope, source_node);3003 IrInstructionSaveErrRetAddr *instruction = ir_build_instruction<IrInstructionSaveErrRetAddr>(irb, scope, source_node);
3264 return &instruction->base;3004 return &instruction->base;
...@@ -3275,21 +3015,6 @@ static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *s...@@ -3275,21 +3015,6 @@ static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *s
3275 return &instruction->base;3015 return &instruction->base;
3276}3016}
32773017
3278static IrInstruction *ir_build_merge_err_ret_traces(IrBuilder *irb, Scope *scope, AstNode *source_node,
3279 IrInstruction *coro_promise_ptr, IrInstruction *src_err_ret_trace_ptr, IrInstruction *dest_err_ret_trace_ptr)
3280{
3281 IrInstructionMergeErrRetTraces *instruction = ir_build_instruction<IrInstructionMergeErrRetTraces>(irb, scope, source_node);
3282 instruction->coro_promise_ptr = coro_promise_ptr;
3283 instruction->src_err_ret_trace_ptr = src_err_ret_trace_ptr;
3284 instruction->dest_err_ret_trace_ptr = dest_err_ret_trace_ptr;
3285
3286 ir_ref_instruction(coro_promise_ptr, irb->current_basic_block);
3287 ir_ref_instruction(src_err_ret_trace_ptr, irb->current_basic_block);
3288 ir_ref_instruction(dest_err_ret_trace_ptr, irb->current_basic_block);
3289
3290 return &instruction->base;
3291}
3292
3293static IrInstruction *ir_build_mark_err_ret_trace_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *err_ret_trace_ptr) {3018static IrInstruction *ir_build_mark_err_ret_trace_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *err_ret_trace_ptr) {
3294 IrInstructionMarkErrRetTracePtr *instruction = ir_build_instruction<IrInstructionMarkErrRetTracePtr>(irb, scope, source_node);3019 IrInstructionMarkErrRetTracePtr *instruction = ir_build_instruction<IrInstructionMarkErrRetTracePtr>(irb, scope, source_node);
3295 instruction->err_ret_trace_ptr = err_ret_trace_ptr;3020 instruction->err_ret_trace_ptr = err_ret_trace_ptr;
...@@ -3488,7 +3213,6 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco...@@ -3488,7 +3213,6 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco
3488 continue;3213 continue;
3489 case ScopeIdDeferExpr:3214 case ScopeIdDeferExpr:
3490 case ScopeIdCImport:3215 case ScopeIdCImport:
3491 case ScopeIdCoroPrelude:
3492 zig_unreachable();3216 zig_unreachable();
3493 }3217 }
3494 }3218 }
...@@ -3544,7 +3268,6 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o...@@ -3544,7 +3268,6 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
3544 continue;3268 continue;
3545 case ScopeIdDeferExpr:3269 case ScopeIdDeferExpr:
3546 case ScopeIdCImport:3270 case ScopeIdCImport:
3547 case ScopeIdCoroPrelude:
3548 zig_unreachable();3271 zig_unreachable();
3549 }3272 }
3550 }3273 }
...@@ -3563,18 +3286,6 @@ static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *...@@ -3563,18 +3286,6 @@ static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *
3563 ir_set_cursor_at_end(irb, basic_block);3286 ir_set_cursor_at_end(irb, basic_block);
3564}3287}
35653288
3566static ScopeSuspend *get_scope_suspend(Scope *scope) {
3567 while (scope) {
3568 if (scope->id == ScopeIdSuspend)
3569 return (ScopeSuspend *)scope;
3570 if (scope->id == ScopeIdFnDef)
3571 return nullptr;
3572
3573 scope = scope->parent;
3574 }
3575 return nullptr;
3576}
3577
3578static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {3289static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {
3579 while (scope) {3290 while (scope) {
3580 if (scope->id == ScopeIdDeferExpr)3291 if (scope->id == ScopeIdDeferExpr)
...@@ -3604,47 +3315,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode...@@ -3604,47 +3315,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode
3604 return return_inst;3315 return return_inst;
3605 }3316 }
36063317
3607 IrBasicBlock *suspended_block = ir_create_basic_block(irb, scope, "Suspended");3318 zig_panic("TODO async return");
3608 IrBasicBlock *not_suspended_block = ir_create_basic_block(irb, scope, "NotSuspended");
3609 IrBasicBlock *store_awaiter_block = ir_create_basic_block(irb, scope, "StoreAwaiter");
3610 IrBasicBlock *check_canceled_block = ir_create_basic_block(irb, scope, "CheckCanceled");
3611
3612 IrInstruction *inverted_ptr_mask = ir_build_const_usize(irb, scope, node, 0x7); // 0b111
3613 IrInstruction *ptr_mask = ir_build_un_op(irb, scope, node, IrUnOpBinNot, inverted_ptr_mask); // 0b111...000
3614 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001
3615 IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010
3616 IrInstruction *promise_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_promise);
3617 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, false);
3618 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);
3619
3620 ir_build_store_ptr(irb, scope, node, irb->exec->coro_result_field_ptr, return_value);
3621 IrInstruction *usize_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize);
3622 IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,
3623 usize_type_val, irb->exec->atomic_state_field_ptr, nullptr, ptr_mask, nullptr,
3624 AtomicRmwOp_or, AtomicOrderSeqCst);
3625
3626 IrInstruction *is_suspended_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, is_suspended_mask, false);
3627 IrInstruction *is_suspended_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_suspended_value, zero, false);
3628 ir_build_cond_br(irb, scope, node, is_suspended_bool, suspended_block, not_suspended_block, is_comptime);
3629
3630 ir_set_cursor_at_end_and_append_block(irb, suspended_block);
3631 ir_build_unreachable(irb, scope, node);
3632
3633 ir_set_cursor_at_end_and_append_block(irb, not_suspended_block);
3634 IrInstruction *await_handle_addr = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, ptr_mask, false);
3635 // if we ever add null checking safety to the ptrtoint instruction, it needs to be disabled here
3636 IrInstruction *have_await_handle = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, await_handle_addr, zero, false);
3637 ir_build_cond_br(irb, scope, node, have_await_handle, store_awaiter_block, check_canceled_block, is_comptime);
3638
3639 ir_set_cursor_at_end_and_append_block(irb, store_awaiter_block);
3640 IrInstruction *await_handle = ir_build_int_to_ptr(irb, scope, node, promise_type_val, await_handle_addr);
3641 ir_build_store_ptr(irb, scope, node, irb->exec->await_handle_var_ptr, await_handle);
3642 ir_build_br(irb, scope, node, irb->exec->coro_normal_final, is_comptime);
3643
3644 ir_set_cursor_at_end_and_append_block(irb, check_canceled_block);
3645 IrInstruction *is_canceled_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, is_canceled_mask, false);
3646 IrInstruction *is_canceled_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_canceled_value, zero, false);
3647 return ir_build_cond_br(irb, scope, node, is_canceled_bool, irb->exec->coro_final_cleanup_block, irb->exec->coro_early_final, is_comptime);
3648}3319}
36493320
3650static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {3321static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
...@@ -5386,7 +5057,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5386,7 +5057,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5386 FnInline fn_inline = (builtin_fn->id == BuiltinFnIdInlineCall) ? FnInlineAlways : FnInlineNever;5057 FnInline fn_inline = (builtin_fn->id == BuiltinFnIdInlineCall) ? FnInlineAlways : FnInlineNever;
53875058
5388 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false,5059 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false,
5389 fn_inline, false, nullptr, nullptr, result_loc);5060 fn_inline, false, nullptr, result_loc);
5390 return ir_lval_wrap(irb, scope, call, lval, result_loc);5061 return ir_lval_wrap(irb, scope, call, lval, result_loc);
5391 }5062 }
5392 case BuiltinFnIdNewStackCall:5063 case BuiltinFnIdNewStackCall:
...@@ -5417,7 +5088,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5417,7 +5088,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5417 }5088 }
54185089
5419 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false,5090 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false,
5420 FnInlineAuto, false, nullptr, new_stack, result_loc);5091 FnInlineAuto, false, new_stack, result_loc);
5421 return ir_lval_wrap(irb, scope, call, lval, result_loc);5092 return ir_lval_wrap(irb, scope, call, lval, result_loc);
5422 }5093 }
5423 case BuiltinFnIdTypeId:5094 case BuiltinFnIdTypeId:
...@@ -5722,17 +5393,12 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node...@@ -5722,17 +5393,12 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
5722 }5393 }
57235394
5724 bool is_async = node->data.fn_call_expr.is_async;5395 bool is_async = node->data.fn_call_expr.is_async;
5725 IrInstruction *async_allocator = nullptr;
5726 if (is_async) {5396 if (is_async) {
5727 if (node->data.fn_call_expr.async_allocator) {5397 zig_panic("TODO async fn call");
5728 async_allocator = ir_gen_node(irb, node->data.fn_call_expr.async_allocator, scope);
5729 if (async_allocator == irb->codegen->invalid_instruction)
5730 return async_allocator;
5731 }
5732 }5398 }
57335399
5734 IrInstruction *fn_call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false, FnInlineAuto,5400 IrInstruction *fn_call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false, FnInlineAuto,
5735 is_async, async_allocator, nullptr, result_loc);5401 is_async, nullptr, result_loc);
5736 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);5402 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);
5737}5403}
57385404
...@@ -6751,22 +6417,6 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n...@@ -6751,22 +6417,6 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
6751 }6417 }
6752}6418}
67536419
6754static IrInstruction *ir_gen_promise_type(IrBuilder *irb, Scope *scope, AstNode *node) {
6755 assert(node->type == NodeTypePromiseType);
6756
6757 AstNode *payload_type_node = node->data.promise_type.payload_type;
6758 IrInstruction *payload_type_value = nullptr;
6759
6760 if (payload_type_node != nullptr) {
6761 payload_type_value = ir_gen_node(irb, payload_type_node, scope);
6762 if (payload_type_value == irb->codegen->invalid_instruction)
6763 return payload_type_value;
6764
6765 }
6766
6767 return ir_build_promise_type(irb, scope, node, payload_type_value);
6768}
6769
6770static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, Scope *scope, AstNode *node) {6420static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
6771 assert(node->type == NodeTypeUndefinedLiteral);6421 assert(node->type == NodeTypeUndefinedLiteral);
6772 return ir_build_const_undefined(irb, scope, node);6422 return ir_build_const_undefined(irb, scope, node);
...@@ -7969,87 +7619,7 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7969,87 +7619,7 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
7969 //return_type = nullptr;7619 //return_type = nullptr;
7970 }7620 }
79717621
7972 IrInstruction *async_allocator_type_value = nullptr;7622 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, return_type, is_var_args);
7973 if (node->data.fn_proto.async_allocator_type != nullptr) {
7974 async_allocator_type_value = ir_gen_node(irb, node->data.fn_proto.async_allocator_type, parent_scope);
7975 if (async_allocator_type_value == irb->codegen->invalid_instruction)
7976 return irb->codegen->invalid_instruction;
7977 }
7978
7979 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, return_type,
7980 async_allocator_type_value, is_var_args);
7981}
7982
7983static IrInstruction *ir_gen_cancel_target(IrBuilder *irb, Scope *scope, AstNode *node,
7984 IrInstruction *target_inst, bool cancel_non_suspended, bool cancel_awaited)
7985{
7986 IrBasicBlock *done_block = ir_create_basic_block(irb, scope, "CancelDone");
7987 IrBasicBlock *not_canceled_block = ir_create_basic_block(irb, scope, "NotCanceled");
7988 IrBasicBlock *pre_return_block = ir_create_basic_block(irb, scope, "PreReturn");
7989 IrBasicBlock *post_return_block = ir_create_basic_block(irb, scope, "PostReturn");
7990 IrBasicBlock *do_cancel_block = ir_create_basic_block(irb, scope, "DoCancel");
7991
7992 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);
7993 IrInstruction *usize_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize);
7994 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, false);
7995 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001
7996 IrInstruction *promise_T_type_val = ir_build_const_type(irb, scope, node,
7997 get_promise_type(irb->codegen, irb->codegen->builtin_types.entry_void));
7998 IrInstruction *inverted_ptr_mask = ir_build_const_usize(irb, scope, node, 0x7); // 0b111
7999 IrInstruction *ptr_mask = ir_build_un_op(irb, scope, node, IrUnOpBinNot, inverted_ptr_mask); // 0b111...000
8000 IrInstruction *await_mask = ir_build_const_usize(irb, scope, node, 0x4); // 0b100
8001 IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010
8002
8003 // TODO relies on Zig not re-ordering fields
8004 IrInstruction *casted_target_inst = ir_build_ptr_cast_src(irb, scope, node, promise_T_type_val, target_inst,
8005 false);
8006 IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, casted_target_inst);
8007 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
8008 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
8009 atomic_state_field_name, false);
8010
8011 // set the is_canceled bit
8012 IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,
8013 usize_type_val, atomic_state_ptr, nullptr, is_canceled_mask, nullptr,
8014 AtomicRmwOp_or, AtomicOrderSeqCst);
8015
8016 IrInstruction *is_canceled_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, is_canceled_mask, false);
8017 IrInstruction *is_canceled_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_canceled_value, zero, false);
8018 ir_build_cond_br(irb, scope, node, is_canceled_bool, done_block, not_canceled_block, is_comptime);
8019
8020 ir_set_cursor_at_end_and_append_block(irb, not_canceled_block);
8021 IrInstruction *awaiter_addr = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, ptr_mask, false);
8022 IrInstruction *is_returned_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpEq, awaiter_addr, ptr_mask, false);
8023 ir_build_cond_br(irb, scope, node, is_returned_bool, post_return_block, pre_return_block, is_comptime);
8024
8025 ir_set_cursor_at_end_and_append_block(irb, post_return_block);
8026 if (cancel_awaited) {
8027 ir_build_br(irb, scope, node, do_cancel_block, is_comptime);
8028 } else {
8029 IrInstruction *is_awaited_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, await_mask, false);
8030 IrInstruction *is_awaited_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_awaited_value, zero, false);
8031 ir_build_cond_br(irb, scope, node, is_awaited_bool, done_block, do_cancel_block, is_comptime);
8032 }
8033
8034 ir_set_cursor_at_end_and_append_block(irb, pre_return_block);
8035 if (cancel_awaited) {
8036 if (cancel_non_suspended) {
8037 ir_build_br(irb, scope, node, do_cancel_block, is_comptime);
8038 } else {
8039 IrInstruction *is_suspended_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, is_suspended_mask, false);
8040 IrInstruction *is_suspended_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_suspended_value, zero, false);
8041 ir_build_cond_br(irb, scope, node, is_suspended_bool, do_cancel_block, done_block, is_comptime);
8042 }
8043 } else {
8044 ir_build_br(irb, scope, node, done_block, is_comptime);
8045 }
8046
8047 ir_set_cursor_at_end_and_append_block(irb, do_cancel_block);
8048 ir_build_cancel(irb, scope, node, target_inst);
8049 ir_build_br(irb, scope, node, done_block, is_comptime);
8050
8051 ir_set_cursor_at_end_and_append_block(irb, done_block);
8052 return ir_build_const_void(irb, scope, node);
8053}7623}
80547624
8055static IrInstruction *ir_gen_cancel(IrBuilder *irb, Scope *scope, AstNode *node) {7625static IrInstruction *ir_gen_cancel(IrBuilder *irb, Scope *scope, AstNode *node) {
...@@ -8059,57 +7629,7 @@ static IrInstruction *ir_gen_cancel(IrBuilder *irb, Scope *scope, AstNode *node)...@@ -8059,57 +7629,7 @@ static IrInstruction *ir_gen_cancel(IrBuilder *irb, Scope *scope, AstNode *node)
8059 if (target_inst == irb->codegen->invalid_instruction)7629 if (target_inst == irb->codegen->invalid_instruction)
8060 return irb->codegen->invalid_instruction;7630 return irb->codegen->invalid_instruction;
80617631
8062 return ir_gen_cancel_target(irb, scope, node, target_inst, false, true);7632 zig_panic("TODO ir_gen_cancel");
8063}
8064
8065static IrInstruction *ir_gen_resume_target(IrBuilder *irb, Scope *scope, AstNode *node,
8066 IrInstruction *target_inst)
8067{
8068 IrBasicBlock *done_block = ir_create_basic_block(irb, scope, "ResumeDone");
8069 IrBasicBlock *not_canceled_block = ir_create_basic_block(irb, scope, "NotCanceled");
8070 IrBasicBlock *suspended_block = ir_create_basic_block(irb, scope, "IsSuspended");
8071 IrBasicBlock *not_suspended_block = ir_create_basic_block(irb, scope, "IsNotSuspended");
8072
8073 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);
8074 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001
8075 IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010
8076 IrInstruction *and_mask = ir_build_un_op(irb, scope, node, IrUnOpBinNot, is_suspended_mask);
8077 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, false);
8078 IrInstruction *usize_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize);
8079 IrInstruction *promise_T_type_val = ir_build_const_type(irb, scope, node,
8080 get_promise_type(irb->codegen, irb->codegen->builtin_types.entry_void));
8081
8082 // TODO relies on Zig not re-ordering fields
8083 IrInstruction *casted_target_inst = ir_build_ptr_cast_src(irb, scope, node, promise_T_type_val, target_inst,
8084 false);
8085 IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, casted_target_inst);
8086 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
8087 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
8088 atomic_state_field_name, false);
8089
8090 // clear the is_suspended bit
8091 IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,
8092 usize_type_val, atomic_state_ptr, nullptr, and_mask, nullptr,
8093 AtomicRmwOp_and, AtomicOrderSeqCst);
8094
8095 IrInstruction *is_canceled_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, is_canceled_mask, false);
8096 IrInstruction *is_canceled_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_canceled_value, zero, false);
8097 ir_build_cond_br(irb, scope, node, is_canceled_bool, done_block, not_canceled_block, is_comptime);
8098
8099 ir_set_cursor_at_end_and_append_block(irb, not_canceled_block);
8100 IrInstruction *is_suspended_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, is_suspended_mask, false);
8101 IrInstruction *is_suspended_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_suspended_value, zero, false);
8102 ir_build_cond_br(irb, scope, node, is_suspended_bool, suspended_block, not_suspended_block, is_comptime);
8103
8104 ir_set_cursor_at_end_and_append_block(irb, not_suspended_block);
8105 ir_build_unreachable(irb, scope, node);
8106
8107 ir_set_cursor_at_end_and_append_block(irb, suspended_block);
8108 ir_build_coro_resume(irb, scope, node, target_inst);
8109 ir_build_br(irb, scope, node, done_block, is_comptime);
8110
8111 ir_set_cursor_at_end_and_append_block(irb, done_block);
8112 return ir_build_const_void(irb, scope, node);
8113}7633}
81147634
8115static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) {7635static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) {
...@@ -8119,7 +7639,7 @@ static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node)...@@ -8119,7 +7639,7 @@ static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node)
8119 if (target_inst == irb->codegen->invalid_instruction)7639 if (target_inst == irb->codegen->invalid_instruction)
8120 return irb->codegen->invalid_instruction;7640 return irb->codegen->invalid_instruction;
81217641
8122 return ir_gen_resume_target(irb, scope, node, target_inst);7642 zig_panic("TODO ir_gen_resume");
8123}7643}
81247644
8125static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *node) {7645static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
...@@ -8129,298 +7649,13 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -8129,298 +7649,13 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
8129 if (target_inst == irb->codegen->invalid_instruction)7649 if (target_inst == irb->codegen->invalid_instruction)
8130 return irb->codegen->invalid_instruction;7650 return irb->codegen->invalid_instruction;
81317651
8132 ZigFn *fn_entry = exec_fn_entry(irb->exec);7652 zig_panic("TODO ir_gen_await_expr");
8133 if (!fn_entry) {
8134 add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));
8135 return irb->codegen->invalid_instruction;
8136 }
8137 if (fn_entry->type_entry->data.fn.fn_type_id.cc != CallingConventionAsync) {
8138 add_node_error(irb->codegen, node, buf_sprintf("await in non-async function"));
8139 return irb->codegen->invalid_instruction;
8140 }
8141
8142 ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope);
8143 if (scope_defer_expr) {
8144 if (!scope_defer_expr->reported_err) {
8145 add_node_error(irb->codegen, node, buf_sprintf("cannot await inside defer expression"));
8146 scope_defer_expr->reported_err = true;
8147 }
8148 return irb->codegen->invalid_instruction;
8149 }
8150
8151 Scope *outer_scope = irb->exec->begin_scope;
8152
8153 IrInstruction *coro_promise_ptr = ir_build_coro_promise(irb, scope, node, target_inst);
8154 Buf *result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME);
8155 IrInstruction *result_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_ptr_field_name, false);
8156
8157 if (irb->codegen->have_err_ret_tracing) {
8158 IrInstruction *err_ret_trace_ptr = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::NonNull);
8159 Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME);
8160 IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name, false);
8161 ir_build_store_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr, err_ret_trace_ptr);
8162 }
8163
8164 IrBasicBlock *already_awaited_block = ir_create_basic_block(irb, scope, "AlreadyAwaited");
8165 IrBasicBlock *not_awaited_block = ir_create_basic_block(irb, scope, "NotAwaited");
8166 IrBasicBlock *not_canceled_block = ir_create_basic_block(irb, scope, "NotCanceled");
8167 IrBasicBlock *yes_suspend_block = ir_create_basic_block(irb, scope, "YesSuspend");
8168 IrBasicBlock *no_suspend_block = ir_create_basic_block(irb, scope, "NoSuspend");
8169 IrBasicBlock *merge_block = ir_create_basic_block(irb, scope, "MergeSuspend");
8170 IrBasicBlock *cleanup_block = ir_create_basic_block(irb, scope, "SuspendCleanup");
8171 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "SuspendResume");
8172 IrBasicBlock *cancel_target_block = ir_create_basic_block(irb, scope, "CancelTarget");
8173 IrBasicBlock *do_cancel_block = ir_create_basic_block(irb, scope, "DoCancel");
8174 IrBasicBlock *do_defers_block = ir_create_basic_block(irb, scope, "DoDefers");
8175 IrBasicBlock *destroy_block = ir_create_basic_block(irb, scope, "DestroyBlock");
8176 IrBasicBlock *my_suspended_block = ir_create_basic_block(irb, scope, "AlreadySuspended");
8177 IrBasicBlock *my_not_suspended_block = ir_create_basic_block(irb, scope, "NotAlreadySuspended");
8178 IrBasicBlock *do_suspend_block = ir_create_basic_block(irb, scope, "DoSuspend");
8179
8180 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
8181 IrInstruction *atomic_state_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
8182 atomic_state_field_name, false);
8183
8184 IrInstruction *promise_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_promise);
8185 IrInstruction *const_bool_false = ir_build_const_bool(irb, scope, node, false);
8186 IrInstruction *undef = ir_build_const_undefined(irb, scope, node);
8187 IrInstruction *usize_type_val = ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_usize);
8188 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);
8189 IrInstruction *inverted_ptr_mask = ir_build_const_usize(irb, scope, node, 0x7); // 0b111
8190 IrInstruction *ptr_mask = ir_build_un_op(irb, scope, node, IrUnOpBinNot, inverted_ptr_mask); // 0b111...000
8191 IrInstruction *await_mask = ir_build_const_usize(irb, scope, node, 0x4); // 0b100
8192 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001
8193 IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010
8194
8195 ZigVar *result_var = ir_create_var(irb, node, scope, nullptr,
8196 false, false, true, const_bool_false);
8197 IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst);
8198 IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type);
8199 ir_build_await_bookkeeping(irb, scope, node, promise_result_type);
8200 IrInstruction *undef_promise_result = ir_build_implicit_cast(irb, scope, node, promise_result_type, undef, nullptr);
8201 build_decl_var_and_init(irb, scope, node, result_var, undef_promise_result, "result", const_bool_false);
8202 IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, scope, node, result_var);
8203 ir_build_store_ptr(irb, scope, node, result_ptr_field_ptr, my_result_var_ptr);
8204 IrInstruction *save_token = ir_build_coro_save(irb, scope, node, irb->exec->coro_handle);
8205
8206 IrInstruction *coro_handle_addr = ir_build_ptr_to_int(irb, scope, node, irb->exec->coro_handle);
8207 IrInstruction *mask_bits = ir_build_bin_op(irb, scope, node, IrBinOpBinOr, coro_handle_addr, await_mask, false);
8208 IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,
8209 usize_type_val, atomic_state_ptr, nullptr, mask_bits, nullptr,
8210 AtomicRmwOp_or, AtomicOrderSeqCst);
8211
8212 IrInstruction *is_awaited_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, await_mask, false);
8213 IrInstruction *is_awaited_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_awaited_value, zero, false);
8214 ir_build_cond_br(irb, scope, node, is_awaited_bool, already_awaited_block, not_awaited_block, const_bool_false);
8215
8216 ir_set_cursor_at_end_and_append_block(irb, already_awaited_block);
8217 ir_build_unreachable(irb, scope, node);
8218
8219 ir_set_cursor_at_end_and_append_block(irb, not_awaited_block);
8220 IrInstruction *await_handle_addr = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, ptr_mask, false);
8221 IrInstruction *is_non_null = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, await_handle_addr, zero, false);
8222 IrInstruction *is_canceled_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, prev_atomic_value, is_canceled_mask, false);
8223 IrInstruction *is_canceled_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, is_canceled_value, zero, false);
8224 ir_build_cond_br(irb, scope, node, is_canceled_bool, cancel_target_block, not_canceled_block, const_bool_false);
8225
8226 ir_set_cursor_at_end_and_append_block(irb, not_canceled_block);
8227 ir_build_cond_br(irb, scope, node, is_non_null, no_suspend_block, yes_suspend_block, const_bool_false);
8228
8229 ir_set_cursor_at_end_and_append_block(irb, cancel_target_block);
8230 ir_build_cancel(irb, scope, node, target_inst);
8231 ir_mark_gen(ir_build_br(irb, scope, node, cleanup_block, const_bool_false));
8232
8233 ir_set_cursor_at_end_and_append_block(irb, no_suspend_block);
8234 if (irb->codegen->have_err_ret_tracing) {
8235 Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME);
8236 IrInstruction *src_err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name, false);
8237 IrInstruction *dest_err_ret_trace_ptr = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::NonNull);
8238 ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, src_err_ret_trace_ptr, dest_err_ret_trace_ptr);
8239 }
8240 Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME);
8241 IrInstruction *promise_result_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_field_name, false);
8242 // If the type of the result handle_is_ptr then this does not actually perform a load. But we need it to,
8243 // because we're about to destroy the memory. So we store it into our result variable.
8244 IrInstruction *no_suspend_result = ir_build_load_ptr(irb, scope, node, promise_result_ptr);
8245 ir_build_store_ptr(irb, scope, node, my_result_var_ptr, no_suspend_result);
8246 ir_build_cancel(irb, scope, node, target_inst);
8247 ir_build_br(irb, scope, node, merge_block, const_bool_false);
8248
8249
8250 ir_set_cursor_at_end_and_append_block(irb, yes_suspend_block);
8251 IrInstruction *my_prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,
8252 usize_type_val, irb->exec->atomic_state_field_ptr, nullptr, is_suspended_mask, nullptr,
8253 AtomicRmwOp_or, AtomicOrderSeqCst);
8254 IrInstruction *my_is_suspended_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, my_prev_atomic_value, is_suspended_mask, false);
8255 IrInstruction *my_is_suspended_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, my_is_suspended_value, zero, false);
8256 ir_build_cond_br(irb, scope, node, my_is_suspended_bool, my_suspended_block, my_not_suspended_block, const_bool_false);
8257
8258 ir_set_cursor_at_end_and_append_block(irb, my_suspended_block);
8259 ir_build_unreachable(irb, scope, node);
8260
8261 ir_set_cursor_at_end_and_append_block(irb, my_not_suspended_block);
8262 IrInstruction *my_is_canceled_value = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, my_prev_atomic_value, is_canceled_mask, false);
8263 IrInstruction *my_is_canceled_bool = ir_build_bin_op(irb, scope, node, IrBinOpCmpNotEq, my_is_canceled_value, zero, false);
8264 ir_build_cond_br(irb, scope, node, my_is_canceled_bool, cleanup_block, do_suspend_block, const_bool_false);
8265
8266 ir_set_cursor_at_end_and_append_block(irb, do_suspend_block);
8267 IrInstruction *suspend_code = ir_build_coro_suspend(irb, scope, node, save_token, const_bool_false);
8268
8269 IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(2);
8270 cases[0].value = ir_build_const_u8(irb, scope, node, 0);
8271 cases[0].block = resume_block;
8272 cases[1].value = ir_build_const_u8(irb, scope, node, 1);
8273 cases[1].block = destroy_block;
8274 ir_build_switch_br(irb, scope, node, suspend_code, irb->exec->coro_suspend_block,
8275 2, cases, const_bool_false, nullptr);
8276
8277 ir_set_cursor_at_end_and_append_block(irb, destroy_block);
8278 ir_gen_cancel_target(irb, scope, node, target_inst, false, true);
8279 ir_mark_gen(ir_build_br(irb, scope, node, cleanup_block, const_bool_false));
8280
8281 ir_set_cursor_at_end_and_append_block(irb, cleanup_block);
8282 IrInstruction *my_mask_bits = ir_build_bin_op(irb, scope, node, IrBinOpBinOr, ptr_mask, is_canceled_mask, false);
8283 IrInstruction *b_my_prev_atomic_value = ir_build_atomic_rmw(irb, scope, node,
8284 usize_type_val, irb->exec->atomic_state_field_ptr, nullptr, my_mask_bits, nullptr,
8285 AtomicRmwOp_or, AtomicOrderSeqCst);
8286 IrInstruction *my_await_handle_addr = ir_build_bin_op(irb, scope, node, IrBinOpBinAnd, b_my_prev_atomic_value, ptr_mask, false);
8287 IrInstruction *dont_have_my_await_handle = ir_build_bin_op(irb, scope, node, IrBinOpCmpEq, my_await_handle_addr, zero, false);
8288 IrInstruction *dont_destroy_ourselves = ir_build_bin_op(irb, scope, node, IrBinOpBoolAnd, dont_have_my_await_handle, is_canceled_bool, false);
8289 ir_build_cond_br(irb, scope, node, dont_have_my_await_handle, do_defers_block, do_cancel_block, const_bool_false);
8290
8291 ir_set_cursor_at_end_and_append_block(irb, do_cancel_block);
8292 IrInstruction *my_await_handle = ir_build_int_to_ptr(irb, scope, node, promise_type_val, my_await_handle_addr);
8293 ir_gen_cancel_target(irb, scope, node, my_await_handle, true, false);
8294 ir_mark_gen(ir_build_br(irb, scope, node, do_defers_block, const_bool_false));
8295
8296 ir_set_cursor_at_end_and_append_block(irb, do_defers_block);
8297 ir_gen_defers_for_block(irb, scope, outer_scope, true);
8298 ir_mark_gen(ir_build_cond_br(irb, scope, node, dont_destroy_ourselves, irb->exec->coro_early_final, irb->exec->coro_final_cleanup_block, const_bool_false));
8299
8300 ir_set_cursor_at_end_and_append_block(irb, resume_block);
8301 ir_build_br(irb, scope, node, merge_block, const_bool_false);
8302
8303 ir_set_cursor_at_end_and_append_block(irb, merge_block);
8304 return ir_build_load_ptr(irb, scope, node, my_result_var_ptr);
8305}7653}
83067654
8307static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) {7655static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
8308 assert(node->type == NodeTypeSuspend);7656 assert(node->type == NodeTypeSuspend);
83097657
8310 ZigFn *fn_entry = exec_fn_entry(irb->exec);7658 zig_panic("TODO ir_gen_suspend");
8311 if (!fn_entry) {
8312 add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));
8313 return irb->codegen->invalid_instruction;
8314 }
8315 if (fn_entry->type_entry->data.fn.fn_type_id.cc != CallingConventionAsync) {
8316 add_node_error(irb->codegen, node, buf_sprintf("suspend in non-async function"));
8317 return irb->codegen->invalid_instruction;
8318 }
8319
8320 ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(parent_scope);
8321 if (scope_defer_expr) {
8322 if (!scope_defer_expr->reported_err) {
8323 ErrorMsg *msg = add_node_error(irb->codegen, node, buf_sprintf("cannot suspend inside defer expression"));
8324 add_error_note(irb->codegen, msg, scope_defer_expr->base.source_node, buf_sprintf("defer here"));
8325 scope_defer_expr->reported_err = true;
8326 }
8327 return irb->codegen->invalid_instruction;
8328 }
8329 ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope);
8330 if (existing_suspend_scope) {
8331 if (!existing_suspend_scope->reported_err) {
8332 ErrorMsg *msg = add_node_error(irb->codegen, node, buf_sprintf("cannot suspend inside suspend block"));
8333 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here"));
8334 existing_suspend_scope->reported_err = true;
8335 }
8336 return irb->codegen->invalid_instruction;
8337 }
8338
8339 Scope *outer_scope = irb->exec->begin_scope;
8340
8341 IrBasicBlock *cleanup_block = ir_create_basic_block(irb, parent_scope, "SuspendCleanup");
8342 IrBasicBlock *resume_block = ir_create_basic_block(irb, parent_scope, "SuspendResume");
8343 IrBasicBlock *suspended_block = ir_create_basic_block(irb, parent_scope, "AlreadySuspended");
8344 IrBasicBlock *canceled_block = ir_create_basic_block(irb, parent_scope, "IsCanceled");
8345 IrBasicBlock *not_canceled_block = ir_create_basic_block(irb, parent_scope, "NotCanceled");
8346 IrBasicBlock *not_suspended_block = ir_create_basic_block(irb, parent_scope, "NotAlreadySuspended");
8347 IrBasicBlock *cancel_awaiter_block = ir_create_basic_block(irb, parent_scope, "CancelAwaiter");
8348
8349 IrInstruction *promise_type_val = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_promise);
8350 IrInstruction *const_bool_true = ir_build_const_bool(irb, parent_scope, node, true);
8351 IrInstruction *const_bool_false = ir_build_const_bool(irb, parent_scope, node, false);
8352 IrInstruction *usize_type_val = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_usize);
8353 IrInstruction *is_canceled_mask = ir_build_const_usize(irb, parent_scope, node, 0x1); // 0b001
8354 IrInstruction *is_suspended_mask = ir_build_const_usize(irb, parent_scope, node, 0x2); // 0b010
8355 IrInstruction *zero = ir_build_const_usize(irb, parent_scope, node, 0);
8356 IrInstruction *inverted_ptr_mask = ir_build_const_usize(irb, parent_scope, node, 0x7); // 0b111
8357 IrInstruction *ptr_mask = ir_build_un_op(irb, parent_scope, node, IrUnOpBinNot, inverted_ptr_mask); // 0b111...000
8358
8359 IrInstruction *prev_atomic_value = ir_build_atomic_rmw(irb, parent_scope, node,
8360 usize_type_val, irb->exec->atomic_state_field_ptr, nullptr, is_suspended_mask, nullptr,
8361 AtomicRmwOp_or, AtomicOrderSeqCst);
8362
8363 IrInstruction *is_canceled_value = ir_build_bin_op(irb, parent_scope, node, IrBinOpBinAnd, prev_atomic_value, is_canceled_mask, false);
8364 IrInstruction *is_canceled_bool = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpNotEq, is_canceled_value, zero, false);
8365 ir_build_cond_br(irb, parent_scope, node, is_canceled_bool, canceled_block, not_canceled_block, const_bool_false);
8366
8367 ir_set_cursor_at_end_and_append_block(irb, canceled_block);
8368 IrInstruction *await_handle_addr = ir_build_bin_op(irb, parent_scope, node, IrBinOpBinAnd, prev_atomic_value, ptr_mask, false);
8369 IrInstruction *have_await_handle = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpNotEq, await_handle_addr, zero, false);
8370 IrBasicBlock *post_canceled_block = irb->current_basic_block;
8371 ir_build_cond_br(irb, parent_scope, node, have_await_handle, cancel_awaiter_block, cleanup_block, const_bool_false);
8372
8373 ir_set_cursor_at_end_and_append_block(irb, cancel_awaiter_block);
8374 IrInstruction *await_handle = ir_build_int_to_ptr(irb, parent_scope, node, promise_type_val, await_handle_addr);
8375 ir_gen_cancel_target(irb, parent_scope, node, await_handle, true, false);
8376 IrBasicBlock *post_cancel_awaiter_block = irb->current_basic_block;
8377 ir_build_br(irb, parent_scope, node, cleanup_block, const_bool_false);
8378
8379 ir_set_cursor_at_end_and_append_block(irb, not_canceled_block);
8380 IrInstruction *is_suspended_value = ir_build_bin_op(irb, parent_scope, node, IrBinOpBinAnd, prev_atomic_value, is_suspended_mask, false);
8381 IrInstruction *is_suspended_bool = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpNotEq, is_suspended_value, zero, false);
8382 ir_build_cond_br(irb, parent_scope, node, is_suspended_bool, suspended_block, not_suspended_block, const_bool_false);
8383
8384 ir_set_cursor_at_end_and_append_block(irb, suspended_block);
8385 ir_build_unreachable(irb, parent_scope, node);
8386
8387 ir_set_cursor_at_end_and_append_block(irb, not_suspended_block);
8388 IrInstruction *suspend_code;
8389 if (node->data.suspend.block == nullptr) {
8390 suspend_code = ir_build_coro_suspend(irb, parent_scope, node, nullptr, const_bool_false);
8391 } else {
8392 Scope *child_scope;
8393 ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope);
8394 suspend_scope->resume_block = resume_block;
8395 child_scope = &suspend_scope->base;
8396 IrInstruction *save_token = ir_build_coro_save(irb, child_scope, node, irb->exec->coro_handle);
8397 ir_gen_node(irb, node->data.suspend.block, child_scope);
8398 suspend_code = ir_mark_gen(ir_build_coro_suspend(irb, parent_scope, node, save_token, const_bool_false));
8399 }
8400
8401 IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(2);
8402 cases[0].value = ir_mark_gen(ir_build_const_u8(irb, parent_scope, node, 0));
8403 cases[0].block = resume_block;
8404 cases[1].value = ir_mark_gen(ir_build_const_u8(irb, parent_scope, node, 1));
8405 cases[1].block = canceled_block;
8406 IrInstructionSwitchBr *switch_br = ir_build_switch_br(irb, parent_scope, node, suspend_code,
8407 irb->exec->coro_suspend_block, 2, cases, const_bool_false, nullptr);
8408 ir_mark_gen(&switch_br->base);
8409
8410 ir_set_cursor_at_end_and_append_block(irb, cleanup_block);
8411 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2);
8412 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
8413 incoming_blocks[0] = post_canceled_block;
8414 incoming_values[0] = const_bool_true;
8415 incoming_blocks[1] = post_cancel_awaiter_block;
8416 incoming_values[1] = const_bool_false;
8417 IrInstruction *destroy_ourselves = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values,
8418 nullptr);
8419 ir_gen_defers_for_block(irb, parent_scope, outer_scope, true);
8420 ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, destroy_ourselves, irb->exec->coro_final_cleanup_block, irb->exec->coro_early_final, const_bool_false));
8421
8422 ir_set_cursor_at_end_and_append_block(irb, resume_block);
8423 return ir_mark_gen(ir_build_const_void(irb, parent_scope, node));
8424}7659}
84257660
8426static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,7661static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,
...@@ -8512,8 +7747,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -8512,8 +7747,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
8512 return ir_lval_wrap(irb, scope, ir_gen_array_type(irb, scope, node), lval, result_loc);7747 return ir_lval_wrap(irb, scope, ir_gen_array_type(irb, scope, node), lval, result_loc);
8513 case NodeTypePointerType:7748 case NodeTypePointerType:
8514 return ir_lval_wrap(irb, scope, ir_gen_pointer_type(irb, scope, node), lval, result_loc);7749 return ir_lval_wrap(irb, scope, ir_gen_pointer_type(irb, scope, node), lval, result_loc);
8515 case NodeTypePromiseType:
8516 return ir_lval_wrap(irb, scope, ir_gen_promise_type(irb, scope, node), lval, result_loc);
8517 case NodeTypeStringLiteral:7750 case NodeTypeStringLiteral:
8518 return ir_lval_wrap(irb, scope, ir_gen_string_literal(irb, scope, node), lval, result_loc);7751 return ir_lval_wrap(irb, scope, ir_gen_string_literal(irb, scope, node), lval, result_loc);
8519 case NodeTypeUndefinedLiteral:7752 case NodeTypeUndefinedLiteral:
...@@ -8624,105 +7857,8 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -8624,105 +7857,8 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
8624 ZigFn *fn_entry = exec_fn_entry(irb->exec);7857 ZigFn *fn_entry = exec_fn_entry(irb->exec);
86257858
8626 bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;7859 bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
8627 IrInstruction *coro_id;
8628 IrInstruction *u8_ptr_type;
8629 IrInstruction *const_bool_false;
8630 IrInstruction *coro_promise_ptr;
8631 IrInstruction *err_ret_trace_ptr;
8632 ZigType *return_type;
8633 Buf *result_ptr_field_name;
8634 ZigVar *coro_size_var;
8635 if (is_async) {7860 if (is_async) {
8636 // create the coro promise7861 zig_panic("ir_gen async fn");
8637 Scope *coro_scope = create_coro_prelude_scope(irb->codegen, node, scope);
8638 const_bool_false = ir_build_const_bool(irb, coro_scope, node, false);
8639 ZigVar *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
8640
8641 return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
8642 IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node);
8643 // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa
8644 ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type);
8645 IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type);
8646 IrInstruction *undef_coro_frame = ir_build_implicit_cast(irb, coro_scope, node, coro_frame_type_value, undef, nullptr);
8647 build_decl_var_and_init(irb, coro_scope, node, promise_var, undef_coro_frame, "promise", const_bool_false);
8648 coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var);
8649
8650 ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
8651 IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node);
8652 IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node,
8653 get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise));
8654 IrInstruction *null_await_handle = ir_build_implicit_cast(irb, coro_scope, node, await_handle_type_val, null_value, nullptr);
8655 build_decl_var_and_init(irb, coro_scope, node, await_handle_var, null_await_handle, "await_handle", const_bool_false);
8656 irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var);
8657
8658 u8_ptr_type = ir_build_const_type(irb, coro_scope, node,
8659 get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_u8, false));
8660 IrInstruction *promise_as_u8_ptr = ir_build_ptr_cast_src(irb, coro_scope, node, u8_ptr_type,
8661 coro_promise_ptr, false);
8662 coro_id = ir_build_coro_id(irb, coro_scope, node, promise_as_u8_ptr);
8663 coro_size_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false);
8664 IrInstruction *coro_size = ir_build_coro_size(irb, coro_scope, node);
8665 build_decl_var_and_init(irb, coro_scope, node, coro_size_var, coro_size, "coro_size", const_bool_false);
8666 IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, coro_scope, node,
8667 ImplicitAllocatorIdArg);
8668 irb->exec->coro_allocator_var = ir_create_var(irb, node, coro_scope, nullptr, true, true, true, const_bool_false);
8669 build_decl_var_and_init(irb, coro_scope, node, irb->exec->coro_allocator_var, implicit_allocator_ptr,
8670 "allocator", const_bool_false);
8671 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);
8672 IrInstruction *realloc_fn_ptr = ir_build_field_ptr(irb, coro_scope, node, implicit_allocator_ptr, realloc_field_name, false);
8673 IrInstruction *realloc_fn = ir_build_load_ptr(irb, coro_scope, node, realloc_fn_ptr);
8674 IrInstruction *maybe_coro_mem_ptr = ir_build_coro_alloc_helper(irb, coro_scope, node, realloc_fn, coro_size);
8675 IrInstruction *alloc_result_is_ok = ir_build_test_nonnull(irb, coro_scope, node, maybe_coro_mem_ptr);
8676 IrBasicBlock *alloc_err_block = ir_create_basic_block(irb, coro_scope, "AllocError");
8677 IrBasicBlock *alloc_ok_block = ir_create_basic_block(irb, coro_scope, "AllocOk");
8678 ir_build_cond_br(irb, coro_scope, node, alloc_result_is_ok, alloc_ok_block, alloc_err_block, const_bool_false);
8679
8680 ir_set_cursor_at_end_and_append_block(irb, alloc_err_block);
8681 // we can return undefined here, because the caller passes a pointer to the error struct field
8682 // in the error union result, and we populate it in case of allocation failure.
8683 ir_build_return(irb, coro_scope, node, undef);
8684
8685 ir_set_cursor_at_end_and_append_block(irb, alloc_ok_block);
8686 IrInstruction *coro_mem_ptr = ir_build_ptr_cast_src(irb, coro_scope, node, u8_ptr_type, maybe_coro_mem_ptr,
8687 false);
8688 irb->exec->coro_handle = ir_build_coro_begin(irb, coro_scope, node, coro_id, coro_mem_ptr);
8689
8690 Buf *atomic_state_field_name = buf_create_from_str(ATOMIC_STATE_FIELD_NAME);
8691 irb->exec->atomic_state_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr,
8692 atomic_state_field_name, false);
8693 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);
8694 ir_build_store_ptr(irb, scope, node, irb->exec->atomic_state_field_ptr, zero);
8695 Buf *result_field_name = buf_create_from_str(RESULT_FIELD_NAME);
8696 irb->exec->coro_result_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_field_name, false);
8697 result_ptr_field_name = buf_create_from_str(RESULT_PTR_FIELD_NAME);
8698 irb->exec->coro_result_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, result_ptr_field_name, false);
8699 ir_build_store_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr, irb->exec->coro_result_field_ptr);
8700 if (irb->codegen->have_err_ret_tracing) {
8701 // initialize the error return trace
8702 Buf *return_addresses_field_name = buf_create_from_str(RETURN_ADDRESSES_FIELD_NAME);
8703 IrInstruction *return_addresses_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, return_addresses_field_name, false);
8704
8705 Buf *err_ret_trace_field_name = buf_create_from_str(ERR_RET_TRACE_FIELD_NAME);
8706 err_ret_trace_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_field_name, false);
8707 ir_build_mark_err_ret_trace_ptr(irb, scope, node, err_ret_trace_ptr);
8708
8709 // coordinate with builtin.zig
8710 Buf *index_name = buf_create_from_str("index");
8711 IrInstruction *index_ptr = ir_build_field_ptr(irb, scope, node, err_ret_trace_ptr, index_name, false);
8712 ir_build_store_ptr(irb, scope, node, index_ptr, zero);
8713
8714 Buf *instruction_addresses_name = buf_create_from_str("instruction_addresses");
8715 IrInstruction *addrs_slice_ptr = ir_build_field_ptr(irb, scope, node, err_ret_trace_ptr, instruction_addresses_name, false);
8716
8717 IrInstruction *slice_value = ir_build_slice_src(irb, scope, node, return_addresses_ptr, zero, nullptr, false, no_result_loc());
8718 ir_build_store_ptr(irb, scope, node, addrs_slice_ptr, slice_value);
8719 }
8720
8721
8722 irb->exec->coro_early_final = ir_create_basic_block(irb, scope, "CoroEarlyFinal");
8723 irb->exec->coro_normal_final = ir_create_basic_block(irb, scope, "CoroNormalFinal");
8724 irb->exec->coro_suspend_block = ir_create_basic_block(irb, scope, "Suspend");
8725 irb->exec->coro_final_cleanup_block = ir_create_basic_block(irb, scope, "FinalCleanup");
8726 }7862 }
87277863
8728 IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);7864 IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
...@@ -8735,117 +7871,6 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -8735,117 +7871,6 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
8735 ir_gen_async_return(irb, scope, result->source_node, result, true);7871 ir_gen_async_return(irb, scope, result->source_node, result, true);
8736 }7872 }
87377873
8738 if (is_async) {
8739 IrBasicBlock *invalid_resume_block = ir_create_basic_block(irb, scope, "InvalidResume");
8740 IrBasicBlock *check_free_block = ir_create_basic_block(irb, scope, "CheckFree");
8741
8742 ir_set_cursor_at_end_and_append_block(irb, irb->exec->coro_early_final);
8743 IrInstruction *const_bool_true = ir_build_const_bool(irb, scope, node, true);
8744 IrInstruction *suspend_code = ir_build_coro_suspend(irb, scope, node, nullptr, const_bool_true);
8745 IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(2);
8746 cases[0].value = ir_build_const_u8(irb, scope, node, 0);
8747 cases[0].block = invalid_resume_block;
8748 cases[1].value = ir_build_const_u8(irb, scope, node, 1);
8749 cases[1].block = irb->exec->coro_final_cleanup_block;
8750 ir_build_switch_br(irb, scope, node, suspend_code, irb->exec->coro_suspend_block, 2, cases, const_bool_false, nullptr);
8751
8752 ir_set_cursor_at_end_and_append_block(irb, irb->exec->coro_suspend_block);
8753 ir_build_coro_end(irb, scope, node);
8754 ir_build_return(irb, scope, node, irb->exec->coro_handle);
8755
8756 ir_set_cursor_at_end_and_append_block(irb, invalid_resume_block);
8757 ir_build_unreachable(irb, scope, node);
8758
8759 ir_set_cursor_at_end_and_append_block(irb, irb->exec->coro_normal_final);
8760 if (type_has_bits(return_type)) {
8761 IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node,
8762 get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8,
8763 false, false, PtrLenUnknown, 0, 0, 0, false));
8764 IrInstruction *result_ptr = ir_build_load_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr);
8765 IrInstruction *result_ptr_as_u8_ptr = ir_build_ptr_cast_src(irb, scope, node, u8_ptr_type_unknown_len,
8766 result_ptr, false);
8767 IrInstruction *return_value_ptr_as_u8_ptr = ir_build_ptr_cast_src(irb, scope, node,
8768 u8_ptr_type_unknown_len, irb->exec->coro_result_field_ptr, false);
8769 IrInstruction *return_type_inst = ir_build_const_type(irb, scope, node,
8770 fn_entry->type_entry->data.fn.fn_type_id.return_type);
8771 IrInstruction *size_of_ret_val = ir_build_size_of(irb, scope, node, return_type_inst);
8772 ir_build_memcpy(irb, scope, node, result_ptr_as_u8_ptr, return_value_ptr_as_u8_ptr, size_of_ret_val);
8773 }
8774 if (irb->codegen->have_err_ret_tracing) {
8775 Buf *err_ret_trace_ptr_field_name = buf_create_from_str(ERR_RET_TRACE_PTR_FIELD_NAME);
8776 IrInstruction *err_ret_trace_ptr_field_ptr = ir_build_field_ptr(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr_field_name, false);
8777 IrInstruction *dest_err_ret_trace_ptr = ir_build_load_ptr(irb, scope, node, err_ret_trace_ptr_field_ptr);
8778 ir_build_merge_err_ret_traces(irb, scope, node, coro_promise_ptr, err_ret_trace_ptr, dest_err_ret_trace_ptr);
8779 }
8780 // Before we destroy the coroutine frame, we need to load the target promise into
8781 // a register or local variable which does not get spilled into the frame,
8782 // otherwise llvm tries to access memory inside the destroyed frame.
8783 IrInstruction *unwrapped_await_handle_ptr = ir_build_optional_unwrap_ptr(irb, scope, node,
8784 irb->exec->await_handle_var_ptr, false, false);
8785 IrInstruction *await_handle_in_block = ir_build_load_ptr(irb, scope, node, unwrapped_await_handle_ptr);
8786 ir_build_br(irb, scope, node, check_free_block, const_bool_false);
8787
8788 ir_set_cursor_at_end_and_append_block(irb, irb->exec->coro_final_cleanup_block);
8789 ir_build_br(irb, scope, node, check_free_block, const_bool_false);
8790
8791 ir_set_cursor_at_end_and_append_block(irb, check_free_block);
8792 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2);
8793 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
8794 incoming_blocks[0] = irb->exec->coro_final_cleanup_block;
8795 incoming_values[0] = const_bool_false;
8796 incoming_blocks[1] = irb->exec->coro_normal_final;
8797 incoming_values[1] = const_bool_true;
8798 IrInstruction *resume_awaiter = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);
8799
8800 IrBasicBlock **merge_incoming_blocks = allocate<IrBasicBlock *>(2);
8801 IrInstruction **merge_incoming_values = allocate<IrInstruction *>(2);
8802 merge_incoming_blocks[0] = irb->exec->coro_final_cleanup_block;
8803 merge_incoming_values[0] = ir_build_const_undefined(irb, scope, node);
8804 merge_incoming_blocks[1] = irb->exec->coro_normal_final;
8805 merge_incoming_values[1] = await_handle_in_block;
8806 IrInstruction *awaiter_handle = ir_build_phi(irb, scope, node, 2, merge_incoming_blocks, merge_incoming_values, nullptr);
8807
8808 Buf *shrink_field_name = buf_create_from_str(ASYNC_SHRINK_FIELD_NAME);
8809 IrInstruction *implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, scope, node,
8810 ImplicitAllocatorIdLocalVar);
8811 IrInstruction *shrink_fn_ptr = ir_build_field_ptr(irb, scope, node, implicit_allocator_ptr, shrink_field_name, false);
8812 IrInstruction *shrink_fn = ir_build_load_ptr(irb, scope, node, shrink_fn_ptr);
8813 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);
8814 IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle);
8815 IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node,
8816 get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8,
8817 false, false, PtrLenUnknown, 0, 0, 0, false));
8818 IrInstruction *coro_mem_ptr = ir_build_ptr_cast_src(irb, scope, node, u8_ptr_type_unknown_len,
8819 coro_mem_ptr_maybe, false);
8820 IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false);
8821 IrInstruction *coro_size_ptr = ir_build_var_ptr(irb, scope, node, coro_size_var);
8822 IrInstruction *coro_size = ir_build_load_ptr(irb, scope, node, coro_size_ptr);
8823 IrInstruction *mem_slice = ir_build_slice_src(irb, scope, node, coro_mem_ptr_ref, zero, coro_size, false,
8824 no_result_loc());
8825 size_t arg_count = 5;
8826 IrInstruction **args = allocate<IrInstruction *>(arg_count);
8827 args[0] = implicit_allocator_ptr; // self
8828 args[1] = mem_slice; // old_mem
8829 args[2] = ir_build_const_usize(irb, scope, node, 8); // old_align
8830 // TODO: intentional memory leak here. If this is set to 0 then there is an issue where a coroutine
8831 // calls the function and it frees its own stack frame, but then the return value is a slice, which
8832 // is implemented as an sret struct. writing to the return pointer causes invalid memory write.
8833 // We could work around it by having a global helper function which has a void return type
8834 // and calling that instead. But instead this hack will suffice until I rework coroutines to be
8835 // non-allocating. Basically coroutines are not supported right now until they are reworked.
8836 args[3] = ir_build_const_usize(irb, scope, node, 1); // new_size
8837 args[4] = ir_build_const_usize(irb, scope, node, 1); // new_align
8838 ir_build_call_src(irb, scope, node, nullptr, shrink_fn, arg_count, args, false, FnInlineAuto, false, nullptr,
8839 nullptr, no_result_loc());
8840
8841 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "Resume");
8842 ir_build_cond_br(irb, scope, node, resume_awaiter, resume_block, irb->exec->coro_suspend_block, const_bool_false);
8843
8844 ir_set_cursor_at_end_and_append_block(irb, resume_block);
8845 ir_gen_resume_target(irb, scope, node, awaiter_handle);
8846 ir_build_br(irb, scope, node, irb->exec->coro_suspend_block, const_bool_false);
8847 }
8848
8849 return true;7874 return true;
8850}7875}
88517876
...@@ -10189,12 +9214,6 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -10189,12 +9214,6 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
10189 return result;9214 return result;
10190 }9215 }
101919216
10192 if (wanted_type == ira->codegen->builtin_types.entry_promise &&
10193 actual_type->id == ZigTypeIdPromise)
10194 {
10195 return result;
10196 }
10197
10198 // fn9217 // fn
10199 if (wanted_type->id == ZigTypeIdFn &&9218 if (wanted_type->id == ZigTypeIdFn &&
10200 actual_type->id == ZigTypeIdFn)9219 actual_type->id == ZigTypeIdFn)
...@@ -10229,20 +9248,6 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -10229,20 +9248,6 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
10229 return result;9248 return result;
10230 }9249 }
10231 }9250 }
10232 if (!wanted_type->data.fn.is_generic && wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync) {
10233 ConstCastOnly child = types_match_const_cast_only(ira,
10234 actual_type->data.fn.fn_type_id.async_allocator_type,
10235 wanted_type->data.fn.fn_type_id.async_allocator_type,
10236 source_node, false);
10237 if (child.id == ConstCastResultIdInvalid)
10238 return child;
10239 if (child.id != ConstCastResultIdOk) {
10240 result.id = ConstCastResultIdAsyncAllocatorType;
10241 result.data.async_allocator_type = allocate_nonzero<ConstCastOnly>(1);
10242 *result.data.async_allocator_type = child;
10243 return result;
10244 }
10245 }
10246 if (wanted_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {9251 if (wanted_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {
10247 result.id = ConstCastResultIdFnArgCount;9252 result.id = ConstCastResultIdFnArgCount;
10248 return result;9253 return result;
...@@ -12559,12 +11564,10 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou...@@ -12559,12 +11564,10 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
12559static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {11564static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
12560 if (ty->id == ZigTypeIdPointer) return ty->data.pointer.child_type->id != ZigTypeIdPointer;11565 if (ty->id == ZigTypeIdPointer) return ty->data.pointer.child_type->id != ZigTypeIdPointer;
12561 if (ty->id == ZigTypeIdFn) return true;11566 if (ty->id == ZigTypeIdFn) return true;
12562 if (ty->id == ZigTypeIdPromise) return true;
12563 if (ty->id == ZigTypeIdOptional) {11567 if (ty->id == ZigTypeIdOptional) {
12564 ZigType *ptr_ty = ty->data.maybe.child_type;11568 ZigType *ptr_ty = ty->data.maybe.child_type;
12565 if (ptr_ty->id == ZigTypeIdPointer) return ptr_ty->data.pointer.child_type->id != ZigTypeIdPointer;11569 if (ptr_ty->id == ZigTypeIdPointer) return ptr_ty->data.pointer.child_type->id != ZigTypeIdPointer;
12566 if (ptr_ty->id == ZigTypeIdFn) return true;11570 if (ptr_ty->id == ZigTypeIdFn) return true;
12567 if (ptr_ty->id == ZigTypeIdPromise) return true;
12568 }11571 }
12569 return false;11572 return false;
12570}11573}
...@@ -13640,7 +12643,6 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -13640,7 +12643,6 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
13640 case ZigTypeIdOpaque:12643 case ZigTypeIdOpaque:
13641 case ZigTypeIdBoundFn:12644 case ZigTypeIdBoundFn:
13642 case ZigTypeIdArgTuple:12645 case ZigTypeIdArgTuple:
13643 case ZigTypeIdPromise:
13644 case ZigTypeIdEnum:12646 case ZigTypeIdEnum:
13645 case ZigTypeIdEnumLiteral:12647 case ZigTypeIdEnumLiteral:
13646 operator_allowed = is_equality_cmp;12648 operator_allowed = is_equality_cmp;
...@@ -15021,7 +14023,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -15021,7 +14023,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
15021 case ZigTypeIdBoundFn:14023 case ZigTypeIdBoundFn:
15022 case ZigTypeIdArgTuple:14024 case ZigTypeIdArgTuple:
15023 case ZigTypeIdOpaque:14025 case ZigTypeIdOpaque:
15024 case ZigTypeIdPromise:
15025 ir_add_error(ira, target,14026 ir_add_error(ira, target,
15026 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));14027 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
15027 break;14028 break;
...@@ -15045,7 +14046,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -15045,7 +14046,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
15045 case ZigTypeIdBoundFn:14046 case ZigTypeIdBoundFn:
15046 case ZigTypeIdArgTuple:14047 case ZigTypeIdArgTuple:
15047 case ZigTypeIdOpaque:14048 case ZigTypeIdOpaque:
15048 case ZigTypeIdPromise:
15049 case ZigTypeIdEnumLiteral:14049 case ZigTypeIdEnumLiteral:
15050 ir_add_error(ira, target,14050 ir_add_error(ira, target,
15051 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));14051 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));
...@@ -15124,42 +14124,6 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,...@@ -15124,42 +14124,6 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
15124 return ir_const_type(ira, &instruction->base, result_type);14124 return ir_const_type(ira, &instruction->base, result_type);
15125}14125}
1512614126
15127IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, ImplicitAllocatorId id) {
15128 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
15129 if (parent_fn_entry == nullptr) {
15130 ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available"));
15131 return ira->codegen->invalid_instruction;
15132 }
15133
15134 FnTypeId *parent_fn_type = &parent_fn_entry->type_entry->data.fn.fn_type_id;
15135 if (parent_fn_type->cc != CallingConventionAsync) {
15136 ir_add_error(ira, source_instr, buf_sprintf("async function call from non-async caller requires allocator parameter"));
15137 return ira->codegen->invalid_instruction;
15138 }
15139
15140 assert(parent_fn_type->async_allocator_type != nullptr);
15141
15142 switch (id) {
15143 case ImplicitAllocatorIdArg:
15144 {
15145 IrInstruction *result = ir_build_get_implicit_allocator(&ira->new_irb, source_instr->scope,
15146 source_instr->source_node, ImplicitAllocatorIdArg);
15147 result->value.type = parent_fn_type->async_allocator_type;
15148 return result;
15149 }
15150 case ImplicitAllocatorIdLocalVar:
15151 {
15152 ZigVar *coro_allocator_var = ira->old_irb.exec->coro_allocator_var;
15153 assert(coro_allocator_var != nullptr);
15154 IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var);
15155 IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst, nullptr);
15156 assert(result->value.type != nullptr);
15157 return result;
15158 }
15159 }
15160 zig_unreachable();
15161}
15162
15163static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_inst, ZigType *var_type,14127static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_inst, ZigType *var_type,
15164 uint32_t align, const char *name_hint, bool force_comptime)14128 uint32_t align, const char *name_hint, bool force_comptime)
15165{14129{
...@@ -15589,50 +14553,6 @@ static IrInstruction *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInst...@@ -15589,50 +14553,6 @@ static IrInstruction *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInst
15589 return ir_const_void(ira, &instruction->base);14553 return ir_const_void(ira, &instruction->base);
15590}14554}
1559114555
15592static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction, ZigFn *fn_entry,
15593 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,
15594 IrInstruction *async_allocator_inst)
15595{
15596 Buf *realloc_field_name = buf_create_from_str(ASYNC_REALLOC_FIELD_NAME);
15597 ir_assert(async_allocator_inst->value.type->id == ZigTypeIdPointer, &call_instruction->base);
15598 ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type;
15599 IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, realloc_field_name, &call_instruction->base,
15600 async_allocator_inst, container_type, false);
15601 if (type_is_invalid(field_ptr_inst->value.type)) {
15602 return ira->codegen->invalid_instruction;
15603 }
15604 ZigType *ptr_to_realloc_fn_type = field_ptr_inst->value.type;
15605 ir_assert(ptr_to_realloc_fn_type->id == ZigTypeIdPointer, &call_instruction->base);
15606
15607 ZigType *realloc_fn_type = ptr_to_realloc_fn_type->data.pointer.child_type;
15608 if (realloc_fn_type->id != ZigTypeIdFn) {
15609 ir_add_error(ira, &call_instruction->base,
15610 buf_sprintf("expected reallocation function, found '%s'", buf_ptr(&realloc_fn_type->name)));
15611 return ira->codegen->invalid_instruction;
15612 }
15613
15614 ZigType *realloc_fn_return_type = realloc_fn_type->data.fn.fn_type_id.return_type;
15615 if (realloc_fn_return_type->id != ZigTypeIdErrorUnion) {
15616 ir_add_error(ira, fn_ref,
15617 buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&realloc_fn_return_type->name)));
15618 return ira->codegen->invalid_instruction;
15619 }
15620 ZigType *alloc_fn_error_set_type = realloc_fn_return_type->data.error_union.err_set_type;
15621 ZigType *return_type = fn_type->data.fn.fn_type_id.return_type;
15622 ZigType *promise_type = get_promise_type(ira->codegen, return_type);
15623 ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type);
15624
15625 IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, no_result_loc(),
15626 async_return_type, nullptr, true, true);
15627 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
15628 return result_loc;
15629 }
15630
15631 return ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count,
15632 casted_args, FnInlineAuto, true, async_allocator_inst, nullptr, result_loc,
15633 async_return_type);
15634}
15635
15636static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node,14556static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node,
15637 IrInstruction *arg, Scope **exec_scope, size_t *next_proto_i)14557 IrInstruction *arg, Scope **exec_scope, size_t *next_proto_i)
15638{14558{
...@@ -16330,32 +15250,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -16330,32 +15250,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
16330 break;15250 break;
16331 }15251 }
16332 }15252 }
16333 IrInstruction *async_allocator_inst = nullptr;
16334 if (call_instruction->is_async) {15253 if (call_instruction->is_async) {
16335 AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type;15254 zig_panic("TODO async call");
16336 if (async_allocator_type_node != nullptr) {
16337 ZigType *async_allocator_type = ir_analyze_type_expr(ira, impl_fn->child_scope, async_allocator_type_node);
16338 if (type_is_invalid(async_allocator_type))
16339 return ira->codegen->invalid_instruction;
16340 inst_fn_type_id.async_allocator_type = async_allocator_type;
16341 }
16342 IrInstruction *uncasted_async_allocator_inst;
16343 if (call_instruction->async_allocator == nullptr) {
16344 uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base,
16345 ImplicitAllocatorIdLocalVar);
16346 if (type_is_invalid(uncasted_async_allocator_inst->value.type))
16347 return ira->codegen->invalid_instruction;
16348 } else {
16349 uncasted_async_allocator_inst = call_instruction->async_allocator->child;
16350 if (type_is_invalid(uncasted_async_allocator_inst->value.type))
16351 return ira->codegen->invalid_instruction;
16352 }
16353 if (inst_fn_type_id.async_allocator_type == nullptr) {
16354 inst_fn_type_id.async_allocator_type = uncasted_async_allocator_inst->value.type;
16355 }
16356 async_allocator_inst = ir_implicit_cast(ira, uncasted_async_allocator_inst, inst_fn_type_id.async_allocator_type);
16357 if (type_is_invalid(async_allocator_inst->value.type))
16358 return ira->codegen->invalid_instruction;
16359 }15255 }
1636015256
16361 auto existing_entry = ira->codegen->generic_table.put_unique(generic_id, impl_fn);15257 auto existing_entry = ira->codegen->generic_table.put_unique(generic_id, impl_fn);
...@@ -16398,15 +15294,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -16398,15 +15294,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1639815294
16399 size_t impl_param_count = impl_fn_type_id->param_count;15295 size_t impl_param_count = impl_fn_type_id->param_count;
16400 if (call_instruction->is_async) {15296 if (call_instruction->is_async) {
16401 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry,15297 zig_panic("TODO async call");
16402 fn_ref, casted_args, impl_param_count, async_allocator_inst);
16403 return ir_finish_anal(ira, result);
16404 }15298 }
1640515299
16406 assert(async_allocator_inst == nullptr);
16407 IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base,15300 IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base,
16408 impl_fn, nullptr, impl_param_count, casted_args, fn_inline,15301 impl_fn, nullptr, impl_param_count, casted_args, fn_inline,
16409 call_instruction->is_async, nullptr, casted_new_stack, result_loc,15302 call_instruction->is_async, casted_new_stack, result_loc,
16410 impl_fn_type_id->return_type);15303 impl_fn_type_id->return_type);
1641115304
16412 return ir_finish_anal(ira, new_call_instruction);15305 return ir_finish_anal(ira, new_call_instruction);
...@@ -16474,25 +15367,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -16474,25 +15367,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
16474 return ira->codegen->invalid_instruction;15367 return ira->codegen->invalid_instruction;
1647515368
16476 if (call_instruction->is_async) {15369 if (call_instruction->is_async) {
16477 IrInstruction *uncasted_async_allocator_inst;15370 zig_panic("TODO async call");
16478 if (call_instruction->async_allocator == nullptr) {
16479 uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base,
16480 ImplicitAllocatorIdLocalVar);
16481 if (type_is_invalid(uncasted_async_allocator_inst->value.type))
16482 return ira->codegen->invalid_instruction;
16483 } else {
16484 uncasted_async_allocator_inst = call_instruction->async_allocator->child;
16485 if (type_is_invalid(uncasted_async_allocator_inst->value.type))
16486 return ira->codegen->invalid_instruction;
16487
16488 }
16489 IrInstruction *async_allocator_inst = ir_implicit_cast(ira, uncasted_async_allocator_inst, fn_type_id->async_allocator_type);
16490 if (type_is_invalid(async_allocator_inst->value.type))
16491 return ira->codegen->invalid_instruction;
16492
16493 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, fn_entry, fn_type, fn_ref,
16494 casted_args, call_param_count, async_allocator_inst);
16495 return ir_finish_anal(ira, result);
16496 }15371 }
1649715372
16498 if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && fn_inline == FnInlineNever) {15373 if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && fn_inline == FnInlineNever) {
...@@ -16513,7 +15388,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -16513,7 +15388,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
16513 }15388 }
1651415389
16515 IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref,15390 IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref,
16516 call_param_count, casted_args, fn_inline, false, nullptr, casted_new_stack,15391 call_param_count, casted_args, fn_inline, false, casted_new_stack,
16517 result_loc, return_type);15392 result_loc, return_type);
16518 return ir_finish_anal(ira, new_call_instruction);15393 return ir_finish_anal(ira, new_call_instruction);
16519}15394}
...@@ -16694,7 +15569,6 @@ static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_...@@ -16694,7 +15569,6 @@ static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_
16694 case ZigTypeIdFn:15569 case ZigTypeIdFn:
16695 case ZigTypeIdBoundFn:15570 case ZigTypeIdBoundFn:
16696 case ZigTypeIdArgTuple:15571 case ZigTypeIdArgTuple:
16697 case ZigTypeIdPromise:
16698 return ir_const_type(ira, &un_op_instruction->base, get_optional_type(ira->codegen, type_entry));15572 return ir_const_type(ira, &un_op_instruction->base, get_optional_type(ira->codegen, type_entry));
16699 case ZigTypeIdUnreachable:15573 case ZigTypeIdUnreachable:
16700 case ZigTypeIdOpaque:15574 case ZigTypeIdOpaque:
...@@ -18465,7 +17339,6 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -18465,7 +17339,6 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
18465 case ZigTypeIdUnion:17339 case ZigTypeIdUnion:
18466 case ZigTypeIdFn:17340 case ZigTypeIdFn:
18467 case ZigTypeIdBoundFn:17341 case ZigTypeIdBoundFn:
18468 case ZigTypeIdPromise:
18469 case ZigTypeIdVector:17342 case ZigTypeIdVector:
18470 {17343 {
18471 ResolveStatus needed_status = (align_bytes == 0) ?17344 ResolveStatus needed_status = (align_bytes == 0) ?
...@@ -18580,7 +17453,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -18580,7 +17453,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
18580 case ZigTypeIdUnion:17453 case ZigTypeIdUnion:
18581 case ZigTypeIdFn:17454 case ZigTypeIdFn:
18582 case ZigTypeIdBoundFn:17455 case ZigTypeIdBoundFn:
18583 case ZigTypeIdPromise:
18584 case ZigTypeIdVector:17456 case ZigTypeIdVector:
18585 {17457 {
18586 if ((err = ensure_complete_type(ira->codegen, child_type)))17458 if ((err = ensure_complete_type(ira->codegen, child_type)))
...@@ -18592,22 +17464,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -18592,22 +17464,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
18592 zig_unreachable();17464 zig_unreachable();
18593}17465}
1859417466
18595static IrInstruction *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) {
18596 ZigType *promise_type;
18597
18598 if (instruction->payload_type == nullptr) {
18599 promise_type = ira->codegen->builtin_types.entry_promise;
18600 } else {
18601 ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->child);
18602 if (type_is_invalid(payload_type))
18603 return ira->codegen->invalid_instruction;
18604
18605 promise_type = get_promise_type(ira->codegen, payload_type);
18606 }
18607
18608 return ir_const_type(ira, &instruction->base, promise_type);
18609}
18610
18611static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,17467static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,
18612 IrInstructionSizeOf *size_of_instruction)17468 IrInstructionSizeOf *size_of_instruction)
18613{17469{
...@@ -18647,7 +17503,6 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,...@@ -18647,7 +17503,6 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,
18647 case ZigTypeIdEnum:17503 case ZigTypeIdEnum:
18648 case ZigTypeIdUnion:17504 case ZigTypeIdUnion:
18649 case ZigTypeIdFn:17505 case ZigTypeIdFn:
18650 case ZigTypeIdPromise:
18651 case ZigTypeIdVector:17506 case ZigTypeIdVector:
18652 {17507 {
18653 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);17508 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);
...@@ -19134,7 +17989,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -19134,7 +17989,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
19134 case ZigTypeIdComptimeInt:17989 case ZigTypeIdComptimeInt:
19135 case ZigTypeIdEnumLiteral:17990 case ZigTypeIdEnumLiteral:
19136 case ZigTypeIdPointer:17991 case ZigTypeIdPointer:
19137 case ZigTypeIdPromise:
19138 case ZigTypeIdFn:17992 case ZigTypeIdFn:
19139 case ZigTypeIdErrorSet: {17993 case ZigTypeIdErrorSet: {
19140 if (pointee_val) {17994 if (pointee_val) {
...@@ -20645,32 +19499,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -20645,32 +19499,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
20645 fields[0].type = ira->codegen->builtin_types.entry_type;19499 fields[0].type = ira->codegen->builtin_types.entry_type;
20646 fields[0].data.x_type = type_entry->data.maybe.child_type;19500 fields[0].data.x_type = type_entry->data.maybe.child_type;
2064719501
20648 break;
20649 }
20650 case ZigTypeIdPromise:
20651 {
20652 result = create_const_vals(1);
20653 result->special = ConstValSpecialStatic;
20654 result->type = ir_type_info_get_type(ira, "Promise", nullptr);
20655
20656 ConstExprValue *fields = create_const_vals(1);
20657 result->data.x_struct.fields = fields;
20658
20659 // child: ?type
20660 ensure_field_index(result->type, "child", 0);
20661 fields[0].special = ConstValSpecialStatic;
20662 fields[0].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
20663
20664 if (type_entry->data.promise.result_type == nullptr)
20665 fields[0].data.x_optional = nullptr;
20666 else {
20667 ConstExprValue *child_type = create_const_vals(1);
20668 child_type->special = ConstValSpecialStatic;
20669 child_type->type = ira->codegen->builtin_types.entry_type;
20670 child_type->data.x_type = type_entry->data.promise.result_type;
20671 fields[0].data.x_optional = child_type;
20672 }
20673
20674 break;19502 break;
20675 }19503 }
20676 case ZigTypeIdEnum:19504 case ZigTypeIdEnum:
...@@ -20982,7 +19810,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -20982,7 +19810,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
20982 result->special = ConstValSpecialStatic;19810 result->special = ConstValSpecialStatic;
20983 result->type = ir_type_info_get_type(ira, "Fn", nullptr);19811 result->type = ir_type_info_get_type(ira, "Fn", nullptr);
2098419812
20985 ConstExprValue *fields = create_const_vals(6);19813 ConstExprValue *fields = create_const_vals(5);
20986 result->data.x_struct.fields = fields;19814 result->data.x_struct.fields = fields;
2098719815
20988 // calling_convention: TypeInfo.CallingConvention19816 // calling_convention: TypeInfo.CallingConvention
...@@ -21015,19 +19843,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21015,19 +19843,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21015 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;19843 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
21016 fields[3].data.x_optional = return_type;19844 fields[3].data.x_optional = return_type;
21017 }19845 }
21018 // async_allocator_type: type
21019 ensure_field_index(result->type, "async_allocator_type", 4);
21020 fields[4].special = ConstValSpecialStatic;
21021 fields[4].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
21022 if (type_entry->data.fn.fn_type_id.async_allocator_type == nullptr)
21023 fields[4].data.x_optional = nullptr;
21024 else {
21025 ConstExprValue *async_alloc_type = create_const_vals(1);
21026 async_alloc_type->special = ConstValSpecialStatic;
21027 async_alloc_type->type = ira->codegen->builtin_types.entry_type;
21028 async_alloc_type->data.x_type = type_entry->data.fn.fn_type_id.async_allocator_type;
21029 fields[4].data.x_optional = async_alloc_type;
21030 }
21031 // args: []TypeInfo.FnArg19846 // args: []TypeInfo.FnArg
21032 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);19847 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
21033 if ((err = type_resolve(ira->codegen, type_info_fn_arg_type, ResolveStatusSizeKnown))) {19848 if ((err = type_resolve(ira->codegen, type_info_fn_arg_type, ResolveStatusSizeKnown))) {
...@@ -21042,10 +19857,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -21042,10 +19857,9 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
21042 fn_arg_array->data.x_array.special = ConstArraySpecialNone;19857 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
21043 fn_arg_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);19858 fn_arg_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);
2104419859
21045 init_const_slice(ira->codegen, &fields[5], fn_arg_array, 0, fn_arg_count, false);19860 init_const_slice(ira->codegen, &fields[4], fn_arg_array, 0, fn_arg_count, false);
2104619861
21047 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++)19862 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
21048 {
21049 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];19863 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];
21050 ConstExprValue *fn_arg_val = &fn_arg_array->data.x_array.data.s_none.elements[fn_arg_index];19864 ConstExprValue *fn_arg_val = &fn_arg_array->data.x_array.data.s_none.elements[fn_arg_index];
2105119865
...@@ -22803,11 +21617,7 @@ static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrIns...@@ -22803,11 +21617,7 @@ static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrIns
22803}21617}
2280421618
22805static IrInstruction *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) {21619static IrInstruction *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) {
22806 IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node);21620 zig_panic("TODO anlayze @handle()");
22807 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
22808 assert(fn_entry != nullptr);
22809 result->value.type = get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type);
22810 return result;
22811}21621}
2281221622
22813static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {21623static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
...@@ -22841,7 +21651,6 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct...@@ -22841,7 +21651,6 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
22841 case ZigTypeIdInt:21651 case ZigTypeIdInt:
22842 case ZigTypeIdFloat:21652 case ZigTypeIdFloat:
22843 case ZigTypeIdPointer:21653 case ZigTypeIdPointer:
22844 case ZigTypeIdPromise:
22845 case ZigTypeIdArray:21654 case ZigTypeIdArray:
22846 case ZigTypeIdStruct:21655 case ZigTypeIdStruct:
22847 case ZigTypeIdOptional:21656 case ZigTypeIdOptional:
...@@ -23401,15 +22210,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -23401,15 +22210,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
23401 }22210 }
2340222211
23403 if (fn_type_id.cc == CallingConventionAsync) {22212 if (fn_type_id.cc == CallingConventionAsync) {
23404 if (instruction->async_allocator_type_value == nullptr) {22213 zig_panic("TODO");
23405 ir_add_error(ira, &instruction->base,
23406 buf_sprintf("async fn proto missing allocator type"));
23407 return ira->codegen->invalid_instruction;
23408 }
23409 IrInstruction *async_allocator_type_value = instruction->async_allocator_type_value->child;
23410 fn_type_id.async_allocator_type = ir_resolve_type(ira, async_allocator_type_value);
23411 if (type_is_invalid(fn_type_id.async_allocator_type))
23412 return ira->codegen->invalid_instruction;
23413 }22214 }
2341422215
23415 return ir_const_type(ira, &instruction->base, get_fn_type(ira->codegen, &fn_type_id));22216 return ir_const_type(ira, &instruction->base, get_fn_type(ira->codegen, &fn_type_id));
...@@ -23905,7 +22706,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -23905,7 +22706,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
23905 case ZigTypeIdEnumLiteral:22706 case ZigTypeIdEnumLiteral:
23906 case ZigTypeIdUndefined:22707 case ZigTypeIdUndefined:
23907 case ZigTypeIdNull:22708 case ZigTypeIdNull:
23908 case ZigTypeIdPromise:
23909 case ZigTypeIdErrorUnion:22709 case ZigTypeIdErrorUnion:
23910 case ZigTypeIdErrorSet:22710 case ZigTypeIdErrorSet:
23911 zig_unreachable();22711 zig_unreachable();
...@@ -24059,7 +22859,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -24059,7 +22859,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
24059 case ZigTypeIdEnumLiteral:22859 case ZigTypeIdEnumLiteral:
24060 case ZigTypeIdUndefined:22860 case ZigTypeIdUndefined:
24061 case ZigTypeIdNull:22861 case ZigTypeIdNull:
24062 case ZigTypeIdPromise:
24063 zig_unreachable();22862 zig_unreachable();
24064 case ZigTypeIdVoid:22863 case ZigTypeIdVoid:
24065 return ErrorNone;22864 return ErrorNone;
...@@ -24546,181 +23345,7 @@ static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruct...@@ -24546,181 +23345,7 @@ static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruct
24546}23345}
2454723346
24548static IrInstruction *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {23347static IrInstruction *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {
24549 IrInstruction *target_inst = instruction->target->child;23348 zig_panic("TODO analyze cancel");
24550 if (type_is_invalid(target_inst->value.type))
24551 return ira->codegen->invalid_instruction;
24552 IrInstruction *casted_target = ir_implicit_cast(ira, target_inst, ira->codegen->builtin_types.entry_promise);
24553 if (type_is_invalid(casted_target->value.type))
24554 return ira->codegen->invalid_instruction;
24555
24556 IrInstruction *result = ir_build_cancel(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_target);
24557 result->value.type = ira->codegen->builtin_types.entry_void;
24558 result->value.special = ConstValSpecialStatic;
24559 return result;
24560}
24561
24562static IrInstruction *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) {
24563 IrInstruction *promise_ptr = instruction->promise_ptr->child;
24564 if (type_is_invalid(promise_ptr->value.type))
24565 return ira->codegen->invalid_instruction;
24566
24567 IrInstruction *result = ir_build_coro_id(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
24568 promise_ptr);
24569 result->value.type = ira->codegen->builtin_types.entry_usize;
24570 return result;
24571}
24572
24573static IrInstruction *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) {
24574 IrInstruction *coro_id = instruction->coro_id->child;
24575 if (type_is_invalid(coro_id->value.type))
24576 return ira->codegen->invalid_instruction;
24577
24578 IrInstruction *result = ir_build_coro_alloc(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
24579 coro_id);
24580 result->value.type = ira->codegen->builtin_types.entry_bool;
24581 return result;
24582}
24583
24584static IrInstruction *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) {
24585 IrInstruction *result = ir_build_coro_size(&ira->new_irb, instruction->base.scope, instruction->base.source_node);
24586 result->value.type = ira->codegen->builtin_types.entry_usize;
24587 return result;
24588}
24589
24590static IrInstruction *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) {
24591 IrInstruction *coro_id = instruction->coro_id->child;
24592 if (type_is_invalid(coro_id->value.type))
24593 return ira->codegen->invalid_instruction;
24594
24595 IrInstruction *coro_mem_ptr = instruction->coro_mem_ptr->child;
24596 if (type_is_invalid(coro_mem_ptr->value.type))
24597 return ira->codegen->invalid_instruction;
24598
24599 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
24600 ir_assert(fn_entry != nullptr, &instruction->base);
24601 IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node,
24602 coro_id, coro_mem_ptr);
24603 result->value.type = get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type);
24604 return result;
24605}
24606
24607static IrInstruction *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) {
24608 return ir_get_implicit_allocator(ira, &instruction->base, instruction->id);
24609}
24610
24611static IrInstruction *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) {
24612 IrInstruction *err_val = instruction->err_val->child;
24613 if (type_is_invalid(err_val->value.type))
24614 return ir_unreach_error(ira);
24615
24616 IrInstruction *result = ir_build_coro_alloc_fail(&ira->new_irb, instruction->base.scope, instruction->base.source_node, err_val);
24617 result->value.type = ira->codegen->builtin_types.entry_unreachable;
24618 return ir_finish_anal(ira, result);
24619}
24620
24621static IrInstruction *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) {
24622 IrInstruction *save_point = nullptr;
24623 if (instruction->save_point != nullptr) {
24624 save_point = instruction->save_point->child;
24625 if (type_is_invalid(save_point->value.type))
24626 return ira->codegen->invalid_instruction;
24627 }
24628
24629 IrInstruction *is_final = instruction->is_final->child;
24630 if (type_is_invalid(is_final->value.type))
24631 return ira->codegen->invalid_instruction;
24632
24633 IrInstruction *result = ir_build_coro_suspend(&ira->new_irb, instruction->base.scope,
24634 instruction->base.source_node, save_point, is_final);
24635 result->value.type = ira->codegen->builtin_types.entry_u8;
24636 return result;
24637}
24638
24639static IrInstruction *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) {
24640 IrInstruction *result = ir_build_coro_end(&ira->new_irb, instruction->base.scope,
24641 instruction->base.source_node);
24642 result->value.type = ira->codegen->builtin_types.entry_void;
24643 return result;
24644}
24645
24646static IrInstruction *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) {
24647 IrInstruction *coro_id = instruction->coro_id->child;
24648 if (type_is_invalid(coro_id->value.type))
24649 return ira->codegen->invalid_instruction;
24650
24651 IrInstruction *coro_handle = instruction->coro_handle->child;
24652 if (type_is_invalid(coro_handle->value.type))
24653 return ira->codegen->invalid_instruction;
24654
24655 IrInstruction *result = ir_build_coro_free(&ira->new_irb, instruction->base.scope,
24656 instruction->base.source_node, coro_id, coro_handle);
24657 ZigType *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
24658 result->value.type = get_optional_type(ira->codegen, ptr_type);
24659 return result;
24660}
24661
24662static IrInstruction *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) {
24663 IrInstruction *awaiter_handle = instruction->awaiter_handle->child;
24664 if (type_is_invalid(awaiter_handle->value.type))
24665 return ira->codegen->invalid_instruction;
24666
24667 IrInstruction *casted_target = ir_implicit_cast(ira, awaiter_handle, ira->codegen->builtin_types.entry_promise);
24668 if (type_is_invalid(casted_target->value.type))
24669 return ira->codegen->invalid_instruction;
24670
24671 IrInstruction *result = ir_build_coro_resume(&ira->new_irb, instruction->base.scope,
24672 instruction->base.source_node, casted_target);
24673 result->value.type = ira->codegen->builtin_types.entry_void;
24674 return result;
24675}
24676
24677static IrInstruction *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) {
24678 IrInstruction *coro_handle = instruction->coro_handle->child;
24679 if (type_is_invalid(coro_handle->value.type))
24680 return ira->codegen->invalid_instruction;
24681
24682 IrInstruction *result = ir_build_coro_save(&ira->new_irb, instruction->base.scope,
24683 instruction->base.source_node, coro_handle);
24684 result->value.type = ira->codegen->builtin_types.entry_usize;
24685 return result;
24686}
24687
24688static IrInstruction *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) {
24689 IrInstruction *coro_handle = instruction->coro_handle->child;
24690 if (type_is_invalid(coro_handle->value.type))
24691 return ira->codegen->invalid_instruction;
24692
24693 if (coro_handle->value.type->id != ZigTypeIdPromise ||
24694 coro_handle->value.type->data.promise.result_type == nullptr)
24695 {
24696 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
24697 buf_ptr(&coro_handle->value.type->name)));
24698 return ira->codegen->invalid_instruction;
24699 }
24700
24701 ZigType *coro_frame_type = get_promise_frame_type(ira->codegen,
24702 coro_handle->value.type->data.promise.result_type);
24703
24704 IrInstruction *result = ir_build_coro_promise(&ira->new_irb, instruction->base.scope,
24705 instruction->base.source_node, coro_handle);
24706 result->value.type = get_pointer_to_type(ira->codegen, coro_frame_type, false);
24707 return result;
24708}
24709
24710static IrInstruction *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) {
24711 IrInstruction *realloc_fn = instruction->realloc_fn->child;
24712 if (type_is_invalid(realloc_fn->value.type))
24713 return ira->codegen->invalid_instruction;
24714
24715 IrInstruction *coro_size = instruction->coro_size->child;
24716 if (type_is_invalid(coro_size->value.type))
24717 return ira->codegen->invalid_instruction;
24718
24719 IrInstruction *result = ir_build_coro_alloc_helper(&ira->new_irb, instruction->base.scope,
24720 instruction->base.source_node, realloc_fn, coro_size);
24721 ZigType *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false);
24722 result->value.type = get_optional_type(ira->codegen, u8_ptr_type);
24723 return result;
24724}23349}
2472523350
24726static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {23351static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
...@@ -24853,65 +23478,6 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr...@@ -24853,65 +23478,6 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
24853 return result;23478 return result;
24854}23479}
2485523480
24856static IrInstruction *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) {
24857 ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->child);
24858 if (type_is_invalid(promise_type))
24859 return ira->codegen->invalid_instruction;
24860
24861 if (promise_type->id != ZigTypeIdPromise || promise_type->data.promise.result_type == nullptr) {
24862 ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'",
24863 buf_ptr(&promise_type->name)));
24864 return ira->codegen->invalid_instruction;
24865 }
24866
24867 return ir_const_type(ira, &instruction->base, promise_type->data.promise.result_type);
24868}
24869
24870static IrInstruction *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) {
24871 ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->child);
24872 if (type_is_invalid(promise_result_type))
24873 return ira->codegen->invalid_instruction;
24874
24875 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
24876 ir_assert(fn_entry != nullptr, &instruction->base);
24877
24878 if (type_can_fail(promise_result_type)) {
24879 fn_entry->calls_or_awaits_errorable_fn = true;
24880 }
24881
24882 return ir_const_void(ira, &instruction->base);
24883}
24884
24885static IrInstruction *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira,
24886 IrInstructionMergeErrRetTraces *instruction)
24887{
24888 IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->child;
24889 if (type_is_invalid(coro_promise_ptr->value.type))
24890 return ira->codegen->invalid_instruction;
24891
24892 ir_assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer, &instruction->base);
24893 ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type;
24894 ir_assert(promise_frame_type->id == ZigTypeIdStruct, &instruction->base);
24895 ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry;
24896
24897 if (!type_can_fail(promise_result_type)) {
24898 return ir_const_void(ira, &instruction->base);
24899 }
24900
24901 IrInstruction *src_err_ret_trace_ptr = instruction->src_err_ret_trace_ptr->child;
24902 if (type_is_invalid(src_err_ret_trace_ptr->value.type))
24903 return ira->codegen->invalid_instruction;
24904
24905 IrInstruction *dest_err_ret_trace_ptr = instruction->dest_err_ret_trace_ptr->child;
24906 if (type_is_invalid(dest_err_ret_trace_ptr->value.type))
24907 return ira->codegen->invalid_instruction;
24908
24909 IrInstruction *result = ir_build_merge_err_ret_traces(&ira->new_irb, instruction->base.scope,
24910 instruction->base.source_node, coro_promise_ptr, src_err_ret_trace_ptr, dest_err_ret_trace_ptr);
24911 result->value.type = ira->codegen->builtin_types.entry_void;
24912 return result;
24913}
24914
24915static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {23481static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
24916 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,23482 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,
24917 instruction->base.source_node);23483 instruction->base.source_node);
...@@ -25530,8 +24096,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction...@@ -25530,8 +24096,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
25530 return ir_analyze_instruction_asm(ira, (IrInstructionAsm *)instruction);24096 return ir_analyze_instruction_asm(ira, (IrInstructionAsm *)instruction);
25531 case IrInstructionIdArrayType:24097 case IrInstructionIdArrayType:
25532 return ir_analyze_instruction_array_type(ira, (IrInstructionArrayType *)instruction);24098 return ir_analyze_instruction_array_type(ira, (IrInstructionArrayType *)instruction);
25533 case IrInstructionIdPromiseType:
25534 return ir_analyze_instruction_promise_type(ira, (IrInstructionPromiseType *)instruction);
25535 case IrInstructionIdSizeOf:24099 case IrInstructionIdSizeOf:
25536 return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction);24100 return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction);
25537 case IrInstructionIdTestNonNull:24101 case IrInstructionIdTestNonNull:
...@@ -25704,46 +24268,14 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction...@@ -25704,46 +24268,14 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
25704 return ir_analyze_instruction_error_union(ira, (IrInstructionErrorUnion *)instruction);24268 return ir_analyze_instruction_error_union(ira, (IrInstructionErrorUnion *)instruction);
25705 case IrInstructionIdCancel:24269 case IrInstructionIdCancel:
25706 return ir_analyze_instruction_cancel(ira, (IrInstructionCancel *)instruction);24270 return ir_analyze_instruction_cancel(ira, (IrInstructionCancel *)instruction);
25707 case IrInstructionIdCoroId:
25708 return ir_analyze_instruction_coro_id(ira, (IrInstructionCoroId *)instruction);
25709 case IrInstructionIdCoroAlloc:
25710 return ir_analyze_instruction_coro_alloc(ira, (IrInstructionCoroAlloc *)instruction);
25711 case IrInstructionIdCoroSize:
25712 return ir_analyze_instruction_coro_size(ira, (IrInstructionCoroSize *)instruction);
25713 case IrInstructionIdCoroBegin:
25714 return ir_analyze_instruction_coro_begin(ira, (IrInstructionCoroBegin *)instruction);
25715 case IrInstructionIdGetImplicitAllocator:
25716 return ir_analyze_instruction_get_implicit_allocator(ira, (IrInstructionGetImplicitAllocator *)instruction);
25717 case IrInstructionIdCoroAllocFail:
25718 return ir_analyze_instruction_coro_alloc_fail(ira, (IrInstructionCoroAllocFail *)instruction);
25719 case IrInstructionIdCoroSuspend:
25720 return ir_analyze_instruction_coro_suspend(ira, (IrInstructionCoroSuspend *)instruction);
25721 case IrInstructionIdCoroEnd:
25722 return ir_analyze_instruction_coro_end(ira, (IrInstructionCoroEnd *)instruction);
25723 case IrInstructionIdCoroFree:
25724 return ir_analyze_instruction_coro_free(ira, (IrInstructionCoroFree *)instruction);
25725 case IrInstructionIdCoroResume:
25726 return ir_analyze_instruction_coro_resume(ira, (IrInstructionCoroResume *)instruction);
25727 case IrInstructionIdCoroSave:
25728 return ir_analyze_instruction_coro_save(ira, (IrInstructionCoroSave *)instruction);
25729 case IrInstructionIdCoroPromise:
25730 return ir_analyze_instruction_coro_promise(ira, (IrInstructionCoroPromise *)instruction);
25731 case IrInstructionIdCoroAllocHelper:
25732 return ir_analyze_instruction_coro_alloc_helper(ira, (IrInstructionCoroAllocHelper *)instruction);
25733 case IrInstructionIdAtomicRmw:24271 case IrInstructionIdAtomicRmw:
25734 return ir_analyze_instruction_atomic_rmw(ira, (IrInstructionAtomicRmw *)instruction);24272 return ir_analyze_instruction_atomic_rmw(ira, (IrInstructionAtomicRmw *)instruction);
25735 case IrInstructionIdAtomicLoad:24273 case IrInstructionIdAtomicLoad:
25736 return ir_analyze_instruction_atomic_load(ira, (IrInstructionAtomicLoad *)instruction);24274 return ir_analyze_instruction_atomic_load(ira, (IrInstructionAtomicLoad *)instruction);
25737 case IrInstructionIdPromiseResultType:
25738 return ir_analyze_instruction_promise_result_type(ira, (IrInstructionPromiseResultType *)instruction);
25739 case IrInstructionIdAwaitBookkeeping:
25740 return ir_analyze_instruction_await_bookkeeping(ira, (IrInstructionAwaitBookkeeping *)instruction);
25741 case IrInstructionIdSaveErrRetAddr:24275 case IrInstructionIdSaveErrRetAddr:
25742 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstructionSaveErrRetAddr *)instruction);24276 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstructionSaveErrRetAddr *)instruction);
25743 case IrInstructionIdAddImplicitReturnType:24277 case IrInstructionIdAddImplicitReturnType:
25744 return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstructionAddImplicitReturnType *)instruction);24278 return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstructionAddImplicitReturnType *)instruction);
25745 case IrInstructionIdMergeErrRetTraces:
25746 return ir_analyze_instruction_merge_err_ret_traces(ira, (IrInstructionMergeErrRetTraces *)instruction);
25747 case IrInstructionIdMarkErrRetTracePtr:24279 case IrInstructionIdMarkErrRetTracePtr:
25748 return ir_analyze_instruction_mark_err_ret_trace_ptr(ira, (IrInstructionMarkErrRetTracePtr *)instruction);24280 return ir_analyze_instruction_mark_err_ret_trace_ptr(ira, (IrInstructionMarkErrRetTracePtr *)instruction);
25749 case IrInstructionIdFloatOp:24281 case IrInstructionIdFloatOp:
...@@ -25788,9 +24320,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -25788,9 +24320,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
25788 old_exec->analysis = ira;24320 old_exec->analysis = ira;
25789 ira->codegen = codegen;24321 ira->codegen = codegen;
2579024322
25791 ZigFn *fn_entry = exec_fn_entry(old_exec);24323 ira->explicit_return_type = expected_type;
25792 bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync;
25793 ira->explicit_return_type = is_async ? get_promise_type(codegen, expected_type) : expected_type;
25794 ira->explicit_return_type_source_node = expected_type_source_node;24324 ira->explicit_return_type_source_node = expected_type_source_node;
2579524325
25796 ira->old_irb.codegen = codegen;24326 ira->old_irb.codegen = codegen;
...@@ -25889,17 +24419,8 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -25889,17 +24419,8 @@ bool ir_has_side_effects(IrInstruction *instruction) {
25889 case IrInstructionIdSetAlignStack:24419 case IrInstructionIdSetAlignStack:
25890 case IrInstructionIdExport:24420 case IrInstructionIdExport:
25891 case IrInstructionIdCancel:24421 case IrInstructionIdCancel:
25892 case IrInstructionIdCoroId:
25893 case IrInstructionIdCoroBegin:
25894 case IrInstructionIdCoroAllocFail:
25895 case IrInstructionIdCoroEnd:
25896 case IrInstructionIdCoroResume:
25897 case IrInstructionIdCoroSave:
25898 case IrInstructionIdCoroAllocHelper:
25899 case IrInstructionIdAwaitBookkeeping:
25900 case IrInstructionIdSaveErrRetAddr:24422 case IrInstructionIdSaveErrRetAddr:
25901 case IrInstructionIdAddImplicitReturnType:24423 case IrInstructionIdAddImplicitReturnType:
25902 case IrInstructionIdMergeErrRetTraces:
25903 case IrInstructionIdMarkErrRetTracePtr:24424 case IrInstructionIdMarkErrRetTracePtr:
25904 case IrInstructionIdAtomicRmw:24425 case IrInstructionIdAtomicRmw:
25905 case IrInstructionIdCmpxchgGen:24426 case IrInstructionIdCmpxchgGen:
...@@ -25933,7 +24454,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -25933,7 +24454,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
25933 case IrInstructionIdTypeOf:24454 case IrInstructionIdTypeOf:
25934 case IrInstructionIdStructFieldPtr:24455 case IrInstructionIdStructFieldPtr:
25935 case IrInstructionIdArrayType:24456 case IrInstructionIdArrayType:
25936 case IrInstructionIdPromiseType:
25937 case IrInstructionIdSliceType:24457 case IrInstructionIdSliceType:
25938 case IrInstructionIdSizeOf:24458 case IrInstructionIdSizeOf:
25939 case IrInstructionIdTestNonNull:24459 case IrInstructionIdTestNonNull:
...@@ -25993,13 +24513,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -25993,13 +24513,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
25993 case IrInstructionIdTagType:24513 case IrInstructionIdTagType:
25994 case IrInstructionIdErrorReturnTrace:24514 case IrInstructionIdErrorReturnTrace:
25995 case IrInstructionIdErrorUnion:24515 case IrInstructionIdErrorUnion:
25996 case IrInstructionIdGetImplicitAllocator:
25997 case IrInstructionIdCoroAlloc:
25998 case IrInstructionIdCoroSize:
25999 case IrInstructionIdCoroSuspend:
26000 case IrInstructionIdCoroFree:
26001 case IrInstructionIdCoroPromise:
26002 case IrInstructionIdPromiseResultType:
26003 case IrInstructionIdFloatOp:24516 case IrInstructionIdFloatOp:
26004 case IrInstructionIdMulAdd:24517 case IrInstructionIdMulAdd:
26005 case IrInstructionIdAtomicLoad:24518 case IrInstructionIdAtomicLoad:
src/ir_print.cpp+2-188
...@@ -257,13 +257,7 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {...@@ -257,13 +257,7 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
257257
258static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instruction) {258static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instruction) {
259 if (call_instruction->is_async) {259 if (call_instruction->is_async) {
260 fprintf(irp->f, "async");260 fprintf(irp->f, "async ");
261 if (call_instruction->async_allocator != nullptr) {
262 fprintf(irp->f, "<");
263 ir_print_other_instruction(irp, call_instruction->async_allocator);
264 fprintf(irp->f, ">");
265 }
266 fprintf(irp->f, " ");
267 }261 }
268 if (call_instruction->fn_entry) {262 if (call_instruction->fn_entry) {
269 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));263 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
...@@ -284,13 +278,7 @@ static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instructi...@@ -284,13 +278,7 @@ static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instructi
284278
285static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instruction) {279static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instruction) {
286 if (call_instruction->is_async) {280 if (call_instruction->is_async) {
287 fprintf(irp->f, "async");281 fprintf(irp->f, "async ");
288 if (call_instruction->async_allocator != nullptr) {
289 fprintf(irp->f, "<");
290 ir_print_other_instruction(irp, call_instruction->async_allocator);
291 fprintf(irp->f, ">");
292 }
293 fprintf(irp->f, " ");
294 }282 }
295 if (call_instruction->fn_entry) {283 if (call_instruction->fn_entry) {
296 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));284 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
...@@ -477,14 +465,6 @@ static void ir_print_array_type(IrPrint *irp, IrInstructionArrayType *instructio...@@ -477,14 +465,6 @@ static void ir_print_array_type(IrPrint *irp, IrInstructionArrayType *instructio
477 ir_print_other_instruction(irp, instruction->child_type);465 ir_print_other_instruction(irp, instruction->child_type);
478}466}
479467
480static void ir_print_promise_type(IrPrint *irp, IrInstructionPromiseType *instruction) {
481 fprintf(irp->f, "promise");
482 if (instruction->payload_type != nullptr) {
483 fprintf(irp->f, "->");
484 ir_print_other_instruction(irp, instruction->payload_type);
485 }
486}
487
488static void ir_print_slice_type(IrPrint *irp, IrInstructionSliceType *instruction) {468static void ir_print_slice_type(IrPrint *irp, IrInstructionSliceType *instruction) {
489 const char *const_kw = instruction->is_const ? "const " : "";469 const char *const_kw = instruction->is_const ? "const " : "";
490 fprintf(irp->f, "[]%s", const_kw);470 fprintf(irp->f, "[]%s", const_kw);
...@@ -1396,105 +1376,6 @@ static void ir_print_cancel(IrPrint *irp, IrInstructionCancel *instruction) {...@@ -1396,105 +1376,6 @@ static void ir_print_cancel(IrPrint *irp, IrInstructionCancel *instruction) {
1396 ir_print_other_instruction(irp, instruction->target);1376 ir_print_other_instruction(irp, instruction->target);
1397}1377}
13981378
1399static void ir_print_get_implicit_allocator(IrPrint *irp, IrInstructionGetImplicitAllocator *instruction) {
1400 fprintf(irp->f, "@getImplicitAllocator(");
1401 switch (instruction->id) {
1402 case ImplicitAllocatorIdArg:
1403 fprintf(irp->f, "Arg");
1404 break;
1405 case ImplicitAllocatorIdLocalVar:
1406 fprintf(irp->f, "LocalVar");
1407 break;
1408 }
1409 fprintf(irp->f, ")");
1410}
1411
1412static void ir_print_coro_id(IrPrint *irp, IrInstructionCoroId *instruction) {
1413 fprintf(irp->f, "@coroId(");
1414 ir_print_other_instruction(irp, instruction->promise_ptr);
1415 fprintf(irp->f, ")");
1416}
1417
1418static void ir_print_coro_alloc(IrPrint *irp, IrInstructionCoroAlloc *instruction) {
1419 fprintf(irp->f, "@coroAlloc(");
1420 ir_print_other_instruction(irp, instruction->coro_id);
1421 fprintf(irp->f, ")");
1422}
1423
1424static void ir_print_coro_size(IrPrint *irp, IrInstructionCoroSize *instruction) {
1425 fprintf(irp->f, "@coroSize()");
1426}
1427
1428static void ir_print_coro_begin(IrPrint *irp, IrInstructionCoroBegin *instruction) {
1429 fprintf(irp->f, "@coroBegin(");
1430 ir_print_other_instruction(irp, instruction->coro_id);
1431 fprintf(irp->f, ",");
1432 ir_print_other_instruction(irp, instruction->coro_mem_ptr);
1433 fprintf(irp->f, ")");
1434}
1435
1436static void ir_print_coro_alloc_fail(IrPrint *irp, IrInstructionCoroAllocFail *instruction) {
1437 fprintf(irp->f, "@coroAllocFail(");
1438 ir_print_other_instruction(irp, instruction->err_val);
1439 fprintf(irp->f, ")");
1440}
1441
1442static void ir_print_coro_suspend(IrPrint *irp, IrInstructionCoroSuspend *instruction) {
1443 fprintf(irp->f, "@coroSuspend(");
1444 if (instruction->save_point != nullptr) {
1445 ir_print_other_instruction(irp, instruction->save_point);
1446 } else {
1447 fprintf(irp->f, "null");
1448 }
1449 fprintf(irp->f, ",");
1450 ir_print_other_instruction(irp, instruction->is_final);
1451 fprintf(irp->f, ")");
1452}
1453
1454static void ir_print_coro_end(IrPrint *irp, IrInstructionCoroEnd *instruction) {
1455 fprintf(irp->f, "@coroEnd()");
1456}
1457
1458static void ir_print_coro_free(IrPrint *irp, IrInstructionCoroFree *instruction) {
1459 fprintf(irp->f, "@coroFree(");
1460 ir_print_other_instruction(irp, instruction->coro_id);
1461 fprintf(irp->f, ",");
1462 ir_print_other_instruction(irp, instruction->coro_handle);
1463 fprintf(irp->f, ")");
1464}
1465
1466static void ir_print_coro_resume(IrPrint *irp, IrInstructionCoroResume *instruction) {
1467 fprintf(irp->f, "@coroResume(");
1468 ir_print_other_instruction(irp, instruction->awaiter_handle);
1469 fprintf(irp->f, ")");
1470}
1471
1472static void ir_print_coro_save(IrPrint *irp, IrInstructionCoroSave *instruction) {
1473 fprintf(irp->f, "@coroSave(");
1474 ir_print_other_instruction(irp, instruction->coro_handle);
1475 fprintf(irp->f, ")");
1476}
1477
1478static void ir_print_coro_promise(IrPrint *irp, IrInstructionCoroPromise *instruction) {
1479 fprintf(irp->f, "@coroPromise(");
1480 ir_print_other_instruction(irp, instruction->coro_handle);
1481 fprintf(irp->f, ")");
1482}
1483
1484static void ir_print_promise_result_type(IrPrint *irp, IrInstructionPromiseResultType *instruction) {
1485 fprintf(irp->f, "@PromiseResultType(");
1486 ir_print_other_instruction(irp, instruction->promise_type);
1487 fprintf(irp->f, ")");
1488}
1489
1490static void ir_print_coro_alloc_helper(IrPrint *irp, IrInstructionCoroAllocHelper *instruction) {
1491 fprintf(irp->f, "@coroAllocHelper(");
1492 ir_print_other_instruction(irp, instruction->realloc_fn);
1493 fprintf(irp->f, ",");
1494 ir_print_other_instruction(irp, instruction->coro_size);
1495 fprintf(irp->f, ")");
1496}
1497
1498static void ir_print_atomic_rmw(IrPrint *irp, IrInstructionAtomicRmw *instruction) {1379static void ir_print_atomic_rmw(IrPrint *irp, IrInstructionAtomicRmw *instruction) {
1499 fprintf(irp->f, "@atomicRmw(");1380 fprintf(irp->f, "@atomicRmw(");
1500 if (instruction->operand_type != nullptr) {1381 if (instruction->operand_type != nullptr) {
...@@ -1539,12 +1420,6 @@ static void ir_print_atomic_load(IrPrint *irp, IrInstructionAtomicLoad *instruct...@@ -1539,12 +1420,6 @@ static void ir_print_atomic_load(IrPrint *irp, IrInstructionAtomicLoad *instruct
1539 fprintf(irp->f, ")");1420 fprintf(irp->f, ")");
1540}1421}
15411422
1542static void ir_print_await_bookkeeping(IrPrint *irp, IrInstructionAwaitBookkeeping *instruction) {
1543 fprintf(irp->f, "@awaitBookkeeping(");
1544 ir_print_other_instruction(irp, instruction->promise_result_type);
1545 fprintf(irp->f, ")");
1546}
1547
1548static void ir_print_save_err_ret_addr(IrPrint *irp, IrInstructionSaveErrRetAddr *instruction) {1423static void ir_print_save_err_ret_addr(IrPrint *irp, IrInstructionSaveErrRetAddr *instruction) {
1549 fprintf(irp->f, "@saveErrRetAddr()");1424 fprintf(irp->f, "@saveErrRetAddr()");
1550}1425}
...@@ -1555,16 +1430,6 @@ static void ir_print_add_implicit_return_type(IrPrint *irp, IrInstructionAddImpl...@@ -1555,16 +1430,6 @@ static void ir_print_add_implicit_return_type(IrPrint *irp, IrInstructionAddImpl
1555 fprintf(irp->f, ")");1430 fprintf(irp->f, ")");
1556}1431}
15571432
1558static void ir_print_merge_err_ret_traces(IrPrint *irp, IrInstructionMergeErrRetTraces *instruction) {
1559 fprintf(irp->f, "@mergeErrRetTraces(");
1560 ir_print_other_instruction(irp, instruction->coro_promise_ptr);
1561 fprintf(irp->f, ",");
1562 ir_print_other_instruction(irp, instruction->src_err_ret_trace_ptr);
1563 fprintf(irp->f, ",");
1564 ir_print_other_instruction(irp, instruction->dest_err_ret_trace_ptr);
1565 fprintf(irp->f, ")");
1566}
1567
1568static void ir_print_mark_err_ret_trace_ptr(IrPrint *irp, IrInstructionMarkErrRetTracePtr *instruction) {1433static void ir_print_mark_err_ret_trace_ptr(IrPrint *irp, IrInstructionMarkErrRetTracePtr *instruction) {
1569 fprintf(irp->f, "@markErrRetTracePtr(");1434 fprintf(irp->f, "@markErrRetTracePtr(");
1570 ir_print_other_instruction(irp, instruction->err_ret_trace_ptr);1435 ir_print_other_instruction(irp, instruction->err_ret_trace_ptr);
...@@ -1727,9 +1592,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1727,9 +1592,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1727 case IrInstructionIdArrayType:1592 case IrInstructionIdArrayType:
1728 ir_print_array_type(irp, (IrInstructionArrayType *)instruction);1593 ir_print_array_type(irp, (IrInstructionArrayType *)instruction);
1729 break;1594 break;
1730 case IrInstructionIdPromiseType:
1731 ir_print_promise_type(irp, (IrInstructionPromiseType *)instruction);
1732 break;
1733 case IrInstructionIdSliceType:1595 case IrInstructionIdSliceType:
1734 ir_print_slice_type(irp, (IrInstructionSliceType *)instruction);1596 ir_print_slice_type(irp, (IrInstructionSliceType *)instruction);
1735 break;1597 break;
...@@ -2033,63 +1895,15 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -2033,63 +1895,15 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
2033 case IrInstructionIdCancel:1895 case IrInstructionIdCancel:
2034 ir_print_cancel(irp, (IrInstructionCancel *)instruction);1896 ir_print_cancel(irp, (IrInstructionCancel *)instruction);
2035 break;1897 break;
2036 case IrInstructionIdGetImplicitAllocator:
2037 ir_print_get_implicit_allocator(irp, (IrInstructionGetImplicitAllocator *)instruction);
2038 break;
2039 case IrInstructionIdCoroId:
2040 ir_print_coro_id(irp, (IrInstructionCoroId *)instruction);
2041 break;
2042 case IrInstructionIdCoroAlloc:
2043 ir_print_coro_alloc(irp, (IrInstructionCoroAlloc *)instruction);
2044 break;
2045 case IrInstructionIdCoroSize:
2046 ir_print_coro_size(irp, (IrInstructionCoroSize *)instruction);
2047 break;
2048 case IrInstructionIdCoroBegin:
2049 ir_print_coro_begin(irp, (IrInstructionCoroBegin *)instruction);
2050 break;
2051 case IrInstructionIdCoroAllocFail:
2052 ir_print_coro_alloc_fail(irp, (IrInstructionCoroAllocFail *)instruction);
2053 break;
2054 case IrInstructionIdCoroSuspend:
2055 ir_print_coro_suspend(irp, (IrInstructionCoroSuspend *)instruction);
2056 break;
2057 case IrInstructionIdCoroEnd:
2058 ir_print_coro_end(irp, (IrInstructionCoroEnd *)instruction);
2059 break;
2060 case IrInstructionIdCoroFree:
2061 ir_print_coro_free(irp, (IrInstructionCoroFree *)instruction);
2062 break;
2063 case IrInstructionIdCoroResume:
2064 ir_print_coro_resume(irp, (IrInstructionCoroResume *)instruction);
2065 break;
2066 case IrInstructionIdCoroSave:
2067 ir_print_coro_save(irp, (IrInstructionCoroSave *)instruction);
2068 break;
2069 case IrInstructionIdCoroAllocHelper:
2070 ir_print_coro_alloc_helper(irp, (IrInstructionCoroAllocHelper *)instruction);
2071 break;
2072 case IrInstructionIdAtomicRmw:1898 case IrInstructionIdAtomicRmw:
2073 ir_print_atomic_rmw(irp, (IrInstructionAtomicRmw *)instruction);1899 ir_print_atomic_rmw(irp, (IrInstructionAtomicRmw *)instruction);
2074 break;1900 break;
2075 case IrInstructionIdCoroPromise:
2076 ir_print_coro_promise(irp, (IrInstructionCoroPromise *)instruction);
2077 break;
2078 case IrInstructionIdPromiseResultType:
2079 ir_print_promise_result_type(irp, (IrInstructionPromiseResultType *)instruction);
2080 break;
2081 case IrInstructionIdAwaitBookkeeping:
2082 ir_print_await_bookkeeping(irp, (IrInstructionAwaitBookkeeping *)instruction);
2083 break;
2084 case IrInstructionIdSaveErrRetAddr:1901 case IrInstructionIdSaveErrRetAddr:
2085 ir_print_save_err_ret_addr(irp, (IrInstructionSaveErrRetAddr *)instruction);1902 ir_print_save_err_ret_addr(irp, (IrInstructionSaveErrRetAddr *)instruction);
2086 break;1903 break;
2087 case IrInstructionIdAddImplicitReturnType:1904 case IrInstructionIdAddImplicitReturnType:
2088 ir_print_add_implicit_return_type(irp, (IrInstructionAddImplicitReturnType *)instruction);1905 ir_print_add_implicit_return_type(irp, (IrInstructionAddImplicitReturnType *)instruction);
2089 break;1906 break;
2090 case IrInstructionIdMergeErrRetTraces:
2091 ir_print_merge_err_ret_traces(irp, (IrInstructionMergeErrRetTraces *)instruction);
2092 break;
2093 case IrInstructionIdMarkErrRetTracePtr:1907 case IrInstructionIdMarkErrRetTracePtr:
2094 ir_print_mark_err_ret_trace_ptr(irp, (IrInstructionMarkErrRetTracePtr *)instruction);1908 ir_print_mark_err_ret_trace_ptr(irp, (IrInstructionMarkErrRetTracePtr *)instruction);
2095 break;1909 break;
src/parser.cpp-32
...@@ -282,9 +282,6 @@ static AstNode *ast_parse_prefix_op_expr(...@@ -282,9 +282,6 @@ static AstNode *ast_parse_prefix_op_expr(
282 case NodeTypeAwaitExpr:282 case NodeTypeAwaitExpr:
283 right = &prefix->data.await_expr.expr;283 right = &prefix->data.await_expr.expr;
284 break;284 break;
285 case NodeTypePromiseType:
286 right = &prefix->data.promise_type.payload_type;
287 break;
288 case NodeTypeArrayType:285 case NodeTypeArrayType:
289 right = &prefix->data.array_type.child_type;286 right = &prefix->data.array_type.child_type;
290 break;287 break;
...@@ -1643,10 +1640,6 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {...@@ -1643,10 +1640,6 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
1643 if (null != nullptr)1640 if (null != nullptr)
1644 return ast_create_node(pc, NodeTypeNullLiteral, null);1641 return ast_create_node(pc, NodeTypeNullLiteral, null);
16451642
1646 Token *promise = eat_token_if(pc, TokenIdKeywordPromise);
1647 if (promise != nullptr)
1648 return ast_create_node(pc, NodeTypePromiseType, promise);
1649
1650 Token *true_token = eat_token_if(pc, TokenIdKeywordTrue);1643 Token *true_token = eat_token_if(pc, TokenIdKeywordTrue);
1651 if (true_token != nullptr) {1644 if (true_token != nullptr) {
1652 AstNode *res = ast_create_node(pc, NodeTypeBoolLiteral, true_token);1645 AstNode *res = ast_create_node(pc, NodeTypeBoolLiteral, true_token);
...@@ -2042,11 +2035,6 @@ static Optional<AstNodeFnProto> ast_parse_fn_cc(ParseContext *pc) {...@@ -2042,11 +2035,6 @@ static Optional<AstNodeFnProto> ast_parse_fn_cc(ParseContext *pc) {
2042 }2035 }
2043 if (eat_token_if(pc, TokenIdKeywordAsync) != nullptr) {2036 if (eat_token_if(pc, TokenIdKeywordAsync) != nullptr) {
2044 res.cc = CallingConventionAsync;2037 res.cc = CallingConventionAsync;
2045 if (eat_token_if(pc, TokenIdCmpLessThan) == nullptr)
2046 return Optional<AstNodeFnProto>::some(res);
2047
2048 res.async_allocator_type = ast_expect(pc, ast_parse_type_expr);
2049 expect_token(pc, TokenIdCmpGreaterThan);
2050 return Optional<AstNodeFnProto>::some(res);2038 return Optional<AstNodeFnProto>::some(res);
2051 }2039 }
20522040
...@@ -2533,16 +2521,6 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) {...@@ -2533,16 +2521,6 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) {
2533 return res;2521 return res;
2534 }2522 }
25352523
2536 Token *promise = eat_token_if(pc, TokenIdKeywordPromise);
2537 if (promise != nullptr) {
2538 if (eat_token_if(pc, TokenIdArrow) != nullptr) {
2539 AstNode *res = ast_create_node(pc, NodeTypePromiseType, promise);
2540 return res;
2541 }
2542
2543 put_back_token(pc);
2544 }
2545
2546 AstNode *array = ast_parse_array_type_start(pc);2524 AstNode *array = ast_parse_array_type_start(pc);
2547 if (array != nullptr) {2525 if (array != nullptr) {
2548 assert(array->type == NodeTypeArrayType);2526 assert(array->type == NodeTypeArrayType);
...@@ -2680,11 +2658,6 @@ static AstNode *ast_parse_async_prefix(ParseContext *pc) {...@@ -2680,11 +2658,6 @@ static AstNode *ast_parse_async_prefix(ParseContext *pc) {
2680 AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, async);2658 AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, async);
2681 res->data.fn_call_expr.is_async = true;2659 res->data.fn_call_expr.is_async = true;
2682 res->data.fn_call_expr.seen = false;2660 res->data.fn_call_expr.seen = false;
2683 if (eat_token_if(pc, TokenIdCmpLessThan) != nullptr) {
2684 AstNode *prefix_expr = ast_expect(pc, ast_parse_prefix_expr);
2685 expect_token(pc, TokenIdCmpGreaterThan);
2686 res->data.fn_call_expr.async_allocator = prefix_expr;
2687 }
26882661
2689 return res;2662 return res;
2690}2663}
...@@ -2858,7 +2831,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont...@@ -2858,7 +2831,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
2858 visit_node_list(&node->data.fn_proto.params, visit, context);2831 visit_node_list(&node->data.fn_proto.params, visit, context);
2859 visit_field(&node->data.fn_proto.align_expr, visit, context);2832 visit_field(&node->data.fn_proto.align_expr, visit, context);
2860 visit_field(&node->data.fn_proto.section_expr, visit, context);2833 visit_field(&node->data.fn_proto.section_expr, visit, context);
2861 visit_field(&node->data.fn_proto.async_allocator_type, visit, context);
2862 break;2834 break;
2863 case NodeTypeFnDef:2835 case NodeTypeFnDef:
2864 visit_field(&node->data.fn_def.fn_proto, visit, context);2836 visit_field(&node->data.fn_def.fn_proto, visit, context);
...@@ -2918,7 +2890,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont...@@ -2918,7 +2890,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
2918 case NodeTypeFnCallExpr:2890 case NodeTypeFnCallExpr:
2919 visit_field(&node->data.fn_call_expr.fn_ref_expr, visit, context);2891 visit_field(&node->data.fn_call_expr.fn_ref_expr, visit, context);
2920 visit_node_list(&node->data.fn_call_expr.params, visit, context);2892 visit_node_list(&node->data.fn_call_expr.params, visit, context);
2921 visit_field(&node->data.fn_call_expr.async_allocator, visit, context);
2922 break;2893 break;
2923 case NodeTypeArrayAccessExpr:2894 case NodeTypeArrayAccessExpr:
2924 visit_field(&node->data.array_access_expr.array_ref_expr, visit, context);2895 visit_field(&node->data.array_access_expr.array_ref_expr, visit, context);
...@@ -3034,9 +3005,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont...@@ -3034,9 +3005,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
3034 case NodeTypeInferredArrayType:3005 case NodeTypeInferredArrayType:
3035 visit_field(&node->data.array_type.child_type, visit, context);3006 visit_field(&node->data.array_type.child_type, visit, context);
3036 break;3007 break;
3037 case NodeTypePromiseType:
3038 visit_field(&node->data.promise_type.payload_type, visit, context);
3039 break;
3040 case NodeTypeErrorType:3008 case NodeTypeErrorType:
3041 // none3009 // none
3042 break;3010 break;
src/tokenizer.cpp-2
...@@ -136,7 +136,6 @@ static const struct ZigKeyword zig_keywords[] = {...@@ -136,7 +136,6 @@ static const struct ZigKeyword zig_keywords[] = {
136 {"or", TokenIdKeywordOr},136 {"or", TokenIdKeywordOr},
137 {"orelse", TokenIdKeywordOrElse},137 {"orelse", TokenIdKeywordOrElse},
138 {"packed", TokenIdKeywordPacked},138 {"packed", TokenIdKeywordPacked},
139 {"promise", TokenIdKeywordPromise},
140 {"pub", TokenIdKeywordPub},139 {"pub", TokenIdKeywordPub},
141 {"resume", TokenIdKeywordResume},140 {"resume", TokenIdKeywordResume},
142 {"return", TokenIdKeywordReturn},141 {"return", TokenIdKeywordReturn},
...@@ -1558,7 +1557,6 @@ const char * token_name(TokenId id) {...@@ -1558,7 +1557,6 @@ const char * token_name(TokenId id) {
1558 case TokenIdKeywordOr: return "or";1557 case TokenIdKeywordOr: return "or";
1559 case TokenIdKeywordOrElse: return "orelse";1558 case TokenIdKeywordOrElse: return "orelse";
1560 case TokenIdKeywordPacked: return "packed";1559 case TokenIdKeywordPacked: return "packed";
1561 case TokenIdKeywordPromise: return "promise";
1562 case TokenIdKeywordPub: return "pub";1560 case TokenIdKeywordPub: return "pub";
1563 case TokenIdKeywordReturn: return "return";1561 case TokenIdKeywordReturn: return "return";
1564 case TokenIdKeywordLinkSection: return "linksection";1562 case TokenIdKeywordLinkSection: return "linksection";
src/tokenizer.hpp-1
...@@ -81,7 +81,6 @@ enum TokenId {...@@ -81,7 +81,6 @@ enum TokenId {
81 TokenIdKeywordOr,81 TokenIdKeywordOr,
82 TokenIdKeywordOrElse,82 TokenIdKeywordOrElse,
83 TokenIdKeywordPacked,83 TokenIdKeywordPacked,
84 TokenIdKeywordPromise,
85 TokenIdKeywordPub,84 TokenIdKeywordPub,
86 TokenIdKeywordResume,85 TokenIdKeywordResume,
87 TokenIdKeywordReturn,86 TokenIdKeywordReturn,
std/fmt.zig-3
...@@ -328,9 +328,6 @@ pub fn formatType(...@@ -328,9 +328,6 @@ pub fn formatType(
328 try output(context, "error.");328 try output(context, "error.");
329 return output(context, @errorName(value));329 return output(context, @errorName(value));
330 },330 },
331 .Promise => {
332 return format(context, Errors, output, "promise@{x}", @ptrToInt(value));
333 },
334 .Enum => {331 .Enum => {
335 if (comptime std.meta.trait.hasFn("format")(T)) {332 if (comptime std.meta.trait.hasFn("format")(T)) {
336 return value.format(fmt, options, context, Errors, output);333 return value.format(fmt, options, context, Errors, output);
std/hash_map.zig+1-1
...@@ -560,7 +560,7 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type...@@ -560,7 +560,7 @@ pub fn autoHash(key: var, comptime rng: *std.rand.Random, comptime HashInt: type
560 builtin.TypeId.Bool => return autoHash(@boolToInt(key), rng, HashInt),560 builtin.TypeId.Bool => return autoHash(@boolToInt(key), rng, HashInt),
561 builtin.TypeId.Enum => return autoHash(@enumToInt(key), rng, HashInt),561 builtin.TypeId.Enum => return autoHash(@enumToInt(key), rng, HashInt),
562 builtin.TypeId.ErrorSet => return autoHash(@errorToInt(key), rng, HashInt),562 builtin.TypeId.ErrorSet => return autoHash(@errorToInt(key), rng, HashInt),
563 builtin.TypeId.Promise, builtin.TypeId.Fn => return autoHash(@ptrToInt(key), rng, HashInt),563 builtin.TypeId.Fn => return autoHash(@ptrToInt(key), rng, HashInt),
564564
565 builtin.TypeId.BoundFn,565 builtin.TypeId.BoundFn,
566 builtin.TypeId.ComptimeFloat,566 builtin.TypeId.ComptimeFloat,
std/meta.zig+1-3
...@@ -104,8 +104,7 @@ pub fn Child(comptime T: type) type {...@@ -104,8 +104,7 @@ pub fn Child(comptime T: type) type {
104 TypeId.Array => |info| info.child,104 TypeId.Array => |info| info.child,
105 TypeId.Pointer => |info| info.child,105 TypeId.Pointer => |info| info.child,
106 TypeId.Optional => |info| info.child,106 TypeId.Optional => |info| info.child,
107 TypeId.Promise => |info| if (info.child) |child| child else null,107 else => @compileError("Expected pointer, optional, or array type, " ++ "found '" ++ @typeName(T) ++ "'"),
108 else => @compileError("Expected promise, pointer, optional, or array type, " ++ "found '" ++ @typeName(T) ++ "'"),
109 };108 };
110}109}
111110
...@@ -114,7 +113,6 @@ test "std.meta.Child" {...@@ -114,7 +113,6 @@ test "std.meta.Child" {
114 testing.expect(Child(*u8) == u8);113 testing.expect(Child(*u8) == u8);
115 testing.expect(Child([]u8) == u8);114 testing.expect(Child([]u8) == u8);
116 testing.expect(Child(?u8) == u8);115 testing.expect(Child(?u8) == u8);
117 testing.expect(Child(promise->u8) == u8);
118}116}
119117
120pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {118pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
std/testing.zig-1
...@@ -45,7 +45,6 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {...@@ -45,7 +45,6 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
45 TypeId.EnumLiteral,45 TypeId.EnumLiteral,
46 TypeId.Enum,46 TypeId.Enum,
47 TypeId.Fn,47 TypeId.Fn,
48 TypeId.Promise,
49 TypeId.Vector,48 TypeId.Vector,
50 TypeId.ErrorSet,49 TypeId.ErrorSet,
51 => {50 => {
test/stage1/behavior.zig+3-3
...@@ -39,11 +39,11 @@ comptime {...@@ -39,11 +39,11 @@ comptime {
39 _ = @import("behavior/bugs/828.zig");39 _ = @import("behavior/bugs/828.zig");
40 _ = @import("behavior/bugs/920.zig");40 _ = @import("behavior/bugs/920.zig");
41 _ = @import("behavior/byval_arg_var.zig");41 _ = @import("behavior/byval_arg_var.zig");
42 _ = @import("behavior/cancel.zig");42 //_ = @import("behavior/cancel.zig");
43 _ = @import("behavior/cast.zig");43 _ = @import("behavior/cast.zig");
44 _ = @import("behavior/const_slice_child.zig");44 _ = @import("behavior/const_slice_child.zig");
45 _ = @import("behavior/coroutine_await_struct.zig");45 //_ = @import("behavior/coroutine_await_struct.zig");
46 _ = @import("behavior/coroutines.zig");46 //_ = @import("behavior/coroutines.zig");
47 _ = @import("behavior/defer.zig");47 _ = @import("behavior/defer.zig");
48 _ = @import("behavior/enum.zig");48 _ = @import("behavior/enum.zig");
49 _ = @import("behavior/enum_with_members.zig");49 _ = @import("behavior/enum_with_members.zig");
test/stage1/behavior/type_info.zig+2-18
...@@ -116,21 +116,6 @@ fn testOptional() void {...@@ -116,21 +116,6 @@ fn testOptional() void {
116 expect(null_info.Optional.child == void);116 expect(null_info.Optional.child == void);
117}117}
118118
119test "type info: promise info" {
120 testPromise();
121 comptime testPromise();
122}
123
124fn testPromise() void {
125 const null_promise_info = @typeInfo(promise);
126 expect(TypeId(null_promise_info) == TypeId.Promise);
127 expect(null_promise_info.Promise.child == null);
128
129 const promise_info = @typeInfo(promise->usize);
130 expect(TypeId(promise_info) == TypeId.Promise);
131 expect(promise_info.Promise.child.? == usize);
132}
133
134test "type info: error set, error union info" {119test "type info: error set, error union info" {
135 testErrorSet();120 testErrorSet();
136 comptime testErrorSet();121 comptime testErrorSet();
...@@ -192,11 +177,11 @@ fn testUnion() void {...@@ -192,11 +177,11 @@ fn testUnion() void {
192 expect(TypeId(typeinfo_info) == TypeId.Union);177 expect(TypeId(typeinfo_info) == TypeId.Union);
193 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);178 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
194 expect(typeinfo_info.Union.tag_type.? == TypeId);179 expect(typeinfo_info.Union.tag_type.? == TypeId);
195 expect(typeinfo_info.Union.fields.len == 25);180 expect(typeinfo_info.Union.fields.len == 24);
196 expect(typeinfo_info.Union.fields[4].enum_field != null);181 expect(typeinfo_info.Union.fields[4].enum_field != null);
197 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);182 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
198 expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));183 expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));
199 expect(typeinfo_info.Union.decls.len == 21);184 expect(typeinfo_info.Union.decls.len == 20);
200185
201 const TestNoTagUnion = union {186 const TestNoTagUnion = union {
202 Foo: void,187 Foo: void,
...@@ -265,7 +250,6 @@ fn testFunction() void {...@@ -265,7 +250,6 @@ fn testFunction() void {
265 expect(fn_info.Fn.args.len == 2);250 expect(fn_info.Fn.args.len == 2);
266 expect(fn_info.Fn.is_var_args);251 expect(fn_info.Fn.is_var_args);
267 expect(fn_info.Fn.return_type == null);252 expect(fn_info.Fn.return_type == null);
268 expect(fn_info.Fn.async_allocator_type == null);
269253
270 const test_instance: TestStruct = undefined;254 const test_instance: TestStruct = undefined;
271 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));255 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));