authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-05-04 16:00:12-04:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-05-10 21:00:10+02:00
log24dfa61236aba6d1c613f929ef06e67f7ce5ddcf
treef13ed77ef4b790a8a7c1ce7b5f2278eb94d7082b
parent8f8efcdd6e333e5ee3cf406fd095d0c8d47ab89c

stage1: remove outdated error message regarding #447


6 files changed, 55 insertions(+), 85 deletions(-)

lib/std/zig/parse.zig+1-1
...@@ -639,7 +639,7 @@ const Parser = struct {...@@ -639,7 +639,7 @@ const Parser = struct {
639 };639 };
640 }640 }
641641
642 /// FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? CallConv? EXCLAMATIONMARK? (Keyword_anytype / TypeExpr)642 /// FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? CallConv? EXCLAMATIONMARK? TypeExpr
643 fn parseFnProto(p: *Parser) !Node.Index {643 fn parseFnProto(p: *Parser) !Node.Index {
644 const fn_token = p.eatToken(.keyword_fn) orelse return null_node;644 const fn_token = p.eatToken(.keyword_fn) orelse return null_node;
645645
src/stage1/all_types.hpp-1
...@@ -718,7 +718,6 @@ struct AstNodeFnProto {...@@ -718,7 +718,6 @@ struct AstNodeFnProto {
718 Buf *name;718 Buf *name;
719 ZigList<AstNode *> params;719 ZigList<AstNode *> params;
720 AstNode *return_type;720 AstNode *return_type;
721 Token *return_anytype_token;
722 AstNode *fn_def_node;721 AstNode *fn_def_node;
723 // populated if this is an extern declaration722 // populated if this is an extern declaration
724 Buf *lib_name;723 Buf *lib_name;
src/stage1/analyze.cpp-13
...@@ -2125,18 +2125,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc...@@ -2125,18 +2125,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
2125 return g->builtin_types.entry_invalid;2125 return g->builtin_types.entry_invalid;
2126 }2126 }
21272127
2128 if (fn_proto->return_anytype_token != nullptr) {
2129 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
2130 add_node_error(g, fn_proto->return_type,
2131 buf_sprintf("return type 'anytype' not allowed in function with calling convention '%s'",
2132 calling_convention_name(fn_type_id.cc)));
2133 return g->builtin_types.entry_invalid;
2134 }
2135 add_node_error(g, proto_node,
2136 buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"));
2137 return g->builtin_types.entry_invalid;
2138 }
2139
2140 ZigType *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);2128 ZigType *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);
2141 if (type_is_invalid(specified_return_type)) {2129 if (type_is_invalid(specified_return_type)) {
2142 fn_type_id.return_type = g->builtin_types.entry_invalid;2130 fn_type_id.return_type = g->builtin_types.entry_invalid;
...@@ -10220,4 +10208,3 @@ const char *float_op_to_name(BuiltinFnId op) {...@@ -10220,4 +10208,3 @@ const char *float_op_to_name(BuiltinFnId op) {
10220 zig_unreachable();10208 zig_unreachable();
10221 }10209 }
10222}10210}
10223
src/stage1/ast_render.cpp+6-10
...@@ -490,17 +490,13 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -490,17 +490,13 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
490 fprintf(ar->f, ")");490 fprintf(ar->f, ")");
491 }491 }
492492
493 if (node->data.fn_proto.return_anytype_token != nullptr) {493 AstNode *return_type_node = node->data.fn_proto.return_type;
494 fprintf(ar->f, "anytype");494 assert(return_type_node != nullptr);
495 } else {495 fprintf(ar->f, " ");
496 AstNode *return_type_node = node->data.fn_proto.return_type;496 if (node->data.fn_proto.auto_err_set) {
497 assert(return_type_node != nullptr);497 fprintf(ar->f, "!");
498 fprintf(ar->f, " ");
499 if (node->data.fn_proto.auto_err_set) {
500 fprintf(ar->f, "!");
501 }
502 render_node_grouped(ar, return_type_node);
503 }498 }
499 render_node_grouped(ar, return_type_node);
504 break;500 break;
505 }501 }
506 case NodeTypeFnDef:502 case NodeTypeFnDef:
src/stage1/ir.cpp+37-46
...@@ -10104,19 +10104,12 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod...@@ -10104,19 +10104,12 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod
10104 }10104 }
1010510105
10106 IrInstSrc *return_type;10106 IrInstSrc *return_type;
10107 if (node->data.fn_proto.return_anytype_token == nullptr) {10107 if (node->data.fn_proto.return_type == nullptr) {
10108 if (node->data.fn_proto.return_type == nullptr) {10108 return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void);
10109 return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void);
10110 } else {
10111 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
10112 if (return_type == irb->codegen->invalid_inst_src)
10113 return irb->codegen->invalid_inst_src;
10114 }
10115 } else {10109 } else {
10116 add_node_error(irb->codegen, node,10110 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
10117 buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"));10111 if (return_type == irb->codegen->invalid_inst_src)
10118 return irb->codegen->invalid_inst_src;10112 return irb->codegen->invalid_inst_src;
10119 //return_type = nullptr;
10120 }10113 }
1012110114
10122 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args);10115 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args);
...@@ -14978,7 +14971,7 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou...@@ -14978,7 +14971,7 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou
1497814971
14979 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))14972 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))
14980 return ira->codegen->invalid_inst_gen;14973 return ira->codegen->invalid_inst_gen;
14981 14974
14982 size_t array_len = wanted_type->data.array.len;14975 size_t array_len = wanted_type->data.array.len;
14983 size_t instr_field_count = actual_type->data.structure.src_field_count;14976 size_t instr_field_count = actual_type->data.structure.src_field_count;
14984 assert(array_len == instr_field_count);14977 assert(array_len == instr_field_count);
...@@ -20953,44 +20946,42 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -20953,44 +20946,42 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
20953 inst_fn_type_id.alignment = align_bytes;20946 inst_fn_type_id.alignment = align_bytes;
20954 }20947 }
2095520948
20956 if (fn_proto_node->data.fn_proto.return_anytype_token == nullptr) {20949 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
20957 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;20950 ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node);
20958 ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node);20951 if (type_is_invalid(specified_return_type))
20959 if (type_is_invalid(specified_return_type))20952 return ira->codegen->invalid_inst_gen;
20960 return ira->codegen->invalid_inst_gen;
20961
20962 if(!is_valid_return_type(specified_return_type)){
20963 ErrorMsg *msg = ir_add_error(ira, source_instr,
20964 buf_sprintf("call to generic function with %s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name)));
20965 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here"));
2096620953
20967 Tld *tld = find_decl(ira->codegen, &fn_entry->fndef_scope->base, &specified_return_type->name);20954 if(!is_valid_return_type(specified_return_type)){
20968 if (tld != nullptr) {20955 ErrorMsg *msg = ir_add_error(ira, source_instr,
20969 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("type declared here"));20956 buf_sprintf("call to generic function with %s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name)));
20970 }20957 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here"));
20971 return ira->codegen->invalid_inst_gen;
20972 }
2097320958
20974 if (fn_proto_node->data.fn_proto.auto_err_set) {20959 Tld *tld = find_decl(ira->codegen, &fn_entry->fndef_scope->base, &specified_return_type->name);
20975 ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);20960 if (tld != nullptr) {
20976 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))20961 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("type declared here"));
20977 return ira->codegen->invalid_inst_gen;
20978 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
20979 } else {
20980 inst_fn_type_id.return_type = specified_return_type;
20981 }20962 }
20963 return ira->codegen->invalid_inst_gen;
20964 }
2098220965
20983 switch (type_requires_comptime(ira->codegen, specified_return_type)) {20966 if (fn_proto_node->data.fn_proto.auto_err_set) {
20984 case ReqCompTimeYes:20967 ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);
20985 // Throw out our work and call the function as if it were comptime.20968 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))
20986 return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr,
20987 first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin,
20988 args_ptr, args_len, ret_ptr, call_result_loc);
20989 case ReqCompTimeInvalid:
20990 return ira->codegen->invalid_inst_gen;20969 return ira->codegen->invalid_inst_gen;
20991 case ReqCompTimeNo:20970 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
20992 break;20971 } else {
20993 }20972 inst_fn_type_id.return_type = specified_return_type;
20973 }
20974
20975 switch (type_requires_comptime(ira->codegen, specified_return_type)) {
20976 case ReqCompTimeYes:
20977 // Throw out our work and call the function as if it were comptime.
20978 return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr,
20979 first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin,
20980 args_ptr, args_len, ret_ptr, call_result_loc);
20981 case ReqCompTimeInvalid:
20982 return ira->codegen->invalid_inst_gen;
20983 case ReqCompTimeNo:
20984 break;
20994 }20985 }
2099520986
20996 auto existing_entry = ira->codegen->generic_table.put_unique(generic_id, impl_fn);20987 auto existing_entry = ira->codegen->generic_table.put_unique(generic_id, impl_fn);
src/stage1/parser.cpp+11-14
...@@ -820,21 +820,19 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {...@@ -820,21 +820,19 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {
820 AstNode *align_expr = ast_parse_byte_align(pc);820 AstNode *align_expr = ast_parse_byte_align(pc);
821 AstNode *section_expr = ast_parse_link_section(pc);821 AstNode *section_expr = ast_parse_link_section(pc);
822 AstNode *callconv_expr = ast_parse_callconv(pc);822 AstNode *callconv_expr = ast_parse_callconv(pc);
823 Token *anytype = eat_token_if(pc, TokenIdKeywordAnyType);
824 Token *exmark = nullptr;823 Token *exmark = nullptr;
825 AstNode *return_type = nullptr;824 AstNode *return_type = nullptr;
826 if (anytype == nullptr) {825
827 exmark = eat_token_if(pc, TokenIdBang);826 exmark = eat_token_if(pc, TokenIdBang);
828 return_type = ast_parse_type_expr(pc);827 return_type = ast_parse_type_expr(pc);
829 if (return_type == nullptr) {828 if (return_type == nullptr) {
830 Token *next = peek_token(pc);829 Token *next = peek_token(pc);
831 ast_error(830 ast_error(
832 pc,831 pc,
833 next,832 next,
834 "expected return type (use 'void' to return nothing), found: '%s'",833 "expected return type (use 'void' to return nothing), found: '%s'",
835 token_name(next->id)834 token_name(next->id)
836 );835 );
837 }
838 }836 }
839837
840 AstNode *res = ast_create_node(pc, NodeTypeFnProto, first);838 AstNode *res = ast_create_node(pc, NodeTypeFnProto, first);
...@@ -844,7 +842,6 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {...@@ -844,7 +842,6 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {
844 res->data.fn_proto.align_expr = align_expr;842 res->data.fn_proto.align_expr = align_expr;
845 res->data.fn_proto.section_expr = section_expr;843 res->data.fn_proto.section_expr = section_expr;
846 res->data.fn_proto.callconv_expr = callconv_expr;844 res->data.fn_proto.callconv_expr = callconv_expr;
847 res->data.fn_proto.return_anytype_token = anytype;
848 res->data.fn_proto.auto_err_set = exmark != nullptr;845 res->data.fn_proto.auto_err_set = exmark != nullptr;
849 res->data.fn_proto.return_type = return_type;846 res->data.fn_proto.return_type = return_type;
850847