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

DeprecationInfo Remove deprecated attribute from generated code. #6312

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

pkhry
Copy link
Contributor

@pkhry pkhry commented Oct 31, 2024

Description

Removed #[deprecated] attribute from the generated code, so that code is not littered with useless warnings but DeprecationInfo is still propagated in MetadataIr

see an example of warnings being too noisy: #6169

Review Notes

The change itself is just adding attribute removal code after specific steps during macro expansion.

@pkhry pkhry added R0-silent Changes should not be mentioned in any release notes T1-FRAME This PR/Issue is related to core FRAME, the framework. D1-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase. labels Oct 31, 2024
@pkhry pkhry self-assigned this Oct 31, 2024
@pkhry pkhry removed the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Oct 31, 2024
@pkhry
Copy link
Contributor Author

pkhry commented Oct 31, 2024

bot fmt

@command-bot
Copy link

command-bot bot commented Oct 31, 2024

@pkhry https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7675374 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 11-d04b7269-e0fa-486f-aeea-391e95ae9915 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Oct 31, 2024

@pkhry Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7675374 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7675374/artifacts/download.

@pkhry
Copy link
Contributor Author

pkhry commented Oct 31, 2024

/cmd fmt

@pkhry pkhry marked this pull request as ready for review October 31, 2024 15:01
@pkhry pkhry requested a review from a team as a code owner October 31, 2024 15:01
@pkhry pkhry requested a review from kianenigma October 31, 2024 15:02
Copy link

Command "fmt" has started 🚀 See logs here

Copy link

Command "fmt" has finished ✅ See logs here

@pkhry
Copy link
Contributor Author

pkhry commented Nov 1, 2024

bot update-ui

@command-bot
Copy link

command-bot bot commented Nov 1, 2024

@pkhry https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7677803 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/update-ui/update-ui.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 12-aa9c7dd9-df58-453f-9d18-c4c165eebfb0 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Nov 1, 2024

@pkhry Command "$PIPELINE_SCRIPTS_DIR/commands/update-ui/update-ui.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7677803 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7677803/artifacts/download.

@@ -209,6 +210,8 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
let return_type =
&call.methods.get(i).expect("def should be consistent with item").return_type;

remove_deprecation_attribute(&mut method.attrs);
Copy link
Contributor

Choose a reason for hiding this comment

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

So this removes the deprecated attribute from the call?
I think it is not ideal, because we lose the deprecation of the call itself in rust code.

I think the ideal is to have the deprecation on the call function, also the deprecation on the call variant.
But then all usage of this call inside the macro should be used with #[allow(deprecated)] on top of the instruction. (We should be careful not to have this #[allow(deprecated)] for logic written by user).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted this change

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking a more fine-grained implementation.

Like the dispatch_bypass_filter would be implemented with #[allow(deprecated)] just above the function call

<#pallet_ident<#type_use_gen>>::#fn_name(origin, #( #args_name, )* )

Same for all other types: when the macro use them we would write: #[allow(deprecated)].

But then we have to be careful not to write #[allow(deprecated)] on top of blocks which include code written by user. So that user is still notified when they use deprecated elements in their own code.

If it is too difficult, maybe we can merge this PR, without the revert then.

Copy link
Contributor Author

@pkhry pkhry Nov 5, 2024

Choose a reason for hiding this comment

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

I've tried implementing it this morning, and i can't seem to understand how to propagate #[allow(deprecated)] from defs inside #[pallet] to expansion of construct_runtime!. Ie if we deprecate an event or an error we dont have any attributes to include maybe_allow_attrs inside code generated by construct_runtime!

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I agree here with @gui1117. Just removing the deprecation attribute, because it adds more noise is not the right way. The attribute is doing exactly for what it is designed for.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've tried implementing it this morning, and i can't seem to understand how to propagate #[allow(deprecated)] from defs inside #[pallet] to expansion of construct_runtime!. Ie if we deprecate an event or an error we dont have any attributes to include maybe_allow_attrs inside code generated by construct_runtime!

about construct_runtime! if the whole call or event or pallet is deprecated, then I think the writer of the construct_runtime! should add #[allow(deprecated)] on top of the pallet variant:

construct_runtime!{
struct Runtime {
  #[allow(deprecated)]
  MyPalletWithDeprecatedCall: my_pallet; // my pallet is using call implicitly here.
}
}

Otherwise it is fair to actually warn the runtime writer than one of the pallet he uses has actual deprecated elements.

Note that this should only happen when deprecating whole types like Event or Call or Pallet, not when deprecating a single call inside the pallet Call.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure what the purpose of deprecating these types would be. I mean I would understand if the entire pallet would be deprecated.

@pkhry pkhry requested a review from gui1117 November 4, 2024 09:49
@paritytech-review-bot paritytech-review-bot bot requested a review from a team November 4, 2024 09:49
@pkhry pkhry requested a review from davidk-pt November 5, 2024 11:33
@pkhry
Copy link
Contributor Author

pkhry commented Dec 3, 2024

/cmd fmt

@paritytech-review-bot paritytech-review-bot bot requested a review from a team December 3, 2024 10:19
Copy link

github-actions bot commented Dec 3, 2024

Command "fmt" has started 🚀 See logs here

Copy link

github-actions bot commented Dec 3, 2024

Command "fmt" has finished ✅ See logs here

@pkhry
Copy link
Contributor Author

pkhry commented Dec 3, 2024

/cmd fmt

Copy link

github-actions bot commented Dec 3, 2024

Command "fmt" has started 🚀 See logs here

Copy link

github-actions bot commented Dec 3, 2024

Command "fmt" has finished ✅ See logs here

@pkhry pkhry requested a review from gui1117 December 3, 2024 10:59
@pkhry pkhry requested a review from gui1117 December 4, 2024 10:33
@paritytech-review-bot paritytech-review-bot bot requested a review from a team December 4, 2024 10:33
@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/12164030100
Failed job name: test-linux-stable

@pkhry
Copy link
Contributor Author

pkhry commented Dec 5, 2024

bot update-ui

@command-bot
Copy link

command-bot bot commented Dec 5, 2024

@pkhry https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7871580 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/update-ui/update-ui.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 9-5f84b5dc-d1a7-42be-ad69-4ff18c93225f to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Dec 5, 2024

@pkhry Command "$PIPELINE_SCRIPTS_DIR/commands/update-ui/update-ui.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7871580 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7871580/artifacts/download.

@pkhry pkhry requested a review from bkchr December 6, 2024 23:22
Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

Some more comments, overall I think it is ok, do you think there is still time to not put some deprecate information in the metadata?
Like do you think it makes sense to reduce the scope of the deprecated information to only most relevant information?
But the PR should be good now.

@@ -82,6 +88,7 @@ pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream {
quote::quote_spanned!(def.pallet_struct.attr_span =>
impl<#type_impl_gen> #pallet_ident<#type_use_gen> #config_where_clause {
#[doc(hidden)]
#[allow(deprecated)]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only when the full error type is deprecated, I also would not handle this case personally. But it can be fine.

substrate/frame/support/test/tests/enum_deprecation.rs Outdated Show resolved Hide resolved
@@ -14,7 +14,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#![allow(useless_deprecated, deprecated, clippy::deprecated_semver)]
#![allow(useless_deprecated, clippy::deprecated_semver)]
Copy link
Contributor

Choose a reason for hiding this comment

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

why is deprecated_semver needed by the way?
Also people will have to bound useless_deprecated, or we can remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there were tests during the initial review with non-semver strings in the deprecation attribute. removed all of allows above

@paritytech-review-bot paritytech-review-bot bot requested a review from a team December 11, 2024 00:06
@pkhry pkhry requested a review from gui1117 December 11, 2024 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D1-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase. R0-silent Changes should not be mentioned in any release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants