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

Adding support for stringifier functions in Kotlin #738

Merged
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: 0 additions & 2 deletions core/src/hir/elision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ pub trait LifetimeLowerer {
/// Lowers a slice of [`ast::Lifetime`]s by calling
/// [`LifetimeLowerer::lower_lifetime`] repeatedly.
///

/// `type_generics` is the full list of generics on the type definition of the type
/// this lifetimes list is found on (needed for generating anon lifetimes)
fn lower_lifetimes(
Expand Down Expand Up @@ -143,7 +142,6 @@ pub trait LifetimeLowerer {
///
/// `type_generics` is the full list of generics on the type definition of the type
/// this generics list is found on (needed for generating anon lifetimes)

fn lower_generics(
&mut self,
lifetimes: &[ast::Lifetime],
Expand Down
1 change: 0 additions & 1 deletion core/src/hir/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl LifetimeEnv {

/// Get an iterator of all lifetimes that this must live as long as (including itself)
/// with the first lifetime always being returned first

pub fn all_shorter_lifetimes(
&self,
lt: impl Borrow<Lifetime>,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions runtime/src/slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub struct DiplomatSlice<'a, T> {
phantom: PhantomData<&'a [T]>,
}

impl<'a, T> Clone for DiplomatSlice<'a, T> {
impl<T> Clone for DiplomatSlice<'_, T> {
fn clone(&self) -> Self {
*self
}
}
impl<'a, T> Copy for DiplomatSlice<'a, T> {}
impl<T> Copy for DiplomatSlice<'_, T> {}

impl<'a, T> From<&'a [T]> for DiplomatSlice<'a, T> {
fn from(x: &'a [T]) -> Self {
Expand Down Expand Up @@ -46,7 +46,7 @@ impl<'a, T> From<DiplomatSlice<'a, T>> for &'a [T] {
}
}

impl<'a, T> Deref for DiplomatSlice<'a, T> {
impl<T> Deref for DiplomatSlice<'_, T> {
type Target = [T];
fn deref(&self) -> &[T] {
(*self).into()
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'a, T> From<DiplomatSliceMut<'a, T>> for &'a mut [T] {
}
}

impl<'a, T> Deref for DiplomatSliceMut<'a, T> {
impl<T> Deref for DiplomatSliceMut<'_, T> {
type Target = [T];
fn deref(&self) -> &[T] {
if self.ptr.is_null() {
Expand All @@ -102,7 +102,7 @@ impl<'a, T> Deref for DiplomatSliceMut<'a, T> {
}
}

impl<'a, T> DerefMut for DiplomatSliceMut<'a, T> {
impl<T> DerefMut for DiplomatSliceMut<'_, T> {
fn deref_mut(&mut self) -> &mut [T] {
if self.ptr.is_null() {
debug_assert!(self.len == 0);
Expand Down Expand Up @@ -210,7 +210,7 @@ impl<'a> From<DiplomatUtf8StrSlice<'a>> for &'a str {
}
}

impl<'a> Deref for DiplomatUtf8StrSlice<'a> {
impl Deref for DiplomatUtf8StrSlice<'_> {
type Target = str;
fn deref(&self) -> &str {
(*self).into()
Expand Down
24 changes: 18 additions & 6 deletions tool/src/kotlin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) fn attr_support() -> BackendAttrSupport {
a.named_constructors = false; // TODO
a.fallible_constructors = false; // TODO
a.accessors = false;
a.stringifiers = false; // TODO
a.stringifiers = true;
a.comparators = false; // TODO
a.iterators = true;
a.iterables = true;
Expand Down Expand Up @@ -1188,11 +1188,21 @@ returnVal.option() ?: return null
panic!("Can only have one iterable method per opaque struct")
}
}
_ => format!(
"fun {}({}): {return_ty}",
self.formatter.fmt_method_name(method),
params
),
Some(SpecialMethod::Stringifier) => {
if !special_methods.has_stringifier {
special_methods.has_stringifier = true;
"override fun toString(): String".to_string()
} else {
panic!("Can only have one stringifier method per opaque struct")
}
}
_ => {
format!(
"fun {}({}): {return_ty}",
self.formatter.fmt_method_name(method),
params
)
}
};

MethodTpl {
Expand Down Expand Up @@ -1901,6 +1911,7 @@ struct SpecialMethods {
iterator_type: Option<String>,
indexer_type: Option<IndexerType>,
iterable_type: Option<String>,
has_stringifier: bool,
}

struct IndexerType {
Expand All @@ -1921,6 +1932,7 @@ impl SpecialMethodsImpl {
iterator_type,
indexer_type,
iterable_type,
has_stringifier: _,
}: SpecialMethods,
) -> Self {
let interfaces = iterator_type
Expand Down
Loading