Skip to content

Commit

Permalink
Make the default the reentrant storage
Browse files Browse the repository at this point in the history
  • Loading branch information
lilizoey committed Nov 26, 2023
1 parent 18e1f46 commit 93c9f5b
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 591 deletions.
116 changes: 0 additions & 116 deletions .github/workflows/full-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ name: Full CI
# Runs before merging. Rebases on master to make sure CI passes for latest integration, not only for the PR at the time of creation.

on:
push:
merge_group:
# push:

Expand Down Expand Up @@ -189,50 +188,25 @@ jobs:
artifact-name: macos-nightly
godot-binary: godot.macos.editor.dev.x86_64
rust-extra-args: --features godot/custom-godot

- name: macos-bind-self
os: macos-12
artifact-name: macos-nightly
godot-binary: godot.macos.editor.dev.x86_64
rust-extra-args: --features godot/custom-godot,itest/experimental-bind-self

- name: macos-double
os: macos-12
artifact-name: macos-double-nightly
godot-binary: godot.macos.editor.dev.double.x86_64
rust-extra-args: --features godot/custom-godot,godot/double-precision

- name: macos-double-bind-self
os: macos-12
artifact-name: macos-double-nightly
godot-binary: godot.macos.editor.dev.double.x86_64
rust-extra-args: --features godot/custom-godot,godot/double-precision,itest/experimental-bind-self

- name: macos-4.1
os: macos-12
artifact-name: macos-stable
godot-binary: godot.macos.editor.dev.x86_64
#godot-prebuilt-patch: '4.1'
rust-extra-args: --features itest/experimental-bind-self

- name: macos-bind-self-4.1
os: macos-12
artifact-name: macos-stable
godot-binary: godot.macos.editor.dev.x86_64
#godot-prebuilt-patch: '4.1'

# TODO merge with other jobs
- name: macos-lazy-fptrs
os: macos-12
artifact-name: macos-nightly
godot-binary: godot.macos.editor.dev.x86_64
rust-extra-args: --features godot/lazy-function-tables

- name: macos-lazy-fptrs-bind-self
os: macos-12
artifact-name: macos-nightly
godot-binary: godot.macos.editor.dev.x86_64
rust-extra-args: --features godot/lazy-function-tables,itest/experimental-bind-self

# Windows

Expand All @@ -242,49 +216,24 @@ jobs:
godot-binary: godot.windows.editor.dev.x86_64.exe
rust-extra-args: --features godot/custom-godot

- name: windows-bind-self
os: windows-latest
artifact-name: windows-nightly
godot-binary: godot.windows.editor.dev.x86_64.exe
rust-extra-args: --features godot/custom-godot,itest/experimental-bind-self

- name: windows-double
os: windows-latest
artifact-name: windows-double-nightly
godot-binary: godot.windows.editor.dev.double.x86_64.exe
rust-extra-args: --features godot/custom-godot,godot/double-precision

- name: windows-double-bind-self
os: windows-latest
artifact-name: windows-double-nightly
godot-binary: godot.windows.editor.dev.double.x86_64.exe
rust-extra-args: --features godot/custom-godot,godot/double-precision,itest/experimental-bind-self

- name: windows-4.1
os: windows-latest
artifact-name: windows-stable
godot-binary: godot.windows.editor.dev.x86_64.exe
#godot-prebuilt-patch: '4.1'

- name: windows-bind-self-4.1
os: windows-latest
artifact-name: windows-stable
godot-binary: godot.windows.editor.dev.x86_64.exe
#godot-prebuilt-patch: '4.1'
rust-extra-args: --features itest/experimental-bind-self

# TODO merge with other jobs
- name: windows-lazy-fptrs
os: windows-latest
artifact-name: windows-nightly
godot-binary: godot.windows.editor.dev.x86_64.exe
rust-extra-args: --features godot/lazy-function-tables

- name: windows-lazy-fptrs-bind-self
os: windows-latest
artifact-name: windows-nightly
godot-binary: godot.windows.editor.dev.x86_64.exe
rust-extra-args: --features godot/lazy-function-tables,itest/experimental-bind-self

# Linux

Expand All @@ -296,49 +245,25 @@ jobs:
godot-binary: godot.linuxbsd.editor.dev.x86_64
rust-extra-args: --features godot/custom-godot

- name: linux-bind-self
os: ubuntu-20.04
artifact-name: linux-nightly
godot-binary: godot.linuxbsd.editor.dev.x86_64
rust-extra-args: --features godot/custom-godot,itest/experimental-bind-self

- name: linux-double
os: ubuntu-20.04
artifact-name: linux-double-nightly
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
rust-extra-args: --features godot/custom-godot,godot/double-precision

- name: linux-double-bind-self
os: ubuntu-20.04
artifact-name: linux-double-nightly
godot-binary: godot.linuxbsd.editor.dev.double.x86_64
rust-extra-args: --features godot/custom-godot,godot/double-precision,itest/experimental-bind-self

- name: linux-features
os: ubuntu-20.04
artifact-name: linux-nightly
godot-binary: godot.linuxbsd.editor.dev.x86_64
rust-extra-args: --features godot/custom-godot,godot/experimental-threads,godot/serde

- name: linux-features-bind-self
os: ubuntu-20.04
artifact-name: linux-nightly
godot-binary: godot.linuxbsd.editor.dev.x86_64
rust-extra-args: --features godot/custom-godot,godot/experimental-threads,godot/serde,itest/experimental-bind-self

# TODO merge with other jobs
- name: linux-lazy-fptrs
os: ubuntu-20.04
artifact-name: linux-nightly
godot-binary: godot.linuxbsd.editor.dev.x86_64
rust-extra-args: --features godot/lazy-function-tables

- name: linux-lazy-fptrs-bind-self
os: ubuntu-20.04
artifact-name: linux-nightly
godot-binary: godot.linuxbsd.editor.dev.x86_64
rust-extra-args: --features godot/lazy-function-tables,itest/experimental-bind-self

# Linux compat

- name: linux-4.1.1
Expand All @@ -347,38 +272,18 @@ jobs:
godot-binary: godot.linuxbsd.editor.dev.x86_64
#godot-prebuilt-patch: '4.1.1'

- name: linux-bind-self-4.1.1
os: ubuntu-20.04
artifact-name: linux-stable
godot-binary: godot.linuxbsd.editor.dev.x86_64
#godot-prebuilt-patch: '4.1.1'
rust-extra-args: --features itest/experimental-bind-self

- name: linux-4.1
os: ubuntu-20.04
artifact-name: linux-stable
godot-binary: godot.linuxbsd.editor.dev.x86_64
godot-prebuilt-patch: '4.1'

- name: linux-bind-self-4.1
os: ubuntu-20.04
artifact-name: linux-stable
godot-binary: godot.linuxbsd.editor.dev.x86_64
godot-prebuilt-patch: '4.1'
rust-extra-args: --features itest/experimental-bind-self

- name: linux-4.0.4
os: ubuntu-20.04
artifact-name: linux-4.0.4
godot-binary: godot.linuxbsd.editor.dev.x86_64
godot-prebuilt-patch: '4.0.4'

- name: linux-bind-self-4.0.4
os: ubuntu-20.04
artifact-name: linux-4.0.4
godot-binary: godot.linuxbsd.editor.dev.x86_64
godot-prebuilt-patch: '4.0.4'
rust-extra-args: --features itest/experimental-bind-self

# Memory checks: special Godot binaries compiled with AddressSanitizer/LeakSanitizer to detect UB/leaks.
# See also https://rustc-dev-guide.rust-lang.org/sanitizers.html.
Expand All @@ -397,16 +302,6 @@ jobs:
# Sanitizers can't build proc-macros and build scripts; with --target, cargo ignores RUSTFLAGS for those two.
rust-target: x86_64-unknown-linux-gnu

- name: linux-memcheck-bind-self
os: ubuntu-20.04
artifact-name: linux-memcheck-clang-nightly
godot-binary: godot.linuxbsd.editor.dev.x86_64.llvm.san
rust-toolchain: nightly
rust-env-rustflags: -Zrandomize-layout -Zsanitizer=address
rust-extra-args: --features godot/custom-godot,itest/experimental-bind-self
# Sanitizers can't build proc-macros and build scripts; with --target, cargo ignores RUSTFLAGS for those two.
rust-target: x86_64-unknown-linux-gnu

- name: linux-memcheck-4.0.4
os: ubuntu-20.04
artifact-name: linux-memcheck-clang-4.0.4
Expand All @@ -416,17 +311,6 @@ jobs:
rust-env-rustflags: -Zrandomize-layout -Zsanitizer=address
# Sanitizers can't build proc-macros and build scripts; with --target, cargo ignores RUSTFLAGS for those two.
rust-target: x86_64-unknown-linux-gnu

- name: linux-memcheck-bind-self-4.0.4
os: ubuntu-20.04
artifact-name: linux-memcheck-clang-4.0.4
godot-binary: godot.linuxbsd.editor.dev.x86_64.llvm.san
godot-prebuilt-patch: '4.0.4'
rust-toolchain: nightly
rust-env-rustflags: -Zrandomize-layout -Zsanitizer=address
rust-extra-args: --features itest/experimental-bind-self
# Sanitizers can't build proc-macros and build scripts; with --target, cargo ignores RUSTFLAGS for those two.
rust-target: x86_64-unknown-linux-gnu

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 1 addition & 2 deletions godot-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ custom-godot = ["godot-ffi/custom-godot", "godot-codegen/custom-godot"]
double-precision = ["godot-codegen/double-precision"]
experimental-godot-api = ["godot-codegen/experimental-godot-api"]
experimental-threads = []
experimental-bind-self = ["godot-cell"]
trace = ["godot-ffi/trace"]

[dependencies]
Expand All @@ -28,7 +27,7 @@ godot-ffi = { path = "../godot-ffi" }
# See https://docs.rs/glam/latest/glam/index.html#feature-gates
glam = { version = "0.23", features = ["debug-glam-assert"] }
serde = { version = "1", features = ["derive"], optional = true }
godot-cell = { path = "../godot-cell", optional = true }
godot-cell = { path = "../godot-cell" }

# Reverse dev dependencies so doctests can use `godot::` prefix
[dev-dependencies]
Expand Down
8 changes: 3 additions & 5 deletions godot-core/src/obj/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ pub trait WithBaseField: GodotClass<Declarer = dom::UserDomain> {

/// Returns a mutable reference suitable for calling engine methods on this object.
///
/// If the feature `experimental-bind-self` is enabled, then this method will allow you to call back into
/// the same object from Godot.
/// This method will allow you to call back into the same object from Godot, unlike what would happen
/// if you used [`to_gd()`](WithBaseField::to_gd).
///
/// # Examples
///
Expand Down Expand Up @@ -316,7 +316,7 @@ pub trait WithBaseField: GodotClass<Declarer = dom::UserDomain> {
/// # unsafe impl ExtensionLibrary for Test {}
/// ```
///
/// And with `experimental-bind-self` enabled, code such as this works:
/// We can call back into `self` through Godot:
///
/// ```
/// use godot::prelude::*;
Expand All @@ -331,8 +331,6 @@ pub trait WithBaseField: GodotClass<Declarer = dom::UserDomain> {
/// #[godot_api]
/// impl INode for MyClass {
/// fn process(&mut self, _delta: f64) {
/// // Only works with `experimental-bind-self` enabled. Without that feature, this will panic at
/// // runtime.
/// self.base_mut().call("other_method".into(), &[]);
/// }
/// }
Expand Down
44 changes: 4 additions & 40 deletions godot-core/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,11 @@ impl AtomicLifecycle {
}
}

#[cfg_attr(
all(
not(feature = "experimental-bind-self"),
feature = "experimental-threads"
),
allow(dead_code)
)]
#[cfg_attr(feature = "experimental-threads", allow(dead_code))]
mod single_threaded;

#[cfg_attr(
all(
not(feature = "experimental-bind-self"),
not(feature = "experimental-threads")
),
allow(dead_code)
)]
mod multi_threaded;

#[cfg(feature = "experimental-bind-self")]
#[cfg_attr(not(feature = "experimental-threads"), allow(dead_code))]
mod reentrant_multi_threaded;
#[cfg(feature = "experimental-bind-self")]
#[cfg_attr(feature = "experimental-threads", allow(dead_code))]
mod reentrant_single_threaded;
mod multi_threaded;

/// A storage for an instance binding.
///
Expand Down Expand Up @@ -130,8 +111,6 @@ pub unsafe trait Storage {
///
/// This can use the provided `instance` to provide extra safety guarantees such as allowing reentrant
/// code to create new mutable references.
///
/// Currently only has an effect if `experimental-bind-self` is enabled.
fn get_base_mut<'a: 'b, 'b>(
&'a self,
instance: &'b mut Self::Instance,
Expand Down Expand Up @@ -202,27 +181,12 @@ pub(crate) trait StorageRefCounted: Storage {
fn on_dec_ref(&self);
}

#[cfg(all(
not(feature = "experimental-threads"),
not(feature = "experimental-bind-self")
))]
#[cfg(not(feature = "experimental-threads"))]
pub type InstanceStorage<T> = single_threaded::InstanceStorage<T>;

#[cfg(all(
feature = "experimental-threads",
not(feature = "experimental-bind-self")
))]
#[cfg(feature = "experimental-threads")]
pub type InstanceStorage<T> = multi_threaded::InstanceStorage<T>;

#[cfg(all(
not(feature = "experimental-threads"),
feature = "experimental-bind-self"
))]
pub type InstanceStorage<T> = reentrant_single_threaded::InstanceStorage<T>;

#[cfg(all(feature = "experimental-threads", feature = "experimental-bind-self"))]
pub type InstanceStorage<T> = reentrant_multi_threaded::InstanceStorage<T>;

pub type RefGuard<'a, T> = <InstanceStorage<T> as Storage>::RefGuard<'a>;
pub type MutGuard<'a, T> = <InstanceStorage<T> as Storage>::MutGuard<'a>;
pub type BaseMutGuard<'a, T> = <InstanceStorage<T> as Storage>::BaseMutGuard<'a>;
Expand Down
Loading

0 comments on commit 93c9f5b

Please sign in to comment.