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

Use TrustedRandomAccess for loop desugaring #93243

Closed
wants to merge 13 commits into from

Commits on Apr 19, 2022

  1. add benchmark

    the8472 committed Apr 19, 2022
    Configuration menu
    Copy the full SHA
    c7e60e7 View commit details
    Browse the repository at this point in the history
  2. This aligns the inline attributes of existing `__iterator_get_uncheck…

    …ed` with those of `next()` on adapters that have both.
    
    It improves the performance of iterators using unchecked access when building in incremental mode
    (due to the larger CGU count?). It might negatively affect incremental compile times for better runtime results,
    but considering that the equivalent `next()` implementations also are `#[inline]` and usually are more complex this
    should be ok.
    
    ```
    ./x.py bench library/core -i --stage 0 --test-args bench_trusted_random_access
    
    OLD: 119,172 ns/iter
    NEW:  17,714 ns/iter
    ```
    the8472 committed Apr 19, 2022
    Configuration menu
    Copy the full SHA
    f6dea97 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    f1b9b12 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    0eacaab View commit details
    Browse the repository at this point in the history
  5. bless diagnostics

    the8472 committed Apr 19, 2022
    Configuration menu
    Copy the full SHA
    7d10caf View commit details
    Browse the repository at this point in the history
  6. Remove fake IntoIterator trait, invoke ForLoopDesugar directly and ru…

    …n cleanup on drop
    
    The on-drop cleanup will enable using TRA in try_fold(&mut self) and implementing TRA for &mut Iterator
    the8472 committed Apr 19, 2022
    Configuration menu
    Copy the full SHA
    0b534b3 View commit details
    Browse the repository at this point in the history
  7. simplify iter::Zip

    This removes all TrustedRandomAccess specialization from Zip, which means Zip::next no
    longer gets optimized as well. But since for loop desugaring uses TRA we retain most of the benefits.
    
    We're still losing optimizations on fold, try_fold and reverse iteration. But those can
    be re-specialized more easily.
    the8472 committed Apr 19, 2022
    Configuration menu
    Copy the full SHA
    a56524a View commit details
    Browse the repository at this point in the history
  8. Reimplement TrustedRandomAccess specializations for Zip::fold and Zip…

    …::try_fold
    
    Previously these optimizations automatically fell out of the default implementation for `fold` and `try_fold`
    because `next()` was specialized. Since that is gone we now need to implement it explicitly.
    the8472 committed Apr 19, 2022
    Configuration menu
    Copy the full SHA
    e6d6e5c View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    a66cd5b View commit details
    Browse the repository at this point in the history
  10. remove TrustedRandomAccess vs. TrustedRandomAccessNoCoerce distinction

    TRA is no longer used for single-step (`next()`) specializations, only loops and after each
    loop we bring the iterator back into a safe state, meaning coercions are now safe because
    the user code will not have access to an iterator instance that would be unsafe to coerce.
    the8472 committed Apr 19, 2022
    Configuration menu
    Copy the full SHA
    aec6846 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    9686822 View commit details
    Browse the repository at this point in the history

Commits on Apr 20, 2022

  1. Use marker/specialization traits instead of associated consts to sign…

    …al the need for pre/post loop calls
    
    The loop setup and cleanup functions are only required for some specific iterators.
    To avoid emitting IR when they're not needed even in debug mode we need to use the type system
    instead of const-DCE because the constants would only be known after monomorphization.
    the8472 committed Apr 20, 2022
    Configuration menu
    Copy the full SHA
    14f829a View commit details
    Browse the repository at this point in the history
  2. use separate methods for forward and backward cleanup

    This reduces the amount of IR generated when post-loop cleanup is needed
    the8472 committed Apr 20, 2022
    Configuration menu
    Copy the full SHA
    ffff194 View commit details
    Browse the repository at this point in the history