-
Notifications
You must be signed in to change notification settings - Fork 856
Space efficient custom_panic
#3951
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,6 +279,44 @@ macro_rules! custom_panic_default { | |
| }; | ||
| } | ||
|
|
||
| /// This is a more space efficient implementation of custom panic. | ||
| /// It is about 1kb in size and depends on the unstable feature `panic_info_message`, | ||
| /// which is going to be stabilized in Rust 1.84. | ||
| /// | ||
| /// It works just like the default custom panic, except that dynamic generated error | ||
| /// messages are not shown. For instance, trying to access an index out of bounds of a vector | ||
| /// would give us `index Y is out of bounds for length X`. As the length is only know at runtime | ||
| /// time, this message is elided. | ||
| /// | ||
| /// All messages known at compile time are correctly displayed, e.g. `called unwrap in a None`, | ||
| /// file names, line and column numbers. | ||
| #[macro_export] | ||
| macro_rules! custom_panic_space_efficient { | ||
| () => { | ||
| #[cfg(all(not(feature = "custom-panic"), target_os = "solana"))] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to remove the "gate" on the Removing the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My idea is that the space efficient implementation will replace the existing one, once we have Rust 1.84 or higher in the platform tools. What do you think of this? |
||
| #[no_mangle] | ||
| fn custom_panic(info: &core::panic::PanicInfo<'_>) { | ||
| if let Some(Some(mm)) = info.message().map(|mes| mes.as_str()) { | ||
| let mes = mm.as_bytes(); | ||
| unsafe { | ||
| solana_program::syscalls::sol_log_(mes.as_ptr(), mes.len() as u64); | ||
| } | ||
| } | ||
|
|
||
| if let Some(loc) = info.location() { | ||
| unsafe { | ||
| solana_program::syscalls::sol_panic_( | ||
| loc.file().as_ptr(), | ||
| loc.file().len() as u64, | ||
| loc.line() as u64, | ||
| loc.column() as u64, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add some test programs with this implementation. I'm looking for early feedback now. |
||
| /// The bump allocator used as the default rust heap when running programs. | ||
| pub struct BumpAllocator { | ||
| pub start: usize, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not yet replacing the exiting custom panic, because this new one requires Rust 1.84, which is going to be the next toolchain upgrade.