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-10601] Very slow type check of simple expression #53001

Open
swift-ci opened this issue May 2, 2019 · 7 comments
Open

[SR-10601] Very slow type check of simple expression #53001

swift-ci opened this issue May 2, 2019 · 7 comments
Labels
compiler The Swift compiler in itself improvement performance type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented May 2, 2019

Previous ID SR-10601
Radar None
Original Reporter smartgo (JIRA User)
Type Improvement

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, Performance, TypeChecker
Assignee None
Priority Medium

md5: b1b1c9d94f36a6da0d8d01bdd475d461

Issue Description:

let bit    : UInt32 = 8
let offset1: UInt32 = 8
let offset2: UInt32 = 16
let offset3: UInt32 = 24
 
// The following expression took over 1000 ms to type-check.
let result: UInt32 = UInt32(bit | UInt32(bit << offset1) | UInt32(bit << offset2) | UInt32(bit << offset3))

Xcode project attached.

@theblixguy
Copy link
Collaborator

cc @xedin

@theblixguy
Copy link
Collaborator

Actually, this no longer produces that diagnostic on Swift 5 (Xcode 10.2.1).

@belkadan
Copy link
Contributor

belkadan commented May 2, 2019

You'd probably get faster type-checking if you left out the conversions to UInt32. You may actually be getting different behavior from what you expect there, because UInt32(a >> b) is very different from a >> b as UInt32.

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 2, 2019

Comment by Anders Kierulf (JIRA)

This was indeed with Xcode 10.2.1, Swift 5, so surprised you're not seeing it.

I added the extra UInt32 in a previous version to speed up type checks, helped at that point. The behavior should be the same as long as there's guaranteed to be no overflow, right? The following is even slower to type check:

let result: UInt32 = UInt32(bit \| (bit \<\< offset1) \| (bit \<\< offset2) \| (bit \<\< offset3))

But the following is fast:

let result: UInt32 = (bit \| (bit \<\< offset1) \| (bit \<\< offset2) \| (bit \<\< offset3))

@theblixguy
Copy link
Collaborator

Yeah, that is indeed strange: https://imgur.com/a/k5HrRiq. I copy-pasted the code into Playgrounds as well, but no error.

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 2, 2019

Comment by Anders Kierulf (JIRA)

Do you set -Xfrontend -warn-long-expression-type-checking=100 in Other Swift Flags? I'm not seeing an error, just the slow type-check warning.

@belkadan
Copy link
Contributor

belkadan commented May 3, 2019

Yes, I'd expect the result to be the same in this case, with all the types being UInt32. Sorry, I was thinking of the more general case where someone mixes types, but in practice you'll end up with the same behavior here.

@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
compiler The Swift compiler in itself improvement performance type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants