Skip to content

Conversation

@oinoom
Copy link
Contributor

@oinoom oinoom commented Jun 14, 2023

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

@oinoom oinoom requested a review from spernsteiner June 14, 2023 16:34
@oinoom oinoom linked an issue Jun 14, 2023 that may be closed by this pull request
@oinoom oinoom force-pushed the fix.rewriter.foreign branch from 616cd8d to 97bbed5 Compare June 14, 2023 16:35
Fixes an issue where we would rewrite structs and their fields
even though they appear in extern blocks.
@oinoom oinoom force-pushed the fix.rewriter.foreign branch from 97bbed5 to b90b646 Compare June 14, 2023 16:39
@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.

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

@oinoom oinoom requested a review from spernsteiner June 15, 2023 18:44
@oinoom oinoom requested a review from spernsteiner June 15, 2023 20:38
@oinoom
Copy link
Contributor Author

oinoom commented Jun 16, 2023

@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
@oinoom oinoom force-pushed the fix.rewriter.foreign branch from 29fa269 to 9d20b20 Compare June 16, 2023 17:40
@oinoom oinoom force-pushed the fix.rewriter.foreign branch from 9d20b20 to 0a4557d Compare June 16, 2023 17:53
@oinoom oinoom requested a review from spernsteiner June 16, 2023 18:18
@oinoom oinoom force-pushed the fix.rewriter.foreign branch from 46b5ca8 to b854368 Compare June 16, 2023 18:25
{
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

4 participants