Repository navigation
Commit 2136250
authored
Rollup merge of #161275 - bushrat011899:variadic_min_refactor, r=scottmcm
Refactor `core::cmp::{smallest, largest}` & add `mir-opt` test
Tracking Issue: #160728
# Description
Based on [this](#160687 (comment)) feedback from the initial implementation, I've added a `mir-opt` test to highlight the amount of MIR added by using a variadic `min` implementation. ~~To my knowledge, there isn't a way to actually test the MIR generated by the actual implementation in `core`, so I've replicated a smaller representative sample in a test instead. Please see [GodBolt](https://godbolt.org/z/1qGzboeo3) for a more detailed comparison between the (unoptimised) MIR for the current and splatted versions of `min` (`max` omitted since it's identical).~~
~~In short, the splat version does produce more MIR, especially for the additional trait implementations for larger tuple sizes. However, the added MIR almost exclusively comes from the indirection of calling a method on a trait, and not specifically the `#[rustc_splat]` variadic implementation. Because of this, it may be worth considering a MIR pass which could inline this kind of static dispatch.~~
Moving to a pre-codegen test with some MIR optimisation has narrowed the gap between `smallest` and `min` to basically nothing (an extra scope from the looks of it). I'm guessing the chained `a.min(b).min(c).min(d)` style (with a lack of explicit temporaries) is something MIR is able to readily optimise!
From experimenting with this test, I also found a simpler way to implement `smaller` and `larger`. The most notable difference is instead of passing all arguments through the splat, I've pulled out the first argument so they aren't de/tupled. It improves codegen slightly, but more importantly simplifies the macro implementation.
---
## Notes
- No AI tooling of any kind was used during the creation of this PR.4 files changed
Lines changed: 115 additions & 49 deletions
File tree
- library/core/src
- tests/mir-opt/pre-codegen
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1967 | 1967 | | |
1968 | 1968 | | |
1969 | 1969 | | |
1970 | | - | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
1971 | 1973 | | |
1972 | 1974 | | |
1973 | 1975 | | |
1974 | | - | |
1975 | | - | |
1976 | | - | |
1977 | | - | |
| 1976 | + | |
1978 | 1977 | | |
1979 | 1978 | | |
1980 | | - | |
1981 | | - | |
1982 | | - | |
1983 | | - | |
1984 | | - | |
1985 | | - | |
1986 | | - | |
1987 | | - | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
1988 | 1983 | | |
1989 | 1984 | | |
1990 | 1985 | | |
| |||
2040 | 2035 | | |
2041 | 2036 | | |
2042 | 2037 | | |
2043 | | - | |
| 2038 | + | |
| 2039 | + | |
2044 | 2040 | | |
2045 | | - | |
| 2041 | + | |
2046 | 2042 | | |
2047 | 2043 | | |
2048 | 2044 | | |
2049 | 2045 | | |
2050 | 2046 | | |
2051 | 2047 | | |
2052 | | - | |
| 2048 | + | |
2053 | 2049 | | |
2054 | | - | |
| 2050 | + | |
2055 | 2051 | | |
2056 | 2052 | | |
2057 | 2053 | | |
2058 | | - | |
2059 | | - | |
2060 | | - | |
2061 | | - | |
2062 | | - | |
2063 | | - | |
2064 | | - | |
2065 | | - | |
2066 | | - | |
2067 | | - | |
2068 | | - | |
2069 | | - | |
2070 | | - | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
2071 | 2064 | | |
2072 | | - | |
| 2065 | + | |
2073 | 2066 | | |
2074 | 2067 | | |
2075 | 2068 | | |
| |||
2125 | 2118 | | |
2126 | 2119 | | |
2127 | 2120 | | |
2128 | | - | |
| 2121 | + | |
| 2122 | + | |
2129 | 2123 | | |
2130 | | - | |
| 2124 | + | |
2131 | 2125 | | |
2132 | 2126 | | |
2133 | 2127 | | |
2134 | 2128 | | |
2135 | 2129 | | |
2136 | 2130 | | |
2137 | | - | |
| 2131 | + | |
2138 | 2132 | | |
2139 | | - | |
| 2133 | + | |
2140 | 2134 | | |
2141 | 2135 | | |
2142 | 2136 | | |
2143 | | - | |
2144 | | - | |
2145 | | - | |
2146 | | - | |
2147 | | - | |
2148 | | - | |
2149 | | - | |
2150 | | - | |
2151 | | - | |
2152 | | - | |
2153 | | - | |
2154 | | - | |
2155 | | - | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
2156 | 2147 | | |
2157 | | - | |
| 2148 | + | |
2158 | 2149 | | |
2159 | 2150 | | |
2160 | 2151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments