aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-07-26 22:51:16 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-07-27 10:12:08 -0700
commite66190025ffab39527da601980b7e3211069b6f5 (patch)
treea5ab77ea514c9993edcbd9335ad3904cebefd7bd /src/Sema.zig
parent9a3adeea6ef0eb30e75e732148e0a2b93d0d0c99 (diff)
downloadzig-e66190025ffab39527da601980b7e3211069b6f5.tar.gz
zig-e66190025ffab39527da601980b7e3211069b6f5.zip
frontend: make fn calls byval; fix false positive isNonErr
This commit does two things which seem unrelated at first, but, together, solve a miscompilation, and potentially slightly speed up compiler perf, at the expense of making #2765 trickier to implement in the future. Sema: avoid returning a false positive for whether an inferred error set is comptime-known to be empty. AstGen: mark function calls as not being interested in a result location. This prevents the test case "ret_ptr doesn't cause own inferred error set to be resolved" from being regressed. If we want to accept and implement #2765 in the future, it will require solving this problem a different way, but the principle of YAGNI tells us to go ahead with this change. Old ZIR looks like this: %97 = ret_ptr() %101 = store_node(%97, %100) %102 = load(%97) %103 = ret_is_non_err(%102) New ZIR looks like this: %97 = ret_type() %101 = as_node(%97, %100) %102 = ret_is_non_err(%101) closes #15669
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 3ae2ab96bd..4a4823df2d 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -30732,18 +30732,10 @@ fn analyzeIsNonErrComptimeOnly(
else => return .none,
},
}
- for (ies.inferred_error_sets.keys()) |other_ies_index| {
- if (set_ty == other_ies_index) continue;
- const other_resolved =
- try sema.resolveInferredErrorSet(block, src, other_ies_index);
- if (other_resolved == .anyerror_type) {
- ies.resolved = .anyerror_type;
- return .none;
- }
- if (ip.indexToKey(other_resolved).error_set_type.names.len != 0)
- return .none;
- }
- return .bool_true;
+ // We do not have a comptime answer because this inferred error
+ // set is not resolved, and an instruction later in this function
+ // body may or may not cause an error to be added to this set.
+ return .none;
},
else => switch (ip.indexToKey(set_ty)) {
.error_set_type => |error_set_type| {
@@ -30771,18 +30763,10 @@ fn analyzeIsNonErrComptimeOnly(
else => return .none,
},
}
- for (ies.inferred_error_sets.keys()) |other_ies_index| {
- if (set_ty == other_ies_index) continue;
- const other_resolved =
- try sema.resolveInferredErrorSet(block, src, other_ies_index);
- if (other_resolved == .anyerror_type) {
- ies.resolved = .anyerror_type;
- return .none;
- }
- if (ip.indexToKey(other_resolved).error_set_type.names.len != 0)
- return .none;
- }
- return .bool_true;
+ // We do not have a comptime answer because this inferred error
+ // set is not resolved, and an instruction later in this function
+ // body may or may not cause an error to be added to this set.
+ return .none;
}
}
const resolved_ty = try sema.resolveInferredErrorSet(block, src, set_ty);