Skip to content

Commit 02436ea

Browse files
authored
Refactor slow to type check expression (#8565)
### Motivation: An expression in `SwiftRunCommand` was taking almost 2 seconds to type check on my M4 MacBook. ### Modifications: Break it out in to multiple, faster to type check expressions. ### Result: This brings each individual expression down to under 80ms to check. This was diagnosed with: ``` swift build \ -Xswiftc -Xfrontend -Xswiftc -warn-long-function-bodies=80 \ -Xswiftc -Xfrontend -Xswiftc -warn-long-expression-type-checking=80 ```
1 parent ed31e6e commit 02436ea

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Sources/Commands/SwiftRunCommand.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ public struct SwiftRunCommand: AsyncSwiftCommand {
274274
// If the executable is implicit, search through root products.
275275
let rootExecutables = graph.rootPackages
276276
.flatMap { $0.products }
277-
.filter { $0.type == .executable || $0.type == .snippet }
277+
// The type checker slows down significantly when ProductTypes arent explicitly typed.
278+
.filter { $0.type == ProductType.executable || $0.type == ProductType.snippet }
278279
.map { $0.name }
279280

280281
// Error out if the package contains no executables.

0 commit comments

Comments
 (0)