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-12267] math sequence hangs up compiler #54695

Open
swift-ci opened this issue Feb 25, 2020 · 2 comments
Open

[SR-12267] math sequence hangs up compiler #54695

swift-ci opened this issue Feb 25, 2020 · 2 comments
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

@swift-ci
Copy link
Collaborator

Previous ID SR-12267
Radar rdar://problem/59791961
Original Reporter earney (JIRA User)
Type Bug
Environment

swift --version
Swift version 5.1.3 (swift-5.1.3-RELEASE)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: b830a3b4ab6dc26bd4f27733249c3aba

Issue Description:

Everything works as expected until I uncomment the line for eq3.

when I uncomment eq3 in the file test.swift, nothing gets printed and it just hangs..

test.swift:

print("got here")
var eq = 1.0
var eq1 = 1.0 - 1/3.0
var eq2 = 1.0 - 1/3.0 + 1/5.0
print("got here")

//var eq3 = 1.0 - 1/3.0 + 1/5.0 - 1/7.0
print("we never get here... 🙁")

swift test.swift

(no output), just hangs..

Any ideas?

@hborla
Copy link
Member

hborla commented Feb 26, 2020

@swift-ci create

@hborla
Copy link
Member

hborla commented Feb 26, 2020

This is a well-known type checker performance issue. If you wait long enough, you'll get this error: error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

As the error message states, the workaround is to break up the sequence of literals and operators into smaller expressions, which will be type checked separately:

var eq2 = 1.0 - 1/3.0 + 1/5.0
var eq3 = eq2 - 1/7.0

You could also help the type checker out by adding more explicit types into the source code. For example, this code:

var eq3 = 1.0 - Double(1/3.0) + Double(1/5.0) - Double(1/7.0)

compiles just fine.

@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

2 participants