authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-12-18 00:30:16+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-12-21 01:41:50+01:00
log138f85bf258d3520591e4a5abfb6d5db7ae45d97
tree186349f134a5defe0896738ed908d5cbb5e52672
parent16bddecff99eafb6c60d2c7a406d92d9c2d3c35a

stage2: only create inferred error sets for inferred error set functions


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

src/Sema.zig+14-12
...@@ -3912,18 +3912,20 @@ fn analyzeCall(...@@ -3912,18 +3912,20 @@ fn analyzeCall(
3912 const ret_ty_inst = try sema.resolveBody(&child_block, fn_info.ret_ty_body);3912 const ret_ty_inst = try sema.resolveBody(&child_block, fn_info.ret_ty_body);
3913 const ret_ty_src = func_src; // TODO better source location3913 const ret_ty_src = func_src; // TODO better source location
3914 const bare_return_type = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);3914 const bare_return_type = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);
3915 // If the function has an inferred error set, `bare_return_type` is the payload type only.3915 // Create a fresh inferred error set type for inline/comptime calls.
3916 const fn_ret_ty = blk: {3916 const fn_ret_ty = blk: {
3917 if (func_ty_info.return_type.tag() == .error_union) {3917 if (func_ty_info.return_type.castTag(.error_union)) |payload| {
3918 const node = try sema.gpa.create(Module.Fn.InferredErrorSetListNode);3918 if (payload.data.error_set.tag() == .error_set_inferred) {
3919 node.data = .{ .func = module_fn };3919 const node = try sema.gpa.create(Module.Fn.InferredErrorSetListNode);
3920 parent_func.?.inferred_error_sets.prepend(node);3920 node.data = .{ .func = module_fn };
39213921 parent_func.?.inferred_error_sets.prepend(node);
3922 const error_set_ty = try Type.Tag.error_set_inferred.create(sema.arena, &node.data);3922
3923 break :blk try Type.Tag.error_union.create(sema.arena, .{3923 const error_set_ty = try Type.Tag.error_set_inferred.create(sema.arena, &node.data);
3924 .error_set = error_set_ty,3924 break :blk try Type.Tag.error_union.create(sema.arena, .{
3925 .payload = bare_return_type,3925 .error_set = error_set_ty,
3926 });3926 .payload = bare_return_type,
3927 });
3928 }
3927 }3929 }
3928 break :blk bare_return_type;3930 break :blk bare_return_type;
3929 };3931 };
...@@ -12473,7 +12475,7 @@ fn coerceInMemoryAllowed(...@@ -12473,7 +12475,7 @@ fn coerceInMemoryAllowed(
12473 dest_ty: Type,12475 dest_ty: Type,
12474 src_ty: Type,12476 src_ty: Type,
12475 dest_is_mut: bool,12477 dest_is_mut: bool,
12476 target: std.Target12478 target: std.Target,
12477) CompileError!InMemoryCoercionResult {12479) CompileError!InMemoryCoercionResult {
12478 if (dest_ty.eql(src_ty))12480 if (dest_ty.eql(src_ty))
12479 return .ok;12481 return .ok;