authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 20:27:53-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 20:27:53-05:00
log6cbea99ed6c0a87b4e4b779975f7f26738241280
treeaf144b1a6ecadf6628e0d780b7f82a0073e32a44
parentb018c64ca2c92f5d6a4d3e5dcdfdc0cf70680027

async functions are allowed to accept zig types


1 files changed, 22 insertions(+), 8 deletions(-)

src/analyze.cpp+22-8
......@@ -927,6 +927,20 @@ static const char *calling_convention_fn_type_str(CallingConvention cc) {
927927 zig_unreachable();
928928}
929929
930static bool calling_convention_allows_zig_types(CallingConvention cc) {
931 switch (cc) {
932 case CallingConventionUnspecified:
933 case CallingConventionAsync:
934 return true;
935 case CallingConventionC:
936 case CallingConventionCold:
937 case CallingConventionNaked:
938 case CallingConventionStdcall:
939 return false;
940 }
941 zig_unreachable();
942}
943
930944TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g) {
931945 if (g->stack_trace_type == nullptr) {
932946 ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace");
......@@ -1380,7 +1394,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
13801394 bool param_is_var_args = param_node->data.param_decl.is_var_args;
13811395
13821396 if (param_is_comptime) {
1383 if (fn_type_id.cc != CallingConventionUnspecified) {
1397 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
13841398 add_node_error(g, param_node,
13851399 buf_sprintf("comptime parameter not allowed in function with calling convention '%s'",
13861400 calling_convention_name(fn_type_id.cc)));
......@@ -1391,7 +1405,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
13911405 if (fn_type_id.cc == CallingConventionC) {
13921406 fn_type_id.param_count = fn_type_id.next_param_index;
13931407 continue;
1394 } else if (fn_type_id.cc == CallingConventionUnspecified) {
1408 } else if (calling_convention_allows_zig_types(fn_type_id.cc)) {
13951409 return get_generic_fn_type(g, &fn_type_id);
13961410 } else {
13971411 add_node_error(g, param_node,
......@@ -1405,7 +1419,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
14051419 if (type_is_invalid(type_entry)) {
14061420 return g->builtin_types.entry_invalid;
14071421 }
1408 if (fn_type_id.cc != CallingConventionUnspecified) {
1422 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
14091423 type_ensure_zero_bits_known(g, type_entry);
14101424 if (!type_has_bits(type_entry)) {
14111425 add_node_error(g, param_node->data.param_decl.type,
......@@ -1415,7 +1429,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
14151429 }
14161430 }
14171431
1418 if (fn_type_id.cc != CallingConventionUnspecified && !type_allowed_in_extern(g, type_entry)) {
1432 if (!calling_convention_allows_zig_types(fn_type_id.cc) && !type_allowed_in_extern(g, type_entry)) {
14191433 add_node_error(g, param_node->data.param_decl.type,
14201434 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",
14211435 buf_ptr(&type_entry->name),
......@@ -1435,7 +1449,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
14351449 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));
14361450 return g->builtin_types.entry_invalid;
14371451 case TypeTableEntryIdVar:
1438 if (fn_type_id.cc != CallingConventionUnspecified) {
1452 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
14391453 add_node_error(g, param_node->data.param_decl.type,
14401454 buf_sprintf("parameter of type 'var' not allowed in function with calling convention '%s'",
14411455 calling_convention_name(fn_type_id.cc)));
......@@ -1467,7 +1481,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
14671481 case TypeTableEntryIdFn:
14681482 case TypeTableEntryIdPromise:
14691483 ensure_complete_type(g, type_entry);
1470 if (fn_type_id.cc == CallingConventionUnspecified && !type_is_copyable(g, type_entry)) {
1484 if (calling_convention_allows_zig_types(fn_type_id.cc) && !type_is_copyable(g, type_entry)) {
14711485 add_node_error(g, param_node->data.param_decl.type,
14721486 buf_sprintf("type '%s' is not copyable; cannot pass by value", buf_ptr(&type_entry->name)));
14731487 return g->builtin_types.entry_invalid;
......@@ -1498,7 +1512,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
14981512 fn_type_id.return_type = specified_return_type;
14991513 }
15001514
1501 if (fn_type_id.cc != CallingConventionUnspecified && !type_allowed_in_extern(g, fn_type_id.return_type)) {
1515 if (!calling_convention_allows_zig_types(fn_type_id.cc) && !type_allowed_in_extern(g, fn_type_id.return_type)) {
15021516 add_node_error(g, fn_proto->return_type,
15031517 buf_sprintf("return type '%s' not allowed in function with calling convention '%s'",
15041518 buf_ptr(&fn_type_id.return_type->name),
......@@ -1525,7 +1539,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
15251539 case TypeTableEntryIdBoundFn:
15261540 case TypeTableEntryIdVar:
15271541 case TypeTableEntryIdMetaType:
1528 if (fn_type_id.cc != CallingConventionUnspecified) {
1542 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
15291543 add_node_error(g, fn_proto->return_type,
15301544 buf_sprintf("return type '%s' not allowed in function with calling convention '%s'",
15311545 buf_ptr(&fn_type_id.return_type->name),