Skip to content

[6.0][ConstraintSystem] Order VarDecls before other kinds of decls in disjunctions. #72784

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

Merged

Conversation

hborla
Copy link
Member

@hborla hborla commented Apr 2, 2024

  • Explanation: The implementation of count(where:) caused a source compatibility failure in penny-bot. The following code example was reduced from the project:

    func f(
      a: String?,
      b: String?,
      c: Int,
      d: String?,
      e: String?
    ) -> Int {
      return (a?.unicodeScalars.count ?? 0) +
      (b?.unicodeScalars.count ?? 0) +
      c +
      (d?.unicodeScalars.count ?? 0) +
      (e?.unicodeScalars.count ?? 0)
    }

    To fix this, order VarDecls before other kinds of declarations in a disjunction because they are effectively favored over functions when the two are in the same overload set. This disjunction order allows SK_UnappliedFunction to prune later overload choices that are functions when a solution has already been found with a property.

  • Scope: Only impacts overload sets that contain both VarDecls and other kinds of declarations.

  • Risk: Changing type variable binding order always carries some amount of risk for code that happened to find a solution faster with the old binding order, but it's rare to have functions and variables in the same overload set, so I would call this a relatively low risk constraint system change.

  • Testing: Added a new type checker performance test. Source compatibility testing for penny-bot also succeeded on main.

  • Reviewer: @xedin

  • Main branch PR: [ConstraintSystem] Order VarDecls before other kinds of decls in disjunctions. #72755

hborla added 2 commits April 2, 2024 13:57
…ce test now

that it's in the standard library.

(cherry picked from commit a3ac8ec)
@hborla hborla requested a review from a team as a code owner April 2, 2024 20:59
@hborla
Copy link
Member Author

hborla commented Apr 2, 2024

@swift-ci please test

@rintaro rintaro merged commit 34a8bf4 into swiftlang:release/6.0 Apr 3, 2024
@hborla hborla deleted the 6.0-disjunction-variable-ordering branch April 3, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants