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-838] expression was too complex to be solved in reasonable time #43450

Closed
swift-ci opened this issue Feb 27, 2016 · 2 comments
Closed

[SR-838] expression was too complex to be solved in reasonable time #43450

swift-ci opened this issue Feb 27, 2016 · 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-838
Radar rdar://problem/33688251
Original Reporter gradha (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

OSX 10.11.3, (swiftlang-700.1.101.15 clang-700.1.81) and 3.0-dev (LLVM b361b0fc05, Clang 11493b0f62, Swift fc26104)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee gradha (JIRA)
Priority Medium

md5: fe202e8bfaf1fa66a16a05747307a3c6

Issue Description:

The following test case can't be compiled by swift. In a file named main.swift put

test_seconds()

and in a file named time_nanos.swift put

struct Nano : CustomStringConvertible {
    var value: Int64 = 0
    init(_ x: Int64) { self.value = x }
    var description: String { return "\(self.value)" }
}

let u_nano = Nano(1)
let u_second = Nano(1_000_000_00)
let u_minute = u_second * 60

func *(lhs: Nano, rhs: Int) -> Nano { return Nano(lhs.value * Int64(rhs)); }
func *(lhs: Int, rhs: Nano) -> Nano { return Nano(Int64(lhs) * rhs.value); }
func +(lhs: Nano, rhs: String) -> String { return lhs.description + rhs; }
func +(lhs: String, rhs: Nano) -> String { return lhs + rhs.description; }
func +(lhs: Nano, rhs: Nano) -> Nano { return Nano(lhs.value + rhs.value); }

extension Int {
    var ns: Nano { return Nano(Int64(self)) }
    var s: Nano { return self * u_second }
    var i: Nano { return self * u_minute }
}

func test_seconds() {
    print("Testing second operations:\n")
    print(u_minute + u_second + Nano(500) + " = " + 1.i + 1.s + 500.ns)
    print((u_minute + u_second + Nano(500)) + " = " + (1.i + 1.s + 500.ns))
}

Compiling from the commandline shows that the first expression is too complex:

$ time swiftc -o main.exe main.swift  time_nanos.swift 
time_nanos.swift:25:2: error: expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions
        print(u_minute + u_second + Nano(500) + " = " + 1.i + 1.s + 500.ns)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

real    0m4.874s
user    0m4.690s
sys 0m0.167s
$ swiftc -v
Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81)
Target: x86_64-apple-darwin15.3.0

If that line is commented out the test compiles in about 1.5 seconds. Using the latest development snapshot swift-DEVELOPMENT-SNAPSHOT-2016-02-25-a-osx the performance seems worse:

$ time swiftc -o main.exe main.swift  time_nanos.swift
time_nanos.swift:25:2: error: expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions
        print(u_minute + u_second + Nano(500) + " = " + 1.i + 1.s + 500.ns)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
time_nanos.swift:26:2: error: expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions
        print((u_minute + u_second + Nano(500)) + " = " + (1.i + 1.s + 500.ns))
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

real    0m7.230s
user    0m7.004s
sys 0m0.212s
$ swiftc -v
Apple Swift version 3.0-dev (LLVM b361b0fc05, Clang 11493b0f62, Swift fc261045a5)
Target: x86_64-apple-macosx10.9

With this version the compiler seems to be worse since even the easier subexpression has troubles being compiled. The compiler shouldn't have troubles with such simple expressions.

@rudkx
Copy link
Member

rudkx commented Aug 25, 2016

Resolved by: 5a8950a

@xedin
Copy link
Member

xedin commented Aug 3, 2017

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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