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

Revise never type fallback algorithm #88804

Merged
merged 7 commits into from
Sep 24, 2021

Commits on Sep 17, 2021

  1. introduce new fallback algorithm

    We now fallback type variables using the following rules:
    
    * Construct a coercion graph `A -> B` where `A` and `B` are unresolved
      type variables or the `!` type.
    * Let D be those variables that are reachable from `!`.
    * Let N be those variables that are reachable from a variable not in
    D.
    * All variables in (D \ N) fallback to `!`.
    * All variables in (D & N) fallback to `()`.
    nikomatsakis authored and Mark-Simulacrum committed Sep 17, 2021
    Configuration menu
    Copy the full SHA
    2ee8914 View commit details
    Browse the repository at this point in the history
  2. remove diverging type variables from fn check

    The comment seems incorrect. Testing revealed that the examples in
    question still work (as well as some variants) even without the
    special casing here.
    nikomatsakis authored and Mark-Simulacrum committed Sep 17, 2021
    Configuration menu
    Copy the full SHA
    ebb8ff9 View commit details
    Browse the repository at this point in the history
  3. remove reliance on "diverging" type variables

    Instead, we now record those type variables that are the target of a
    `NeverToAny` adjustment and consider those to be the "diverging" type
    variables. This allows us to remove the special case logic that
    creates a type variable for `!` in coercion.
    nikomatsakis authored and Mark-Simulacrum committed Sep 17, 2021
    Configuration menu
    Copy the full SHA
    1c004f2 View commit details
    Browse the repository at this point in the history
  4. stop categorizing inference variables as diverging when created

    Instead, we now rely on the code that looks for a NeverToAny adjustment.
    nikomatsakis authored and Mark-Simulacrum committed Sep 17, 2021
    Configuration menu
    Copy the full SHA
    bc2ece2 View commit details
    Browse the repository at this point in the history
  5. optimization: use a single DepthFirstSearch instead of hashsets

    Extend the `DepthFirstSearch` iterator so that it can be re-used and
    extended with add'l start nodes. Then replace the FxHashSets of nodes
    we were using in the fallback analysis with a single iterator. This
    way we won't re-walk portions of the graph that are reached more than
    once, and we also do less allocation etc.
    nikomatsakis authored and Mark-Simulacrum committed Sep 17, 2021
    Configuration menu
    Copy the full SHA
    59dc201 View commit details
    Browse the repository at this point in the history
  6. Add another case of fallback to () avoid breakage

    This adds src/test/ui/never_type/fallback-closure-ret.rs as a test case which
    showcases the failure mode fixed by this commit.
    Mark-Simulacrum committed Sep 17, 2021
    Configuration menu
    Copy the full SHA
    078e3fd View commit details
    Browse the repository at this point in the history
  7. Add nofallback tests

    Mark-Simulacrum committed Sep 17, 2021
    Configuration menu
    Copy the full SHA
    c4c5fc8 View commit details
    Browse the repository at this point in the history