Conversation
MarijnS95
left a comment
There was a problem hiding this comment.
Nice to see gpu-allocator usable on no_std with relatively minor changes! Thanks for doing the setup work here.
Just not sure if we're happy to commit to this rather tricky list of mutually exclusive features here. Consider someone uses gpu-allocator in their library crate and sets default-features = false to make it compile with a minimal set and no_std-compliance by default. They now have to enable the hashbrown feature to get it to compile.
When some other application crate uses that library crate, and also uses gpu-allocator with std feature to get backtrace support, this will now no longer compile because those are mutually exclusive.
I've suggested a change to make the hashbrown and std features coexist.
Can you add these lints to ensure this'll be easier to maintain in the future:
#![warn(
clippy::alloc_instead_of_core,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
)]And update the CI to ensure that it tests both no_std as well as std: we can add these to the matrix in the check_msrv, test and clippy jobs.
Finally, I ended up not spending any comments on it but instead recommend you to undo a few unnecessary import reorderings with:
cargo fmt -- --config imports_granularity=Crate --config group_imports=StdExternalCrateThe output isn't ideal (you have to group visualizer mod+use back together for example) but at least the ordering is back in check: log goes separate from the std/core/alloc "standard libraries" for example.
| /// Log out every free that is being called with log level Debug, rather spammy so off by default | ||
| pub log_frees: bool, | ||
| /// Log out stack traces when either `log_allocations` or `log_frees` is enabled. | ||
| #[cfg(feature = "std")] |
There was a problem hiding this comment.
Since this is a pub struct, we should probably mark this #[non_exhaustive] to always force callers to initialize it with a default:
let settings = AllocatorDebugSettings {
log_memory_information: true,
..Default::default()
};That way, any library that uses gpu-allocator with no_std will still compile when a consumer crate enables gpu-allocator with std (which enables these fields that the library crate otherwise wouldn't have set).
There was a problem hiding this comment.
As it turns out this does not work as expected outside of the crate, because of https://rust-lang.github.io/rfcs/2008-non-exhaustive.html#functional-record-updates: it assumes that a private field might be added which cannot be set with field-record-update even if only public fields are set and the rest is provided with spread syntax (..Default::default()) 1. In other words, the only valid syntax now seems to be:
let mut settings = AllocatorDebugSettings::default();
settings.log_memory_information = true;Let me think about possible solutions and alternatives, before likely removing #[non_exhaustive] again.
Footnotes
-
I assume because of https://rust-lang.github.io/rfcs/0736-privacy-respecting-fru.html. ↩
Cargo.toml
Outdated
| thiserror = "1.0" | ||
| presser = { version = "0.3" } | ||
| log = { version = "0.4", default-feature = false } | ||
| thiserror = { version = "2.0", default-feature = false } |
There was a problem hiding this comment.
Keep thiserror at 1 for now instead of pushing this drive-by change?
There was a problem hiding this comment.
std can be disabled in thiserror since v2, but its msrv is 1.81+ dtolnay/thiserror#373.
But we can use derive_more instead, its msrv is 1.75+.
There was a problem hiding this comment.
@MarijnS95
Should we use derive_more for bumping lower MSRV?
There was a problem hiding this comment.
Hmm we still need to look into this. IIRC there was some pushback on bumping to thiserror in some of our other repos because the crate is used incredibly frequently and requires an update throughout many (of our) crates in the ecosystem.
OTOH I don't think we require them to match to compile our code, it's just a duplicate dependency we can take on in cargo-deny.
There was a problem hiding this comment.
We're committing to a slow but steady thiserror 2 upgrade now, fine to take it in via this pull request. Would it make sense to force the thiserror/std feature when gpu-allocator/std is enabled? I have not read up on the features that it provides, nor weighed the advantages of forcing the feature on versus having downstream users lack std capabilities on returned thiserror types unless they take a dependency with "std" feature on thiserror themselves.
|
Almost forgot to mention: can you please drop the
I don't think a one-off |
a22352a to
eb9e04c
Compare
|
|
c5b70f0 to
f2a6bfb
Compare
MarijnS95
left a comment
There was a problem hiding this comment.
Nice update!
Only two things remaining: the formatting of the reports is broken, please test your changes to these before pushing them. I've suggested how to fix this in one file.
The previous review contained a request to update the CI to ensure that we test both with and without these new feature combinations, that would be very helpful to prevent breakage going forward. Right now we always build with specific backends and --no-default-features, meaning neither "hashbrown" nor "std" (nor a combination) ever gets exercised properly.
Accidentally posted "Approved" instead of "Comment"
a315296 to
541e814
Compare
edaf69e to
541e814
Compare
MarijnS95
left a comment
There was a problem hiding this comment.
Nice! I trust you'll be able to follow up on the remaining CI errors so that we can merge this! Do you think support for no_std needs a nice shout-out (including how to use it with default-features = false and that "hashbrown" must be used?) in the README?
I'll meanwhile look into how far we are with a thiserror 2.0 migration in our dependency tree, that might be more useful than to switch crates.
ef44339 to
e896fab
Compare
95587a0 to
c4da9ba
Compare
0b6904c to
b0b38a9
Compare
d45044d to
6fd4a3a
Compare
|
I'm thinking of raising the MSRV unconditionally, that seems a lot less tricky to users than pretending it's |
790f7a7 to
e0a278c
Compare
|
I've squashed everything down into a single commit because our branch protection requires every individual commit to have been signed. Even if squash-merging will squash and resign the entire PR with GitHub's "web workflow" signature anyway 🤷 Since I contributed to and approve the final result, it makes sense for me to sign such a final result (but not individual commits) :) |
|
Should we go ahead and merge this? |
commit 790f7a7 Author: Marijn Suijten <marijn@traverseresearch.nl> Date: Thu Jun 12 22:13:17 2025 +0200 CI: Ensure MSRV of `std` and `no_std` are tested independently commit fdf945c Author: Marijn Suijten <marijn@traverseresearch.nl> Date: Thu Jun 12 22:10:10 2025 +0200 Test `visualizer` feature with `std` requirement separately from `no_std` commit dab3bb6 Author: Marijn Suijten <marijn@traverseresearch.nl> Date: Thu Jun 12 22:07:26 2025 +0200 README: Remove manual reflows commit 6fd4a3a Author: Marijn Suijten <marijn@traverseresearch.nl> Date: Thu Jun 12 21:43:44 2025 +0200 Revert "update `CI`" This reverts commit e896fab. commit c7e3c3c Merge: c3e2d51 0c5fc95 Author: Marijn Suijten <marijn@traverseresearch.nl> Date: Thu Jun 12 21:42:56 2025 +0200 Merge remote-tracking branch 'origin/main' into no-std-support commit c3e2d51 Author: Marijn Suijten <marijn@traverseresearch.nl> Date: Thu Jun 12 21:28:57 2025 +0200 Revert `version = ""` addition where not needed commit 477b6c5 Author: Marijn Suijten <marijn@traverseresearch.nl> Date: Thu Jun 12 21:36:43 2025 +0200 Fix greedy match that would truncate a trailing `, default-features ... "` commit b37c69f Author: Marijn Suijten <marijn@traverseresearch.nl> Date: Thu Jun 12 21:32:39 2025 +0200 release: Fix unescaped `{` (otherwise treated as repetition quantifier) commit f93b1da Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Apr 17 09:04:22 2025 +0800 update `README` commit b0b38a9 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Apr 17 08:49:37 2025 +0800 update `release.toml` commit d27a627 Merge: d73de57 642dc91 Author: CrazyboyQCD <53971641+CrazyboyQCD@users.noreply.github.com> Date: Thu Apr 3 09:05:10 2025 +0800 Merge branch 'main' into no-std-support commit d73de57 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Apr 3 08:59:50 2025 +0800 fix `CI` commit c4da9ba Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Apr 3 08:42:56 2025 +0800 add `no_std` content in `README` commit 8bdedba Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Apr 2 17:46:51 2025 +0800 fix lint commit e896fab Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Apr 2 17:44:42 2025 +0800 update `CI` commit 0ab0c88 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Apr 2 17:40:17 2025 +0800 fix lint commit 10d0742 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Apr 2 17:35:05 2025 +0800 update missed `std` usages commit 66dbf08 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Apr 2 17:21:23 2025 +0800 add todo related with storing of `format_args!` outside `format!` commit 3d962a4 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Apr 2 09:06:09 2025 +0800 keep style of compile error the same commit 4123593 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Apr 2 09:03:37 2025 +0800 update missed `std` usages commit 541e814 Author: Marijn Suijten <marijn@traverseresearch.nl> Date: Tue Apr 1 12:54:04 2025 +0200 CI: Simplify and complete `matrix` setup commit 3e453ed Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Tue Apr 1 17:59:54 2025 +0800 emit compile error when none of `std` and `hashbrown` is enabled commit 694b6ff Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Tue Apr 1 17:24:56 2025 +0800 update `CI` with `no_std` commit 742a2ce Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Tue Apr 1 17:23:55 2025 +0800 document the `hashbrown` feature in `Cargo.toml` commit 39abe59 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 27 09:41:57 2025 +0800 update `CI` for `std` environment commit 578ada0 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 27 09:37:05 2025 +0800 prefer using `hashbrown`'s collections when `std` and `hashbrown` are both enabled commit 457411a Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 27 09:30:58 2025 +0800 simplify memory leak logging commit 3e00364 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 27 09:14:16 2025 +0800 remove empty line and reorder import commit d59fe26 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 27 09:09:24 2025 +0800 restore trailing comma commit f2a6bfb Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 13 10:50:51 2025 +0800 make `std` feature conflict with `hashbrown` in compile error and gate `free_list_allocator` by feature commit 4c45a01 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 13 10:27:19 2025 +0800 reorder mod in allocator module commit d1caf98 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 13 10:17:14 2025 +0800 format backtrace ahead by feature instead of duplicated log statements commit a4d3463 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 13 09:54:11 2025 +0800 reorder imports and mods commit 51e8723 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 13 09:46:52 2025 +0800 add non_exhaustive for `AllocatorDebugSettings` for backward compatible commit 3cee15f Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 13 09:43:13 2025 +0800 fix typos in deps commit 4d7b668 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 13 09:43:01 2025 +0800 revert formatting of `Cargo.toml` commit 48be63c Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Thu Feb 13 09:35:20 2025 +0800 add clippy lints for `no_std` maintenance commit eb9e04c Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Feb 12 16:20:03 2025 +0800 replace `std::*` with `core::*` or `alloc::*` commit e3ca7fb Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Feb 12 16:19:21 2025 +0800 remove `std::backtrace::Backtrace` in `no_std` commit 8f853b0 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Feb 12 16:03:09 2025 +0800 add `no_std` feature compile error commit fbc57a3 Author: CrazyboyQCD <yzc13697716338@gmail.com> Date: Wed Feb 12 16:02:29 2025 +0800 add `default-feature = false` to some deps, `std` feature and `hashbrown`
573fb24 to
b8e07a2
Compare
no_stdsupport can be enabled by compiling with--no-default-featuresto disablestdsupport and--features hashbrownforHashcollections that are only defined instdfor internal usages in crate. For example: