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
signaturelock-open 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
466466 comp.link_objects = link_objects;
467467
468468 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);
470470 defer cancel process_build_events_handle;
471471 loop.run();
472472}
......@@ -578,7 +578,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
578578 var zig_compiler = try ZigCompiler.init(&loop);
579579 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);
582582 defer cancel handle;
583583
584584 loop.run();
......@@ -663,12 +663,12 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
663663 defer loop.deinit();
664664
665665 var result: FmtError!void = undefined;
666 const main_handle = try async<allocator> asyncFmtMainChecked(
667 &result,
668 &loop,
669 &flags,
670 color,
671 );
666 // TODO const main_handle = try async<allocator> asyncFmtMainChecked(
667 // TODO &result,
668 // TODO &loop,
669 // TODO &flags,
670 // TODO color,
671 // TODO );
672672 defer cancel main_handle;
673673 loop.run();
674674 return result;
src/all_types.hpp-191
......@@ -70,17 +70,6 @@ struct IrExecutable {
7070 Scope *begin_scope;
7171 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
8473 bool invalid;
8574 bool is_inline;
8675 bool is_generic_instantiation;
......@@ -489,7 +478,6 @@ enum NodeType {
489478 NodeTypeResume,
490479 NodeTypeAwaitExpr,
491480 NodeTypeSuspend,
492 NodeTypePromiseType,
493481 NodeTypeEnumLiteral,
494482};
495483
......@@ -522,7 +510,6 @@ struct AstNodeFnProto {
522510 AstNode *section_expr;
523511
524512 bool auto_err_set;
525 AstNode *async_allocator_type;
526513};
527514
528515struct AstNodeFnDef {
......@@ -657,7 +644,6 @@ struct AstNodeFnCallExpr {
657644 bool is_builtin;
658645 bool is_async;
659646 bool seen; // used by @compileLog
660 AstNode *async_allocator;
661647};
662648
663649struct AstNodeArrayAccessExpr {
......@@ -949,10 +935,6 @@ struct AstNodeSuspend {
949935 AstNode *block;
950936};
951937
952struct AstNodePromiseType {
953 AstNode *payload_type; // can be NULL
954};
955
956938struct AstNodeEnumLiteral {
957939 Token *period;
958940 Token *identifier;
......@@ -1018,7 +1000,6 @@ struct AstNode {
10181000 AstNodeResumeExpr resume_expr;
10191001 AstNodeAwaitExpr await_expr;
10201002 AstNodeSuspend suspend;
1021 AstNodePromiseType promise_type;
10221003 AstNodeEnumLiteral enum_literal;
10231004 } data;
10241005};
......@@ -1047,7 +1028,6 @@ struct FnTypeId {
10471028 bool is_var_args;
10481029 CallingConvention cc;
10491030 uint32_t alignment;
1050 ZigType *async_allocator_type;
10511031};
10521032
10531033uint32_t fn_type_id_hash(FnTypeId*);
......@@ -1241,11 +1221,6 @@ struct ZigTypeBoundFn {
12411221 ZigType *fn_type;
12421222};
12431223
1244struct ZigTypePromise {
1245 // null if `promise` instead of `promise->T`
1246 ZigType *result_type;
1247};
1248
12491224struct ZigTypeVector {
12501225 // The type must be a pointer, integer, or float
12511226 ZigType *elem_type;
......@@ -1276,7 +1251,6 @@ enum ZigTypeId {
12761251 ZigTypeIdBoundFn,
12771252 ZigTypeIdArgTuple,
12781253 ZigTypeIdOpaque,
1279 ZigTypeIdPromise,
12801254 ZigTypeIdVector,
12811255 ZigTypeIdEnumLiteral,
12821256};
......@@ -1314,7 +1288,6 @@ struct ZigType {
13141288 ZigTypeUnion unionation;
13151289 ZigTypeFn fn;
13161290 ZigTypeBoundFn bound_fn;
1317 ZigTypePromise promise;
13181291 ZigTypeVector vector;
13191292 ZigTypeOpaque opaque;
13201293 } data;
......@@ -1322,8 +1295,6 @@ struct ZigType {
13221295 // use these fields to make sure we don't duplicate type table entries for the same type
13231296 ZigType *pointer_parent[2]; // [0 - mut, 1 - const]
13241297 ZigType *optional_parent;
1325 ZigType *promise_parent;
1326 ZigType *promise_frame_parent;
13271298 // If we generate a constant name value for this type, we memoize it here.
13281299 // The type of this is array
13291300 ConstExprValue *cached_const_name_val;
......@@ -1709,20 +1680,6 @@ struct CodeGen {
17091680 LLVMValueRef trap_fn_val;
17101681 LLVMValueRef return_address_fn_val;
17111682 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;
17261683 LLVMValueRef add_error_return_trace_addr_fn_val;
17271684 LLVMValueRef stacksave_fn_val;
17281685 LLVMValueRef stackrestore_fn_val;
......@@ -1797,7 +1754,6 @@ struct CodeGen {
17971754 ZigType *entry_var;
17981755 ZigType *entry_global_error_set;
17991756 ZigType *entry_arg_tuple;
1800 ZigType *entry_promise;
18011757 ZigType *entry_enum_literal;
18021758 } builtin_types;
18031759 ZigType *align_amt_type;
......@@ -1985,7 +1941,6 @@ enum ScopeId {
19851941 ScopeIdSuspend,
19861942 ScopeIdFnDef,
19871943 ScopeIdCompTime,
1988 ScopeIdCoroPrelude,
19891944 ScopeIdRuntime,
19901945};
19911946
......@@ -2128,12 +2083,6 @@ struct ScopeFnDef {
21282083 ZigFn *fn_entry;
21292084};
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
21372086// synchronized with code in define_builtin_compile_vars
21382087enum AtomicOrder {
21392088 AtomicOrderUnordered,
......@@ -2231,7 +2180,6 @@ enum IrInstructionId {
22312180 IrInstructionIdSetRuntimeSafety,
22322181 IrInstructionIdSetFloatMode,
22332182 IrInstructionIdArrayType,
2234 IrInstructionIdPromiseType,
22352183 IrInstructionIdSliceType,
22362184 IrInstructionIdGlobalAsm,
22372185 IrInstructionIdAsm,
......@@ -2329,26 +2277,10 @@ enum IrInstructionId {
23292277 IrInstructionIdErrorReturnTrace,
23302278 IrInstructionIdErrorUnion,
23312279 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,
23452280 IrInstructionIdAtomicRmw,
23462281 IrInstructionIdAtomicLoad,
2347 IrInstructionIdPromiseResultType,
2348 IrInstructionIdAwaitBookkeeping,
23492282 IrInstructionIdSaveErrRetAddr,
23502283 IrInstructionIdAddImplicitReturnType,
2351 IrInstructionIdMergeErrRetTraces,
23522284 IrInstructionIdMarkErrRetTracePtr,
23532285 IrInstructionIdErrSetCast,
23542286 IrInstructionIdToBytes,
......@@ -2606,7 +2538,6 @@ struct IrInstructionCallSrc {
26062538 IrInstruction **args;
26072539 ResultLoc *result_loc;
26082540
2609 IrInstruction *async_allocator;
26102541 IrInstruction *new_stack;
26112542 FnInline fn_inline;
26122543 bool is_async;
......@@ -2622,7 +2553,6 @@ struct IrInstructionCallGen {
26222553 IrInstruction **args;
26232554 IrInstruction *result_loc;
26242555
2625 IrInstruction *async_allocator;
26262556 IrInstruction *new_stack;
26272557 FnInline fn_inline;
26282558 bool is_async;
......@@ -2743,12 +2673,6 @@ struct IrInstructionPtrType {
27432673 bool is_allow_zero;
27442674};
27452675
2746struct IrInstructionPromiseType {
2747 IrInstruction base;
2748
2749 IrInstruction *payload_type;
2750};
2751
27522676struct IrInstructionSliceType {
27532677 IrInstruction base;
27542678
......@@ -3178,7 +3102,6 @@ struct IrInstructionFnProto {
31783102 IrInstruction **param_types;
31793103 IrInstruction *align_value;
31803104 IrInstruction *return_type;
3181 IrInstruction *async_allocator_type_value;
31823105 bool is_var_args;
31833106};
31843107
......@@ -3414,89 +3337,6 @@ struct IrInstructionCancel {
34143337 IrInstruction *target;
34153338};
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
35003340struct IrInstructionAtomicRmw {
35013341 IrInstruction base;
35023342
......@@ -3518,18 +3358,6 @@ struct IrInstructionAtomicLoad {
35183358 AtomicOrder resolved_ordering;
35193359};
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
35333361struct IrInstructionSaveErrRetAddr {
35343362 IrInstruction base;
35353363};
......@@ -3540,14 +3368,6 @@ struct IrInstructionAddImplicitReturnType {
35403368 IrInstruction *value;
35413369};
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
35513371struct IrInstructionMarkErrRetTracePtr {
35523372 IrInstruction base;
35533373
......@@ -3777,17 +3597,6 @@ static const size_t err_union_payload_index = 1;
37773597// MUST BE A POWER OF TWO.
37783598static 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
37913600#define NAMESPACE_SEP_CHAR '.'
37923601#define NAMESPACE_SEP_STR "."
37933602
src/analyze.cpp+14-158
......@@ -188,12 +188,6 @@ Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent) {
188188 return &scope->base;
189189}
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
197191ZigType *get_scope_import(Scope *scope) {
198192 while (scope) {
199193 if (scope->id == ScopeIdDecls) {
......@@ -254,7 +248,6 @@ AstNode *type_decl_node(ZigType *type_entry) {
254248 case ZigTypeIdFn:
255249 case ZigTypeIdBoundFn:
256250 case ZigTypeIdArgTuple:
257 case ZigTypeIdPromise:
258251 case ZigTypeIdVector:
259252 return nullptr;
260253 }
......@@ -307,7 +300,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
307300 case ZigTypeIdFn:
308301 case ZigTypeIdBoundFn:
309302 case ZigTypeIdArgTuple:
310 case ZigTypeIdPromise:
311303 case ZigTypeIdVector:
312304 return true;
313305 }
......@@ -341,31 +333,6 @@ ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {
341333 return get_int_type(g, false, bits_needed_for_unsigned(x));
342334}
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
369336static const char *ptr_len_to_star_str(PtrLen ptr_len) {
370337 switch (ptr_len) {
371338 case PtrLenSingle:
......@@ -490,42 +457,6 @@ ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const) {
490457 return get_pointer_to_type_extra(g, child_type, is_const, false, PtrLenSingle, 0, 0, 0, false);
491458}
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
529460ZigType *get_optional_type(CodeGen *g, ZigType *child_type) {
530461 if (child_type->optional_parent != nullptr) {
531462 return child_type->optional_parent;
......@@ -879,13 +810,8 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
879810
880811 // populate the name of the type
881812 buf_resize(&fn_type->name, 0);
882 if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {
883 assert(fn_type_id->async_allocator_type != nullptr);
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 }
813 const char *cc_str = calling_convention_fn_type_str(fn_type->data.fn.fn_type_id.cc);
814 buf_appendf(&fn_type->name, "%s", cc_str);
889815 buf_appendf(&fn_type->name, "fn(");
890816 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
891817 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
......@@ -998,14 +924,8 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
998924ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
999925 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
1000926 buf_resize(&fn_type->name, 0);
1001 if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) {
1002 const char *async_allocator_type_str = (fn_type->data.fn.fn_type_id.async_allocator_type == nullptr) ?
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 }
927 const char *cc_str = calling_convention_fn_type_str(fn_type->data.fn.fn_type_id.cc);
928 buf_appendf(&fn_type->name, "%s", cc_str);
1009929 buf_appendf(&fn_type->name, "fn(");
1010930 size_t i = 0;
1011931 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
11191039 case ZigTypeIdBoundFn:
11201040 case ZigTypeIdArgTuple:
11211041 case ZigTypeIdOpaque:
1122 case ZigTypeIdPromise:
11231042 add_node_error(g, source_node,
11241043 buf_sprintf("type '%s' not allowed in packed struct; no guaranteed in-memory representation",
11251044 buf_ptr(&type_entry->name)));
......@@ -1207,7 +1126,6 @@ bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
12071126 case ZigTypeIdErrorSet:
12081127 case ZigTypeIdBoundFn:
12091128 case ZigTypeIdArgTuple:
1210 case ZigTypeIdPromise:
12111129 case ZigTypeIdVoid:
12121130 return false;
12131131 case ZigTypeIdOpaque:
......@@ -1378,7 +1296,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
13781296 case ZigTypeIdEnum:
13791297 case ZigTypeIdUnion:
13801298 case ZigTypeIdFn:
1381 case ZigTypeIdPromise:
13821299 case ZigTypeIdVector:
13831300 switch (type_requires_comptime(g, type_entry)) {
13841301 case ReqCompTimeNo:
......@@ -1474,7 +1391,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
14741391 case ZigTypeIdEnum:
14751392 case ZigTypeIdUnion:
14761393 case ZigTypeIdFn:
1477 case ZigTypeIdPromise:
14781394 case ZigTypeIdVector:
14791395 switch (type_requires_comptime(g, fn_type_id.return_type)) {
14801396 case ReqCompTimeInvalid:
......@@ -1487,16 +1403,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
14871403 break;
14881404 }
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
15001406 return get_fn_type(g, &fn_type_id);
15011407}
15021408
......@@ -3039,7 +2945,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
30392945 case NodeTypeResume:
30402946 case NodeTypeAwaitExpr:
30412947 case NodeTypeSuspend:
3042 case NodeTypePromiseType:
30432948 case NodeTypeEnumLiteral:
30442949 zig_unreachable();
30452950 }
......@@ -3091,7 +2996,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
30912996 case ZigTypeIdUnion:
30922997 case ZigTypeIdFn:
30932998 case ZigTypeIdBoundFn:
3094 case ZigTypeIdPromise:
30952999 case ZigTypeIdVector:
30963000 return type_entry;
30973001 }
......@@ -3591,7 +3495,6 @@ bool is_container(ZigType *type_entry) {
35913495 case ZigTypeIdBoundFn:
35923496 case ZigTypeIdArgTuple:
35933497 case ZigTypeIdOpaque:
3594 case ZigTypeIdPromise:
35953498 case ZigTypeIdVector:
35963499 return false;
35973500 }
......@@ -3648,7 +3551,6 @@ Error resolve_container_type(CodeGen *g, ZigType *type_entry) {
36483551 case ZigTypeIdInvalid:
36493552 case ZigTypeIdArgTuple:
36503553 case ZigTypeIdOpaque:
3651 case ZigTypeIdPromise:
36523554 case ZigTypeIdVector:
36533555 zig_unreachable();
36543556 }
......@@ -3658,13 +3560,11 @@ Error resolve_container_type(CodeGen *g, ZigType *type_entry) {
36583560ZigType *get_src_ptr_type(ZigType *type) {
36593561 if (type->id == ZigTypeIdPointer) return type;
36603562 if (type->id == ZigTypeIdFn) return type;
3661 if (type->id == ZigTypeIdPromise) return type;
36623563 if (type->id == ZigTypeIdOptional) {
36633564 if (type->data.maybe.child_type->id == ZigTypeIdPointer) {
36643565 return type->data.maybe.child_type->data.pointer.allow_zero ? nullptr : type->data.maybe.child_type;
36653566 }
36663567 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;
36683568 }
36693569 return nullptr;
36703570}
......@@ -3691,8 +3591,6 @@ uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
36913591 // when getting the alignment of `?extern fn() void`.
36923592 // See http://lists.llvm.org/pipermail/llvm-dev/2018-September/126142.html
36933593 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);
36963594 } else {
36973595 zig_unreachable();
36983596 }
......@@ -3704,8 +3602,6 @@ bool get_ptr_const(ZigType *type) {
37043602 return ptr_type->data.pointer.is_const;
37053603 } else if (ptr_type->id == ZigTypeIdFn) {
37063604 return true;
3707 } else if (ptr_type->id == ZigTypeIdPromise) {
3708 return true;
37093605 } else {
37103606 zig_unreachable();
37113607 }
......@@ -4102,7 +3998,6 @@ bool handle_is_ptr(ZigType *type_entry) {
41023998 case ZigTypeIdErrorSet:
41033999 case ZigTypeIdFn:
41044000 case ZigTypeIdEnum:
4105 case ZigTypeIdPromise:
41064001 case ZigTypeIdVector:
41074002 return false;
41084003 case ZigTypeIdArray:
......@@ -4142,7 +4037,6 @@ uint32_t fn_type_id_hash(FnTypeId *id) {
41424037 result += ((uint32_t)(id->cc)) * (uint32_t)3349388391;
41434038 result += id->is_var_args ? (uint32_t)1931444534 : 0;
41444039 result += hash_ptr(id->return_type);
4145 result += hash_ptr(id->async_allocator_type);
41464040 result += id->alignment * 0xd3b3f3e2;
41474041 for (size_t i = 0; i < id->param_count; i += 1) {
41484042 FnTypeParamInfo *info = &id->param_info[i];
......@@ -4157,8 +4051,7 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {
41574051 a->return_type != b->return_type ||
41584052 a->is_var_args != b->is_var_args ||
41594053 a->param_count != b->param_count ||
4160 a->alignment != b->alignment ||
4161 a->async_allocator_type != b->async_allocator_type)
4054 a->alignment != b->alignment)
41624055 {
41634056 return false;
41644057 }
......@@ -4320,9 +4213,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
43204213 return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry);
43214214 case ZigTypeIdPointer:
43224215 return hash_const_val_ptr(const_val);
4323 case ZigTypeIdPromise:
4324 // TODO better hashing algorithm
4325 return 223048345;
43264216 case ZigTypeIdUndefined:
43274217 return 162837799;
43284218 case ZigTypeIdNull:
......@@ -4418,7 +4308,6 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
44184308 case ZigTypeIdBoundFn:
44194309 case ZigTypeIdFn:
44204310 case ZigTypeIdOpaque:
4421 case ZigTypeIdPromise:
44224311 case ZigTypeIdErrorSet:
44234312 case ZigTypeIdEnum:
44244313 return false;
......@@ -4488,7 +4377,6 @@ static bool return_type_is_cacheable(ZigType *return_type) {
44884377 case ZigTypeIdBoundFn:
44894378 case ZigTypeIdFn:
44904379 case ZigTypeIdOpaque:
4491 case ZigTypeIdPromise:
44924380 case ZigTypeIdErrorSet:
44934381 case ZigTypeIdEnum:
44944382 case ZigTypeIdPointer:
......@@ -4623,7 +4511,6 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
46234511 case ZigTypeIdFn:
46244512 case ZigTypeIdBool:
46254513 case ZigTypeIdFloat:
4626 case ZigTypeIdPromise:
46274514 case ZigTypeIdErrorUnion:
46284515 return OnePossibleValueNo;
46294516 case ZigTypeIdUndefined:
......@@ -4712,7 +4599,6 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry) {
47124599 case ZigTypeIdFloat:
47134600 case ZigTypeIdVoid:
47144601 case ZigTypeIdUnreachable:
4715 case ZigTypeIdPromise:
47164602 return ReqCompTimeNo;
47174603 }
47184604 zig_unreachable();
......@@ -5278,7 +5164,6 @@ bool const_values_equal(CodeGen *g, ConstExprValue *a, ConstExprValue *b) {
52785164 case ZigTypeIdBoundFn:
52795165 case ZigTypeIdInvalid:
52805166 case ZigTypeIdUnreachable:
5281 case ZigTypeIdPromise:
52825167 zig_unreachable();
52835168 }
52845169 zig_unreachable();
......@@ -5611,8 +5496,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
56115496 buf_appendf(buf, "(args value)");
56125497 return;
56135498 }
5614 case ZigTypeIdPromise:
5615 zig_unreachable();
56165499 }
56175500 zig_unreachable();
56185501}
......@@ -5659,7 +5542,6 @@ uint32_t type_id_hash(TypeId x) {
56595542 case ZigTypeIdFn:
56605543 case ZigTypeIdBoundFn:
56615544 case ZigTypeIdArgTuple:
5662 case ZigTypeIdPromise:
56635545 zig_unreachable();
56645546 case ZigTypeIdErrorUnion:
56655547 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) {
57015583 case ZigTypeIdUndefined:
57025584 case ZigTypeIdNull:
57035585 case ZigTypeIdOptional:
5704 case ZigTypeIdPromise:
57055586 case ZigTypeIdErrorSet:
57065587 case ZigTypeIdEnum:
57075588 case ZigTypeIdUnion:
......@@ -5874,7 +5755,6 @@ static const ZigTypeId all_type_ids[] = {
58745755 ZigTypeIdBoundFn,
58755756 ZigTypeIdArgTuple,
58765757 ZigTypeIdOpaque,
5877 ZigTypeIdPromise,
58785758 ZigTypeIdVector,
58795759 ZigTypeIdEnumLiteral,
58805760};
......@@ -5938,12 +5818,10 @@ size_t type_id_index(ZigType *entry) {
59385818 return 20;
59395819 case ZigTypeIdOpaque:
59405820 return 21;
5941 case ZigTypeIdPromise:
5942 return 22;
59435821 case ZigTypeIdVector:
5944 return 23;
5822 return 22;
59455823 case ZigTypeIdEnumLiteral:
5946 return 24;
5824 return 23;
59475825 }
59485826 zig_unreachable();
59495827}
......@@ -5998,8 +5876,6 @@ const char *type_id_name(ZigTypeId id) {
59985876 return "ArgTuple";
59995877 case ZigTypeIdOpaque:
60005878 return "Opaque";
6001 case ZigTypeIdPromise:
6002 return "Promise";
60035879 case ZigTypeIdVector:
60045880 return "Vector";
60055881 }
......@@ -6066,13 +5942,6 @@ bool type_is_global_error_set(ZigType *err_set_type) {
60665942 return err_set_type->data.error_set.err_count == UINT32_MAX;
60675943}
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
60765945bool type_can_fail(ZigType *type_entry) {
60775946 return type_entry->id == ZigTypeIdErrorUnion || type_entry->id == ZigTypeIdErrorSet;
60785947}
......@@ -7105,19 +6974,13 @@ static void resolve_llvm_types_fn(CodeGen *g, ZigType *fn_type) {
71056974 param_di_types.append(get_llvm_di_type(g, gen_type));
71066975 }
71076976 if (is_async) {
7108 {
7109 // async allocator param
7110 ZigType *gen_type = fn_type_id->async_allocator_type;
7111 gen_param_types.append(get_llvm_type(g, gen_type));
7112 param_di_types.append(get_llvm_di_type(g, gen_type));
7113 }
7114
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 }
6977 // coroutine frame pointer
6978 // TODO if we can make this typed a little more it will be better for
6979 // debug symbols.
6980 // TODO do we need to make this aligned more?
6981 ZigType *void_star = get_pointer_to_type(g, g->builtin_types.entry_c_void, false);
6982 gen_param_types.append(get_llvm_type(g, void_star));
6983 param_di_types.append(get_llvm_di_type(g, void_star));
71216984 }
71226985
71236986 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
72247087 return resolve_llvm_types_union(g, type, wanted_resolve_status);
72257088 case ZigTypeIdPointer:
72267089 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 }
72347090 case ZigTypeIdInt:
72357091 return resolve_llvm_types_integer(g, type);
72367092 case ZigTypeIdOptional:
src/analyze.hpp-4
......@@ -39,8 +39,6 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry);
3939ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *full_name, Buf *bare_name);
4040ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
4141 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);
4442ZigType *get_test_fn_type(CodeGen *g);
4543bool handle_is_ptr(ZigType *type_entry);
4644
......@@ -117,7 +115,6 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);
117115ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);
118116ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);
119117Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);
120Scope *create_coro_prelude_scope(CodeGen *g, AstNode *node, Scope *parent);
121118Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime);
122119
123120void 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
204201
205202ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry);
206203
207uint32_t get_coro_frame_align_bytes(CodeGen *g);
208204bool fn_type_can_fail(FnTypeId *fn_type_id);
209205bool type_can_fail(ZigType *type_entry);
210206bool 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) {
257257 return "AwaitExpr";
258258 case NodeTypeSuspend:
259259 return "Suspend";
260 case NodeTypePromiseType:
261 return "PromiseType";
262260 case NodeTypePointerType:
263261 return "PointerType";
264262 case NodeTypeEnumLiteral:
......@@ -692,13 +690,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
692690 fprintf(ar->f, "@");
693691 }
694692 if (node->data.fn_call_expr.is_async) {
695 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, " ");
693 fprintf(ar->f, "async ");
702694 }
703695 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;
704696 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) {
855847 render_node_ungrouped(ar, node->data.inferred_array_type.child_type);
856848 break;
857849 }
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 }
867850 case NodeTypeErrorType:
868851 fprintf(ar->f, "anyerror");
869852 break;
src/codegen.cpp+4-670
......@@ -721,7 +721,6 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
721721 case ScopeIdLoop:
722722 case ScopeIdSuspend:
723723 case ScopeIdCompTime:
724 case ScopeIdCoroPrelude:
725724 case ScopeIdRuntime:
726725 return get_di_scope(g, scope->parent);
727726 }
......@@ -1083,177 +1082,6 @@ static LLVMValueRef get_write_register_fn_val(CodeGen *g) {
10831082 return g->write_register_fn_val;
10841083}
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
12571085static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
12581086 if (g->return_address_fn_val)
12591087 return g->return_address_fn_val;
......@@ -1346,140 +1174,6 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
13461174 return fn_val;
13471175}
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
14831177static LLVMValueRef get_return_err_fn(CodeGen *g) {
14841178 if (g->return_err_fn != nullptr)
14851179 return g->return_err_fn;
......@@ -1667,24 +1361,12 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
16671361 return fn_val;
16681362}
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
16821364static LLVMValueRef get_cur_err_ret_trace_val(CodeGen *g, Scope *scope) {
16831365 if (!g->have_err_ret_tracing) {
16841366 return nullptr;
16851367 }
16861368 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;
16881370 }
16891371 if (g->cur_err_ret_trace_val_stack != nullptr) {
16901372 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) {
36973379 fn_type_id->cc == CallingConventionAsync);
36983380}
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
37133382static LLVMValueRef get_new_stack_addr(CodeGen *g, LLVMValueRef new_stack) {
37143383 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, new_stack, (unsigned)slice_ptr_index, "");
37153384 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
37783447 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope));
37793448 }
37803449 if (instruction->is_async) {
3781 gen_param_values.append(ir_llvm_value(g, instruction->async_allocator));
3782
3783 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, result_loc, err_union_err_index, "");
3784 gen_param_values.append(err_val_ptr);
3450 zig_panic("TODO codegen async call");
37853451 }
37863452 FnWalk fn_walk = {};
37873453 fn_walk.id = FnWalkIdCall;
......@@ -4471,10 +4137,6 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
44714137 {
44724138 align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment;
44734139 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");
44784140 } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) {
44794141 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry;
44804142 align_bytes = get_ptr_align(g, slice_ptr_type);
......@@ -4519,17 +4181,7 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu
45194181}
45204182
45214183static LLVMValueRef ir_render_cancel(CodeGen *g, IrExecutable *executable, IrInstructionCancel *instruction) {
4522 LLVMValueRef target_handle = ir_llvm_value(g, instruction->target);
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);
4184 zig_panic("TODO cancel");
45334185}
45344186
45354187static LLVMAtomicOrdering to_LLVMAtomicOrdering(AtomicOrder atomic_order) {
......@@ -4840,24 +4492,10 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable
48404492 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");
48414493}
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
48564495static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,
48574496 IrInstructionHandle *instruction)
48584497{
4859 LLVMValueRef zero = LLVMConstNull(get_llvm_type(g, g->builtin_types.entry_promise));
4860 return LLVMBuildCall(g->builder, get_handle_fn_val(g), &zero, 0, "");
4498 zig_panic("TODO @handle() codegen");
48614499}
48624500
48634501static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {
......@@ -5123,248 +4761,6 @@ static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutable *executable, IrInst
51234761 return nullptr;
51244762}
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
53684764static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
53694765 IrInstructionAtomicRmw *instruction)
53704766{
......@@ -5402,19 +4798,6 @@ static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,
54024798 return load_inst;
54034799}
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
54184801static LLVMValueRef ir_render_mark_err_ret_trace_ptr(CodeGen *g, IrExecutable *executable,
54194802 IrInstructionMarkErrRetTracePtr *instruction)
54204803{
......@@ -5559,7 +4942,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
55594942 case IrInstructionIdSetRuntimeSafety:
55604943 case IrInstructionIdSetFloatMode:
55614944 case IrInstructionIdArrayType:
5562 case IrInstructionIdPromiseType:
55634945 case IrInstructionIdSliceType:
55644946 case IrInstructionIdSizeOf:
55654947 case IrInstructionIdSwitchTarget:
......@@ -5599,8 +4981,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
55994981 case IrInstructionIdTagType:
56004982 case IrInstructionIdExport:
56014983 case IrInstructionIdErrorUnion:
5602 case IrInstructionIdPromiseResultType:
5603 case IrInstructionIdAwaitBookkeeping:
56044984 case IrInstructionIdAddImplicitReturnType:
56054985 case IrInstructionIdIntCast:
56064986 case IrInstructionIdFloatCast:
......@@ -5757,40 +5137,12 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
57575137 return ir_render_error_return_trace(g, executable, (IrInstructionErrorReturnTrace *)instruction);
57585138 case IrInstructionIdCancel:
57595139 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);
57865140 case IrInstructionIdAtomicRmw:
57875141 return ir_render_atomic_rmw(g, executable, (IrInstructionAtomicRmw *)instruction);
57885142 case IrInstructionIdAtomicLoad:
57895143 return ir_render_atomic_load(g, executable, (IrInstructionAtomicLoad *)instruction);
57905144 case IrInstructionIdSaveErrRetAddr:
57915145 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);
57945146 case IrInstructionIdMarkErrRetTracePtr:
57955147 return ir_render_mark_err_ret_trace_ptr(g, executable, (IrInstructionMarkErrRetTracePtr *)instruction);
57965148 case IrInstructionIdFloatOp:
......@@ -6008,7 +5360,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
60085360 case ZigTypeIdPointer:
60095361 case ZigTypeIdFn:
60105362 case ZigTypeIdOptional:
6011 case ZigTypeIdPromise:
60125363 {
60135364 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");
60145365 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
65915942 case ZigTypeIdBoundFn:
65925943 case ZigTypeIdArgTuple:
65935944 case ZigTypeIdOpaque:
6594 case ZigTypeIdPromise:
65955945 zig_unreachable();
65965946
65975947 }
......@@ -7294,13 +6644,6 @@ static void define_builtin_types(CodeGen *g) {
72946644
72956645 g->primitive_type_table.put(&entry->name, entry);
72966646 }
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 }
73046647}
73056648
73066649
......@@ -7729,7 +7072,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
77297072 " BoundFn: Fn,\n"
77307073 " ArgTuple: void,\n"
77317074 " Opaque: void,\n"
7732 " Promise: Promise,\n"
77337075 " Vector: Vector,\n"
77347076 " EnumLiteral: void,\n"
77357077 "\n\n"
......@@ -7842,14 +7184,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
78427184 " is_generic: bool,\n"
78437185 " is_var_args: bool,\n"
78447186 " return_type: ?type,\n"
7845 " async_allocator_type: ?type,\n"
78467187 " args: []FnArg,\n"
78477188 " };\n"
78487189 "\n"
7849 " pub const Promise = struct {\n"
7850 " child: ?type,\n"
7851 " };\n"
7852 "\n"
78537190 " pub const Vector = struct {\n"
78547191 " len: comptime_int,\n"
78557192 " child: type,\n"
......@@ -8998,7 +8335,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
89988335 case ZigTypeIdArgTuple:
89998336 case ZigTypeIdErrorUnion:
90008337 case ZigTypeIdErrorSet:
9001 case ZigTypeIdPromise:
90028338 zig_unreachable();
90038339 case ZigTypeIdVoid:
90048340 case ZigTypeIdUnreachable:
......@@ -9182,7 +8518,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
91828518 case ZigTypeIdUndefined:
91838519 case ZigTypeIdNull:
91848520 case ZigTypeIdArgTuple:
9185 case ZigTypeIdPromise:
91868521 zig_unreachable();
91878522 }
91888523}
......@@ -9349,7 +8684,6 @@ static void gen_h_file(CodeGen *g) {
93498684 case ZigTypeIdArgTuple:
93508685 case ZigTypeIdOptional:
93518686 case ZigTypeIdFn:
9352 case ZigTypeIdPromise:
93538687 case ZigTypeIdVector:
93548688 zig_unreachable();
93558689 case ZigTypeIdEnum:
src/ir.cpp+26-1513
......@@ -99,7 +99,6 @@ struct ConstCastOnly {
9999 ConstCastErrUnionErrSetMismatch *error_union_error_set;
100100 ConstCastTypeMismatch *type_mismatch;
101101 ConstCastOnly *return_type;
102 ConstCastOnly *async_allocator_type;
103102 ConstCastOnly *null_wrap_ptr_child;
104103 ConstCastArg fn_arg;
105104 ConstCastArgNoAlias arg_no_alias;
......@@ -318,7 +317,6 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
318317 case ZigTypeIdUnion:
319318 case ZigTypeIdFn:
320319 case ZigTypeIdArgTuple:
321 case ZigTypeIdPromise:
322320 case ZigTypeIdVector:
323321 return false;
324322 }
......@@ -564,10 +562,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayType *) {
564562 return IrInstructionIdArrayType;
565563}
566564
567static constexpr IrInstructionId ir_instruction_id(IrInstructionPromiseType *) {
568 return IrInstructionIdPromiseType;
569}
570
571565static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceType *) {
572566 return IrInstructionIdSliceType;
573567}
......@@ -964,58 +958,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionCancel *) {
964958 return IrInstructionIdCancel;
965959}
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
1019961static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicRmw *) {
1020962 return IrInstructionIdAtomicRmw;
1021963}
......@@ -1024,14 +966,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicLoad *) {
1024966 return IrInstructionIdAtomicLoad;
1025967}
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
1035969static constexpr IrInstructionId ir_instruction_id(IrInstructionSaveErrRetAddr *) {
1036970 return IrInstructionIdSaveErrRetAddr;
1037971}
......@@ -1040,10 +974,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAddImplicitRetur
1040974 return IrInstructionIdAddImplicitReturnType;
1041975}
1042976
1043static constexpr IrInstructionId ir_instruction_id(IrInstructionMergeErrRetTraces *) {
1044 return IrInstructionIdMergeErrRetTraces;
1045}
1046
1047977static constexpr IrInstructionId ir_instruction_id(IrInstructionMarkErrRetTracePtr *) {
1048978 return IrInstructionIdMarkErrRetTracePtr;
1049979}
......@@ -1213,14 +1143,6 @@ static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode
12131143 return &const_instruction->base;
12141144}
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
12241146static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
12251147 ZigType *type_entry)
12261148{
......@@ -1428,7 +1350,7 @@ static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, Ast
14281350
14291351static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
14301352 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,
14321354 IrInstruction *new_stack, ResultLoc *result_loc)
14331355{
14341356 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
14391361 call_instruction->args = args;
14401362 call_instruction->arg_count = arg_count;
14411363 call_instruction->is_async = is_async;
1442 call_instruction->async_allocator = async_allocator;
14431364 call_instruction->new_stack = new_stack;
14441365 call_instruction->result_loc = result_loc;
14451366
14461367 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, irb->current_basic_block);
14471368 for (size_t i = 0; i < arg_count; i += 1)
14481369 ir_ref_instruction(args[i], irb->current_basic_block);
1449 if (async_allocator != nullptr) ir_ref_instruction(async_allocator, irb->current_basic_block);
14501370 if (new_stack != nullptr) ir_ref_instruction(new_stack, irb->current_basic_block);
14511371
14521372 return &call_instruction->base;
......@@ -1454,7 +1374,7 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s
14541374
14551375static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction,
14561376 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,
14581378 IrInstruction *result_loc, ZigType *return_type)
14591379{
14601380 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
14661386 call_instruction->args = args;
14671387 call_instruction->arg_count = arg_count;
14681388 call_instruction->is_async = is_async;
1469 call_instruction->async_allocator = async_allocator;
14701389 call_instruction->new_stack = new_stack;
14711390 call_instruction->result_loc = result_loc;
14721391
14731392 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block);
14741393 for (size_t i = 0; i < arg_count; i += 1)
14751394 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);
14771395 if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block);
14781396 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
17531671 return &instruction->base;
17541672}
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
17671674static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
17681675 IrInstruction *child_type, bool is_const, bool is_volatile, IrInstruction *align_value, bool is_allow_zero)
17691676{
......@@ -2595,13 +2502,12 @@ static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope,
25952502
25962503static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node,
25972504 IrInstruction **param_types, IrInstruction *align_value, IrInstruction *return_type,
2598 IrInstruction *async_allocator_type_value, bool is_var_args)
2505 bool is_var_args)
25992506{
26002507 IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node);
26012508 instruction->param_types = param_types;
26022509 instruction->align_value = align_value;
26032510 instruction->return_type = return_type;
2604 instruction->async_allocator_type_value = async_allocator_type_value;
26052511 instruction->is_var_args = is_var_args;
26062512
26072513 assert(source_node->type == NodeTypeFnProto);
......@@ -2611,7 +2517,6 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s
26112517 if (param_types[i] != nullptr) ir_ref_instruction(param_types[i], irb->current_basic_block);
26122518 }
26132519 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);
26152520 ir_ref_instruction(return_type, irb->current_basic_block);
26162521
26172522 return &instruction->base;
......@@ -3055,149 +2960,6 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode
30552960 return &instruction->base;
30562961}
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
32012963static IrInstruction *ir_build_atomic_rmw(IrBuilder *irb, Scope *scope, AstNode *source_node,
32022964 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *op, IrInstruction *operand,
32032965 IrInstruction *ordering, AtomicRmwOp resolved_op, AtomicOrder resolved_ordering)
......@@ -3237,28 +2999,6 @@ static IrInstruction *ir_build_atomic_load(IrBuilder *irb, Scope *scope, AstNode
32372999 return &instruction->base;
32383000}
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
32623002static IrInstruction *ir_build_save_err_ret_addr(IrBuilder *irb, Scope *scope, AstNode *source_node) {
32633003 IrInstructionSaveErrRetAddr *instruction = ir_build_instruction<IrInstructionSaveErrRetAddr>(irb, scope, source_node);
32643004 return &instruction->base;
......@@ -3275,21 +3015,6 @@ static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *s
32753015 return &instruction->base;
32763016}
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
32933018static IrInstruction *ir_build_mark_err_ret_trace_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *err_ret_trace_ptr) {
32943019 IrInstructionMarkErrRetTracePtr *instruction = ir_build_instruction<IrInstructionMarkErrRetTracePtr>(irb, scope, source_node);
32953020 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
34883213 continue;
34893214 case ScopeIdDeferExpr:
34903215 case ScopeIdCImport:
3491 case ScopeIdCoroPrelude:
34923216 zig_unreachable();
34933217 }
34943218 }
......@@ -3544,7 +3268,6 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
35443268 continue;
35453269 case ScopeIdDeferExpr:
35463270 case ScopeIdCImport:
3547 case ScopeIdCoroPrelude:
35483271 zig_unreachable();
35493272 }
35503273 }
......@@ -3563,18 +3286,6 @@ static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *
35633286 ir_set_cursor_at_end(irb, basic_block);
35643287}
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
35783289static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {
35793290 while (scope) {
35803291 if (scope->id == ScopeIdDeferExpr)
......@@ -3604,47 +3315,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode
36043315 return return_inst;
36053316 }
36063317
3607 IrBasicBlock *suspended_block = ir_create_basic_block(irb, scope, "Suspended");
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);
3318 zig_panic("TODO async return");
36483319}
36493320
36503321static 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
53865057 FnInline fn_inline = (builtin_fn->id == BuiltinFnIdInlineCall) ? FnInlineAlways : FnInlineNever;
53875058
53885059 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);
53905061 return ir_lval_wrap(irb, scope, call, lval, result_loc);
53915062 }
53925063 case BuiltinFnIdNewStackCall:
......@@ -5417,7 +5088,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
54175088 }
54185089
54195090 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);
54215092 return ir_lval_wrap(irb, scope, call, lval, result_loc);
54225093 }
54235094 case BuiltinFnIdTypeId:
......@@ -5722,17 +5393,12 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
57225393 }
57235394
57245395 bool is_async = node->data.fn_call_expr.is_async;
5725 IrInstruction *async_allocator = nullptr;
57265396 if (is_async) {
5727 if (node->data.fn_call_expr.async_allocator) {
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 }
5397 zig_panic("TODO async fn call");
57325398 }
57335399
57345400 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);
57365402 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);
57375403}
57385404
......@@ -6751,22 +6417,6 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
67516417 }
67526418}
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
67706420static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
67716421 assert(node->type == NodeTypeUndefinedLiteral);
67726422 return ir_build_const_undefined(irb, scope, node);
......@@ -7969,87 +7619,7 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
79697619 //return_type = nullptr;
79707620 }
79717621
7972 IrInstruction *async_allocator_type_value = nullptr;
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);
7622 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, return_type, is_var_args);
80537623}
80547624
80557625static 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)
80597629 if (target_inst == irb->codegen->invalid_instruction)
80607630 return irb->codegen->invalid_instruction;
80617631
8062 return ir_gen_cancel_target(irb, scope, node, target_inst, false, true);
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);
7632 zig_panic("TODO ir_gen_cancel");
81137633}
81147634
81157635static 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)
81197639 if (target_inst == irb->codegen->invalid_instruction)
81207640 return irb->codegen->invalid_instruction;
81217641
8122 return ir_gen_resume_target(irb, scope, node, target_inst);
7642 zig_panic("TODO ir_gen_resume");
81237643}
81247644
81257645static 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
81297649 if (target_inst == irb->codegen->invalid_instruction)
81307650 return irb->codegen->invalid_instruction;
81317651
8132 ZigFn *fn_entry = exec_fn_entry(irb->exec);
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);
7652 zig_panic("TODO ir_gen_await_expr");
83057653}
83067654
83077655static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) {
83087656 assert(node->type == NodeTypeSuspend);
83097657
8310 ZigFn *fn_entry = exec_fn_entry(irb->exec);
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));
7658 zig_panic("TODO ir_gen_suspend");
84247659}
84257660
84267661static 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
85127747 return ir_lval_wrap(irb, scope, ir_gen_array_type(irb, scope, node), lval, result_loc);
85137748 case NodeTypePointerType:
85147749 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);
85177750 case NodeTypeStringLiteral:
85187751 return ir_lval_wrap(irb, scope, ir_gen_string_literal(irb, scope, node), lval, result_loc);
85197752 case NodeTypeUndefinedLiteral:
......@@ -8624,105 +7857,8 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
86247857 ZigFn *fn_entry = exec_fn_entry(irb->exec);
86257858
86267859 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;
86357860 if (is_async) {
8636 // create the coro promise
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");
7861 zig_panic("ir_gen async fn");
87267862 }
87277863
87287864 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
87357871 ir_gen_async_return(irb, scope, result->source_node, result, true);
87367872 }
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
88497874 return true;
88507875}
88517876
......@@ -10189,12 +9214,6 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
101899214 return result;
101909215 }
101919216
10192 if (wanted_type == ira->codegen->builtin_types.entry_promise &&
10193 actual_type->id == ZigTypeIdPromise)
10194 {
10195 return result;
10196 }
10197
101989217 // fn
101999218 if (wanted_type->id == ZigTypeIdFn &&
102009219 actual_type->id == ZigTypeIdFn)
......@@ -10229,20 +9248,6 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
102299248 return result;
102309249 }
102319250 }
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 }
102469251 if (wanted_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {
102479252 result.id = ConstCastResultIdFnArgCount;
102489253 return result;
......@@ -12559,12 +11564,10 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
1255911564static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
1256011565 if (ty->id == ZigTypeIdPointer) return ty->data.pointer.child_type->id != ZigTypeIdPointer;
1256111566 if (ty->id == ZigTypeIdFn) return true;
12562 if (ty->id == ZigTypeIdPromise) return true;
1256311567 if (ty->id == ZigTypeIdOptional) {
1256411568 ZigType *ptr_ty = ty->data.maybe.child_type;
1256511569 if (ptr_ty->id == ZigTypeIdPointer) return ptr_ty->data.pointer.child_type->id != ZigTypeIdPointer;
1256611570 if (ptr_ty->id == ZigTypeIdFn) return true;
12567 if (ptr_ty->id == ZigTypeIdPromise) return true;
1256811571 }
1256911572 return false;
1257011573}
......@@ -13640,7 +12643,6 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1364012643 case ZigTypeIdOpaque:
1364112644 case ZigTypeIdBoundFn:
1364212645 case ZigTypeIdArgTuple:
13643 case ZigTypeIdPromise:
1364412646 case ZigTypeIdEnum:
1364512647 case ZigTypeIdEnumLiteral:
1364612648 operator_allowed = is_equality_cmp;
......@@ -15021,7 +14023,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1502114023 case ZigTypeIdBoundFn:
1502214024 case ZigTypeIdArgTuple:
1502314025 case ZigTypeIdOpaque:
15024 case ZigTypeIdPromise:
1502514026 ir_add_error(ira, target,
1502614027 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
1502714028 break;
......@@ -15045,7 +14046,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1504514046 case ZigTypeIdBoundFn:
1504614047 case ZigTypeIdArgTuple:
1504714048 case ZigTypeIdOpaque:
15048 case ZigTypeIdPromise:
1504914049 case ZigTypeIdEnumLiteral:
1505014050 ir_add_error(ira, target,
1505114051 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,
1512414124 return ir_const_type(ira, &instruction->base, result_type);
1512514125}
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
1516314127static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_inst, ZigType *var_type,
1516414128 uint32_t align, const char *name_hint, bool force_comptime)
1516514129{
......@@ -15589,50 +14553,6 @@ static IrInstruction *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInst
1558914553 return ir_const_void(ira, &instruction->base);
1559014554}
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
1563614556static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node,
1563714557 IrInstruction *arg, Scope **exec_scope, size_t *next_proto_i)
1563814558{
......@@ -16330,32 +15250,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1633015250 break;
1633115251 }
1633215252 }
16333 IrInstruction *async_allocator_inst = nullptr;
1633415253 if (call_instruction->is_async) {
16335 AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type;
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;
15254 zig_panic("TODO async call");
1635915255 }
1636015256
1636115257 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
1639815294
1639915295 size_t impl_param_count = impl_fn_type_id->param_count;
1640015296 if (call_instruction->is_async) {
16401 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry,
16402 fn_ref, casted_args, impl_param_count, async_allocator_inst);
16403 return ir_finish_anal(ira, result);
15297 zig_panic("TODO async call");
1640415298 }
1640515299
16406 assert(async_allocator_inst == nullptr);
1640715300 IrInstruction *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base,
1640815301 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,
1641015303 impl_fn_type_id->return_type);
1641115304
1641215305 return ir_finish_anal(ira, new_call_instruction);
......@@ -16474,25 +15367,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1647415367 return ira->codegen->invalid_instruction;
1647515368
1647615369 if (call_instruction->is_async) {
16477 IrInstruction *uncasted_async_allocator_inst;
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);
15370 zig_panic("TODO async call");
1649615371 }
1649715372
1649815373 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
1651315388 }
1651415389
1651515390 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,
1651715392 result_loc, return_type);
1651815393 return ir_finish_anal(ira, new_call_instruction);
1651915394}
......@@ -16694,7 +15569,6 @@ static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_
1669415569 case ZigTypeIdFn:
1669515570 case ZigTypeIdBoundFn:
1669615571 case ZigTypeIdArgTuple:
16697 case ZigTypeIdPromise:
1669815572 return ir_const_type(ira, &un_op_instruction->base, get_optional_type(ira->codegen, type_entry));
1669915573 case ZigTypeIdUnreachable:
1670015574 case ZigTypeIdOpaque:
......@@ -18465,7 +17339,6 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
1846517339 case ZigTypeIdUnion:
1846617340 case ZigTypeIdFn:
1846717341 case ZigTypeIdBoundFn:
18468 case ZigTypeIdPromise:
1846917342 case ZigTypeIdVector:
1847017343 {
1847117344 ResolveStatus needed_status = (align_bytes == 0) ?
......@@ -18580,7 +17453,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
1858017453 case ZigTypeIdUnion:
1858117454 case ZigTypeIdFn:
1858217455 case ZigTypeIdBoundFn:
18583 case ZigTypeIdPromise:
1858417456 case ZigTypeIdVector:
1858517457 {
1858617458 if ((err = ensure_complete_type(ira->codegen, child_type)))
......@@ -18592,22 +17464,6 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
1859217464 zig_unreachable();
1859317465}
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
1861117467static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,
1861217468 IrInstructionSizeOf *size_of_instruction)
1861317469{
......@@ -18647,7 +17503,6 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira,
1864717503 case ZigTypeIdEnum:
1864817504 case ZigTypeIdUnion:
1864917505 case ZigTypeIdFn:
18650 case ZigTypeIdPromise:
1865117506 case ZigTypeIdVector:
1865217507 {
1865317508 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);
......@@ -19134,7 +17989,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1913417989 case ZigTypeIdComptimeInt:
1913517990 case ZigTypeIdEnumLiteral:
1913617991 case ZigTypeIdPointer:
19137 case ZigTypeIdPromise:
1913817992 case ZigTypeIdFn:
1913917993 case ZigTypeIdErrorSet: {
1914017994 if (pointee_val) {
......@@ -20645,32 +19499,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2064519499 fields[0].type = ira->codegen->builtin_types.entry_type;
2064619500 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
2067419502 break;
2067519503 }
2067619504 case ZigTypeIdEnum:
......@@ -20982,7 +19810,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2098219810 result->special = ConstValSpecialStatic;
2098319811 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);
2098619814 result->data.x_struct.fields = fields;
2098719815
2098819816 // calling_convention: TypeInfo.CallingConvention
......@@ -21015,19 +19843,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2101519843 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
2101619844 fields[3].data.x_optional = return_type;
2101719845 }
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 }
2103119846 // args: []TypeInfo.FnArg
2103219847 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
2103319848 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
2104219857 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
2104319858 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++)
21048 {
19862 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
2104919863 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];
2105019864 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
2280321617}
2280421618
2280521619static 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);
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;
21620 zig_panic("TODO anlayze @handle()");
2281121621}
2281221622
2281321623static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
......@@ -22841,7 +21651,6 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
2284121651 case ZigTypeIdInt:
2284221652 case ZigTypeIdFloat:
2284321653 case ZigTypeIdPointer:
22844 case ZigTypeIdPromise:
2284521654 case ZigTypeIdArray:
2284621655 case ZigTypeIdStruct:
2284721656 case ZigTypeIdOptional:
......@@ -23401,15 +22210,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
2340122210 }
2340222211
2340322212 if (fn_type_id.cc == CallingConventionAsync) {
23404 if (instruction->async_allocator_type_value == nullptr) {
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;
22213 zig_panic("TODO");
2341322214 }
2341422215
2341522216 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
2390522706 case ZigTypeIdEnumLiteral:
2390622707 case ZigTypeIdUndefined:
2390722708 case ZigTypeIdNull:
23908 case ZigTypeIdPromise:
2390922709 case ZigTypeIdErrorUnion:
2391022710 case ZigTypeIdErrorSet:
2391122711 zig_unreachable();
......@@ -24059,7 +22859,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2405922859 case ZigTypeIdEnumLiteral:
2406022860 case ZigTypeIdUndefined:
2406122861 case ZigTypeIdNull:
24062 case ZigTypeIdPromise:
2406322862 zig_unreachable();
2406422863 case ZigTypeIdVoid:
2406522864 return ErrorNone;
......@@ -24546,181 +23345,7 @@ static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruct
2454623345}
2454723346
2454823347static IrInstruction *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) {
24549 IrInstruction *target_inst = instruction->target->child;
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;
23348 zig_panic("TODO analyze cancel");
2472423349}
2472523350
2472623351static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {
......@@ -24853,65 +23478,6 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr
2485323478 return result;
2485423479}
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
2491523481static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {
2491623482 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,
2491723483 instruction->base.source_node);
......@@ -25530,8 +24096,6 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
2553024096 return ir_analyze_instruction_asm(ira, (IrInstructionAsm *)instruction);
2553124097 case IrInstructionIdArrayType:
2553224098 return ir_analyze_instruction_array_type(ira, (IrInstructionArrayType *)instruction);
25533 case IrInstructionIdPromiseType:
25534 return ir_analyze_instruction_promise_type(ira, (IrInstructionPromiseType *)instruction);
2553524099 case IrInstructionIdSizeOf:
2553624100 return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction);
2553724101 case IrInstructionIdTestNonNull:
......@@ -25704,46 +24268,14 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
2570424268 return ir_analyze_instruction_error_union(ira, (IrInstructionErrorUnion *)instruction);
2570524269 case IrInstructionIdCancel:
2570624270 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);
2573324271 case IrInstructionIdAtomicRmw:
2573424272 return ir_analyze_instruction_atomic_rmw(ira, (IrInstructionAtomicRmw *)instruction);
2573524273 case IrInstructionIdAtomicLoad:
2573624274 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);
2574124275 case IrInstructionIdSaveErrRetAddr:
2574224276 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstructionSaveErrRetAddr *)instruction);
2574324277 case IrInstructionIdAddImplicitReturnType:
2574424278 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);
2574724279 case IrInstructionIdMarkErrRetTracePtr:
2574824280 return ir_analyze_instruction_mark_err_ret_trace_ptr(ira, (IrInstructionMarkErrRetTracePtr *)instruction);
2574924281 case IrInstructionIdFloatOp:
......@@ -25788,9 +24320,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2578824320 old_exec->analysis = ira;
2578924321 ira->codegen = codegen;
2579024322
25791 ZigFn *fn_entry = exec_fn_entry(old_exec);
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;
24323 ira->explicit_return_type = expected_type;
2579424324 ira->explicit_return_type_source_node = expected_type_source_node;
2579524325
2579624326 ira->old_irb.codegen = codegen;
......@@ -25889,17 +24419,8 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2588924419 case IrInstructionIdSetAlignStack:
2589024420 case IrInstructionIdExport:
2589124421 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:
2590024422 case IrInstructionIdSaveErrRetAddr:
2590124423 case IrInstructionIdAddImplicitReturnType:
25902 case IrInstructionIdMergeErrRetTraces:
2590324424 case IrInstructionIdMarkErrRetTracePtr:
2590424425 case IrInstructionIdAtomicRmw:
2590524426 case IrInstructionIdCmpxchgGen:
......@@ -25933,7 +24454,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2593324454 case IrInstructionIdTypeOf:
2593424455 case IrInstructionIdStructFieldPtr:
2593524456 case IrInstructionIdArrayType:
25936 case IrInstructionIdPromiseType:
2593724457 case IrInstructionIdSliceType:
2593824458 case IrInstructionIdSizeOf:
2593924459 case IrInstructionIdTestNonNull:
......@@ -25993,13 +24513,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2599324513 case IrInstructionIdTagType:
2599424514 case IrInstructionIdErrorReturnTrace:
2599524515 case IrInstructionIdErrorUnion:
25996 case IrInstructionIdGetImplicitAllocator:
25997 case IrInstructionIdCoroAlloc:
25998 case IrInstructionIdCoroSize:
25999 case IrInstructionIdCoroSuspend:
26000 case IrInstructionIdCoroFree:
26001 case IrInstructionIdCoroPromise:
26002 case IrInstructionIdPromiseResultType:
2600324516 case IrInstructionIdFloatOp:
2600424517 case IrInstructionIdMulAdd:
2600524518 case IrInstructionIdAtomicLoad:
src/ir_print.cpp+2-188
......@@ -257,13 +257,7 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
257257
258258static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instruction) {
259259 if (call_instruction->is_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, " ");
260 fprintf(irp->f, "async ");
267261 }
268262 if (call_instruction->fn_entry) {
269263 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
284278
285279static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instruction) {
286280 if (call_instruction->is_async) {
287 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, " ");
281 fprintf(irp->f, "async ");
294282 }
295283 if (call_instruction->fn_entry) {
296284 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
477465 ir_print_other_instruction(irp, instruction->child_type);
478466}
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
488468static void ir_print_slice_type(IrPrint *irp, IrInstructionSliceType *instruction) {
489469 const char *const_kw = instruction->is_const ? "const " : "";
490470 fprintf(irp->f, "[]%s", const_kw);
......@@ -1396,105 +1376,6 @@ static void ir_print_cancel(IrPrint *irp, IrInstructionCancel *instruction) {
13961376 ir_print_other_instruction(irp, instruction->target);
13971377}
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
14981379static void ir_print_atomic_rmw(IrPrint *irp, IrInstructionAtomicRmw *instruction) {
14991380 fprintf(irp->f, "@atomicRmw(");
15001381 if (instruction->operand_type != nullptr) {
......@@ -1539,12 +1420,6 @@ static void ir_print_atomic_load(IrPrint *irp, IrInstructionAtomicLoad *instruct
15391420 fprintf(irp->f, ")");
15401421}
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
15481423static void ir_print_save_err_ret_addr(IrPrint *irp, IrInstructionSaveErrRetAddr *instruction) {
15491424 fprintf(irp->f, "@saveErrRetAddr()");
15501425}
......@@ -1555,16 +1430,6 @@ static void ir_print_add_implicit_return_type(IrPrint *irp, IrInstructionAddImpl
15551430 fprintf(irp->f, ")");
15561431}
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
15681433static void ir_print_mark_err_ret_trace_ptr(IrPrint *irp, IrInstructionMarkErrRetTracePtr *instruction) {
15691434 fprintf(irp->f, "@markErrRetTracePtr(");
15701435 ir_print_other_instruction(irp, instruction->err_ret_trace_ptr);
......@@ -1727,9 +1592,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
17271592 case IrInstructionIdArrayType:
17281593 ir_print_array_type(irp, (IrInstructionArrayType *)instruction);
17291594 break;
1730 case IrInstructionIdPromiseType:
1731 ir_print_promise_type(irp, (IrInstructionPromiseType *)instruction);
1732 break;
17331595 case IrInstructionIdSliceType:
17341596 ir_print_slice_type(irp, (IrInstructionSliceType *)instruction);
17351597 break;
......@@ -2033,63 +1895,15 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
20331895 case IrInstructionIdCancel:
20341896 ir_print_cancel(irp, (IrInstructionCancel *)instruction);
20351897 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;
20721898 case IrInstructionIdAtomicRmw:
20731899 ir_print_atomic_rmw(irp, (IrInstructionAtomicRmw *)instruction);
20741900 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;
20841901 case IrInstructionIdSaveErrRetAddr:
20851902 ir_print_save_err_ret_addr(irp, (IrInstructionSaveErrRetAddr *)instruction);
20861903 break;
20871904 case IrInstructionIdAddImplicitReturnType:
20881905 ir_print_add_implicit_return_type(irp, (IrInstructionAddImplicitReturnType *)instruction);
20891906 break;
2090 case IrInstructionIdMergeErrRetTraces:
2091 ir_print_merge_err_ret_traces(irp, (IrInstructionMergeErrRetTraces *)instruction);
2092 break;
20931907 case IrInstructionIdMarkErrRetTracePtr:
20941908 ir_print_mark_err_ret_trace_ptr(irp, (IrInstructionMarkErrRetTracePtr *)instruction);
20951909 break;
src/parser.cpp-32
......@@ -282,9 +282,6 @@ static AstNode *ast_parse_prefix_op_expr(
282282 case NodeTypeAwaitExpr:
283283 right = &prefix->data.await_expr.expr;
284284 break;
285 case NodeTypePromiseType:
286 right = &prefix->data.promise_type.payload_type;
287 break;
288285 case NodeTypeArrayType:
289286 right = &prefix->data.array_type.child_type;
290287 break;
......@@ -1643,10 +1640,6 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
16431640 if (null != nullptr)
16441641 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
16501643 Token *true_token = eat_token_if(pc, TokenIdKeywordTrue);
16511644 if (true_token != nullptr) {
16521645 AstNode *res = ast_create_node(pc, NodeTypeBoolLiteral, true_token);
......@@ -2042,11 +2035,6 @@ static Optional<AstNodeFnProto> ast_parse_fn_cc(ParseContext *pc) {
20422035 }
20432036 if (eat_token_if(pc, TokenIdKeywordAsync) != nullptr) {
20442037 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);
20502038 return Optional<AstNodeFnProto>::some(res);
20512039 }
20522040
......@@ -2533,16 +2521,6 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) {
25332521 return res;
25342522 }
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
25462524 AstNode *array = ast_parse_array_type_start(pc);
25472525 if (array != nullptr) {
25482526 assert(array->type == NodeTypeArrayType);
......@@ -2680,11 +2658,6 @@ static AstNode *ast_parse_async_prefix(ParseContext *pc) {
26802658 AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, async);
26812659 res->data.fn_call_expr.is_async = true;
26822660 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
26892662 return res;
26902663}
......@@ -2858,7 +2831,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
28582831 visit_node_list(&node->data.fn_proto.params, visit, context);
28592832 visit_field(&node->data.fn_proto.align_expr, visit, context);
28602833 visit_field(&node->data.fn_proto.section_expr, visit, context);
2861 visit_field(&node->data.fn_proto.async_allocator_type, visit, context);
28622834 break;
28632835 case NodeTypeFnDef:
28642836 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
29182890 case NodeTypeFnCallExpr:
29192891 visit_field(&node->data.fn_call_expr.fn_ref_expr, visit, context);
29202892 visit_node_list(&node->data.fn_call_expr.params, visit, context);
2921 visit_field(&node->data.fn_call_expr.async_allocator, visit, context);
29222893 break;
29232894 case NodeTypeArrayAccessExpr:
29242895 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
30343005 case NodeTypeInferredArrayType:
30353006 visit_field(&node->data.array_type.child_type, visit, context);
30363007 break;
3037 case NodeTypePromiseType:
3038 visit_field(&node->data.promise_type.payload_type, visit, context);
3039 break;
30403008 case NodeTypeErrorType:
30413009 // none
30423010 break;
src/tokenizer.cpp-2
......@@ -136,7 +136,6 @@ static const struct ZigKeyword zig_keywords[] = {
136136 {"or", TokenIdKeywordOr},
137137 {"orelse", TokenIdKeywordOrElse},
138138 {"packed", TokenIdKeywordPacked},
139 {"promise", TokenIdKeywordPromise},
140139 {"pub", TokenIdKeywordPub},
141140 {"resume", TokenIdKeywordResume},
142141 {"return", TokenIdKeywordReturn},
......@@ -1558,7 +1557,6 @@ const char * token_name(TokenId id) {
15581557 case TokenIdKeywordOr: return "or";
15591558 case TokenIdKeywordOrElse: return "orelse";
15601559 case TokenIdKeywordPacked: return "packed";
1561 case TokenIdKeywordPromise: return "promise";
15621560 case TokenIdKeywordPub: return "pub";
15631561 case TokenIdKeywordReturn: return "return";
15641562 case TokenIdKeywordLinkSection: return "linksection";
src/tokenizer.hpp-1
......@@ -81,7 +81,6 @@ enum TokenId {
8181 TokenIdKeywordOr,
8282 TokenIdKeywordOrElse,
8383 TokenIdKeywordPacked,
84 TokenIdKeywordPromise,
8584 TokenIdKeywordPub,
8685 TokenIdKeywordResume,
8786 TokenIdKeywordReturn,
std/fmt.zig-3
......@@ -328,9 +328,6 @@ pub fn formatType(
328328 try output(context, "error.");
329329 return output(context, @errorName(value));
330330 },
331 .Promise => {
332 return format(context, Errors, output, "promise@{x}", @ptrToInt(value));
333 },
334331 .Enum => {
335332 if (comptime std.meta.trait.hasFn("format")(T)) {
336333 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
560560 builtin.TypeId.Bool => return autoHash(@boolToInt(key), rng, HashInt),
561561 builtin.TypeId.Enum => return autoHash(@enumToInt(key), rng, HashInt),
562562 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
565565 builtin.TypeId.BoundFn,
566566 builtin.TypeId.ComptimeFloat,
std/meta.zig+1-3
......@@ -104,8 +104,7 @@ pub fn Child(comptime T: type) type {
104104 TypeId.Array => |info| info.child,
105105 TypeId.Pointer => |info| info.child,
106106 TypeId.Optional => |info| info.child,
107 TypeId.Promise => |info| if (info.child) |child| child else null,
108 else => @compileError("Expected promise, pointer, optional, or array type, " ++ "found '" ++ @typeName(T) ++ "'"),
107 else => @compileError("Expected pointer, optional, or array type, " ++ "found '" ++ @typeName(T) ++ "'"),
109108 };
110109}
111110
......@@ -114,7 +113,6 @@ test "std.meta.Child" {
114113 testing.expect(Child(*u8) == u8);
115114 testing.expect(Child([]u8) == u8);
116115 testing.expect(Child(?u8) == u8);
117 testing.expect(Child(promise->u8) == u8);
118116}
119117
120118pub fn containerLayout(comptime T: type) TypeInfo.ContainerLayout {
std/testing.zig-1
......@@ -45,7 +45,6 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
4545 TypeId.EnumLiteral,
4646 TypeId.Enum,
4747 TypeId.Fn,
48 TypeId.Promise,
4948 TypeId.Vector,
5049 TypeId.ErrorSet,
5150 => {
test/stage1/behavior.zig+3-3
......@@ -39,11 +39,11 @@ comptime {
3939 _ = @import("behavior/bugs/828.zig");
4040 _ = @import("behavior/bugs/920.zig");
4141 _ = @import("behavior/byval_arg_var.zig");
42 _ = @import("behavior/cancel.zig");
42 //_ = @import("behavior/cancel.zig");
4343 _ = @import("behavior/cast.zig");
4444 _ = @import("behavior/const_slice_child.zig");
45 _ = @import("behavior/coroutine_await_struct.zig");
46 _ = @import("behavior/coroutines.zig");
45 //_ = @import("behavior/coroutine_await_struct.zig");
46 //_ = @import("behavior/coroutines.zig");
4747 _ = @import("behavior/defer.zig");
4848 _ = @import("behavior/enum.zig");
4949 _ = @import("behavior/enum_with_members.zig");
test/stage1/behavior/type_info.zig+2-18
......@@ -116,21 +116,6 @@ fn testOptional() void {
116116 expect(null_info.Optional.child == void);
117117}
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
134119test "type info: error set, error union info" {
135120 testErrorSet();
136121 comptime testErrorSet();
......@@ -192,11 +177,11 @@ fn testUnion() void {
192177 expect(TypeId(typeinfo_info) == TypeId.Union);
193178 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
194179 expect(typeinfo_info.Union.tag_type.? == TypeId);
195 expect(typeinfo_info.Union.fields.len == 25);
180 expect(typeinfo_info.Union.fields.len == 24);
196181 expect(typeinfo_info.Union.fields[4].enum_field != null);
197182 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
198183 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
201186 const TestNoTagUnion = union {
202187 Foo: void,
......@@ -265,7 +250,6 @@ fn testFunction() void {
265250 expect(fn_info.Fn.args.len == 2);
266251 expect(fn_info.Fn.is_var_args);
267252 expect(fn_info.Fn.return_type == null);
268 expect(fn_info.Fn.async_allocator_type == null);
269253
270254 const test_instance: TestStruct = undefined;
271255 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));