I was under the impression that this wasn't part of any variadic generic pitches (except the future directions of 0393). But given what you said I went and tried the syntax from the future directions and to my surprise it worked (woohoo). Is that meant to have been moved out of future directions at some point given that it's implemented, or is the implementation anticipating a future pitch that hasn't been made public yet?
I've been trying the experimental VariadicGenerics feature in the latest snapshot. Is there a way to try out parameter packs in generic types yet and run them (not just compile them behind unreachable @available
checks)? I'm assuming that given that they are only available on 'macOS 99.99.0' they're probably missing runtime support on macOS and only work on Linux (if at all) where the runtime isn't so tied to the system or something?
On a completely unrelated note, I've run into a crash related to same shape requirement simplification with a pretty simple example (compiled with xcrun --toolchain swift swift build
);
protocol P {}
struct A<each V> {
init(_ v: repeat each V) {}
}
func foo<each V>(_ v: repeat each V) -> A<repeat each V> {
return A<repeat each V>(repeat each v)
}
Here's what I think is probably the most informative part of the error (I don't want to dump the entire thing in a forum post).
6 libsystem_c.dylib 0x00000001a98c6620 err + 0
7 swift-frontend 0x0000000107808ad8 swift::constraints::ConstraintSystem::simplifySameShapeConstraint(swift::Type, swift::Type, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) (.cold.30) + 0
8 swift-frontend 0x000000010363ec84 swift::constraints::ConstraintSystem::simplifySameShapeConstraint(swift::Type, swift::Type, swift::OptionSet<swift::constraints::ConstraintSystem::TypeMatchFlags, unsigned int>, swift::constraints::ConstraintLocatorBuilder) + 2152
Should I create an issue in the swift repo? I'm not exactly sure how bugs in experimental features are usually reported
I believe you are looking for SE-0399: Tuple of value pack expansion
Ah thank you! I completely missed that pitch somehow
This feature has gone through Swift evolution review and is now accepted, so please do not hesitate to file issues on GitHub!
Just opened issue #66095 for the crash
We are still looking for feedback!
Binaries built with the developer snapshots are linked against libswiftCore in the toolchain, and not the libswiftCore in the system. But you need to pass “-Xfrontend -disable-availability-checking” until this makes it into an official release.
Ah, thank you so much!
@hborla @Slava_Pestov Should the current implementation for variadic generics work with KeyPaths? I can't make the following code compiles (2023-05-22 Snapshot):
struct T {
var p1: String
var p2: Int
var p3: Double
}
extension Array {
func f<each P: Comparable>(_ keyPath: repeat KeyPath<Self.Element, each P>) {
// repeat print(each keyPath) // Type of expression is ambiguous without more context
}
}
let ts: [T] = []
ts.f(\.p1, \.p2, \.p3)
I don't see any reason why your code shouldn't work. Please file an issue on GitHub!