mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Generic parameter references, which occur in generic requirement metadata, were hardcoding associated type indices. Instead, use relative references to associated type descriptors and perform the index calculation at runtime. Associated types can now be reordered resiliently (without relying on sorting), which is the first main step toward rdar://problem/44167982.
74 lines
1.1 KiB
Swift
74 lines
1.1 KiB
Swift
public protocol Bed {
|
|
func squiggle()
|
|
}
|
|
|
|
public protocol Outfit {
|
|
var size: Int { get }
|
|
}
|
|
|
|
public protocol Eater {
|
|
#if BEFORE
|
|
func eat()
|
|
func poop()
|
|
#else
|
|
func poop()
|
|
func eat()
|
|
#endif
|
|
}
|
|
|
|
public protocol Wiggler {
|
|
#if BEFORE
|
|
func wiggle()
|
|
func cry()
|
|
#else
|
|
func cry()
|
|
func wiggle()
|
|
#endif
|
|
}
|
|
|
|
#if BEFORE
|
|
|
|
public protocol Baby : Eater, Wiggler {
|
|
associatedtype Bassinet : Bed
|
|
associatedtype Onesie : Outfit
|
|
|
|
var outfitSize: Int { get }
|
|
|
|
func sleep(in: Bassinet)
|
|
func wear(outfit: Onesie)
|
|
}
|
|
|
|
#else
|
|
|
|
public protocol Baby : Wiggler, Eater {
|
|
associatedtype Onesie : Outfit
|
|
associatedtype Bassinet : Bed
|
|
|
|
var outfitSize: Int { get }
|
|
|
|
func wear(outfit: Onesie)
|
|
func sleep(in: Bassinet)
|
|
}
|
|
|
|
#endif
|
|
|
|
public protocol Adoring {
|
|
func adore() -> String
|
|
}
|
|
|
|
public func goodDay<B : Baby>(for baby: B,
|
|
sleepingIn bed: B.Bassinet,
|
|
wearing outfit: B.Onesie) {
|
|
if baby.outfitSize != outfit.size {
|
|
fatalError("I grew too much!")
|
|
}
|
|
|
|
baby.wear(outfit: outfit)
|
|
baby.sleep(in: bed)
|
|
baby.poop()
|
|
baby.sleep(in: bed)
|
|
baby.eat()
|
|
baby.sleep(in: bed)
|
|
baby.wiggle()
|
|
}
|