authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-21 13:33:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-21 17:03:04-07:00
logaf9a2c7c50802435213b1f7eab0874f08ea0f19a
tree99ce1aea836f6ba7429ef96d3949d6eb3056b74e
parentfee5aad699232d4feeece72f345d09d67faf1494

Sema: don't miscompile fns with inferred error sets


1 files changed, 12 insertions(+), 10 deletions(-)

src/Sema.zig+12-10
...@@ -1069,19 +1069,17 @@ fn zirOpaqueDecl(...@@ -1069,19 +1069,17 @@ fn zirOpaqueDecl(
1069 inst: Zir.Inst.Index,1069 inst: Zir.Inst.Index,
1070 name_strategy: Zir.Inst.NameStrategy,1070 name_strategy: Zir.Inst.NameStrategy,
1071) InnerError!*Inst {1071) InnerError!*Inst {
1072 _ = name_strategy;
1073 const tracy = trace(@src());1072 const tracy = trace(@src());
1074 defer tracy.end();1073 defer tracy.end();
10751074
1076 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;1075 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1077 const src = inst_data.src();1076 const src = inst_data.src();
1078 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);1077 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
1079 if (false) {
1080 inst_data;
1081 src;
1082 extra;
1083 }
10841078
1079 _ = name_strategy;
1080 _ = inst_data;
1081 _ = src;
1082 _ = extra;
1085 return sema.mod.fail(&block.base, sema.src, "TODO implement zirOpaqueDecl", .{});1083 return sema.mod.fail(&block.base, sema.src, "TODO implement zirOpaqueDecl", .{});
1086}1084}
10871085
...@@ -1244,8 +1242,7 @@ fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In...@@ -1244,8 +1242,7 @@ fn zirArg(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*In
12441242
1245 // TODO check if arg_name shadows a Decl1243 // TODO check if arg_name shadows a Decl
12461244
1247 if (block.inlining) |inlining| {1245 if (block.inlining) |_| {
1248 _ = inlining;
1249 return sema.param_inst_list[arg_index];1246 return sema.param_inst_list[arg_index];
1250 }1247 }
12511248
...@@ -3067,7 +3064,6 @@ fn funcCommon(...@@ -3067,7 +3064,6 @@ fn funcCommon(
3067 src_locs: Zir.Inst.Func.SrcLocs,3064 src_locs: Zir.Inst.Func.SrcLocs,
3068 opt_lib_name: ?[]const u8,3065 opt_lib_name: ?[]const u8,
3069) InnerError!*Inst {3066) InnerError!*Inst {
3070 _ = inferred_error_set;
3071 const src: LazySrcLoc = .{ .node_offset = src_node_offset };3067 const src: LazySrcLoc = .{ .node_offset = src_node_offset };
3072 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };3068 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };
3073 const return_type = try sema.resolveType(block, ret_ty_src, zir_return_type);3069 const return_type = try sema.resolveType(block, ret_ty_src, zir_return_type);
...@@ -3076,7 +3072,9 @@ fn funcCommon(...@@ -3076,7 +3072,9 @@ fn funcCommon(
30763072
3077 const fn_ty: Type = fn_ty: {3073 const fn_ty: Type = fn_ty: {
3078 // Hot path for some common function types.3074 // Hot path for some common function types.
3079 if (zir_param_types.len == 0 and !var_args and align_val.tag() == .null_value) {3075 if (zir_param_types.len == 0 and !var_args and align_val.tag() == .null_value and
3076 !inferred_error_set)
3077 {
3080 if (return_type.zigTypeTag() == .NoReturn and cc == .Unspecified) {3078 if (return_type.zigTypeTag() == .NoReturn and cc == .Unspecified) {
3081 break :fn_ty Type.initTag(.fn_noreturn_no_args);3079 break :fn_ty Type.initTag(.fn_noreturn_no_args);
3082 }3080 }
...@@ -3107,6 +3105,10 @@ fn funcCommon(...@@ -3107,6 +3105,10 @@ fn funcCommon(
3107 return mod.fail(&block.base, src, "TODO implement support for function prototypes to have alignment specified", .{});3105 return mod.fail(&block.base, src, "TODO implement support for function prototypes to have alignment specified", .{});
3108 }3106 }
31093107
3108 if (inferred_error_set) {
3109 return mod.fail(&block.base, src, "TODO implement functions with inferred error sets", .{});
3110 }
3111
3110 break :fn_ty try Type.Tag.function.create(sema.arena, .{3112 break :fn_ty try Type.Tag.function.create(sema.arena, .{
3111 .param_types = param_types,3113 .param_types = param_types,
3112 .return_type = return_type,3114 .return_type = return_type,