Skip to content

Commit c2a0cc7

Browse files
authored
Merge pull request swiftlang#79402 from DougGregor/disable-closure-discriminator-check-noasserts-6.1
[6.1] Disable the crash in non-asserts builds when closures don't have a discriminator
2 parents a4f13dc + c44cb52 commit c2a0cc7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/AST/Expr.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,12 @@ unsigned AbstractClosureExpr::getDiscriminator() const {
19491949
evaluateOrDefault(
19501950
ctx.evaluator, LocalDiscriminatorsRequest{getParent()}, 0);
19511951

1952+
#if NDEBUG
1953+
static constexpr bool useFallbackDiscriminator = true;
1954+
#else
1955+
static constexpr bool useFallbackDiscriminator = false;
1956+
#endif
1957+
19521958
// If we don't have a discriminator, and either
19531959
// 1. We have ill-formed code and we're able to assign a discriminator, or
19541960
// 2. We are in a macro expansion buffer
@@ -1958,7 +1964,8 @@ unsigned AbstractClosureExpr::getDiscriminator() const {
19581964
if (getRawDiscriminator() == InvalidDiscriminator &&
19591965
(ctx.Diags.hadAnyError() ||
19601966
getParentSourceFile()->getFulfilledMacroRole() != std::nullopt ||
1961-
getParent()->isModuleScopeContext())) {
1967+
getParent()->isModuleScopeContext() ||
1968+
useFallbackDiscriminator)) {
19621969
auto discriminator = ctx.getNextDiscriminator(getParent());
19631970
ctx.setMaxAssignedDiscriminator(getParent(), discriminator + 1);
19641971
const_cast<AbstractClosureExpr *>(this)->

0 commit comments

Comments
 (0)