swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.3k stars 10.34k forks source link

[SR-14652] Compiler slowdown (type checking) with custom operator expressions. #57004

Open davidbjames opened 3 years ago

davidbjames commented 3 years ago
Previous ID SR-14652
Radar rdar://problem/78415278
Original Reporter @davidbjames
Type Bug
Environment Xcode 12.5
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, TypeChecker | |Assignee | @hborla | |Priority | Medium | md5: 67e4238e397c5c89246c55aaaf320f38

Issue Description:

There was a great slowdown on type checking custom operator expressions between Xcode 12.3 and 12.4 (or maybe it was between 12.4 and 12.5) but it persists in 12.5 (build 12E262). During all of those releases I had build setting `-warn-long-expression-type-checking=1000` and `-warn-long-function-bodies=3500`. Importantly, on previous releases (at least from 12.3 and earlier) there were no warnings. When upgrading (I'm pretty sure to 12.4) suddenly there a many warnings. Something has changed.

typesanitizer commented 3 years ago

@davidbjames could you please share the overloads you've added as well as the code snippets?

davidbjames commented 3 years ago

Hi theindigamer (JIRA User) thanks for the response. I was able to narrow down the compiler slowdown to a prefix operator ➕ that had several implementations.

public prefix func +(tag:ExtendedStyleTag) -> ExtendedStyleTag {
    return tag
}
internal prefix func +(tag:InternalTag) -> InternalTag {
    return tag
}
// etc

.. where the "tag" (in this example) was an enum of some kind. It is shorthand for spelling out the entire enum type name, so

+.implicitCorners vs. ExtendedStyleTag.implicitCorners

This was causing a compiler slowdown (in recent Xcode, not before):

((Typographicals & +.subTitle) | (UIButton.self - +.title)) => [
    .font(fonts.subTitle),
    .textAlignment(.center),
],

.. but changing it to this (spelling out the enum type), fixed the slowdown

((Typographicals & ExtendedStyleTag.subTitle) | (UIButton.self - ExtendedStyleTag.title)) => [
    .font(fonts.subTitle),
    .textAlignment(.center),
],
typesanitizer commented 3 years ago

@swift-ci create

slavapestov commented 3 years ago

@davidbjames Is there any chance you could come up with a self-contained test case demonstrating the problem? In particular, having the definitions of ExtendedStyleTag and InternalTag (I'm guessing they're enums?) with the relevant members would be helpful.