You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-9712 Swift 5 fails to recognise thin closure (assertion failure)
Issue Description:
Disclaimer: I'm not sure if this should be treated as a bug, as included use case relies on `@inline(__always)`, but I guess it could be affecting stdlib in some cases too.
Problem
There seems to be regression in Swift 5, where the compiler fails to optimise (both thin and thick) closures across module boundaries.
// main.swift
import Foundation
import Darwin
import foo
#if swift(>=5.0)dump("swift-5.0")#elsedump("swift-4.2")#endiffunc measureMiliseconds(_ work:()->Void)->Double{varinfo=mach_timebase_info()
guard mach_timebase_info(&info)== KERN_SUCCESS else{return-1}letstart=mach_absolute_time()work()letend=mach_absolute_time()letelapsed= end - start
letnano= elapsed * UInt64(info.numer)/ UInt64(info.denom)returnTimeInterval(nano)/ TimeInterval(NSEC_PER_MSEC)}@discardableResult@inline(never)func sink<T>(_ val:T)->T{return val }@discardableResult@inline(never)func sink<T>(_ val:inoutT)->T{return val }func bench(times:Int=10, _ work:()->Void)->TimeInterval{
guard times >0else{return0}return(0..< times).reduce(TimeInterval(0),{ result, _ inreturn result + measureMiliseconds(work)})/ TimeInterval(times)}letn=1000000func doHeap(){varval=Foo<Int,Never>.success(10)
for var i in 0..< n {
val = val.map{ _ inreturnsink(&i)}}sink(val)}func doStack(){varval=Foo<Int,Never>.success(10)
for var i in 0..< n {
val = val.mapContext(&i){returnsink(&$1)}}sink(val)}print("Bench heap: \(bench(doHeap))")print("Bench stack: \(bench(doStack))")
I'm still seeing some pretty significant performance differences. With the same code, with higher benchmark sample (100) and `n` equal to 10000000, those are results:
Attachment: Download
Environment
Swift 5 - swift-5.0-DEVELOPMENT-SNAPSHOT-2019-01-18
Swift 4.2.1 - Xcode 10.1
Additional Detail from JIRA
md5: 975cbca4be4db22be3121cb69a0e583a
cloned to:
thin
closure (assertion failure)Issue Description:
Disclaimer: I'm not sure if this should be treated as a bug, as included use case relies on `@inline(__always)`, but I guess it could be affecting stdlib in some cases too.
Problem
There seems to be regression in Swift 5, where the compiler fails to optimise (both thin and thick) closures across module boundaries.
Code
Given module foo:
and our client module:
Compilation
Example Output
Swift 4.2
Swift 5
The text was updated successfully, but these errors were encountered: