Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not rewrite ADTs mentioned in extern blocks #960

Merged
merged 25 commits into from
Jun 16, 2023
Merged

Conversation

aneksteind
Copy link
Contributor

@aneksteind aneksteind commented Jun 14, 2023

Fixes #948. Fixes an issue where we would rewrite structs and their fields even though they appear in extern blocks.

Fixes an issue where we would rewrite structs and their fields
even though they appear in extern blocks.
@kkysen
Copy link
Contributor

kkysen commented Jun 14, 2023

Also, I changed "addresses" to "fixes" in the PR description as I don't think "addresses" is one of the keywords for closing an issue from a PR.

c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@spernsteiner spernsteiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good approach overall

c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/rewrite/ty.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/main.rs Outdated Show resolved Hide resolved
@aneksteind
Copy link
Contributor Author

@spernsteiner I’m not clear on what further changes you’d like to see. Could you let me know if I’ve missed any concerns of yours?

Copy link
Contributor

@kkysen kkysen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small nit left: walk_adts instead of walk_adt, as the latter sounds like it's walking over only one. Otherwise, it all LGTM now!

@kkysen kkysen changed the title Do not rewrite structs mentioned in extern blocks Do not rewrite ADTs mentioned in extern blocks Jun 16, 2023
{
for arg in ty.walk() {
if let GenericArgKind::Type(ty) = arg.unpack() {
if let TyKind::Adt(adt_def, _) = ty.kind() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we need to substitute generics here? Then generic fields will just be TyKind::Param and we won't recognize that it may be an ADT or other type we need to recurse into.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, that should be covered by .walk instead, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll indeed see TyKind::Param when visiting fields of generic structs, but walk will separately visit the type that would have been substituted in.

struct Wrapper<T> { x: T }
struct Inner { y: u32 }
extern "C" {
    fn foo(ptr: *mut Wrapper<Inner>);
}

walk(*mut Wrapper<Inner>) will visit Wrapper<Inner> and Inner, so it's okay that the traversal of the x field sees only TyKind::Param instead of Inner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

analyze: avoid rewriting structs mentioned in extern declarations
3 participants