Skip to content

Introduce private modules and infrastructure#3844

Closed
tcharding wants to merge 3 commits intorust-bitcoin:masterfrom
tcharding:01-02-private-write-err
Closed

Introduce private modules and infrastructure#3844
tcharding wants to merge 3 commits intorust-bitcoin:masterfrom
tcharding:01-02-private-write-err

Conversation

@tcharding
Copy link
Copy Markdown
Member

@tcharding tcharding commented Jan 1, 2025

EDIT: After sleeping on this I'm not happy with the removal of int() change. I've had another idea.

Note to reviewers:

Warning this is an f'ing nightmare. To review this I'd first look at the contrib/diff-private.sh script. Then once you are convinced that all the private modules are the same just look at the one in internals.

The int() function proved too hard for me to solve so I inlined it. That change could be pulled out into a separate PR if needed.

The original idea for this PR was discussed here: #3817 (comment)


We currently share code by way of public code in the internals crate. This was a hack to reduce code duplication while trying to keep things private - it failed. We currently have at least one "private" type in the public API (InputString).

In an effort to solve the original problem while fixing the mistake we came up with the idea of having a private directory in internals with a bunch of small modules in it. We define this as the Single Source Of Truth (SSOT). Then we copy this directory to other crates as needed. To ensure that we don't inadvertently update one and not the other we use CI to diff against the SSOT.

Introduce the internals/src/private directory. Add a bunch of stuff to allow use to fully encapsulate the InputString type.

Add infrastructure to CI to test that the new stuff in private stays in sync.

The readme is stale, we forgot to add the `API` job to the readme.
@github-actions github-actions bot added ci C-bitcoin PRs modifying the bitcoin crate C-units PRs modifying the units crate C-internals PRs modifying the internals crate doc C-primitives C-base58 PRs modifying the base58 crate labels Jan 1, 2025
@tcharding tcharding mentioned this pull request Jan 1, 2025
@tcharding
Copy link
Copy Markdown
Member Author

The idea for this PR was discussed in #3817

@tcharding
Copy link
Copy Markdown
Member Author

Ooph, I was hoping to minimze the size of the diff in this PR but it seems InputString is too tightly coupled with write_err to handle it separately. Will need more work.

@tcharding tcharding marked this pull request as draft January 1, 2025 22:47
@tcharding tcharding force-pushed the 01-02-private-write-err branch 2 times, most recently from 9dce036 to ff32453 Compare January 2, 2025 02:48
We currently share code by way of public code in the `internals` crate.
This was a hack to reduce code duplication while trying to keep things
private - it failed. We currently have at least one "private" type in
the public API (`InputString`).

In an effort to solve the original problem while fixing the mistake we
came up with the idea of having a private directory in `internals` with
a bunch of small modules in it. We define this as the Single Source Of
Truth (SSOT). Then we copy this directory to other crates as needed. To
ensure that we don't inadvertently update one and not the other we use
CI to diff against the SSOT.

Introduce the `internals/src/private` directory. Add a bunch of stuff
to allow use to fully encapsulate the `InputString` type.

Add infrastructure to CI to test that the new stuff in `private` stays
in sync.
@tcharding tcharding force-pushed the 01-02-private-write-err branch from ff32453 to b26b6e2 Compare January 2, 2025 02:51
@tcharding tcharding marked this pull request as ready for review January 2, 2025 02:58
@tcharding tcharding marked this pull request as draft January 2, 2025 21:16
@tcharding
Copy link
Copy Markdown
Member Author

Reconsider after #3848 goes in.

@tcharding
Copy link
Copy Markdown
Member Author

Closing, we are going to try using the includes/ directory to solve this problem now.

@tcharding tcharding closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-base58 PRs modifying the base58 crate C-bitcoin PRs modifying the bitcoin crate C-internals PRs modifying the internals crate C-primitives C-units PRs modifying the units crate ci doc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant