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 |
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.