| author | |
| committer | |
| log | 5951b79af40212754071157596b8aebbe2414ffb |
| tree | 9e2377dddfec47701210dd4135d0c0f1de12926d |
| parent | 0a9daeb37e997ff75dcd16d1fc3b4cc143314e85 |
| signature | Commit is signed but in an unrecognized format. |
10 files changed, 31 insertions(+), 52 deletions(-)
lib/std/builtin.zig-1| ... | ... | @@ -322,7 +322,6 @@ pub const TypeInfo = union(enum) { |
| 322 | 322 | pub const FnDecl = struct { |
| 323 | 323 | fn_type: type, |
| 324 | 324 | inline_type: Inline, |
| 325 | calling_convention: CallingConvention, | |
| 326 | 325 | is_var_args: bool, |
| 327 | 326 | is_extern: bool, |
| 328 | 327 | is_export: bool, |
lib/std/zig/parser_test.zig+3-1| ... | ... | @@ -10,13 +10,15 @@ test "zig fmt: change @typeOf to @TypeOf" { |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | // TODO: Remove nakedcc/stdcallcc once zig 0.6.0 is released. See https://github.com/ziglang/zig/pull/3977 |
| 13 | test "zig fmt: convert nakedcc/stdcallcc into callconv(...)" { | |
| 13 | test "zig fmt: convert extern/nakedcc/stdcallcc into callconv(...)" { | |
| 14 | 14 | try testTransform( |
| 15 | 15 | \\nakedcc fn foo1() void {} |
| 16 | 16 | \\stdcallcc fn foo2() void {} |
| 17 | \\extern fn foo3() void {} | |
| 17 | 18 | , |
| 18 | 19 | \\fn foo1() callconv(.Naked) void {} |
| 19 | 20 | \\fn foo2() callconv(.Stdcall) void {} |
| 21 | \\fn foo3() callconv(.C) void {} | |
| 20 | 22 | \\ |
| 21 | 23 | ); |
| 22 | 24 | } |
lib/std/zig/render.zig+10-5| ... | ... | @@ -1311,17 +1311,22 @@ fn renderExpression( |
| 1311 | 1311 | try renderToken(tree, stream, visib_token_index, indent, start_col, Space.Space); // pub |
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | // Some extra machinery is needed to rewrite the old-style cc | |
| 1315 | // notation to the new callconv one | |
| 1316 | var cc_rewrite_str: ?[*:0]const u8 = null; | |
| 1314 | 1317 | if (fn_proto.extern_export_inline_token) |extern_export_inline_token| { |
| 1315 | try renderToken(tree, stream, extern_export_inline_token, indent, start_col, Space.Space); // extern/export | |
| 1318 | const tok = tree.tokens.at(extern_export_inline_token); | |
| 1319 | if (tok.id != .Keyword_extern or fn_proto.body_node == null) { | |
| 1320 | try renderToken(tree, stream, extern_export_inline_token, indent, start_col, Space.Space); // extern/export | |
| 1321 | } else { | |
| 1322 | cc_rewrite_str = ".C"; | |
| 1323 | } | |
| 1316 | 1324 | } |
| 1317 | 1325 | |
| 1318 | 1326 | if (fn_proto.lib_name) |lib_name| { |
| 1319 | 1327 | try renderExpression(allocator, stream, tree, indent, start_col, lib_name, Space.Space); |
| 1320 | 1328 | } |
| 1321 | 1329 | |
| 1322 | // Some extra machinery is needed to rewrite the old-style cc | |
| 1323 | // notation to the new callconv one | |
| 1324 | var cc_rewrite_str: ?[*:0]const u8 = null; | |
| 1325 | 1330 | if (fn_proto.cc_token) |cc_token| { |
| 1326 | 1331 | var str = tree.tokenSlicePtr(tree.tokens.at(cc_token)); |
| 1327 | 1332 | if (mem.eql(u8, str, "stdcallcc")) { |
| ... | ... | @@ -1405,7 +1410,7 @@ fn renderExpression( |
| 1405 | 1410 | const callconv_lparen = tree.prevToken(callconv_expr.firstToken()); |
| 1406 | 1411 | const callconv_kw = tree.prevToken(callconv_lparen); |
| 1407 | 1412 | |
| 1408 | try renderToken(tree, stream, callconv_kw, indent, start_col, Space.None); // section | |
| 1413 | try renderToken(tree, stream, callconv_kw, indent, start_col, Space.None); // callconv | |
| 1409 | 1414 | try renderToken(tree, stream, callconv_lparen, indent, start_col, Space.None); // ( |
| 1410 | 1415 | try renderExpression(allocator, stream, tree, indent, start_col, callconv_expr, Space.None); |
| 1411 | 1416 | try renderToken(tree, stream, callconv_rparen, indent, start_col, Space.Space); // ) |
src/all_types.hpp-3| ... | ... | @@ -653,8 +653,6 @@ struct AstNodeFnProto { |
| 653 | 653 | Buf doc_comments; |
| 654 | 654 | |
| 655 | 655 | FnInline fn_inline; |
| 656 | bool is_nakedcc; | |
| 657 | bool is_stdcallcc; | |
| 658 | 656 | bool is_async; |
| 659 | 657 | |
| 660 | 658 | VisibMod visib_mod; |
| ... | ... | @@ -1610,7 +1608,6 @@ struct ZigFn { |
| 1610 | 1608 | Buf **param_names; |
| 1611 | 1609 | IrInstruction *err_code_spill; |
| 1612 | 1610 | AstNode *assumed_non_async; |
| 1613 | CallingConvention cc; | |
| 1614 | 1611 | |
| 1615 | 1612 | AstNode *fn_no_inline_set_node; |
| 1616 | 1613 | AstNode *fn_static_eval_set_node; |
src/analyze.cpp+10-12| ... | ... | @@ -1451,8 +1451,6 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { |
| 1451 | 1451 | ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { |
| 1452 | 1452 | ZigType *fn_type = new_type_table_entry(ZigTypeIdFn); |
| 1453 | 1453 | buf_resize(&fn_type->name, 0); |
| 1454 | if (fn_type->data.fn.fn_type_id.cc == CallingConventionC) | |
| 1455 | buf_append_str(&fn_type->name, "extern "); | |
| 1456 | 1454 | buf_appendf(&fn_type->name, "fn("); |
| 1457 | 1455 | size_t i = 0; |
| 1458 | 1456 | for (; i < fn_type_id->next_param_index; i += 1) { |
| ... | ... | @@ -1465,7 +1463,7 @@ ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { |
| 1465 | 1463 | buf_appendf(&fn_type->name, "%svar", comma_str); |
| 1466 | 1464 | } |
| 1467 | 1465 | buf_append_str(&fn_type->name, ")"); |
| 1468 | if (fn_type_id->cc != CallingConventionUnspecified && fn_type_id->cc != CallingConventionC) { | |
| 1466 | if (fn_type_id->cc != CallingConventionUnspecified) { | |
| 1469 | 1467 | buf_appendf(&fn_type->name, " callconv(%s)", calling_convention_name(fn_type_id->cc)); |
| 1470 | 1468 | } |
| 1471 | 1469 | buf_append_str(&fn_type->name, " var"); |
| ... | ... | @@ -1479,10 +1477,6 @@ ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { |
| 1479 | 1477 | } |
| 1480 | 1478 | |
| 1481 | 1479 | CallingConvention cc_from_fn_proto(AstNodeFnProto *fn_proto) { |
| 1482 | if (fn_proto->is_nakedcc) | |
| 1483 | return CallingConventionNaked; | |
| 1484 | if (fn_proto->is_stdcallcc) | |
| 1485 | return CallingConventionStdcall; | |
| 1486 | 1480 | if (fn_proto->is_async) |
| 1487 | 1481 | return CallingConventionAsync; |
| 1488 | 1482 | // Compatible with the C ABI |
| ... | ... | @@ -1764,13 +1758,15 @@ ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) { |
| 1764 | 1758 | return err_set_type; |
| 1765 | 1759 | } |
| 1766 | 1760 | |
| 1767 | static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, ZigFn *fn_entry) { | |
| 1761 | static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, ZigFn *fn_entry, | |
| 1762 | CallingConvention cc) | |
| 1763 | { | |
| 1768 | 1764 | assert(proto_node->type == NodeTypeFnProto); |
| 1769 | 1765 | AstNodeFnProto *fn_proto = &proto_node->data.fn_proto; |
| 1770 | 1766 | Error err; |
| 1771 | 1767 | |
| 1772 | 1768 | FnTypeId fn_type_id = {0}; |
| 1773 | init_fn_type_id(&fn_type_id, proto_node, fn_entry->cc, proto_node->data.fn_proto.params.length); | |
| 1769 | init_fn_type_id(&fn_type_id, proto_node, cc, proto_node->data.fn_proto.params.length); | |
| 1774 | 1770 | |
| 1775 | 1771 | for (; fn_type_id.next_param_index < fn_type_id.param_count; fn_type_id.next_param_index += 1) { |
| 1776 | 1772 | AstNode *param_node = fn_proto->params.at(fn_type_id.next_param_index); |
| ... | ... | @@ -3432,7 +3428,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3432 | 3428 | |
| 3433 | 3429 | Scope *child_scope = fn_table_entry->fndef_scope ? &fn_table_entry->fndef_scope->base : tld_fn->base.parent_scope; |
| 3434 | 3430 | |
| 3435 | fn_table_entry->cc = cc_from_fn_proto(fn_proto); | |
| 3431 | CallingConvention cc; | |
| 3436 | 3432 | if (fn_proto->callconv_expr != nullptr) { |
| 3437 | 3433 | ZigType *cc_enum_value = get_builtin_type(g, "CallingConvention"); |
| 3438 | 3434 | |
| ... | ... | @@ -3444,7 +3440,9 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3444 | 3440 | return; |
| 3445 | 3441 | } |
| 3446 | 3442 | |
| 3447 | fn_table_entry->cc = (CallingConvention)bigint_as_u32(&result_val->data.x_enum_tag); | |
| 3443 | cc = (CallingConvention)bigint_as_u32(&result_val->data.x_enum_tag); | |
| 3444 | } else { | |
| 3445 | cc = cc_from_fn_proto(fn_proto); | |
| 3448 | 3446 | } |
| 3449 | 3447 | |
| 3450 | 3448 | if (fn_proto->section_expr != nullptr) { |
| ... | ... | @@ -3455,7 +3453,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3455 | 3453 | } |
| 3456 | 3454 | } |
| 3457 | 3455 | |
| 3458 | fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry); | |
| 3456 | fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry, cc); | |
| 3459 | 3457 | |
| 3460 | 3458 | if (type_is_invalid(fn_table_entry->type_entry)) { |
| 3461 | 3459 | tld_fn->base.resolution = TldResolutionInvalid; |
src/codegen.cpp+1-1| ... | ... | @@ -519,7 +519,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { |
| 519 | 519 | if (cc == CallingConventionNaked) { |
| 520 | 520 | addLLVMFnAttr(llvm_fn, "naked"); |
| 521 | 521 | } else { |
| 522 | ZigLLVMFunctionSetCallingConv(llvm_fn, get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc)); | |
| 522 | ZigLLVMFunctionSetCallingConv(llvm_fn, get_llvm_cc(g, cc)); | |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | bool want_cold = fn->is_cold || cc == CallingConventionCold; |
src/ir.cpp+6-12| ... | ... | @@ -18263,7 +18263,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i |
| 18263 | 18263 | buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name); |
| 18264 | 18264 | impl_fn->fndef_scope = create_fndef_scope(ira->codegen, impl_fn->body_node, parent_scope, impl_fn); |
| 18265 | 18265 | impl_fn->child_scope = &impl_fn->fndef_scope->base; |
| 18266 | impl_fn->cc = fn_entry->cc; | |
| 18267 | 18266 | FnTypeId inst_fn_type_id = {0}; |
| 18268 | 18267 | init_fn_type_id(&inst_fn_type_id, fn_proto_node, fn_type_id->cc, new_fn_arg_count); |
| 18269 | 18268 | inst_fn_type_id.param_count = 0; |
| ... | ... | @@ -22599,29 +22598,24 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 22599 | 22598 | fn_decl_fields[1]->special = ConstValSpecialStatic; |
| 22600 | 22599 | fn_decl_fields[1]->type = type_info_fn_decl_inline_type; |
| 22601 | 22600 | bigint_init_unsigned(&fn_decl_fields[1]->data.x_enum_tag, fn_entry->fn_inline); |
| 22602 | // calling_convention: TypeInfo.CallingConvention | |
| 22603 | ensure_field_index(fn_decl_val->type, "calling_convention", 2); | |
| 22604 | fn_decl_fields[2]->special = ConstValSpecialStatic; | |
| 22605 | fn_decl_fields[2]->type = get_builtin_type(ira->codegen, "CallingConvention"); | |
| 22606 | bigint_init_unsigned(&fn_decl_fields[2]->data.x_enum_tag, fn_entry->cc); | |
| 22607 | 22601 | // is_var_args: bool |
| 22608 | ensure_field_index(fn_decl_val->type, "is_var_args", 3); | |
| 22602 | ensure_field_index(fn_decl_val->type, "is_var_args", 2); | |
| 22609 | 22603 | bool is_varargs = fn_node->is_var_args; |
| 22610 | 22604 | fn_decl_fields[3]->special = ConstValSpecialStatic; |
| 22611 | 22605 | fn_decl_fields[3]->type = ira->codegen->builtin_types.entry_bool; |
| 22612 | 22606 | fn_decl_fields[3]->data.x_bool = is_varargs; |
| 22613 | 22607 | // is_extern: bool |
| 22614 | ensure_field_index(fn_decl_val->type, "is_extern", 4); | |
| 22608 | ensure_field_index(fn_decl_val->type, "is_extern", 3); | |
| 22615 | 22609 | fn_decl_fields[4]->special = ConstValSpecialStatic; |
| 22616 | 22610 | fn_decl_fields[4]->type = ira->codegen->builtin_types.entry_bool; |
| 22617 | 22611 | fn_decl_fields[4]->data.x_bool = fn_node->is_extern; |
| 22618 | 22612 | // is_export: bool |
| 22619 | ensure_field_index(fn_decl_val->type, "is_export", 5); | |
| 22613 | ensure_field_index(fn_decl_val->type, "is_export", 4); | |
| 22620 | 22614 | fn_decl_fields[5]->special = ConstValSpecialStatic; |
| 22621 | 22615 | fn_decl_fields[5]->type = ira->codegen->builtin_types.entry_bool; |
| 22622 | 22616 | fn_decl_fields[5]->data.x_bool = fn_node->is_export; |
| 22623 | 22617 | // lib_name: ?[]const u8 |
| 22624 | ensure_field_index(fn_decl_val->type, "lib_name", 6); | |
| 22618 | ensure_field_index(fn_decl_val->type, "lib_name", 5); | |
| 22625 | 22619 | fn_decl_fields[6]->special = ConstValSpecialStatic; |
| 22626 | 22620 | ZigType *u8_ptr = get_pointer_to_type_extra( |
| 22627 | 22621 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| ... | ... | @@ -22637,12 +22631,12 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 22637 | 22631 | fn_decl_fields[6]->data.x_optional = nullptr; |
| 22638 | 22632 | } |
| 22639 | 22633 | // return_type: type |
| 22640 | ensure_field_index(fn_decl_val->type, "return_type", 7); | |
| 22634 | ensure_field_index(fn_decl_val->type, "return_type", 6); | |
| 22641 | 22635 | fn_decl_fields[7]->special = ConstValSpecialStatic; |
| 22642 | 22636 | fn_decl_fields[7]->type = ira->codegen->builtin_types.entry_type; |
| 22643 | 22637 | fn_decl_fields[7]->data.x_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; |
| 22644 | 22638 | // arg_names: [][] const u8 |
| 22645 | ensure_field_index(fn_decl_val->type, "arg_names", 8); | |
| 22639 | ensure_field_index(fn_decl_val->type, "arg_names", 7); | |
| 22646 | 22640 | size_t fn_arg_count = fn_entry->variable_list.length; |
| 22647 | 22641 | ZigValue *fn_arg_name_array = create_const_vals(1); |
| 22648 | 22642 | fn_arg_name_array->special = ConstValSpecialStatic; |
src/parser.cpp+1-11| ... | ... | @@ -2117,20 +2117,10 @@ static AstNode *ast_parse_callconv(ParseContext *pc) { |
| 2117 | 2117 | } |
| 2118 | 2118 | |
| 2119 | 2119 | // FnCC |
| 2120 | // <- KEYWORD_nakedcc | |
| 2121 | // / KEYWORD_stdcallcc | |
| 2122 | // / KEYWORD_extern | |
| 2120 | // <- KEYWORD_extern | |
| 2123 | 2121 | // / KEYWORD_async |
| 2124 | 2122 | static Optional<AstNodeFnProto> ast_parse_fn_cc(ParseContext *pc) { |
| 2125 | 2123 | AstNodeFnProto res = {}; |
| 2126 | if (eat_token_if(pc, TokenIdKeywordNakedCC) != nullptr) { | |
| 2127 | res.is_nakedcc = true; | |
| 2128 | return Optional<AstNodeFnProto>::some(res); | |
| 2129 | } | |
| 2130 | if (eat_token_if(pc, TokenIdKeywordStdcallCC) != nullptr) { | |
| 2131 | res.is_stdcallcc = true; | |
| 2132 | return Optional<AstNodeFnProto>::some(res); | |
| 2133 | } | |
| 2134 | 2124 | if (eat_token_if(pc, TokenIdKeywordAsync) != nullptr) { |
| 2135 | 2125 | res.is_async = true; |
| 2136 | 2126 | return Optional<AstNodeFnProto>::some(res); |
src/tokenizer.cpp-4| ... | ... | @@ -127,7 +127,6 @@ static const struct ZigKeyword zig_keywords[] = { |
| 127 | 127 | {"for", TokenIdKeywordFor}, |
| 128 | 128 | {"if", TokenIdKeywordIf}, |
| 129 | 129 | {"inline", TokenIdKeywordInline}, |
| 130 | {"nakedcc", TokenIdKeywordNakedCC}, | |
| 131 | 130 | {"noalias", TokenIdKeywordNoAlias}, |
| 132 | 131 | {"noasync", TokenIdKeywordNoAsync}, |
| 133 | 132 | {"noinline", TokenIdKeywordNoInline}, |
| ... | ... | @@ -139,7 +138,6 @@ static const struct ZigKeyword zig_keywords[] = { |
| 139 | 138 | {"resume", TokenIdKeywordResume}, |
| 140 | 139 | {"return", TokenIdKeywordReturn}, |
| 141 | 140 | {"linksection", TokenIdKeywordLinkSection}, |
| 142 | {"stdcallcc", TokenIdKeywordStdcallCC}, | |
| 143 | 141 | {"struct", TokenIdKeywordStruct}, |
| 144 | 142 | {"suspend", TokenIdKeywordSuspend}, |
| 145 | 143 | {"switch", TokenIdKeywordSwitch}, |
| ... | ... | @@ -1562,7 +1560,6 @@ const char * token_name(TokenId id) { |
| 1562 | 1560 | case TokenIdKeywordFor: return "for"; |
| 1563 | 1561 | case TokenIdKeywordIf: return "if"; |
| 1564 | 1562 | case TokenIdKeywordInline: return "inline"; |
| 1565 | case TokenIdKeywordNakedCC: return "nakedcc"; | |
| 1566 | 1563 | case TokenIdKeywordNoAlias: return "noalias"; |
| 1567 | 1564 | case TokenIdKeywordNoAsync: return "noasync"; |
| 1568 | 1565 | case TokenIdKeywordNoInline: return "noinline"; |
| ... | ... | @@ -1573,7 +1570,6 @@ const char * token_name(TokenId id) { |
| 1573 | 1570 | case TokenIdKeywordPub: return "pub"; |
| 1574 | 1571 | case TokenIdKeywordReturn: return "return"; |
| 1575 | 1572 | case TokenIdKeywordLinkSection: return "linksection"; |
| 1576 | case TokenIdKeywordStdcallCC: return "stdcallcc"; | |
| 1577 | 1573 | case TokenIdKeywordStruct: return "struct"; |
| 1578 | 1574 | case TokenIdKeywordSwitch: return "switch"; |
| 1579 | 1575 | case TokenIdKeywordTest: return "test"; |
src/tokenizer.hpp-2| ... | ... | @@ -77,7 +77,6 @@ enum TokenId { |
| 77 | 77 | TokenIdKeywordInline, |
| 78 | 78 | TokenIdKeywordNoInline, |
| 79 | 79 | TokenIdKeywordLinkSection, |
| 80 | TokenIdKeywordNakedCC, | |
| 81 | 80 | TokenIdKeywordNoAlias, |
| 82 | 81 | TokenIdKeywordNoAsync, |
| 83 | 82 | TokenIdKeywordNull, |
| ... | ... | @@ -87,7 +86,6 @@ enum TokenId { |
| 87 | 86 | TokenIdKeywordPub, |
| 88 | 87 | TokenIdKeywordResume, |
| 89 | 88 | TokenIdKeywordReturn, |
| 90 | TokenIdKeywordStdcallCC, | |
| 91 | 89 | TokenIdKeywordStruct, |
| 92 | 90 | TokenIdKeywordSuspend, |
| 93 | 91 | TokenIdKeywordSwitch, |