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

Allow namespace override #370

Merged
merged 8 commits into from
Oct 29, 2020
Merged

Conversation

adetaylor
Copy link
Collaborator

@adetaylor adetaylor commented Oct 26, 2020

This PR consists of lots of commits adding tests, then a commit which actually achieves it.

It should achieve points 1-3 on the plan in #353, and most of #​4 (it doesn't currently look for namespace attributes on extern blocks but the rest is done).

Obsoletes #369.

This change allows a

 #[namespace (namespace = A::B)]

attribute for each item in a cxx::bridge.

We now have a fair number of different types of name floating
around:
* C++ identifiers
* C++ fully-qualified names
* Rust identifiers
* Rust fully-qualified names (future, when we support sub-modules)
* Items with both a Rust and C++ name (a 'Pair')
* Types with only a known Rust name, which can be resolved to a
  C++ name.

This change attempts to put some sensible names for all these
things in syntax/mod.rs, and so that would be a good place to start
review.

At the moment, the Namespace (included in each CppName)
is ruthlessly cloned all over the place. As a given namespace is
likely to be applicable to many types and functions, it may
save significant memory in future to use Rc<> here. But let's not
optimise too early.
gen/src/namespace_organizer.rs Show resolved Hide resolved
gen/src/namespace_organizer.rs Show resolved Hide resolved
gen/src/namespace_organizer.rs Show resolved Hide resolved
gen/src/namespace_organizer.rs Show resolved Hide resolved
tests/ffi/class_in_ns.rs Show resolved Hide resolved
@adetaylor
Copy link
Collaborator Author

Thanks for the review! I agree with all your points and will (eventually) get to them.

gen/src/namespace_organizer.rs Show resolved Hide resolved
syntax/impls.rs Show resolved Hide resolved
syntax/impls.rs Show resolved Hide resolved
syntax/impls.rs Show resolved Hide resolved
syntax/symbol.rs Show resolved Hide resolved
Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks, this is great. I agree with the comments above but I don't mind merging as is and taking followup PRs to clean up.

@dtolnay dtolnay merged commit d60c07b into dtolnay:master Oct 29, 2020
@adetaylor
Copy link
Collaborator Author

Thanks for merging! I will prioritize a PR to get the syntax finalized per #370 (comment) (I assume you agree with that @dtolnay ), hopefully I'll get that done tomorrow. I'll then do more cleanup PRs subsequently for all the other comments. Thanks for the review both!

@dtolnay
Copy link
Owner

dtolnay commented Oct 30, 2020

Yeah it should be #[namespace = "path::to"] for now (though implemented in such a way that it accepts #[namespace = path::to] if the user's future compiler is able to feed us that). We can also update existing use of #[cxx::bridge(namespace = ...)] in documentation and tests to #[cxx::bridge(namespace = "...")] to maintain parity.

@adetaylor
Copy link
Collaborator Author

#380 updates the syntax to #[namespace = "path::to"] using @sbrocket's code. Future PRs will do the various other bits of tidying here.

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.

3 participants