-
Notifications
You must be signed in to change notification settings - Fork 210
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
Simplify module structure (redundant re-exports) #788
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the hard work. This looks like a really good start to the changes! I've left a bit of my thoughts as well as some confirmation points. I think I understand where we are going with the changes. It should make it a bit easier to validate.
Have you tried generating the docs with this PR?
@@ -53,12 +53,12 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of this change is to remove the workaround that was previously put in place. To confirm, the reason for this change is that the workaround is no longer needed, correct? If so, I think removing all the references as well as the comment may be the best option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, this is still a WIP and I need to first confirm that the workaround is no longer needed (at least on stable Rust).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I built the docs from your branch and currently it looks like regardless of what we do we're still getting the multiple module paths when searching the docs.
Your changes:
https://godot-rust.github.io/docs/gdnative/
@@ -82,3 +82,6 @@ impl std::fmt::Display for GodotError { | |||
} | |||
|
|||
impl std::error::Error for GodotError {} | |||
|
|||
/// Result type with [GodotError] | |||
pub type GodotResult = Result<(), GodotError>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it the rationale behind moving GodotResult to core_types
is that it's the Rust-side implementation for the Godot Error codes, correct? If so, I like this change. It makes a lot of sense to put GodotResult
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and to be honest I didn't know a module that would fit better. But your reason sounds more sophisticated 😅
@@ -1,11 +1,16 @@ | |||
//! Types that represent core-datatypes of Godot. | |||
//! Types that represent core data types of Godot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirming, most of the changes in here are for organizational purposes, correct? If so, looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I don't want to introduce any semantic changes in this PR.
There might be breaking changes due to new module structure, but functionality-wise, we should not lose anything.
@@ -43,7 +44,7 @@ pub use rid::*; | |||
pub use string::*; | |||
pub use string_array::*; | |||
pub use transform2d::*; | |||
pub use typed_array::{Element, TypedArray}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Element is intended to be an internal implementation detail? Or was this initially made public (in the past) by mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wondered the same thing. A lot of stuff is public and sometimes even appears in the documentation, though I don't think anyone uses it. Probably we should locate some of those cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the Element
re-export in the serde PR. It's not technically needed anymore, but it was discussed here: #743 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah interesting, thanks!
Element
is documented at the moment, and it's nice for the user to see which element types are supported. If we want to keep the core_types::typed_array
module hidden, we should also keep re-exporting Element
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could potentially be useful to allow users to implement their own traits generically for all TypedArray
s.
@@ -56,7 +55,7 @@ pub mod private; | |||
// | |||
|
|||
pub use init::{InitializeInfo, TerminateInfo}; | |||
pub use new_ref::NewRef; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good change. It's probably a good idea to keep all the similar stuff together, as such merging new_ref
and object
is a really good change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my idea is that all helper types related to object and reference handling would become part of the object
module. I also moved object.rs
to object/mod.rs
, which contains the large part of the symbols.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! From your feedback, there are still these tasks left (in addition to those in the initial post):
- what needs to be public --
Element
and possibly others -
#[doc(inline)]
workaround in gdnative/src/lib.rs - what exactly belongs to
object
module - check resulting documentation after changes
@@ -53,12 +53,12 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, this is still a WIP and I need to first confirm that the workaround is no longer needed (at least on stable Rust).
@@ -56,7 +55,7 @@ pub mod private; | |||
// | |||
|
|||
pub use init::{InitializeInfo, TerminateInfo}; | |||
pub use new_ref::NewRef; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, my idea is that all helper types related to object and reference handling would become part of the object
module. I also moved object.rs
to object/mod.rs
, which contains the large part of the symbols.
@@ -1,11 +1,16 @@ | |||
//! Types that represent core-datatypes of Godot. | |||
//! Types that represent core data types of Godot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I don't want to introduce any semantic changes in this PR.
There might be breaking changes due to new module structure, but functionality-wise, we should not lose anything.
@@ -43,7 +44,7 @@ pub use rid::*; | |||
pub use string::*; | |||
pub use string_array::*; | |||
pub use transform2d::*; | |||
pub use typed_array::{Element, TypedArray}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wondered the same thing. A lot of stuff is public and sometimes even appears in the documentation, though I don't think anyone uses it. Probably we should locate some of those cases.
@Bromeon I'm glad to help. That tasklist sounds correct. Most of it is just checking my assumptions about the changes. I think double-checking whether anything else belongs in I am curious if newer versions of |
3295c67
to
a308bc7
Compare
Changes so far:
The above are not yet 100% done, needs some double-checking. Tasks left for consideration:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look great. I like the new module structure. I think that we can continue down this route.
Regarding your proposals for additional changes,
Tasks left for consideration:
Move Instance/RefInstance from nativescript to object, so they're next to Ref/TRef.
I am 100% in favor of this. Ref/TRef
or Instance/RefInstance
should be in the same module as they are super closely related.
Check if nativescript can be organized better -- and is its name helpful?
I think nativescript is in a solid enough spot. I'm not sure that I would move anything else out of there.
What do do with global macros like godot_init, godot_error etc.
These might be a good candidate for a macros module. (Not sure 100% where they are currently)
Lots of symbols are #[doc(hidden)] but maybe part of the API; others are implementation details but public.
Hide symbols which the user doesn't get into contact with.
Decide if deprecation of a handful symbols (like gdnative::Ref, gdnative::NativeScript) is useful, or not.
Both of the above are great ideas.
Is this referring only to the re-export? If so, I think this would be a good idea. I think we generally want users to do one of two things when interacting with the API.
a. Only make use of the prelude (use gdnative::prelude::*
) which should contain everything necessary for normal use.
b. Use the full canonical name, not use use gdnative::{thing}
For non-type symbols, this would possibly require code duplication...
Which non-type symbols are you specifically considering here? Some code duplication is inevitable, but we could probably manage it by clever use of the include! macro.
Go through prelude symbols and check if their inclusion is justified
This sounds like a good idea, if you would like to ping me on a review, I'd be happy to run through the list and give my thoughts on each item.
Thanks a lot for your feedback!
Currently they're in top-level Maybe
Yes, I wouldn't change/deprecate any functionality as part of this PR, just module names.
Macros/macro attributes like
If you have the time, that would be nice! All the bindings types should definitely stay there, as well as the core types. Probably makes sense to keep important members of |
8b93d92
to
13b966b
Compare
…from top-level Adjust imports in derive macros, examples and UI tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. The docs also appear to be building properly. Thank you for all the hard work! :)
(There did seem to be a couple of clippy lints that were failing in nightly related to two panics though) |
bors try |
tryBuild succeeded: |
2cc56b3
to
4a3aec4
Compare
bors try |
tryBuild succeeded: |
4a3aec4
to
eb2c5d6
Compare
bors r+ |
788: Simplify module structure (redundant re-exports) r=Bromeon a=Bromeon Simplifies the module structure and closes #771. ## Changes **TLDR:** * Every symbol lives in exactly one module (+ optionally the prelude) * No symbols except modules at `gdnative` crate root (not even macros) * Some module renamings for clarification * No semantic changes -- may break imports however **Detailed list:** * Change `gdnative::object` * Now official home for `Ref`, `TRef` etc. * Move several verifying traits: `object` -> object::bounds * Move/rename `gdnative::thread_access` -> `gdnative::object::ownership` * Move/rename `gdnative::ref_kind` -> `gdnative::object::memory` * Change `gdnative::core_types` * No more nested modules * Move `gdnative::GodotError` to `gdnative::object::GodotError` * Change `gdnative::nativescript` * Rename `init` -> `export` * Rename `profiling` -> `profiler` * `export` and `user_data` no longer re-exported to `nativescript` * `class` now private, symbols re-exported to `nativescript` * Macro `profile_sig!` now in `profiler` * Improve documentation + fix doc tests * **Add** `gdnative::macros` * replaces crate root for `godot_init!` etc. * **Add** `gdnative::derive` * contains derive macros and macro attributes * Document feature flags in lib.rs and `Variant` ## Things not (yet) done Those could be discussed in separate PRs. * Changes to the prelude * Clean up the modules inside `gdnative::api` The issue here is that the modules under `api` are used for grouping related symbols. For example, `api::node` has 3 structs `Node`, `DuplicateFlags` and `PauseMode`. In C++, they would be represented as enum/struct inside a `class Node`, however Rust does not support nested types in struct, hence the module is used. An alternative would be to remove `api::Node` and just use `api::node::Node`, but this is less ergonomic. * Some very deep nestings, such as `gdnative::nativescript::export::property::hint::ArrayHint` Co-authored-by: Jan Haller <[email protected]>
Build failed: |
Windows CI workers did not start -- let's try again. |
788: Simplify module structure (redundant re-exports) r=Bromeon a=Bromeon Simplifies the module structure and closes #771. ## Changes **TLDR:** * Every symbol lives in exactly one module (+ optionally the prelude) * No symbols except modules at `gdnative` crate root (not even macros) * Some module renamings for clarification * No semantic changes -- may break imports however **Detailed list:** * Change `gdnative::object` * Now official home for `Ref`, `TRef` etc. * Move several verifying traits: `object` -> object::bounds * Move/rename `gdnative::thread_access` -> `gdnative::object::ownership` * Move/rename `gdnative::ref_kind` -> `gdnative::object::memory` * Change `gdnative::core_types` * No more nested modules * Move `gdnative::GodotError` to `gdnative::object::GodotError` * Change `gdnative::nativescript` * Rename `init` -> `export` * Rename `profiling` -> `profiler` * `export` and `user_data` no longer re-exported to `nativescript` * `class` now private, symbols re-exported to `nativescript` * Macro `profile_sig!` now in `profiler` * Improve documentation + fix doc tests * **Add** `gdnative::macros` * replaces crate root for `godot_init!` etc. * **Add** `gdnative::derive` * contains derive macros and macro attributes * Document feature flags in lib.rs and `Variant` ## Things not (yet) done Those could be discussed in separate PRs. * Changes to the prelude * Clean up the modules inside `gdnative::api` The issue here is that the modules under `api` are used for grouping related symbols. For example, `api::node` has 3 structs `Node`, `DuplicateFlags` and `PauseMode`. In C++, they would be represented as enum/struct inside a `class Node`, however Rust does not support nested types in struct, hence the module is used. An alternative would be to remove `api::Node` and just use `api::node::Node`, but this is less ergonomic. * Some very deep nestings, such as `gdnative::nativescript::export::property::hint::ArrayHint` Co-authored-by: Jan Haller <[email protected]>
Build failed: |
GitHub confirmed issues with Action runners: https://twitter.com/githubstatus/status/1448208551416041473 Or https://www.githubstatus.com/
In case it's fixed within the next hour before the timeout: |
788: Simplify module structure (redundant re-exports) r=Bromeon a=Bromeon Simplifies the module structure and closes #771. ## Changes **TLDR:** * Every symbol lives in exactly one module (+ optionally the prelude) * No symbols except modules at `gdnative` crate root (not even macros) * Some module renamings for clarification * No semantic changes -- may break imports however **Detailed list:** * Change `gdnative::object` * Now official home for `Ref`, `TRef` etc. * Move several verifying traits: `object` -> object::bounds * Move/rename `gdnative::thread_access` -> `gdnative::object::ownership` * Move/rename `gdnative::ref_kind` -> `gdnative::object::memory` * Change `gdnative::core_types` * No more nested modules * Move `gdnative::GodotError` to `gdnative::object::GodotError` * Change `gdnative::nativescript` * Rename `init` -> `export` * Rename `profiling` -> `profiler` * `export` and `user_data` no longer re-exported to `nativescript` * `class` now private, symbols re-exported to `nativescript` * Macro `profile_sig!` now in `profiler` * Improve documentation + fix doc tests * **Add** `gdnative::macros` * replaces crate root for `godot_init!` etc. * **Add** `gdnative::derive` * contains derive macros and macro attributes * Document feature flags in lib.rs and `Variant` ## Things not (yet) done Those could be discussed in separate PRs. * Changes to the prelude * Clean up the modules inside `gdnative::api` The issue here is that the modules under `api` are used for grouping related symbols. For example, `api::node` has 3 structs `Node`, `DuplicateFlags` and `PauseMode`. In C++, they would be represented as enum/struct inside a `class Node`, however Rust does not support nested types in struct, hence the module is used. An alternative would be to remove `api::Node` and just use `api::node::Node`, but this is less ergonomic. * Some very deep nestings, such as `gdnative::nativescript::export::property::hint::ArrayHint` Co-authored-by: Jan Haller <[email protected]>
Build failed: |
bors retry |
Build succeeded: |
811: Simplify module structure II r=Bromeon a=Bromeon This PR is a continuation of #788 and addresses the remaining, somewhat ambitious tasks for module cleanup. Goals: * Every symbol appears at most once in prelude * Every symbol appears at exactly once outside prelude * 2-3 modules (inside the crate) are the maximum nesting depth * Modules named according to related functionality from user point of view Changes: 1. `nativescript` module * Rename to `export`. Rationale: "native script" is quite a wide term, while most the module's current functionality is directly related to _exporting_ symbols from Rust. In practice, godot-rust is always (?) used as a native script. Other potential use cases, as a pure Godot API library or with native_calls, seem to be the exception, if at all. * Along with renaming, the `nativescript` feature is removed. * Nested symbols in `export::{properties, methods}` are moved one level up. * As a result, we can avoid very long qualifiers and multiple candidates for `use` statements. * `nativescript::init::property::hint::EnumHint` -> `export::hint::EnumHint` * `nativescript::export::method::MethodBuilder` -> `export::MethodBuilder` 1. `api` module * Remove inner types like `api::area::Area`, as they are already present in `api`. * Remove all modules which would then become empty. * Create doc links between class (`Camera2D`) and related module (`camera_2d`). 1. Smaller top-level modules * Add `init` (previously part of `nativescript`). * Add `profiler` (previously part of `nativescript`). * Extend `log` with related macros. * Remove `macros` and distribute its symbols to the most fitting API. 1. `prelude` module * Remove a few macros (`godot_gdnative_init` etc.) from the prelude, suggesting that `godot_init` should be used. * `user_data` symbols are accessible through `prelude::user_data` instead of `prelude` directly. This mirrors common usage in examples. 1. `core_types` module No changes in this PR; see PR discussion for reasons and potential alternatives. Co-authored-by: Jan Haller <[email protected]>
811: Simplify module structure II r=Bromeon a=Bromeon This PR is a continuation of #788 and addresses the remaining, somewhat ambitious tasks for module cleanup. Goals: * Every symbol appears at most once in prelude * Every symbol appears at exactly once outside prelude * 2-3 modules (inside the crate) are the maximum nesting depth * Modules named according to related functionality from user point of view Changes: 1. `nativescript` module * Rename to `export`. Rationale: "native script" is quite a wide term, while most the module's current functionality is directly related to _exporting_ symbols from Rust. In practice, godot-rust is always (?) used as a native script. Other potential use cases, as a pure Godot API library or with native_calls, seem to be the exception, if at all. * Along with renaming, the `nativescript` feature is removed. * Nested symbols in `export::{properties, methods}` are moved one level up. * As a result, we can avoid very long qualifiers and multiple candidates for `use` statements. * `nativescript::init::property::hint::EnumHint` -> `export::hint::EnumHint` * `nativescript::export::method::MethodBuilder` -> `export::MethodBuilder` 1. `api` module * Remove inner types like `api::area::Area`, as they are already present in `api`. * Remove all modules which would then become empty. * Create doc links between class (`Camera2D`) and related module (`camera_2d`). 1. Smaller top-level modules * Add `init` (previously part of `nativescript`). * Add `profiler` (previously part of `nativescript`). * Extend `log` with related macros. * Remove `macros` and distribute its symbols to the most fitting API. 1. `prelude` module * Remove a few macros (`godot_gdnative_init` etc.) from the prelude, suggesting that `godot_init` should be used. * `user_data` symbols are accessible through `prelude::user_data` instead of `prelude` directly. This mirrors common usage in examples. 1. `core_types` module No changes in this PR; see PR discussion for reasons and potential alternatives. Co-authored-by: Jan Haller <[email protected]>
Simplifies the module structure and closes #771.
Changes
TLDR:
gdnative
crate root (not even macros)Detailed list:
gdnative::object
Ref
,TRef
etc.object
-> object::boundsgdnative::thread_access
->gdnative::object::ownership
gdnative::ref_kind
->gdnative::object::memory
gdnative::core_types
gdnative::GodotError
togdnative::object::GodotError
gdnative::nativescript
init
->export
profiling
->profiler
export
anduser_data
no longer re-exported tonativescript
class
now private, symbols re-exported tonativescript
profile_sig!
now inprofiler
gdnative::macros
godot_init!
etc.gdnative::derive
Variant
Things not (yet) done
Those could be discussed in separate PRs.
gdnative::api
The issue here is that the modules under
api
are used for grouping related symbols. For example,api::node
has 3 structsNode
,DuplicateFlags
andPauseMode
. In C++, they would be represented as enum/struct inside aclass Node
, however Rust does not support nested types in struct, hence the module is used. An alternative would be to removeapi::Node
and just useapi::node::Node
, but this is less ergonomic.gdnative::nativescript::export::property::hint::ArrayHint