mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* Revert "[CSOptimizer] Look through `OptionalEvaluationExpr`s when dealing with unapplied disjunctions" This reverts commit72340f39b8. * Revert "[CSOptimizer] Don't consider disabled overloads when checking whether disjunction is supported" This reverts commit6bc23b5057. * Revert "[CSOptimizer] Disjunctions with IUO overload choices are unsupported" This reverts commit471ee21535. * Revert "[CSOptimizer] MemberImportVisibility: Don't consider overloads that come from implicit imports" This reverts commitaa4a2b9071. * Revert "[CSOptimizer] Don't consider CGFloat widening when explicit initializer is used" This reverts commit3cc76eacdd. * Revert "[CSOptimizer] Literal arguments should cause score reset only for operators" This reverts commite3987beffb. * Revert "[CSOptimizer] NFC: check whether a choice is of operator instead of whole disjunction" This reverts commit6c82892c3c. * Revert "[CSOptimizer/Tests] NFC: Add a perf test-case fixed by improved literal array handling" This reverts commitcfd34e54c4. * Revert "[CSOptimizer] Extend candidate/parameter matching to support array literals" This reverts commit8a304f88c6. * Revert "[CSOptimizer] Favor choices that don't require application" This reverts commit0737542da8. * Revert "[CSOptimizer] Disable CGFloat -> Double conversion for unary operators" This reverts commitbc3a15fbe6. * Revert "[CSOptimizer] Mark bitwise operators as supported" This reverts commit860ae08d1b. * Revert "[CSOptimizer] Simplify handling of non-applied disjunctions" This reverts commit43ca7dfff9. * Revert "[ConstraintSystem] Fix `getEffectiveOverloadType` handling of `mutating` methods" This reverts commitc767f7aff7. * Revert "[CSOptimizer] Reduce overload types before ranking" This reverts commit95b47aead6. * Revert "[CSOptimizer] Implement special prioritization rules for result builder contexts" This reverts commit56d6635e46. * Revert "[CSOptimizer] Allow only widening CGFloat->Double conversions while matching candidate arguments" This reverts commitbf8ae3bc1b. * Revert "[CSSimplify] CGFloat-Double: Rank narrowing correctly when result is injected into an optional" This reverts commitcb876cbd9e. * Revert "[CSBindings] Prevent `BindingSet::isViable` from dropping viable bindings (v2)" This reverts commitb7e7493076. * Revert "[CSOptimizer] Add support for chained members without arguments" This reverts commit87cd5f8733. * Revert "[CSOptimizer] Mark compiler synthesized disjunctions as optimized" This reverts commit867e64182f. * Revert "[CSOptimizer] Make a light-weight generic overload check if some requirements are unsatisfiable" This reverts commit15c773b9d7. * Revert "[CSOptimizer] Fix `selectDisjunction` to use favored choices even if disjunction was not optimized" This reverts commitc2a55886f0. * Revert "[CSOptimizer] Limit "old" behavior compatibility to unlabeled unary arguments" This reverts commit9fb73143f6. * Revert "[Tests] NFC: Update a couple of type-checker tests" This reverts commitff8663ff16. * Revert "[Tests] NFC: Move simd related test-case from `slow` to `fast`" This reverts commit28396a6dce. * Revert "[CSGen] NFC: Remove obsolete `ConstraintSystem::{get, set}FavoredType`" This reverts commit8bd288447f. * Revert "[CSOptimizer] Allow literal arguments to match parameters that conform to `ExpressibleBy{Integer, Float}Literal`" This reverts commit2fdd4b6c35. * Revert "[CSOptimizer] Adjust `scoreCandidateMatch` to indicate when match cannot be decided" This reverts commit9b62c84a4f. * Revert "[CSOptimizer] Fix Double<->CGFloat implicit conversion support when arguments are literals" This reverts commit6caf1ccbb2. * Revert "[CSOptimizer] A more comprehensive generic overload checking when candidates are fully resolved" This reverts commite30587bda4. * Revert "[CSOptimizer] Restore old hack behavior which used to favor overloads based on arity matches" This reverts commita3a3ec4fe0. * Revert "[CSOptimizer] Desugar types before checking for equality" This reverts commit802f5cd105. * Revert "[ConstraintSystem] Narrowly disable `tryOptimizeGenericDisjunction` when some of the arguments are number literals" This reverts commit8d5cb112ef. * Revert "[CSOptimizer] Infer argument candidates from calls to `Double` and CGFloat constructors" This reverts commitf2a6677a6d. * Revert "[CSOptimizer] Score all of the overload choices matching on literals uniformly" This reverts commit59109c2d60. * Revert "[CSOptimizer] Enable ranking of `Int*`, `Float{80}` and `Double` initializers" This reverts commit6fb6d1cf90. * Revert "[CSOptimizer] Rank disjunctions based on score only if both sides are supported" This reverts commit8818d399f9. * Revert "[CSOptimizer] Rank results of operators regardless of whether anything is known about parameters" This reverts commit3996b25fbd. * Revert "[Tests] NFC: Add more test-cases that were previously solved due to old hacks behavior" This reverts commitd0ff6c81b8. * Revert "[CSOptimizer] Average score should reflect number of defaulted parameters" This reverts commit23589add74. * Revert "[Tests] NFC: Adjust a couple of improved tests" This reverts commit66981364fe. * Revert "[CSOptimizer] Don't optimize (implicit) calls with code completion arguments" This reverts commit8a918e2369. * Revert "[CSOptimizer] attempt to rank only standard/simd operators and fully concrete overload sets" This reverts commitdeca9b61c5. * Revert "[CSOptimizer] Record best scores for each disjunction and use them in `selectDisjunction`" This reverts commit3819ddfb40. * Revert "[CSOptimizer] Let `determineBestChoicesInContext` return the best disjunction if one is available" This reverts commitcf05405eae. * Revert "[CSOptimizer] Emulate old behavior related to favoring of unary calls to members" This reverts commit527de22bec. * Revert "[Tests] NFC: Add a test-case for rdar://133340307 which is now fast" This reverts commit670127abd6. * Revert "[CSOptimizer] Prefer homogeneous arithmetic operator overloads when argument(s) or result match" This reverts commitd69b6a0594. * Revert "[CSOptimizer] Remove an outdated optimization to compare resolved argument types with all else equal" This reverts commit1760bd1f1e. * Revert "[CSOptimizer] NFC: Switch from llvm::Optional to std::optional post-rebase" This reverts commitc429f5b9ec. * Revert "[CSOptimizer] Increase score when type matches opaque type" This reverts commit2869dff995. * Revert "[CSOptimizer] NFC: Switch to llvm::Optional" This reverts commit0fc6806922. * Revert "[CSOptimizer] NFC: Adjust conformance check to use `ConstraintSystem::lookupConformance`" This reverts commitda65333d41. * Revert "[CSOptimizer] Treat all type parameters equally" This reverts commit957a5f4270. * Revert "[CSStep] Remove disjunction pruning logic from DisjunctionStep" This reverts commit2c44e37948. * Revert "[CSOptimizer] Relax candidate type requirements from equality to set of no-impact conversions" This reverts commit11b897b32f. * Revert "[CSOptimizer] Use `matchCallArguments` to establish argument-to-parameter relationships" This reverts commitcb1cb2018d. * Revert "[CSOptimizer] Don't attempt to optimize calls with code completion token(s) in argument position" This reverts commit14e2a16fce. * Revert "[CSOptimizer] Allow generic operator overloads without associated type parameters" This reverts commitbc5f70a9a3. * Revert "[CSOptimizer] Make sure that all parameters without arguments are defaulted" This reverts commit7c1c46d4e4. * Revert "[CSStep] Don't favor choices until the disjunction is picked" This reverts commite404ed722a. * Revert "[CSOptimizer] Keep track of mismatches while evaluating candidates" This reverts commita094c3ebb0. * Revert "[CSOptimizer] Favor SIMD related arithmetic operator choices if argument is SIMD<N> type" This reverts commitc2f7451c7b. * Revert "[CSOptimizer] Initial implementation of disjunction choice favoring algorithm" This reverts commit672ae3d252. * Revert "[ConstraintSystem] Add skeleton of constraint optimizer" This reverts commitb5f08a4009. * Revert "[CSGen] Remove ConstraintOptimizer and all favoring logic" This reverts commit4432c51f57. * Revert "[ConstraintSystem] Remove `shrink`" This reverts commit757ca24e8a. * [TypeChecker] NFC: Remove resurrected use of `SolverShrinkUnsolvedThreshold` * [TypeChecker] Bring back `SolverDisableShrink` * [Tests] NFC: Mark tests affected by solver-perf revert as slow * [Tests] NFC: Adjust async tests that are affected by performance hacks
332 lines
8.5 KiB
Swift
332 lines
8.5 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
// https://github.com/apple/swift/issues/43735
|
|
// Test constraint simplification of chains of binary operators.
|
|
do {
|
|
let a: String? = "a"
|
|
let b: String? = "b"
|
|
let c: String? = "c"
|
|
let _: String? = a! + b! + c!
|
|
|
|
let x: Double = 1
|
|
_ = x + x + x
|
|
|
|
// https://github.com/apple/swift/issues/46071
|
|
let y1: Double? = 1
|
|
_ = y1! + y1! + y1!
|
|
|
|
// https://github.com/apple/swift/issues/45241
|
|
let y2: [String: Double] = ["pizza": 10.99, "ice cream": 4.99, "salad": 7.99]
|
|
_ = y2["pizza"]!
|
|
_ = y2["pizza"]! + y2["salad"]!
|
|
_ = y2["pizza"]! + y2["salad"]! + y2["ice cream"]!
|
|
}
|
|
|
|
// Use operators defined within a type.
|
|
struct S0 {
|
|
static func +(lhs: S0, rhs: S0) -> S0 { return lhs }
|
|
}
|
|
|
|
func useS0(lhs: S0, rhs: S0) {
|
|
_ = lhs + rhs
|
|
}
|
|
|
|
// Use operators defined within a generic type.
|
|
struct S0b<T> {
|
|
static func + <U>(lhs: S0b<T>, rhs: U) -> S0b<U> { return S0b<U>() }
|
|
}
|
|
|
|
func useS0b(s1i: S0b<Int>, s: String) {
|
|
var s1s = s1i + s
|
|
s1s = S0b<String>()
|
|
_ = s1s
|
|
}
|
|
|
|
// Use operators defined within a protocol extension.
|
|
infix operator %%%
|
|
infix operator %%%%
|
|
|
|
protocol P1 {
|
|
static func %%%(lhs: Self, rhs: Self) -> Bool
|
|
}
|
|
|
|
extension P1 {
|
|
static func %%%%(lhs: Self, rhs: Self) -> Bool {
|
|
return !(lhs %%% rhs)
|
|
}
|
|
}
|
|
|
|
func useP1Directly<T : P1>(lhs: T, rhs: T) {
|
|
_ = lhs %%% rhs
|
|
_ = lhs %%%% rhs
|
|
}
|
|
|
|
struct S1 : P1 {
|
|
static func %%%(lhs: S1, rhs: S1) -> Bool { return false }
|
|
}
|
|
|
|
func useP1Model(lhs: S1, rhs: S1) {
|
|
_ = lhs %%% rhs
|
|
_ = lhs %%%% rhs
|
|
}
|
|
|
|
struct S1b<T> : P1 {
|
|
static func %%%(lhs: S1b<T>, rhs: S1b<T>) -> Bool { return false }
|
|
}
|
|
|
|
func useP1ModelB(lhs: S1b<Int>, rhs: S1b<Int>) {
|
|
_ = lhs %%% rhs
|
|
_ = lhs %%%% rhs
|
|
}
|
|
|
|
func useP1ModelBGeneric<T>(lhs: S1b<T>, rhs: S1b<T>) {
|
|
_ = lhs %%% rhs
|
|
_ = lhs %%%% rhs
|
|
}
|
|
|
|
// Use operators defined within a protocol extension to satisfy a requirement.
|
|
protocol P2 {
|
|
static func %%%(lhs: Self, rhs: Self) -> Bool
|
|
static func %%%%(lhs: Self, rhs: Self) -> Bool
|
|
}
|
|
|
|
extension P2 {
|
|
static func %%%%(lhs: Self, rhs: Self) -> Bool {
|
|
return !(lhs %%% rhs)
|
|
}
|
|
}
|
|
|
|
func useP2Directly<T : P2>(lhs: T, rhs: T) {
|
|
_ = lhs %%% rhs
|
|
_ = lhs %%%% rhs
|
|
}
|
|
|
|
struct S2 : P2 {
|
|
static func %%%(lhs: S2, rhs: S2) -> Bool { return false }
|
|
}
|
|
|
|
func useP2Model(lhs: S2, rhs: S2) {
|
|
_ = lhs %%% rhs
|
|
_ = lhs %%%% rhs
|
|
}
|
|
|
|
struct S2b<T> : P2 {
|
|
static func %%%(lhs: S2b<T>, rhs: S2b<T>) -> Bool { return false }
|
|
}
|
|
|
|
func useP2Model2(lhs: S2b<Int>, rhs: S2b<Int>) {
|
|
_ = lhs %%% rhs
|
|
_ = lhs %%%% rhs
|
|
}
|
|
|
|
func useP2Model2Generic<T>(lhs: S2b<T>, rhs: S2b<T>) {
|
|
_ = lhs %%% rhs
|
|
_ = lhs %%%% rhs
|
|
}
|
|
|
|
// Using an extension of one protocol to satisfy another conformance.
|
|
protocol P3 { }
|
|
|
|
extension P3 {
|
|
static func ==(lhs: Self, rhs: Self) -> Bool {
|
|
return true
|
|
}
|
|
}
|
|
|
|
struct S3 : P3, Equatable { }
|
|
|
|
// rdar://problem/30220565
|
|
func shrinkTooFar(_ : Double, closure : ()->()) {}
|
|
func testShrinkTooFar() {
|
|
shrinkTooFar(0*0*0) {}
|
|
}
|
|
|
|
// rdar://problem/33759839
|
|
|
|
enum E_33759839 {
|
|
case foo
|
|
case bar(String)
|
|
}
|
|
|
|
let foo_33759839 = ["a", "b", "c"]
|
|
let bar_33759839 = ["A", "B", "C"]
|
|
|
|
let _: [E_33759839] = foo_33759839.map { .bar($0) } +
|
|
bar_33759839.map { .bar($0) } +
|
|
[E_33759839.foo] // Ok
|
|
|
|
// rdar://problem/28688585
|
|
|
|
class B_28688585 {
|
|
var value: Int
|
|
|
|
init(value: Int) {
|
|
self.value = value
|
|
}
|
|
|
|
func add(_ other: B_28688585) -> B_28688585 {
|
|
return B_28688585(value: value + other.value)
|
|
}
|
|
}
|
|
|
|
class D_28688585 : B_28688585 {
|
|
}
|
|
|
|
func + (lhs: B_28688585, rhs: B_28688585) -> B_28688585 {
|
|
return lhs.add(rhs)
|
|
}
|
|
|
|
let var_28688585 = D_28688585(value: 1)
|
|
_ = var_28688585 + var_28688585 + var_28688585 // Ok
|
|
|
|
// rdar://problem/35740653 - Fix `LinkedExprAnalyzer` greedy operator linking
|
|
|
|
struct S_35740653 {
|
|
var v: Double = 42
|
|
|
|
static func value(_ value: Double) -> S_35740653 {
|
|
return S_35740653(v: value)
|
|
}
|
|
|
|
static func / (lhs: S_35740653, rhs: S_35740653) -> Double {
|
|
return lhs.v / rhs.v
|
|
}
|
|
}
|
|
|
|
func rdar35740653(val: S_35740653) {
|
|
let _ = 0...Int(val / .value(1.0 / 42.0)) // Ok
|
|
}
|
|
|
|
protocol P_37290898 {}
|
|
struct S_37290898: P_37290898 {}
|
|
|
|
func rdar37290898(_ arr: inout [P_37290898], _ element: S_37290898?) {
|
|
arr += [element].compactMap { $0 } // Ok
|
|
}
|
|
|
|
// https://github.com/apple/swift/issues/50753
|
|
infix operator ??=
|
|
func ??= <T>(lhs: inout T?, rhs: T?) {}
|
|
var c: Int = 0 // expected-note {{change variable type to 'Int?' if it doesn't need to be declared as 'Int'}}
|
|
c ??= 5 // expected-error{{inout argument could be set to a value with a type other than 'Int'; use a value declared as type 'Int?' instead}}
|
|
|
|
func rdar46459603() {
|
|
enum E {
|
|
case foo(value: String)
|
|
}
|
|
|
|
let e = E.foo(value: "String")
|
|
var arr = ["key": e]
|
|
|
|
_ = arr.values == [e]
|
|
// expected-error@-1 {{referencing operator function '==' on 'Equatable' requires that 'Dictionary<String, E>.Values' conform to 'Equatable'}}
|
|
// expected-error@-2 {{cannot convert value of type '[E]' to expected argument type 'Dictionary<String, E>.Values'}}
|
|
|
|
_ = [arr.values] == [[e]]
|
|
// expected-error@-1 {{referencing operator function '==' on 'Array' requires that 'E' conform to 'Equatable'}} expected-note@-1 {{binary operator '==' cannot be synthesized for enums with associated values}}
|
|
// expected-error@-2 {{cannot convert value of type 'Dictionary<String, E>.Values' to expected element type '[E]'}}
|
|
}
|
|
|
|
// https://github.com/apple/swift/issues/53233
|
|
|
|
infix operator ^^^
|
|
func ^^^ (lhs: String, rhs: String) {}
|
|
|
|
// FIXME: Operator lookup does not reach local types so this must be a
|
|
// top-level struct (https://github.com/apple/swift/issues/51378).
|
|
struct S_53233 {
|
|
static func ^^^ (lhs: S_53233, rhs: S_53233) {}
|
|
}
|
|
do {
|
|
let s = S_53233()
|
|
(^^^)(s, s)
|
|
_ = (==)(0, 0)
|
|
}
|
|
|
|
// https://github.com/apple/swift/issues/53359
|
|
|
|
precedencegroup PowerPrecedence {
|
|
lowerThan: BitwiseShiftPrecedence
|
|
higherThan: AdditionPrecedence
|
|
associativity: right
|
|
}
|
|
infix operator ^^ : PowerPrecedence
|
|
|
|
extension Int {
|
|
static func ^^ (lhs: Int, rhs: Int) -> Int {
|
|
var result = 1
|
|
for _ in 1...rhs { result *= lhs }
|
|
return result
|
|
}
|
|
}
|
|
|
|
_ = 1 ^^ 2 ^^ 3 * 4 // expected-error {{adjacent operators are in unordered precedence groups 'PowerPrecedence' and 'MultiplicationPrecedence'}}
|
|
|
|
// rdar://problem/60185506 - Ambiguity with Float comparison
|
|
func rdar_60185506() {
|
|
struct X {
|
|
var foo: Float
|
|
}
|
|
|
|
func test(x: X?) {
|
|
let _ = (x?.foo ?? 0) <= 0.5 // Ok
|
|
}
|
|
}
|
|
|
|
// rdar://problem/60727310
|
|
func rdar60727310() {
|
|
func myAssertion<T>(_ a: T, _ op: ((T,T)->Bool), _ b: T) {}
|
|
var e: Error? = nil
|
|
myAssertion(e, ==, nil) // expected-error {{cannot convert value of type '(any Error)?' to expected argument type '(any Any.Type)?'}}
|
|
}
|
|
|
|
// https://github.com/apple/swift/issues/54877
|
|
// FIXME: Bad diagnostic.
|
|
func f_54877(_ e: Error) {
|
|
func foo<T>(_ a: T, _ op: ((T, T) -> Bool)) {}
|
|
foo(e, ==) // expected-error {{type of expression is ambiguous without a type annotation}}
|
|
}
|
|
|
|
// rdar://problem/62054241 - Swift compiler crashes when passing < as the sort function in sorted(by:) and the type of the array is not comparable
|
|
func rdar_62054241() {
|
|
struct Foo {
|
|
let a: Int
|
|
}
|
|
|
|
func test(_ arr: [Foo]) -> [Foo] {
|
|
return arr.sorted(by: <) // expected-error {{no exact matches in reference to operator function '<'}}
|
|
// expected-note@-1 {{found candidate with type '(Foo, Foo) -> Bool'}}
|
|
}
|
|
}
|
|
|
|
// https://github.com/apple/swift/issues/53800
|
|
// Operator returning IUO doesn't implicitly unwrap
|
|
|
|
postfix operator ^^^
|
|
postfix func ^^^ (lhs: Int) -> Int! { 0 }
|
|
|
|
let x: Int = 1^^^
|
|
|
|
// https://github.com/apple/swift/issues/44672 - DiagnosticsQoI
|
|
do {
|
|
enum TestEnum: Int {
|
|
case First, Second
|
|
}
|
|
|
|
let number = 1
|
|
let test = true || number == .First.rawValue // expected-error {{type 'Int' has no member 'First'}}
|
|
}
|
|
|
|
// https://github.com/apple/swift/issues/60954
|
|
enum I60954 {
|
|
// expected-error@+1{{operator implementation without matching operator declaration}}
|
|
func ?= (pattern: I60954?, version: Self) { // expected-error{{operator '?=' declared in type 'I60954' must be 'static'}}
|
|
// expected-error@+2{{operator is not a known binary operator}}
|
|
// expected-error@+1{{initializer 'init(_:)' requires that 'I60954' conform to 'StringProtocol'}}
|
|
pattern ?= .init(version) // expected-error{{value of optional type 'I60954?' must be unwrapped to a value of type 'I60954'}}
|
|
// expected-note@-1{{coalesce using '??' to provide a default when the optional value contains 'nil'}}
|
|
// expected-note@-2{{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
|
|
}
|
|
init?<S>(_ string: S) where S: StringProtocol {} // expected-note{{where 'S' = 'I60954'}}
|
|
}
|