-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add tinystr-neo to experimental/ #1508
Changes from 1 commit
8c13b98
ad88484
3044449
1361678
510c57a
73a799d
6bfbfc3
2cdeab3
347c955
601787d
d009c19
2d9e801
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 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,14 +4,12 @@ | |||||||||||||||||
|
||||||||||||||||||
#[macro_export] | ||||||||||||||||||
macro_rules! tinystr { | ||||||||||||||||||
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. Thought: We maybe don't need the macro any more. People can just use the const function constructors directly. Fewer imports and friendlier to the compiler. 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. So as mentioned in #1511 (comment) , I think it's important to give users a convenient way to call this in a const context, given that it's rare and unusual for Rust programmers to MBEs (non proc macros, like this one) are pretty friendly to the compiler; and this is going to be even smaller once I rebase over the rust update. I don't find that argument that compelling. 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. Yeah, |
||||||||||||||||||
($n:literal, $s:literal) => { | ||||||||||||||||||
({ | ||||||||||||||||||
// Force it into a const context; otherwise it may get evaluated at runtime instead. | ||||||||||||||||||
const TINYSTR_MACRO_CONST: Result<$crate::TinyAsciiStr<$n>, $crate::TinyStrError> = $crate::TinyAsciiStr::from_str($s); | ||||||||||||||||||
TINYSTR_MACRO_CONST | ||||||||||||||||||
// Note: Rust 1.57 allows panics in consts, until we update to that version we have to panic outside of the const and hope it optimizes away | ||||||||||||||||||
}).unwrap() | ||||||||||||||||||
} | ||||||||||||||||||
($n:literal, $s:literal) => {{ | ||||||||||||||||||
// Force it into a const context; otherwise it may get evaluated at runtime instead. | ||||||||||||||||||
const TINYSTR_MACRO_CONST: $crate::TinyAsciiStr<$n> = | ||||||||||||||||||
$crate::TinyAsciiStr::from_str_panicky($s); | ||||||||||||||||||
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. Suggestion: does it work if you do this?
Suggested change
or perhaps
Suggested change
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. (with the 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. No, unwrap isn't stably const 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. Not even const TINYSTR_MACRO_CONST: $crate::TinyAsciiStr<$n> =
match $crate::TinyAsciiStr::from_str($s) {
Ok(s) => s,
Err(_) => panic!("{}", $s) // Invalid tinystr
} Or, keep it the way it is. It's just that it might be nice to not have a panicky library function. 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. Yeah I didn't like that function either, moved |
||||||||||||||||||
TINYSTR_MACRO_CONST | ||||||||||||||||||
}}; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
#[cfg(test)] | ||||||||||||||||||
|
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.
note: previously we were able to use
.trailing_zeroes()
/leading_zeroes()
which are a single instruction. If rustc unrolls this loop for small N we should also be fine here, but I'm not sure if that's happening, we should bench this.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.
Yeah; this is one of the things I was wondering how we would implement efficiently. We should definitely test. I think this would be a good thing for IAI as opposed to Clippy.