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

Refactor pattern-matching usefulness algorithm #65160

Closed
wants to merge 87 commits into from

Commits on Oct 18, 2019

  1. Run rustfmt

    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    c9b33ee View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    3ea9c9c View commit details
    Browse the repository at this point in the history
  3. Clarify and fix the explanation of the algorithm

    There was a bit of confusion between individual patterns and lists of
    patterns, and index mismatches linked to that. This introduces a
    vocabulary of "pattern-stacks" to provide a clearer mental model of what
    is happening. This also adds examples.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    f983460 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    77e3a95 View commit details
    Browse the repository at this point in the history
  5. Remove some redundancy

    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    e1b7627 View commit details
    Browse the repository at this point in the history
  6. Remove duplicate logic in compute_missing_constructors

    This is equivalent to the previous code in terms of performance. The
    expensive path is clearly identical. The fast path is also the same,
    because in both cases we loop until we get a non-empty `refined_ctors`,
    and then stop there. So the new code doesn't compute anything more
    than the previous did.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    a075db8 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    7ee9cb7 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    a150d97 View commit details
    Browse the repository at this point in the history
  9. Clarify some variable names

    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    f0e8c78 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    8a2274b View commit details
    Browse the repository at this point in the history
  11. Wording

    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    0f5e02e View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    c95b7ae View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    ea3fe4e View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    d4cc125 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    501cf3a View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    b2ae93c View commit details
    Browse the repository at this point in the history
  17. Rework the exhaustiveness algorithm to better integrate meta-construc…

    …tors
    
    This is strictly a refactoring: the new algorithm does exactly the same
    work as the previous one. However, it replaces the ad-hoc handling of
    ranges and slice patterns with a unified approach, using meta-constructors.
    This should improve both code legibility and future extensibility.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    89df721 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    1bd18d2 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    ad28919 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    ec57a89 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    6d9a35d View commit details
    Browse the repository at this point in the history
  22. Match constructor first instead of type first in various functions

    Needed since there may now be meta-constructors for the given type.
    Also implement the trivial MissingConstructors cases for some of those functions.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    6e392f0 View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    d9871b8 View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    cf90304 View commit details
    Browse the repository at this point in the history
  25. Factor out some bits

    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    931d7a9 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    142df8b View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    cb4715d View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    a1b3800 View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    6337864 View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    c0359ce View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    33273f2 View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    cb3452c View commit details
    Browse the repository at this point in the history
  33. Gather together usefulness tests

    I took most tests that were testing only for match exhaustiveness,
    pattern refutability or match arm reachability, and put them in
    the same test folder.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    ad78eff View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    a91cdd4 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    8e89f3c View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    9ae4c52 View commit details
    Browse the repository at this point in the history
  37. Use Wildcard instead of MissingConstructors when relevant

    This both simplifies the missing constructors codepath and
    exactly matches what we want for witness construction. So this
    behaviour of witness construction isn't an ad-hoc tweak anymore,
    it also makes semantic sense.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    b3de6fd View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    4be3802 View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    d12b172 View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    2687140 View commit details
    Browse the repository at this point in the history
  41. Extract constructor_intersects_pattern function

    This reverses changes from rust-lang#65089, but I need this temporarily
    for rebase to be tractable.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    1f8d93c View commit details
    Browse the repository at this point in the history
  42. Configuration menu
    Copy the full SHA
    1b65bec View commit details
    Browse the repository at this point in the history
  43. Configuration menu
    Copy the full SHA
    12bb3b7 View commit details
    Browse the repository at this point in the history
  44. Regroup similar code paths

    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    022c620 View commit details
    Browse the repository at this point in the history
  45. Configuration menu
    Copy the full SHA
    0ab764b View commit details
    Browse the repository at this point in the history
  46. Configuration menu
    Copy the full SHA
    956838d View commit details
    Browse the repository at this point in the history
  47. Configuration menu
    Copy the full SHA
    1793ad5 View commit details
    Browse the repository at this point in the history
  48. Configuration menu
    Copy the full SHA
    527fe65 View commit details
    Browse the repository at this point in the history
  49. Configuration menu
    Copy the full SHA
    0d58ead View commit details
    Browse the repository at this point in the history
  50. Make exhaustiveness error message more consistent for slice patterns

    Now it doesn't depend on the rather arbitrary (from the user's point of
    view) max_slice_length limit. When slice_patterns is not enabled, and
    the missing pattern is e.g. `[_, _, ..]`, the message will report that
    `[_, _]` is missing. Previously, it would sometimes report a few more
    missing patterns but of course never all of them. When the feature is
    enabled, the message correctly reports that `[_, _, ..]` is missing.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    0b353b3 View commit details
    Browse the repository at this point in the history
  51. Configuration menu
    Copy the full SHA
    cf4dc88 View commit details
    Browse the repository at this point in the history
  52. Configuration menu
    Copy the full SHA
    1e43487 View commit details
    Browse the repository at this point in the history
  53. Configuration menu
    Copy the full SHA
    c8ac41e View commit details
    Browse the repository at this point in the history
  54. Tidy up

    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    244ac8d View commit details
    Browse the repository at this point in the history
  55. Configuration menu
    Copy the full SHA
    ad09cc5 View commit details
    Browse the repository at this point in the history
  56. Configuration menu
    Copy the full SHA
    47ee628 View commit details
    Browse the repository at this point in the history
  57. Inline max_slice_length

    Note that where we previously ran `max_slice_len` with input having not
    only matrix_head_ctors but also all of v_constructors. Now we run it on
    matrix_head_ctors and one constructor of v_constructors at a time. In
    the presence of or-patterns, those two things might differ. However the
    new behaviour is still valid with regards to the specified semantics of
    split_meta_constructor.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    c6d1cad View commit details
    Browse the repository at this point in the history
  58. Add some test cases

    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    0c0fe9f View commit details
    Browse the repository at this point in the history
  59. Splitting variable-length slices now respects the required invariant

    The previous behaviour did not respect the invariant specified in the
    description of the algorithm. As a nice side-effect, exhaustiveness
    errors have improved when slice_patterns is enabled; they now capture
    all missing lengths instead of the shortest.
    Note: this changes diagnostics, but only when slice_patterns is enabled.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    6b4426a View commit details
    Browse the repository at this point in the history
  60. PatCtxt is not useful anymore

    It was introduced to carry max_slice_length so we don't need it anymore.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    72c3a68 View commit details
    Browse the repository at this point in the history
  61. Cleanup comments

    Several comments were leftover from before the rework of the algorithm
    and didn't make sens anymore.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    f5d833f View commit details
    Browse the repository at this point in the history
  62. Store Const in ConstantRange

    This makes the conversions from/to Const better localized. In
    particular, eval_bits only happens in IntRange::from_ctor.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    94227f5 View commit details
    Browse the repository at this point in the history
  63. Configuration menu
    Copy the full SHA
    60021ce View commit details
    Browse the repository at this point in the history
  64. Configuration menu
    Copy the full SHA
    3d0945d View commit details
    Browse the repository at this point in the history
  65. Configuration menu
    Copy the full SHA
    5badbb7 View commit details
    Browse the repository at this point in the history
  66. Incorporate varkor's review

    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    defc66d View commit details
    Browse the repository at this point in the history
  67. Configuration menu
    Copy the full SHA
    d8b71d4 View commit details
    Browse the repository at this point in the history
  68. Move range exhaustiveness check to IntRange::intersection

    Only IntRange needs to worry about range exhaustiveness really.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    66dac52 View commit details
    Browse the repository at this point in the history
  69. Configuration menu
    Copy the full SHA
    b85e4be View commit details
    Browse the repository at this point in the history
  70. Configuration menu
    Copy the full SHA
    eea0b79 View commit details
    Browse the repository at this point in the history
  71. Configuration menu
    Copy the full SHA
    34b0774 View commit details
    Browse the repository at this point in the history
  72. Configuration menu
    Copy the full SHA
    087adfe View commit details
    Browse the repository at this point in the history
  73. Configuration menu
    Copy the full SHA
    a66dcd5 View commit details
    Browse the repository at this point in the history
  74. Configuration menu
    Copy the full SHA
    a2624f2 View commit details
    Browse the repository at this point in the history
  75. Configuration menu
    Copy the full SHA
    79efdb4 View commit details
    Browse the repository at this point in the history
  76. Configuration menu
    Copy the full SHA
    1f6a5a5 View commit details
    Browse the repository at this point in the history
  77. Configuration menu
    Copy the full SHA
    455095a View commit details
    Browse the repository at this point in the history
  78. Configuration menu
    Copy the full SHA
    d379a43 View commit details
    Browse the repository at this point in the history
  79. Configuration menu
    Copy the full SHA
    1de1683 View commit details
    Browse the repository at this point in the history
  80. Configuration menu
    Copy the full SHA
    3aa5fb3 View commit details
    Browse the repository at this point in the history
  81. Name the field of PatStack

    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    c956c65 View commit details
    Browse the repository at this point in the history
  82. Configuration menu
    Copy the full SHA
    368c71b View commit details
    Browse the repository at this point in the history
  83. Compute constructors on PatStack construction

    All the constructed PatStacks end up having `head_ctors` called on them,
    so this does not unnecessarily precompute anything.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    6df1815 View commit details
    Browse the repository at this point in the history
  84. Restore performance

    Stop checking that cached constructors are valid. Avoid cloning
    constructors when not necessary.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    ed3ea67 View commit details
    Browse the repository at this point in the history
  85. Configuration menu
    Copy the full SHA
    9c3682f View commit details
    Browse the repository at this point in the history
  86. Don't use SmallVec when we could use Option

    This reverts some of the or-patterns future-proofing, for the sake of
    performance.
    Nadrieril committed Oct 18, 2019
    Configuration menu
    Copy the full SHA
    b052036 View commit details
    Browse the repository at this point in the history
  87. Configuration menu
    Copy the full SHA
    fd3ec66 View commit details
    Browse the repository at this point in the history