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

Fix fnptr not auto implement fn once #3492

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

badumbatish
Copy link
Contributor

@badumbatish badumbatish commented Mar 7, 2025

im a bit rather new to this area...

this fixes #3354

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (VariantDef::clone): reformat 
* (VariantDef::monomorphized_clone): reformat 
* (FnPtr::setup_fn_once_output): Fix fnptr not auto implement fn once
* typecheck/rust-tyty.h: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/format_args_basic_expansion.rs: add sized and fn_once
* rust/compile/issue-2042.rs: add sized and fn_once
* rust/compile/privacy6.rs: add sized and fn_once
* rust/compile/rust_abi.rs: add sized and fn_once
* rust/compile/torture/function_reference2.rs: add sized and fn_once
* rust/compile/torture/function_reference3.rs: add sized and fn_once
* rust/compile/torture/function_reference4.rs: add sized and fn_once
* rust/compile/try-catch-unwind-new.rs: add sized and fn_once
* rust/compile/try-catch-unwind-old.rs: add sized and fn_once

@badumbatish badumbatish force-pushed the fn_once_trait_on_fnptr branch from 9f2c10d to 735c652 Compare March 7, 2025 06:48
@P-E-P P-E-P requested a review from philberty March 7, 2025 16:47
gcc/rust/ChangeLog:
	* typecheck/rust-tyty.cc (FnPtr::setup_fn_once_output):
	Fix fnptr not auto implement fn once
	* typecheck/rust-tyty.h: Likewise.

gcc/testsuite/ChangeLog:

	* rust/compile/format_args_basic_expansion.rs: add sized and fn_once
	* rust/compile/issue-2042.rs: add sized and fn_once
	* rust/compile/privacy6.rs: add sized and fn_once
	* rust/compile/rust_abi.rs: add sized and fn_once
	* rust/compile/torture/function_reference2.rs: add sized and fn_once
	* rust/compile/torture/function_reference3.rs: add sized and fn_once
	* rust/compile/torture/function_reference4.rs: add sized and fn_once
	* rust/compile/try-catch-unwind-new.rs: add sized and fn_once
	* rust/compile/try-catch-unwind-old.rs: add sized and fn_once
@badumbatish badumbatish force-pushed the fn_once_trait_on_fnptr branch from 735c652 to 1eaee67 Compare March 11, 2025 05:01
@badumbatish
Copy link
Contributor Author

i somehow missed privacy6.rs ... will force push soo for merge if Philip doesn't have any change requests

@dkm
Copy link
Member

dkm commented Mar 20, 2025

I may be wrong, but I think you're missing the "Signed-off-by" footer (unless you've filed copyright assignment, in that case please ignore my comment) :)

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code looks good, and it's not easy so well done. I'll let Philip take a look before merging as that is more his area of expertise. Thanks for working on this @badumbatish!!

Comment on lines +2229 to +2243
auto fn_once_lookup = mappings.lookup_lang_item (LangItem::Kind::FN_ONCE);
auto fn_once_output_lookup
= mappings.lookup_lang_item (LangItem::Kind::FN_ONCE_OUTPUT);
if (!fn_once_lookup)
{
rust_fatal_error (UNKNOWN_LOCATION,
"Missing required %<fn_once%> lang item");
return;
}
if (!fn_once_output_lookup)
{
rust_fatal_error (UNKNOWN_LOCATION,
"Missing required %<fn_once_ouput%> lang item");
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be a mappings.get_lang_item(...) API which already emits the rust_fatal_error for you. we should probably rename it btw lol

Comment on lines +2245 to +2246
DefId &trait_id = fn_once_lookup.value ();
DefId &trait_item_id = fn_once_output_lookup.value ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would also allow you to avoid these lines, as get_lang_item already returns a DefId instead of an optional<Defid>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll probably fix the original code from Philip too

Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is part of the fix but there are some work to be done for bounds checking. Which i think the original issue is about. I think we do need this though.

@@ -2222,6 +2222,56 @@ FnPtr::clone () const
get_combined_refs ());
}

void
FnPtr::setup_fn_once_output () const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a dup of ClosureType::setup_fn_once_output its probably better to find a way to extract that out to be a shared helper

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, will do

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would adding this to CallableTypeInterface work?

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 this pull request may close these issues.

Bad closure bounds check
6 participants