Skip to content

Commit 80e6cbf

Browse files
authored
Merge pull request #85460 from xedin/replace-checkconformancewithoutcontext-with-conformstoknownprotocol
[CSOptimizer] Use `conformsToKnownProtocol` to check whether paramete…
2 parents bf26dbf + 62a9178 commit 80e6cbf

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,27 +1348,20 @@ static void determineBestChoicesInContext(
13481348
return 0.3;
13491349
}
13501350

1351-
auto &ctx = cs.getASTContext();
1352-
13531351
// Check if the other side conforms to `ExpressibleByArrayLiteral`
13541352
// protocol (in some way). We want an overly optimistic result
13551353
// here to avoid under-favoring.
13561354
if (candidateType->isArray() &&
1357-
checkConformanceWithoutContext(
1358-
paramType,
1359-
ctx.getProtocol(KnownProtocolKind::ExpressibleByArrayLiteral),
1360-
/*allowMissing=*/true))
1355+
TypeChecker::conformsToKnownProtocol(
1356+
paramType, KnownProtocolKind::ExpressibleByArrayLiteral))
13611357
return 0.3;
13621358

13631359
// Check if the other side conforms to
13641360
// `ExpressibleByDictionaryLiteral` protocol (in some way).
13651361
// We want an overly optimistic result here to avoid under-favoring.
13661362
if (candidateType->isDictionary() &&
1367-
checkConformanceWithoutContext(
1368-
paramType,
1369-
ctx.getProtocol(
1370-
KnownProtocolKind::ExpressibleByDictionaryLiteral),
1371-
/*allowMissing=*/true))
1363+
TypeChecker::conformsToKnownProtocol(
1364+
paramType, KnownProtocolKind::ExpressibleByDictionaryLiteral))
13721365
return 0.3;
13731366
}
13741367

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %scale-test --begin 1 --end 15 --step 1 --select NumLeafScopes %s
2+
// REQUIRES: asserts,no_asan
3+
4+
struct MyIntValue: ExpressibleByArrayLiteral {
5+
init(arrayLiteral: Int...) {}
6+
}
7+
8+
func +(x: MyIntValue, y: MyIntValue) -> MyIntValue { [] }
9+
func +(x: MyIntValue, y: Int) -> MyIntValue { [] }
10+
11+
func test(y: Int) {
12+
%for i in range(0, N):
13+
[1] + y +
14+
%end
15+
[1] + y
16+
}

0 commit comments

Comments
 (0)