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

Disable Serde's default-features #905

Merged
merged 3 commits into from Apr 30, 2022

Conversation

ass3rt
Copy link

@ass3rt ass3rt commented Mar 24, 2022

With this patch, existing users of the use-serde feature will no longer be
compiling with serde/std enabled, but this allows dependent projects
to import serde and enable serde/alloc as required by some no-std targets.

@ass3rt
Copy link
Author

ass3rt commented Mar 24, 2022

Seems I have some test failures to look into. I'll try to get these worked out tonight.

@tcharding
Copy link
Member

Changing features makes this a breaking change, right? We are in the process of a big breaking release anyways but thought I'd flag it.

Cargo.toml Outdated Show resolved Hide resolved
@ass3rt
Copy link
Author

ass3rt commented Mar 25, 2022

Changing features makes this a breaking change, right?

That is my understanding 👍

apoelstra
apoelstra previously approved these changes Mar 26, 2022
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK f18c42c

Yes, this is a breaking change, but it's fine to bring into the RC.

Copy link
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

NACK: build is broken due to test dependency issues + possible undesirable side-effect of always having non-std serde even for std builds

Cargo.toml Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@ass3rt
Copy link
Author

ass3rt commented Mar 28, 2022

Sorry for the repeated test failures. I promise I am running ./contrib/test.sh before submitting patches, but the tests are passing on my system. Perhaps I'm missing a step. If anyone has a recommended test workflow before submitting PRs, I will happily accept any advice to improve my testing :)

@apoelstra
Copy link
Member

There are probably some environment variables you need to set to get test.sh to do anything. In particular DO_FEATURE_MATRIX=true.

@Kixunil
Copy link
Collaborator

Kixunil commented Mar 29, 2022

The test failures are actually caused by the lack of serde-std feature. We really have to use it since I don't believe anyone here wants to bump MSRV to 1.60.

@ass3rt ass3rt force-pushed the disable-serde-defaults branch 2 times, most recently from dd63987 to 9cc4844 Compare April 6, 2022 03:56
@ass3rt
Copy link
Author

ass3rt commented Apr 6, 2022

I've reworked this PR to address comments, fix tests, and rebase onto master. Sorry for the delay (its been a busy week on other projects).

Specifically, I added the serde-std feature for those that need it, and enabled it for tests.

Cargo.toml Outdated Show resolved Hide resolved
Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

This doesn't look right, the feature is not used anywhere. Did you forget to commit some files?

@ass3rt
Copy link
Author

ass3rt commented Apr 6, 2022

This doesn't look right, the feature is not used anywhere. Did you forget to commit some files?

The only place I am aware of that requires serde-std is in tests, which I added. Are you aware of anywhere else that requires it?

Keep in mind, any feature which enables serde-std will break no-std builds (obviously), so IMO it should not be a requirement for any code which we expect to be no-std compatible

@Kixunil
Copy link
Collaborator

Kixunil commented Apr 7, 2022

Sorry, it looks like I was confused and you don't need serde-std, just call tests with use-serde,std or use-serde,no-std (which is broken because of #947).

@ass3rt
Copy link
Author

ass3rt commented Apr 7, 2022

Ok, I'll back out serde-std. It was a useful thought experiment, if nothing else :)

@Kixunil
Copy link
Collaborator

Kixunil commented Apr 7, 2022

Also to address @dr-orlovsky concern: users needing serde/std can and should enable it explicitly when depending on serde.

@ass3rt ass3rt force-pushed the disable-serde-defaults branch 2 times, most recently from 2ed3175 to fcbe52d Compare April 7, 2022 18:35
@ass3rt
Copy link
Author

ass3rt commented Apr 7, 2022

Oops I forgot to run the dep_test. I did have environment variables set to enable that test, but I must've cleared them before my last push 🤦.

I forgot to explicitly add serde with default features as a dependency for the dep_test. Fixed and force pushed. Tests are passing again. Sorry for all the churn!

@Kixunil
Copy link
Collaborator

Kixunil commented Apr 8, 2022

Oh, shit. I got confused. For some reason the compatibility issue can't be triggered from normal cargo test, only from a dependency and I also forgot to set the env var. 🤦‍♂️

To clean up my shit, I looked at it properly and found a proper solution. Wanted to make a PR against your repo but was unable to do so. Here are my changes: Kixunil@28bb060

Explanation:

I started re-adding serde-std but then I realized the affected methods actually re-implement the default behavior (the existing ones already forward!) so I could just delete them. It looked like that was the only change required but then I noticed in case of script we can get perf benefit from overriding. I then realized we don't need serde-std but serde-alloc and soon after I realized we can depend on it unconditionally because the whole library already depends on alloc and I don't think it will stop depending on it any time soon. (Maybe bitcoin-units will one day.) Thus I just added alloc to the serde features and kept the other changes (even though they are off-topic).

If you want to be super-pedantic and make the history nicer you could split it up into three commits (changing serde features, removing default impls, adding override) but I personally wouldn't block the PR if you don't want to.

Suggested commit descriptions:

  1. same as now
  2. Removed reimplementations of default methods. (next paragraph) The default methods do the exact same thing thus our overrides are useless, potentially even problematic.
  3. Override default visit_byte_buf on Script. (next paragraph) This override may avoid allocation and thus make the deserialization faster.

@ass3rt
Copy link
Author

ass3rt commented Apr 8, 2022

@Kixunil good finds! I like that approach. I am afk for several hours today, but I found the github setting to let others push commits to my PR. You should be able to push now. If not, I'll pull your changes in when I get a chance this evening.

@Kixunil
Copy link
Collaborator

Kixunil commented Apr 9, 2022

Cool, pushed! Do you want to do the squashing?

@Kixunil
Copy link
Collaborator

Kixunil commented Apr 9, 2022

Oh, shit, MSRV issues. Suggested solution: remove the optimization and alloc dependency and reintroduce them after MSRV bump.

Now I finally understand why serde didn't do std = ["alloc"] but conditions everything using any(feature = "std", feature = "alloc").

@Kixunil Kixunil added the before edition bump We want to merge this before edition is bumped label Apr 22, 2022
@Kixunil Kixunil added this to the 0.29.0 milestone Apr 22, 2022
@Kixunil
Copy link
Collaborator

Kixunil commented Apr 22, 2022

Let's just wait for #964

@apoelstra
Copy link
Member

We have #964 now -- can you rebase?

@ass3rt
Copy link
Author

ass3rt commented Apr 22, 2022

We have #964 now -- can you rebase?

Awesome. Done ✔️

@Kixunil
Copy link
Collaborator

Kixunil commented Apr 25, 2022

Could you clean up the git history please? Ideally make it three commits: 1. the topic of this PR, 2. removing unneeded method impls, 2 adding the optimization. But I can accept squashing to a single commit.

ass3rt added 3 commits April 25, 2022 09:51
We do not need serde/std, only serde/alloc. Serde/std breaks no-std
builds, but serde/alloc does not. Depending on serde/alloc is the more
compatible approach, as the entire library already depends on alloc.
The default methods do the exact same thing thus our overrides are
useless, potentially even problematic.

Credit to Kixunil for this fix: rust-bitcoin#905 (comment)
This override may avoid allocation and thus make the deserialization
faster.

Credit to Kixunil for this fix: rust-bitcoin#905 (comment)
@ass3rt
Copy link
Author

ass3rt commented Apr 25, 2022

@Kixunil good call. Done. Thanks for all your assistance!

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

Perfect, thanks!

ACK 76fcf81

@Kixunil Kixunil added the one ack PRs that have one ACK, so one more can progress them label Apr 25, 2022
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 76fcf81

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 76fcf81

@apoelstra apoelstra merged commit 9f81798 into rust-bitcoin:master Apr 30, 2022
ChallengeDev210 pushed a commit to ChallengeDev210/rust-bitcoin that referenced this pull request Aug 1, 2022
The default methods do the exact same thing thus our overrides are
useless, potentially even problematic.

Credit to Kixunil for this fix: rust-bitcoin/rust-bitcoin#905 (comment)
ChallengeDev210 pushed a commit to ChallengeDev210/rust-bitcoin that referenced this pull request Aug 1, 2022
This override may avoid allocation and thus make the deserialization
faster.

Credit to Kixunil for this fix: rust-bitcoin/rust-bitcoin#905 (comment)
ChallengeDev210 pushed a commit to ChallengeDev210/rust-bitcoin that referenced this pull request Aug 1, 2022
76fcf81 Override default visit_byte_buf on Script (ass3rt)
add100c Removed reimplementations of default methods (ass3rt)
7db03f2 Disable Serde's default-features (ass3rt)

Pull request description:

  With this patch, existing users of the `use-serde` feature will no longer be
  compiling with `serde/std` enabled, but this allows dependent projects
  to import serde and enable `serde/alloc` as required by some no-std targets.

ACKs for top commit:
  Kixunil:
    ACK 76fcf81
  tcharding:
    ACK 76fcf81
  apoelstra:
    ACK 76fcf81

Tree-SHA512: 5748e64e1f91f19dbfbf32bead6e6d759e448e92ed0dab731b3059f6b37bd811fad6654edc8fbd113e3be17fefaf9fc4912145d6b61484ced0517712361ecfdc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
before edition bump We want to merge this before edition is bumped one ack PRs that have one ACK, so one more can progress them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants