Skip to content

Remove deprecated symbols from before v0.1 #808

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

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion godot-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ heck = "0.4"
nanoserde = "0.1.35"

# Minimum versions compatible with -Zminimal-versions
proc-macro2 = "1.0.63"
proc-macro2 = "1.0.80" # Literal::c_string() added in 1.0.80.
quote = "1.0.29"

# Since we don't use Regex for unicode parsing, the features unicode-bool/unicode-gencat are used instead of unicode-perl.
Expand Down
25 changes: 16 additions & 9 deletions godot-codegen/src/generator/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ pub fn generate_builtin_class_files(
std::fs::create_dir_all(gen_path).expect("create classes directory");

let mut modules = vec![];
for class in api.builtins.iter() {
let Some(class) = class.builtin_class.as_ref() else {
for variant in api.builtins.iter() {
let Some(class) = variant.builtin_class.as_ref() else {
continue;
};

// let godot_class_name = &class.name().godot_ty;
let module_name = class.mod_name();

let generated_class = make_builtin_class(class, ctx);
let variant_shout_name = util::ident(variant.godot_shout_name());
let generated_class = make_builtin_class(class, &variant_shout_name, ctx);
let file_contents = generated_class.code;

let out_path = gen_path.join(format!("{}.rs", module_name.rust_mod));
Expand Down Expand Up @@ -87,7 +88,11 @@ pub fn make_builtin_module_file(classes_and_modules: Vec<GeneratedBuiltinModule>
// ----------------------------------------------------------------------------------------------------------------------------------------------
// Implementation

fn make_builtin_class(class: &BuiltinClass, ctx: &mut Context) -> GeneratedBuiltin {
fn make_builtin_class(
class: &BuiltinClass,
variant_shout_name: &Ident,
ctx: &mut Context,
) -> GeneratedBuiltin {
let godot_name = &class.name().godot_ty;

let RustTy::BuiltinIdent(outer_class) = conv::to_rust_type(godot_name, None, ctx) else {
Expand All @@ -98,7 +103,7 @@ fn make_builtin_class(class: &BuiltinClass, ctx: &mut Context) -> GeneratedBuilt
let FnDefinitions {
functions: methods,
builders,
} = make_builtin_methods(class, &class.methods, ctx);
} = make_builtin_methods(class, variant_shout_name, &class.methods, ctx);

let imports = util::make_imports();
let enums = enums::make_enums(&class.enums, &TokenStream::new());
Expand Down Expand Up @@ -134,12 +139,13 @@ fn make_builtin_class(class: &BuiltinClass, ctx: &mut Context) -> GeneratedBuilt

fn make_builtin_methods(
builtin_class: &BuiltinClass,
variant_shout_name: &Ident,
methods: &[BuiltinMethod],
ctx: &mut Context,
) -> FnDefinitions {
let definitions = methods
.iter()
.map(|method| make_builtin_method_definition(builtin_class, method, ctx));
let definitions = methods.iter().map(|method| {
make_builtin_method_definition(builtin_class, variant_shout_name, method, ctx)
});

FnDefinitions::expand(definitions)
}
Expand Down Expand Up @@ -180,6 +186,7 @@ fn method_safety_doc(class_name: &TyName, method: &BuiltinMethod) -> Option<Toke

fn make_builtin_method_definition(
builtin_class: &BuiltinClass,
variant_shout_name: &Ident,
method: &BuiltinMethod,
ctx: &mut Context,
) -> FnDefinition {
Expand All @@ -192,7 +199,7 @@ fn make_builtin_method_definition(
let method_name_str = method.godot_name();

let fptr_access = if cfg!(feature = "codegen-lazy-fptrs") {
let variant_type = quote! { sys::VariantType::#builtin_name };
let variant_type = quote! { sys::VariantType::#variant_shout_name };
let variant_type_str = &builtin_name.godot_ty;

quote! {
Expand Down
15 changes: 4 additions & 11 deletions godot-codegen/src/generator/central_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use quote::{format_ident, quote, ToTokens};

pub fn make_sys_central_code(api: &ExtensionApi) -> TokenStream {
let build_config_struct = gdext_build_struct::make_gdext_build_struct(&api.godot_version);
let (variant_type_enum, variant_type_deprecated_enumerators) =
make_variant_type_enum(api, true);
let variant_type_enum = make_variant_type_enum(api, true);
let [opaque_32bit, opaque_64bit] = make_opaque_types(api);

quote! {
Expand Down Expand Up @@ -45,8 +44,6 @@ pub fn make_sys_central_code(api: &ExtensionApi) -> TokenStream {
pub fn sys(self) -> crate::GDExtensionVariantType {
self.ord as _
}

#variant_type_deprecated_enumerators
}
}
}
Expand All @@ -60,7 +57,7 @@ pub fn make_core_central_code(api: &ExtensionApi, ctx: &mut Context) -> TokenStr
} = make_variant_enums(api, ctx);

let (global_enum_defs, global_reexported_enum_defs) = make_global_enums(api);
let variant_type_traits = make_variant_type_enum(api, false).0;
let variant_type_traits = make_variant_type_enum(api, false);

// TODO impl Clone, Debug, PartialEq, PartialOrd, Hash for VariantDispatch
// TODO could use try_to().unwrap_unchecked(), since type is already verified. Also directly overload from_variant().
Expand Down Expand Up @@ -205,7 +202,7 @@ fn make_global_enums(api: &ExtensionApi) -> (Vec<TokenStream>, Vec<TokenStream>)
(global_enum_defs, global_reexported_enum_defs)
}

fn make_variant_type_enum(api: &ExtensionApi, is_definition: bool) -> (TokenStream, TokenStream) {
fn make_variant_type_enum(api: &ExtensionApi, is_definition: bool) -> TokenStream {
let variant_type_enum = api
.global_enums
.iter()
Expand All @@ -215,9 +212,5 @@ fn make_variant_type_enum(api: &ExtensionApi, is_definition: bool) -> (TokenStre
let define_enum = is_definition;
let define_traits = !is_definition;

let enum_definition =
enums::make_enum_definition_with(variant_type_enum, define_enum, define_traits);
let deprecated_enumerators = enums::make_deprecated_enumerators(variant_type_enum);

(enum_definition, deprecated_enumerators)
enums::make_enum_definition_with(variant_type_enum, define_enum, define_traits)
}
31 changes: 0 additions & 31 deletions godot-codegen/src/generator/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//! See also models/domain/enums.rs for other enum-related methods.

use crate::models::domain::{Enum, Enumerator, EnumeratorValue};
use crate::{conv, util};
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};

Expand Down Expand Up @@ -335,33 +334,3 @@ fn make_enumerator_definition(
}
}
}

pub(crate) fn make_deprecated_enumerators(enum_: &Enum) -> TokenStream {
let enum_name = &enum_.name;
let deprecated_enumerators = enum_.enumerators.iter().filter_map(|enumerator| {
let Enumerator { name, .. } = enumerator;

if name == "MAX" {
return None;
}

let converted = conv::to_pascal_case(&name.to_string())
.replace("2d", "2D")
.replace("3d", "3D");

let pascal_name = util::ident(&converted);
let msg = format!("Use `{enum_name}::{name}` instead.");

let decl = quote! {
#[deprecated = #msg]
#[doc(hidden)] // No longer advertise in API docs.
pub const #pascal_name: #enum_name = Self::#name;
};

Some(decl)
});

quote! {
#( #deprecated_enumerators )*
}
}
13 changes: 4 additions & 9 deletions godot-codegen/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ pub fn make_imports() -> TokenStream {

#[cfg(since_api = "4.2")]
pub fn make_string_name(identifier: &str) -> TokenStream {
let lit = Literal::byte_string(format!("{identifier}\0").as_bytes());
quote! {
// TODO: C-string literals cannot currently be constructed in proc-macros, see the tracking issue:
// https://github.com/rust-lang/rust/issues/119750
{
#[allow(deprecated)]
StringName::from_latin1_with_nul(#lit)
}
}
let c_string = std::ffi::CString::new(identifier).expect("CString::new() failed");
let lit = Literal::c_string(&c_string);

quote! { StringName::from(#lit) }
}

#[cfg(before_api = "4.2")]
Expand Down
18 changes: 0 additions & 18 deletions godot-core/src/builtin/collections/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@ impl<T: ArrayElement> Array<T> {
}
}

#[deprecated = "Renamed to `get`."]
#[doc(hidden)] // No longer advertise in API docs.
pub fn try_get(&self, index: usize) -> Option<T> {
self.get(index)
}

/// Returns `true` if the array contains the given value. Equivalent of `has` in GDScript.
pub fn contains(&self, value: &T) -> bool {
self.as_inner().has(value.to_variant())
Expand Down Expand Up @@ -251,18 +245,6 @@ impl<T: ArrayElement> Array<T> {
})
}

#[deprecated = "Renamed to `front`, in line with GDScript method and consistent with `push_front` and `pop_front`."]
#[doc(hidden)] // No longer advertise in API docs.
pub fn first(&self) -> Option<T> {
self.front()
}

#[deprecated = "Renamed to `back`, in line with GDScript method."]
#[doc(hidden)] // No longer advertise in API docs.
pub fn last(&self) -> Option<T> {
self.back()
}

/// Clears the array, removing all elements.
pub fn clear(&mut self) {
// SAFETY: No new values are written to the array, we only remove values from the array.
Expand Down
22 changes: 0 additions & 22 deletions godot-core/src/builtin/collections/packed_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,6 @@ macro_rules! impl_packed_array {
self.as_inner().clear();
}

/// Sets the value at the specified index.
///
/// # Panics
///
/// If `index` is out of bounds.
#[deprecated = "Use [] operator (IndexMut) instead."]
#[doc(hidden)] // No longer advertise in API docs.
pub fn set(&mut self, index: usize, value: $Element) {
let ptr_mut = self.ptr_mut(index);

// SAFETY: `ptr_mut` just checked that the index is not out of bounds.
unsafe {
*ptr_mut = value;
}
}

/// Appends an element to the end of the array. Equivalent of `append` and `push_back`
/// in GDScript.
#[doc(alias = "append")]
Expand Down Expand Up @@ -312,12 +296,6 @@ macro_rules! impl_packed_array {
to_usize(self.as_inner().bsearch(Self::to_arg(value), true))
}

#[deprecated = "Renamed to bsearch like in Godot, to avoid confusion with Rust's slice::binary_search."]
#[doc(hidden)] // No longer advertise in API docs.
pub fn binary_search(&self, value: $Element) -> usize {
self.bsearch(&value)
}

/// Reverses the order of the elements in the array.
pub fn reverse(&mut self) {
self.as_inner().reverse();
Expand Down
13 changes: 0 additions & 13 deletions godot-core/src/builtin/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,19 +377,6 @@ pub enum ColorChannelOrder {
ARGB,
}

#[allow(non_upper_case_globals)]
#[doc(hidden)] // No longer advertise in API docs.
impl ColorChannelOrder {
#[deprecated(note = "Renamed to `ColorChannelOrder::RGBA`.")]
pub const Rgba: Self = Self::RGBA;

#[deprecated(note = "Renamed to `ColorChannelOrder::ABGR`.")]
pub const Abgr: Self = Self::ABGR;

#[deprecated(note = "Renamed to `ColorChannelOrder::ARGB`.")]
pub const Argb: Self = Self::ARGB;
}

impl ColorChannelOrder {
fn pack<T>(self, rgba: [T; 4]) -> [T; 4] {
let [r, g, b, a] = rgba;
Expand Down
50 changes: 0 additions & 50 deletions godot-core/src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,56 +133,6 @@ pub(crate) fn to_isize(i: usize) -> isize {
i.try_into().unwrap()
}

// ----------------------------------------------------------------------------------------------------------------------------------------------
// Deprecated symbols

/// Specialized types related to arrays.
#[deprecated = "Merged into `godot::builtin::iter`."]
#[doc(hidden)] // No longer advertise in API docs.
pub mod array {
pub type Iter<'a, T> = super::iter::ArrayIter<'a, T>;
}

/// Specialized types related to dictionaries.
#[deprecated = "Merged into `godot::builtin::iter`."]
#[doc(hidden)] // No longer advertise in API docs.
pub mod dictionary {
pub type Iter<'a> = super::iter::DictIter<'a>;
pub type Keys<'a> = super::iter::DictKeys<'a>;
pub type TypedIter<'a, K, V> = super::iter::DictTypedIter<'a, K, V>;
pub type TypedKeys<'a, K> = super::iter::DictTypedKeys<'a, K>;
}

#[deprecated = "Moved to `godot::meta` and submodules."]
#[doc(hidden)] // No longer advertise in API docs.
pub mod meta {
pub use crate::meta::error::*;
pub use crate::meta::*;
}

/// The side of a [`Rect2`] or [`Rect2i`].
///
/// _Godot equivalent: `@GlobalScope.Side`_
#[deprecated = "Merged with `godot::builtin::Side`."]
#[doc(hidden)] // No longer advertise in API docs.
pub type RectSide = Side;

#[allow(non_upper_case_globals)]
#[doc(hidden)] // No longer advertise in API docs.
impl Side {
#[deprecated(note = "Renamed to `Side::LEFT`.")]
pub const Left: Side = Side::LEFT;

#[deprecated(note = "Renamed to `Side::TOP`.")]
pub const Top: Side = Side::TOP;

#[deprecated(note = "Renamed to `Side::RIGHT`.")]
pub const Right: Side = Side::RIGHT;

#[deprecated(note = "Renamed to `Side::BOTTOM`.")]
pub const Bottom: Side = Side::BOTTOM;
}

// ----------------------------------------------------------------------------------------------------------------------------------------------
// #[test] utils for serde

Expand Down
31 changes: 0 additions & 31 deletions godot-core/src/builtin/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,28 +551,6 @@ pub enum ProjectionPlane {
BOTTOM = 5,
}

#[allow(non_upper_case_globals)]
#[doc(hidden)] // No longer advertise in API docs.
impl ProjectionPlane {
#[deprecated(note = "Renamed to `ProjectionPlane::NEAR`")]
pub const Near: Self = Self::NEAR;

#[deprecated(note = "Renamed to `ProjectionPlane::FAR`")]
pub const Far: Self = Self::FAR;

#[deprecated(note = "Renamed to `ProjectionPlane::LEFT`")]
pub const Left: Self = Self::LEFT;

#[deprecated(note = "Renamed to `ProjectionPlane::TOP`")]
pub const Top: Self = Self::TOP;

#[deprecated(note = "Renamed to `ProjectionPlane::RIGHT`")]
pub const Right: Self = Self::RIGHT;

#[deprecated(note = "Renamed to `ProjectionPlane::BOTTOM`")]
pub const Bottom: Self = Self::BOTTOM;
}

impl ProjectionPlane {
/// Convert from one of GDScript's `Projection.PLANE_*` integer constants.
pub fn try_from_ord(ord: i64) -> Option<Self> {
Expand All @@ -596,15 +574,6 @@ pub enum ProjectionEye {
RIGHT = 2,
}

#[allow(non_upper_case_globals)]
impl ProjectionEye {
#[deprecated(note = "Renamed to `ProjectionEye::LEFT`")]
pub const Left: Self = Self::LEFT;

#[deprecated(note = "Renamed to `ProjectionEye::RIGHT`")]
pub const Right: Self = Self::RIGHT;
}

impl ProjectionEye {
/// Convert from numbers `1` and `2`.
pub fn try_from_ord(ord: i64) -> Option<Self> {
Expand Down
Loading
Loading