authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-16 13:31:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-16 13:31:53-07:00
log94672dfb1941289eb65fdeab2e1dcc39ca70c3b7
treea28abab9a820840a1cbe8ebdaffa301020e5765e
parent92a09eb1e4d5914e5ea81c55c5feb322fcd90e7b

stage2: fully resolve fn types after analyzing its body


2 files changed, 28 insertions(+), 2 deletions(-)

src/Module.zig+15-2
......@@ -4739,7 +4739,8 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem
47394739 // map the comptime parameters to constant values and only emit arg AIR instructions
47404740 // for the runtime ones.
47414741 const fn_ty = decl.ty;
4742 const runtime_params_len = @intCast(u32, fn_ty.fnParamLen());
4742 const fn_ty_info = fn_ty.fnInfo();
4743 const runtime_params_len = @intCast(u32, fn_ty_info.param_types.len);
47434744 try inner_block.instructions.ensureTotalCapacityPrecise(gpa, runtime_params_len);
47444745 try sema.air_instructions.ensureUnusedCapacity(gpa, fn_info.total_params_len * 2); // * 2 for the `addType`
47454746 try sema.inst_map.ensureUnusedCapacity(gpa, fn_info.total_params_len);
......@@ -4771,7 +4772,7 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem
47714772 continue;
47724773 }
47734774 }
4774 const param_type = fn_ty.fnParamType(runtime_param_index);
4775 const param_type = fn_ty_info.param_types[runtime_param_index];
47754776 const opt_opv = sema.typeHasOnePossibleValue(&inner_block, param.src, param_type) catch |err| switch (err) {
47764777 error.NeededSourceLocation => unreachable,
47774778 error.GenericPoison => unreachable,
......@@ -4822,6 +4823,18 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) Sem
48224823 func.state = .success;
48234824 log.debug("set {s} to success", .{decl.name});
48244825
4826 // Finally we must resolve the return type and parameter types so that backends
4827 // have full access to type information.
4828 const src: LazySrcLoc = .{ .node_offset = 0 };
4829 sema.resolveFnTypes(&inner_block, src, fn_ty_info) catch |err| switch (err) {
4830 error.NeededSourceLocation => unreachable,
4831 error.GenericPoison => unreachable,
4832 error.ComptimeReturn => unreachable,
4833 error.ComptimeBreak => unreachable,
4834 error.AnalysisFail => {},
4835 else => |e| return e,
4836 };
4837
48254838 return Air{
48264839 .instructions = sema.air_instructions.toOwnedSlice(),
48274840 .extra = sema.air_extra.toOwnedSlice(gpa),
src/Sema.zig+13
......@@ -20006,6 +20006,19 @@ fn resolvePeerTypes(
2000620006 return chosen_ty;
2000720007}
2000820008
20009pub fn resolveFnTypes(
20010 sema: *Sema,
20011 block: *Block,
20012 src: LazySrcLoc,
20013 fn_info: Type.Payload.Function.Data,
20014) CompileError!void {
20015 try sema.resolveTypeFully(block, src, fn_info.return_type);
20016
20017 for (fn_info.param_types) |param_ty| {
20018 try sema.resolveTypeFully(block, src, param_ty);
20019 }
20020}
20021
2000920022fn resolveTypeLayout(
2001020023 sema: *Sema,
2001120024 block: *Block,