- 
                Notifications
    
You must be signed in to change notification settings  - Fork 10.6k
 
Closed
Closed
Copy link
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfperformancetype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
Description
| Previous ID | SR-5322 | 
| Radar | rdar://problem/32999041 | 
| Original Reporter | @rudkx | 
| Type | Bug | 
Additional Detail from JIRA
| Votes | 0 | 
| Component/s | Compiler | 
| Labels | Bug, Performance, TypeChecker | 
| Assignee | None | 
| Priority | Medium | 
md5: c72cfc034a2bc02949fcd0bdb36cd2a7
Issue Description:
I'm not sure if this is anything more specific than other slow type checking cases we've seen, but I noticed that two expressions in swift-corelibs-foundation were accounting for quite a bit of type checking time (something like 7s and 63s respectively in an unoptimized asserts-enabled build).
diff --git a/Foundation/NSCFString.swift b/Foundation/NSCFString.swift
index 6d0d8a1..7cbb2b4 100644
--- a/Foundation/NSCFString.swift
+++ b/Foundation/NSCFString.swift
@@ -59,13 +59,19 @@ internal class _NSCFString : NSMutableString {
 
 internal final class _NSCFConstantString : _NSCFString {
     internal var _ptr : UnsafePointer<UInt8> {
-        let offset = MemoryLayout<OpaquePointer>.size + MemoryLayout<Int32>.size + MemoryLayout<Int32>.size + MemoryLayout<_CFInfo>.size
+        // FIXME: Split expression as a work-around for slow type checking.
+        let offTemp1 = MemoryLayout<OpaquePointer>.size + MemoryLayout<Int32>.size
+        let offTemp2 = MemoryLayout<Int32>.size + MemoryLayout<_CFInfo>.size
+        let offset = offTemp1 + offTemp2
         let ptr = Unmanaged.passUnretained(self).toOpaque()
         return ptr.load(fromByteOffset: offset, as: UnsafePointer<UInt8>.self)
     }
 
     private var _lenOffset : Int {
-        return MemoryLayout<OpaquePointer>.size + MemoryLayout<Int32>.size + MemoryLayout<Int32>.size + MemoryLayout<_CFInfo>.size + MemoryLayout<UnsafePointer<UInt8>>.size
+        // FIXME: Split expression as a work-around for slow type checking.
+        let offTemp1 = MemoryLayout<OpaquePointer>.size + MemoryLayout<Int32>.size
+        let offTemp2 = MemoryLayout<Int32>.size + MemoryLayout<_CFInfo>.size
+        return offTemp1 + offTemp2 + MemoryLayout<UnsafePointer<UInt8>>.size
     }
 
     private var _lenPtr :  UnsafeMutableRawPointer {Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfperformancetype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis