Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
davidbjames opened this issue May 21, 2021 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@davidbjames
Copy link

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
Copy link

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

@davidbjames
Copy link
Author

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
Copy link

@swift-ci create

@slavapestov
Copy link
Member

@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.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants