| author | |
| committer | |
| log | eff3530dfab5ecb4e480e0516ed57a8f564543f5 |
| tree | 6d407f8f334e1910e0ae6ea16190aa9c3e5de016 |
| parent | 44ae891bd79cc8b2f9040a39c176317ebf4a4ef8 |
closes #7798 files changed, 116 insertions(+), 154 deletions(-)
doc/langref.html.in+3-3| ... | ... | @@ -5733,19 +5733,19 @@ UseDecl = "use" Expression ";" |
| 5733 | 5733 | |
| 5734 | 5734 | ExternDecl = "extern" option(String) (FnProto | VariableDeclaration) ";" |
| 5735 | 5735 | |
| 5736 | FnProto = option("nakedcc" | "stdcallcc" | "extern" | ("async" option("(" Expression ")"))) "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("!") TypeExpr | |
| 5736 | FnProto = option("nakedcc" | "stdcallcc" | "extern" | ("async" option("(" Expression ")"))) "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("!") (TypeExpr | "var") | |
| 5737 | 5737 | |
| 5738 | 5738 | FnDef = option("inline" | "export") FnProto Block |
| 5739 | 5739 | |
| 5740 | 5740 | ParamDeclList = "(" list(ParamDecl, ",") ")" |
| 5741 | 5741 | |
| 5742 | ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "...") | |
| 5742 | ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "var" | "...") | |
| 5743 | 5743 | |
| 5744 | 5744 | Block = option(Symbol ":") "{" many(Statement) "}" |
| 5745 | 5745 | |
| 5746 | 5746 | Statement = LocalVarDecl ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";" |
| 5747 | 5747 | |
| 5748 | TypeExpr = ErrorSetExpr | "var" | |
| 5748 | TypeExpr = ErrorSetExpr | |
| 5749 | 5749 | |
| 5750 | 5750 | ErrorSetExpr = (PrefixOpExpression "!" PrefixOpExpression) | PrefixOpExpression |
| 5751 | 5751 |
src/all_types.hpp+3-6| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | #include "bigint.hpp" |
| 17 | 17 | #include "bigfloat.hpp" |
| 18 | 18 | #include "target.hpp" |
| 19 | #include "tokenizer.hpp" | |
| 19 | 20 | |
| 20 | 21 | struct AstNode; |
| 21 | 22 | struct ImportTableEntry; |
| ... | ... | @@ -399,7 +400,6 @@ enum NodeType { |
| 399 | 400 | NodeTypeStructValueField, |
| 400 | 401 | NodeTypeArrayType, |
| 401 | 402 | NodeTypeErrorType, |
| 402 | NodeTypeVarLiteral, | |
| 403 | 403 | NodeTypeIfErrorExpr, |
| 404 | 404 | NodeTypeTestExpr, |
| 405 | 405 | NodeTypeErrorSetDecl, |
| ... | ... | @@ -427,6 +427,7 @@ struct AstNodeFnProto { |
| 427 | 427 | Buf *name; |
| 428 | 428 | ZigList<AstNode *> params; |
| 429 | 429 | AstNode *return_type; |
| 430 | Token *return_var_token; | |
| 430 | 431 | bool is_var_args; |
| 431 | 432 | bool is_extern; |
| 432 | 433 | bool is_export; |
| ... | ... | @@ -456,6 +457,7 @@ struct AstNodeFnDecl { |
| 456 | 457 | struct AstNodeParamDecl { |
| 457 | 458 | Buf *name; |
| 458 | 459 | AstNode *type; |
| 460 | Token *var_token; | |
| 459 | 461 | bool is_noalias; |
| 460 | 462 | bool is_inline; |
| 461 | 463 | bool is_var_args; |
| ... | ... | @@ -866,9 +868,6 @@ struct AstNodeUnreachableExpr { |
| 866 | 868 | struct AstNodeErrorType { |
| 867 | 869 | }; |
| 868 | 870 | |
| 869 | struct AstNodeVarLiteral { | |
| 870 | }; | |
| 871 | ||
| 872 | 871 | struct AstNodeAwaitExpr { |
| 873 | 872 | AstNode *expr; |
| 874 | 873 | }; |
| ... | ... | @@ -933,7 +932,6 @@ struct AstNode { |
| 933 | 932 | AstNodeUnreachableExpr unreachable_expr; |
| 934 | 933 | AstNodeArrayType array_type; |
| 935 | 934 | AstNodeErrorType error_type; |
| 936 | AstNodeVarLiteral var_literal; | |
| 937 | 935 | AstNodeErrorSetDecl err_set_decl; |
| 938 | 936 | AstNodeCancelExpr cancel_expr; |
| 939 | 937 | AstNodeResumeExpr resume_expr; |
| ... | ... | @@ -1134,7 +1132,6 @@ struct TypeTableEntryPromise { |
| 1134 | 1132 | |
| 1135 | 1133 | enum TypeTableEntryId { |
| 1136 | 1134 | TypeTableEntryIdInvalid, |
| 1137 | TypeTableEntryIdVar, | |
| 1138 | 1135 | TypeTableEntryIdMetaType, |
| 1139 | 1136 | TypeTableEntryIdVoid, |
| 1140 | 1137 | TypeTableEntryIdBool, |
src/analyze.cpp+18-28| ... | ... | @@ -200,7 +200,6 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) { |
| 200 | 200 | bool type_is_complete(TypeTableEntry *type_entry) { |
| 201 | 201 | switch (type_entry->id) { |
| 202 | 202 | case TypeTableEntryIdInvalid: |
| 203 | case TypeTableEntryIdVar: | |
| 204 | 203 | zig_unreachable(); |
| 205 | 204 | case TypeTableEntryIdStruct: |
| 206 | 205 | return type_entry->data.structure.complete; |
| ... | ... | @@ -239,7 +238,6 @@ bool type_is_complete(TypeTableEntry *type_entry) { |
| 239 | 238 | bool type_has_zero_bits_known(TypeTableEntry *type_entry) { |
| 240 | 239 | switch (type_entry->id) { |
| 241 | 240 | case TypeTableEntryIdInvalid: |
| 242 | case TypeTableEntryIdVar: | |
| 243 | 241 | zig_unreachable(); |
| 244 | 242 | case TypeTableEntryIdStruct: |
| 245 | 243 | return type_entry->data.structure.zero_bits_known; |
| ... | ... | @@ -1281,7 +1279,6 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf ** |
| 1281 | 1279 | static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { |
| 1282 | 1280 | switch (type_entry->id) { |
| 1283 | 1281 | case TypeTableEntryIdInvalid: |
| 1284 | case TypeTableEntryIdVar: | |
| 1285 | 1282 | zig_unreachable(); |
| 1286 | 1283 | case TypeTableEntryIdMetaType: |
| 1287 | 1284 | case TypeTableEntryIdUnreachable: |
| ... | ... | @@ -1324,7 +1321,6 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { |
| 1324 | 1321 | static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) { |
| 1325 | 1322 | switch (type_entry->id) { |
| 1326 | 1323 | case TypeTableEntryIdInvalid: |
| 1327 | case TypeTableEntryIdVar: | |
| 1328 | 1324 | zig_unreachable(); |
| 1329 | 1325 | case TypeTableEntryIdMetaType: |
| 1330 | 1326 | case TypeTableEntryIdNumLitFloat: |
| ... | ... | @@ -1428,6 +1424,14 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1428 | 1424 | calling_convention_name(fn_type_id.cc))); |
| 1429 | 1425 | return g->builtin_types.entry_invalid; |
| 1430 | 1426 | } |
| 1427 | } else if (param_node->data.param_decl.var_token != nullptr) { | |
| 1428 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { | |
| 1429 | add_node_error(g, param_node->data.param_decl.type, | |
| 1430 | buf_sprintf("parameter of type 'var' not allowed in function with calling convention '%s'", | |
| 1431 | calling_convention_name(fn_type_id.cc))); | |
| 1432 | return g->builtin_types.entry_invalid; | |
| 1433 | } | |
| 1434 | return get_generic_fn_type(g, &fn_type_id); | |
| 1431 | 1435 | } |
| 1432 | 1436 | |
| 1433 | 1437 | TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type); |
| ... | ... | @@ -1463,14 +1467,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1463 | 1467 | add_node_error(g, param_node->data.param_decl.type, |
| 1464 | 1468 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); |
| 1465 | 1469 | return g->builtin_types.entry_invalid; |
| 1466 | case TypeTableEntryIdVar: | |
| 1467 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { | |
| 1468 | add_node_error(g, param_node->data.param_decl.type, | |
| 1469 | buf_sprintf("parameter of type 'var' not allowed in function with calling convention '%s'", | |
| 1470 | calling_convention_name(fn_type_id.cc))); | |
| 1471 | return g->builtin_types.entry_invalid; | |
| 1472 | } | |
| 1473 | return get_generic_fn_type(g, &fn_type_id); | |
| 1474 | 1470 | case TypeTableEntryIdNumLitFloat: |
| 1475 | 1471 | case TypeTableEntryIdNumLitInt: |
| 1476 | 1472 | case TypeTableEntryIdNamespace: |
| ... | ... | @@ -1527,6 +1523,16 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1527 | 1523 | fn_type_id.return_type = specified_return_type; |
| 1528 | 1524 | } |
| 1529 | 1525 | |
| 1526 | if (fn_proto->return_var_token != nullptr) { | |
| 1527 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { | |
| 1528 | add_node_error(g, fn_proto->return_type, | |
| 1529 | buf_sprintf("return type 'var' not allowed in function with calling convention '%s'", | |
| 1530 | calling_convention_name(fn_type_id.cc))); | |
| 1531 | return g->builtin_types.entry_invalid; | |
| 1532 | } | |
| 1533 | return get_generic_fn_type(g, &fn_type_id); | |
| 1534 | } | |
| 1535 | ||
| 1530 | 1536 | if (!calling_convention_allows_zig_types(fn_type_id.cc) && !type_allowed_in_extern(g, fn_type_id.return_type)) { |
| 1531 | 1537 | add_node_error(g, fn_proto->return_type, |
| 1532 | 1538 | buf_sprintf("return type '%s' not allowed in function with calling convention '%s'", |
| ... | ... | @@ -1552,7 +1558,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1552 | 1558 | case TypeTableEntryIdNamespace: |
| 1553 | 1559 | case TypeTableEntryIdBlock: |
| 1554 | 1560 | case TypeTableEntryIdBoundFn: |
| 1555 | case TypeTableEntryIdVar: | |
| 1556 | 1561 | case TypeTableEntryIdMetaType: |
| 1557 | 1562 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1558 | 1563 | add_node_error(g, fn_proto->return_type, |
| ... | ... | @@ -3226,7 +3231,6 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 3226 | 3231 | case NodeTypeStructValueField: |
| 3227 | 3232 | case NodeTypeArrayType: |
| 3228 | 3233 | case NodeTypeErrorType: |
| 3229 | case NodeTypeVarLiteral: | |
| 3230 | 3234 | case NodeTypeIfErrorExpr: |
| 3231 | 3235 | case NodeTypeTestExpr: |
| 3232 | 3236 | case NodeTypeErrorSetDecl: |
| ... | ... | @@ -3262,7 +3266,6 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt |
| 3262 | 3266 | case TypeTableEntryIdInvalid: |
| 3263 | 3267 | return g->builtin_types.entry_invalid; |
| 3264 | 3268 | case TypeTableEntryIdUnreachable: |
| 3265 | case TypeTableEntryIdVar: | |
| 3266 | 3269 | case TypeTableEntryIdNumLitFloat: |
| 3267 | 3270 | case TypeTableEntryIdNumLitInt: |
| 3268 | 3271 | case TypeTableEntryIdUndefLit: |
| ... | ... | @@ -3641,7 +3644,6 @@ TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *t |
| 3641 | 3644 | static bool is_container(TypeTableEntry *type_entry) { |
| 3642 | 3645 | switch (type_entry->id) { |
| 3643 | 3646 | case TypeTableEntryIdInvalid: |
| 3644 | case TypeTableEntryIdVar: | |
| 3645 | 3647 | zig_unreachable(); |
| 3646 | 3648 | case TypeTableEntryIdStruct: |
| 3647 | 3649 | case TypeTableEntryIdEnum: |
| ... | ... | @@ -3716,7 +3718,6 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) { |
| 3716 | 3718 | case TypeTableEntryIdBlock: |
| 3717 | 3719 | case TypeTableEntryIdBoundFn: |
| 3718 | 3720 | case TypeTableEntryIdInvalid: |
| 3719 | case TypeTableEntryIdVar: | |
| 3720 | 3721 | case TypeTableEntryIdArgTuple: |
| 3721 | 3722 | case TypeTableEntryIdOpaque: |
| 3722 | 3723 | case TypeTableEntryIdPromise: |
| ... | ... | @@ -4216,7 +4217,6 @@ bool handle_is_ptr(TypeTableEntry *type_entry) { |
| 4216 | 4217 | case TypeTableEntryIdNamespace: |
| 4217 | 4218 | case TypeTableEntryIdBlock: |
| 4218 | 4219 | case TypeTableEntryIdBoundFn: |
| 4219 | case TypeTableEntryIdVar: | |
| 4220 | 4220 | case TypeTableEntryIdArgTuple: |
| 4221 | 4221 | case TypeTableEntryIdOpaque: |
| 4222 | 4222 | zig_unreachable(); |
| ... | ... | @@ -4515,7 +4515,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { |
| 4515 | 4515 | case TypeTableEntryIdBoundFn: |
| 4516 | 4516 | case TypeTableEntryIdInvalid: |
| 4517 | 4517 | case TypeTableEntryIdUnreachable: |
| 4518 | case TypeTableEntryIdVar: | |
| 4519 | 4518 | zig_unreachable(); |
| 4520 | 4519 | } |
| 4521 | 4520 | zig_unreachable(); |
| ... | ... | @@ -4613,7 +4612,6 @@ bool type_has_bits(TypeTableEntry *type_entry) { |
| 4613 | 4612 | bool type_requires_comptime(TypeTableEntry *type_entry) { |
| 4614 | 4613 | switch (type_entry->id) { |
| 4615 | 4614 | case TypeTableEntryIdInvalid: |
| 4616 | case TypeTableEntryIdVar: | |
| 4617 | 4615 | case TypeTableEntryIdOpaque: |
| 4618 | 4616 | zig_unreachable(); |
| 4619 | 4617 | case TypeTableEntryIdNumLitFloat: |
| ... | ... | @@ -5109,7 +5107,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { |
| 5109 | 5107 | case TypeTableEntryIdBoundFn: |
| 5110 | 5108 | case TypeTableEntryIdInvalid: |
| 5111 | 5109 | case TypeTableEntryIdUnreachable: |
| 5112 | case TypeTableEntryIdVar: | |
| 5113 | 5110 | case TypeTableEntryIdPromise: |
| 5114 | 5111 | zig_unreachable(); |
| 5115 | 5112 | } |
| ... | ... | @@ -5189,9 +5186,6 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 5189 | 5186 | case TypeTableEntryIdInvalid: |
| 5190 | 5187 | buf_appendf(buf, "(invalid)"); |
| 5191 | 5188 | return; |
| 5192 | case TypeTableEntryIdVar: | |
| 5193 | buf_appendf(buf, "(var)"); | |
| 5194 | return; | |
| 5195 | 5189 | case TypeTableEntryIdVoid: |
| 5196 | 5190 | buf_appendf(buf, "{}"); |
| 5197 | 5191 | return; |
| ... | ... | @@ -5427,7 +5421,6 @@ TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) |
| 5427 | 5421 | uint32_t type_id_hash(TypeId x) { |
| 5428 | 5422 | switch (x.id) { |
| 5429 | 5423 | case TypeTableEntryIdInvalid: |
| 5430 | case TypeTableEntryIdVar: | |
| 5431 | 5424 | case TypeTableEntryIdOpaque: |
| 5432 | 5425 | case TypeTableEntryIdMetaType: |
| 5433 | 5426 | case TypeTableEntryIdVoid: |
| ... | ... | @@ -5474,7 +5467,6 @@ bool type_id_eql(TypeId a, TypeId b) { |
| 5474 | 5467 | return false; |
| 5475 | 5468 | switch (a.id) { |
| 5476 | 5469 | case TypeTableEntryIdInvalid: |
| 5477 | case TypeTableEntryIdVar: | |
| 5478 | 5470 | case TypeTableEntryIdMetaType: |
| 5479 | 5471 | case TypeTableEntryIdVoid: |
| 5480 | 5472 | case TypeTableEntryIdBool: |
| ... | ... | @@ -5629,7 +5621,6 @@ size_t type_id_len() { |
| 5629 | 5621 | size_t type_id_index(TypeTableEntryId id) { |
| 5630 | 5622 | switch (id) { |
| 5631 | 5623 | case TypeTableEntryIdInvalid: |
| 5632 | case TypeTableEntryIdVar: | |
| 5633 | 5624 | zig_unreachable(); |
| 5634 | 5625 | case TypeTableEntryIdMetaType: |
| 5635 | 5626 | return 0; |
| ... | ... | @@ -5688,7 +5679,6 @@ size_t type_id_index(TypeTableEntryId id) { |
| 5688 | 5679 | const char *type_id_name(TypeTableEntryId id) { |
| 5689 | 5680 | switch (id) { |
| 5690 | 5681 | case TypeTableEntryIdInvalid: |
| 5691 | case TypeTableEntryIdVar: | |
| 5692 | 5682 | zig_unreachable(); |
| 5693 | 5683 | case TypeTableEntryIdMetaType: |
| 5694 | 5684 | return "Type"; |
src/ast_render.cpp+12-11| ... | ... | @@ -236,8 +236,6 @@ static const char *node_type_str(NodeType node_type) { |
| 236 | 236 | return "ArrayType"; |
| 237 | 237 | case NodeTypeErrorType: |
| 238 | 238 | return "ErrorType"; |
| 239 | case NodeTypeVarLiteral: | |
| 240 | return "VarLiteral"; | |
| 241 | 239 | case NodeTypeIfErrorExpr: |
| 242 | 240 | return "IfErrorExpr"; |
| 243 | 241 | case NodeTypeTestExpr: |
| ... | ... | @@ -436,6 +434,8 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 436 | 434 | } |
| 437 | 435 | if (param_decl->data.param_decl.is_var_args) { |
| 438 | 436 | fprintf(ar->f, "..."); |
| 437 | } else if (param_decl->data.param_decl.var_token != nullptr) { | |
| 438 | fprintf(ar->f, "var"); | |
| 439 | 439 | } else { |
| 440 | 440 | render_node_grouped(ar, param_decl->data.param_decl.type); |
| 441 | 441 | } |
| ... | ... | @@ -456,13 +456,17 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 456 | 456 | fprintf(ar->f, ")"); |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | AstNode *return_type_node = node->data.fn_proto.return_type; | |
| 460 | assert(return_type_node != nullptr); | |
| 461 | fprintf(ar->f, " "); | |
| 462 | if (node->data.fn_proto.auto_err_set) { | |
| 463 | fprintf(ar->f, "!"); | |
| 459 | if (node->data.fn_proto.return_var_token != nullptr) { | |
| 460 | fprintf(ar->f, "var"); | |
| 461 | } else { | |
| 462 | AstNode *return_type_node = node->data.fn_proto.return_type; | |
| 463 | assert(return_type_node != nullptr); | |
| 464 | fprintf(ar->f, " "); | |
| 465 | if (node->data.fn_proto.auto_err_set) { | |
| 466 | fprintf(ar->f, "!"); | |
| 467 | } | |
| 468 | render_node_grouped(ar, return_type_node); | |
| 464 | 469 | } |
| 465 | render_node_grouped(ar, return_type_node); | |
| 466 | 470 | break; |
| 467 | 471 | } |
| 468 | 472 | case NodeTypeFnDef: |
| ... | ... | @@ -768,9 +772,6 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 768 | 772 | case NodeTypeErrorType: |
| 769 | 773 | fprintf(ar->f, "error"); |
| 770 | 774 | break; |
| 771 | case NodeTypeVarLiteral: | |
| 772 | fprintf(ar->f, "var"); | |
| 773 | break; | |
| 774 | 775 | case NodeTypeAsmExpr: |
| 775 | 776 | { |
| 776 | 777 | AstNodeAsmExpr *asm_expr = &node->data.asm_expr; |
src/codegen.cpp-10| ... | ... | @@ -4508,7 +4508,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con |
| 4508 | 4508 | assert(!type_entry->zero_bits); |
| 4509 | 4509 | switch (type_entry->id) { |
| 4510 | 4510 | case TypeTableEntryIdInvalid: |
| 4511 | case TypeTableEntryIdVar: | |
| 4512 | 4511 | case TypeTableEntryIdMetaType: |
| 4513 | 4512 | case TypeTableEntryIdUnreachable: |
| 4514 | 4513 | case TypeTableEntryIdNumLitFloat: |
| ... | ... | @@ -4960,7 +4959,6 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c |
| 4960 | 4959 | case TypeTableEntryIdNamespace: |
| 4961 | 4960 | case TypeTableEntryIdBlock: |
| 4962 | 4961 | case TypeTableEntryIdBoundFn: |
| 4963 | case TypeTableEntryIdVar: | |
| 4964 | 4962 | case TypeTableEntryIdArgTuple: |
| 4965 | 4963 | case TypeTableEntryIdOpaque: |
| 4966 | 4964 | case TypeTableEntryIdPromise: |
| ... | ... | @@ -5611,11 +5609,6 @@ static void define_builtin_types(CodeGen *g) { |
| 5611 | 5609 | entry->zero_bits = true; |
| 5612 | 5610 | g->builtin_types.entry_null = entry; |
| 5613 | 5611 | } |
| 5614 | { | |
| 5615 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdVar); | |
| 5616 | buf_init_from_str(&entry->name, "(var)"); | |
| 5617 | g->builtin_types.entry_var = entry; | |
| 5618 | } | |
| 5619 | 5612 | { |
| 5620 | 5613 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArgTuple); |
| 5621 | 5614 | buf_init_from_str(&entry->name, "(args)"); |
| ... | ... | @@ -6444,7 +6437,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry |
| 6444 | 6437 | |
| 6445 | 6438 | switch (type_entry->id) { |
| 6446 | 6439 | case TypeTableEntryIdInvalid: |
| 6447 | case TypeTableEntryIdVar: | |
| 6448 | 6440 | case TypeTableEntryIdMetaType: |
| 6449 | 6441 | case TypeTableEntryIdNumLitFloat: |
| 6450 | 6442 | case TypeTableEntryIdNumLitInt: |
| ... | ... | @@ -6639,7 +6631,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf |
| 6639 | 6631 | case TypeTableEntryIdNumLitInt: |
| 6640 | 6632 | case TypeTableEntryIdUndefLit: |
| 6641 | 6633 | case TypeTableEntryIdNullLit: |
| 6642 | case TypeTableEntryIdVar: | |
| 6643 | 6634 | case TypeTableEntryIdArgTuple: |
| 6644 | 6635 | case TypeTableEntryIdPromise: |
| 6645 | 6636 | zig_unreachable(); |
| ... | ... | @@ -6781,7 +6772,6 @@ static void gen_h_file(CodeGen *g) { |
| 6781 | 6772 | TypeTableEntry *type_entry = gen_h->types_to_declare.at(type_i); |
| 6782 | 6773 | switch (type_entry->id) { |
| 6783 | 6774 | case TypeTableEntryIdInvalid: |
| 6784 | case TypeTableEntryIdVar: | |
| 6785 | 6775 | case TypeTableEntryIdMetaType: |
| 6786 | 6776 | case TypeTableEntryIdVoid: |
| 6787 | 6777 | case TypeTableEntryIdBool: |
src/ir.cpp+50-72| ... | ... | @@ -2147,7 +2147,7 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s |
| 2147 | 2147 | size_t param_count = source_node->data.fn_proto.params.length; |
| 2148 | 2148 | if (is_var_args) param_count -= 1; |
| 2149 | 2149 | for (size_t i = 0; i < param_count; i += 1) { |
| 2150 | ir_ref_instruction(param_types[i], irb->current_basic_block); | |
| 2150 | if (param_types[i] != nullptr) ir_ref_instruction(param_types[i], irb->current_basic_block); | |
| 2151 | 2151 | } |
| 2152 | 2152 | if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block); |
| 2153 | 2153 | ir_ref_instruction(return_type, irb->current_basic_block); |
| ... | ... | @@ -3305,12 +3305,6 @@ static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode |
| 3305 | 3305 | return ir_build_const_null(irb, scope, node); |
| 3306 | 3306 | } |
| 3307 | 3307 | |
| 3308 | static IrInstruction *ir_gen_var_literal(IrBuilder *irb, Scope *scope, AstNode *node) { | |
| 3309 | assert(node->type == NodeTypeVarLiteral); | |
| 3310 | ||
| 3311 | return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var); | |
| 3312 | } | |
| 3313 | ||
| 3314 | 3308 | static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { |
| 3315 | 3309 | assert(node->type == NodeTypeSymbol); |
| 3316 | 3310 | |
| ... | ... | @@ -5916,11 +5910,15 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5916 | 5910 | is_var_args = true; |
| 5917 | 5911 | break; |
| 5918 | 5912 | } |
| 5919 | AstNode *type_node = param_node->data.param_decl.type; | |
| 5920 | IrInstruction *type_value = ir_gen_node(irb, type_node, parent_scope); | |
| 5921 | if (type_value == irb->codegen->invalid_instruction) | |
| 5922 | return irb->codegen->invalid_instruction; | |
| 5923 | param_types[i] = type_value; | |
| 5913 | if (param_node->data.param_decl.var_token == nullptr) { | |
| 5914 | AstNode *type_node = param_node->data.param_decl.type; | |
| 5915 | IrInstruction *type_value = ir_gen_node(irb, type_node, parent_scope); | |
| 5916 | if (type_value == irb->codegen->invalid_instruction) | |
| 5917 | return irb->codegen->invalid_instruction; | |
| 5918 | param_types[i] = type_value; | |
| 5919 | } else { | |
| 5920 | param_types[i] = nullptr; | |
| 5921 | } | |
| 5924 | 5922 | } |
| 5925 | 5923 | |
| 5926 | 5924 | IrInstruction *align_value = nullptr; |
| ... | ... | @@ -5931,12 +5929,16 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5931 | 5929 | } |
| 5932 | 5930 | |
| 5933 | 5931 | IrInstruction *return_type; |
| 5934 | if (node->data.fn_proto.return_type == nullptr) { | |
| 5935 | return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void); | |
| 5932 | if (node->data.fn_proto.return_var_token == nullptr) { | |
| 5933 | if (node->data.fn_proto.return_type == nullptr) { | |
| 5934 | return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void); | |
| 5935 | } else { | |
| 5936 | return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope); | |
| 5937 | if (return_type == irb->codegen->invalid_instruction) | |
| 5938 | return irb->codegen->invalid_instruction; | |
| 5939 | } | |
| 5936 | 5940 | } else { |
| 5937 | return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope); | |
| 5938 | if (return_type == irb->codegen->invalid_instruction) | |
| 5939 | return irb->codegen->invalid_instruction; | |
| 5941 | return_type = nullptr; | |
| 5940 | 5942 | } |
| 5941 | 5943 | |
| 5942 | 5944 | return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, return_type, is_var_args); |
| ... | ... | @@ -6189,8 +6191,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 6189 | 6191 | return ir_lval_wrap(irb, scope, ir_gen_asm_expr(irb, scope, node), lval); |
| 6190 | 6192 | case NodeTypeNullLiteral: |
| 6191 | 6193 | return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval); |
| 6192 | case NodeTypeVarLiteral: | |
| 6193 | return ir_lval_wrap(irb, scope, ir_gen_var_literal(irb, scope, node), lval); | |
| 6194 | 6194 | case NodeTypeIfErrorExpr: |
| 6195 | 6195 | return ir_lval_wrap(irb, scope, ir_gen_if_err_expr(irb, scope, node), lval); |
| 6196 | 6196 | case NodeTypeTestExpr: |
| ... | ... | @@ -7515,11 +7515,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 7515 | 7515 | return ImplicitCastMatchResultReportedError; |
| 7516 | 7516 | } |
| 7517 | 7517 | |
| 7518 | // implicit conversion from anything to var | |
| 7519 | if (expected_type->id == TypeTableEntryIdVar) { | |
| 7520 | return ImplicitCastMatchResultYes; | |
| 7521 | } | |
| 7522 | ||
| 7523 | 7518 | // implicit conversion from non maybe type to maybe type |
| 7524 | 7519 | if (expected_type->id == TypeTableEntryIdMaybe && |
| 7525 | 7520 | ir_types_match_with_implicit_cast(ira, expected_type->data.maybe.child_type, actual_type, value)) |
| ... | ... | @@ -9341,9 +9336,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 9341 | 9336 | return ira->codegen->invalid_instruction; |
| 9342 | 9337 | } |
| 9343 | 9338 | |
| 9344 | if (wanted_type->id == TypeTableEntryIdVar) | |
| 9345 | return value; | |
| 9346 | ||
| 9347 | 9339 | // explicit match or non-const to const |
| 9348 | 9340 | if (types_match_const_cast_only(ira, wanted_type, actual_type, source_node).id == ConstCastResultIdOk) { |
| 9349 | 9341 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); |
| ... | ... | @@ -10311,9 +10303,6 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp |
| 10311 | 10303 | ir_add_error_node(ira, source_node, |
| 10312 | 10304 | buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name))); |
| 10313 | 10305 | return ira->codegen->builtin_types.entry_invalid; |
| 10314 | ||
| 10315 | case TypeTableEntryIdVar: | |
| 10316 | zig_unreachable(); | |
| 10317 | 10306 | } |
| 10318 | 10307 | |
| 10319 | 10308 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); |
| ... | ... | @@ -11106,7 +11095,6 @@ static VarClassRequired get_var_class_required(TypeTableEntry *type_entry) { |
| 11106 | 11095 | case TypeTableEntryIdInvalid: |
| 11107 | 11096 | zig_unreachable(); |
| 11108 | 11097 | case TypeTableEntryIdUnreachable: |
| 11109 | case TypeTableEntryIdVar: | |
| 11110 | 11098 | return VarClassRequiredIllegal; |
| 11111 | 11099 | case TypeTableEntryIdBool: |
| 11112 | 11100 | case TypeTableEntryIdInt: |
| ... | ... | @@ -11279,7 +11267,6 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 11279 | 11267 | |
| 11280 | 11268 | switch (target->value.type->id) { |
| 11281 | 11269 | case TypeTableEntryIdInvalid: |
| 11282 | case TypeTableEntryIdVar: | |
| 11283 | 11270 | case TypeTableEntryIdUnreachable: |
| 11284 | 11271 | zig_unreachable(); |
| 11285 | 11272 | case TypeTableEntryIdFn: { |
| ... | ... | @@ -11332,7 +11319,6 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 11332 | 11319 | TypeTableEntry *type_value = target->value.data.x_type; |
| 11333 | 11320 | switch (type_value->id) { |
| 11334 | 11321 | case TypeTableEntryIdInvalid: |
| 11335 | case TypeTableEntryIdVar: | |
| 11336 | 11322 | zig_unreachable(); |
| 11337 | 11323 | case TypeTableEntryIdStruct: |
| 11338 | 11324 | if (is_slice(type_value)) { |
| ... | ... | @@ -11543,14 +11529,20 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 11543 | 11529 | { |
| 11544 | 11530 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); |
| 11545 | 11531 | assert(param_decl_node->type == NodeTypeParamDecl); |
| 11546 | AstNode *param_type_node = param_decl_node->data.param_decl.type; | |
| 11547 | TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node); | |
| 11548 | if (type_is_invalid(param_type)) | |
| 11549 | return false; | |
| 11550 | 11532 | |
| 11551 | IrInstruction *casted_arg = ir_implicit_cast(ira, arg, param_type); | |
| 11552 | if (type_is_invalid(casted_arg->value.type)) | |
| 11553 | return false; | |
| 11533 | IrInstruction *casted_arg; | |
| 11534 | if (param_decl_node->data.param_decl.var_token == nullptr) { | |
| 11535 | AstNode *param_type_node = param_decl_node->data.param_decl.type; | |
| 11536 | TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node); | |
| 11537 | if (type_is_invalid(param_type)) | |
| 11538 | return false; | |
| 11539 | ||
| 11540 | casted_arg = ir_implicit_cast(ira, arg, param_type); | |
| 11541 | if (type_is_invalid(casted_arg->value.type)) | |
| 11542 | return false; | |
| 11543 | } else { | |
| 11544 | casted_arg = arg; | |
| 11545 | } | |
| 11554 | 11546 | |
| 11555 | 11547 | ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefBad); |
| 11556 | 11548 | if (!arg_val) |
| ... | ... | @@ -11579,19 +11571,18 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 11579 | 11571 | arg_part_of_generic_id = true; |
| 11580 | 11572 | casted_arg = ir_implicit_byval_const_ref_cast(ira, arg); |
| 11581 | 11573 | } else { |
| 11582 | AstNode *param_type_node = param_decl_node->data.param_decl.type; | |
| 11583 | TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node); | |
| 11584 | if (type_is_invalid(param_type)) | |
| 11585 | return false; | |
| 11574 | if (param_decl_node->data.param_decl.var_token == nullptr) { | |
| 11575 | AstNode *param_type_node = param_decl_node->data.param_decl.type; | |
| 11576 | TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node); | |
| 11577 | if (type_is_invalid(param_type)) | |
| 11578 | return false; | |
| 11586 | 11579 | |
| 11587 | bool is_var_type = (param_type->id == TypeTableEntryIdVar); | |
| 11588 | if (is_var_type) { | |
| 11589 | arg_part_of_generic_id = true; | |
| 11590 | casted_arg = ir_implicit_byval_const_ref_cast(ira, arg); | |
| 11591 | } else { | |
| 11592 | 11580 | casted_arg = ir_implicit_cast(ira, arg, param_type); |
| 11593 | 11581 | if (type_is_invalid(casted_arg->value.type)) |
| 11594 | 11582 | return false; |
| 11583 | } else { | |
| 11584 | arg_part_of_generic_id = true; | |
| 11585 | casted_arg = ir_implicit_byval_const_ref_cast(ira, arg); | |
| 11595 | 11586 | } |
| 11596 | 11587 | } |
| 11597 | 11588 | |
| ... | ... | @@ -12304,7 +12295,6 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op |
| 12304 | 12295 | return ira->codegen->builtin_types.entry_invalid; |
| 12305 | 12296 | switch (type_entry->id) { |
| 12306 | 12297 | case TypeTableEntryIdInvalid: |
| 12307 | case TypeTableEntryIdVar: | |
| 12308 | 12298 | zig_unreachable(); |
| 12309 | 12299 | case TypeTableEntryIdMetaType: |
| 12310 | 12300 | case TypeTableEntryIdVoid: |
| ... | ... | @@ -13539,10 +13529,6 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi |
| 13539 | 13529 | switch (type_entry->id) { |
| 13540 | 13530 | case TypeTableEntryIdInvalid: |
| 13541 | 13531 | zig_unreachable(); // handled above |
| 13542 | case TypeTableEntryIdVar: | |
| 13543 | ir_add_error_node(ira, expr_value->source_node, | |
| 13544 | buf_sprintf("type '%s' not eligible for @typeOf", buf_ptr(&type_entry->name))); | |
| 13545 | return ira->codegen->builtin_types.entry_invalid; | |
| 13546 | 13532 | case TypeTableEntryIdNumLitFloat: |
| 13547 | 13533 | case TypeTableEntryIdNumLitInt: |
| 13548 | 13534 | case TypeTableEntryIdUndefLit: |
| ... | ... | @@ -13807,7 +13793,6 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 13807 | 13793 | switch (child_type->id) { |
| 13808 | 13794 | case TypeTableEntryIdInvalid: // handled above |
| 13809 | 13795 | zig_unreachable(); |
| 13810 | case TypeTableEntryIdVar: | |
| 13811 | 13796 | case TypeTableEntryIdUnreachable: |
| 13812 | 13797 | case TypeTableEntryIdUndefLit: |
| 13813 | 13798 | case TypeTableEntryIdNullLit: |
| ... | ... | @@ -13916,7 +13901,6 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 13916 | 13901 | switch (child_type->id) { |
| 13917 | 13902 | case TypeTableEntryIdInvalid: // handled above |
| 13918 | 13903 | zig_unreachable(); |
| 13919 | case TypeTableEntryIdVar: | |
| 13920 | 13904 | case TypeTableEntryIdUnreachable: |
| 13921 | 13905 | case TypeTableEntryIdUndefLit: |
| 13922 | 13906 | case TypeTableEntryIdNullLit: |
| ... | ... | @@ -13968,7 +13952,6 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 13968 | 13952 | switch (type_entry->id) { |
| 13969 | 13953 | case TypeTableEntryIdInvalid: // handled above |
| 13970 | 13954 | zig_unreachable(); |
| 13971 | case TypeTableEntryIdVar: | |
| 13972 | 13955 | case TypeTableEntryIdUnreachable: |
| 13973 | 13956 | case TypeTableEntryIdUndefLit: |
| 13974 | 13957 | case TypeTableEntryIdNullLit: |
| ... | ... | @@ -14316,7 +14299,6 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 14316 | 14299 | |
| 14317 | 14300 | switch (target_type->id) { |
| 14318 | 14301 | case TypeTableEntryIdInvalid: |
| 14319 | case TypeTableEntryIdVar: | |
| 14320 | 14302 | zig_unreachable(); |
| 14321 | 14303 | case TypeTableEntryIdMetaType: |
| 14322 | 14304 | case TypeTableEntryIdVoid: |
| ... | ... | @@ -14911,7 +14893,6 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_ |
| 14911 | 14893 | } |
| 14912 | 14894 | case TypeTableEntryIdEnum: |
| 14913 | 14895 | zig_panic("TODO min/max value for enum type"); |
| 14914 | case TypeTableEntryIdVar: | |
| 14915 | 14896 | case TypeTableEntryIdMetaType: |
| 14916 | 14897 | case TypeTableEntryIdUnreachable: |
| 14917 | 14898 | case TypeTableEntryIdPointer: |
| ... | ... | @@ -16159,7 +16140,6 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc |
| 16159 | 16140 | |
| 16160 | 16141 | switch (type_entry->id) { |
| 16161 | 16142 | case TypeTableEntryIdInvalid: |
| 16162 | case TypeTableEntryIdVar: | |
| 16163 | 16143 | zig_unreachable(); |
| 16164 | 16144 | case TypeTableEntryIdMetaType: |
| 16165 | 16145 | case TypeTableEntryIdUnreachable: |
| ... | ... | @@ -16461,21 +16441,23 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc |
| 16461 | 16441 | zig_unreachable(); |
| 16462 | 16442 | } |
| 16463 | 16443 | } |
| 16464 | IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other; | |
| 16465 | if (type_is_invalid(param_type_value->value.type)) | |
| 16466 | return ira->codegen->builtin_types.entry_invalid; | |
| 16467 | ||
| 16468 | 16444 | FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index]; |
| 16469 | 16445 | param_info->is_noalias = param_node->data.param_decl.is_noalias; |
| 16470 | param_info->type = ir_resolve_type(ira, param_type_value); | |
| 16471 | if (type_is_invalid(param_info->type)) | |
| 16472 | return ira->codegen->builtin_types.entry_invalid; | |
| 16473 | 16446 | |
| 16474 | if (param_info->type->id == TypeTableEntryIdVar) { | |
| 16447 | if (instruction->param_types[fn_type_id.next_param_index] == nullptr) { | |
| 16448 | param_info->type = nullptr; | |
| 16475 | 16449 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16476 | 16450 | out_val->data.x_type = get_generic_fn_type(ira->codegen, &fn_type_id); |
| 16477 | 16451 | return ira->codegen->builtin_types.entry_type; |
| 16452 | } else { | |
| 16453 | IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other; | |
| 16454 | if (type_is_invalid(param_type_value->value.type)) | |
| 16455 | return ira->codegen->builtin_types.entry_invalid; | |
| 16456 | param_info->type = ir_resolve_type(ira, param_type_value); | |
| 16457 | if (type_is_invalid(param_info->type)) | |
| 16458 | return ira->codegen->builtin_types.entry_invalid; | |
| 16478 | 16459 | } |
| 16460 | ||
| 16479 | 16461 | } |
| 16480 | 16462 | |
| 16481 | 16463 | if (instruction->align_value != nullptr) { |
| ... | ... | @@ -16869,7 +16851,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 16869 | 16851 | assert(val->special == ConstValSpecialStatic); |
| 16870 | 16852 | switch (val->type->id) { |
| 16871 | 16853 | case TypeTableEntryIdInvalid: |
| 16872 | case TypeTableEntryIdVar: | |
| 16873 | 16854 | case TypeTableEntryIdMetaType: |
| 16874 | 16855 | case TypeTableEntryIdOpaque: |
| 16875 | 16856 | case TypeTableEntryIdBoundFn: |
| ... | ... | @@ -16937,7 +16918,6 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 16937 | 16918 | assert(val->special == ConstValSpecialStatic); |
| 16938 | 16919 | switch (val->type->id) { |
| 16939 | 16920 | case TypeTableEntryIdInvalid: |
| 16940 | case TypeTableEntryIdVar: | |
| 16941 | 16921 | case TypeTableEntryIdMetaType: |
| 16942 | 16922 | case TypeTableEntryIdOpaque: |
| 16943 | 16923 | case TypeTableEntryIdBoundFn: |
| ... | ... | @@ -17014,7 +16994,6 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc |
| 17014 | 16994 | |
| 17015 | 16995 | switch (src_type->id) { |
| 17016 | 16996 | case TypeTableEntryIdInvalid: |
| 17017 | case TypeTableEntryIdVar: | |
| 17018 | 16997 | case TypeTableEntryIdMetaType: |
| 17019 | 16998 | case TypeTableEntryIdOpaque: |
| 17020 | 16999 | case TypeTableEntryIdBoundFn: |
| ... | ... | @@ -17041,7 +17020,6 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc |
| 17041 | 17020 | |
| 17042 | 17021 | switch (dest_type->id) { |
| 17043 | 17022 | case TypeTableEntryIdInvalid: |
| 17044 | case TypeTableEntryIdVar: | |
| 17045 | 17023 | case TypeTableEntryIdMetaType: |
| 17046 | 17024 | case TypeTableEntryIdOpaque: |
| 17047 | 17025 | case TypeTableEntryIdBoundFn: |
src/parser.cpp+23-24| ... | ... | @@ -263,21 +263,14 @@ static AstNode *ast_parse_error_set_expr(ParseContext *pc, size_t *token_index, |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /* |
| 266 | TypeExpr = ErrorSetExpr | "var" | |
| 266 | TypeExpr = ErrorSetExpr | |
| 267 | 267 | */ |
| 268 | 268 | static AstNode *ast_parse_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 269 | Token *token = &pc->tokens->at(*token_index); | |
| 270 | if (token->id == TokenIdKeywordVar) { | |
| 271 | AstNode *node = ast_create_node(pc, NodeTypeVarLiteral, token); | |
| 272 | *token_index += 1; | |
| 273 | return node; | |
| 274 | } else { | |
| 275 | return ast_parse_error_set_expr(pc, token_index, mandatory); | |
| 276 | } | |
| 269 | return ast_parse_error_set_expr(pc, token_index, mandatory); | |
| 277 | 270 | } |
| 278 | 271 | |
| 279 | 272 | /* |
| 280 | ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "...") | |
| 273 | ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "var" | "...") | |
| 281 | 274 | */ |
| 282 | 275 | static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) { |
| 283 | 276 | Token *token = &pc->tokens->at(*token_index); |
| ... | ... | @@ -308,6 +301,9 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) { |
| 308 | 301 | if (ellipsis_tok->id == TokenIdEllipsis3) { |
| 309 | 302 | *token_index += 1; |
| 310 | 303 | node->data.param_decl.is_var_args = true; |
| 304 | } else if (ellipsis_tok->id == TokenIdKeywordVar) { | |
| 305 | *token_index += 1; | |
| 306 | node->data.param_decl.var_token = ellipsis_tok; | |
| 311 | 307 | } else { |
| 312 | 308 | node->data.param_decl.type = ast_parse_type_expr(pc, token_index, true); |
| 313 | 309 | } |
| ... | ... | @@ -2421,7 +2417,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand |
| 2421 | 2417 | } |
| 2422 | 2418 | |
| 2423 | 2419 | /* |
| 2424 | FnProto = option("nakedcc" | "stdcallcc" | "extern" | ("async" option("(" Expression ")"))) "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("!") TypeExpr | |
| 2420 | FnProto = option("nakedcc" | "stdcallcc" | "extern" | ("async" option("(" Expression ")"))) "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("!") (TypeExpr | "var") | |
| 2425 | 2421 | */ |
| 2426 | 2422 | static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory, VisibMod visib_mod) { |
| 2427 | 2423 | Token *first_token = &pc->tokens->at(*token_index); |
| ... | ... | @@ -2507,19 +2503,25 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m |
| 2507 | 2503 | ast_eat_token(pc, token_index, TokenIdRParen); |
| 2508 | 2504 | next_token = &pc->tokens->at(*token_index); |
| 2509 | 2505 | } |
| 2510 | if (next_token->id == TokenIdKeywordError) { | |
| 2511 | Token *maybe_lbrace_tok = &pc->tokens->at(*token_index + 1); | |
| 2512 | if (maybe_lbrace_tok->id == TokenIdLBrace) { | |
| 2513 | *token_index += 1; | |
| 2514 | node->data.fn_proto.return_type = ast_create_node(pc, NodeTypeErrorType, next_token); | |
| 2515 | return node; | |
| 2516 | } | |
| 2517 | } else if (next_token->id == TokenIdBang) { | |
| 2506 | if (next_token->id == TokenIdKeywordVar) { | |
| 2507 | node->data.fn_proto.return_var_token = next_token; | |
| 2518 | 2508 | *token_index += 1; |
| 2519 | node->data.fn_proto.auto_err_set = true; | |
| 2520 | 2509 | next_token = &pc->tokens->at(*token_index); |
| 2510 | } else { | |
| 2511 | if (next_token->id == TokenIdKeywordError) { | |
| 2512 | Token *maybe_lbrace_tok = &pc->tokens->at(*token_index + 1); | |
| 2513 | if (maybe_lbrace_tok->id == TokenIdLBrace) { | |
| 2514 | *token_index += 1; | |
| 2515 | node->data.fn_proto.return_type = ast_create_node(pc, NodeTypeErrorType, next_token); | |
| 2516 | return node; | |
| 2517 | } | |
| 2518 | } else if (next_token->id == TokenIdBang) { | |
| 2519 | *token_index += 1; | |
| 2520 | node->data.fn_proto.auto_err_set = true; | |
| 2521 | next_token = &pc->tokens->at(*token_index); | |
| 2522 | } | |
| 2523 | node->data.fn_proto.return_type = ast_parse_type_expr(pc, token_index, true); | |
| 2521 | 2524 | } |
| 2522 | node->data.fn_proto.return_type = ast_parse_type_expr(pc, token_index, true); | |
| 2523 | 2525 | |
| 2524 | 2526 | return node; |
| 2525 | 2527 | } |
| ... | ... | @@ -3069,9 +3071,6 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont |
| 3069 | 3071 | case NodeTypeErrorType: |
| 3070 | 3072 | // none |
| 3071 | 3073 | break; |
| 3072 | case NodeTypeVarLiteral: | |
| 3073 | // none | |
| 3074 | break; | |
| 3075 | 3074 | case NodeTypeAddrOfExpr: |
| 3076 | 3075 | visit_field(&node->data.addr_of_expr.align_expr, visit, context); |
| 3077 | 3076 | visit_field(&node->data.addr_of_expr.op_expr, visit, context); |
test/compile_errors.zig+7| ... | ... | @@ -1,6 +1,13 @@ |
| 1 | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | |
| 3 | 3 | pub fn addCases(cases: &tests.CompileErrorContext) void { |
| 4 | cases.add("var not allowed in structs", | |
| 5 | \\export fn entry() void { | |
| 6 | \\ var s = (struct{v: var}){.v=i32(10)}; | |
| 7 | \\} | |
| 8 | , | |
| 9 | ".tmp_source.zig:2:23: error: invalid token: 'var'"); | |
| 10 | ||
| 4 | 11 | cases.add("@ptrCast discards const qualifier", |
| 5 | 12 | \\export fn entry() void { |
| 6 | 13 | \\ const x: i32 = 1234; |