mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #85460 from xedin/replace-checkconformancewithoutcontext-with-conformstoknownprotocol
[CSOptimizer] Use `conformsToKnownProtocol` to check whether paramete…
This commit is contained in:
@@ -1348,27 +1348,20 @@ static void determineBestChoicesInContext(
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
auto &ctx = cs.getASTContext();
|
||||
|
||||
// Check if the other side conforms to `ExpressibleByArrayLiteral`
|
||||
// protocol (in some way). We want an overly optimistic result
|
||||
// here to avoid under-favoring.
|
||||
if (candidateType->isArray() &&
|
||||
checkConformanceWithoutContext(
|
||||
paramType,
|
||||
ctx.getProtocol(KnownProtocolKind::ExpressibleByArrayLiteral),
|
||||
/*allowMissing=*/true))
|
||||
TypeChecker::conformsToKnownProtocol(
|
||||
paramType, KnownProtocolKind::ExpressibleByArrayLiteral))
|
||||
return 0.3;
|
||||
|
||||
// Check if the other side conforms to
|
||||
// `ExpressibleByDictionaryLiteral` protocol (in some way).
|
||||
// We want an overly optimistic result here to avoid under-favoring.
|
||||
if (candidateType->isDictionary() &&
|
||||
checkConformanceWithoutContext(
|
||||
paramType,
|
||||
ctx.getProtocol(
|
||||
KnownProtocolKind::ExpressibleByDictionaryLiteral),
|
||||
/*allowMissing=*/true))
|
||||
TypeChecker::conformsToKnownProtocol(
|
||||
paramType, KnownProtocolKind::ExpressibleByDictionaryLiteral))
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// RUN: %scale-test --begin 1 --end 15 --step 1 --select NumLeafScopes %s
|
||||
// REQUIRES: asserts,no_asan
|
||||
|
||||
struct MyIntValue: ExpressibleByArrayLiteral {
|
||||
init(arrayLiteral: Int...) {}
|
||||
}
|
||||
|
||||
func +(x: MyIntValue, y: MyIntValue) -> MyIntValue { [] }
|
||||
func +(x: MyIntValue, y: Int) -> MyIntValue { [] }
|
||||
|
||||
func test(y: Int) {
|
||||
%for i in range(0, N):
|
||||
[1] + y +
|
||||
%end
|
||||
[1] + y
|
||||
}
|
||||
Reference in New Issue
Block a user