Commit 3120b98
authored
Optimize
Fixes rust-lang#16605
This PR addresses the 6.2% compilation performance regression introduced
by the original `allow_unwrap_types` implementation (which natively
allocated AST strings on every `unwrap` call via `bumpalo`).
The implementation has been refactored to pre-resolve types securely
without a performance penalty:
**Pre-Resolution Cache via `LateLintPass`**: Instead of executing
`ty.to_string()` and `lookup_path_str` inside the immediate
`unwrap_expect_used` hot check for every method call encountered,
`allow-unwrap-types` configuration strings are now parsed exactly *once*
per crate compilation during the `LateLintPass::check_crate` hook in
`clippy_lints/src/methods/mod.rs`.
**`DefId` Native Storage**: The parsed `DefId` representations are
stored in-memory using highly efficient caching maps directly on the
main `Methods` struct:
- `unwrap_allowed_ids: FxHashSet<DefId>`: Allows instant O(1) lookups
for standard types.
- `unwrap_allowed_aliases: Vec<DefId>`: Tracks type aliases requiring
signature substitution checking later.
**Execution Relief**: Inside `unwrap_expect_used::check()`, string
manipulation is completely removed and `ty::Adt` checking uses
lightning-fast `.contains(&adt.did())` operations to categorically avoid
regression allocation loops. This implementation strongly parallels the
pre-resolution type-routing logic in
`clippy_config::types::create_disallowed_map` without altering the core
`clippy.toml` config requirements.
<!-- TRIAGEBOT_START -->
<!-- TRIAGEBOT_SUMMARY_START -->
### Summary Notes
-
[Beta-nomination](rust-lang#16652 (comment))
by [samueltardieu](https://github.com/samueltardieu)
*Managed by `@rustbot`—see
[help](https://forge.rust-lang.org/triagebot/note.html) for details*
<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
changelog: noneallow_unwrap_types evaluation to eliminate performance regression (rust-lang#16652)2 files changed
+64
-48
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4761 | 4761 | | |
4762 | 4762 | | |
4763 | 4763 | | |
| 4764 | + | |
| 4765 | + | |
4764 | 4766 | | |
4765 | 4767 | | |
4766 | 4768 | | |
| |||
4778 | 4780 | | |
4779 | 4781 | | |
4780 | 4782 | | |
| 4783 | + | |
| 4784 | + | |
4781 | 4785 | | |
4782 | 4786 | | |
4783 | 4787 | | |
| |||
4953 | 4957 | | |
4954 | 4958 | | |
4955 | 4959 | | |
| 4960 | + | |
| 4961 | + | |
| 4962 | + | |
| 4963 | + | |
| 4964 | + | |
| 4965 | + | |
| 4966 | + | |
| 4967 | + | |
| 4968 | + | |
| 4969 | + | |
| 4970 | + | |
| 4971 | + | |
| 4972 | + | |
4956 | 4973 | | |
4957 | 4974 | | |
4958 | 4975 | | |
| |||
4976 | 4993 | | |
4977 | 4994 | | |
4978 | 4995 | | |
4979 | | - | |
| 4996 | + | |
| 4997 | + | |
4980 | 4998 | | |
4981 | 4999 | | |
4982 | 5000 | | |
| |||
5730 | 5748 | | |
5731 | 5749 | | |
5732 | 5750 | | |
5733 | | - | |
| 5751 | + | |
| 5752 | + | |
5734 | 5753 | | |
5735 | 5754 | | |
5736 | 5755 | | |
| |||
5743 | 5762 | | |
5744 | 5763 | | |
5745 | 5764 | | |
5746 | | - | |
| 5765 | + | |
| 5766 | + | |
5747 | 5767 | | |
5748 | 5768 | | |
5749 | 5769 | | |
| |||
5764 | 5784 | | |
5765 | 5785 | | |
5766 | 5786 | | |
5767 | | - | |
| 5787 | + | |
| 5788 | + | |
5768 | 5789 | | |
5769 | 5790 | | |
5770 | 5791 | | |
| |||
5776 | 5797 | | |
5777 | 5798 | | |
5778 | 5799 | | |
5779 | | - | |
| 5800 | + | |
| 5801 | + | |
5780 | 5802 | | |
5781 | 5803 | | |
5782 | 5804 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 70 | + | |
| 71 | + | |
73 | 72 | | |
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
108 | 86 | | |
109 | | - | |
110 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
111 | 97 | | |
112 | 98 | | |
113 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
114 | 103 | | |
115 | 104 | | |
116 | 105 | | |
| |||
149 | 138 | | |
150 | 139 | | |
151 | 140 | | |
152 | | - | |
| 141 | + | |
| 142 | + | |
153 | 143 | | |
154 | 144 | | |
155 | 145 | | |
| |||
167 | 157 | | |
168 | 158 | | |
169 | 159 | | |
170 | | - | |
| 160 | + | |
| 161 | + | |
171 | 162 | | |
172 | 163 | | |
173 | 164 | | |
| |||
179 | 170 | | |
180 | 171 | | |
181 | 172 | | |
182 | | - | |
| 173 | + | |
| 174 | + | |
183 | 175 | | |
184 | 176 | | |
185 | 177 | | |
| |||
191 | 183 | | |
192 | 184 | | |
193 | 185 | | |
194 | | - | |
| 186 | + | |
| 187 | + | |
195 | 188 | | |
196 | 189 | | |
197 | 190 | | |
| |||
203 | 196 | | |
204 | 197 | | |
205 | 198 | | |
206 | | - | |
| 199 | + | |
| 200 | + | |
207 | 201 | | |
208 | 202 | | |
209 | 203 | | |
| |||
0 commit comments