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

Overloading on borrowing/consuming results in ambiguities with performance hacks removed #77001

Open
xedin opened this issue Oct 13, 2024 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. ownership Feature: Ownership modifiers and semantics

Comments

@xedin
Copy link
Contributor

xedin commented Oct 13, 2024

Description

One of the test-cases introduced by #76834 depends on a type-checker hack that applies only to initializers - https://github.com/swiftlang/swift/blob/main/lib/Sema/CSSimplify.cpp#L9843-L9855. Removal of this hack makes the code ambiguous.

Reproduction

struct View : ~Escapable {
 init(_ otherBV: borrowing View) {}
 init(_ k: consuming View) {}
}

@lifetime(x)
func getConsumingView(_ x: consuming View) -> View {
  return View(x)
}

Without perf hack this produces:

 error: ambiguous use of 'init(_:)'

Expected behavior

We need to define expected type/flag matching behavior for borrowing and consuming parameters that does not depend on the performance hack(s).

Environment

Swift compiler main branch.

Additional information

No response

@xedin xedin added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Oct 13, 2024
@xedin
Copy link
Contributor Author

xedin commented Oct 13, 2024

cc @meg-gupta

@xedin
Copy link
Contributor Author

xedin commented Oct 13, 2024

This is actually even worse than just ambiguity because the hack always prefers the first overload which means that flipping overloads around would result in a different pick.

@meg-gupta meg-gupta added ownership Feature: Ownership modifiers and semantics and removed triage needed This issue needs more specific labels labels Oct 14, 2024
@meg-gupta
Copy link
Contributor

This is an issue with non initializers as well.

This is accepted:

class Klass {}

func test(_ a: borrowing Klass) {}
func test(_ a: consuming Klass) {}

@jckarter
Copy link
Contributor

These should be rejected. We don't allow overloading on ownership qualifiers.

@xedin
Copy link
Contributor Author

xedin commented Oct 14, 2024

@meg-gupta Yeah, similar hack for one parameter overload sets, but that falls apart when there is more than one.

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. ownership Feature: Ownership modifiers and semantics
Projects
None yet
Development

No branches or pull requests

3 participants