lint ImproperCTypes: refactor linting architecture (part 2)#146273
lint ImproperCTypes: refactor linting architecture (part 2)#146273niacdoial wants to merge 2 commits intorust-lang:mainfrom
Conversation
There was a problem hiding this comment.
I think a lot of this makes sense, but aren't there behavior changes here? It looks like tuples and arrays may be treated slightly differently.
Which is probably fine, that would ideally just be split from the refactoring and come with test updates.
1dbb0e2 to
f54061c
Compare
I moved the actual change in behaviour in a later commit. |
This comment has been minimized.
This comment has been minimized.
f54061c to
66037fd
Compare
This comment has been minimized.
This comment has been minimized.
66037fd to
2781ebd
Compare
"split type visiting into subfunctions" still has some changes right? (Possible I'm missing something here) |
That's a bit of logic that was moved from |
efe195a to
69b0807
Compare
This comment has been minimized.
This comment has been minimized.
69b0807 to
64106e6
Compare
|
Btw if these are ready for a more final review, feel free to un-draft them (just gets them actually into my queue) |
64106e6 to
359cb79
Compare
|
just double-checked: |
|
@niacdoial what exactly are these waiting on? I assume they're close to ready based on your above comment, but they are still marked as drafts. |
|
ah, I knew I was missing something (talking about the PR still being a draft) |
|
Reminder, once the PR becomes ready for a review, use |
c52aa53 to
2150411
Compare
….2, r=petrochenkov Improperctypes refactor2.2 This is "part 2/3 of 2/3 of 1/2" of the original pull request rust-lang#134697 (refactor plus overhaul of the ImproperCTypes family of lints) (all pulls of this series of pulls are supersets of the previous pulls.) previous pull: rust-lang#155358 next pull: rust-lang#146273 This commit splits the lint's `visit_type` function into multiple functions that focus on specific things: - visit_indirection (references, boxes, raw pointers) - visit_variant_fields (the list of fields of a struct, enum variant, or union) - visit_enum - visit_struct_or_union - visit_type (most "easy" decisions such as labeling `char` unsafe are here) since, during these visits, we often move from an "outer type" to an "inner type" (structs, arrays, pointers, etc...), two structs have been added to track the current state of a visit: - VisitorState tracks the state related to the "original type" being checked (function argument/return, static variable) - OuterTyData tracks the data related to the type "immediately outer to the current visited type" r? petrochenkov (because you asked me to)
Rollup merge of #155359 - niacdoial:improperctypes-refactor2.2, r=petrochenkov Improperctypes refactor2.2 This is "part 2/3 of 2/3 of 1/2" of the original pull request #134697 (refactor plus overhaul of the ImproperCTypes family of lints) (all pulls of this series of pulls are supersets of the previous pulls.) previous pull: #155358 next pull: #146273 This commit splits the lint's `visit_type` function into multiple functions that focus on specific things: - visit_indirection (references, boxes, raw pointers) - visit_variant_fields (the list of fields of a struct, enum variant, or union) - visit_enum - visit_struct_or_union - visit_type (most "easy" decisions such as labeling `char` unsafe are here) since, during these visits, we often move from an "outer type" to an "inner type" (structs, arrays, pointers, etc...), two structs have been added to track the current state of a visit: - VisitorState tracks the state related to the "original type" being checked (function argument/return, static variable) - OuterTyData tracks the data related to the type "immediately outer to the current visited type" r? petrochenkov (because you asked me to)
This comment has been minimized.
This comment has been minimized.
2150411 to
ac62a57
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot review |
ac62a57 to
405a44a
Compare
Another user-transparent change, unifying outer-type information and the existing VisitorState flags.
In order to follow along with the efforts to properly distinguish already-normalised and unnormalized types, we separate the internal interfaces of this lint that rely on normalized types from those that do not. We do that by adding the `Unnormalized` wrapper to some interfaces.
405a44a to
0300277
Compare
|
added a new commit to better make use of the |
|
wait, have I not...? |
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| struct VisitorState: u8 { | ||
| struct RootUseFlags: u16 { |
There was a problem hiding this comment.
| struct RootUseFlags: u16 { | |
| struct RootUseFlags: u8 { |
Extending to 16 bit is not (yet?) necessary.
| @@ -286,8 +295,10 @@ enum IndirectionKind { | |||
| } | |||
|
|
|||
| bitflags! { | |||
| /// VisitorState flags that are linked with the root type's use. | |||
| /// (These are the permanent part of the state, kept when visiting new mir::Ty.) | |||
There was a problem hiding this comment.
| /// (These are the permanent part of the state, kept when visiting new mir::Ty.) | |
| /// (These are the permanent part of the state, kept when visiting new `Ty`.) |
I've just noticed, what is mir::Ty?
In this PR it seems to refer to the usual Ty, which is not "mir".
There was a problem hiding this comment.
ah, my bad.
It was to differentiate from hir::Ty (rustc_hir::ty::Ty) used elsewhere in the file, and I kinda assumed this meant the usual Ty (rustc_middle::ty::Ty) is MIR.
Should I still make it obvious this isn't the same as hir::Ty?
There was a problem hiding this comment.
If you need to disambiguate, then ty::Ty or hir::Ty can be used (whatever requires less annotations).
|
r=me after addressing the remaining nits. |
View all comments
This is the second PR in an effort to split #134697 (refactor plus overhaul of the ImproperCTypes family of lints) into individually-mergeable parts.
Contains the changes of the first PR, and splits the core type checking function into several bits, each focused on a specific aspect of FFI-safety.
Some logic which was outside of said core function was also moved into the new functions.
Superset of: #146271