authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-20 16:42:14-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-20 16:42:14-05:00
log65a51b401cfe17daee0c64404c8f564b0f282224
tree9e799afd7d582bcbc14692ec6fb22b086a1edd2b
parenta06f3c74fdc0d8bf0f42427a261ab32351753fcb

add promise type

See #727

5 files changed, 80 insertions(+), 8 deletions(-)

src/all_types.hpp+8
...@@ -1096,6 +1096,11 @@ struct TypeTableEntryBoundFn {...@@ -1096,6 +1096,11 @@ struct TypeTableEntryBoundFn {
1096 TypeTableEntry *fn_type;1096 TypeTableEntry *fn_type;
1097};1097};
10981098
1099struct TypeTableEntryPromise {
1100 // null if `promise` instead of `promise->T`
1101 TypeTableEntry *result_type;
1102};
1103
1099enum TypeTableEntryId {1104enum TypeTableEntryId {
1100 TypeTableEntryIdInvalid,1105 TypeTableEntryIdInvalid,
1101 TypeTableEntryIdVar,1106 TypeTableEntryIdVar,
...@@ -1123,6 +1128,7 @@ enum TypeTableEntryId {...@@ -1123,6 +1128,7 @@ enum TypeTableEntryId {
1123 TypeTableEntryIdBoundFn,1128 TypeTableEntryIdBoundFn,
1124 TypeTableEntryIdArgTuple,1129 TypeTableEntryIdArgTuple,
1125 TypeTableEntryIdOpaque,1130 TypeTableEntryIdOpaque,
1131 TypeTableEntryIdPromise,
1126};1132};
11271133
1128struct TypeTableEntry {1134struct TypeTableEntry {
...@@ -1149,11 +1155,13 @@ struct TypeTableEntry {...@@ -1149,11 +1155,13 @@ struct TypeTableEntry {
1149 TypeTableEntryUnion unionation;1155 TypeTableEntryUnion unionation;
1150 TypeTableEntryFn fn;1156 TypeTableEntryFn fn;
1151 TypeTableEntryBoundFn bound_fn;1157 TypeTableEntryBoundFn bound_fn;
1158 TypeTableEntryPromise promise;
1152 } data;1159 } data;
11531160
1154 // use these fields to make sure we don't duplicate type table entries for the same type1161 // use these fields to make sure we don't duplicate type table entries for the same type
1155 TypeTableEntry *pointer_parent[2]; // [0 - mut, 1 - const]1162 TypeTableEntry *pointer_parent[2]; // [0 - mut, 1 - const]
1156 TypeTableEntry *maybe_parent;1163 TypeTableEntry *maybe_parent;
1164 TypeTableEntry *promise_parent;
1157 // If we generate a constant name value for this type, we memoize it here.1165 // If we generate a constant name value for this type, we memoize it here.
1158 // The type of this is array1166 // The type of this is array
1159 ConstExprValue *cached_const_name_val;1167 ConstExprValue *cached_const_name_val;
src/analyze.cpp+51-1
...@@ -230,6 +230,7 @@ bool type_is_complete(TypeTableEntry *type_entry) {...@@ -230,6 +230,7 @@ bool type_is_complete(TypeTableEntry *type_entry) {
230 case TypeTableEntryIdBlock:230 case TypeTableEntryIdBlock:
231 case TypeTableEntryIdBoundFn:231 case TypeTableEntryIdBoundFn:
232 case TypeTableEntryIdArgTuple:232 case TypeTableEntryIdArgTuple:
233 case TypeTableEntryIdPromise:
233 return true;234 return true;
234 }235 }
235 zig_unreachable();236 zig_unreachable();
...@@ -267,6 +268,7 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) {...@@ -267,6 +268,7 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) {
267 case TypeTableEntryIdBoundFn:268 case TypeTableEntryIdBoundFn:
268 case TypeTableEntryIdArgTuple:269 case TypeTableEntryIdArgTuple:
269 case TypeTableEntryIdOpaque:270 case TypeTableEntryIdOpaque:
271 case TypeTableEntryIdPromise:
270 return true;272 return true;
271 }273 }
272 zig_unreachable();274 zig_unreachable();
...@@ -339,6 +341,32 @@ TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {...@@ -339,6 +341,32 @@ TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) {
339 return get_int_type(g, false, bits_needed_for_unsigned(x));341 return get_int_type(g, false, bits_needed_for_unsigned(x));
340}342}
341343
344TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *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 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);
352 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPromise);
353 entry->type_ref = u8_ptr_type->type_ref;
354 entry->zero_bits = false;
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 entry->di_type = u8_ptr_type->di_type;
361
362 if (result_type != nullptr) {
363 result_type->promise_parent = entry;
364 } else if (result_type == nullptr) {
365 g->builtin_types.entry_promise = entry;
366 }
367 return entry;
368}
369
342TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,370TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const,
343 bool is_volatile, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count)371 bool is_volatile, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count)
344{372{
...@@ -1203,6 +1231,7 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {...@@ -1203,6 +1231,7 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {
1203 case TypeTableEntryIdBoundFn:1231 case TypeTableEntryIdBoundFn:
1204 case TypeTableEntryIdArgTuple:1232 case TypeTableEntryIdArgTuple:
1205 case TypeTableEntryIdOpaque:1233 case TypeTableEntryIdOpaque:
1234 case TypeTableEntryIdPromise:
1206 return false;1235 return false;
1207 case TypeTableEntryIdVoid:1236 case TypeTableEntryIdVoid:
1208 case TypeTableEntryIdBool:1237 case TypeTableEntryIdBool:
...@@ -1243,6 +1272,7 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {...@@ -1243,6 +1272,7 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {
1243 case TypeTableEntryIdBlock:1272 case TypeTableEntryIdBlock:
1244 case TypeTableEntryIdBoundFn:1273 case TypeTableEntryIdBoundFn:
1245 case TypeTableEntryIdArgTuple:1274 case TypeTableEntryIdArgTuple:
1275 case TypeTableEntryIdPromise:
1246 return false;1276 return false;
1247 case TypeTableEntryIdOpaque:1277 case TypeTableEntryIdOpaque:
1248 case TypeTableEntryIdUnreachable:1278 case TypeTableEntryIdUnreachable:
...@@ -1383,7 +1413,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1383,7 +1413,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1383 case TypeTableEntryIdBoundFn:1413 case TypeTableEntryIdBoundFn:
1384 case TypeTableEntryIdMetaType:1414 case TypeTableEntryIdMetaType:
1385 add_node_error(g, param_node->data.param_decl.type,1415 add_node_error(g, param_node->data.param_decl.type,
1386 buf_sprintf("parameter of type '%s' must be declared inline",1416 buf_sprintf("parameter of type '%s' must be declared comptime",
1387 buf_ptr(&type_entry->name)));1417 buf_ptr(&type_entry->name)));
1388 return g->builtin_types.entry_invalid;1418 return g->builtin_types.entry_invalid;
1389 case TypeTableEntryIdVoid:1419 case TypeTableEntryIdVoid:
...@@ -1399,6 +1429,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1399,6 +1429,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1399 case TypeTableEntryIdEnum:1429 case TypeTableEntryIdEnum:
1400 case TypeTableEntryIdUnion:1430 case TypeTableEntryIdUnion:
1401 case TypeTableEntryIdFn:1431 case TypeTableEntryIdFn:
1432 case TypeTableEntryIdPromise:
1402 ensure_complete_type(g, type_entry);1433 ensure_complete_type(g, type_entry);
1403 if (fn_type_id.cc == CallingConventionUnspecified && !type_is_copyable(g, type_entry)) {1434 if (fn_type_id.cc == CallingConventionUnspecified && !type_is_copyable(g, type_entry)) {
1404 add_node_error(g, param_node->data.param_decl.type,1435 add_node_error(g, param_node->data.param_decl.type,
...@@ -1480,6 +1511,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1480,6 +1511,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1480 case TypeTableEntryIdEnum:1511 case TypeTableEntryIdEnum:
1481 case TypeTableEntryIdUnion:1512 case TypeTableEntryIdUnion:
1482 case TypeTableEntryIdFn:1513 case TypeTableEntryIdFn:
1514 case TypeTableEntryIdPromise:
1483 break;1515 break;
1484 }1516 }
14851517
...@@ -3175,6 +3207,7 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt...@@ -3175,6 +3207,7 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
3175 case TypeTableEntryIdUnion:3207 case TypeTableEntryIdUnion:
3176 case TypeTableEntryIdFn:3208 case TypeTableEntryIdFn:
3177 case TypeTableEntryIdBoundFn:3209 case TypeTableEntryIdBoundFn:
3210 case TypeTableEntryIdPromise:
3178 return type_entry;3211 return type_entry;
3179 }3212 }
3180 zig_unreachable();3213 zig_unreachable();
...@@ -3553,6 +3586,7 @@ static bool is_container(TypeTableEntry *type_entry) {...@@ -3553,6 +3586,7 @@ static bool is_container(TypeTableEntry *type_entry) {
3553 case TypeTableEntryIdBoundFn:3586 case TypeTableEntryIdBoundFn:
3554 case TypeTableEntryIdArgTuple:3587 case TypeTableEntryIdArgTuple:
3555 case TypeTableEntryIdOpaque:3588 case TypeTableEntryIdOpaque:
3589 case TypeTableEntryIdPromise:
3556 return false;3590 return false;
3557 }3591 }
3558 zig_unreachable();3592 zig_unreachable();
...@@ -3603,6 +3637,7 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {...@@ -3603,6 +3637,7 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {
3603 case TypeTableEntryIdVar:3637 case TypeTableEntryIdVar:
3604 case TypeTableEntryIdArgTuple:3638 case TypeTableEntryIdArgTuple:
3605 case TypeTableEntryIdOpaque:3639 case TypeTableEntryIdOpaque:
3640 case TypeTableEntryIdPromise:
3606 zig_unreachable();3641 zig_unreachable();
3607 }3642 }
3608}3643}
...@@ -4095,6 +4130,7 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {...@@ -4095,6 +4130,7 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
4095 case TypeTableEntryIdErrorSet:4130 case TypeTableEntryIdErrorSet:
4096 case TypeTableEntryIdFn:4131 case TypeTableEntryIdFn:
4097 case TypeTableEntryIdEnum:4132 case TypeTableEntryIdEnum:
4133 case TypeTableEntryIdPromise:
4098 return false;4134 return false;
4099 case TypeTableEntryIdArray:4135 case TypeTableEntryIdArray:
4100 case TypeTableEntryIdStruct:4136 case TypeTableEntryIdStruct:
...@@ -4342,6 +4378,9 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {...@@ -4342,6 +4378,9 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
4342 }4378 }
4343 zig_unreachable();4379 zig_unreachable();
4344 }4380 }
4381 case TypeTableEntryIdPromise:
4382 // TODO better hashing algorithm
4383 return 223048345;
4345 case TypeTableEntryIdUndefLit:4384 case TypeTableEntryIdUndefLit:
4346 return 162837799;4385 return 162837799;
4347 case TypeTableEntryIdNullLit:4386 case TypeTableEntryIdNullLit:
...@@ -4501,6 +4540,7 @@ bool type_requires_comptime(TypeTableEntry *type_entry) {...@@ -4501,6 +4540,7 @@ bool type_requires_comptime(TypeTableEntry *type_entry) {
4501 case TypeTableEntryIdPointer:4540 case TypeTableEntryIdPointer:
4502 case TypeTableEntryIdVoid:4541 case TypeTableEntryIdVoid:
4503 case TypeTableEntryIdUnreachable:4542 case TypeTableEntryIdUnreachable:
4543 case TypeTableEntryIdPromise:
4504 return false;4544 return false;
4505 }4545 }
4506 zig_unreachable();4546 zig_unreachable();
...@@ -4970,6 +5010,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {...@@ -4970,6 +5010,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
4970 case TypeTableEntryIdInvalid:5010 case TypeTableEntryIdInvalid:
4971 case TypeTableEntryIdUnreachable:5011 case TypeTableEntryIdUnreachable:
4972 case TypeTableEntryIdVar:5012 case TypeTableEntryIdVar:
5013 case TypeTableEntryIdPromise:
4973 zig_unreachable();5014 zig_unreachable();
4974 }5015 }
4975 zig_unreachable();5016 zig_unreachable();
...@@ -5244,6 +5285,8 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {...@@ -5244,6 +5285,8 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
5244 buf_appendf(buf, "(args value)");5285 buf_appendf(buf, "(args value)");
5245 return;5286 return;
5246 }5287 }
5288 case TypeTableEntryIdPromise:
5289 zig_unreachable();
5247 }5290 }
5248 zig_unreachable();5291 zig_unreachable();
5249}5292}
...@@ -5305,6 +5348,7 @@ uint32_t type_id_hash(TypeId x) {...@@ -5305,6 +5348,7 @@ uint32_t type_id_hash(TypeId x) {
5305 case TypeTableEntryIdBlock:5348 case TypeTableEntryIdBlock:
5306 case TypeTableEntryIdBoundFn:5349 case TypeTableEntryIdBoundFn:
5307 case TypeTableEntryIdArgTuple:5350 case TypeTableEntryIdArgTuple:
5351 case TypeTableEntryIdPromise:
5308 zig_unreachable();5352 zig_unreachable();
5309 case TypeTableEntryIdErrorUnion:5353 case TypeTableEntryIdErrorUnion:
5310 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);5354 return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type);
...@@ -5342,6 +5386,7 @@ bool type_id_eql(TypeId a, TypeId b) {...@@ -5342,6 +5386,7 @@ bool type_id_eql(TypeId a, TypeId b) {
5342 case TypeTableEntryIdUndefLit:5386 case TypeTableEntryIdUndefLit:
5343 case TypeTableEntryIdNullLit:5387 case TypeTableEntryIdNullLit:
5344 case TypeTableEntryIdMaybe:5388 case TypeTableEntryIdMaybe:
5389 case TypeTableEntryIdPromise:
5345 case TypeTableEntryIdErrorSet:5390 case TypeTableEntryIdErrorSet:
5346 case TypeTableEntryIdEnum:5391 case TypeTableEntryIdEnum:
5347 case TypeTableEntryIdUnion:5392 case TypeTableEntryIdUnion:
...@@ -5469,6 +5514,7 @@ static const TypeTableEntryId all_type_ids[] = {...@@ -5469,6 +5514,7 @@ static const TypeTableEntryId all_type_ids[] = {
5469 TypeTableEntryIdBoundFn,5514 TypeTableEntryIdBoundFn,
5470 TypeTableEntryIdArgTuple,5515 TypeTableEntryIdArgTuple,
5471 TypeTableEntryIdOpaque,5516 TypeTableEntryIdOpaque,
5517 TypeTableEntryIdPromise,
5472};5518};
54735519
5474TypeTableEntryId type_id_at_index(size_t index) {5520TypeTableEntryId type_id_at_index(size_t index) {
...@@ -5533,6 +5579,8 @@ size_t type_id_index(TypeTableEntryId id) {...@@ -5533,6 +5579,8 @@ size_t type_id_index(TypeTableEntryId id) {
5533 return 22;5579 return 22;
5534 case TypeTableEntryIdOpaque:5580 case TypeTableEntryIdOpaque:
5535 return 23;5581 return 23;
5582 case TypeTableEntryIdPromise:
5583 return 24;
5536 }5584 }
5537 zig_unreachable();5585 zig_unreachable();
5538}5586}
...@@ -5590,6 +5638,8 @@ const char *type_id_name(TypeTableEntryId id) {...@@ -5590,6 +5638,8 @@ const char *type_id_name(TypeTableEntryId id) {
5590 return "ArgTuple";5638 return "ArgTuple";
5591 case TypeTableEntryIdOpaque:5639 case TypeTableEntryIdOpaque:
5592 return "Opaque";5640 return "Opaque";
5641 case TypeTableEntryIdPromise:
5642 return "Promise";
5593 }5643 }
5594 zig_unreachable();5644 zig_unreachable();
5595}5645}
src/analyze.hpp+1
...@@ -35,6 +35,7 @@ TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry);...@@ -35,6 +35,7 @@ TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry);
35TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name);35TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name);
36TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],36TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[],
37 TypeTableEntry *field_types[], size_t field_count);37 TypeTableEntry *field_types[], size_t field_count);
38TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type);
38TypeTableEntry *get_test_fn_type(CodeGen *g);39TypeTableEntry *get_test_fn_type(CodeGen *g);
39bool handle_is_ptr(TypeTableEntry *type_entry);40bool handle_is_ptr(TypeTableEntry *type_entry);
40void find_libc_include_path(CodeGen *g);41void find_libc_include_path(CodeGen *g);
src/codegen.cpp+6-7
...@@ -4017,6 +4017,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con...@@ -4017,6 +4017,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
4017 case TypeTableEntryIdPointer:4017 case TypeTableEntryIdPointer:
4018 case TypeTableEntryIdFn:4018 case TypeTableEntryIdFn:
4019 case TypeTableEntryIdMaybe:4019 case TypeTableEntryIdMaybe:
4020 case TypeTableEntryIdPromise:
4020 {4021 {
4021 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");4022 LLVMValueRef ptr_val = gen_const_val(g, const_val, "");
4022 LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->type_ref);4023 LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->type_ref);
...@@ -4434,6 +4435,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -4434,6 +4435,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
4434 case TypeTableEntryIdVar:4435 case TypeTableEntryIdVar:
4435 case TypeTableEntryIdArgTuple:4436 case TypeTableEntryIdArgTuple:
4436 case TypeTableEntryIdOpaque:4437 case TypeTableEntryIdOpaque:
4438 case TypeTableEntryIdPromise:
4437 zig_unreachable();4439 zig_unreachable();
44384440
4439 }4441 }
...@@ -5280,13 +5282,7 @@ static void define_builtin_types(CodeGen *g) {...@@ -5280,13 +5282,7 @@ static void define_builtin_types(CodeGen *g) {
5280 g->primitive_type_table.put(&entry->name, entry);5282 g->primitive_type_table.put(&entry->name, entry);
5281 }5283 }
5282 {5284 {
5283 TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false);5285 TypeTableEntry *entry = get_promise_type(g, nullptr);
5284 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdVoid);
5285 entry->type_ref = u8_ptr_type->type_ref;
5286 entry->zero_bits = false;
5287 buf_init_from_str(&entry->name, "promise");
5288 entry->di_type = u8_ptr_type->di_type;
5289 g->builtin_types.entry_promise = entry;
5290 g->primitive_type_table.put(&entry->name, entry);5286 g->primitive_type_table.put(&entry->name, entry);
5291 }5287 }
52925288
...@@ -5916,6 +5912,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry...@@ -5916,6 +5912,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry
5916 case TypeTableEntryIdArgTuple:5912 case TypeTableEntryIdArgTuple:
5917 case TypeTableEntryIdErrorUnion:5913 case TypeTableEntryIdErrorUnion:
5918 case TypeTableEntryIdErrorSet:5914 case TypeTableEntryIdErrorSet:
5915 case TypeTableEntryIdPromise:
5919 zig_unreachable();5916 zig_unreachable();
5920 case TypeTableEntryIdVoid:5917 case TypeTableEntryIdVoid:
5921 case TypeTableEntryIdUnreachable:5918 case TypeTableEntryIdUnreachable:
...@@ -6102,6 +6099,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf...@@ -6102,6 +6099,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
6102 case TypeTableEntryIdNullLit:6099 case TypeTableEntryIdNullLit:
6103 case TypeTableEntryIdVar:6100 case TypeTableEntryIdVar:
6104 case TypeTableEntryIdArgTuple:6101 case TypeTableEntryIdArgTuple:
6102 case TypeTableEntryIdPromise:
6105 zig_unreachable();6103 zig_unreachable();
6106 }6104 }
6107}6105}
...@@ -6262,6 +6260,7 @@ static void gen_h_file(CodeGen *g) {...@@ -6262,6 +6260,7 @@ static void gen_h_file(CodeGen *g) {
6262 case TypeTableEntryIdArgTuple:6260 case TypeTableEntryIdArgTuple:
6263 case TypeTableEntryIdMaybe:6261 case TypeTableEntryIdMaybe:
6264 case TypeTableEntryIdFn:6262 case TypeTableEntryIdFn:
6263 case TypeTableEntryIdPromise:
6265 zig_unreachable();6264 zig_unreachable();
6266 case TypeTableEntryIdEnum:6265 case TypeTableEntryIdEnum:
6267 assert(type_entry->data.enumeration.layout == ContainerLayoutExtern);6266 assert(type_entry->data.enumeration.layout == ContainerLayoutExtern);
src/ir.cpp+14
...@@ -9589,6 +9589,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -9589,6 +9589,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
9589 case TypeTableEntryIdBlock:9589 case TypeTableEntryIdBlock:
9590 case TypeTableEntryIdBoundFn:9590 case TypeTableEntryIdBoundFn:
9591 case TypeTableEntryIdArgTuple:9591 case TypeTableEntryIdArgTuple:
9592 case TypeTableEntryIdPromise:
9592 if (!is_equality_cmp) {9593 if (!is_equality_cmp) {
9593 ir_add_error_node(ira, source_node,9594 ir_add_error_node(ira, source_node,
9594 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));9595 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
...@@ -10418,6 +10419,7 @@ static VarClassRequired get_var_class_required(TypeTableEntry *type_entry) {...@@ -10418,6 +10419,7 @@ static VarClassRequired get_var_class_required(TypeTableEntry *type_entry) {
10418 case TypeTableEntryIdVoid:10419 case TypeTableEntryIdVoid:
10419 case TypeTableEntryIdErrorSet:10420 case TypeTableEntryIdErrorSet:
10420 case TypeTableEntryIdFn:10421 case TypeTableEntryIdFn:
10422 case TypeTableEntryIdPromise:
10421 return VarClassRequiredAny;10423 return VarClassRequiredAny;
10422 case TypeTableEntryIdNumLitFloat:10424 case TypeTableEntryIdNumLitFloat:
10423 case TypeTableEntryIdNumLitInt:10425 case TypeTableEntryIdNumLitInt:
...@@ -10688,6 +10690,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi...@@ -10688,6 +10690,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
10688 case TypeTableEntryIdBoundFn:10690 case TypeTableEntryIdBoundFn:
10689 case TypeTableEntryIdArgTuple:10691 case TypeTableEntryIdArgTuple:
10690 case TypeTableEntryIdOpaque:10692 case TypeTableEntryIdOpaque:
10693 case TypeTableEntryIdPromise:
10691 ir_add_error(ira, target,10694 ir_add_error(ira, target,
10692 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));10695 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
10693 break;10696 break;
...@@ -10712,6 +10715,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi...@@ -10712,6 +10715,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
10712 case TypeTableEntryIdBoundFn:10715 case TypeTableEntryIdBoundFn:
10713 case TypeTableEntryIdArgTuple:10716 case TypeTableEntryIdArgTuple:
10714 case TypeTableEntryIdOpaque:10717 case TypeTableEntryIdOpaque:
10718 case TypeTableEntryIdPromise:
10715 ir_add_error(ira, target,10719 ir_add_error(ira, target,
10716 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));10720 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name)));
10717 break;10721 break;
...@@ -11481,6 +11485,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op...@@ -11481,6 +11485,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
11481 case TypeTableEntryIdBlock:11485 case TypeTableEntryIdBlock:
11482 case TypeTableEntryIdBoundFn:11486 case TypeTableEntryIdBoundFn:
11483 case TypeTableEntryIdArgTuple:11487 case TypeTableEntryIdArgTuple:
11488 case TypeTableEntryIdPromise:
11484 {11489 {
11485 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);11490 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base);
11486 out_val->data.x_type = get_maybe_type(ira->codegen, type_entry);11491 out_val->data.x_type = get_maybe_type(ira->codegen, type_entry);
...@@ -12710,6 +12715,7 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi...@@ -12710,6 +12715,7 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
12710 case TypeTableEntryIdFn:12715 case TypeTableEntryIdFn:
12711 case TypeTableEntryIdArgTuple:12716 case TypeTableEntryIdArgTuple:
12712 case TypeTableEntryIdOpaque:12717 case TypeTableEntryIdOpaque:
12718 case TypeTableEntryIdPromise:
12713 {12719 {
12714 ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base);12720 ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base);
12715 out_val->data.x_type = type_entry;12721 out_val->data.x_type = type_entry;
...@@ -12977,6 +12983,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -12977,6 +12983,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
12977 case TypeTableEntryIdFn:12983 case TypeTableEntryIdFn:
12978 case TypeTableEntryIdNamespace:12984 case TypeTableEntryIdNamespace:
12979 case TypeTableEntryIdBoundFn:12985 case TypeTableEntryIdBoundFn:
12986 case TypeTableEntryIdPromise:
12980 {12987 {
12981 type_ensure_zero_bits_known(ira->codegen, child_type);12988 type_ensure_zero_bits_known(ira->codegen, child_type);
12982 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,12989 TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type,
...@@ -13085,6 +13092,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -13085,6 +13092,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
13085 case TypeTableEntryIdFn:13092 case TypeTableEntryIdFn:
13086 case TypeTableEntryIdNamespace:13093 case TypeTableEntryIdNamespace:
13087 case TypeTableEntryIdBoundFn:13094 case TypeTableEntryIdBoundFn:
13095 case TypeTableEntryIdPromise:
13088 {13096 {
13089 TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size);13097 TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size);
13090 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base);13098 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base);
...@@ -13136,6 +13144,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,...@@ -13136,6 +13144,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
13136 case TypeTableEntryIdEnum:13144 case TypeTableEntryIdEnum:
13137 case TypeTableEntryIdUnion:13145 case TypeTableEntryIdUnion:
13138 case TypeTableEntryIdFn:13146 case TypeTableEntryIdFn:
13147 case TypeTableEntryIdPromise:
13139 {13148 {
13140 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);13149 uint64_t size_in_bytes = type_size(ira->codegen, type_entry);
13141 ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base);13150 ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base);
...@@ -13465,6 +13474,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -13465,6 +13474,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
13465 case TypeTableEntryIdNumLitFloat:13474 case TypeTableEntryIdNumLitFloat:
13466 case TypeTableEntryIdNumLitInt:13475 case TypeTableEntryIdNumLitInt:
13467 case TypeTableEntryIdPointer:13476 case TypeTableEntryIdPointer:
13477 case TypeTableEntryIdPromise:
13468 case TypeTableEntryIdFn:13478 case TypeTableEntryIdFn:
13469 case TypeTableEntryIdNamespace:13479 case TypeTableEntryIdNamespace:
13470 case TypeTableEntryIdErrorSet:13480 case TypeTableEntryIdErrorSet:
...@@ -14053,6 +14063,7 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_...@@ -14053,6 +14063,7 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
14053 case TypeTableEntryIdMetaType:14063 case TypeTableEntryIdMetaType:
14054 case TypeTableEntryIdUnreachable:14064 case TypeTableEntryIdUnreachable:
14055 case TypeTableEntryIdPointer:14065 case TypeTableEntryIdPointer:
14066 case TypeTableEntryIdPromise:
14056 case TypeTableEntryIdArray:14067 case TypeTableEntryIdArray:
14057 case TypeTableEntryIdStruct:14068 case TypeTableEntryIdStruct:
14058 case TypeTableEntryIdNumLitFloat:14069 case TypeTableEntryIdNumLitFloat:
...@@ -15313,6 +15324,7 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc...@@ -15313,6 +15324,7 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc
15313 case TypeTableEntryIdInt:15324 case TypeTableEntryIdInt:
15314 case TypeTableEntryIdFloat:15325 case TypeTableEntryIdFloat:
15315 case TypeTableEntryIdPointer:15326 case TypeTableEntryIdPointer:
15327 case TypeTableEntryIdPromise:
15316 case TypeTableEntryIdArray:15328 case TypeTableEntryIdArray:
15317 case TypeTableEntryIdStruct:15329 case TypeTableEntryIdStruct:
15318 case TypeTableEntryIdMaybe:15330 case TypeTableEntryIdMaybe:
...@@ -16008,6 +16020,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -16008,6 +16020,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
16008 case TypeTableEntryIdNumLitInt:16020 case TypeTableEntryIdNumLitInt:
16009 case TypeTableEntryIdUndefLit:16021 case TypeTableEntryIdUndefLit:
16010 case TypeTableEntryIdNullLit:16022 case TypeTableEntryIdNullLit:
16023 case TypeTableEntryIdPromise:
16011 zig_unreachable();16024 zig_unreachable();
16012 case TypeTableEntryIdVoid:16025 case TypeTableEntryIdVoid:
16013 return;16026 return;
...@@ -16075,6 +16088,7 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -16075,6 +16088,7 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
16075 case TypeTableEntryIdNumLitInt:16088 case TypeTableEntryIdNumLitInt:
16076 case TypeTableEntryIdUndefLit:16089 case TypeTableEntryIdUndefLit:
16077 case TypeTableEntryIdNullLit:16090 case TypeTableEntryIdNullLit:
16091 case TypeTableEntryIdPromise:
16078 zig_unreachable();16092 zig_unreachable();
16079 case TypeTableEntryIdVoid:16093 case TypeTableEntryIdVoid:
16080 return;16094 return;