authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-13 03:07:58-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-13 03:07:58-04:00
logbf57d8a7e3beb8d69dec38e131a3717f008f6c5e
tree1559356eda32fa631d1bac1de5efb5dcf7be0d48
parentbf67427c67dac00ca10ed7423ae8d99e2901262f

typedefpocalypse

closes #314

14 files changed, 334 insertions(+), 620 deletions(-)

doc/langref.md+2-4
......@@ -9,9 +9,7 @@ TopLevelItem = ErrorValueDecl | CompTimeExpression(Block) | TopLevelDecl | TestD
99
1010TestDecl = "test" String Block
1111
12TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | TypeDecl | UseDecl)
13
14TypeDecl = "type" Symbol "=" TypeExpr ";"
12TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | UseDecl)
1513
1614ErrorValueDecl = "error" Symbol ";"
1715
......@@ -155,7 +153,7 @@ GotoExpression = "goto" Symbol
155153
156154GroupedExpression = "(" Expression ")"
157155
158KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this" | "unreachable"
156KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "this" | "unreachable"
159157
160158ContainerDecl = option("extern" | "packed") ("struct" | "enum" | "union") "{" many(ContainerMember) "}"
161159```
src/all_types.hpp+1-27
......@@ -254,7 +254,6 @@ enum TldId {
254254 TldIdVar,
255255 TldIdFn,
256256 TldIdContainer,
257 TldIdTypeDef,
258257 TldIdCompTime,
259258};
260259
......@@ -303,12 +302,6 @@ struct TldContainer {
303302 TypeTableEntry *type_entry;
304303};
305304
306struct TldTypeDef {
307 Tld base;
308
309 TypeTableEntry *type_entry;
310};
311
312305struct TldCompTime {
313306 Tld base;
314307};
......@@ -330,7 +323,6 @@ enum NodeType {
330323 NodeTypeReturnExpr,
331324 NodeTypeDefer,
332325 NodeTypeVariableDeclaration,
333 NodeTypeTypeDecl,
334326 NodeTypeErrorValueDecl,
335327 NodeTypeTestDecl,
336328 NodeTypeBinOpExpr,
......@@ -369,7 +361,6 @@ enum NodeType {
369361 NodeTypeStructValueField,
370362 NodeTypeArrayType,
371363 NodeTypeErrorType,
372 NodeTypeTypeLiteral,
373364 NodeTypeVarLiteral,
374365 NodeTypeTryExpr,
375366 NodeTypeInlineExpr,
......@@ -448,12 +439,6 @@ struct AstNodeVariableDeclaration {
448439 AstNode *expr;
449440};
450441
451struct AstNodeTypeDecl {
452 VisibMod visib_mod;
453 Buf *symbol;
454 AstNode *child_type;
455};
456
457442struct AstNodeErrorValueDecl {
458443 Buf *name;
459444
......@@ -790,9 +775,6 @@ struct AstNodeArrayType {
790775struct AstNodeErrorType {
791776};
792777
793struct AstNodeTypeLiteral {
794};
795
796778struct AstNodeVarLiteral {
797779};
798780
......@@ -816,7 +798,6 @@ struct AstNode {
816798 AstNodeReturnExpr return_expr;
817799 AstNodeDefer defer;
818800 AstNodeVariableDeclaration variable_declaration;
819 AstNodeTypeDecl type_decl;
820801 AstNodeErrorValueDecl error_value_decl;
821802 AstNodeTestDecl test_decl;
822803 AstNodeBinOpExpr bin_op_expr;
......@@ -856,7 +837,6 @@ struct AstNode {
856837 AstNodeUnreachableExpr unreachable_expr;
857838 AstNodeArrayType array_type;
858839 AstNodeErrorType error_type;
859 AstNodeTypeLiteral type_literal;
860840 AstNodeVarLiteral var_literal;
861841 AstNodeInlineExpr inline_expr;
862842 } data;
......@@ -1026,11 +1006,6 @@ struct TypeTableEntryBoundFn {
10261006 TypeTableEntry *fn_type;
10271007};
10281008
1029struct TypeTableEntryTypeDecl {
1030 TypeTableEntry *child_type;
1031 TypeTableEntry *canonical_type;
1032};
1033
10341009enum TypeTableEntryId {
10351010 TypeTableEntryIdInvalid,
10361011 TypeTableEntryIdVar,
......@@ -1054,11 +1029,11 @@ enum TypeTableEntryId {
10541029 TypeTableEntryIdEnumTag,
10551030 TypeTableEntryIdUnion,
10561031 TypeTableEntryIdFn,
1057 TypeTableEntryIdTypeDecl,
10581032 TypeTableEntryIdNamespace,
10591033 TypeTableEntryIdBlock,
10601034 TypeTableEntryIdBoundFn,
10611035 TypeTableEntryIdArgTuple,
1036 TypeTableEntryIdOpaque,
10621037};
10631038
10641039struct TypeTableEntry {
......@@ -1083,7 +1058,6 @@ struct TypeTableEntry {
10831058 TypeTableEntryEnumTag enum_tag;
10841059 TypeTableEntryUnion unionation;
10851060 TypeTableEntryFn fn;
1086 TypeTableEntryTypeDecl type_decl;
10871061 TypeTableEntryBoundFn bound_fn;
10881062 } data;
10891063
src/analyze.cpp+76-114
......@@ -186,6 +186,8 @@ bool type_is_complete(TypeTableEntry *type_entry) {
186186 return type_entry->data.enumeration.complete;
187187 case TypeTableEntryIdUnion:
188188 return type_entry->data.unionation.complete;
189 case TypeTableEntryIdOpaque:
190 return false;
189191 case TypeTableEntryIdMetaType:
190192 case TypeTableEntryIdVoid:
191193 case TypeTableEntryIdBool:
......@@ -202,7 +204,6 @@ bool type_is_complete(TypeTableEntry *type_entry) {
202204 case TypeTableEntryIdErrorUnion:
203205 case TypeTableEntryIdPureError:
204206 case TypeTableEntryIdFn:
205 case TypeTableEntryIdTypeDecl:
206207 case TypeTableEntryIdNamespace:
207208 case TypeTableEntryIdBlock:
208209 case TypeTableEntryIdBoundFn:
......@@ -240,12 +241,12 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) {
240241 case TypeTableEntryIdErrorUnion:
241242 case TypeTableEntryIdPureError:
242243 case TypeTableEntryIdFn:
243 case TypeTableEntryIdTypeDecl:
244244 case TypeTableEntryIdNamespace:
245245 case TypeTableEntryIdBlock:
246246 case TypeTableEntryIdBoundFn:
247247 case TypeTableEntryIdEnumTag:
248248 case TypeTableEntryIdArgTuple:
249 case TypeTableEntryIdOpaque:
249250 return true;
250251 }
251252 zig_unreachable();
......@@ -254,18 +255,17 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) {
254255
255256uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) {
256257 assert(type_is_complete(type_entry));
257 TypeTableEntry *canon_type = get_underlying_type(type_entry);
258258
259259 if (!type_has_bits(type_entry))
260260 return 0;
261261
262 if (canon_type->id == TypeTableEntryIdStruct && canon_type->data.structure.layout == ContainerLayoutPacked) {
262 if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
263263 uint64_t size_in_bits = type_size_bits(g, type_entry);
264264 return (size_in_bits + 7) / 8;
265 } else if (canon_type->id == TypeTableEntryIdArray) {
266 TypeTableEntry *canon_child_type = get_underlying_type(canon_type->data.array.child_type);
267 if (canon_child_type->id == TypeTableEntryIdStruct &&
268 canon_child_type->data.structure.layout == ContainerLayoutPacked)
265 } else if (type_entry->id == TypeTableEntryIdArray) {
266 TypeTableEntry *child_type = type_entry->data.array.child_type;
267 if (child_type->id == TypeTableEntryIdStruct &&
268 child_type->data.structure.layout == ContainerLayoutPacked)
269269 {
270270 uint64_t size_in_bits = type_size_bits(g, type_entry);
271271 return (size_in_bits + 7) / 8;
......@@ -277,27 +277,26 @@ uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) {
277277
278278uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) {
279279 assert(type_is_complete(type_entry));
280 TypeTableEntry *canon_type = get_underlying_type(type_entry);
281280
282281 if (!type_has_bits(type_entry))
283282 return 0;
284283
285 if (canon_type->id == TypeTableEntryIdStruct && canon_type->data.structure.layout == ContainerLayoutPacked) {
284 if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) {
286285 uint64_t result = 0;
287 for (size_t i = 0; i < canon_type->data.structure.src_field_count; i += 1) {
288 result += type_size_bits(g, canon_type->data.structure.fields[i].type_entry);
286 for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
287 result += type_size_bits(g, type_entry->data.structure.fields[i].type_entry);
289288 }
290289 return result;
291 } else if (canon_type->id == TypeTableEntryIdArray) {
292 TypeTableEntry *canon_child_type = get_underlying_type(canon_type->data.array.child_type);
293 if (canon_child_type->id == TypeTableEntryIdStruct &&
294 canon_child_type->data.structure.layout == ContainerLayoutPacked)
290 } else if (type_entry->id == TypeTableEntryIdArray) {
291 TypeTableEntry *child_type = type_entry->data.array.child_type;
292 if (child_type->id == TypeTableEntryIdStruct &&
293 child_type->data.structure.layout == ContainerLayoutPacked)
295294 {
296 return canon_type->data.array.len * type_size_bits(g, canon_child_type);
295 return type_entry->data.array.len * type_size_bits(g, child_type);
297296 }
298297 }
299298
300 return LLVMSizeOfTypeInBits(g->target_data_ref, canon_type->type_ref);
299 return LLVMSizeOfTypeInBits(g->target_data_ref, type_entry->type_ref);
301300}
302301
303302static bool type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) {
......@@ -360,10 +359,9 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
360359 bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));
361360 }
362361
363 TypeTableEntry *canon_child_type = get_underlying_type(child_type);
364 assert(canon_child_type->id != TypeTableEntryIdInvalid);
362 assert(child_type->id != TypeTableEntryIdInvalid);
365363
366 entry->zero_bits = !type_has_bits(canon_child_type);
364 entry->zero_bits = !type_has_bits(child_type);
367365
368366 if (!entry->zero_bits) {
369367 entry->type_ref = LLVMPointerType(child_type->type_ref, 0);
......@@ -766,17 +764,22 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *child_type, bool is_c
766764 }
767765}
768766
769TypeTableEntry *get_typedecl_type(CodeGen *g, const char *name, TypeTableEntry *child_type) {
770 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdTypeDecl);
767TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) {
768 TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOpaque);
771769
772770 buf_init_from_str(&entry->name, name);
773771
774 entry->is_copyable = type_is_copyable(g, child_type);
775 entry->type_ref = child_type->type_ref;
776 entry->di_type = child_type->di_type;
777 entry->zero_bits = child_type->zero_bits;
778 entry->data.type_decl.child_type = child_type;
779 entry->data.type_decl.canonical_type = get_underlying_type(child_type);
772 ImportTableEntry *import = scope ? get_scope_import(scope) : nullptr;
773 unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0;
774
775 entry->is_copyable = false;
776 entry->type_ref = LLVMInt8Type();
777 entry->di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder,
778 ZigLLVMTag_DW_structure_type(), buf_ptr(&entry->name),
779 import ? ZigLLVMFileToScope(import->di_file) : nullptr,
780 import ? import->di_file : nullptr,
781 line);
782 entry->zero_bits = false;
780783
781784 return entry;
782785}
......@@ -968,14 +971,6 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKi
968971 return entry;
969972}
970973
971TypeTableEntry *get_underlying_type(TypeTableEntry *type_entry) {
972 if (type_entry->id == TypeTableEntryIdTypeDecl) {
973 return type_entry->data.type_decl.canonical_type;
974 } else {
975 return type_entry;
976 }
977}
978
979974static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, TypeTableEntry *type_entry, Buf *type_name) {
980975 size_t backward_branch_count = 0;
981976 return ir_eval_const_value(g, scope, node, type_entry,
......@@ -1066,6 +1061,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
10661061 case TypeTableEntryIdUndefLit:
10671062 case TypeTableEntryIdNullLit:
10681063 case TypeTableEntryIdArgTuple:
1064 case TypeTableEntryIdOpaque:
10691065 add_node_error(g, param_node->data.param_decl.type,
10701066 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));
10711067 return g->builtin_types.entry_invalid;
......@@ -1099,7 +1095,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
10991095 case TypeTableEntryIdEnum:
11001096 case TypeTableEntryIdUnion:
11011097 case TypeTableEntryIdFn:
1102 case TypeTableEntryIdTypeDecl:
11031098 case TypeTableEntryIdEnumTag:
11041099 ensure_complete_type(g, type_entry);
11051100 if (!fn_type_id.is_extern && !type_is_copyable(g, type_entry)) {
......@@ -1123,6 +1118,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
11231118 case TypeTableEntryIdUndefLit:
11241119 case TypeTableEntryIdNullLit:
11251120 case TypeTableEntryIdArgTuple:
1121 case TypeTableEntryIdOpaque:
11261122 add_node_error(g, fn_proto->return_type,
11271123 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
11281124 return g->builtin_types.entry_invalid;
......@@ -1155,7 +1151,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
11551151 case TypeTableEntryIdEnum:
11561152 case TypeTableEntryIdUnion:
11571153 case TypeTableEntryIdFn:
1158 case TypeTableEntryIdTypeDecl:
11591154 case TypeTableEntryIdEnumTag:
11601155 break;
11611156 }
......@@ -1173,8 +1168,6 @@ bool type_is_invalid(TypeTableEntry *type_entry) {
11731168 return type_entry->data.enumeration.is_invalid;
11741169 case TypeTableEntryIdUnion:
11751170 return type_entry->data.unionation.is_invalid;
1176 case TypeTableEntryIdTypeDecl:
1177 return type_is_invalid(type_entry->data.type_decl.canonical_type);
11781171 default:
11791172 return false;
11801173 }
......@@ -1380,8 +1373,7 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
13801373}
13811374
13821375static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {
1383 TypeTableEntry *canon_type = get_underlying_type(type_entry);
1384 switch (canon_type->id) {
1376 switch (type_entry->id) {
13851377 case TypeTableEntryIdInvalid:
13861378 case TypeTableEntryIdVar:
13871379 zig_unreachable();
......@@ -1395,11 +1387,11 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {
13951387 case TypeTableEntryIdPureError:
13961388 case TypeTableEntryIdEnum:
13971389 case TypeTableEntryIdEnumTag:
1398 case TypeTableEntryIdTypeDecl:
13991390 case TypeTableEntryIdNamespace:
14001391 case TypeTableEntryIdBlock:
14011392 case TypeTableEntryIdBoundFn:
14021393 case TypeTableEntryIdArgTuple:
1394 case TypeTableEntryIdOpaque:
14031395 return false;
14041396 case TypeTableEntryIdVoid:
14051397 case TypeTableEntryIdBool:
......@@ -1411,11 +1403,11 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {
14111403 case TypeTableEntryIdFn:
14121404 return true;
14131405 case TypeTableEntryIdStruct:
1414 return canon_type->data.structure.layout == ContainerLayoutPacked;
1406 return type_entry->data.structure.layout == ContainerLayoutPacked;
14151407 case TypeTableEntryIdMaybe:
14161408 {
1417 TypeTableEntry *canon_child_type = get_underlying_type(canon_type->data.maybe.child_type);
1418 return canon_child_type->id == TypeTableEntryIdPointer || canon_child_type->id == TypeTableEntryIdFn;
1409 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
1410 return child_type->id == TypeTableEntryIdPointer || child_type->id == TypeTableEntryIdFn;
14191411 }
14201412 }
14211413 zig_unreachable();
......@@ -2037,15 +2029,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
20372029 add_top_level_decl(g, decls_scope, &tld_var->base);
20382030 break;
20392031 }
2040 case NodeTypeTypeDecl:
2041 {
2042 Buf *name = node->data.type_decl.symbol;
2043 VisibMod visib_mod = node->data.type_decl.visib_mod;
2044 TldTypeDef *tld_typedef = allocate<TldTypeDef>(1);
2045 init_tld(&tld_typedef->base, TldIdTypeDef, name, visib_mod, node, &decls_scope->base);
2046 add_top_level_decl(g, decls_scope, &tld_typedef->base);
2047 break;
2048 }
20492032 case NodeTypeFnProto:
20502033 {
20512034 // if the name is missing, we immediately announce an error
......@@ -2126,7 +2109,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
21262109 case NodeTypeStructValueField:
21272110 case NodeTypeArrayType:
21282111 case NodeTypeErrorType:
2129 case NodeTypeTypeLiteral:
21302112 case NodeTypeVarLiteral:
21312113 case NodeTypeTryExpr:
21322114 case NodeTypeInlineExpr:
......@@ -2154,10 +2136,7 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) {
21542136}
21552137
21562138TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry) {
2157 TypeTableEntry *underlying_type = get_underlying_type(type_entry);
2158 switch (underlying_type->id) {
2159 case TypeTableEntryIdTypeDecl:
2160 zig_unreachable();
2139 switch (type_entry->id) {
21612140 case TypeTableEntryIdInvalid:
21622141 return g->builtin_types.entry_invalid;
21632142 case TypeTableEntryIdUnreachable:
......@@ -2168,8 +2147,9 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
21682147 case TypeTableEntryIdNullLit:
21692148 case TypeTableEntryIdBlock:
21702149 case TypeTableEntryIdArgTuple:
2150 case TypeTableEntryIdOpaque:
21712151 add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed",
2172 buf_ptr(&underlying_type->name)));
2152 buf_ptr(&type_entry->name)));
21732153 return g->builtin_types.entry_invalid;
21742154 case TypeTableEntryIdNamespace:
21752155 case TypeTableEntryIdMetaType:
......@@ -2328,17 +2308,6 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
23282308 g->global_vars.append(tld_var);
23292309}
23302310
2331static void resolve_decl_typedef(CodeGen *g, TldTypeDef *tld_typedef) {
2332 AstNode *typedef_node = tld_typedef->base.source_node;
2333 assert(typedef_node->type == NodeTypeTypeDecl);
2334 AstNode *type_node = typedef_node->data.type_decl.child_type;
2335 Buf *decl_name = typedef_node->data.type_decl.symbol;
2336
2337 TypeTableEntry *child_type = analyze_type_expr(g, tld_typedef->base.parent_scope, type_node);
2338 tld_typedef->type_entry = (child_type->id == TypeTableEntryIdInvalid) ?
2339 child_type : get_typedecl_type(g, buf_ptr(decl_name), child_type);
2340}
2341
23422311void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only) {
23432312 if (tld->resolution != TldResolutionUnresolved)
23442313 return;
......@@ -2370,12 +2339,6 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only) {
23702339 resolve_decl_container(g, tld_container);
23712340 break;
23722341 }
2373 case TldIdTypeDef:
2374 {
2375 TldTypeDef *tld_typedef = (TldTypeDef *)tld;
2376 resolve_decl_typedef(g, tld_typedef);
2377 break;
2378 }
23792342 case TldIdCompTime:
23802343 {
23812344 TldCompTime *tld_comptime = (TldCompTime *)tld;
......@@ -2589,6 +2552,7 @@ static bool is_container(TypeTableEntry *type_entry) {
25892552 switch (type_entry->id) {
25902553 case TypeTableEntryIdInvalid:
25912554 case TypeTableEntryIdVar:
2555 case TypeTableEntryIdOpaque:
25922556 zig_unreachable();
25932557 case TypeTableEntryIdStruct:
25942558 case TypeTableEntryIdEnum:
......@@ -2610,7 +2574,6 @@ static bool is_container(TypeTableEntry *type_entry) {
26102574 case TypeTableEntryIdErrorUnion:
26112575 case TypeTableEntryIdPureError:
26122576 case TypeTableEntryIdFn:
2613 case TypeTableEntryIdTypeDecl:
26142577 case TypeTableEntryIdNamespace:
26152578 case TypeTableEntryIdBlock:
26162579 case TypeTableEntryIdBoundFn:
......@@ -2659,7 +2622,6 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {
26592622 case TypeTableEntryIdErrorUnion:
26602623 case TypeTableEntryIdPureError:
26612624 case TypeTableEntryIdFn:
2662 case TypeTableEntryIdTypeDecl:
26632625 case TypeTableEntryIdNamespace:
26642626 case TypeTableEntryIdBlock:
26652627 case TypeTableEntryIdBoundFn:
......@@ -2667,6 +2629,7 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {
26672629 case TypeTableEntryIdVar:
26682630 case TypeTableEntryIdEnumTag:
26692631 case TypeTableEntryIdArgTuple:
2632 case TypeTableEntryIdOpaque:
26702633 zig_unreachable();
26712634 }
26722635}
......@@ -3062,6 +3025,7 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
30623025 case TypeTableEntryIdBoundFn:
30633026 case TypeTableEntryIdVar:
30643027 case TypeTableEntryIdArgTuple:
3028 case TypeTableEntryIdOpaque:
30653029 zig_unreachable();
30663030 case TypeTableEntryIdUnreachable:
30673031 case TypeTableEntryIdVoid:
......@@ -3086,8 +3050,6 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
30863050 return type_has_bits(type_entry->data.maybe.child_type) &&
30873051 type_entry->data.maybe.child_type->id != TypeTableEntryIdPointer &&
30883052 type_entry->data.maybe.child_type->id != TypeTableEntryIdFn;
3089 case TypeTableEntryIdTypeDecl:
3090 return handle_is_ptr(type_entry->data.type_decl.canonical_type);
30913053 }
30923054 zig_unreachable();
30933055}
......@@ -3165,6 +3127,8 @@ bool fn_type_id_eql(FnTypeId *a, FnTypeId *b) {
31653127static uint32_t hash_const_val(ConstExprValue *const_val) {
31663128 assert(const_val->special == ConstValSpecialStatic);
31673129 switch (const_val->type->id) {
3130 case TypeTableEntryIdOpaque:
3131 zig_unreachable();
31683132 case TypeTableEntryIdBool:
31693133 return const_val->data.x_bool ? (uint32_t)127863866 : (uint32_t)215080464;
31703134 case TypeTableEntryIdMetaType:
......@@ -3254,8 +3218,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
32543218 case TypeTableEntryIdFn:
32553219 return hash_ptr(const_val->data.x_fn.fn_entry) +
32563220 (const_val->data.x_fn.is_inline ? 4133894920 : 3983484790);
3257 case TypeTableEntryIdTypeDecl:
3258 return hash_ptr(const_val->data.x_type);
32593221 case TypeTableEntryIdNamespace:
32603222 return hash_ptr(const_val->data.x_import);
32613223 case TypeTableEntryIdBlock:
......@@ -3359,10 +3321,10 @@ bool type_has_bits(TypeTableEntry *type_entry) {
33593321}
33603322
33613323bool type_requires_comptime(TypeTableEntry *type_entry) {
3362 switch (get_underlying_type(type_entry)->id) {
3324 switch (type_entry->id) {
33633325 case TypeTableEntryIdInvalid:
33643326 case TypeTableEntryIdVar:
3365 case TypeTableEntryIdTypeDecl:
3327 case TypeTableEntryIdOpaque:
33663328 zig_unreachable();
33673329 case TypeTableEntryIdNumLitFloat:
33683330 case TypeTableEntryIdNumLitInt:
......@@ -3603,14 +3565,14 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_
36033565
36043566
36053567void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
3606 TypeTableEntry *canon_wanted_type = get_underlying_type(const_val->type);
3607 if (canon_wanted_type->id == TypeTableEntryIdArray) {
3568 TypeTableEntry *wanted_type = const_val->type;
3569 if (wanted_type->id == TypeTableEntryIdArray) {
36083570 const_val->special = ConstValSpecialStatic;
3609 size_t elem_count = canon_wanted_type->data.array.len;
3571 size_t elem_count = wanted_type->data.array.len;
36103572 const_val->data.x_array.elements = allocate<ConstExprValue>(elem_count);
36113573 for (size_t i = 0; i < elem_count; i += 1) {
36123574 ConstExprValue *element_val = &const_val->data.x_array.elements[i];
3613 element_val->type = canon_wanted_type->data.array.child_type;
3575 element_val->type = wanted_type->data.array.child_type;
36143576 init_const_undefined(g, element_val);
36153577 ConstParent *parent = get_const_val_parent(element_val);
36163578 if (parent != nullptr) {
......@@ -3619,15 +3581,15 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
36193581 parent->data.p_array.elem_index = i;
36203582 }
36213583 }
3622 } else if (canon_wanted_type->id == TypeTableEntryIdStruct) {
3623 ensure_complete_type(g, canon_wanted_type);
3584 } else if (wanted_type->id == TypeTableEntryIdStruct) {
3585 ensure_complete_type(g, wanted_type);
36243586
36253587 const_val->special = ConstValSpecialStatic;
3626 size_t field_count = canon_wanted_type->data.structure.src_field_count;
3588 size_t field_count = wanted_type->data.structure.src_field_count;
36273589 const_val->data.x_struct.fields = allocate<ConstExprValue>(field_count);
36283590 for (size_t i = 0; i < field_count; i += 1) {
36293591 ConstExprValue *field_val = &const_val->data.x_struct.fields[i];
3630 field_val->type = canon_wanted_type->data.structure.fields[i].type_entry;
3592 field_val->type = wanted_type->data.structure.fields[i].type_entry;
36313593 assert(field_val->type);
36323594 init_const_undefined(g, field_val);
36333595 ConstParent *parent = get_const_val_parent(field_val);
......@@ -3678,6 +3640,8 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
36783640 assert(a->special == ConstValSpecialStatic);
36793641 assert(b->special == ConstValSpecialStatic);
36803642 switch (a->type->id) {
3643 case TypeTableEntryIdOpaque:
3644 zig_unreachable();
36813645 case TypeTableEntryIdEnum:
36823646 {
36833647 ConstEnumValue *enum1 = &a->data.x_enum;
......@@ -3767,8 +3731,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
37673731 }
37683732 case TypeTableEntryIdErrorUnion:
37693733 zig_panic("TODO");
3770 case TypeTableEntryIdTypeDecl:
3771 zig_panic("TODO");
37723734 case TypeTableEntryIdNamespace:
37733735 return a->data.x_import == b->data.x_import;
37743736 case TypeTableEntryIdBlock:
......@@ -3857,9 +3819,9 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
38573819 }
38583820 assert(const_val->type);
38593821
3860 TypeTableEntry *canon_type = get_underlying_type(const_val->type);
3861 switch (canon_type->id) {
3862 case TypeTableEntryIdTypeDecl:
3822 TypeTableEntry *type_entry = const_val->type;
3823 switch (type_entry->id) {
3824 case TypeTableEntryIdOpaque:
38633825 zig_unreachable();
38643826 case TypeTableEntryIdInvalid:
38653827 buf_appendf(buf, "(invalid)");
......@@ -3926,7 +3888,7 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
39263888 return;
39273889 }
39283890 case ConstPtrSpecialHardCodedAddr:
3929 buf_appendf(buf, "(&%s)(%" PRIx64 ")", buf_ptr(&canon_type->data.pointer.child_type->name),
3891 buf_appendf(buf, "(&%s)(%" PRIx64 ")", buf_ptr(&type_entry->data.pointer.child_type->name),
39303892 const_val->data.x_ptr.data.hard_coded_addr.addr);
39313893 return;
39323894 case ConstPtrSpecialDiscard:
......@@ -3949,8 +3911,8 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
39493911 }
39503912 case TypeTableEntryIdArray:
39513913 {
3952 TypeTableEntry *child_type = canon_type->data.array.child_type;
3953 uint64_t len = canon_type->data.array.len;
3914 TypeTableEntry *child_type = type_entry->data.array.child_type;
3915 uint64_t len = type_entry->data.array.len;
39543916
39553917 // if it's []u8, assume UTF-8 and output a string
39563918 if (child_type->id == TypeTableEntryIdInt &&
......@@ -3973,7 +3935,7 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
39733935 return;
39743936 }
39753937
3976 buf_appendf(buf, "%s{", buf_ptr(&canon_type->name));
3938 buf_appendf(buf, "%s{", buf_ptr(&type_entry->name));
39773939 for (uint64_t i = 0; i < len; i += 1) {
39783940 if (i != 0)
39793941 buf_appendf(buf, ",");
......@@ -4021,22 +3983,22 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
40213983 }
40223984 case TypeTableEntryIdStruct:
40233985 {
4024 buf_appendf(buf, "(struct %s constant)", buf_ptr(&canon_type->name));
3986 buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name));
40253987 return;
40263988 }
40273989 case TypeTableEntryIdEnum:
40283990 {
4029 buf_appendf(buf, "(enum %s constant)", buf_ptr(&canon_type->name));
3991 buf_appendf(buf, "(enum %s constant)", buf_ptr(&type_entry->name));
40303992 return;
40313993 }
40323994 case TypeTableEntryIdErrorUnion:
40333995 {
4034 buf_appendf(buf, "(error union %s constant)", buf_ptr(&canon_type->name));
3996 buf_appendf(buf, "(error union %s constant)", buf_ptr(&type_entry->name));
40353997 return;
40363998 }
40373999 case TypeTableEntryIdUnion:
40384000 {
4039 buf_appendf(buf, "(union %s constant)", buf_ptr(&canon_type->name));
4001 buf_appendf(buf, "(union %s constant)", buf_ptr(&type_entry->name));
40404002 return;
40414003 }
40424004 case TypeTableEntryIdPureError:
......@@ -4046,7 +4008,7 @@ void render_const_value(Buf *buf, ConstExprValue *const_val) {
40464008 }
40474009 case TypeTableEntryIdEnumTag:
40484010 {
4049 TypeTableEntry *enum_type = canon_type->data.enum_tag.enum_type;
4011 TypeTableEntry *enum_type = type_entry->data.enum_tag.enum_type;
40504012 TypeEnumField *field = &enum_type->data.enumeration.fields[const_val->data.x_bignum.data.x_uint];
40514013 buf_appendf(buf, "%s.%s", buf_ptr(&enum_type->name), buf_ptr(field->name));
40524014 return;
......@@ -4095,6 +4057,7 @@ uint32_t type_id_hash(TypeId x) {
40954057 switch (x.id) {
40964058 case TypeTableEntryIdInvalid:
40974059 case TypeTableEntryIdVar:
4060 case TypeTableEntryIdOpaque:
40984061 case TypeTableEntryIdMetaType:
40994062 case TypeTableEntryIdVoid:
41004063 case TypeTableEntryIdBool:
......@@ -4112,7 +4075,6 @@ uint32_t type_id_hash(TypeId x) {
41124075 case TypeTableEntryIdEnumTag:
41134076 case TypeTableEntryIdUnion:
41144077 case TypeTableEntryIdFn:
4115 case TypeTableEntryIdTypeDecl:
41164078 case TypeTableEntryIdNamespace:
41174079 case TypeTableEntryIdBlock:
41184080 case TypeTableEntryIdBoundFn:
......@@ -4157,11 +4119,11 @@ bool type_id_eql(TypeId a, TypeId b) {
41574119 case TypeTableEntryIdEnumTag:
41584120 case TypeTableEntryIdUnion:
41594121 case TypeTableEntryIdFn:
4160 case TypeTableEntryIdTypeDecl:
41614122 case TypeTableEntryIdNamespace:
41624123 case TypeTableEntryIdBlock:
41634124 case TypeTableEntryIdBoundFn:
41644125 case TypeTableEntryIdArgTuple:
4126 case TypeTableEntryIdOpaque:
41654127 zig_unreachable();
41664128 case TypeTableEntryIdPointer:
41674129 return a.data.pointer.child_type == b.data.pointer.child_type &&
......@@ -4211,10 +4173,10 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {
42114173
42124174ConstParent *get_const_val_parent(ConstExprValue *value) {
42134175 assert(value->type);
4214 TypeTableEntry *canon_type = get_underlying_type(value->type);
4215 if (canon_type->id == TypeTableEntryIdArray) {
4176 TypeTableEntry *type_entry = value->type;
4177 if (type_entry->id == TypeTableEntryIdArray) {
42164178 return &value->data.x_array.parent;
4217 } else if (canon_type->id == TypeTableEntryIdStruct) {
4179 } else if (type_entry->id == TypeTableEntryIdStruct) {
42184180 return &value->data.x_struct.parent;
42194181 }
42204182 return nullptr;
src/analyze.hpp+1-2
......@@ -24,7 +24,6 @@ TypeTableEntry **get_int_type_ptr(CodeGen *g, bool is_signed, uint32_t size_in_b
2424TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits);
2525TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type);
2626TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type);
27TypeTableEntry *get_typedecl_type(CodeGen *g, const char *name, TypeTableEntry *child_type);
2827TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id);
2928TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type);
3029TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size);
......@@ -34,11 +33,11 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKi
3433TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x);
3534TypeTableEntry *get_error_type(CodeGen *g, TypeTableEntry *child_type);
3635TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry);
36TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name);
3737bool handle_is_ptr(TypeTableEntry *type_entry);
3838void find_libc_include_path(CodeGen *g);
3939void find_libc_lib_path(CodeGen *g);
4040
41TypeTableEntry *get_underlying_type(TypeTableEntry *type_entry);
4241bool type_has_bits(TypeTableEntry *type_entry);
4342
4443
src/ast_render.cpp+6-28
......@@ -166,8 +166,6 @@ static const char *node_type_str(NodeType node_type) {
166166 return "Defer";
167167 case NodeTypeVariableDeclaration:
168168 return "VariableDeclaration";
169 case NodeTypeTypeDecl:
170 return "TypeDecl";
171169 case NodeTypeErrorValueDecl:
172170 return "ErrorValueDecl";
173171 case NodeTypeTestDecl:
......@@ -234,8 +232,6 @@ static const char *node_type_str(NodeType node_type) {
234232 return "ArrayType";
235233 case NodeTypeErrorType:
236234 return "ErrorType";
237 case NodeTypeTypeLiteral:
238 return "TypeLiteral";
239235 case NodeTypeVarLiteral:
240236 return "VarLiteral";
241237 case NodeTypeTryExpr:
......@@ -394,7 +390,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
394390
395391 if (child->type == NodeTypeUse ||
396392 child->type == NodeTypeVariableDeclaration ||
397 child->type == NodeTypeTypeDecl ||
398393 child->type == NodeTypeErrorValueDecl ||
399394 child->type == NodeTypeFnProto)
400395 {
......@@ -507,14 +502,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
507502 }
508503 break;
509504 }
510 case NodeTypeTypeDecl:
511 {
512 const char *pub_str = visib_mod_string(node->data.type_decl.visib_mod);
513 const char *var_name = buf_ptr(node->data.type_decl.symbol);
514 fprintf(ar->f, "%stype %s = ", pub_str, var_name);
515 render_node_grouped(ar, node->data.type_decl.child_type);
516 break;
517 }
518505 case NodeTypeBinOpExpr:
519506 if (!grouped) fprintf(ar->f, "(");
520507 render_node_ungrouped(ar, node->data.bin_op_expr.op1);
......@@ -668,9 +655,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
668655 case NodeTypeErrorType:
669656 fprintf(ar->f, "error");
670657 break;
671 case NodeTypeTypeLiteral:
672 fprintf(ar->f, "type");
673 break;
674658 case NodeTypeVarLiteral:
675659 fprintf(ar->f, "var");
676660 break;
......@@ -1034,6 +1018,12 @@ static void ast_render_tld_var(AstRender *ar, Buf *name, TldVar *tld_var) {
10341018 fprintf(ar->f, "union {");
10351019 fprintf(ar->f, "TODO");
10361020 fprintf(ar->f, "}");
1021 } else if (type_entry->id == TypeTableEntryIdOpaque) {
1022 if (buf_eql_buf(&type_entry->name, name)) {
1023 fprintf(ar->f, "@OpaqueType()");
1024 } else {
1025 fprintf(ar->f, "%s", buf_ptr(&type_entry->name));
1026 }
10371027 } else {
10381028 fprintf(ar->f, "%s", buf_ptr(&type_entry->name));
10391029 }
......@@ -1047,15 +1037,6 @@ static void ast_render_tld_var(AstRender *ar, Buf *name, TldVar *tld_var) {
10471037 fprintf(ar->f, ";\n");
10481038}
10491039
1050static void ast_render_tld_typedef(AstRender *ar, Buf *name, TldTypeDef *tld_typedef) {
1051 TypeTableEntry *type_entry = tld_typedef->type_entry;
1052 TypeTableEntry *canon_type = get_underlying_type(type_entry);
1053
1054 fprintf(ar->f, "pub type ");
1055 print_symbol(ar, name);
1056 fprintf(ar->f, " = %s;\n", buf_ptr(&canon_type->name));
1057}
1058
10591040void ast_render_decls(FILE *f, int indent_size, ImportTableEntry *import) {
10601041 AstRender ar = {0};
10611042 ar.f = f;
......@@ -1087,9 +1068,6 @@ void ast_render_decls(FILE *f, int indent_size, ImportTableEntry *import) {
10871068 case TldIdContainer:
10881069 fprintf(stdout, "container\n");
10891070 break;
1090 case TldIdTypeDef:
1091 ast_render_tld_typedef(&ar, entry->key, (TldTypeDef *)tld);
1092 break;
10931071 case TldIdCompTime:
10941072 fprintf(stdout, "comptime\n");
10951073 break;
src/codegen.cpp+85-89
......@@ -649,12 +649,9 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,
649649 LLVMPositionBuilderAtEnd(g->builder, ok_block);
650650}
651651
652static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, TypeTableEntry *actual_type_non_canon,
653 TypeTableEntry *wanted_type_non_canon, LLVMValueRef expr_val)
652static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, TypeTableEntry *actual_type,
653 TypeTableEntry *wanted_type, LLVMValueRef expr_val)
654654{
655 TypeTableEntry *actual_type = get_underlying_type(actual_type_non_canon);
656 TypeTableEntry *wanted_type = get_underlying_type(wanted_type_non_canon);
657
658655 assert(actual_type->id == wanted_type->id);
659656
660657 uint64_t actual_bits;
......@@ -852,7 +849,7 @@ static LLVMValueRef gen_struct_memcpy(CodeGen *g, LLVMValueRef src, LLVMValueRef
852849static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *ptr_type,
853850 LLVMValueRef value)
854851{
855 TypeTableEntry *child_type = get_underlying_type(ptr_type->data.pointer.child_type);
852 TypeTableEntry *child_type = ptr_type->data.pointer.child_type;
856853
857854 if (!type_has_bits(child_type))
858855 return nullptr;
......@@ -1111,7 +1108,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
11111108 IrInstruction *op2 = bin_op_instruction->op2;
11121109
11131110 assert(op1->value.type == op2->value.type);
1114 TypeTableEntry *canon_type = get_underlying_type(op1->value.type);
1111 TypeTableEntry *type_entry = op1->value.type;
11151112
11161113 bool want_debug_safety = bin_op_instruction->safety_check_on &&
11171114 ir_want_debug_safety(g, &bin_op_instruction->base);
......@@ -1133,22 +1130,22 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
11331130 case IrBinOpCmpGreaterThan:
11341131 case IrBinOpCmpLessOrEq:
11351132 case IrBinOpCmpGreaterOrEq:
1136 if (canon_type->id == TypeTableEntryIdFloat) {
1133 if (type_entry->id == TypeTableEntryIdFloat) {
11371134 LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id);
11381135 return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, "");
1139 } else if (canon_type->id == TypeTableEntryIdInt) {
1140 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, canon_type->data.integral.is_signed);
1136 } else if (type_entry->id == TypeTableEntryIdInt) {
1137 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, type_entry->data.integral.is_signed);
11411138 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
1142 } else if (canon_type->id == TypeTableEntryIdEnum) {
1143 if (canon_type->data.enumeration.gen_field_count == 0) {
1139 } else if (type_entry->id == TypeTableEntryIdEnum) {
1140 if (type_entry->data.enumeration.gen_field_count == 0) {
11441141 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
11451142 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
11461143 } else {
11471144 zig_unreachable();
11481145 }
1149 } else if (canon_type->id == TypeTableEntryIdPureError ||
1150 canon_type->id == TypeTableEntryIdPointer ||
1151 canon_type->id == TypeTableEntryIdBool)
1146 } else if (type_entry->id == TypeTableEntryIdPureError ||
1147 type_entry->id == TypeTableEntryIdPointer ||
1148 type_entry->id == TypeTableEntryIdBool)
11521149 {
11531150 LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false);
11541151 return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, "");
......@@ -1157,15 +1154,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
11571154 }
11581155 case IrBinOpAdd:
11591156 case IrBinOpAddWrap:
1160 if (canon_type->id == TypeTableEntryIdFloat) {
1157 if (type_entry->id == TypeTableEntryIdFloat) {
11611158 return LLVMBuildFAdd(g->builder, op1_value, op2_value, "");
1162 } else if (canon_type->id == TypeTableEntryIdInt) {
1159 } else if (type_entry->id == TypeTableEntryIdInt) {
11631160 bool is_wrapping = (op_id == IrBinOpAddWrap);
11641161 if (is_wrapping) {
11651162 return LLVMBuildAdd(g->builder, op1_value, op2_value, "");
11661163 } else if (want_debug_safety) {
1167 return gen_overflow_op(g, canon_type, AddSubMulAdd, op1_value, op2_value);
1168 } else if (canon_type->data.integral.is_signed) {
1164 return gen_overflow_op(g, type_entry, AddSubMulAdd, op1_value, op2_value);
1165 } else if (type_entry->data.integral.is_signed) {
11691166 return LLVMBuildNSWAdd(g->builder, op1_value, op2_value, "");
11701167 } else {
11711168 return LLVMBuildNUWAdd(g->builder, op1_value, op2_value, "");
......@@ -1182,36 +1179,36 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
11821179 case IrBinOpBitShiftLeft:
11831180 case IrBinOpBitShiftLeftWrap:
11841181 {
1185 assert(canon_type->id == TypeTableEntryIdInt);
1182 assert(type_entry->id == TypeTableEntryIdInt);
11861183 bool is_wrapping = (op_id == IrBinOpBitShiftLeftWrap);
11871184 if (is_wrapping) {
11881185 return LLVMBuildShl(g->builder, op1_value, op2_value, "");
11891186 } else if (want_debug_safety) {
1190 return gen_overflow_shl_op(g, canon_type, op1_value, op2_value);
1191 } else if (canon_type->data.integral.is_signed) {
1187 return gen_overflow_shl_op(g, type_entry, op1_value, op2_value);
1188 } else if (type_entry->data.integral.is_signed) {
11921189 return ZigLLVMBuildNSWShl(g->builder, op1_value, op2_value, "");
11931190 } else {
11941191 return ZigLLVMBuildNUWShl(g->builder, op1_value, op2_value, "");
11951192 }
11961193 }
11971194 case IrBinOpBitShiftRight:
1198 assert(canon_type->id == TypeTableEntryIdInt);
1199 if (canon_type->data.integral.is_signed) {
1195 assert(type_entry->id == TypeTableEntryIdInt);
1196 if (type_entry->data.integral.is_signed) {
12001197 return LLVMBuildAShr(g->builder, op1_value, op2_value, "");
12011198 } else {
12021199 return LLVMBuildLShr(g->builder, op1_value, op2_value, "");
12031200 }
12041201 case IrBinOpSub:
12051202 case IrBinOpSubWrap:
1206 if (canon_type->id == TypeTableEntryIdFloat) {
1203 if (type_entry->id == TypeTableEntryIdFloat) {
12071204 return LLVMBuildFSub(g->builder, op1_value, op2_value, "");
1208 } else if (canon_type->id == TypeTableEntryIdInt) {
1205 } else if (type_entry->id == TypeTableEntryIdInt) {
12091206 bool is_wrapping = (op_id == IrBinOpSubWrap);
12101207 if (is_wrapping) {
12111208 return LLVMBuildSub(g->builder, op1_value, op2_value, "");
12121209 } else if (want_debug_safety) {
1213 return gen_overflow_op(g, canon_type, AddSubMulSub, op1_value, op2_value);
1214 } else if (canon_type->data.integral.is_signed) {
1210 return gen_overflow_op(g, type_entry, AddSubMulSub, op1_value, op2_value);
1211 } else if (type_entry->data.integral.is_signed) {
12151212 return LLVMBuildNSWSub(g->builder, op1_value, op2_value, "");
12161213 } else {
12171214 return LLVMBuildNUWSub(g->builder, op1_value, op2_value, "");
......@@ -1221,15 +1218,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
12211218 }
12221219 case IrBinOpMult:
12231220 case IrBinOpMultWrap:
1224 if (canon_type->id == TypeTableEntryIdFloat) {
1221 if (type_entry->id == TypeTableEntryIdFloat) {
12251222 return LLVMBuildFMul(g->builder, op1_value, op2_value, "");
1226 } else if (canon_type->id == TypeTableEntryIdInt) {
1223 } else if (type_entry->id == TypeTableEntryIdInt) {
12271224 bool is_wrapping = (op_id == IrBinOpMultWrap);
12281225 if (is_wrapping) {
12291226 return LLVMBuildMul(g->builder, op1_value, op2_value, "");
12301227 } else if (want_debug_safety) {
1231 return gen_overflow_op(g, canon_type, AddSubMulMul, op1_value, op2_value);
1232 } else if (canon_type->data.integral.is_signed) {
1228 return gen_overflow_op(g, type_entry, AddSubMulMul, op1_value, op2_value);
1229 } else if (type_entry->data.integral.is_signed) {
12331230 return LLVMBuildNSWMul(g->builder, op1_value, op2_value, "");
12341231 } else {
12351232 return LLVMBuildNUWMul(g->builder, op1_value, op2_value, "");
......@@ -1238,9 +1235,9 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
12381235 zig_unreachable();
12391236 }
12401237 case IrBinOpDiv:
1241 return gen_div(g, want_debug_safety, op1_value, op2_value, canon_type, false);
1238 return gen_div(g, want_debug_safety, op1_value, op2_value, type_entry, false);
12421239 case IrBinOpRem:
1243 return gen_rem(g, want_debug_safety, op1_value, op2_value, canon_type);
1240 return gen_rem(g, want_debug_safety, op1_value, op2_value, type_entry);
12441241 }
12451242 zig_unreachable();
12461243}
......@@ -1644,7 +1641,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
16441641 LLVMValueRef value = ir_llvm_value(g, instruction->value);
16451642
16461643 assert(instruction->ptr->value.type->id == TypeTableEntryIdPointer);
1647 TypeTableEntry *ptr_type = get_underlying_type(instruction->ptr->value.type);
1644 TypeTableEntry *ptr_type = instruction->ptr->value.type;
16481645
16491646 gen_assign_raw(g, ptr, ptr_type, value);
16501647
......@@ -1685,9 +1682,9 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
16851682 if (array_ptr_type->data.pointer.unaligned_bit_count != 0) {
16861683 return array_ptr_ptr;
16871684 }
1688 TypeTableEntry *canon_child_type = get_underlying_type(array_type->data.array.child_type);
1689 if (canon_child_type->id == TypeTableEntryIdStruct &&
1690 canon_child_type->data.structure.layout == ContainerLayoutPacked)
1685 TypeTableEntry *child_type = array_type->data.array.child_type;
1686 if (child_type->id == TypeTableEntryIdStruct &&
1687 child_type->data.structure.layout == ContainerLayoutPacked)
16911688 {
16921689 size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count;
16931690 if (unaligned_bit_count != 0) {
......@@ -1701,7 +1698,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
17011698 byte_offset
17021699 };
17031700 LLVMValueRef elem_byte_ptr = LLVMBuildInBoundsGEP(g->builder, u8_array_ptr, indices, 1, "");
1704 return LLVMBuildBitCast(g->builder, elem_byte_ptr, LLVMPointerType(canon_child_type->type_ref, 0), "");
1701 return LLVMBuildBitCast(g->builder, elem_byte_ptr, LLVMPointerType(child_type->type_ref, 0), "");
17051702 }
17061703 }
17071704 LLVMValueRef indices[] = {
......@@ -2206,8 +2203,8 @@ static LLVMValueRef ir_render_div_exact(CodeGen *g, IrExecutable *executable, Ir
22062203
22072204static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {
22082205 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
2209 TypeTableEntry *dest_type = get_underlying_type(instruction->base.value.type);
2210 TypeTableEntry *src_type = get_underlying_type(instruction->target->value.type);
2206 TypeTableEntry *dest_type = instruction->base.value.type;
2207 TypeTableEntry *src_type = instruction->target->value.type;
22112208 if (dest_type == src_type) {
22122209 // no-op
22132210 return target_val;
......@@ -2228,7 +2225,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
22282225
22292226 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
22302227
2231 TypeTableEntry *ptr_type = get_underlying_type(instruction->dest_ptr->value.type);
2228 TypeTableEntry *ptr_type = instruction->dest_ptr->value.type;
22322229 assert(ptr_type->id == TypeTableEntryIdPointer);
22332230
22342231 LLVMValueRef is_volatile = ptr_type->data.pointer.is_volatile ?
......@@ -2256,8 +2253,8 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
22562253 LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
22572254 LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, "");
22582255
2259 TypeTableEntry *dest_ptr_type = get_underlying_type(instruction->dest_ptr->value.type);
2260 TypeTableEntry *src_ptr_type = get_underlying_type(instruction->src_ptr->value.type);
2256 TypeTableEntry *dest_ptr_type = instruction->dest_ptr->value.type;
2257 TypeTableEntry *src_ptr_type = instruction->src_ptr->value.type;
22612258
22622259 assert(dest_ptr_type->id == TypeTableEntryIdPointer);
22632260 assert(src_ptr_type->id == TypeTableEntryIdPointer);
......@@ -2407,7 +2404,7 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable
24072404}
24082405
24092406static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {
2410 TypeTableEntry *int_type = get_underlying_type(instruction->result_ptr_type);
2407 TypeTableEntry *int_type = instruction->result_ptr_type;
24112408 assert(int_type->id == TypeTableEntryIdInt);
24122409
24132410 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
......@@ -2444,7 +2441,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
24442441 return render_shl_with_overflow(g, instruction);
24452442 }
24462443
2447 TypeTableEntry *int_type = get_underlying_type(instruction->result_ptr_type);
2444 TypeTableEntry *int_type = instruction->result_ptr_type;
24482445 assert(int_type->id == TypeTableEntryIdInt);
24492446
24502447 LLVMValueRef fn_val = get_int_overflow_fn(g, int_type, add_sub_mul);
......@@ -2467,8 +2464,8 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
24672464}
24682465
24692466static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErr *instruction) {
2470 TypeTableEntry *err_union_type = get_underlying_type(instruction->value->value.type);
2471 TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type);
2467 TypeTableEntry *err_union_type = instruction->value->value.type;
2468 TypeTableEntry *child_type = err_union_type->data.error.child_type;
24722469 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->value);
24732470
24742471 LLVMValueRef err_val;
......@@ -2484,11 +2481,11 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
24842481}
24852482
24862483static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) {
2487 TypeTableEntry *ptr_type = get_underlying_type(instruction->value->value.type);
2484 TypeTableEntry *ptr_type = instruction->value->value.type;
24882485 assert(ptr_type->id == TypeTableEntryIdPointer);
24892486 bool is_volatile = ptr_type->data.pointer.is_volatile;
2490 TypeTableEntry *err_union_type = get_underlying_type(ptr_type->data.pointer.child_type);
2491 TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type);
2487 TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type;
2488 TypeTableEntry *child_type = err_union_type->data.error.child_type;
24922489 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
24932490 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, is_volatile);
24942491
......@@ -2501,11 +2498,11 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
25012498}
25022499
25032500static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) {
2504 TypeTableEntry *ptr_type = get_underlying_type(instruction->value->value.type);
2501 TypeTableEntry *ptr_type = instruction->value->value.type;
25052502 assert(ptr_type->id == TypeTableEntryIdPointer);
25062503 bool is_volatile = ptr_type->data.pointer.is_volatile;
2507 TypeTableEntry *err_union_type = get_underlying_type(ptr_type->data.pointer.child_type);
2508 TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type);
2504 TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type;
2505 TypeTableEntry *child_type = err_union_type->data.error.child_type;
25092506 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
25102507 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, is_volatile);
25112508
......@@ -2941,9 +2938,9 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
29412938 break;
29422939 }
29432940
2944 TypeTableEntry *canon_type = get_underlying_type(const_val->type);
2945 assert(!canon_type->zero_bits);
2946 switch (canon_type->id) {
2941 TypeTableEntry *type_entry = const_val->type;
2942 assert(!type_entry->zero_bits);
2943 switch (type_entry->id) {
29472944 case TypeTableEntryIdInvalid:
29482945 case TypeTableEntryIdVar:
29492946 case TypeTableEntryIdMetaType:
......@@ -2956,12 +2953,12 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
29562953 case TypeTableEntryIdPureError:
29572954 case TypeTableEntryIdEnum:
29582955 case TypeTableEntryIdEnumTag:
2959 case TypeTableEntryIdTypeDecl:
29602956 case TypeTableEntryIdNamespace:
29612957 case TypeTableEntryIdBlock:
29622958 case TypeTableEntryIdBoundFn:
29632959 case TypeTableEntryIdArgTuple:
29642960 case TypeTableEntryIdVoid:
2961 case TypeTableEntryIdOpaque:
29652962 zig_unreachable();
29662963 case TypeTableEntryIdBool:
29672964 return LLVMConstInt(big_int_type_ref, const_val->data.x_bool ? 1 : 0, false);
......@@ -2975,7 +2972,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
29752972 {
29762973 LLVMValueRef float_val = gen_const_val(g, const_val);
29772974 LLVMValueRef int_val = LLVMConstFPToUI(float_val,
2978 LLVMIntType((unsigned)canon_type->data.floating.bit_count));
2975 LLVMIntType((unsigned)type_entry->data.floating.bit_count));
29792976 return LLVMConstZExt(int_val, big_int_type_ref);
29802977 }
29812978 case TypeTableEntryIdPointer:
......@@ -2992,11 +2989,11 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
29922989 zig_panic("TODO bit pack a union");
29932990 case TypeTableEntryIdStruct:
29942991 {
2995 assert(canon_type->data.structure.layout == ContainerLayoutPacked);
2992 assert(type_entry->data.structure.layout == ContainerLayoutPacked);
29962993
29972994 LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false);
2998 for (size_t i = 0; i < canon_type->data.structure.src_field_count; i += 1) {
2999 TypeStructField *field = &canon_type->data.structure.fields[i];
2995 for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
2996 TypeStructField *field = &type_entry->data.structure.fields[i];
30002997 if (field->gen_index == SIZE_MAX) {
30012998 continue;
30022999 }
......@@ -3012,37 +3009,35 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
30123009}
30133010
30143011static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
3015 TypeTableEntry *canon_type = get_underlying_type(const_val->type);
3016 assert(!canon_type->zero_bits);
3012 TypeTableEntry *type_entry = const_val->type;
3013 assert(!type_entry->zero_bits);
30173014
30183015 switch (const_val->special) {
30193016 case ConstValSpecialRuntime:
30203017 zig_unreachable();
30213018 case ConstValSpecialUndef:
3022 return LLVMGetUndef(canon_type->type_ref);
3019 return LLVMGetUndef(type_entry->type_ref);
30233020 case ConstValSpecialStatic:
30243021 break;
30253022 }
30263023
3027 switch (canon_type->id) {
3028 case TypeTableEntryIdTypeDecl:
3029 zig_unreachable();
3024 switch (type_entry->id) {
30303025 case TypeTableEntryIdInt:
30313026 case TypeTableEntryIdEnumTag:
3032 return LLVMConstInt(canon_type->type_ref, bignum_to_twos_complement(&const_val->data.x_bignum), false);
3027 return LLVMConstInt(type_entry->type_ref, bignum_to_twos_complement(&const_val->data.x_bignum), false);
30333028 case TypeTableEntryIdPureError:
30343029 assert(const_val->data.x_pure_err);
30353030 return LLVMConstInt(g->builtin_types.entry_pure_error->type_ref,
30363031 const_val->data.x_pure_err->value, false);
30373032 case TypeTableEntryIdFloat:
30383033 if (const_val->data.x_bignum.kind == BigNumKindFloat) {
3039 return LLVMConstReal(canon_type->type_ref, const_val->data.x_bignum.data.x_float);
3034 return LLVMConstReal(type_entry->type_ref, const_val->data.x_bignum.data.x_float);
30403035 } else {
30413036 double x = (double)const_val->data.x_bignum.data.x_uint;
30423037 if (const_val->data.x_bignum.is_negative) {
30433038 x = -x;
30443039 }
3045 return LLVMConstReal(canon_type->type_ref, x);
3040 return LLVMConstReal(type_entry->type_ref, x);
30463041 }
30473042 case TypeTableEntryIdBool:
30483043 if (const_val->data.x_bool) {
......@@ -3052,7 +3047,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
30523047 }
30533048 case TypeTableEntryIdMaybe:
30543049 {
3055 TypeTableEntry *child_type = canon_type->data.maybe.child_type;
3050 TypeTableEntry *child_type = type_entry->data.maybe.child_type;
30563051 if (child_type->zero_bits) {
30573052 return LLVMConstInt(LLVMInt1Type(), const_val->data.x_maybe ? 1 : 0, false);
30583053 } else if (child_type->id == TypeTableEntryIdPointer ||
......@@ -3082,12 +3077,12 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
30823077 }
30833078 case TypeTableEntryIdStruct:
30843079 {
3085 LLVMValueRef *fields = allocate<LLVMValueRef>(canon_type->data.structure.gen_field_count);
3086 size_t src_field_count = canon_type->data.structure.src_field_count;
3087 if (canon_type->data.structure.layout == ContainerLayoutPacked) {
3080 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
3081 size_t src_field_count = type_entry->data.structure.src_field_count;
3082 if (type_entry->data.structure.layout == ContainerLayoutPacked) {
30883083 size_t src_field_index = 0;
30893084 while (src_field_index < src_field_count) {
3090 TypeStructField *type_struct_field = &canon_type->data.structure.fields[src_field_index];
3085 TypeStructField *type_struct_field = &type_entry->data.structure.fields[src_field_index];
30913086 if (type_struct_field->gen_index == SIZE_MAX) {
30923087 src_field_index += 1;
30933088 continue;
......@@ -3095,7 +3090,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
30953090
30963091 size_t src_field_index_end = src_field_index + 1;
30973092 for (; src_field_index_end < src_field_count; src_field_index_end += 1) {
3098 TypeStructField *it_field = &canon_type->data.structure.fields[src_field_index_end];
3093 TypeStructField *it_field = &type_entry->data.structure.fields[src_field_index_end];
30993094 if (it_field->gen_index != type_struct_field->gen_index)
31003095 break;
31013096 }
......@@ -3104,11 +3099,11 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
31043099 fields[type_struct_field->gen_index] =
31053100 gen_const_val(g, &const_val->data.x_struct.fields[src_field_index]);
31063101 } else {
3107 LLVMTypeRef big_int_type_ref = LLVMStructGetTypeAtIndex(canon_type->type_ref,
3102 LLVMTypeRef big_int_type_ref = LLVMStructGetTypeAtIndex(type_entry->type_ref,
31083103 (unsigned)type_struct_field->gen_index);
31093104 LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false);
31103105 for (size_t i = src_field_index; i < src_field_index_end; i += 1) {
3111 TypeStructField *it_field = &canon_type->data.structure.fields[i];
3106 TypeStructField *it_field = &type_entry->data.structure.fields[i];
31123107 if (it_field->gen_index == SIZE_MAX) {
31133108 continue;
31143109 }
......@@ -3126,14 +3121,14 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
31263121 }
31273122 } else {
31283123 for (uint32_t i = 0; i < src_field_count; i += 1) {
3129 TypeStructField *type_struct_field = &canon_type->data.structure.fields[i];
3124 TypeStructField *type_struct_field = &type_entry->data.structure.fields[i];
31303125 if (type_struct_field->gen_index == SIZE_MAX) {
31313126 continue;
31323127 }
31333128 fields[type_struct_field->gen_index] = gen_const_val(g, &const_val->data.x_struct.fields[i]);
31343129 }
31353130 }
3136 return LLVMConstNamedStruct(canon_type->type_ref, fields, canon_type->data.structure.gen_field_count);
3131 return LLVMConstNamedStruct(type_entry->type_ref, fields, type_entry->data.structure.gen_field_count);
31373132 }
31383133 case TypeTableEntryIdUnion:
31393134 {
......@@ -3141,7 +3136,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
31413136 }
31423137 case TypeTableEntryIdArray:
31433138 {
3144 uint64_t len = canon_type->data.array.len;
3139 uint64_t len = type_entry->data.array.len;
31453140 LLVMValueRef *values = allocate<LLVMValueRef>(len);
31463141 for (uint64_t i = 0; i < len; i += 1) {
31473142 ConstExprValue *elem_value = &const_val->data.x_array.elements[i];
......@@ -3151,13 +3146,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
31513146 }
31523147 case TypeTableEntryIdEnum:
31533148 {
3154 LLVMTypeRef tag_type_ref = canon_type->data.enumeration.tag_type->type_ref;
3149 LLVMTypeRef tag_type_ref = type_entry->data.enumeration.tag_type->type_ref;
31553150 LLVMValueRef tag_value = LLVMConstInt(tag_type_ref, const_val->data.x_enum.tag, false);
3156 if (canon_type->data.enumeration.gen_field_count == 0) {
3151 if (type_entry->data.enumeration.gen_field_count == 0) {
31573152 return tag_value;
31583153 } else {
3159 TypeTableEntry *union_type = canon_type->data.enumeration.union_type;
3160 TypeEnumField *enum_field = &canon_type->data.enumeration.fields[const_val->data.x_enum.tag];
3154 TypeTableEntry *union_type = type_entry->data.enumeration.union_type;
3155 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[const_val->data.x_enum.tag];
31613156 assert(enum_field->value == const_val->data.x_enum.tag);
31623157 LLVMValueRef union_value;
31633158 if (type_has_bits(enum_field->type_entry)) {
......@@ -3261,7 +3256,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
32613256 }
32623257 case TypeTableEntryIdErrorUnion:
32633258 {
3264 TypeTableEntry *child_type = canon_type->data.error.child_type;
3259 TypeTableEntry *child_type = type_entry->data.error.child_type;
32653260 if (!type_has_bits(child_type)) {
32663261 uint64_t value = const_val->data.x_err_union.err ? const_val->data.x_err_union.err->value : 0;
32673262 return LLVMConstInt(g->err_tag_type->type_ref, value, false);
......@@ -3296,6 +3291,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val) {
32963291 case TypeTableEntryIdBoundFn:
32973292 case TypeTableEntryIdVar:
32983293 case TypeTableEntryIdArgTuple:
3294 case TypeTableEntryIdOpaque:
32993295 zig_unreachable();
33003296
33013297 }
......@@ -4107,7 +4103,7 @@ static void define_builtin_types(CodeGen *g) {
41074103 g->builtin_types.entry_i64 = get_int_type(g, true, 64);
41084104
41094105 {
4110 g->builtin_types.entry_c_void = get_typedecl_type(g, "c_void", g->builtin_types.entry_u8);
4106 g->builtin_types.entry_c_void = get_opaque_type(g, nullptr, nullptr, "c_void");
41114107 g->primitive_type_table.put(&g->builtin_types.entry_c_void->name, g->builtin_types.entry_c_void);
41124108 }
41134109
......@@ -4747,6 +4743,7 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
47474743 zig_unreachable();
47484744 }
47494745 }
4746 case TypeTableEntryIdOpaque:
47504747 case TypeTableEntryIdArray:
47514748 case TypeTableEntryIdStruct:
47524749 case TypeTableEntryIdErrorUnion:
......@@ -4754,7 +4751,6 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
47544751 case TypeTableEntryIdEnum:
47554752 case TypeTableEntryIdUnion:
47564753 case TypeTableEntryIdFn:
4757 case TypeTableEntryIdTypeDecl:
47584754 case TypeTableEntryIdEnumTag:
47594755 zig_panic("TODO implement get_c_type for more types");
47604756 case TypeTableEntryIdInvalid:
src/ir.cpp+141-238
......@@ -5323,11 +5323,6 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *scope, AstNode *nod
53235323 return ir_build_br(irb, scope, node, dest_block, is_comptime);
53245324}
53255325
5326static IrInstruction *ir_gen_type_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
5327 assert(node->type == NodeTypeTypeLiteral);
5328 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_type);
5329}
5330
53315326static IrInstruction *ir_gen_error_type(IrBuilder *irb, Scope *scope, AstNode *node) {
53325327 assert(node->type == NodeTypeErrorType);
53335328 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_pure_error);
......@@ -5600,8 +5595,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
56005595 return ir_lval_wrap(irb, scope, ir_gen_goto(irb, scope, node), lval);
56015596 case NodeTypeCompTime:
56025597 return ir_gen_comptime(irb, scope, node, lval);
5603 case NodeTypeTypeLiteral:
5604 return ir_lval_wrap(irb, scope, ir_gen_type_literal(irb, scope, node), lval);
56055598 case NodeTypeErrorType:
56065599 return ir_lval_wrap(irb, scope, ir_gen_error_type(irb, scope, node), lval);
56075600 case NodeTypeBreak:
......@@ -5628,8 +5621,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
56285621 zig_panic("TODO IR gen NodeTypeFnDecl");
56295622 case NodeTypeErrorValueDecl:
56305623 zig_panic("TODO IR gen NodeTypeErrorValueDecl");
5631 case NodeTypeTypeDecl:
5632 zig_panic("TODO IR gen NodeTypeTypeDecl");
56335624 case NodeTypeTestDecl:
56345625 zig_panic("TODO IR gen NodeTypeTestDecl");
56355626 }
......@@ -5753,13 +5744,6 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction,
57535744 return ir_add_error_node(ira, source_instruction->source_node, msg);
57545745}
57555746
5756static void ir_add_typedef_err_note(IrAnalyze *ira, ErrorMsg *msg, TypeTableEntry *type_entry) {
5757 if (type_entry->id == TypeTableEntryIdTypeDecl) {
5758 // requires tracking source_node in the typedecl type
5759 zig_panic("TODO add error note about typedecls");
5760 }
5761}
5762
57635747static IrInstruction *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
57645748 IrBasicBlock *bb = exec->basic_block_list.at(0);
57655749 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
......@@ -5791,27 +5775,25 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
57915775}
57925776
57935777static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *other_type) {
5794 TypeTableEntry *other_type_underlying = get_underlying_type(other_type);
5795
5796 if (type_is_invalid(other_type_underlying)) {
5778 if (type_is_invalid(other_type)) {
57975779 return false;
57985780 }
57995781
58005782 ConstExprValue *const_val = &instruction->value;
58015783 assert(const_val->special != ConstValSpecialRuntime);
5802 if (other_type_underlying->id == TypeTableEntryIdFloat) {
5784 if (other_type->id == TypeTableEntryIdFloat) {
58035785 return true;
5804 } else if (other_type_underlying->id == TypeTableEntryIdInt &&
5786 } else if (other_type->id == TypeTableEntryIdInt &&
58055787 const_val->data.x_bignum.kind == BigNumKindInt)
58065788 {
5807 if (bignum_fits_in_bits(&const_val->data.x_bignum, other_type_underlying->data.integral.bit_count,
5808 other_type_underlying->data.integral.is_signed))
5789 if (bignum_fits_in_bits(&const_val->data.x_bignum, other_type->data.integral.bit_count,
5790 other_type->data.integral.is_signed))
58095791 {
58105792 return true;
58115793 }
5812 } else if ((other_type_underlying->id == TypeTableEntryIdNumLitFloat &&
5794 } else if ((other_type->id == TypeTableEntryIdNumLitFloat &&
58135795 const_val->data.x_bignum.kind == BigNumKindFloat) ||
5814 (other_type_underlying->id == TypeTableEntryIdNumLitInt &&
5796 (other_type->id == TypeTableEntryIdNumLitInt &&
58155797 const_val->data.x_bignum.kind == BigNumKindInt))
58165798 {
58175799 return true;
......@@ -6890,12 +6872,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
68906872 TypeTableEntry *wanted_type, IrInstruction *value)
68916873{
68926874 TypeTableEntry *actual_type = value->value.type;
6893 TypeTableEntry *wanted_type_canon = get_underlying_type(wanted_type);
6894 TypeTableEntry *actual_type_canon = get_underlying_type(actual_type);
6895
68966875 TypeTableEntry *usize_type = ira->codegen->builtin_types.entry_usize;
68976876
6898 if (type_is_invalid(wanted_type_canon) || type_is_invalid(actual_type_canon)) {
6877 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
68996878 return ira->codegen->invalid_instruction;
69006879 }
69016880
......@@ -6908,36 +6887,36 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
69086887 }
69096888
69106889 // explicit cast from bool to int
6911 if (wanted_type_canon->id == TypeTableEntryIdInt &&
6912 actual_type_canon->id == TypeTableEntryIdBool)
6890 if (wanted_type->id == TypeTableEntryIdInt &&
6891 actual_type->id == TypeTableEntryIdBool)
69136892 {
69146893 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpBoolToInt, false);
69156894 }
69166895
69176896 // explicit cast from pointer to usize
6918 if (wanted_type_canon == usize_type && type_is_codegen_pointer(actual_type_canon)) {
6897 if (wanted_type == usize_type && type_is_codegen_pointer(actual_type)) {
69196898 return ir_analyze_ptr_to_int(ira, source_instr, value, wanted_type);
69206899 }
69216900
69226901 // explicit widening or shortening cast
6923 if ((wanted_type_canon->id == TypeTableEntryIdInt &&
6924 actual_type_canon->id == TypeTableEntryIdInt) ||
6925 (wanted_type_canon->id == TypeTableEntryIdFloat &&
6926 actual_type_canon->id == TypeTableEntryIdFloat))
6902 if ((wanted_type->id == TypeTableEntryIdInt &&
6903 actual_type->id == TypeTableEntryIdInt) ||
6904 (wanted_type->id == TypeTableEntryIdFloat &&
6905 actual_type->id == TypeTableEntryIdFloat))
69276906 {
69286907 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
69296908 }
69306909
69316910 // explicit cast from int to float
6932 if (wanted_type_canon->id == TypeTableEntryIdFloat &&
6933 actual_type_canon->id == TypeTableEntryIdInt)
6911 if (wanted_type->id == TypeTableEntryIdFloat &&
6912 actual_type->id == TypeTableEntryIdInt)
69346913 {
69356914 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpIntToFloat, false);
69366915 }
69376916
69386917 // explicit cast from float to int
6939 if (wanted_type_canon->id == TypeTableEntryIdInt &&
6940 actual_type_canon->id == TypeTableEntryIdFloat)
6918 if (wanted_type->id == TypeTableEntryIdInt &&
6919 actual_type->id == TypeTableEntryIdFloat)
69416920 {
69426921 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpFloatToInt, false);
69436922 }
......@@ -7070,17 +7049,17 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
70707049 return ira->codegen->invalid_instruction;
70717050
70727051 return cast2;
7073 } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type_canon)) {
7052 } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type)) {
70747053 CastOp op;
70757054 if ((actual_type->id == TypeTableEntryIdNumLitFloat &&
7076 wanted_type_canon->id == TypeTableEntryIdFloat) ||
7055 wanted_type->id == TypeTableEntryIdFloat) ||
70777056 (actual_type->id == TypeTableEntryIdNumLitInt &&
7078 wanted_type_canon->id == TypeTableEntryIdInt))
7057 wanted_type->id == TypeTableEntryIdInt))
70797058 {
70807059 op = CastOpNoop;
7081 } else if (wanted_type_canon->id == TypeTableEntryIdInt) {
7060 } else if (wanted_type->id == TypeTableEntryIdInt) {
70827061 op = CastOpFloatToInt;
7083 } else if (wanted_type_canon->id == TypeTableEntryIdFloat) {
7062 } else if (wanted_type->id == TypeTableEntryIdFloat) {
70847063 op = CastOpIntToFloat;
70857064 } else {
70867065 zig_unreachable();
......@@ -7475,7 +7454,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
74757454 case TypeTableEntryIdPointer:
74767455 case TypeTableEntryIdPureError:
74777456 case TypeTableEntryIdFn:
7478 case TypeTableEntryIdTypeDecl:
7457 case TypeTableEntryIdOpaque:
74797458 case TypeTableEntryIdNamespace:
74807459 case TypeTableEntryIdBlock:
74817460 case TypeTableEntryIdBoundFn:
......@@ -7709,15 +7688,14 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
77097688 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, instructions, 2);
77107689 if (type_is_invalid(resolved_type))
77117690 return resolved_type;
7712 TypeTableEntry *canon_resolved_type = get_underlying_type(resolved_type);
77137691 IrBinOp op_id = bin_op_instruction->op_id;
77147692
7715 if (canon_resolved_type->id == TypeTableEntryIdInt ||
7716 canon_resolved_type->id == TypeTableEntryIdNumLitInt)
7693 if (resolved_type->id == TypeTableEntryIdInt ||
7694 resolved_type->id == TypeTableEntryIdNumLitInt)
77177695 {
77187696 // int
7719 } else if ((canon_resolved_type->id == TypeTableEntryIdFloat ||
7720 canon_resolved_type->id == TypeTableEntryIdNumLitFloat) &&
7697 } else if ((resolved_type->id == TypeTableEntryIdFloat ||
7698 resolved_type->id == TypeTableEntryIdNumLitFloat) &&
77217699 (op_id == IrBinOpAdd ||
77227700 op_id == IrBinOpSub ||
77237701 op_id == IrBinOpMult ||
......@@ -7751,7 +7729,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
77517729 bin_op_instruction->base.other = &bin_op_instruction->base;
77527730
77537731 int err;
7754 if ((err = ir_eval_math_op(canon_resolved_type, op1_val, op_id, op2_val, out_val))) {
7732 if ((err = ir_eval_math_op(resolved_type, op1_val, op_id, op2_val, out_val))) {
77557733 if (err == ErrorDivByZero) {
77567734 ir_add_error_node(ira, bin_op_instruction->base.source_node,
77577735 buf_sprintf("division by zero is undefined"));
......@@ -7776,13 +7754,13 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
77767754
77777755static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
77787756 IrInstruction *op1 = instruction->op1->other;
7779 TypeTableEntry *op1_canon_type = get_underlying_type(op1->value.type);
7780 if (type_is_invalid(op1_canon_type))
7757 TypeTableEntry *op1_type = op1->value.type;
7758 if (type_is_invalid(op1_type))
77817759 return ira->codegen->builtin_types.entry_invalid;
77827760
77837761 IrInstruction *op2 = instruction->op2->other;
7784 TypeTableEntry *op2_canon_type = get_underlying_type(op2->value.type);
7785 if (type_is_invalid(op2_canon_type))
7762 TypeTableEntry *op2_type = op2->value.type;
7763 if (type_is_invalid(op2_type))
77867764 return ira->codegen->builtin_types.entry_invalid;
77877765
77887766 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
......@@ -7797,22 +7775,22 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
77977775 size_t op1_array_index;
77987776 size_t op1_array_end;
77997777 TypeTableEntry *child_type;
7800 if (op1_canon_type->id == TypeTableEntryIdArray) {
7801 child_type = op1_canon_type->data.array.child_type;
7778 if (op1_type->id == TypeTableEntryIdArray) {
7779 child_type = op1_type->data.array.child_type;
78027780 op1_array_val = op1_val;
78037781 op1_array_index = 0;
7804 op1_array_end = op1_canon_type->data.array.len;
7805 } else if (op1_canon_type->id == TypeTableEntryIdPointer &&
7806 op1_canon_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
7782 op1_array_end = op1_type->data.array.len;
7783 } else if (op1_type->id == TypeTableEntryIdPointer &&
7784 op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
78077785 op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
78087786 op1_val->data.x_ptr.data.base_array.is_cstr)
78097787 {
7810 child_type = op1_canon_type->data.pointer.child_type;
7788 child_type = op1_type->data.pointer.child_type;
78117789 op1_array_val = op1_val->data.x_ptr.data.base_array.array_val;
78127790 op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index;
78137791 op1_array_end = op1_array_val->type->data.array.len - 1;
7814 } else if (is_slice(op1_canon_type)) {
7815 TypeTableEntry *ptr_type = op1_canon_type->data.structure.fields[slice_ptr_index].type_entry;
7792 } else if (is_slice(op1_type)) {
7793 TypeTableEntry *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry;
78167794 child_type = ptr_type->data.pointer.child_type;
78177795 ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index];
78187796 assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray);
......@@ -7822,15 +7800,14 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
78227800 } else {
78237801 ir_add_error(ira, op1,
78247802 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name)));
7825 // TODO if meta_type is type decl, add note pointing to type decl declaration
78267803 return ira->codegen->builtin_types.entry_invalid;
78277804 }
78287805
78297806 ConstExprValue *op2_array_val;
78307807 size_t op2_array_index;
78317808 size_t op2_array_end;
7832 if (op2_canon_type->id == TypeTableEntryIdArray) {
7833 if (op2_canon_type->data.array.child_type != child_type) {
7809 if (op2_type->id == TypeTableEntryIdArray) {
7810 if (op2_type->data.array.child_type != child_type) {
78347811 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
78357812 buf_ptr(&child_type->name),
78367813 buf_ptr(&op2->value.type->name)));
......@@ -7839,8 +7816,8 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
78397816 op2_array_val = op2_val;
78407817 op2_array_index = 0;
78417818 op2_array_end = op2_array_val->type->data.array.len;
7842 } else if (op2_canon_type->id == TypeTableEntryIdPointer &&
7843 op2_canon_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
7819 } else if (op2_type->id == TypeTableEntryIdPointer &&
7820 op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 &&
78447821 op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray &&
78457822 op2_val->data.x_ptr.data.base_array.is_cstr)
78467823 {
......@@ -7853,8 +7830,8 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
78537830 op2_array_val = op2_val->data.x_ptr.data.base_array.array_val;
78547831 op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index;
78557832 op2_array_end = op2_array_val->type->data.array.len - 1;
7856 } else if (is_slice(op2_canon_type)) {
7857 TypeTableEntry *ptr_type = op2_canon_type->data.structure.fields[slice_ptr_index].type_entry;
7833 } else if (is_slice(op2_type)) {
7834 TypeTableEntry *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry;
78587835 if (ptr_type->data.pointer.child_type != child_type) {
78597836 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",
78607837 buf_ptr(&child_type->name),
......@@ -7869,7 +7846,6 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
78697846 } else {
78707847 ir_add_error(ira, op2,
78717848 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name)));
7872 // TODO if meta_type is type decl, add note pointing to type decl declaration
78737849 return ira->codegen->builtin_types.entry_invalid;
78747850 }
78757851
......@@ -7878,7 +7854,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
78787854 TypeTableEntry *result_type;
78797855 ConstExprValue *out_array_val;
78807856 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
7881 if (op1_canon_type->id == TypeTableEntryIdArray || op2_canon_type->id == TypeTableEntryIdArray) {
7857 if (op1_type->id == TypeTableEntryIdArray || op2_type->id == TypeTableEntryIdArray) {
78827858 result_type = get_array_type(ira->codegen, child_type, new_len);
78837859
78847860 out_array_val = out_val;
......@@ -7931,14 +7907,13 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
79317907 if (!ir_resolve_usize(ira, op2, &mult_amt))
79327908 return ira->codegen->builtin_types.entry_invalid;
79337909
7934 TypeTableEntry *array_canon_type = get_underlying_type(op1->value.type);
7935 if (array_canon_type->id != TypeTableEntryIdArray) {
7910 TypeTableEntry *array_type = op1->value.type;
7911 if (array_type->id != TypeTableEntryIdArray) {
79367912 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name)));
7937 // TODO if meta_type is type decl, add note pointing to type decl declaration
79387913 return ira->codegen->builtin_types.entry_invalid;
79397914 }
79407915
7941 uint64_t old_array_len = array_canon_type->data.array.len;
7916 uint64_t old_array_len = array_type->data.array.len;
79427917
79437918 BigNum array_len;
79447919 bignum_init_unsigned(&array_len, old_array_len);
......@@ -7961,7 +7936,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
79617936 }
79627937 assert(i == new_array_len);
79637938
7964 TypeTableEntry *child_type = array_canon_type->data.array.child_type;
7939 TypeTableEntry *child_type = array_type->data.array.child_type;
79657940 return get_array_type(ira->codegen, child_type, new_array_len);
79667941}
79677942
......@@ -8033,7 +8008,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
80338008 AstNode *source_node = decl_var_instruction->base.source_node;
80348009
80358010 IrInstruction *casted_init_value = ir_implicit_cast(ira, init_value, explicit_type);
8036 TypeTableEntry *result_type = get_underlying_type(casted_init_value->value.type);
8011 TypeTableEntry *result_type = casted_init_value->value.type;
80378012 if (type_is_invalid(result_type)) {
80388013 result_type = ira->codegen->builtin_types.entry_invalid;
80398014 }
......@@ -8041,8 +8016,6 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
80418016 bool is_comptime_var = ir_get_var_is_comptime(var);
80428017
80438018 switch (result_type->id) {
8044 case TypeTableEntryIdTypeDecl:
8045 zig_unreachable();
80468019 case TypeTableEntryIdInvalid:
80478020 break; // handled above
80488021 case TypeTableEntryIdNumLitFloat:
......@@ -8057,6 +8030,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
80578030 case TypeTableEntryIdVar:
80588031 case TypeTableEntryIdBlock:
80598032 case TypeTableEntryIdNullLit:
8033 case TypeTableEntryIdOpaque:
80608034 ir_add_error_node(ira, source_node,
80618035 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name)));
80628036 result_type = ira->codegen->builtin_types.entry_invalid;
......@@ -8670,14 +8644,11 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct
86708644 IrInstruction *value = un_op_instruction->value->other;
86718645
86728646 TypeTableEntry *meta_type = ir_resolve_type(ira, value);
8673 TypeTableEntry *underlying_meta_type = get_underlying_type(meta_type);
8674
8675 if (type_is_invalid(underlying_meta_type))
8647 if (type_is_invalid(meta_type))
86768648 return ira->codegen->builtin_types.entry_invalid;
86778649
86788650
8679 switch (underlying_meta_type->id) {
8680 case TypeTableEntryIdTypeDecl:
8651 switch (meta_type->id) {
86818652 case TypeTableEntryIdInvalid: // handled above
86828653 zig_unreachable();
86838654
......@@ -8712,9 +8683,9 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct
87128683 case TypeTableEntryIdUnreachable:
87138684 case TypeTableEntryIdVar:
87148685 case TypeTableEntryIdArgTuple:
8686 case TypeTableEntryIdOpaque:
87158687 ir_add_error_node(ira, un_op_instruction->base.source_node,
87168688 buf_sprintf("unable to wrap type '%s' in error type", buf_ptr(&meta_type->name)));
8717 // TODO if meta_type is type decl, add note pointing to type decl declaration
87188689 return ira->codegen->builtin_types.entry_invalid;
87198690 }
87208691 zig_unreachable();
......@@ -8756,13 +8727,11 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
87568727static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
87578728 IrInstruction *value = un_op_instruction->value->other;
87588729 TypeTableEntry *type_entry = ir_resolve_type(ira, value);
8759 TypeTableEntry *canon_type = get_underlying_type(type_entry);
8760 if (type_is_invalid(canon_type))
8730 if (type_is_invalid(type_entry))
87618731 return ira->codegen->builtin_types.entry_invalid;
8762 switch (canon_type->id) {
8732 switch (type_entry->id) {
87638733 case TypeTableEntryIdInvalid:
87648734 case TypeTableEntryIdVar:
8765 case TypeTableEntryIdTypeDecl:
87668735 zig_unreachable();
87678736 case TypeTableEntryIdMetaType:
87688737 case TypeTableEntryIdVoid:
......@@ -8793,9 +8762,9 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
87938762 return ira->codegen->builtin_types.entry_type;
87948763 }
87958764 case TypeTableEntryIdUnreachable:
8765 case TypeTableEntryIdOpaque:
87968766 ir_add_error_node(ira, un_op_instruction->base.source_node,
87978767 buf_sprintf("type '%s' not nullable", buf_ptr(&type_entry->name)));
8798 // TODO if it's a type decl, put an error note here pointing to the decl
87998768 return ira->codegen->builtin_types.entry_invalid;
88008769 }
88018770 zig_unreachable();
......@@ -9406,23 +9375,6 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
94069375 return ir_analyze_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry,
94079376 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
94089377 }
9409 case TldIdTypeDef:
9410 {
9411 TldTypeDef *tld_typedef = (TldTypeDef *)tld;
9412 assert(tld_typedef->type_entry);
9413
9414 // TODO instead of allocating this every time, put it in the tld value and we can reference
9415 // the same one every time
9416 ConstExprValue *const_val = allocate<ConstExprValue>(1);
9417 const_val->special = ConstValSpecialStatic;
9418 const_val->type = ira->codegen->builtin_types.entry_type;
9419 const_val->data.x_type = tld_typedef->type_entry;
9420
9421 bool ptr_is_const = true;
9422 bool ptr_is_volatile = false;
9423 return ir_analyze_const_ptr(ira, source_instruction, const_val, ira->codegen->builtin_types.entry_type,
9424 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile);
9425 }
94269378 }
94279379 zig_unreachable();
94289380}
......@@ -9726,9 +9678,9 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
97269678 case TypeTableEntryIdEnum:
97279679 case TypeTableEntryIdUnion:
97289680 case TypeTableEntryIdFn:
9729 case TypeTableEntryIdTypeDecl:
97309681 case TypeTableEntryIdEnumTag:
97319682 case TypeTableEntryIdArgTuple:
9683 case TypeTableEntryIdOpaque:
97329684 {
97339685 ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base);
97349686 out_val->data.x_type = type_entry;
......@@ -9990,12 +9942,10 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
99909942 bool is_const = slice_type_instruction->is_const;
99919943
99929944 TypeTableEntry *resolved_child_type = ir_resolve_type(ira, child_type);
9993 TypeTableEntry *canon_child_type = get_underlying_type(resolved_child_type);
9994 if (type_is_invalid(canon_child_type))
9945 if (type_is_invalid(resolved_child_type))
99959946 return ira->codegen->builtin_types.entry_invalid;
99969947
9997 switch (canon_child_type->id) {
9998 case TypeTableEntryIdTypeDecl:
9948 switch (resolved_child_type->id) {
99999949 case TypeTableEntryIdInvalid: // handled above
100009950 zig_unreachable();
100019951 case TypeTableEntryIdVar:
......@@ -10004,9 +9954,9 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
100049954 case TypeTableEntryIdNullLit:
100059955 case TypeTableEntryIdBlock:
100069956 case TypeTableEntryIdArgTuple:
9957 case TypeTableEntryIdOpaque:
100079958 ir_add_error_node(ira, slice_type_instruction->base.source_node,
100089959 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&resolved_child_type->name)));
10009 // TODO if this is a typedecl, add error note showing the declaration of the type decl
100109960 return ira->codegen->builtin_types.entry_invalid;
100119961 case TypeTableEntryIdMetaType:
100129962 case TypeTableEntryIdVoid:
......@@ -10100,11 +10050,9 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
1010010050
1010110051 IrInstruction *child_type_value = array_type_instruction->child_type->other;
1010210052 TypeTableEntry *child_type = ir_resolve_type(ira, child_type_value);
10103 TypeTableEntry *canon_child_type = get_underlying_type(child_type);
10104 if (type_is_invalid(canon_child_type))
10053 if (type_is_invalid(child_type))
1010510054 return ira->codegen->builtin_types.entry_invalid;
10106 switch (canon_child_type->id) {
10107 case TypeTableEntryIdTypeDecl:
10055 switch (child_type->id) {
1010810056 case TypeTableEntryIdInvalid: // handled above
1010910057 zig_unreachable();
1011010058 case TypeTableEntryIdVar:
......@@ -10113,9 +10061,9 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
1011310061 case TypeTableEntryIdNullLit:
1011410062 case TypeTableEntryIdBlock:
1011510063 case TypeTableEntryIdArgTuple:
10064 case TypeTableEntryIdOpaque:
1011610065 ir_add_error_node(ira, array_type_instruction->base.source_node,
1011710066 buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name)));
10118 // TODO if this is a typedecl, add error note showing the declaration of the type decl
1011910067 return ira->codegen->builtin_types.entry_invalid;
1012010068 case TypeTableEntryIdMetaType:
1012110069 case TypeTableEntryIdVoid:
......@@ -10172,15 +10120,13 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
1017210120{
1017310121 IrInstruction *type_value = size_of_instruction->type_value->other;
1017410122 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
10175 TypeTableEntry *canon_type_entry = get_underlying_type(type_entry);
1017610123
1017710124 ensure_complete_type(ira->codegen, type_entry);
10178 if (type_is_invalid(canon_type_entry))
10125 if (type_is_invalid(type_entry))
1017910126 return ira->codegen->builtin_types.entry_invalid;
1018010127
10181 switch (canon_type_entry->id) {
10128 switch (type_entry->id) {
1018210129 case TypeTableEntryIdInvalid: // handled above
10183 case TypeTableEntryIdTypeDecl:
1018410130 zig_unreachable();
1018510131 case TypeTableEntryIdVar:
1018610132 case TypeTableEntryIdUnreachable:
......@@ -10193,9 +10139,9 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
1019310139 case TypeTableEntryIdMetaType:
1019410140 case TypeTableEntryIdNamespace:
1019510141 case TypeTableEntryIdArgTuple:
10142 case TypeTableEntryIdOpaque:
1019610143 ir_add_error_node(ira, size_of_instruction->base.source_node,
1019710144 buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name)));
10198 // TODO if this is a typedecl, add error note showing the declaration of the type decl
1019910145 return ira->codegen->builtin_types.entry_invalid;
1020010146 case TypeTableEntryIdVoid:
1020110147 case TypeTableEntryIdBool:
......@@ -10516,15 +10462,13 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1051610462 if (pointee_val->special == ConstValSpecialRuntime)
1051710463 pointee_val = nullptr;
1051810464 }
10519 TypeTableEntry *canon_target_type = get_underlying_type(target_type);
1052010465 ensure_complete_type(ira->codegen, target_type);
10521 if (type_is_invalid(canon_target_type))
10466 if (type_is_invalid(target_type))
1052210467 return ira->codegen->builtin_types.entry_invalid;
1052310468
10524 switch (canon_target_type->id) {
10469 switch (target_type->id) {
1052510470 case TypeTableEntryIdInvalid:
1052610471 case TypeTableEntryIdVar:
10527 case TypeTableEntryIdTypeDecl:
1052810472 zig_unreachable();
1052910473 case TypeTableEntryIdMetaType:
1053010474 case TypeTableEntryIdVoid:
......@@ -10576,9 +10520,9 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1057610520 case TypeTableEntryIdBlock:
1057710521 case TypeTableEntryIdBoundFn:
1057810522 case TypeTableEntryIdArgTuple:
10523 case TypeTableEntryIdOpaque:
1057910524 ir_add_error(ira, &switch_target_instruction->base,
1058010525 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
10581 // TODO if this is a typedecl, add error note showing the declaration of the type decl
1058210526 return ira->codegen->builtin_types.entry_invalid;
1058310527 }
1058410528 zig_unreachable();
......@@ -10630,9 +10574,8 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr
1063010574 return get_pointer_to_type(ira->codegen, field->type_entry,
1063110575 target_value_ptr->value.type->data.pointer.is_const);
1063210576 } else {
10633 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
10577 ir_add_error(ira, &instruction->base,
1063410578 buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name)));
10635 ir_add_typedef_err_note(ira, msg, target_type);
1063610579 return ira->codegen->builtin_types.entry_invalid;
1063710580 }
1063810581}
......@@ -10743,13 +10686,13 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
1074310686 IrInstructionArrayLen *array_len_instruction)
1074410687{
1074510688 IrInstruction *array_value = array_len_instruction->array_value->other;
10746 TypeTableEntry *canon_type = get_underlying_type(array_value->value.type);
10747 if (type_is_invalid(canon_type)) {
10689 TypeTableEntry *type_entry = array_value->value.type;
10690 if (type_is_invalid(type_entry)) {
1074810691 return ira->codegen->builtin_types.entry_invalid;
10749 } else if (canon_type->id == TypeTableEntryIdArray) {
10692 } else if (type_entry->id == TypeTableEntryIdArray) {
1075010693 return ir_analyze_const_usize(ira, &array_len_instruction->base,
10751 canon_type->data.array.len);
10752 } else if (is_slice(canon_type)) {
10694 type_entry->data.array.len);
10695 } else if (is_slice(type_entry)) {
1075310696 if (array_value->value.special != ConstValSpecialRuntime) {
1075410697 ConstExprValue *len_val = &array_value->value.data.x_struct.fields[slice_len_index];
1075510698 if (len_val->special != ConstValSpecialRuntime) {
......@@ -10757,7 +10700,7 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
1075710700 len_val->data.x_bignum.data.x_uint);
1075810701 }
1075910702 }
10760 TypeStructField *field = &canon_type->data.structure.fields[slice_len_index];
10703 TypeStructField *field = &type_entry->data.structure.fields[slice_len_index];
1076110704 IrInstruction *len_ptr = ir_build_struct_field_ptr(&ira->new_irb, array_len_instruction->base.scope,
1076210705 array_len_instruction->base.source_node, array_value, field);
1076310706 len_ptr->value.type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_usize, true);
......@@ -10766,7 +10709,6 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
1076610709 } else {
1076710710 ir_add_error_node(ira, array_len_instruction->base.source_node,
1076810711 buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->value.type->name)));
10769 // TODO if this is a typedecl, add error note showing the declaration of the type decl
1077010712 return ira->codegen->builtin_types.entry_invalid;
1077110713 }
1077210714}
......@@ -11049,29 +10991,28 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
1104910991 IrInstruction *target_type_value, bool is_max)
1105010992{
1105110993 TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value);
11052 TypeTableEntry *canon_type = get_underlying_type(target_type);
11053 if (type_is_invalid(canon_type))
10994 if (type_is_invalid(target_type))
1105410995 return ira->codegen->builtin_types.entry_invalid;
11055 switch (canon_type->id) {
10996 switch (target_type->id) {
1105610997 case TypeTableEntryIdInvalid:
1105710998 zig_unreachable();
1105810999 case TypeTableEntryIdInt:
1105911000 {
1106011001 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
11061 eval_min_max_value(ira->codegen, canon_type, out_val, is_max);
11002 eval_min_max_value(ira->codegen, target_type, out_val, is_max);
1106211003 return ira->codegen->builtin_types.entry_num_lit_int;
1106311004 }
1106411005 case TypeTableEntryIdFloat:
1106511006 {
1106611007 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
11067 eval_min_max_value(ira->codegen, canon_type, out_val, is_max);
11008 eval_min_max_value(ira->codegen, target_type, out_val, is_max);
1106811009 return ira->codegen->builtin_types.entry_num_lit_float;
1106911010 }
1107011011 case TypeTableEntryIdBool:
1107111012 case TypeTableEntryIdVoid:
1107211013 {
1107311014 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
11074 eval_min_max_value(ira->codegen, canon_type, out_val, is_max);
11015 eval_min_max_value(ira->codegen, target_type, out_val, is_max);
1107511016 return target_type;
1107611017 }
1107711018 case TypeTableEntryIdEnumTag:
......@@ -11092,18 +11033,17 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
1109211033 case TypeTableEntryIdEnum:
1109311034 case TypeTableEntryIdUnion:
1109411035 case TypeTableEntryIdFn:
11095 case TypeTableEntryIdTypeDecl:
1109611036 case TypeTableEntryIdNamespace:
1109711037 case TypeTableEntryIdBlock:
1109811038 case TypeTableEntryIdBoundFn:
1109911039 case TypeTableEntryIdArgTuple:
11040 case TypeTableEntryIdOpaque:
1110011041 {
1110111042 const char *err_format = is_max ?
1110211043 "no max value available for type '%s'" :
1110311044 "no min value available for type '%s'";
1110411045 ir_add_error(ira, source_instruction,
1110511046 buf_sprintf(err_format, buf_ptr(&target_type->name)));
11106 // TODO if this is a typedecl, add error note showing the declaration of the type decl
1110711047 return ira->codegen->builtin_types.entry_invalid;
1110811048 }
1110911049 }
......@@ -11508,14 +11448,11 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru
1150811448 if (type_is_invalid(result_type))
1150911449 return ira->codegen->builtin_types.entry_invalid;
1151011450
11511 TypeTableEntry *canon_type = get_underlying_type(result_type);
11512
11513 if (canon_type->id != TypeTableEntryIdInt &&
11514 canon_type->id != TypeTableEntryIdNumLitInt)
11451 if (result_type->id != TypeTableEntryIdInt &&
11452 result_type->id != TypeTableEntryIdNumLitInt)
1151511453 {
1151611454 ir_add_error(ira, &instruction->base,
1151711455 buf_sprintf("expected integer type, found '%s'", buf_ptr(&result_type->name)));
11518 // TODO if meta_type is type decl, add note pointing to type decl declaration
1151911456 return ira->codegen->builtin_types.entry_invalid;
1152011457 }
1152111458
......@@ -11563,49 +11500,42 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru
1156311500static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {
1156411501 IrInstruction *dest_type_value = instruction->dest_type->other;
1156511502 TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
11566 TypeTableEntry *canon_dest_type = get_underlying_type(dest_type);
11567
11568 if (type_is_invalid(canon_dest_type))
11503 if (type_is_invalid(dest_type))
1156911504 return ira->codegen->builtin_types.entry_invalid;
1157011505
11571 if (canon_dest_type->id != TypeTableEntryIdInt &&
11572 canon_dest_type->id != TypeTableEntryIdNumLitInt)
11506 if (dest_type->id != TypeTableEntryIdInt &&
11507 dest_type->id != TypeTableEntryIdNumLitInt)
1157311508 {
1157411509 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
11575 // TODO if meta_type is type decl, add note pointing to type decl declaration
1157611510 return ira->codegen->builtin_types.entry_invalid;
1157711511 }
1157811512
1157911513 IrInstruction *target = instruction->target->other;
1158011514 TypeTableEntry *src_type = target->value.type;
11581 TypeTableEntry *canon_src_type = get_underlying_type(src_type);
11582 if (type_is_invalid(canon_src_type))
11515 if (type_is_invalid(src_type))
1158311516 return ira->codegen->builtin_types.entry_invalid;
1158411517
11585 if (canon_src_type->id != TypeTableEntryIdInt &&
11586 canon_src_type->id != TypeTableEntryIdNumLitInt)
11518 if (src_type->id != TypeTableEntryIdInt &&
11519 src_type->id != TypeTableEntryIdNumLitInt)
1158711520 {
1158811521 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
11589 // TODO if meta_type is type decl, add note pointing to type decl declaration
1159011522 return ira->codegen->builtin_types.entry_invalid;
1159111523 }
1159211524
11593 if (canon_src_type->data.integral.is_signed != canon_dest_type->data.integral.is_signed) {
11594 const char *sign_str = canon_dest_type->data.integral.is_signed ? "signed" : "unsigned";
11525 if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {
11526 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";
1159511527 ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
11596 // TODO if meta_type is type decl, add note pointing to type decl declaration
1159711528 return ira->codegen->builtin_types.entry_invalid;
11598 } else if (canon_src_type->data.integral.bit_count < canon_dest_type->data.integral.bit_count) {
11529 } else if (src_type->data.integral.bit_count < dest_type->data.integral.bit_count) {
1159911530 ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'",
1160011531 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
11601 // TODO if meta_type is type decl, add note pointing to type decl declaration
1160211532 return ira->codegen->builtin_types.entry_invalid;
1160311533 }
1160411534
1160511535 if (target->value.special == ConstValSpecialStatic) {
1160611536 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1160711537 bignum_init_bignum(&out_val->data.x_bignum, &target->value.data.x_bignum);
11608 bignum_truncate(&out_val->data.x_bignum, canon_dest_type->data.integral.bit_count);
11538 bignum_truncate(&out_val->data.x_bignum, dest_type->data.integral.bit_count);
1160911539 return dest_type;
1161011540 }
1161111541
......@@ -11663,7 +11593,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
1166311593 if (type_is_invalid(count_value->value.type))
1166411594 return ira->codegen->builtin_types.entry_invalid;
1166511595
11666 TypeTableEntry *dest_uncasted_type = get_underlying_type(dest_ptr->value.type);
11596 TypeTableEntry *dest_uncasted_type = dest_ptr->value.type;
1166711597 bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) &&
1166811598 dest_uncasted_type->data.pointer.is_volatile;
1166911599
......@@ -11749,8 +11679,8 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
1174911679 if (type_is_invalid(count_value->value.type))
1175011680 return ira->codegen->builtin_types.entry_invalid;
1175111681
11752 TypeTableEntry *dest_uncasted_type = get_underlying_type(dest_ptr->value.type);
11753 TypeTableEntry *src_uncasted_type = get_underlying_type(src_ptr->value.type);
11682 TypeTableEntry *dest_uncasted_type = dest_ptr->value.type;
11683 TypeTableEntry *src_uncasted_type = src_ptr->value.type;
1175411684 bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) &&
1175511685 dest_uncasted_type->data.pointer.is_volatile;
1175611686 bool src_is_volatile = (src_uncasted_type->id == TypeTableEntryIdPointer) &&
......@@ -11866,8 +11796,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1186611796
1186711797 TypeTableEntry *ptr_type = ptr_ptr->value.type;
1186811798 assert(ptr_type->id == TypeTableEntryIdPointer);
11869 TypeTableEntry *non_canon_array_type = ptr_type->data.pointer.child_type;
11870 TypeTableEntry *canon_array_type = get_underlying_type(non_canon_array_type);
11799 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
1187111800
1187211801 IrInstruction *start = instruction->start->other;
1187311802 if (type_is_invalid(start->value.type))
......@@ -11892,22 +11821,21 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1189211821
1189311822 TypeTableEntry *return_type;
1189411823
11895 if (canon_array_type->id == TypeTableEntryIdArray) {
11896 return_type = get_slice_type(ira->codegen, canon_array_type->data.array.child_type, instruction->is_const);
11897 } else if (canon_array_type->id == TypeTableEntryIdPointer) {
11898 return_type = get_slice_type(ira->codegen, canon_array_type->data.pointer.child_type, instruction->is_const);
11824 if (array_type->id == TypeTableEntryIdArray) {
11825 return_type = get_slice_type(ira->codegen, array_type->data.array.child_type, instruction->is_const);
11826 } else if (array_type->id == TypeTableEntryIdPointer) {
11827 return_type = get_slice_type(ira->codegen, array_type->data.pointer.child_type, instruction->is_const);
1189911828 if (!end) {
1190011829 ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value"));
1190111830 return ira->codegen->builtin_types.entry_invalid;
1190211831 }
11903 } else if (is_slice(canon_array_type)) {
11832 } else if (is_slice(array_type)) {
1190411833 return_type = get_slice_type(ira->codegen,
11905 canon_array_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
11834 array_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
1190611835 instruction->is_const);
1190711836 } else {
1190811837 ir_add_error(ira, &instruction->base,
11909 buf_sprintf("slice of non-array type '%s'", buf_ptr(&non_canon_array_type->name)));
11910 // TODO if this is a typedecl, add error note showing the declaration of the type decl
11838 buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name)));
1191111839 return ira->codegen->builtin_types.entry_invalid;
1191211840 }
1191311841
......@@ -11919,12 +11847,12 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1191911847 ConstExprValue *parent_ptr;
1192011848 size_t abs_offset;
1192111849 size_t rel_end;
11922 if (canon_array_type->id == TypeTableEntryIdArray) {
11850 if (array_type->id == TypeTableEntryIdArray) {
1192311851 array_val = const_ptr_pointee(&ptr_ptr->value);
1192411852 abs_offset = 0;
11925 rel_end = canon_array_type->data.array.len;
11853 rel_end = array_type->data.array.len;
1192611854 parent_ptr = nullptr;
11927 } else if (canon_array_type->id == TypeTableEntryIdPointer) {
11855 } else if (array_type->id == TypeTableEntryIdPointer) {
1192811856 parent_ptr = const_ptr_pointee(&ptr_ptr->value);
1192911857 switch (parent_ptr->data.x_ptr.special) {
1193011858 case ConstPtrSpecialInvalid:
......@@ -11946,7 +11874,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1194611874 array_val = nullptr;
1194711875 break;
1194811876 }
11949 } else if (is_slice(canon_array_type)) {
11877 } else if (is_slice(array_type)) {
1195011878 ConstExprValue *slice_ptr = const_ptr_pointee(&ptr_ptr->value);
1195111879 parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index];
1195211880 ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index];
......@@ -12005,7 +11933,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1200511933 if (array_val) {
1200611934 size_t index = abs_offset + start_scalar;
1200711935 init_const_ptr_array(ira->codegen, ptr_val, array_val, index, instruction->is_const);
12008 if (canon_array_type->id == TypeTableEntryIdArray) {
11936 if (array_type->id == TypeTableEntryIdArray) {
1200911937 ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut;
1201011938 }
1201111939 } else {
......@@ -12045,17 +11973,16 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
1204511973 if (type_is_invalid(container->value.type))
1204611974 return ira->codegen->builtin_types.entry_invalid;
1204711975 TypeTableEntry *container_type = ir_resolve_type(ira, container);
12048 TypeTableEntry *canon_type = get_underlying_type(container_type);
1204911976
1205011977 uint64_t result;
12051 if (type_is_invalid(canon_type)) {
12052 return ira->codegen->builtin_types.entry_invalid;
12053 } else if (canon_type->id == TypeTableEntryIdEnum) {
12054 result = canon_type->data.enumeration.src_field_count;
12055 } else if (canon_type->id == TypeTableEntryIdStruct) {
12056 result = canon_type->data.structure.src_field_count;
12057 } else if (canon_type->id == TypeTableEntryIdUnion) {
12058 result = canon_type->data.unionation.src_field_count;
11978 if (type_is_invalid(container_type)) {
11979 return ira->codegen->builtin_types.entry_invalid;
11980 } else if (container_type->id == TypeTableEntryIdEnum) {
11981 result = container_type->data.enumeration.src_field_count;
11982 } else if (container_type->id == TypeTableEntryIdStruct) {
11983 result = container_type->data.structure.src_field_count;
11984 } else if (container_type->id == TypeTableEntryIdUnion) {
11985 result = container_type->data.unionation.src_field_count;
1205911986 } else {
1206011987 ir_add_error(ira, &instruction->base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
1206111988 return ira->codegen->builtin_types.entry_invalid;
......@@ -12112,14 +12039,12 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1211212039 if (type_is_invalid(type_value->value.type))
1211312040 return ira->codegen->builtin_types.entry_invalid;
1211412041 TypeTableEntry *dest_type = ir_resolve_type(ira, type_value);
12115 TypeTableEntry *canon_type = get_underlying_type(dest_type);
12116 if (type_is_invalid(canon_type))
12042 if (type_is_invalid(dest_type))
1211712043 return ira->codegen->builtin_types.entry_invalid;
1211812044
12119 if (canon_type->id != TypeTableEntryIdInt) {
12045 if (dest_type->id != TypeTableEntryIdInt) {
1212012046 ir_add_error(ira, type_value,
1212112047 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
12122 // TODO if this is a typedecl, add error note showing the declaration of the type decl
1212312048 return ira->codegen->builtin_types.entry_invalid;
1212412049 }
1212512050
......@@ -12171,11 +12096,11 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1217112096 out_val->data.x_bool = bignum_shl(dest_bignum, op1_bignum, op2_bignum);
1217212097 break;
1217312098 }
12174 if (!bignum_fits_in_bits(dest_bignum, canon_type->data.integral.bit_count,
12175 canon_type->data.integral.is_signed))
12099 if (!bignum_fits_in_bits(dest_bignum, dest_type->data.integral.bit_count,
12100 dest_type->data.integral.is_signed))
1217612101 {
1217712102 out_val->data.x_bool = true;
12178 bignum_truncate(dest_bignum, canon_type->data.integral.bit_count);
12103 bignum_truncate(dest_bignum, dest_type->data.integral.bit_count);
1217912104 }
1218012105 pointee_val->special = ConstValSpecialStatic;
1218112106 return ira->codegen->builtin_types.entry_bool;
......@@ -12191,12 +12116,10 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
1219112116 if (type_is_invalid(value->value.type))
1219212117 return ira->codegen->builtin_types.entry_invalid;
1219312118
12194 TypeTableEntry *non_canon_type = value->value.type;
12195
12196 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);
12197 if (type_is_invalid(canon_type)) {
12119 TypeTableEntry *type_entry = value->value.type;
12120 if (type_is_invalid(type_entry)) {
1219812121 return ira->codegen->builtin_types.entry_invalid;
12199 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
12122 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {
1220012123 if (instr_is_comptime(value)) {
1220112124 ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
1220212125 if (!err_union_val)
......@@ -12211,7 +12134,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
1221112134
1221212135 ir_build_test_err_from(&ira->new_irb, &instruction->base, value);
1221312136 return ira->codegen->builtin_types.entry_bool;
12214 } else if (canon_type->id == TypeTableEntryIdPureError) {
12137 } else if (type_entry->id == TypeTableEntryIdPureError) {
1221512138 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
1221612139 out_val->data.x_bool = true;
1221712140 return ira->codegen->builtin_types.entry_bool;
......@@ -12233,11 +12156,10 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
1223312156 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
1223412157 assert(ptr_type->id == TypeTableEntryIdPointer);
1223512158
12236 TypeTableEntry *non_canon_type = ptr_type->data.pointer.child_type;
12237 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);
12238 if (type_is_invalid(canon_type)) {
12159 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
12160 if (type_is_invalid(type_entry)) {
1223912161 return ira->codegen->builtin_types.entry_invalid;
12240 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
12162 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {
1224112163 if (instr_is_comptime(value)) {
1224212164 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
1224312165 if (!ptr_val)
......@@ -12257,8 +12179,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
1225712179 return ira->codegen->builtin_types.entry_pure_error;
1225812180 } else {
1225912181 ir_add_error(ira, value,
12260 buf_sprintf("expected error union type, found '%s'", buf_ptr(&non_canon_type->name)));
12261 // TODO if this is a typedecl, add error note showing the declaration of the type decl
12182 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
1226212183 return ira->codegen->builtin_types.entry_invalid;
1226312184 }
1226412185}
......@@ -12275,12 +12196,11 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1227512196 // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing.
1227612197 assert(ptr_type->id == TypeTableEntryIdPointer);
1227712198
12278 TypeTableEntry *non_canon_type = ptr_type->data.pointer.child_type;
12279 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);
12280 if (type_is_invalid(canon_type)) {
12199 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
12200 if (type_is_invalid(type_entry)) {
1228112201 return ira->codegen->builtin_types.entry_invalid;
12282 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
12283 TypeTableEntry *child_type = canon_type->data.error.child_type;
12202 } else if (type_entry->id == TypeTableEntryIdErrorUnion) {
12203 TypeTableEntry *child_type = type_entry->data.error.child_type;
1228412204 TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, child_type,
1228512205 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, 0, 0);
1228612206 if (instr_is_comptime(value)) {
......@@ -12307,8 +12227,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1230712227 return result_type;
1230812228 } else {
1230912229 ir_add_error(ira, value,
12310 buf_sprintf("expected error union type, found '%s'", buf_ptr(&non_canon_type->name)));
12311 // TODO if this is a typedecl, add error note showing the declaration of the type decl
12230 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
1231212231 return ira->codegen->builtin_types.entry_invalid;
1231312232 }
1231412233
......@@ -12594,22 +12513,6 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira,
1259412513 return ref_instruction->value.type;
1259512514 }
1259612515 }
12597 case TldIdTypeDef:
12598 {
12599 TldTypeDef *tld_typedef = (TldTypeDef *)tld;
12600 TypeTableEntry *typedef_type = tld_typedef->type_entry;
12601
12602 IrInstruction *ref_instruction = ir_create_const_type(&ira->new_irb, instruction->base.scope,
12603 instruction->base.source_node, typedef_type);
12604 if (lval.is_ptr) {
12605 IrInstruction *ptr_inst = ir_get_ref(ira, &instruction->base, ref_instruction, true, false);
12606 ir_link_new_instruction(ptr_inst, &instruction->base);
12607 return ptr_inst->value.type;
12608 } else {
12609 ir_link_new_instruction(ref_instruction, &instruction->base);
12610 return ref_instruction->value.type;
12611 }
12612 }
1261312516 }
1261412517 zig_unreachable();
1261512518}
src/parseh.cpp+16-57
......@@ -219,28 +219,8 @@ static Tld *add_container_tld(Context *c, TypeTableEntry *type_entry) {
219219 return add_const_type(c, &type_entry->name, type_entry);
220220}
221221
222static Tld *add_typedef_tld(Context *c, TypeTableEntry *type_decl) {
223 assert(type_decl);
224 assert(type_decl->id == TypeTableEntryIdTypeDecl);
225
226 TldTypeDef *tld_typedef = allocate<TldTypeDef>(1);
227 parseh_init_tld(c, &tld_typedef->base, TldIdTypeDef, &type_decl->name);
228 tld_typedef->type_entry = type_decl;
229
230 add_global(c, &tld_typedef->base);
231 c->global_type_table.put(&type_decl->name, type_decl);
232
233 return &tld_typedef->base;
234}
235
236222static bool is_c_void_type(Context *c, TypeTableEntry *type_entry) {
237 while (type_entry->id == TypeTableEntryIdTypeDecl) {
238 if (type_entry == c->codegen->builtin_types.entry_c_void) {
239 return true;
240 }
241 type_entry = type_entry->data.type_decl.child_type;
242 }
243 return false;
223 return (type_entry == c->codegen->builtin_types.entry_c_void);
244224}
245225
246226static bool qual_type_child_is_fn_proto(const QualType &qt) {
......@@ -369,7 +349,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
369349 const PointerType *pointer_ty = static_cast<const PointerType*>(ty);
370350 QualType child_qt = pointer_ty->getPointeeType();
371351 TypeTableEntry *child_type = resolve_qual_type(c, child_qt, decl);
372 if (get_underlying_type(child_type)->id == TypeTableEntryIdInvalid) {
352 if (type_is_invalid(child_type)) {
373353 emit_warning(c, decl, "pointer to unresolved type");
374354 return c->codegen->builtin_types.entry_invalid;
375355 }
......@@ -410,7 +390,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
410390 } else {
411391 auto entry = type_table->maybe_get(type_name);
412392 if (entry) {
413 if (get_underlying_type(entry->value)->id == TypeTableEntryIdInvalid) {
393 if (type_is_invalid(entry->value)) {
414394 return c->codegen->builtin_types.entry_invalid;
415395 } else {
416396 return entry->value;
......@@ -507,7 +487,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
507487 fn_type_id.return_type = c->codegen->builtin_types.entry_unreachable;
508488 } else {
509489 fn_type_id.return_type = resolve_qual_type(c, fn_proto_ty->getReturnType(), decl);
510 if (get_underlying_type(fn_type_id.return_type)->id == TypeTableEntryIdInvalid) {
490 if (type_is_invalid(fn_type_id.return_type)) {
511491 emit_warning(c, decl, "unresolved function proto return type");
512492 return c->codegen->builtin_types.entry_invalid;
513493 }
......@@ -522,7 +502,7 @@ static TypeTableEntry *resolve_type_with_table(Context *c, const Type *ty, const
522502 QualType qt = fn_proto_ty->getParamType(i);
523503 TypeTableEntry *param_type = resolve_qual_type(c, qt, decl);
524504
525 if (get_underlying_type(param_type)->id == TypeTableEntryIdInvalid) {
505 if (type_is_invalid(param_type)) {
526506 emit_warning(c, decl, "unresolved function proto parameter type");
527507 return c->codegen->builtin_types.entry_invalid;
528508 }
......@@ -702,6 +682,7 @@ static void replace_with_fwd_decl(Context *c, TypeTableEntry *struct_type, Buf *
702682
703683 ZigLLVMReplaceTemporary(c->codegen->dbuilder, struct_type->di_type, replacement_di_type);
704684 struct_type->di_type = replacement_di_type;
685 struct_type->id = TypeTableEntryIdOpaque;
705686}
706687
707688static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) {
......@@ -809,7 +790,9 @@ static TypeTableEntry *resolve_enum_decl(Context *c, const EnumDecl *enum_decl)
809790
810791 return enum_type;
811792 } else {
812 TypeTableEntry *enum_type = get_typedecl_type(c->codegen, buf_ptr(full_type_name), tag_type_entry);
793 // TODO after issue #305 is solved, make this be an enum with tag_type_entry
794 // as the integer type and set the custom enum values
795 TypeTableEntry *enum_type = tag_type_entry;
813796 c->enum_type_table.put(bare_name, enum_type);
814797 c->decl_table.put(enum_decl, enum_type);
815798
......@@ -847,22 +830,8 @@ static void visit_enum_decl(Context *c, const EnumDecl *enum_decl) {
847830
848831 Buf *bare_name = buf_create_from_str(decl_name(enum_decl));
849832
850 if (enum_type->id == TypeTableEntryIdEnum) {
851 if (enum_type->data.enumeration.complete) {
852 Tld *tld = add_container_tld(c, enum_type);
853 add_global_weak_alias(c, bare_name, tld);
854 } else {
855 TypeTableEntry *typedecl_type = get_typedecl_type(c->codegen, buf_ptr(&enum_type->name),
856 c->codegen->builtin_types.entry_u8);
857 Tld *tld = add_typedef_tld(c, typedecl_type);
858 add_global_weak_alias(c, bare_name, tld);
859 }
860 } else if (enum_type->id == TypeTableEntryIdTypeDecl) {
861 Tld *tld = add_typedef_tld(c, enum_type);
862 add_global_weak_alias(c, bare_name, tld);
863 } else {
864 zig_unreachable();
865 }
833 Tld *tld = add_container_tld(c, enum_type);
834 add_global_weak_alias(c, bare_name, tld);
866835}
867836
868837static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_decl) {
......@@ -912,7 +881,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
912881 const FieldDecl *field_decl = *it;
913882
914883 if (field_decl->isBitField()) {
915 emit_warning(c, field_decl, "struct %s demoted to typedef - has bitfield\n", buf_ptr(bare_name));
884 emit_warning(c, field_decl, "struct %s demoted to opaque type - has bitfield\n", buf_ptr(bare_name));
916885 replace_with_fwd_decl(c, struct_type, full_type_name);
917886 return struct_type;
918887 }
......@@ -939,7 +908,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
939908 type_struct_field->type_entry = field_type;
940909
941910 if (type_is_invalid(field_type) || !type_is_complete(field_type)) {
942 emit_warning(c, field_decl, "struct %s demoted to typedef - unresolved type\n", buf_ptr(bare_name));
911 emit_warning(c, field_decl, "struct %s demoted to opaque type - unresolved type\n", buf_ptr(bare_name));
943912 replace_with_fwd_decl(c, struct_type, full_type_name);
944913 return struct_type;
945914 }
......@@ -1001,23 +970,14 @@ static void visit_record_decl(Context *c, const RecordDecl *record_decl) {
1001970 return;
1002971 }
1003972
1004 assert(struct_type->id == TypeTableEntryIdStruct);
1005
1006973 bool is_anonymous = (record_decl->isAnonymousStructOrUnion() || decl_name(record_decl)[0] == 0);
1007974 if (is_anonymous)
1008975 return;
1009976
1010977 Buf *bare_name = buf_create_from_str(decl_name(record_decl));
1011978
1012 if (struct_type->data.structure.complete) {
1013 Tld *tld = add_container_tld(c, struct_type);
1014 add_global_weak_alias(c, bare_name, tld);
1015 } else {
1016 TypeTableEntry *typedecl_type = get_typedecl_type(c->codegen, buf_ptr(&struct_type->name),
1017 c->codegen->builtin_types.entry_u8);
1018 Tld *tld = add_typedef_tld(c, typedecl_type);
1019 add_global_weak_alias(c, bare_name, tld);
1020 }
979 Tld *tld = add_container_tld(c, struct_type);
980 add_global_weak_alias(c, bare_name, tld);
1021981}
1022982
1023983static void visit_var_decl(Context *c, const VarDecl *var_decl) {
......@@ -1059,8 +1019,7 @@ static void visit_var_decl(Context *c, const VarDecl *var_decl) {
10591019 switch (ap_value->getKind()) {
10601020 case APValue::Int:
10611021 {
1062 TypeTableEntry *canon_type = get_underlying_type(var_type);
1063 if (canon_type->id != TypeTableEntryIdInt) {
1022 if (var_type->id != TypeTableEntryIdInt) {
10641023 emit_warning(c, var_decl,
10651024 "ignoring variable '%s' - int initializer for non int type\n", buf_ptr(name));
10661025 return;
src/parser.cpp+2-43
......@@ -710,7 +710,7 @@ static AstNode *ast_parse_try_expr(ParseContext *pc, size_t *token_index, bool m
710710
711711/*
712712PrimaryExpression = Number | String | CharLiteral | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | (option("extern") FnProto) | AsmExpression | ("error" "." Symbol) | ContainerDecl
713KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "type" | "this" | "unreachable"
713KeywordLiteral = "true" | "false" | "null" | "break" | "continue" | "undefined" | "error" | "this" | "unreachable"
714714*/
715715static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
716716 Token *token = &pc->tokens->at(*token_index);
......@@ -766,10 +766,6 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
766766 AstNode *node = ast_create_node(pc, NodeTypeUnreachable, token);
767767 *token_index += 1;
768768 return node;
769 } else if (token->id == TokenIdKeywordType) {
770 AstNode *node = ast_create_node(pc, NodeTypeTypeLiteral, token);
771 *token_index += 1;
772 return node;
773769 } else if (token->id == TokenIdKeywordError) {
774770 AstNode *node = ast_create_node(pc, NodeTypeErrorType, token);
775771 *token_index += 1;
......@@ -2500,34 +2496,9 @@ static AstNode *ast_parse_test_decl_node(ParseContext *pc, size_t *token_index)
25002496 return node;
25012497}
25022498
2503/*
2504TypeDecl = "type" "Symbol" "=" TypeExpr ";"
2505*/
2506static AstNode *ast_parse_type_decl(ParseContext *pc, size_t *token_index, VisibMod visib_mod) {
2507 Token *first_token = &pc->tokens->at(*token_index);
2508
2509 if (first_token->id != TokenIdKeywordType) {
2510 return nullptr;
2511 }
2512 *token_index += 1;
2513
2514 Token *name_tok = ast_eat_token(pc, token_index, TokenIdSymbol);
2515 ast_eat_token(pc, token_index, TokenIdEq);
2516
2517 AstNode *node = ast_create_node(pc, NodeTypeTypeDecl, first_token);
2518 node->data.type_decl.symbol = token_buf(name_tok);
2519 node->data.type_decl.child_type = ast_parse_type_expr(pc, token_index, true);
2520
2521 ast_eat_token(pc, token_index, TokenIdSemicolon);
2522
2523 node->data.type_decl.visib_mod = visib_mod;
2524
2525 return node;
2526}
2527
25282499/*
25292500TopLevelItem = ErrorValueDecl | CompTimeExpression(Block) | TopLevelDecl | TestDecl
2530TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | TypeDecl | UseDecl)
2501TopLevelDecl = option(VisibleMod) (FnDef | ExternDecl | GlobalVarDecl | UseDecl)
25312502*/
25322503static void ast_parse_top_level_decls(ParseContext *pc, size_t *token_index, ZigList<AstNode *> *top_level_decls) {
25332504 for (;;) {
......@@ -2586,12 +2557,6 @@ static void ast_parse_top_level_decls(ParseContext *pc, size_t *token_index, Zig
25862557 continue;
25872558 }
25882559
2589 AstNode *type_decl_node = ast_parse_type_decl(pc, token_index, visib_mod);
2590 if (type_decl_node) {
2591 top_level_decls->append(type_decl_node);
2592 continue;
2593 }
2594
25952560 return;
25962561 }
25972562 zig_unreachable();
......@@ -2674,9 +2639,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
26742639 visit_field(&node->data.variable_declaration.type, visit, context);
26752640 visit_field(&node->data.variable_declaration.expr, visit, context);
26762641 break;
2677 case NodeTypeTypeDecl:
2678 visit_field(&node->data.type_decl.child_type, visit, context);
2679 break;
26802642 case NodeTypeErrorValueDecl:
26812643 // none
26822644 break;
......@@ -2826,9 +2788,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
28262788 case NodeTypeErrorType:
28272789 // none
28282790 break;
2829 case NodeTypeTypeLiteral:
2830 // none
2831 break;
28322791 case NodeTypeVarLiteral:
28332792 // none
28342793 break;
src/tokenizer.cpp-2
......@@ -139,7 +139,6 @@ static const struct ZigKeyword zig_keywords[] = {
139139 {"this", TokenIdKeywordThis},
140140 {"true", TokenIdKeywordTrue},
141141 {"try", TokenIdKeywordTry},
142 {"type", TokenIdKeywordType},
143142 {"undefined", TokenIdKeywordUndefined},
144143 {"union", TokenIdKeywordUnion},
145144 {"unreachable", TokenIdKeywordUnreachable},
......@@ -1474,7 +1473,6 @@ const char * token_name(TokenId id) {
14741473 case TokenIdKeywordThis: return "this";
14751474 case TokenIdKeywordTrue: return "true";
14761475 case TokenIdKeywordTry: return "try";
1477 case TokenIdKeywordType: return "type";
14781476 case TokenIdKeywordUndefined: return "undefined";
14791477 case TokenIdKeywordUnion: return "union";
14801478 case TokenIdKeywordUnreachable: return "unreachable";
src/tokenizer.hpp-1
......@@ -76,7 +76,6 @@ enum TokenId {
7676 TokenIdKeywordThis,
7777 TokenIdKeywordTrue,
7878 TokenIdKeywordTry,
79 TokenIdKeywordType,
8079 TokenIdKeywordUndefined,
8180 TokenIdKeywordUnion,
8281 TokenIdKeywordUnreachable,
test/cases/typedef.zig deleted-10
......@@ -1,10 +0,0 @@
1const assert = @import("std").debug.assert;
2
3type int = u8;
4
5fn add(a: int, b: int) -> int {
6 a + b
7}
8test "typedef" {
9 assert(add(12, 34) == 46);
10}
test/run_tests.cpp+4-4
......@@ -2191,7 +2191,7 @@ struct Foo {
21912191 add_parseh_case("struct prototype used in func", AllowWarningsNo, R"SOURCE(
21922192struct Foo;
21932193struct Foo *some_func(struct Foo *foo, int x);
2194 )SOURCE", 3, R"OUTPUT(pub type struct_Foo = u8;)OUTPUT",
2194 )SOURCE", 3, R"OUTPUT(pub const struct_Foo = @OpaqueType();)OUTPUT",
21952195 R"OUTPUT(pub extern fn some_func(foo: ?&struct_Foo, x: c_int) -> ?&struct_Foo;)OUTPUT",
21962196 R"OUTPUT(pub const Foo = struct_Foo;)OUTPUT");
21972197
......@@ -2277,12 +2277,12 @@ void foo(void (__cdecl *fn_ptr)(void));
22772277 )SOURCE", 1, "pub const SDL_INIT_VIDEO = 32;");
22782278
22792279 add_parseh_case("zig keywords in C code", AllowWarningsNo, R"SOURCE(
2280struct type {
2280struct comptime {
22812281 int defer;
22822282};
2283 )SOURCE", 2, R"(pub const struct_type = extern struct {
2283 )SOURCE", 2, R"(pub const struct_comptime = extern struct {
22842284 @"defer": c_int,
2285};)", R"(pub const @"type" = struct_type;)");
2285};)", R"(pub const @"comptime" = struct_comptime;)");
22862286
22872287 add_parseh_case("macro defines string literal with octal", AllowWarningsNo, R"SOURCE(
22882288#define FOO "aoeu\023 derp"
test/self_hosted.zig-1
......@@ -31,7 +31,6 @@ comptime {
3131 _ = @import("cases/switch_prong_implicit_cast.zig");
3232 _ = @import("cases/this.zig");
3333 _ = @import("cases/try.zig");
34 _ = @import("cases/typedef.zig");
3534 _ = @import("cases/undefined.zig");
3635 _ = @import("cases/var_args.zig");
3736 _ = @import("cases/void.zig");