Skip to content

Commit

Permalink
Remove ToGodot::into_godot(); Signature marshalling uses to_godot()
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Sep 15, 2024
1 parent 5ef77b7 commit b2b75fe
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 51 deletions.
9 changes: 3 additions & 6 deletions godot-core/src/builtin/collections/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,6 @@ impl<T: ArrayElement> ToGodot for Array<T> {
//self.clone()
}

fn into_godot(self) -> Self::Via {
self
}

fn to_variant(&self) -> Variant {
self.ffi_to_variant()
}
Expand Down Expand Up @@ -1052,8 +1048,9 @@ impl<T: ArrayElement> GodotType for Array<T> {
type Ffi = Self;

fn to_ffi(&self) -> Self::Ffi {
// `to_ffi` is sometimes intentionally called with an array in an invalid state.
self.clone()
// SAFETY: we may pass type-transmuted arrays to FFI (e.g. Array<T> as Array<Variant>). This would fail the regular
// type-check in clone(), so we disable it. Type invariants are upheld by the "front-end" APIs.
unsafe { self.clone_unchecked() }
}

fn into_ffi(self) -> Self::Ffi {
Expand Down
4 changes: 0 additions & 4 deletions godot-core/src/meta/godot_convert/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ where
self.as_ref().map(ToGodot::to_godot)
}

fn into_godot(self) -> Self::Via {
self.map(ToGodot::into_godot)
}

fn to_variant(&self) -> Variant {
match self {
Some(inner) => inner.to_variant(),
Expand Down
31 changes: 16 additions & 15 deletions godot-core/src/meta/godot_convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ pub trait ToGodot: Sized + GodotConvert {
/// Converts this type to the Godot type by reference, usually by cloning.
fn to_godot(&self) -> Self::ToVia<'_>;

/// Converts this type to the Godot type.
///
/// This can in some cases enable minor optimizations, such as avoiding reference counting operations.
fn into_godot(self) -> Self::Via {
//self.to_godot()
todo!()
}

/// Converts this type to a [Variant].
fn to_variant(&self) -> Variant {
self.to_godot().to_ffi().ffi_to_variant()
Expand Down Expand Up @@ -103,8 +95,22 @@ pub trait FromGodot: Sized + GodotConvert {
}
}

pub(crate) fn into_ffi<T: ToGodot>(value: T) -> <T::Via as GodotType>::Ffi {
value.into_godot().into_ffi()
// pub(crate) fn into_ffi<'v, T: ToGodot >(value: T) -> <T::ToVia<'v> as GodotType>::Ffi {
// let by_ref = value.to_godot();
// let ffi = by_ref.to_ffi();
//
// ffi
// }

pub(crate) fn into_ffi<'v, T: ToGodot>(value: &'v T) -> <T::ToVia<'v> as GodotType>::Ffi {
let by_ref = value.to_godot();
let ffi = by_ref.to_ffi();

ffi
}

pub(crate) fn into_ffi_variant<T: ToGodot>(value: &T) -> Variant {
GodotFfiVariant::ffi_to_variant(&into_ffi(value))
}

pub(crate) fn try_from_ffi<T: FromGodot>(
Expand All @@ -128,11 +134,6 @@ macro_rules! impl_godot_as_self {
fn to_godot(&self) -> Self::ToVia<'_> {
self.clone()
}

#[inline]
fn into_godot(self) -> Self::Via {
self
}
}

impl $crate::meta::FromGodot for $T {
Expand Down
18 changes: 10 additions & 8 deletions godot-core/src/meta/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sys::{BuiltinMethodBind, ClassMethodBind, GodotFfi, UtilityFunctionBind};

use crate::builtin::Variant;
use crate::meta::error::{CallError, ConvertError};
use crate::meta::godot_convert::{into_ffi, try_from_ffi};
use crate::meta::godot_convert::{into_ffi, into_ffi_variant, try_from_ffi};
use crate::meta::*;
use crate::obj::{GodotClass, InstanceId};

Expand Down Expand Up @@ -225,7 +225,7 @@ macro_rules! impl_varcall_signature_for_tuple {

let explicit_args = [
$(
GodotFfiVariant::ffi_to_variant(&into_ffi($pn)),
into_ffi_variant(&$pn),
)*
];

Expand Down Expand Up @@ -270,7 +270,7 @@ macro_rules! impl_varcall_signature_for_tuple {
let object_call_script_method = sys::interface_fn!(object_call_script_method);
let explicit_args = [
$(
GodotFfiVariant::ffi_to_variant(&into_ffi($pn)),
into_ffi_variant(&$pn),
)*
];

Expand Down Expand Up @@ -305,7 +305,7 @@ macro_rules! impl_varcall_signature_for_tuple {

let explicit_args: [Variant; $PARAM_COUNT] = [
$(
GodotFfiVariant::ffi_to_variant(&into_ffi($pn)),
into_ffi_variant(&$pn),
)*
];

Expand Down Expand Up @@ -392,7 +392,7 @@ macro_rules! impl_ptrcall_signature_for_tuple {
#[allow(clippy::let_unit_value)]
let marshalled_args = (
$(
into_ffi($pn),
into_ffi(&$pn),
)*
);

Expand Down Expand Up @@ -423,7 +423,7 @@ macro_rules! impl_ptrcall_signature_for_tuple {
#[allow(clippy::let_unit_value)]
let marshalled_args = (
$(
into_ffi($pn),
into_ffi(&$pn),
)*
);

Expand Down Expand Up @@ -451,7 +451,7 @@ macro_rules! impl_ptrcall_signature_for_tuple {
#[allow(clippy::let_unit_value)]
let marshalled_args = (
$(
into_ffi($pn),
into_ffi(&$pn),
)*
);

Expand Down Expand Up @@ -548,7 +548,9 @@ unsafe fn ptrcall_return<R: ToGodot>(
_call_ctx: &CallContext,
call_type: sys::PtrcallType,
) {
let val = into_ffi(ret_val);
//let val = into_ffi(ret_val);
let val = ret_val.to_godot().to_ffi();

val.move_return_ptr(ret, call_type);
}

Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/meta/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub trait GodotType: GodotConvert<Via = Self> + sealed::Sealed + Sized + 'static
// 'static is not technically required, but it simplifies a few things (limits e.g. ObjectArg).
{
#[doc(hidden)]
type Ffi: GodotFfiVariant;
type Ffi: GodotFfiVariant + 'static;

#[doc(hidden)]
fn to_ffi(&self) -> Self::Ffi;
Expand Down
5 changes: 0 additions & 5 deletions godot-core/src/obj/gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,11 +682,6 @@ impl<T: GodotClass> ToGodot for Gd<T> {
self.raw.check_rtti("to_godot");
self.clone()
}

fn into_godot(self) -> Self::Via {
self.raw.check_rtti("into_godot");
self
}
}

impl<T: GodotClass> FromGodot for Gd<T> {
Expand Down
4 changes: 0 additions & 4 deletions godot-core/src/obj/object_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,6 @@ impl<T: GodotClass> ToGodot for ObjectArg<T> {
fn to_godot(&self) -> Self::ToVia<'_> {
(*self).clone()
}

fn into_godot(self) -> Self::Via {
self
}
}

// TODO refactor signature tuples into separate in+out traits, so FromGodot is no longer needed.
Expand Down
4 changes: 0 additions & 4 deletions godot-core/src/obj/raw_gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,6 @@ impl<T: GodotClass> ToGodot for RawGd<T> {
fn to_godot(&self) -> Self::ToVia<'_> {
self.clone()
}

fn into_godot(self) -> Self::Via {
self
}
}

impl<T: GodotClass> FromGodot for RawGd<T> {
Expand Down
4 changes: 0 additions & 4 deletions godot-macros/src/derive/derive_to_godot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ fn make_togodot_for_newtype_struct(name: &Ident, field: &NewtypeStruct) -> Token
fn to_godot(&self) -> #via_type {
::godot::meta::ToGodot::to_godot(&self.#field_name)
}

fn into_godot(self) -> #via_type {
::godot::meta::ToGodot::into_godot(self.#field_name)
}
}
}
}
Expand Down

0 comments on commit b2b75fe

Please sign in to comment.