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

[Concurrency] Tune overloading to to allow sync overloads in async contexts #36247

Merged

Commits on Mar 3, 2021

  1. [Concurrency] Tune overloading to to allow sync overloads in async co…

    …ntexts.
    
    The existing overloading rules strongly prefer async functions within
    async contexts, and synchronous functions in synchronous contexts.
    However, when there are other differences in the
    signature, particularly parameters of function type that differ in
    async vs. synchronous, the overloading rule would force the use of the
    synchronous function even in cases where the synchronous function
    would be better. An example:
    
        func f(_: (Int) -> Int) { }
        func f(_: (Int) async -> Int) async { }
    
        func g(_ x: Int) -> Int { -x }
    
        func h() async {
          f(g) // currently selects async f, want to select synchronous f
        }
    
    Effect the semantics change by splitting the "sync/async mismatch"
    score in the constraint system into an "async in sync mismatch" score
    that is mostly disqualifying (because the call will always fail) and a
    less-important score for "sync used in an async context", which also
    includes conversion from a synchronous function to an asynchronous
    one. This way, only synchronous functions are still considered within
    a synchronous context, but we get more natural overloading behavior
    within an asynchronous context. The end result is intended to be
    equivalent to what one would get with reasync:
    
      func f(_: (Int) async -> Int) async { ... }
    
    Addresses rdar://74289867.
    DougGregor committed Mar 3, 2021
    Configuration menu
    Copy the full SHA
    9ccf206 View commit details
    Browse the repository at this point in the history