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

Replace backtrace crate with stabilized std::backtrace implementation #186

Merged
merged 3 commits into from
Nov 7, 2023

Conversation

MarijnS95
Copy link
Member

@MarijnS95 MarijnS95 commented Nov 2, 2023

Sticking to my promise of updating and submitting this old branch in #183.

Fixes #183 (by no longer using the backrace/cc crate);
Fixes #184 (the old approach from that branch).


Rust 1.65 stabilized std::backtrace::Backtrace, which we can use in place of the backtrace crate to reduce our dependency stack.

Normally Backtrace::capture() would listen to the RUST_BACKTRACE and RUST_LIB_BACKTRACE environment variables, but this is unsuitable for us as capturing backtraces is configured via boolean debug feature flags in the AllocatorDebugSettings struct. Fortunately Backtrace::force_capture() exists which circumvents these env var checks and always returns a backtrace, and is hence used in the codebase here.

Unfortuantely the type no longer implements Clone like backtrace::Backtrace, requiring us to wrap it in an Arc (because most of our types are thread-safe) to clone the Backtrace around various (sub)allocations and statistics reports.

@Jasper-Bekkers
Copy link
Member

I'm not comfortable having the stack trace collection of this crate be dependent on a rust specific environment variable. This is a feature of this crate and should thus be controlled by us / users of this crate directly from code.

@MarijnS95
Copy link
Member Author

MarijnS95 commented Nov 2, 2023

@Jasper-Bekkers the comment exactly explains that that is the reason that Backtrace::force_capture() is used over Backtrace::capture(), because the former ignores Rust-specific environment variables. I see now that that comment wasn't super clear, so I've completely rewritten that paragraph, thanks for highlighting this 👍

@stefnotch stefnotch mentioned this pull request Nov 2, 2023
Cargo.toml Show resolved Hide resolved
Copy link

@stefnotch stefnotch left a comment

Choose a reason for hiding this comment

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

Awesome, thank you for this proper migration to Rust's backtrace. I'll definitely celebrate having slightly fewer dependencies in my apps :)

…tion

Rust 1.65 [stabilized `std::backtrace::Backtrace`], which we can use in
place of the `backtrace` crate to reduce our dependency stack.

Normally `Backtrace::capture()` would listen to the `RUST_BACKTRACE`
and `RUST_LIB_BACKTRACE` environment variables, but this is unsuitable
for us as capturing backtraces is configured via boolean debug
feature flags in the `AllocatorDebugSettings` struct.  Fortunately
`Backtrace::force_capture()` exists which circumvents these env var
checks and always returns a backtrace, and is hence used in the codebase
here.

Unfortuantely the type no longer implements `Clone` like
`backtrace::Backtrace`, requiring us to wrap it in an `Arc` (because
most of our types are thread-safe) to clone the `Backtrace` around
various (sub)allocations and statistics reports.

[stabilized `std::backtrace::Backtrace`]: https://blog.rust-lang.org/2022/11/03/Rust-1.65.0.html#stabilized-apis
@MarijnS95 MarijnS95 merged commit e45e25a into main Nov 7, 2023
22 checks passed
@MarijnS95 MarijnS95 deleted the std-backtrace branch November 7, 2023 08:59
@MarijnS95 MarijnS95 mentioned this pull request Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants