| author | |
| committer | |
| log | 7644e9a752ebe50c4372fae8ea0e8eaecb211508 |
| tree | 423ded389db49148c77ff5a3b36bb7dd4f0cccc7 |
| parent | 1c15091bc8d83b9464082afbdb62ecd9c9176cd6 |
| signature | Commit is signed but in an unrecognized format. |
4 files changed, 38 insertions(+), 42 deletions(-)
src/Module.zig+19-16| ... | @@ -1087,14 +1087,23 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { | ... | @@ -1087,14 +1087,23 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1087 | if (fn_proto.getSectionExpr()) |sect_expr| { | 1087 | if (fn_proto.getSectionExpr()) |sect_expr| { |
| 1088 | return self.failNode(&fn_type_scope.base, sect_expr, "TODO implement function section expression", .{}); | 1088 | return self.failNode(&fn_type_scope.base, sect_expr, "TODO implement function section expression", .{}); |
| 1089 | } | 1089 | } |
| 1090 | if (fn_proto.getCallconvExpr()) |callconv_expr| { | 1090 | |
| 1091 | return self.failNode( | 1091 | const enum_literal_type = try astgen.addZIRInstConst(self, &fn_type_scope.base, fn_src, .{ |
| 1092 | &fn_type_scope.base, | 1092 | .ty = Type.initTag(.type), |
| 1093 | callconv_expr, | 1093 | .val = Value.initTag(.enum_literal_type), |
| 1094 | "TODO implement function calling convention expression", | 1094 | }); |
| 1095 | .{}, | 1095 | const enum_literal_type_rl: astgen.ResultLoc = .{ .ty = enum_literal_type }; |
| 1096 | ); | 1096 | const cc = if (fn_proto.getCallconvExpr()) |callconv_expr| |
| 1097 | } | 1097 | try astgen.expr(self, &fn_type_scope.base, enum_literal_type_rl, callconv_expr) |
| 1098 | else | ||
| 1099 | try astgen.addZIRInstConst(self, &fn_type_scope.base, fn_src, .{ | ||
| 1100 | .ty = Type.initTag(.enum_literal), | ||
| 1101 | .val = try Value.Tag.enum_literal.create( | ||
| 1102 | &fn_type_scope_arena.allocator, | ||
| 1103 | try fn_type_scope_arena.allocator.dupe(u8, "Unspecified"), | ||
| 1104 | ), | ||
| 1105 | }); | ||
| 1106 | |||
| 1098 | const return_type_expr = switch (fn_proto.return_type) { | 1107 | const return_type_expr = switch (fn_proto.return_type) { |
| 1099 | .Explicit => |node| node, | 1108 | .Explicit => |node| node, |
| 1100 | .InferErrorSet => |node| return self.failNode(&fn_type_scope.base, node, "TODO implement inferred error sets", .{}), | 1109 | .InferErrorSet => |node| return self.failNode(&fn_type_scope.base, node, "TODO implement inferred error sets", .{}), |
| ... | @@ -1105,6 +1114,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { | ... | @@ -1105,6 +1114,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1105 | const fn_type_inst = try astgen.addZIRInst(self, &fn_type_scope.base, fn_src, zir.Inst.FnType, .{ | 1114 | const fn_type_inst = try astgen.addZIRInst(self, &fn_type_scope.base, fn_src, zir.Inst.FnType, .{ |
| 1106 | .return_type = return_type_inst, | 1115 | .return_type = return_type_inst, |
| 1107 | .param_types = param_types, | 1116 | .param_types = param_types, |
| 1117 | .cc = cc, | ||
| 1108 | }, .{}); | 1118 | }, .{}); |
| 1109 | 1119 | ||
| 1110 | if (std.builtin.mode == .Debug and self.comp.verbose_ir) { | 1120 | if (std.builtin.mode == .Debug and self.comp.verbose_ir) { |
| ... | @@ -1230,14 +1240,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { | ... | @@ -1230,14 +1240,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1230 | }; | 1240 | }; |
| 1231 | }; | 1241 | }; |
| 1232 | 1242 | ||
| 1233 | const is_inline = blk: { | 1243 | const is_inline = fn_type.fnCallingConvention() == .Inline; |
| 1234 | if (fn_proto.getExternExportInlineToken()) |maybe_inline_token| { | ||
| 1235 | if (tree.token_ids[maybe_inline_token] == .Keyword_inline) { | ||
| 1236 | break :blk true; | ||
| 1237 | } | ||
| 1238 | } | ||
| 1239 | break :blk false; | ||
| 1240 | }; | ||
| 1241 | const anal_state = ([2]Fn.Analysis{ .queued, .inline_only })[@boolToInt(is_inline)]; | 1244 | const anal_state = ([2]Fn.Analysis{ .queued, .inline_only })[@boolToInt(is_inline)]; |
| 1242 | 1245 | ||
| 1243 | new_func.* = .{ | 1246 | new_func.* = .{ |
src/type.zig+3-1| ... | @@ -552,7 +552,9 @@ pub const Type = extern union { | ... | @@ -552,7 +552,9 @@ pub const Type = extern union { |
| 552 | if (i != 0) try out_stream.writeAll(", "); | 552 | if (i != 0) try out_stream.writeAll(", "); |
| 553 | try param_type.format("", .{}, out_stream); | 553 | try param_type.format("", .{}, out_stream); |
| 554 | } | 554 | } |
| 555 | try out_stream.writeAll(") "); | 555 | try out_stream.writeAll(") callconv(."); |
| 556 | try out_stream.writeAll(@tagName(payload.cc)); | ||
| 557 | try out_stream.writeAll(")"); | ||
| 556 | ty = payload.return_type; | 558 | ty = payload.return_type; |
| 557 | continue; | 559 | continue; |
| 558 | }, | 560 | }, |
src/zir.zig+3-6| ... | @@ -863,9 +863,7 @@ pub const Inst = struct { | ... | @@ -863,9 +863,7 @@ pub const Inst = struct { |
| 863 | fn_type: *Inst, | 863 | fn_type: *Inst, |
| 864 | body: Body, | 864 | body: Body, |
| 865 | }, | 865 | }, |
| 866 | kw_args: struct { | 866 | kw_args: struct {}, |
| 867 | is_inline: bool = false, | ||
| 868 | }, | ||
| 869 | }; | 867 | }; |
| 870 | 868 | ||
| 871 | pub const FnType = struct { | 869 | pub const FnType = struct { |
| ... | @@ -875,10 +873,9 @@ pub const Inst = struct { | ... | @@ -875,10 +873,9 @@ pub const Inst = struct { |
| 875 | positionals: struct { | 873 | positionals: struct { |
| 876 | param_types: []*Inst, | 874 | param_types: []*Inst, |
| 877 | return_type: *Inst, | 875 | return_type: *Inst, |
| 876 | cc: *Inst, | ||
| 878 | }, | 877 | }, |
| 879 | kw_args: struct { | 878 | kw_args: struct {}, |
| 880 | cc: std.builtin.CallingConvention = .Unspecified, | ||
| 881 | }, | ||
| 882 | }; | 879 | }; |
| 883 | 880 | ||
| 884 | pub const IntType = struct { | 881 | pub const IntType = struct { |
src/zir_sema.zig+13-19| ... | @@ -980,18 +980,8 @@ fn zirCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst { | ... | @@ -980,18 +980,8 @@ fn zirCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError!*Inst { |
| 980 | 980 | ||
| 981 | const b = try mod.requireFunctionBlock(scope, inst.base.src); | 981 | const b = try mod.requireFunctionBlock(scope, inst.base.src); |
| 982 | const is_comptime_call = b.is_comptime or inst.kw_args.modifier == .compile_time; | 982 | const is_comptime_call = b.is_comptime or inst.kw_args.modifier == .compile_time; |
| 983 | const is_inline_call = is_comptime_call or inst.kw_args.modifier == .always_inline or blk: { | 983 | const is_inline_call = is_comptime_call or inst.kw_args.modifier == .always_inline or |
| 984 | // This logic will get simplified by | 984 | func.ty.fnCallingConvention() == .Inline; |
| 985 | // https://github.com/ziglang/zig/issues/6429 | ||
| 986 | if (try mod.resolveDefinedValue(scope, func)) |func_val| { | ||
| 987 | const module_fn = switch (func_val.tag()) { | ||
| 988 | .function => func_val.castTag(.function).?.data, | ||
| 989 | else => break :blk false, | ||
| 990 | }; | ||
| 991 | break :blk module_fn.state == .inline_only; | ||
| 992 | } | ||
| 993 | break :blk false; | ||
| 994 | }; | ||
| 995 | if (is_inline_call) { | 985 | if (is_inline_call) { |
| 996 | const func_val = try mod.resolveConstValue(scope, func); | 986 | const func_val = try mod.resolveConstValue(scope, func); |
| 997 | const module_fn = switch (func_val.tag()) { | 987 | const module_fn = switch (func_val.tag()) { |
| ... | @@ -1075,7 +1065,7 @@ fn zirFn(mod: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!*Inst { | ... | @@ -1075,7 +1065,7 @@ fn zirFn(mod: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!*Inst { |
| 1075 | const fn_type = try resolveType(mod, scope, fn_inst.positionals.fn_type); | 1065 | const fn_type = try resolveType(mod, scope, fn_inst.positionals.fn_type); |
| 1076 | const new_func = try scope.arena().create(Module.Fn); | 1066 | const new_func = try scope.arena().create(Module.Fn); |
| 1077 | new_func.* = .{ | 1067 | new_func.* = .{ |
| 1078 | .state = if (fn_inst.kw_args.is_inline) .inline_only else .queued, | 1068 | .state = if (fn_type.fnCallingConvention() == .Inline) .inline_only else .queued, |
| 1079 | .zir = fn_inst.positionals.body, | 1069 | .zir = fn_inst.positionals.body, |
| 1080 | .body = undefined, | 1070 | .body = undefined, |
| 1081 | .owner_decl = scope.ownerDecl().?, | 1071 | .owner_decl = scope.ownerDecl().?, |
| ... | @@ -1305,22 +1295,26 @@ fn zirFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!* | ... | @@ -1305,22 +1295,26 @@ fn zirFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!* |
| 1305 | const tracy = trace(@src()); | 1295 | const tracy = trace(@src()); |
| 1306 | defer tracy.end(); | 1296 | defer tracy.end(); |
| 1307 | const return_type = try resolveType(mod, scope, fntype.positionals.return_type); | 1297 | const return_type = try resolveType(mod, scope, fntype.positionals.return_type); |
| 1298 | const cc_tv = try resolveInstConst(mod, scope, fntype.positionals.cc); | ||
| 1299 | const cc_str = cc_tv.val.castTag(.enum_literal).?.data; | ||
| 1300 | const cc = std.meta.stringToEnum(std.builtin.CallingConvention, cc_str) orelse | ||
| 1301 | return mod.fail(scope, fntype.positionals.cc.src, "Unknown calling convention {s}", .{cc_str}); | ||
| 1308 | 1302 | ||
| 1309 | // Hot path for some common function types. | 1303 | // Hot path for some common function types. |
| 1310 | if (fntype.positionals.param_types.len == 0) { | 1304 | if (fntype.positionals.param_types.len == 0) { |
| 1311 | if (return_type.zigTypeTag() == .NoReturn and fntype.kw_args.cc == .Unspecified) { | 1305 | if (return_type.zigTypeTag() == .NoReturn and cc == .Unspecified) { |
| 1312 | return mod.constType(scope, fntype.base.src, Type.initTag(.fn_noreturn_no_args)); | 1306 | return mod.constType(scope, fntype.base.src, Type.initTag(.fn_noreturn_no_args)); |
| 1313 | } | 1307 | } |
| 1314 | 1308 | ||
| 1315 | if (return_type.zigTypeTag() == .Void and fntype.kw_args.cc == .Unspecified) { | 1309 | if (return_type.zigTypeTag() == .Void and cc == .Unspecified) { |
| 1316 | return mod.constType(scope, fntype.base.src, Type.initTag(.fn_void_no_args)); | 1310 | return mod.constType(scope, fntype.base.src, Type.initTag(.fn_void_no_args)); |
| 1317 | } | 1311 | } |
| 1318 | 1312 | ||
| 1319 | if (return_type.zigTypeTag() == .NoReturn and fntype.kw_args.cc == .Naked) { | 1313 | if (return_type.zigTypeTag() == .NoReturn and cc == .Naked) { |
| 1320 | return mod.constType(scope, fntype.base.src, Type.initTag(.fn_naked_noreturn_no_args)); | 1314 | return mod.constType(scope, fntype.base.src, Type.initTag(.fn_naked_noreturn_no_args)); |
| 1321 | } | 1315 | } |
| 1322 | 1316 | ||
| 1323 | if (return_type.zigTypeTag() == .Void and fntype.kw_args.cc == .C) { | 1317 | if (return_type.zigTypeTag() == .Void and cc == .C) { |
| 1324 | return mod.constType(scope, fntype.base.src, Type.initTag(.fn_ccc_void_no_args)); | 1318 | return mod.constType(scope, fntype.base.src, Type.initTag(.fn_ccc_void_no_args)); |
| 1325 | } | 1319 | } |
| 1326 | } | 1320 | } |
| ... | @@ -1337,9 +1331,9 @@ fn zirFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!* | ... | @@ -1337,9 +1331,9 @@ fn zirFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!* |
| 1337 | } | 1331 | } |
| 1338 | 1332 | ||
| 1339 | const fn_ty = try Type.Tag.function.create(arena, .{ | 1333 | const fn_ty = try Type.Tag.function.create(arena, .{ |
| 1340 | .cc = fntype.kw_args.cc, | ||
| 1341 | .return_type = return_type, | ||
| 1342 | .param_types = param_types, | 1334 | .param_types = param_types, |
| 1335 | .return_type = return_type, | ||
| 1336 | .cc = cc, | ||
| 1343 | }); | 1337 | }); |
| 1344 | return mod.constType(scope, fntype.base.src, fn_ty); | 1338 | return mod.constType(scope, fntype.base.src, fn_ty); |
| 1345 | } | 1339 | } |