-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sema: Allow extensions to make generic parameters concrete via same-t…
…ype constraints Fixes <https://bugs.swift.org/browse/SR-1009>.
- Loading branch information
1 parent
8bf32c5
commit 8f88d19
Showing
7 changed files
with
153 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s | ||
// RUN: %target-swift-frontend -emit-ir %s | ||
// RUN: %target-swift-frontend -emit-ir -O %s | ||
|
||
extension Array where Element == Int { | ||
// CHECK-LABEL: sil @_TFe22constrained_extensionsRxzSirSag16instancePropertySi : $@convention(method) (@guaranteed Array<Int>) -> Int | ||
// CHECK-LABEL: sil @_TFe22constrained_extensionsRxzSirSas16instancePropertySi : $@convention(method) (Int, @inout Array<Int>) -> () | ||
// CHECK-LABEL: sil [transparent] [fragile] @_TFe22constrained_extensionsRxzSirSam16instancePropertySi : $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout Array<Int>) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>) | ||
// CHECK-LABEL: sil [transparent] [fragile] @_TFFe22constrained_extensionsRxzSirSam16instancePropertySiU_T_ : $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout Array<Int>, @thick Array<Int>.Type) -> () | ||
public var instanceProperty: Element { | ||
get { | ||
return self[0] | ||
} | ||
set { | ||
self[0] = newValue | ||
} | ||
} | ||
|
||
// CHECK-LABEL: sil @_TFe22constrained_extensionsRxzSirSa14instanceMethodfT_x : $@convention(method) (@guaranteed Array<Int>) -> Int | ||
public func instanceMethod() -> Element { | ||
return instanceProperty | ||
} | ||
|
||
// CHECK-LABEL: sil @_TFe22constrained_extensionsRxzSirSa14instanceMethodfT1ex_x : $@convention(method) (Int, @guaranteed Array<Int>) -> Int | ||
public func instanceMethod(e: Element) -> Element { | ||
return e | ||
} | ||
|
||
// CHECK-LABEL: sil @_TZFe22constrained_extensionsRxzSirSag14staticPropertySi : $@convention(method) (@thin Array<Int>.Type) -> Int | ||
public static var staticProperty: Element { | ||
return 0 | ||
} | ||
|
||
// CHECK-LABEL: sil @_TZFe22constrained_extensionsRxzSirSa12staticMethodfT_x : $@convention(method) (@thin Array<Int>.Type) -> Int | ||
public static func staticMethod() -> Element { | ||
return staticProperty | ||
} | ||
|
||
// CHECK-LABEL: sil @_TIZFe22constrained_extensionsRxzSirSa12staticMethodFT1eGSqx__xA_ : $@convention(thin) () -> Optional<Int> | ||
// CHECK-LABEL: sil @_TZFe22constrained_extensionsRxzSirSa12staticMethodfT1eGSqx__x : $@convention(method) (Optional<Int>, @thin Array<Int>.Type) -> Int | ||
public static func staticMethod(e: Element? = nil) -> Element { | ||
return e! | ||
} | ||
|
||
// CHECK-LABEL: sil @_TFe22constrained_extensionsRxzSirSag9subscriptFT_Si : $@convention(method) (@guaranteed Array<Int>) -> Int | ||
public subscript(i: ()) -> Element { | ||
return self[0] | ||
} | ||
|
||
// CHECK-LABEL: sil @_TFe22constrained_extensionsRxzSirSa21inoutAccessOfPropertyfT_T_ : $@convention(method) (@inout Array<Int>) -> () | ||
public mutating func inoutAccessOfProperty() { | ||
func increment(x: inout Element) { | ||
x += 1 | ||
} | ||
|
||
increment(x: &instanceProperty) | ||
} | ||
} | ||
|
||
extension Dictionary where Key == Int { | ||
// CHECK-LABEL: sil @_TFe22constrained_extensions0_RxzSirVs10Dictionaryg16instancePropertyq_ : $@convention(method) <Int, Value where Int == Int> (@guaranteed Dictionary<Int, Value>) -> @out Value | ||
// CHECK-LABEL: sil @_TFe22constrained_extensions0_RxzSirVs10Dictionarys16instancePropertyq_ : $@convention(method) <Int, Value where Int == Int> (@in Value, @inout Dictionary<Int, Value>) -> () | ||
// CHECK-LABEL: sil [transparent] [fragile] @_TFe22constrained_extensions0_RxzSirVs10Dictionarym16instancePropertyq_ : $@convention(method) <Int, Value where Int == Int> (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout Dictionary<Int, Value>) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>) | ||
// CHECK-LABEL: sil [transparent] [fragile] @_TFFe22constrained_extensions0_RxzSirVs10Dictionarym16instancePropertyq_U_T_ : $@convention(thin) <Int, Value where Int == Int> (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout Dictionary<Int, Value>, @thick Dictionary<Int, Value>.Type) -> () | ||
public var instanceProperty: Value { | ||
get { | ||
return self[0]! | ||
} | ||
set { | ||
self[0] = newValue | ||
} | ||
} | ||
|
||
// CHECK-LABEL: sil @_TFe22constrained_extensions0_RxzSirVs10Dictionary14instanceMethodfT_q_ : $@convention(method) <Int, Value where Int == Int> (@guaranteed Dictionary<Int, Value>) -> @out Value | ||
public func instanceMethod() -> Value { | ||
return instanceProperty | ||
} | ||
|
||
// CHECK-LABEL: sil @_TFe22constrained_extensions0_RxzSirVs10Dictionary14instanceMethodfT1vq__q_ : $@convention(method) <Int, Value where Int == Int> (@in Value, @guaranteed Dictionary<Int, Value>) -> @out Value | ||
public func instanceMethod(v: Value) -> Value { | ||
return v | ||
} | ||
|
||
// CHECK-LABEL: sil @_TZFe22constrained_extensions0_RxzSirVs10Dictionary12staticMethodfT_x : $@convention(method) <Int, Value where Int == Int> (@thin Dictionary<Int, Value>.Type) -> Int | ||
public static func staticMethod() -> Key { | ||
return staticProperty | ||
} | ||
|
||
// CHECK-LABEL: sil @_TZFe22constrained_extensions0_RxzSirVs10Dictionaryg14staticPropertySi : $@convention(method) <Int, Value where Int == Int> (@thin Dictionary<Int, Value>.Type) -> Int | ||
public static var staticProperty: Key { | ||
return 0 | ||
} | ||
|
||
// CHECK-LABEL: sil @_TIZFe22constrained_extensions0_RxzSirVs10Dictionary12staticMethodFT1kGSqx_1vGSqq___q_A_ : $@convention(thin) <Int, Value where Int == Int> () -> Optional<Int> | ||
// CHECK-LABEL: sil @_TIZFe22constrained_extensions0_RxzSirVs10Dictionary12staticMethodFT1kGSqx_1vGSqq___q_A0_ : $@convention(thin) <Int, Value where Int == Int> () -> @out Optional<Value> | ||
// CHECK-LABEL: sil @_TZFe22constrained_extensions0_RxzSirVs10Dictionary12staticMethodfT1kGSqx_1vGSqq___q_ : $@convention(method) <Int, Value where Int == Int> (Optional<Int>, @in Optional<Value>, @thin Dictionary<Int, Value>.Type) -> @out Value | ||
public static func staticMethod(k: Key? = nil, v: Value? = nil) -> Value { | ||
return v! | ||
} | ||
|
||
// CHECK-LABEL: sil @_TZFe22constrained_extensions0_RxzSirVs10Dictionary17callsStaticMethodfT_q_ : $@convention(method) <Int, Value where Int == Int> (@thin Dictionary<Int, Value>.Type) -> @out Value | ||
public static func callsStaticMethod() -> Value { | ||
return staticMethod() | ||
} | ||
|
||
// CHECK-LABEL: sil @_TFe22constrained_extensions0_RxzSirVs10Dictionaryg9subscriptFT_q_ : $@convention(method) <Int, Value where Int == Int> (@guaranteed Dictionary<Int, Value>) -> @out Value | ||
public subscript(i: ()) -> Value { | ||
return self[0]! | ||
} | ||
|
||
// CHECK-LABEL: sil @_TFe22constrained_extensions0_RxzSirVs10Dictionary21inoutAccessOfPropertyfT_T_ : $@convention(method) <Int, Value where Int == Int> (@inout Dictionary<Int, Value>) -> () | ||
public mutating func inoutAccessOfProperty() { | ||
func increment(x: inout Value) { } | ||
|
||
increment(x: &instanceProperty) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8f88d19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, please update the changelog and send a note to swift-dev, asking people to kick the tires!