@@ -7733,123 +7733,117 @@ fn analyzeCall(
7733
7733
} }));
7734
7734
}
7735
7735
7736
- // This `res2` is here instead of directly breaking from `res` due to a stage1
7737
- // bug generating invalid LLVM IR.
7738
- const res2: Air.Inst.Ref = res2: {
7739
- memoize: {
7740
- if (!should_memoize) break :memoize;
7741
- if (!is_comptime_call) break :memoize;
7742
- const memoized_call_index = ip.getIfExists(.{
7743
- .memoized_call = .{
7744
- .func = module_fn_index,
7745
- .arg_values = memoized_arg_values,
7746
- .result = undefined, // ignored by hash+eql
7747
- .branch_count = undefined, // ignored by hash+eql
7748
- },
7749
- }) orelse break :memoize;
7750
- const memoized_call = ip.indexToKey(memoized_call_index).memoized_call;
7751
- if (sema.branch_count + memoized_call.branch_count > sema.branch_quota) {
7752
- // Let the call play out se we get the correct source location for the
7753
- // "evaluation exceeded X backwards branches" error.
7754
- break :memoize;
7755
- }
7756
- sema.branch_count += memoized_call.branch_count;
7757
- break :res2 Air.internedToRef(memoized_call.result);
7736
+ memoize: {
7737
+ if (!should_memoize) break :memoize;
7738
+ if (!is_comptime_call) break :memoize;
7739
+ const memoized_call_index = ip.getIfExists(.{
7740
+ .memoized_call = .{
7741
+ .func = module_fn_index,
7742
+ .arg_values = memoized_arg_values,
7743
+ .result = undefined, // ignored by hash+eql
7744
+ .branch_count = undefined, // ignored by hash+eql
7745
+ },
7746
+ }) orelse break :memoize;
7747
+ const memoized_call = ip.indexToKey(memoized_call_index).memoized_call;
7748
+ if (sema.branch_count + memoized_call.branch_count > sema.branch_quota) {
7749
+ // Let the call play out se we get the correct source location for the
7750
+ // "evaluation exceeded X backwards branches" error.
7751
+ break :memoize;
7758
7752
}
7753
+ sema.branch_count += memoized_call.branch_count;
7754
+ break :res Air.internedToRef(memoized_call.result);
7755
+ }
7759
7756
7760
- new_fn_info.return_type = sema.fn_ret_ty.toIntern();
7761
- if (!is_comptime_call and !block.is_typeof) {
7762
- const zir_tags = sema.code.instructions.items(.tag);
7763
- for (fn_info.param_body) |param| switch (zir_tags[@intFromEnum(param)]) {
7764
- .param, .param_comptime => {
7765
- const inst_data = sema.code.instructions.items(.data)[@intFromEnum(param)].pl_tok;
7766
- const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index);
7767
- const param_name = sema.code.nullTerminatedString(extra.data.name);
7768
- const inst = sema.inst_map.get(param).?;
7769
-
7770
- try sema.addDbgVar(&child_block, inst, .dbg_var_val, param_name);
7771
- },
7772
- .param_anytype, .param_anytype_comptime => {
7773
- const inst_data = sema.code.instructions.items(.data)[@intFromEnum(param)].str_tok;
7774
- const param_name = inst_data.get(sema.code);
7775
- const inst = sema.inst_map.get(param).?;
7757
+ new_fn_info.return_type = sema.fn_ret_ty.toIntern();
7758
+ if (!is_comptime_call and !block.is_typeof) {
7759
+ const zir_tags = sema.code.instructions.items(.tag);
7760
+ for (fn_info.param_body) |param| switch (zir_tags[@intFromEnum(param)]) {
7761
+ .param, .param_comptime => {
7762
+ const inst_data = sema.code.instructions.items(.data)[@intFromEnum(param)].pl_tok;
7763
+ const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index);
7764
+ const param_name = sema.code.nullTerminatedString(extra.data.name);
7765
+ const inst = sema.inst_map.get(param).?;
7766
+
7767
+ try sema.addDbgVar(&child_block, inst, .dbg_var_val, param_name);
7768
+ },
7769
+ .param_anytype, .param_anytype_comptime => {
7770
+ const inst_data = sema.code.instructions.items(.data)[@intFromEnum(param)].str_tok;
7771
+ const param_name = inst_data.get(sema.code);
7772
+ const inst = sema.inst_map.get(param).?;
7776
7773
7777
- try sema.addDbgVar(&child_block, inst, .dbg_var_val, param_name);
7778
- },
7779
- else => continue,
7780
- };
7781
- }
7774
+ try sema.addDbgVar(&child_block, inst, .dbg_var_val, param_name);
7775
+ },
7776
+ else => continue,
7777
+ };
7778
+ }
7782
7779
7783
- if (is_comptime_call and ensure_result_used) {
7784
- try sema.ensureResultUsed(block, sema.fn_ret_ty, call_src);
7785
- }
7780
+ if (is_comptime_call and ensure_result_used) {
7781
+ try sema.ensureResultUsed(block, sema.fn_ret_ty, call_src);
7782
+ }
7786
7783
7787
- if (is_comptime_call or block.is_typeof) {
7788
- // Save the error trace as our first action in the function
7789
- // to match the behavior of runtime function calls.
7790
- const error_return_trace_index = try sema.analyzeSaveErrRetIndex(&child_block);
7791
- sema.error_return_trace_index_on_fn_entry = error_return_trace_index;
7792
- child_block.error_return_trace_index = error_return_trace_index;
7793
- }
7784
+ if (is_comptime_call or block.is_typeof) {
7785
+ // Save the error trace as our first action in the function
7786
+ // to match the behavior of runtime function calls.
7787
+ const error_return_trace_index = try sema.analyzeSaveErrRetIndex(&child_block);
7788
+ sema.error_return_trace_index_on_fn_entry = error_return_trace_index;
7789
+ child_block.error_return_trace_index = error_return_trace_index;
7790
+ }
7794
7791
7795
- // We temporarily set `allow_memoize` to `true` to track this comptime call.
7796
- // It is restored after this call finishes analysis, so that a caller may
7797
- // know whether an in-progress call (containing this call) may be memoized.
7798
- const old_allow_memoize = sema.allow_memoize;
7799
- defer sema.allow_memoize = old_allow_memoize and sema.allow_memoize;
7800
- sema.allow_memoize = true;
7792
+ // We temporarily set `allow_memoize` to `true` to track this comptime call.
7793
+ // It is restored after this call finishes analysis, so that a caller may
7794
+ // know whether an in-progress call (containing this call) may be memoized.
7795
+ const old_allow_memoize = sema.allow_memoize;
7796
+ defer sema.allow_memoize = old_allow_memoize and sema.allow_memoize;
7797
+ sema.allow_memoize = true;
7801
7798
7802
- // Store the current eval branch count so we can find out how many eval branches
7803
- // the comptime call caused.
7804
- const old_branch_count = sema.branch_count;
7799
+ // Store the current eval branch count so we can find out how many eval branches
7800
+ // the comptime call caused.
7801
+ const old_branch_count = sema.branch_count;
7805
7802
7806
- const result = result: {
7807
- sema.analyzeFnBody(&child_block, fn_info.body) catch |err| switch (err) {
7808
- error.ComptimeReturn => break :result inlining.comptime_result,
7809
- else => |e| return e,
7810
- };
7811
- break :result try sema.resolveAnalyzedBlock(block, call_src, &child_block, merges, need_debug_scope);
7803
+ const result = result: {
7804
+ sema.analyzeFnBody(&child_block, fn_info.body) catch |err| switch (err) {
7805
+ error.ComptimeReturn => break :result inlining.comptime_result,
7806
+ else => |e| return e,
7812
7807
};
7808
+ break :result try sema.resolveAnalyzedBlock(block, call_src, &child_block, merges, need_debug_scope);
7809
+ };
7813
7810
7814
- if (is_comptime_call) {
7815
- const result_val = try sema.resolveConstValue(block, LazySrcLoc.unneeded, result, undefined);
7816
- const result_interned = result_val.toIntern();
7817
-
7818
- // Transform ad-hoc inferred error set types into concrete error sets.
7819
- const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_interned);
7820
-
7821
- // If the result can mutate comptime vars, we must not memoize it, as it contains
7822
- // a reference to `comptime_allocs` so is not stable across instances of `Sema`.
7823
- // TODO: check whether any external comptime memory was mutated by the
7824
- // comptime function call. If so, then do not memoize the call here.
7825
- if (should_memoize and sema.allow_memoize and !Value.fromInterned(result_interned).canMutateComptimeVarState(zcu)) {
7826
- _ = try pt.intern(.{ .memoized_call = .{
7827
- .func = module_fn_index,
7828
- .arg_values = memoized_arg_values,
7829
- .result = result_transformed,
7830
- .branch_count = sema.branch_count - old_branch_count,
7831
- } });
7832
- }
7833
-
7834
- break :res2 Air.internedToRef(result_transformed);
7811
+ if (is_comptime_call) {
7812
+ const result_val = try sema.resolveConstValue(block, LazySrcLoc.unneeded, result, undefined);
7813
+ const result_interned = result_val.toIntern();
7814
+
7815
+ // Transform ad-hoc inferred error set types into concrete error sets.
7816
+ const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_interned);
7817
+
7818
+ // If the result can mutate comptime vars, we must not memoize it, as it contains
7819
+ // a reference to `comptime_allocs` so is not stable across instances of `Sema`.
7820
+ // TODO: check whether any external comptime memory was mutated by the
7821
+ // comptime function call. If so, then do not memoize the call here.
7822
+ if (should_memoize and sema.allow_memoize and !Value.fromInterned(result_interned).canMutateComptimeVarState(zcu)) {
7823
+ _ = try pt.intern(.{ .memoized_call = .{
7824
+ .func = module_fn_index,
7825
+ .arg_values = memoized_arg_values,
7826
+ .result = result_transformed,
7827
+ .branch_count = sema.branch_count - old_branch_count,
7828
+ } });
7835
7829
}
7836
7830
7837
- if (try sema.resolveValue(result)) |result_val| {
7838
- const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_val.toIntern());
7839
- break :res2 Air.internedToRef(result_transformed);
7840
- }
7831
+ break :res Air.internedToRef(result_transformed);
7832
+ }
7841
7833
7842
- const new_ty = try sema.resolveAdHocInferredErrorSetTy(block, call_src, sema.typeOf(result).toIntern());
7843
- if (new_ty != .none) {
7844
- // TODO: mutate in place the previous instruction if possible
7845
- // rather than adding a bitcast instruction.
7846
- break :res2 try block.addBitCast(Type.fromInterned(new_ty), result);
7847
- }
7834
+ if (try sema.resolveValue(result)) |result_val| {
7835
+ const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_val.toIntern());
7836
+ break :res Air.internedToRef(result_transformed);
7837
+ }
7848
7838
7849
- break :res2 result;
7850
- };
7839
+ const new_ty = try sema.resolveAdHocInferredErrorSetTy(block, call_src, sema.typeOf(result).toIntern());
7840
+ if (new_ty != .none) {
7841
+ // TODO: mutate in place the previous instruction if possible
7842
+ // rather than adding a bitcast instruction.
7843
+ break :res try block.addBitCast(Type.fromInterned(new_ty), result);
7844
+ }
7851
7845
7852
- break :res res2 ;
7846
+ break :res result ;
7853
7847
} else res: {
7854
7848
assert(!func_ty_info.is_generic);
7855
7849
0 commit comments