Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Denote types with unused template params.#3148

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
adetaylor wants to merge11 commits intorust-lang:main
base:main
Choose a base branch
Loading
fromadetaylor:unused-template-param-callback

Conversation

adetaylor
Copy link
Contributor

Downstream postprocessors such as autocxx may want to use bindgen's
representation of types to generate additional C++ code. bindgen is remarkably
faithful at passing through enough information to make this possible - but for
some C++ types, bindgen chooses to elide some template parameters. It's not
safe for additional C++ code to be generated which references that type.

This adds a callback by which such tools can recognize types where template
parameters have been elided like this, so that extra C++ is avoided.

This information could be provided in the existing
new_item_found callback, but it's very niche and unlikely to be used by
the majority of consumers, so a new callback is added instead.

An alternative approach here is to provide a mode to bindgen where it
always uses all template params, by adding additionalPhantomData
fields to structs where those params are not currently used.
This is being prototyped ingoogle/autocxx#1425
but is unlikely to be successful, on the assumption that lots of the
templated types can't actually be properly represented by bindgen/Rust,
so the current strategy of discarding them is more likely to work
in the broad strokes.

This PR is built on top of#3146, which in turn is on top of various others.

Part ofgoogle/autocxx#124

This extends the existing discovery callback mechanism to report on functionsand methods. At this stage, we don't say much about them, in order to beconsistent with other discovery callbacks. Subsequent PRs will addextra callbacks to provide information especially about methods(virtualness, C++ visibility, etc.) Please request changes if you thinkthat sort of information should arrive in these callbacks.Because methods are a fundamentally C++ thing, this splits thecurrent ParseCallbacks test to cover both a .h and a .hpp header.Part ofgoogle/autocxx#124
No functional change - just deduplicating the logic which calls this callback,which will make it easier to make further changes in future.Part ofgoogle/autocxx#124
This adds more information to ParseCallbacks which indicates the location inthe original source code at which a given item was found.This has proven to be useful in downstream code generators in providingdiagnostics to explain why a given item can't be represented in Rust. (Thereare lots of reasons why this might not be the case - autocxx has around 100which can be found here -https://github.com/google/autocxx/blob/d85eac76c9b3089d0d86249e857ff0e8c36b988f/engine/src/conversion/convert_error.rs#L39- but irrespective of the specific reasons, it's useful to be able to point tothe original location when emitting diagnostics).Should we make this a new callback or include this information withinthe existing callback?Pros of making it a new callback:* No compatibility breakage.Pros of including it in this existing callback:* No need to specify and test a policy about whether such callbacks  always happen together, or may arrive individually* Easier for recipients (including bindgen's own test suite) to  keep track of the source code location received.* Because we add new items to the DiscoveryItem enum anyway,  we seem to have accepted it's OK to break compatibility in this  callback (for now at least).Therefore I'm adding it as a parameter to the existing callback. If it'sdeemed acceptable to break compatibility in this way, I will follow thesame thought process for some other changes too.Part ofgoogle/autocxx#124.
This makes two complementary improvements to the ParseCallbacks.The first is that Mods are now announced, as a new type ofDiscoveredItem. The second is that the parentage of each item isannounced. The parent of an item is often a mod (i.e. aC++ namespace) but not necessarily - it might be a struct withina struct, or similar.The reported information here is dependent on two pre-existingbindgen options:* whether to report C++ namespaces at all* whether to report inline namespaces conservatively.For that reason, the test suite gains two new tests.Part ofgoogle/autocxx#124
This change reports extra C++ information about items:* Whether methods are virtual or pure virtual or neither* Whether a method is a "special member", e.g. a move constructor* Whether a method is defaulted or deleted* C++ visibility (for structs, enums, unions and methods)It builds on top ofrust-lang#3145.A follow up PR should enhance the tests oncerust-lang#3139 is merged.Part ofgoogle/autocxx#124
Downstream postprocessors such as autocxx may want to use bindgen'srepresentation of types to generate additional C++ code. bindgen is remarkablyfaithful at passing through enough information to make this possible - but forsome C++ types, bindgen chooses to elide some template parameters. It's notsafe for additional C++ code to be generated which references that type.This adds a callback by which such tools can recognize types where templateparameters have been elided like this, so that extra C++ is avoided.This information could be provided in the existing`new_item_found` callback, but it's very niche and unlikely to be used bythe majority of consumers, so a new callback is added instead.An alternative approach here is to provide a mode to bindgen where it*always* uses all template params, by adding additional PhantomDatafields to structs where those params are not currently used.This is being prototyped ingoogle/autocxx#1425but is unlikely to be successful, on the assumption that lots of thetemplated types can't actually be properly represented by bindgen/Rust,so the current strategy of discarding them is more likely to workin the broad strokes.Part ofgoogle/autocxx#124
@adetayloradetaylor mentioned this pull requestFeb 22, 2025
8 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@adetaylor

[8]ページ先頭

©2009-2025 Movatter.jp