-
Notifications
You must be signed in to change notification settings - Fork 39
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
Manual block encodings #636
base: master
Are you sure you want to change the base?
Conversation
Right, I think my preferred solution (for now) would be something like the following instead (similar to your proposal in #442 (comment), just with an extra trait): unsafe trait BlockEncodingHelper { // Bikeshed name
type Arguments: EncodingArguments;
type Return: EncodingReturn;
const ENCODING_CSTR: &'static CStr;
}
impl Block {
pub fn with_encoding<'f, A, R, Closure, Helper>(
_helper: Helper,
closure: Closure,
) -> Self
where
Helper: BlockEncodingHelper<Arguments = A, Return = R>,
// ...
{ ... }
}
// Usage
struct Helper;
impl BlockEncodingHelper for Helper {
type Arguments = (i32, Bool);
type Return = u8;
const ENCODING_CSTR: &'static CStr = c"whatever_the_encoding_is_I_have_not_checked_it";
}
let block = RcBlock::with_encoding(Helper, |arg1, arg2| {
if arg2.as_bool() {
arg1 as u8
} else {
0
}
}); |
Ah yes, I was suspecting something of the sort was happening behind the scenes, but did not know the exact underlying mechanism. Thanks for the link.
That seems like it could work, yes thanks. I'll try it soon and see if the promotion works in this case too. |
7bc92d7
to
f796013
Compare
Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
f796013
to
b7a47cf
Compare
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 haven't reviewed all of it yet (use GitHub's UI to request a review when you want me to do so), only saw that you're bumping MSRV, please don't do that.
I think all the examples and tests can use c"string"
without affecting MSRV, but in the places where the actual code is, you'll have to use unsafe { CStr::from_bytes_with_nul_unchecked(b"string\0") }
instead.
Yes, sorry for the notifications, I just wanted to make things work and then check that I haven't missed anything, such as adding new tests, hence why I left is as a draft.
That was also part of the things I wanted to do before formally asking for a review, sorry. 😅
|
Preeetty sure that was only
Perhaps we can just avoid using the If not, then there are ways to do the equivalent of inline |
Woops, sorry. That seems right, yes. Looking at the methods I use, I should be able to avoid any bump here, hopefully.
Probably, yes. I just wanted to avoid the "let's hope promotion works similarly in previous and future compiler versions" kind of stance, although it should be acceptable 🤞
I'll try the above first and then this if it fails somehow. Thanks for the suggestion. |
b7a47cf
to
bda07cf
Compare
In the end, the MSRV bump was indeed not necessary:
Last thing I need to do before declaring this ready to review: try to add the |
9166751
to
91a730f
Compare
Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
0d190d3
to
60689ff
Compare
…onstructors Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
* `StackBlock`'s `Clone` constraint checks: order switch it seems. * `OptionEncode` compile-time checks: small line number shift. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
Small movements it seems. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
5513ae9
to
ae5820d
Compare
ae5820d
to
c2d2088
Compare
Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
c2d2088
to
092cbcc
Compare
Alright @madsmtm, this should now be ready for a proper first review cycle! Sorry for the many CI runs, though, I just struggled endlessly with minor details. |
Hey @madsmtm!
This is an attempt to contribute to #442, by adding the ability to manually provide a block encoding to its constructor so that it sets
BLOCK_HAS_SIGNATURE
and saves the string properly.Included:
StackBlock::with_encoding
.RcBlock::with_encoding
.block2::traits::ManualBlockEncoding
is the smuggling trait.cfg(debug_assertions)
: a bit too strict for now, but can be relaxed later on by implementing a dedicated parser and equivalence checking.Cheers,
Paul.