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

Omit lifetime of wrapper function. #1649

Closed
my-vegetable-has-exploded opened this issue Apr 11, 2024 · 3 comments · Fixed by #1655
Closed

Omit lifetime of wrapper function. #1649

my-vegetable-has-exploded opened this issue Apr 11, 2024 · 3 comments · Fixed by #1655

Comments

@my-vegetable-has-exploded
Copy link
Contributor

Thanks for your great work!

I found the warper function contains unnecessary lifetime. And the rustc compiler warns that lifetime parameter 'a never used.

#[pgrx::pg_extern(immutable, strict, parallel_safe)]
fn _vectors_vector_accum<'a>(
    mut state: AccumulateState<'a>,
    value: Vecf32Input<'_>,
) -> AccumulateState<'a> 

After expanding

pub unsafe extern "C" fn _vectors_vector_accum_wrapper<'a>(
    _fcinfo: ::pgrx::pg_sys::FunctionCallInfo,
) -> ::pgrx::pg_sys::Datum {
    #[allow(non_snake_case)]
    unsafe fn _vectors_vector_accum_wrapper_inner<'a>(
        _fcinfo: ::pgrx::pg_sys::FunctionCallInfo,
    ) -> ::pgrx::pg_sys::Datum { 

The lifetime is useless for _vectors_vector_accum_wrapper.

If this issue makes sense, I'd like to open a pr to fix it.

@workingjubilee
Copy link
Member

I would accept a PR that applies #[allow(unused_lifetimes)] to the wrapper function.

@workingjubilee
Copy link
Member

workingjubilee commented Apr 11, 2024

If I remember correctly, actually omitting the "unused" lifetime does not actually work in all cases, which is why a PR simply omitting the lifetime may not work out. I would be happy to review such a PR, however.

@workingjubilee workingjubilee changed the title Omit lifetime of warpper function. Omit lifetime of wrapper function. Apr 11, 2024
@my-vegetable-has-exploded
Copy link
Contributor Author

my-vegetable-has-exploded commented Apr 14, 2024

If I remember correctly, actually omitting the "unused" lifetime does not actually work in all cases, which is why a PR simply omitting the lifetime may not work out. I would be happy to review such a PR, however.

Thanks for pointing out it. But I think that both wrapper function and wrapper_inner function just take _fcinfo: ::pgrx::pg_sys::FunctionCallInfo as arguments and return ::pgrx::pg_sys::Datum , those type don't contain lifetime. I think maybe your concern is that #resolved_ty contains lifetime<'a> in ::pgrx::fcinfo::pg_getarg::<#resolved_ty> . I am not sure whether lifetime is nessary for ::pgrx::fcinfo::pg_getarg.

(false, None) => quote_spanned! { pat.span() =>
let #pat = unsafe { ::pgrx::fcinfo::pg_getarg::<#resolved_ty>(#fcinfo_ident, #idx).unwrap_or_else(|| panic!("{} is null", stringify!{#pat})) };
},

I would accept a PR that applies #[allow(unused_lifetimes)] to the wrapper function.

Get! It is a really easier way to add #![allow(unused_lifetimes, clippy::extra_unused_lifetimes)].

Thanks @workingjubilee

workingjubilee pushed a commit that referenced this issue Apr 15, 2024
close #1649.

Signed-off-by: my-vegetable-has-exploded <wy1109468038@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants