Skip to content

Commit 62a9178

Browse files
committed
[CSOptimizer] Use conformsToKnownProtocol to check whether parameter conforms to ExpressibleBy{Array, Dictionary}Literal
The existing check is no-op because it would never produce a null for `paramType` under the conditions in `else` branch. A better API it use here is `conformsToKnownProtocol` just like in other cases.
1 parent a604d99 commit 62a9178

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
@@ -1316,27 +1316,20 @@ static void determineBestChoicesInContext(
13161316
return 0.3;
13171317
}
13181318

1319-
auto &ctx = cs.getASTContext();
1320-
13211319
// Check if the other side conforms to `ExpressibleByArrayLiteral`
13221320
// protocol (in some way). We want an overly optimistic result
13231321
// here to avoid under-favoring.
13241322
if (candidateType->isArray() &&
1325-
checkConformanceWithoutContext(
1326-
paramType,
1327-
ctx.getProtocol(KnownProtocolKind::ExpressibleByArrayLiteral),
1328-
/*allowMissing=*/true))
1323+
TypeChecker::conformsToKnownProtocol(
1324+
paramType, KnownProtocolKind::ExpressibleByArrayLiteral))
13291325
return 0.3;
13301326

13311327
// Check if the other side conforms to
13321328
// `ExpressibleByDictionaryLiteral` protocol (in some way).
13331329
// We want an overly optimistic result here to avoid under-favoring.
13341330
if (candidateType->isDictionary() &&
1335-
checkConformanceWithoutContext(
1336-
paramType,
1337-
ctx.getProtocol(
1338-
KnownProtocolKind::ExpressibleByDictionaryLiteral),
1339-
/*allowMissing=*/true))
1331+
TypeChecker::conformsToKnownProtocol(
1332+
paramType, KnownProtocolKind::ExpressibleByDictionaryLiteral))
13401333
return 0.3;
13411334
}
13421335

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)