Open keith opened 1 year ago
This doesn't crash anymore:
error: 'each' cannot be applied to non-pack type 'repeat each State'
return self.combine(repeat (each store).currentState)
^
error: pack expansion requires that 'repeat each State' and 'each State' have the same shape
return self.combine(repeat (each store).currentState)
^
error: type of expression is ambiguous without a type annotation
self.combine = combine
~~~~~~~~~~~~~^~~~~~~~~
With the crash out of the way this looks very much like a manifestation of #68369.
struct CompositeStore<each State> {
let combine: (repeat each State) -> Void
func foo(store: repeat each State) {
_ = self.combine(repeat each store) // error: type of expression is ambiguous without a type annotation [type_of_expression_is_ambiguous]
}
init() {}
}
Fixing the Sema error exposed the crash again.
FYI this seems like the minimal test case that triggers this assertion:
func test1<each T>(ts: (repeat each T)) {}
func test2<each T>(ts: (repeat each T)) {
test1(ts: ts)
}
func test1<each T>(ts: (repeat each T)) {}
func test2<each T>(ts: (repeat each T)) {
test1(ts: ts)
}
@AnthonyLatsis Hmm… this is blocking me (for now). Can you think of any legit workarounds to build that example on 5.10?
func test1<each T>(ts: (repeat each T)) {}
func test2<each T>(ts: (repeat each T)) {
test1(ts: (repeat each ts))
}
This unblocks me on compiling… but then I get a Pack expansion count type should be a pack
fatal error when I run that code in a similar function in my app.
Can you think of any legit workarounds to build that example on 5.10?
You could try to avoid passing around abstract tuples:
func test1<each T>(ts: repeat each T) {}
func test2<each T>(ts: (repeat each T)) {
test1(ts: repeat each ts)
}
You could try to avoid passing around abstract tuples:
@AnthonyLatsis Hmm… I try this workaround and I see another Pack expansion count type should be a pack
fatal error at runtime.
Did you get rid of all abstract tuple parameters? If so, and your code still hits this runtime fatal error, please report it.
@AnthonyLatsis I can try to take a closer look. This repro isn't super clean because I have a few different places that tuple is being passed around from. FWIW… my runtime error is firing from the Observation
stack of all places (I have an Observable
class instance that is generic across a parameter pack).
import Observation
@Observable final class Repeater<each Parameter, Output> {
let parameter: (repeat each Parameter)
var output: Output
init(
parameter: (repeat each Parameter),
output: Output
) {
self.parameter = parameter
self.output = output
}
}
let repeater = Repeater(parameter: (1, 2, 3), output: 4)
repeater.output = 5
/*
#0 0x00000001a0e4b52c in (anonymous namespace)::DecodedMetadataBuilder::beginPackExpansion(swift::MetadataOrPack) ()
#1 0x00000001a0e41c04 in swift::Demangle::__runtime::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::__runtime::Node*, unsigned int, bool) ()
#2 0x00000001a0e45c3c in swift::Demangle::__runtime::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeGenericArgs(swift::Demangle::__runtime::Node*, unsigned int, __swift::__runtime::llvm::SmallVectorImpl<swift::MetadataOrPack>&) ()
#3 0x00000001a0e41da4 in swift::Demangle::__runtime::TypeDecoder<(anonymous namespace)::DecodedMetadataBuilder>::decodeMangledType(swift::Demangle::__runtime::Node*, unsigned int, bool) ()
#4 0x00000001a0e3e55c in swift_getTypeByMangledNodeImpl(swift::MetadataRequest, swift::Demangle::__runtime::Demangler&, swift::Demangle::__runtime::Node*, void const* const*, std::__1::function<void const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#5 0x00000001a0e3e100 in swift_getTypeByMangledNode ()
#6 0x00000001a0e3ebb0 in swift_getTypeByMangledNameImpl(swift::MetadataRequest, __swift::__runtime::llvm::StringRef, void const* const*, std::__1::function<void const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#7 0x00000001a0e38a84 in swift_getTypeByMangledName ()
#8 0x00000001a0e38578 in swift_getTypeByMangledNameInEnvironment ()
#9 0x00000001a0bc6e1c in _resolveKeyPathGenericArgReference(_:genericEnvironment:arguments:) ()
#10 0x00000001a0bc74f4 in specialized _walkKeyPathPattern<τ_0_0>(_:walker:) ()
#11 0x00000001a0bc6928 in _getKeyPathClassAndInstanceSizeFromPattern(_:_:) ()
#12 0x00000001a0bc66d4 in _swift_getKeyPath(pattern:arguments:) ()
#13 0x00000001000025b8 in Repeater.output.setter at /var/folders/1j/0r1s_v0n4bn200kt9nkm9j5w0000gn/T/swift-generated-sources/@__swiftmacro_12RepeaterDemo0A0C6output18ObservationTrackedfMa_.swift:11
#14 0x000000010000242c in main at /Users/rick/Desktop/RepeaterDemo/Sources/main.swift:17
#15 0x0000000190a1a0e0 in start ()
*/
@AnthonyLatsis This seems to be triggering a runtime error for me coming from 5.10 in a simple executable target. I am unable to build that for 6.0 because of a compiler crash.
In my case I needed to retain an abstract tuple because I was saving it as a stored variable and I wasn't able to compile without those round braces.
@AnthonyLatsis I opened https://github.com/apple/swift/issues/73690 for tracking the Observation crash.
@AnthonyLatsis Hmm… I try this workaround and I see another
Pack expansion count type should be a pack
fatal error at runtime.
I just got this same fatal error and this issue is the only instance of it I could find :)
I'm having a hard time reducing a case, but it's related to returning a parameter pack generic type (e.g. MyType<each Value>
) as an opaque some
type from a function.
I'm having a hard time reducing a case, but it's related to returning a parameter pack generic type (e.g. MyType
) as an opaque some type from a function.
@stephencelis Hmm… if it's a 5.10 runtime crash it might be another version of https://github.com/swiftlang/swift/issues/73690 (which is from pairing variadic types with KeyPaths). That one is actually a compiler crash for me on 6.0.
The other possibility is this is another version of https://github.com/swiftlang/swift/issues/61357.
@vanvoorden This crash was on the Xcode 16 beta, and I don't think key paths are involved, just a result builder that was using a parameter pack for a variadic buildBlock
and returning a parameter packed type as a some
type. Simple cases built and ran fine, but more complex cases would lead to the above fatal error. #61357 also doesn't seem parameter pack-related. Let me know if I can help, though!
(FWIW I can probably share a complex code sample with the issue by reverting our workaround of not using some
types, but I find a lot of the non-reduced cases I share here sit around.)
With this code:
The attempted call to
foo(store1)
results in a crash:Steps to reproduce
Environment