Repository navigation
perf:cache FFI safety results in improper_ctypes lint - #163348
Conversation
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
What motivated this change? Do you have any measurements showing that it improves compile times? |
|
The motivation for the change is that the cache is recreated empty at every call site, so a struct shared across many For measurement I profiled a test file containing some
Which gives approx a total of 12% of instructions count reduction. Thank you! |
| let ffi_res = visitor.check_type(state, ty); | ||
| if matches!(ffi_res, FfiResult::FfiSafe) { | ||
| self.known_safe.borrow_mut().insert(key); | ||
| } |
There was a problem hiding this comment.
It's unfortunate to have this contains + "do stuff" + insert pattern repeated three times. Can you factor it out into a separate method? It might need a closure argument for the "do stuff" part.
@rustbot author
There was a problem hiding this comment.
Ok, will make it a separate method . Thank you!
|
Reminder, once the PR becomes ready for a review, use |
|
@rustbot ready |
|
@bors r+ rollup |
… r=nnethercote perf:cache FFI safety results in improper_ctypes lint This PR cache FFI safety results in improper_ctypes lint . ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once . The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.
|
⌛ Testing commit 54a6d2e with merge b1bfbc8... Workflow: https://github.com/rust-lang/rust/actions/runs/37416185729 |
perf:cache FFI safety results in improper_ctypes lint This PR cache FFI safety results in improper_ctypes lint . ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once . The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.
… r=nnethercote perf:cache FFI safety results in improper_ctypes lint This PR cache FFI safety results in improper_ctypes lint . ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once . The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.
|
@bors yield once more |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #163859. |
|
Auto build was cancelled. It was not possible to cancel some workflows. The next pull request likely to be tested is #163831. |
… r=nnethercote perf:cache FFI safety results in improper_ctypes lint This PR cache FFI safety results in improper_ctypes lint . ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once . The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.
… r=nnethercote perf:cache FFI safety results in improper_ctypes lint This PR cache FFI safety results in improper_ctypes lint . ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once . The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.
… r=nnethercote perf:cache FFI safety results in improper_ctypes lint This PR cache FFI safety results in improper_ctypes lint . ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once . The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.
…uwer Rollup of 13 pull requests Successful merges: - #163090 (Run LLDB debuginfo tests on `x86_64-pc-windows-msvc` in CI) - #163863 (use the type name instead of `Self` in constructor paths again) - #163864 (Remove CLAUDE.md) - #163877 (Add regression test for duplicated rustdoc search results between std and core) - #162000 (peel_transparent_wrappers only works on non-1ZST) - #163257 (abby DSL: sanity checks on forall where clauses) - #163348 (perf:cache FFI safety results in improper_ctypes lint) - #163768 (Move more `rustdoc-html` tests in the right location) - #163789 (cg_llvm: Avoid `as_c_char_ptr` in several places) - #163807 (Add `has_reliable_f16b` for Arm) - #163826 (Update books) - #163849 (ci: update to PowerShell 7.6.6) - #163870 (Add if-installed:auto:spellcheck to pre-push script)
… r=nnethercote perf:cache FFI safety results in improper_ctypes lint This PR cache FFI safety results in improper_ctypes lint . ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once . The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.
…uwer Rollup of 17 pull requests Successful merges: - #163090 (Run LLDB debuginfo tests on `x86_64-pc-windows-msvc` in CI) - #163794 (Use `target_family = "wasm"` instead of `target_arch = "wasm32"`) - #163863 (use the type name instead of `Self` in constructor paths again) - #163864 (Remove CLAUDE.md) - #163877 (Add regression test for duplicated rustdoc search results between std and core) - #162000 (peel_transparent_wrappers only works on non-1ZST) - #163257 (abby DSL: sanity checks on forall where clauses) - #163348 (perf:cache FFI safety results in improper_ctypes lint) - #163768 (Move more `rustdoc-html` tests in the right location) - #163778 (check is_indirect_first_projection when replacing in RefProp) - #163789 (cg_llvm: Avoid `as_c_char_ptr` in several places) - #163807 (Add `has_reliable_f16b` for Arm) - #163826 (Update books) - #163849 (ci: update to PowerShell 7.6.6) - #163870 (Add if-installed:auto:spellcheck to pre-push script) - #163874 (explicitly check for fresh vars in canonicalize) - #163880 (Don't add pkgs.rustc to PATH in nix dev shell)
…uwer Rollup of 17 pull requests Successful merges: - #163090 (Run LLDB debuginfo tests on `x86_64-pc-windows-msvc` in CI) - #163794 (Use `target_family = "wasm"` instead of `target_arch = "wasm32"`) - #163863 (use the type name instead of `Self` in constructor paths again) - #163864 (Remove CLAUDE.md) - #163877 (Add regression test for duplicated rustdoc search results between std and core) - #162000 (peel_transparent_wrappers only works on non-1ZST) - #163257 (abby DSL: sanity checks on forall where clauses) - #163348 (perf:cache FFI safety results in improper_ctypes lint) - #163768 (Move more `rustdoc-html` tests in the right location) - #163778 (check is_indirect_first_projection when replacing in RefProp) - #163789 (cg_llvm: Avoid `as_c_char_ptr` in several places) - #163807 (Add `has_reliable_f16b` for Arm) - #163826 (Update books) - #163849 (ci: update to PowerShell 7.6.6) - #163870 (Add if-installed:auto:spellcheck to pre-push script) - #163874 (explicitly check for fresh vars in canonicalize) - #163880 (Don't add pkgs.rustc to PATH in nix dev shell)
…uwer Rollup of 17 pull requests Successful merges: - #163090 (Run LLDB debuginfo tests on `x86_64-pc-windows-msvc` in CI) - #163794 (Use `target_family = "wasm"` instead of `target_arch = "wasm32"`) - #163863 (use the type name instead of `Self` in constructor paths again) - #163864 (Remove CLAUDE.md) - #163877 (Add regression test for duplicated rustdoc search results between std and core) - #162000 (peel_transparent_wrappers only works on non-1ZST) - #163257 (abby DSL: sanity checks on forall where clauses) - #163348 (perf:cache FFI safety results in improper_ctypes lint) - #163768 (Move more `rustdoc-html` tests in the right location) - #163778 (check is_indirect_first_projection when replacing in RefProp) - #163789 (cg_llvm: Avoid `as_c_char_ptr` in several places) - #163807 (Add `has_reliable_f16b` for Arm) - #163826 (Update books) - #163849 (ci: update to PowerShell 7.6.6) - #163870 (Add if-installed:auto:spellcheck to pre-push script) - #163874 (explicitly check for fresh vars in canonicalize) - #163880 (Don't add pkgs.rustc to PATH in nix dev shell)
… r=nnethercote perf:cache FFI safety results in improper_ctypes lint This PR cache FFI safety results in improper_ctypes lint . ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once . The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.
…uwer Rollup of 25 pull requests Successful merges: - #163090 (Run LLDB debuginfo tests on `x86_64-pc-windows-msvc` in CI) - #163806 (even more `tests/crashes` migration for `-Znext-solver`) - #162156 (add IBM f128 type) - #163508 (Document the `rustc_on_unimplemented` attribute.) - #163794 (Use `target_family = "wasm"` instead of `target_arch = "wasm32"`) - #163863 (use the type name instead of `Self` in constructor paths again) - #163864 (Remove CLAUDE.md) - #163877 (Add regression test for duplicated rustdoc search results between std and core) - #163916 (Shrink `PartialRes` and its alignment) - #149753 (On name resolution error in parameter list, suggest possible `const` typo and avoid unnecessary second error) - #152557 (Oneshot `is_ready`) - #157273 (Stabilize `optimize` attribute) - #162000 (peel_transparent_wrappers only works on non-1ZST) - #163257 (abby DSL: sanity checks on forall where clauses) - #163343 (`unit` and `[1 x unit]` layouts are incompatible on big-endian targets) - #163348 (perf:cache FFI safety results in improper_ctypes lint) - #163768 (Move more `rustdoc-html` tests in the right location) - #163778 (check is_indirect_first_projection when replacing in RefProp) - #163789 (cg_llvm: Avoid `as_c_char_ptr` in several places) - #163807 (Add `has_reliable_f16b` for Arm) - #163809 (Switch TLS implementation for wasi and bump SDK version to 34) - #163826 (Update books) - #163849 (ci: update to PowerShell 7.6.6) - #163869 (INSTALL.md: use UCRT64 instead of MINGW64 in MSYS2 section) - #163870 (Add if-installed:auto:spellcheck to pre-push script)
… r=nnethercote perf:cache FFI safety results in improper_ctypes lint This PR cache FFI safety results in improper_ctypes lint . ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once . The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.
…uwer Rollup of 24 pull requests Successful merges: - #163090 (Run LLDB debuginfo tests on `x86_64-pc-windows-msvc` in CI) - #163806 (even more `tests/crashes` migration for `-Znext-solver`) - #163508 (Document the `rustc_on_unimplemented` attribute.) - #163794 (Use `target_family = "wasm"` instead of `target_arch = "wasm32"`) - #163863 (use the type name instead of `Self` in constructor paths again) - #163864 (Remove CLAUDE.md) - #163877 (Add regression test for duplicated rustdoc search results between std and core) - #163916 (Shrink `PartialRes` and its alignment) - #149753 (On name resolution error in parameter list, suggest possible `const` typo and avoid unnecessary second error) - #152557 (Oneshot `is_ready`) - #157273 (Stabilize `optimize` attribute) - #162000 (peel_transparent_wrappers only works on non-1ZST) - #163257 (abby DSL: sanity checks on forall where clauses) - #163343 (`unit` and `[1 x unit]` layouts are incompatible on big-endian targets) - #163348 (perf:cache FFI safety results in improper_ctypes lint) - #163768 (Move more `rustdoc-html` tests in the right location) - #163778 (check is_indirect_first_projection when replacing in RefProp) - #163789 (cg_llvm: Avoid `as_c_char_ptr` in several places) - #163807 (Add `has_reliable_f16b` for Arm) - #163809 (Switch TLS implementation for wasi and bump SDK version to 34) - #163826 (Update books) - #163849 (ci: update to PowerShell 7.6.6) - #163869 (INSTALL.md: use UCRT64 instead of MINGW64 in MSYS2 section) - #163870 (Add if-installed:auto:spellcheck to pre-push script)
…uwer Rollup of 24 pull requests Successful merges: - #163090 (Run LLDB debuginfo tests on `x86_64-pc-windows-msvc` in CI) - #163806 (even more `tests/crashes` migration for `-Znext-solver`) - #163508 (Document the `rustc_on_unimplemented` attribute.) - #163794 (Use `target_family = "wasm"` instead of `target_arch = "wasm32"`) - #163863 (use the type name instead of `Self` in constructor paths again) - #163864 (Remove CLAUDE.md) - #163877 (Add regression test for duplicated rustdoc search results between std and core) - #163916 (Shrink `PartialRes` and its alignment) - #149753 (On name resolution error in parameter list, suggest possible `const` typo and avoid unnecessary second error) - #152557 (Oneshot `is_ready`) - #157273 (Stabilize `optimize` attribute) - #162000 (peel_transparent_wrappers only works on non-1ZST) - #163257 (abby DSL: sanity checks on forall where clauses) - #163343 (`unit` and `[1 x unit]` layouts are incompatible on big-endian targets) - #163348 (perf:cache FFI safety results in improper_ctypes lint) - #163768 (Move more `rustdoc-html` tests in the right location) - #163778 (check is_indirect_first_projection when replacing in RefProp) - #163789 (cg_llvm: Avoid `as_c_char_ptr` in several places) - #163807 (Add `has_reliable_f16b` for Arm) - #163809 (Switch TLS implementation for wasi and bump SDK version to 34) - #163826 (Update books) - #163849 (ci: update to PowerShell 7.6.6) - #163869 (INSTALL.md: use UCRT64 instead of MINGW64 in MSYS2 section) - #163870 (Add if-installed:auto:spellcheck to pre-push script)
…uwer Rollup of 24 pull requests Successful merges: - #163090 (Run LLDB debuginfo tests on `x86_64-pc-windows-msvc` in CI) - #163806 (even more `tests/crashes` migration for `-Znext-solver`) - #163508 (Document the `rustc_on_unimplemented` attribute.) - #163794 (Use `target_family = "wasm"` instead of `target_arch = "wasm32"`) - #163863 (use the type name instead of `Self` in constructor paths again) - #163864 (Remove CLAUDE.md) - #163877 (Add regression test for duplicated rustdoc search results between std and core) - #163916 (Shrink `PartialRes` and its alignment) - #149753 (On name resolution error in parameter list, suggest possible `const` typo and avoid unnecessary second error) - #152557 (Oneshot `is_ready`) - #157273 (Stabilize `optimize` attribute) - #162000 (peel_transparent_wrappers only works on non-1ZST) - #163257 (abby DSL: sanity checks on forall where clauses) - #163343 (`unit` and `[1 x unit]` layouts are incompatible on big-endian targets) - #163348 (perf:cache FFI safety results in improper_ctypes lint) - #163768 (Move more `rustdoc-html` tests in the right location) - #163778 (check is_indirect_first_projection when replacing in RefProp) - #163789 (cg_llvm: Avoid `as_c_char_ptr` in several places) - #163807 (Add `has_reliable_f16b` for Arm) - #163809 (Switch TLS implementation for wasi and bump SDK version to 34) - #163826 (Update books) - #163849 (ci: update to PowerShell 7.6.6) - #163869 (INSTALL.md: use UCRT64 instead of MINGW64 in MSYS2 section) - #163870 (Add if-installed:auto:spellcheck to pre-push script)
…uwer Rollup of 24 pull requests Successful merges: - #163090 (Run LLDB debuginfo tests on `x86_64-pc-windows-msvc` in CI) - #163806 (even more `tests/crashes` migration for `-Znext-solver`) - #163508 (Document the `rustc_on_unimplemented` attribute.) - #163794 (Use `target_family = "wasm"` instead of `target_arch = "wasm32"`) - #163863 (use the type name instead of `Self` in constructor paths again) - #163864 (Remove CLAUDE.md) - #163877 (Add regression test for duplicated rustdoc search results between std and core) - #163916 (Shrink `PartialRes` and its alignment) - #149753 (On name resolution error in parameter list, suggest possible `const` typo and avoid unnecessary second error) - #152557 (Oneshot `is_ready`) - #157273 (Stabilize `optimize` attribute) - #162000 (peel_transparent_wrappers only works on non-1ZST) - #163257 (abby DSL: sanity checks on forall where clauses) - #163343 (`unit` and `[1 x unit]` layouts are incompatible on big-endian targets) - #163348 (perf:cache FFI safety results in improper_ctypes lint) - #163768 (Move more `rustdoc-html` tests in the right location) - #163778 (check is_indirect_first_projection when replacing in RefProp) - #163789 (cg_llvm: Avoid `as_c_char_ptr` in several places) - #163807 (Add `has_reliable_f16b` for Arm) - #163809 (Switch TLS implementation for wasi and bump SDK version to 34) - #163826 (Update books) - #163849 (ci: update to PowerShell 7.6.6) - #163869 (INSTALL.md: use UCRT64 instead of MINGW64 in MSYS2 section) - #163870 (Add if-installed:auto:spellcheck to pre-push script)
…uwer Rollup of 23 pull requests Successful merges: - #163090 (Run LLDB debuginfo tests on `x86_64-pc-windows-msvc` in CI) - #163806 (even more `tests/crashes` migration for `-Znext-solver`) - #163508 (Document the `rustc_on_unimplemented` attribute.) - #163794 (Use `target_family = "wasm"` instead of `target_arch = "wasm32"`) - #163863 (use the type name instead of `Self` in constructor paths again) - #163864 (Remove CLAUDE.md) - #163877 (Add regression test for duplicated rustdoc search results between std and core) - #163916 (Shrink `PartialRes` and its alignment) - #149753 (On name resolution error in parameter list, suggest possible `const` typo and avoid unnecessary second error) - #152557 (Oneshot `is_ready`) - #157273 (Stabilize `optimize` attribute) - #162000 (peel_transparent_wrappers only works on non-1ZST) - #163343 (`unit` and `[1 x unit]` layouts are incompatible on big-endian targets) - #163348 (perf:cache FFI safety results in improper_ctypes lint) - #163768 (Move more `rustdoc-html` tests in the right location) - #163778 (check is_indirect_first_projection when replacing in RefProp) - #163789 (cg_llvm: Avoid `as_c_char_ptr` in several places) - #163807 (Add `has_reliable_f16b` for Arm) - #163809 (Switch TLS implementation for wasi and bump SDK version to 34) - #163826 (Update books) - #163849 (ci: update to PowerShell 7.6.6) - #163869 (INSTALL.md: use UCRT64 instead of MINGW64 in MSYS2 section) - #163870 (Add if-installed:auto:spellcheck to pre-push script)
Rollup merge of #163348 - xonx4l:improper_ctypes-lint-cache, r=nnethercote perf:cache FFI safety results in improper_ctypes lint This PR cache FFI safety results in improper_ctypes lint . ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once . The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.
|
Note This PR was benchmarked as part of triage of its containing rollup: triage URL. Finished benchmarking commit (e5ce1f7): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This perf run didn't have relevant results for this metric. CyclesThis perf run didn't have relevant results for this metric. Binary sizeThis perf run didn't have relevant results for this metric. Artifact size: 408.59 MiB -> 408.61 MiB (0.00%) |
|
This is noise, all PRs in the rollup have the same results |
This PR cache FFI safety results in improper_ctypes lint .
ImproperCTypesVisitor's cache field is recreated empty at every call site, so a struct type gets fully re-walked from scratch each time instead of once .
The implementation here moves the cache onto ImproperCtypesLint, so it remembers types we already checked and found FFI-safe, so we don't check the same type again every time it shows up in another function. We only remember "safe" types, never "unsafe" ones. That way we never need to keep the actual type around, just a fingerprint of it.Thus it persists across a whole module worth of foreign items.