After a very arduous process I finally got the crashing code into a reasonably minimal form:
func thisWillCauseTheCrash () {
Task { await foo(0).run() }
}
func foo <T> (_ t: T) -> some Procedure {
FlatMap(
firstProcedure: AtomicProcedure { t },
secondProcedureGenerator: { _ in someP }
)
}
var someP: some Procedure {
AtomicProcedure { 0 }
}
struct FlatMap
<First: Procedure,
Second: Procedure>:
Procedure {
var firstProcedure: First
var secondProcedureGenerator: (First.Output)async->Second
func run () async -> Second.Output {
let firstOutput = await firstProcedure.run()
let second = await secondProcedureGenerator(firstOutput)
return await second.run()
}
}
struct AtomicProcedure <Output>: Procedure {
var _run: ()async->Output
func run () async -> Output { await _run() }
}
public protocol Procedure <Output> {
func run () async -> Output
associatedtype Output
}
If you put this code into a blank package and run the top function from a unit test you should immediately experience a crash like:
error: memory read failed for 0xb3261800
Any insight into the true source and therefore how to workaround?