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

Fix generating bindings for dead code #8065

Conversation

alexcrichton
Copy link
Member

This commit fixes a bindgen problem where dead types, which had no generated bindings, could be referred to from other dead types, which did have generated bindings. The fix is to not generate code for dead types at all by fixing how type information is analyzed.

Closes #8057

This commit fixes a bindgen problem where dead types, which had no
generated bindings, could be referred to from other dead types, which
did have generated bindings. The fix is to not generate code for dead
types at all by fixing how type information is analyzed.
@alexcrichton alexcrichton requested a review from a team as a code owner March 8, 2024 00:28
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team March 8, 2024 00:28
a(live-type),
b(dead-type),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not clear to me how this tests liveness since both interfaces are part of the imports?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah good point, I should clarify, liveness is calculated in terms of what's used by imported/exported functions. No function actually uses dead-type or v but live-type is used by a function, and so we don't generate bindings for dead-type and this PR fixes a bug where we previously tried to generate bindings for v despite nothing using it.

@alexcrichton alexcrichton requested review from dicej and elliottt and removed request for fitzgen and dicej March 9, 2024 03:44
Comment on lines +45 to +47
for (t, _) in resolve.types.iter() {
self.type_id_info(resolve, t);
}
Copy link
Member

Choose a reason for hiding this comment

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

Does doing this step first mean that the calls to self.type_info in type_info_func should never traverse the whole type (due to the early exit if the entry exists already)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not for this, but the below bits would still need it for setting the owned/borrowed bits.

It's probably best to switching this to LiveSet one day as a future refactoring

@alexcrichton alexcrichton added this pull request to the merge queue Mar 14, 2024
Merged via the queue into bytecodealliance:main with commit b96a9f4 Mar 14, 2024
19 checks passed
@alexcrichton alexcrichton deleted the fix-gen-bindings-for-dead-code branch March 14, 2024 20:15
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.

Component model: bindgen! doesn't generate some structures
3 participants