-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Do not deduce parameter attributes during CTFE #151842
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
Open
eggyal
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
eggyal:skip-deducing-parameter-attrs-during-ctfe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+200
−69
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1811,11 +1811,32 @@ rustc_queries! { | |||||||||||||||||||||
| desc { "computing call ABI of `{}` function pointers", key.value.0 } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for | ||||||||||||||||||||||
| /// direct calls to an `fn`. | ||||||||||||||||||||||
| /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for direct calls* | ||||||||||||||||||||||
| /// to an `fn`. Indirectly-passed parameters in the returned ABI might not include all possible | ||||||||||||||||||||||
| /// codegen optimization attributes (such as `ReadOnly` or `CapturesNone`), as deducing these | ||||||||||||||||||||||
| /// requires inspection of function bodies that can lead to cycles when performed during typeck. | ||||||||||||||||||||||
| /// Post typeck, you should prefer the optimized ABI returned by `fn_abi_of_instance`. | ||||||||||||||||||||||
| /// | ||||||||||||||||||||||
| /// NB: the ABI returned by this query must not differ from that returned by | ||||||||||||||||||||||
| /// `fn_abi_of_instance` in any other way. | ||||||||||||||||||||||
| /// | ||||||||||||||||||||||
| /// * that includes virtual calls, which are represented by "direct calls" to an | ||||||||||||||||||||||
| /// `InstanceKind::Virtual` instance (of `<dyn Trait as Trait>::fn`). | ||||||||||||||||||||||
| query fn_abi_of_instance_no_deduced_attrs( | ||||||||||||||||||||||
| key: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)> | ||||||||||||||||||||||
| ) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> { | ||||||||||||||||||||||
| desc { "computing unadjusted call ABI of `{}`", key.value.0 } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for direct calls* | ||||||||||||||||||||||
| /// to an `fn`. Indirectly-passed parameters in the returned ABI will include applicable | ||||||||||||||||||||||
| /// codegen optimization attributes, including `ReadOnly` and `CapturesNone` -- deduction of | ||||||||||||||||||||||
| /// which requires inspection of function bodies that can lead to cycles when performed during | ||||||||||||||||||||||
| /// typeck. During typeck, you should therefore use instead the unoptimized ABI returned by | ||||||||||||||||||||||
| /// `fn_abi_of_instance_no_deduced_attrs`. | ||||||||||||||||||||||
|
Comment on lines
+1831
to
+1836
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
| /// | ||||||||||||||||||||||
| /// NB: that includes virtual calls, which are represented by "direct calls" | ||||||||||||||||||||||
| /// to an `InstanceKind::Virtual` instance (of `<dyn Trait as Trait>::fn`). | ||||||||||||||||||||||
| /// * that includes virtual calls, which are represented by "direct calls" to an | ||||||||||||||||||||||
| /// `InstanceKind::Virtual` instance (of `<dyn Trait as Trait>::fn`). | ||||||||||||||||||||||
| query fn_abi_of_instance( | ||||||||||||||||||||||
| key: ty::PseudoCanonicalInput<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)> | ||||||||||||||||||||||
| ) -> Result<&'tcx rustc_target::callconv::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //! Items whose type depends on CTFE (such as the async closure/coroutine beneath, whose type | ||
| //! depends upon evaluating `do_nothing`) should not cause a query cycle owing to the deduction of | ||
| //! the function's parameter attributes, which are only required for codegen and not for CTFE. | ||
| //! | ||
| //! Regression test for https://github.com/rust-lang/rust/issues/151748 | ||
| //@ compile-flags: -O | ||
| //@ edition: 2018 | ||
| //@ check-pass | ||
|
|
||
| fn main() { | ||
| let _ = async || { | ||
| let COMPLEX_CONSTANT = (); | ||
| }; | ||
| } | ||
|
|
||
| const fn do_nothing() {} | ||
|
|
||
| const COMPLEX_CONSTANT: () = do_nothing(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not list what exactly gets put into "deduced attrs" as that will inevitably expand in the future.