profile
viewpoint
Hero Bird Robbepop https://robbepop.github.io 🦀Rustacean with C/C++ origins - Enthusiastic about WebAssembly, compilers & SAT solving.

paritytech/ink 277

Parity's ink to write smart contracts

Robbepop/apint 18

Arbitrary precision integers library.

paritytech/scale-info 10

Info about SCALE encodable Rust types

paritytech/canvas-node 8

Canvas Contracts Chain - Node Implementation

Robbepop/dynarray 7

Adjusted implementation of std::experimental::dynarray without stack allocation.

paritytech/canvas-ui 4

Basic Polkadot/Substrate UI for interacting with a node. This is the main user-facing application, allowing access to all features available on Substrate chains.

Robbepop/clpp 4

A thin header-only wrapper around OpenCL 2.0+ for modern and highlevel C++.

paritytech/ink-workshop 3

Hot to setup ink! 3.0 and Canvas Node for the ink! 3.0 workshop at Sub0 2020.

Robbepop/bucket_vec 3

A vector-like collection that guarantees not to move its internal elements.

pull request commentrust-embedded/cortex-m

[WIP] use modular_bitfield crate

CI for Rust 1.38 seems to fail because modular_bitfield's macro hygiene expands to those re-exports that have been introduced in Rust 1.43. Please tell me how big of an issue this is and we might find a solution for you.

Robbepop

comment created time in 11 hours

PR opened rust-embedded/cortex-m

[WIP] use modular_bitfield crate

This experimental PR simply replaced the bitfield! macro from the bitfield crate with the #[bitfield] attribute macro of the modular_bitfield crate. I am the author of the latter crate and wanted to know if you are interested in using it. Some benchmarks I have conducted earlier shows that both crates perform pretty much equally. There was just one benchmark where apparently modular_bitfield performed roughly 25% better for a setter case.

Generally the modular_bitfield crate is actively maintained and just received lots of new features. Also it is probably a bit more convenient to use as you might notice from the diff. Finally, by introducing the modular_bitfield to the cmse.rs file I noticed that the mregion and mvalid fields are unused. Is this intentional?

+25 -24

0 comment

2 changed files

pr created time in 11 hours

create barnchRobbepop/cortex-m

branch : robin-use-modular-bitfield

created branch time in 11 hours

fork Robbepop/cortex-m

Low level access to Cortex-M processors

fork in 11 hours

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha 468b1b152821417d61231f8004d3f370b1f499ce

fix broken inter doc links

view details

push time in 11 hours

issue closedRobbepop/modular-bitfield

Deprecate new constructor for default impl

Currently the #[bitfield] proc. macro generates a new constructor that initializes all bits of the bitfield struct to 0. Unfortunately this may invoke undefined behaviour for bit specifiers that do not allow for the zero bit pattern. This is especially a problem with non-powers-of-two bit specifier enums. This is not checked by the new constructor and what we want instead is a default constructor that initializes all the fields to their default values if available. Besides that we might want to generate some builder-pattern-like or convoluted new constructor to avoid this problem.

Another idea is to make the new constructor only available via where bounds if all fields support the zero bit pattern when this is known at compile time. I think this solution (if it can be worked) would be particularly nice since the new constructor is really efficient and on top of that a const fn that would probably not yet be possible with any other safer constructor type.

closed time in 11 hours

Robbepop

issue commentRobbepop/modular-bitfield

Deprecate new constructor for default impl

Closed since due to the new design new constructor initializing all bits to 0 is totally fine and no replacement is needed right now.

Robbepop

comment created time in 11 hours

release Robbepop/modular-bitfield

v0.10.0

released time in 11 hours

created tagRobbepop/modular-bitfield

tagv0.10.0

Macro to generate bitfields for structs that allow for modular use of enums.

created time in 11 hours

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha 6f579bff0d6806e361a4094825fe2659fc22eefa

bump version 0.9.0 -> 0.10.0

view details

push time in 11 hours

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha 191f013c42c43dd63a3252884cbdb9d67572857d

add release notes for #[derive(Debug)] support

view details

Robin Freyler

commit sha b324901f2c08a38130297a122944c3a7886309b6

[impl] improve docs for #[bitfield] macro

view details

Robin Freyler

commit sha b95363daa97e04b8b487a82aef648af56a861330

[impl] add more docs to the #[bitfield] macro

view details

Robin Freyler

commit sha 7fb7c5273d0e4a052779aa37b457326d9f722e4a

[impl] remove old #[bitfield] docs

view details

push time in 12 hours

pull request commentRobbepop/modular-bitfield

Implement #[derive(Debug)] expansion for #[bitfield]

Oh sorry! I meant to wrap it up but was busy. Thank you.

No problem, I was just a bit too impatient to get this in. :upside_down_face: Thanks for your commitment!

Robbepop

comment created time in 14 hours

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha be3ea16601b63e040bfc14fd0df7dc7a66135841

fix formatting issues in readme

view details

Robin Freyler

commit sha 3b521f81b13ef9e2e7f46eb8210961df44402b6d

Merge branch 'master' of github.com:Robbepop/modular-bitfield

view details

push time in 15 hours

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha cb5cb5e07c656d1793de7c2ee01c4dfd13a5c550

fix formatting issues in readme

view details

jam1garner

commit sha 9cacf18c743ab38da0c507e97d2e7e28699290f6

Handle deriving fmt::Debug impl for bitfields instead of leaving it to the std derive

view details

jam1garner

commit sha 8e9c48f4a5364da9a33c88f64dc255288de479ca

Remove unneeded String conversions

view details

Hero Bird

commit sha 391b6b58534033a77f39f68a9d22e1954a69317c

fix some hygiene problems in the expanded code

view details

Hero Bird

commit sha c8477e5e48ab22d32f17e315d01978f9acb00e50

use syn::Path::is_ident

view details

Hero Bird

commit sha ce6e35c58782fdc4887929479c28c1b1a03054c4

use syn::Path::is_ident (2)

view details

Robin Freyler

commit sha 32964101c42612bdc886a1a658bb95d6e38631b9

[tests] add new #[derive(Debug)] test

view details

Robin Freyler

commit sha a6a164d5167f8384c7e340c51eb88004204b7ee1

[impl] fully integrate the new #[derive(Debug)] feature to new architecture

view details

Robin Freyler

commit sha c02396dab863b401d6bb71ab4e9fdab5da154a46

[tests] add another #[derive(Debug)] test

view details

Robin Freyler

commit sha 226bdbf0cbe55dbc6cc19b43d0d9dcbb1a28e8f8

add #[inline] to generated From impls for #[repr(uN)]

view details

Robin Freyler

commit sha 2e57defbf9e59b78f9aac53e0fd1b2519d8d20ce

[tests] add some more #[derive(Debug)] tests

view details

Robin Freyler

commit sha 8604a7ef8cf992c6725a5de13beb3a5483a181e2

[tests] add failure tests for #[derive(Debug)]

view details

Robin Freyler

commit sha e0b14ed8b7436f2557dae9d4f6e7902043f286be

[tests] add another #[derive(Debug)] test

view details

Robin Freyler

commit sha b2621981c3cf7a7fc9e2fa45f81ff39dceac7f14

[impl] apply clippy suggestion

view details

push time in 15 hours

PR merged Robbepop/modular-bitfield

Implement #[derive(Debug)] expansion for #[bitfield]

Builds on top of https://github.com/Robbepop/modular-bitfield/pull/32. Closes https://github.com/Robbepop/modular-bitfield/issues/31.

+371 -50

0 comment

13 changed files

Robbepop

pr closed time in 15 hours

issue closedRobbepop/modular-bitfield

Provide a way to derive a sensible Debug impl

Currently, the behavior results in the following:

            QuickDir {
                bytes: [
                    111,
                    242,
                    94,
                    29,
                    5,
                    111,
                    0,
                    0,
                    44,
                    10,
                    0,
                    0,
                ],
            },

Since the attribute macro runs before the derive happens, it should be possible to check for #[derive(Debug)], remove Debug from the list of traits to be derived, and manually derive Debug ourselves. This would allow for Debug to look the way it would if you didn't use #[bitfield].

I'm willing to do an implementation, just want to make sure this fits in with the design goals before starting work on it.

closed time in 15 hours

jam1garner

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha 2d168525737b523bdf3b8799a899491e6b33bfa6

[impl] apply clippy suggestion

view details

push time in 15 hours

pull request commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

I have created the follow-up PR here: https://github.com/Robbepop/modular-bitfield/pull/39 @jam1garner

jam1garner

comment created time in 15 hours

PR opened Robbepop/modular-bitfield

Implement #[derive(Debug)] expansion for #[bitfield]

Builds on top of https://github.com/Robbepop/modular-bitfield/pull/32. Closes https://github.com/Robbepop/modular-bitfield/issues/31.

+373 -50

0 comment

13 changed files

pr created time in 15 hours

create barnchRobbepop/modular-bitfield

branch : robin-jam1garner-impl-debug

created branch time in 15 hours

Pull request review commentparitytech/ink

Add example which uses ext_transfer + ext_terminate

 pub trait TypedEnvBackend: EnvBackend {     /// # Note     ///     /// For more details visit: [`ink_env::terminate_contract`]-    fn terminate_contract<T>(&mut self, beneficiary: T::AccountId) -> !+    fn terminate_contract<T>(&mut self, beneficiary: T::AccountId) -> Result<()>

You example contract is fine to cover both APIs. However, I think for transferred_balance we could also create a simple alternative example contract similar to what I did in the release notes of v3.0.0-rc1.

cmichi

comment created time in 17 hours

Pull request review commentparitytech/ink

Add example which uses ext_transfer + ext_terminate

 pub trait TypedEnvBackend: EnvBackend {     /// # Note     ///     /// For more details visit: [`ink_env::terminate_contract`]-    fn terminate_contract<T>(&mut self, beneficiary: T::AccountId) -> !+    fn terminate_contract<T>(&mut self, beneficiary: T::AccountId) -> Result<()>

This means that for example contracts we cannot really off-chain test them properly if they make use of such behavior.

cmichi

comment created time in 17 hours

Pull request review commentparitytech/ink

Add example which uses ext_transfer + ext_terminate

 pub trait TypedEnvBackend: EnvBackend {     /// # Note     ///     /// For more details visit: [`ink_env::terminate_contract`]-    fn terminate_contract<T>(&mut self, beneficiary: T::AccountId) -> !+    fn terminate_contract<T>(&mut self, beneficiary: T::AccountId) -> Result<()>

I guess you changed this API to make it possible to deliver an off-chain implementation of it. However, as you already noticed our off-chain environment is kind of limited and the inability to do proper contract terminations is one. Instead of adjusting useful interfaces to an non useful off-chain implementation we should instead strife for improving the off-chain environment so that it is able to handle those things if possible.

cmichi

comment created time in 17 hours

PullRequestReviewEvent
PullRequestReviewEvent

issue commentparitytech/canvas-ui

Maximum call stack size exceeded error

Can you post us your .wasm and metadata files please?

JeremyConnor

comment created time in 18 hours

PR closed Robbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

Implementation for my suggestion from #31.

+124 -2

4 comments

1 changed file

jam1garner

pr closed time in 18 hours

pull request commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

I am closing this now since I pulled your commits over to some local branch in order to integrate your derive implementation to the new config architecture. Thanks for the PR and work! Your commits are going to be included in the commit log to honor your work. :tada:

jam1garner

comment created time in 18 hours

PullRequestReviewEvent

push eventjam1garner/modular-bitfield

Hero Bird

commit sha 7eb2931ce6848fe0cd795c3b70e9f2bde6fe646b

use syn::Path::is_ident (2)

view details

push time in 20 hours

push eventjam1garner/modular-bitfield

Hero Bird

commit sha 7e33fb2bb30a8a44f216df518156dc39464f26d9

use syn::Path::is_ident

view details

push time in 20 hours

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {     /// amount of bytes to compactly store the information of all its bit fields.     fn generate_struct(&self) -> TokenStream2 {         let span = self.item_struct.span();-        let attrs = &self.item_struct.attrs;+        let attrs = self.get_attrs_no_debug();         let vis = &self.item_struct.vis;         let ident = &self.item_struct.ident;         let size = self.generate_bitfield_size();         let next_divisible_by_8 = Self::next_divisible_by_8(&size);         quote_spanned!(span=>             #( #attrs )*             #[repr(transparent)]-            #[allow(clippy::identity_op)]+            #[allow(clippy::identity_op, unused_attributes)]             #vis struct #ident             {                 bytes: [::core::primitive::u8; #next_divisible_by_8 / 8usize],             }         )     } +    /// Get whether or not `derive(Debug)` is included in the attributes+    fn should_derive_debug(&self) -> bool {+        self.item_struct.attrs.iter().any(|attr| {+            match attr.parse_meta() {+                Ok(syn::Meta::List(meta_list)) => {+                    let is_derive = meta_list+                        .path+                        .get_ident()+                        .map(|ident| *ident == "derive")+                        .unwrap_or(false);++                    if is_derive {+                        meta_list.nested.into_iter().any(|nested| {+                            match nested {+                                syn::NestedMeta::Meta(syn::Meta::Path(path)) => {+                                    path.get_ident()+                                        .map(|ident| *ident == "Debug")+                                        .unwrap_or(false)+                                }+                                _ => false,+                            }+                        })+                    } else {+                        false+                    }+                }+                _ => false,+            }+        })+    }++    /// Get the attributes with `Debug` filtered out of any present derives.+    fn get_attrs_no_debug<'a>(&'a self) -> impl Iterator<Item = TokenStream2> + 'a {+        self.item_struct.attrs.iter().map(|attr| {+            match attr.parse_meta() {+                Ok(syn::Meta::List(mut meta_list)) => {+                    let is_derive = meta_list+                        .path+                        .get_ident()+                        .map(|ident| *ident == "derive")+                        .unwrap_or(false);
                    let is_derive = meta_list.path.is_ident("derive");
jam1garner

comment created time in 20 hours

PullRequestReviewEvent

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {     /// amount of bytes to compactly store the information of all its bit fields.     fn generate_struct(&self) -> TokenStream2 {         let span = self.item_struct.span();-        let attrs = &self.item_struct.attrs;+        let attrs = self.get_attrs_no_debug();         let vis = &self.item_struct.vis;         let ident = &self.item_struct.ident;         let size = self.generate_bitfield_size();         let next_divisible_by_8 = Self::next_divisible_by_8(&size);         quote_spanned!(span=>             #( #attrs )*             #[repr(transparent)]-            #[allow(clippy::identity_op)]+            #[allow(clippy::identity_op, unused_attributes)]             #vis struct #ident             {                 bytes: [::core::primitive::u8; #next_divisible_by_8 / 8usize],             }         )     } +    /// Get whether or not `derive(Debug)` is included in the attributes+    fn should_derive_debug(&self) -> bool {+        self.item_struct.attrs.iter().any(|attr| {+            match attr.parse_meta() {+                Ok(syn::Meta::List(meta_list)) => {+                    let is_derive = meta_list+                        .path+                        .get_ident()+                        .map(|ident| *ident == "derive")+                        .unwrap_or(false);++                    if is_derive {+                        meta_list.nested.into_iter().any(|nested| {+                            match nested {+                                syn::NestedMeta::Meta(syn::Meta::Path(path)) => {+                                    path.get_ident()+                                        .map(|ident| *ident == "Debug")+                                        .unwrap_or(false)+                                }+                                _ => false,+                            }+                        })+                    } else {+                        false+                    }+                }+                _ => false,+            }+        })+    }++    /// Get the attributes with `Debug` filtered out of any present derives.+    fn get_attrs_no_debug<'a>(&'a self) -> impl Iterator<Item = TokenStream2> + 'a {+        self.item_struct.attrs.iter().map(|attr| {+            match attr.parse_meta() {+                Ok(syn::Meta::List(mut meta_list)) => {+                    let is_derive = meta_list+                        .path+                        .get_ident()+                        .map(|ident| *ident == "derive")+                        .unwrap_or(false);++                    if is_derive {+                        meta_list.nested = meta_list+                            .nested+                            .into_iter()+                            .filter(|nested| {+                                match nested {+                                    syn::NestedMeta::Meta(syn::Meta::Path(path)) => {+                                        path.get_ident()+                                            .map(|ident| *ident != "Debug")+                                            .unwrap_or(true)
                                        path.is_ident("Debug")
jam1garner

comment created time in 20 hours

PullRequestReviewEvent

push eventjam1garner/modular-bitfield

Hero Bird

commit sha 62768bb2277031ab31e783ec1bd32ff776006dfc

fix some hygiene problems in the expanded code

view details

push time in 20 hours

issue openedparitytech/cargo-contract

Build artifacts should be put under `target/ink` directory

Currently cargo-contract builds under target which can interfere with other tools that do the same. The established common rule for tools like cargo-contract is to put every artifact under target/<name> and we should do this, too.

created time in a day

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha 8f0c57b71778fe1d9a6668adb3978a77e4403081

add proper docs and examples to BitfieldSpecifier derive macro

view details

Robin Freyler

commit sha c91cb8bcb5b4f97fdf41b9d4857f3637bc8e8676

move BitfieldSpecifier docs to impl

view details

Robin Freyler

commit sha d2cbc17f19bc7e5059f07fdc34aab3f64fc78c8f

restructure imports

view details

Robin Freyler

commit sha 416544f42b7a6bfa1b1e43b6356004f56bd5818d

make readme note about unsafe code more precise

view details

push time in a day

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha fd9767cc33f9d2e9ef54eeb91953b088069dd34f

add preliminary release notes for 0.10.0

view details

Robin Freyler

commit sha 7d55b6118cd5d1c698fcce8df5478335a27f9833

add more release notes for 0.10.0

view details

push time in a day

push eventRobbepop/modular-bitfield

Hero Bird

commit sha 15fb13bcc1422ab8d129d3bc1ce10a571ce45bff

Implements #[repr(uN)] for #[bitfield] structs (#38) * [impl] move Config into its own file Also implement initial structures for it to support #[repr(uN)] attribute. * [tests] add some tests for #[repr(uN)] attribute support * apply rustfmt * [tests] add expected failure test outputs * [impl] add retained attributes to config * [impl] add initial impl to extract bitfield #[repr(..)] attributes * [impl] remove conditional Repr (not needed) The cfg_attr attributes are resolved before macro expansion takes place. * [tests] update repr tests * [impl] generated as_bytes renamed to into_bytes and returns by value now * [impl] bitfield structs no longer implicitly are #[repr(transparent)] Users may now decide if they want that. * [tests] add some more tests and expected test outputs * add initial implementation for bitfield #[repr(uN)] * [tests] move unfilled test up * apply rustfmt * [tests] update byte conversion test * apply clippy suggestions * apply rustfmt

view details

push time in 2 days

PR merged Robbepop/modular-bitfield

Implements #[repr(uN)] for #[bitfield] structs

Closes https://github.com/Robbepop/modular-bitfield/issues/33.

+590 -135

0 comment

29 changed files

Robbepop

pr closed time in 2 days

issue closedRobbepop/modular-bitfield

Add #[repr = uN] annotation support for #[bitfield]

When given a #[bitfield] struct with a #[repr = uN], e.g. #[repr = u32] attribute the #[bitfield] macro shall make sure that the generated bitfield struct respects the bitwidth of the uN, e.g. 8 bits for u8, 16 bits for u16, etc.

Also it shall generate From<uN> and From<BitfieldStruct> for uN implementations. Obviously having #[repr(uN)] also changes the underlying representation of the bitfield type to uN.

Example

#[bitfield]
#[repr(u32)]
struct TtResp {
    mregion: u8,
    sregion: u8, 
    mrvalid: bool,
    srvalid: bool,
    r: bool,
    rw: bool,
    nsr: bool,
    nsrw: bool,
    s: bool,
    irvalid: bool,
    iregion: u8,
}

This allows the user to only conditionally have the repr(u32) effects taken place using cfg_attr:

#[bitfield]
#[cfg_attr(test, repr(u32))]
struct TtResp {
    mregion: u8,
    sregion: u8, 
    mrvalid: bool,
    srvalid: bool,
    r: bool,
    rw: bool,
    nsr: bool,
    nsrw: bool,
    s: bool,
    irvalid: bool,
    iregion: u8,
}

closed time in 2 days

Robbepop

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha c9e7265087b3a2c25dd2e698ee39139bac2e6df4

apply rustfmt

view details

push time in 2 days

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha cb528636c70b5c6e955bb36c74747348b35c54ae

apply clippy suggestions

view details

push time in 2 days

pull request commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

For inspiration on how to do the checks and extractions for attributes on the #[bitfield] struct and re-expansions take a look at: https://github.com/Robbepop/modular-bitfield/blob/robin-implement-repr/impl/src/bitfield.rs#L121

jam1garner

comment created time in 2 days

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {     /// amount of bytes to compactly store the information of all its bit fields.     fn generate_struct(&self) -> TokenStream2 {         let span = self.item_struct.span();-        let attrs = &self.item_struct.attrs;+        let attrs = self.get_attrs_no_debug();         let vis = &self.item_struct.vis;         let ident = &self.item_struct.ident;         let size = self.generate_bitfield_size();         let next_divisible_by_8 = Self::next_divisible_by_8(&size);         quote_spanned!(span=>             #( #attrs )*             #[repr(transparent)]-            #[allow(clippy::identity_op)]+            #[allow(clippy::identity_op, unused_attributes)]             #vis struct #ident             {                 bytes: [::core::primitive::u8; #next_divisible_by_8 / 8usize],             }         )     } +    /// Get whether or not `derive(Debug)` is included in the attributes+    fn should_derive_debug(&self) -> bool {

While implementing this in my own I found out that the Rust compiler already handles this for us. So nothing needs to be done for cfg_attr anywhere fortunately. :) See also: https://github.com/Robbepop/modular-bitfield/pull/38

jam1garner

comment created time in 2 days

PullRequestReviewEvent

PR opened Robbepop/modular-bitfield

Implements #[repr(uN)] for #[bitfield] structs

Closes https://github.com/Robbepop/modular-bitfield/issues/33.

+592 -135

0 comment

29 changed files

pr created time in 2 days

create barnchRobbepop/modular-bitfield

branch : robin-implement-repr

created branch time in 2 days

issue commentparitytech/cargo-contract

Fail the build if wasm-opt not installed

I heavily lean towards the longer, more disgusting --skip-wasm-optimizations since we really don't want to bring any additional comfort to this decision.

ascjones

comment created time in 2 days

startedbytecodealliance/wasm-interface-types

started time in 2 days

issue closedRobbepop/modular-bitfield

Add `filled: bool` parameter to #[bitfield] proc. macro

The proposed filled: bool parameter for the #[bitfield] proc. macro allows to have bitfields with bit widths that are not divisible by 8 and therefore might contain invalid bit patterns that are inaccessible from the outside. E.g. creating a #[bitfield(filled = false)] type with only 5 bits will leave 3 bits completely undefined.

For those #[bitfield] structs we no longer can define the byte conversion routines as infallible operations. Instead they need to return Result and check whether the undefined bits are populated.

Not break the world

In this vein we will declare #[bitfield(specifier = true)] structs to be implicitly filled = false with the same effects. Having #[bitfield(specifier = true, filled = true)] is only valid in case the bitfield struct has a bit width that is divisible by 8.

For a future release we might rethink this approach and instead no longer make #[bitfield(specifier = true)] implicitly be filled = false with all the implied consequences.

closed time in 2 days

Robbepop

issue commentRobbepop/modular-bitfield

Add `filled: bool` parameter to #[bitfield] proc. macro

Implemented in https://github.com/Robbepop/modular-bitfield/pull/37. Closed.

Robbepop

comment created time in 2 days

push eventRobbepop/modular-bitfield

Hero Bird

commit sha 3ecdaf2580200a3ac285a42cc0753211984eb417

Implement `filled: bool` #[bitfield] parameter (#37) * [tests] add tests for `filled: bool` #[bitfield] parameter * [impl] return error upon encountering an unknown parameter * [impl] add some missing docs * [tests] add some expected failure outputs for the new failing tests * [impl] add handling for the new `filled` #[bitfield] parameter * fix bug with #[bitfield(specifier = true)] and non power-of-two bit widths * [impl] make check multiple-of-8 enabled by new `filled` parameter * implement generation of checks for either filled or unfilled * [tests] update expected failure test outputs * fix doc tests and add another * [tests] adjust some tests to new default with filled parameter * [tests] add test to test from_bytes for unfilled bitfields * [impl] change from_bytes impl for unfilled bitfields to return Result * apply rustfmt * apply rustfmt #2 * [tests] fix expected failing UI test output

view details

push time in 2 days

PR merged Robbepop/modular-bitfield

Implement `filled: bool` #[bitfield] parameter

Implements: https://github.com/Robbepop/modular-bitfield/issues/35

+380 -45

0 comment

25 changed files

Robbepop

pr closed time in 2 days

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha 1bf86f65daf6ef653e78f5be24bfc7f0eb306561

[tests] fix expected failing UI test output

view details

push time in 2 days

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha 9bfe8cbe5975bddfb0e1052c82acf991f573188e

apply rustfmt #2

view details

push time in 2 days

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha 4d4131287dd3435b8049801bd76c302adfce9223

apply rustfmt

view details

push time in 2 days

PR opened Robbepop/modular-bitfield

Implement `filled: bool` #[bitfield] parameter

Implements: https://github.com/Robbepop/modular-bitfield/issues/35

+382 -43

0 comment

25 changed files

pr created time in 2 days

create barnchRobbepop/modular-bitfield

branch : robin-implement-fill

created branch time in 2 days

PullRequestReviewEvent
PullRequestReviewEvent

push eventRobbepop/modular-bitfield

Hero Bird

commit sha 7e39c84a0b4c870512367fe47a6f7f163c88b713

Implement `bytes = N` parameter for #[bitfield] (#36) * [tests] write tests for bytes=N #[bitfield] parameter * [tests] fix test case assertions * [tests] add some new failure tests for bytes parameter * [impl] implement bytes parameter parsing and checking * [tests] add test for duplicate bytes parameter * [impl] improve span for duplicate bytes parameter * [tests] add expected failure output for tests #33 and #34 * add implementation of new bytes=N check * [tests] move bytes=N tests into their own directory * [impl] apply rustfmt * add impl sub-crate to workspace of modular_bitfield crate * adjust GitHub actions CI to workspace

view details

push time in 3 days

PR merged Robbepop/modular-bitfield

Implement `bytes = N` parameter for #[bitfield]

Closes https://github.com/Robbepop/modular-bitfield/issues/34 .

+256 -30

0 comment

19 changed files

Robbepop

pr closed time in 3 days

issue closedRobbepop/modular-bitfield

Add `bytes = N` parameter to the `#[bitfield]` macro

For checking whether a #[bitfield] struct is generated to be exactly N bytes big we could add a bytes = N parameter to the #[bitfield] proc. macro. For example for N = 32 a bitfield struct with a bid width of 25 up to 32 bits is going to be valid.

Example

#[bitfield(bytes = 4)]
struct TtResp {
    mregion: u8,
    sregion: u8, 
    mrvalid: bool,
    srvalid: bool,
    r: bool,
    rw: bool,
    nsr: bool,
    nsrw: bool,
    s: bool,
    irvalid: bool,
    iregion: u8,
}

closed time in 3 days

Robbepop

push eventRobbepop/modular-bitfield

Robin Freyler

commit sha 826390cc5fe3d53632619afb65273aab018e8447

[impl] apply rustfmt

view details

Robin Freyler

commit sha 22f8d0703d139f0289441ddcf9dbef3dd40db5cf

add impl sub-crate to workspace of modular_bitfield crate

view details

Robin Freyler

commit sha 46d396186944dee85a7c97f6e0e7fe09d8f5ae36

adjust GitHub actions CI to workspace

view details

push time in 3 days

PR opened Robbepop/modular-bitfield

Implement `bytes = N` parameter for #[bitfield]

Closes https://github.com/Robbepop/modular-bitfield/issues/34 .

+238 -28

0 comment

18 changed files

pr created time in 3 days

create barnchRobbepop/modular-bitfield

branch : robin-implement-bytes

created branch time in 3 days

issue openedRobbepop/modular-bitfield

Add `filled: bool` parameter to #[bitfield] proc. macro

The proposed filled: bool parameter for the #[bitfield] proc. macro allows to have bitfields with bit widths that are not divisible by 8 and therefore might contain invalid bit patterns that are inaccessible from the outside. E.g. creating a #[bitfield(filled = false)] type with only 5 bits will leave 3 bits completely undefined.

For those #[bitfield] structs we no longer can define the byte conversion routines as infallible operations. Instead they need to return Result and check whether the undefined bits are populated.

In this vein we will declare #[bitfield(specifier = true)] structs to be implicitly filled = false with the same effects. Having #[bitfield(specifier = true, filled = true)] is only valid in case the bitfield struct has a bit width that is divisible by 8.

created time in 3 days

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {     /// amount of bytes to compactly store the information of all its bit fields.     fn generate_struct(&self) -> TokenStream2 {         let span = self.item_struct.span();-        let attrs = &self.item_struct.attrs;+        let attrs = self.get_attrs_no_debug();         let vis = &self.item_struct.vis;         let ident = &self.item_struct.ident;         let size = self.generate_bitfield_size();         let next_divisible_by_8 = Self::next_divisible_by_8(&size);         quote_spanned!(span=>             #( #attrs )*             #[repr(transparent)]-            #[allow(clippy::identity_op)]+            #[allow(clippy::identity_op, unused_attributes)]             #vis struct #ident             {                 bytes: [::core::primitive::u8; #next_divisible_by_8 / 8usize],             }         )     } +    /// Get whether or not `derive(Debug)` is included in the attributes+    fn should_derive_debug(&self) -> bool {+        self.item_struct.attrs.iter().any(|attr| {+            match attr.parse_meta() {+                Ok(syn::Meta::List(meta_list)) => {+                    let is_derive = meta_list+                        .path+                        .get_ident()+                        .map(|ident| *ident == "derive")+                        .unwrap_or(false);++                    if is_derive {+                        meta_list.nested.into_iter().any(|nested| {+                            match nested {+                                syn::NestedMeta::Meta(syn::Meta::Path(path)) => {+                                    path.get_ident()+                                        .map(|ident| *ident == "Debug")+                                        .unwrap_or(false)+                                }+                                _ => false,+                            }+                        })+                    } else {+                        false+                    }+                }+                _ => false,+            }+        })+    }++    /// Get the attributes with `Debug` filtered out of any present derives.+    fn get_attrs_no_debug<'a>(&'a self) -> impl Iterator<Item = TokenStream2> + 'a {+        self.item_struct.attrs.iter().map(|attr| {+            match attr.parse_meta() {+                Ok(syn::Meta::List(mut meta_list)) => {+                    let is_derive = meta_list+                        .path+                        .get_ident()+                        .map(|ident| *ident == "derive")+                        .unwrap_or(false);

Should use https://docs.rs/syn/0.15.44/syn/struct.Path.html#method.is_ident instead.

jam1garner

comment created time in 3 days

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {     /// amount of bytes to compactly store the information of all its bit fields.     fn generate_struct(&self) -> TokenStream2 {         let span = self.item_struct.span();-        let attrs = &self.item_struct.attrs;+        let attrs = self.get_attrs_no_debug();         let vis = &self.item_struct.vis;         let ident = &self.item_struct.ident;         let size = self.generate_bitfield_size();         let next_divisible_by_8 = Self::next_divisible_by_8(&size);         quote_spanned!(span=>             #( #attrs )*             #[repr(transparent)]-            #[allow(clippy::identity_op)]+            #[allow(clippy::identity_op, unused_attributes)]             #vis struct #ident             {                 bytes: [::core::primitive::u8; #next_divisible_by_8 / 8usize],             }         )     } +    /// Get whether or not `derive(Debug)` is included in the attributes+    fn should_derive_debug(&self) -> bool {+        self.item_struct.attrs.iter().any(|attr| {+            match attr.parse_meta() {+                Ok(syn::Meta::List(meta_list)) => {+                    let is_derive = meta_list+                        .path+                        .get_ident()+                        .map(|ident| *ident == "derive")+                        .unwrap_or(false);++                    if is_derive {+                        meta_list.nested.into_iter().any(|nested| {+                            match nested {+                                syn::NestedMeta::Meta(syn::Meta::Path(path)) => {+                                    path.get_ident()+                                        .map(|ident| *ident == "Debug")+                                        .unwrap_or(false)+                                }+                                _ => false,+                            }+                        })+                    } else {+                        false+                    }+                }+                _ => false,+            }+        })+    }++    /// Get the attributes with `Debug` filtered out of any present derives.+    fn get_attrs_no_debug<'a>(&'a self) -> impl Iterator<Item = TokenStream2> + 'a {+        self.item_struct.attrs.iter().map(|attr| {+            match attr.parse_meta() {+                Ok(syn::Meta::List(mut meta_list)) => {+                    let is_derive = meta_list+                        .path+                        .get_ident()+                        .map(|ident| *ident == "derive")+                        .unwrap_or(false);++                    if is_derive {+                        meta_list.nested = meta_list+                            .nested+                            .into_iter()+                            .filter(|nested| {+                                match nested {+                                    syn::NestedMeta::Meta(syn::Meta::Path(path)) => {+                                        path.get_ident()+                                            .map(|ident| *ident != "Debug")+                                            .unwrap_or(true)

Should use https://docs.rs/syn/0.15.44/syn/struct.Path.html#method.is_ident here instead.

jam1garner

comment created time in 3 days

PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentparitytech/ink

Improve docs on non-payable constructor

 where /// - If there are duplicate ink! attributes. /// - If the first ink! attribute is not matching the expected. /// - If there are conflicting ink! attributes.-pub fn sanitize_attributes<I, C>(+pub fn sanitize_attributes<I, C, R>(     parent_span: Span,     attrs: I,     is_valid_first: &ir::AttributeArgKind,     mut is_conflicting_attr: C,+    conflict_reason: R,

Not sure why we still need this whole parameter and a new InkAttributeConflictErr type at all with our combine approach.

cmichi

comment created time in 3 days

Pull request review commentparitytech/ink

Improve docs on non-payable constructor

 impl InkAttribute {         })     } +    /// Returns `true` if the ink! attribute contains the `constructor` argument.+    pub fn is_constructor(&self) -> bool {+        self.args()+            .any(|arg| matches!(arg.kind(), AttributeArgKind::Constructor))

While this works a message is only a constructor if the first argument is #[ink(constructor)]`. This is to disambiguate messages and constructors that have been invalidly flagged with both.

cmichi

comment created time in 3 days

Pull request review commentparitytech/ink

Improve docs on non-payable constructor

 mod tests {         );     } +    fn assert_try_from_fails_multiple_times(

Please add proper docs.

cmichi

comment created time in 3 days

PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent

issue commentparitytech/ink

I can't upload my wasm when using Balance * Balance

Thanks for the bug report!

The code you pasted above is not valid ink! code since its message is missing a receiver. Please paste your entire contract source code as well as your Cargo.toml so we can actually help you. Also please tell us what exactly is the error the Canvas UI has with it.

ByteRui

comment created time in 3 days

PullRequestReviewEvent

issue openedRobbepop/modular-bitfield

Add `bytes = N` parameter to the `#[bitfield]` macro

For checking whether a #[bitfield] struct is generated to be exactly N bytes big we could add a bytes = N parameter to the #[bitfield] proc. macro. For example for N = 32 a bitfield struct with a bid width of 25 up to 32 bits is going to be valid.

Example

#[bitfield(bytes = 4)]
struct TtResp {
    mregion: u8,
    sregion: u8, 
    mrvalid: bool,
    srvalid: bool,
    r: bool,
    rw: bool,
    nsr: bool,
    nsrw: bool,
    s: bool,
    irvalid: bool,
    iregion: u8,
}

created time in 3 days

issue openedRobbepop/modular-bitfield

Add #[repr = uN] annotation support for #[bitfield]

When given a #[bitfield] struct with a #[repr = uN], e.g. #[repr = u32] attribute the #[bitfield] macro shall make sure that the generated bitfield struct respects the bitwidth of the uN, e.g. 8 bits for u8, 16 bits for u16, etc.

Also it shall generate From<uN> and From<BitfieldStruct> for uN` implementations.

Example

#[bitfield]
#[repr(u32)]
#[derive(Debug)]
struct TtResp {
    mregion: u8,
    sregion: u8, 
    mrvalid: bool,
    srvalid: bool,
    r: bool,
    rw: bool,
    nsr: bool,
    nsrw: bool,
    s: bool,
    irvalid: bool,
    iregion: u8,
}

created time in 3 days

pull request commentparitytech/parity-common

Add conversions U256 <-> f64

I just think floating point would add additional complexity to this crate and I'm not sure it's worth the effort? However, if enough people wants it, it's fine I guess.

We could put it behind a crate feature.

bh2smith

comment created time in 3 days

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {     /// amount of bytes to compactly store the information of all its bit fields.     fn generate_struct(&self) -> TokenStream2 {         let span = self.item_struct.span();-        let attrs = &self.item_struct.attrs;+        let attrs = self.get_attrs_no_debug();         let vis = &self.item_struct.vis;         let ident = &self.item_struct.ident;         let size = self.generate_bitfield_size();         let next_divisible_by_8 = Self::next_divisible_by_8(&size);         quote_spanned!(span=>             #( #attrs )*             #[repr(transparent)]-            #[allow(clippy::identity_op)]+            #[allow(clippy::identity_op, unused_attributes)]

Would it be possible to simply check if no derives are left and therefore skip re-expanding the whole derive attribute again?

jam1garner

comment created time in 3 days

PullRequestReviewEvent
PullRequestReviewEvent

pull request commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

As a test case you could take my example from the issue:

use modular_bitfield::prelude::*;

#[derive(BitfieldSpecifier)]
#[bits = 3]
pub enum Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }

#[bitfield(specifier = true)]
pub struct Date {
    #[bits = 3]
    weekday: Weekday,
    week: u8,
}

#[bitfield]
pub struct FromTo {
    #[bits = 11]
    from: Date,
    #[bits = 11]
    to: Date,
    distance: B10,
}

The only thing you need in order to make it a real test is to add a fn main() { .. } that asserts the expected debug output.

jam1garner

comment created time in 3 days

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {         ))     } +    /// Get a list of fields, both in the form of a `String` as well as the corresponding faillible+    /// getter method+    fn get_field_strings_and_getters(&self) -> (Vec<String>, Vec<syn::Ident>) {+        self.item_struct+            .fields+            .iter()+            .enumerate()+            .map(|(i, field)| {+                let field_name = field+                    .ident+                    .as_ref()+                    .map(syn::Ident::to_string)+                    .unwrap_or_else(|| format!("get_{}", i));

In this case we want to use the field's actual name as string, so we can strip away the get_ prefix for unnamed fields.

jam1garner

comment created time in 3 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {     /// amount of bytes to compactly store the information of all its bit fields.     fn generate_struct(&self) -> TokenStream2 {         let span = self.item_struct.span();-        let attrs = &self.item_struct.attrs;+        let attrs = self.get_attrs_no_debug();         let vis = &self.item_struct.vis;         let ident = &self.item_struct.ident;         let size = self.generate_bitfield_size();         let next_divisible_by_8 = Self::next_divisible_by_8(&size);         quote_spanned!(span=>             #( #attrs )*             #[repr(transparent)]-            #[allow(clippy::identity_op)]+            #[allow(clippy::identity_op, unused_attributes)]

why is unused_attributes needed here? what code spawns which warnings?

jam1garner

comment created time in 3 days

PullRequestReviewEvent

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {         ))     } +    /// Get a list of fields, both in the form of a `String` as well as the corresponding faillible+    /// getter method+    fn get_field_strings_and_getters(&self) -> (Vec<String>, Vec<syn::Ident>) {+        self.item_struct+            .fields+            .iter()+            .enumerate()+            .map(|(i, field)| {+                let field_name = field+                    .ident+                    .as_ref()+                    .map(syn::Ident::to_string)+                    .unwrap_or_else(|| format!("get_{}", i));+                let fallible_getter =+                    quote::format_ident!("{}_or_err", field_name, span = field.span());

This is not the correct getter identifier for tuple structs with unnamed fields. For those it is: get_N_or_err where N denotes the index of the field.

jam1garner

comment created time in 3 days

PullRequestReviewEvent

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {         ))     } +    /// Get a list of fields, both in the form of a `String` as well as the corresponding faillible+    /// getter method+    fn get_field_strings_and_getters(&self) -> (Vec<String>, Vec<syn::Ident>) {+        self.item_struct+            .fields+            .iter()+            .enumerate()+            .map(|(i, field)| {+                let field_name = field+                    .ident+                    .as_ref()+                    .map(syn::Ident::to_string)+                    .unwrap_or_else(|| format!("get_{}", i));+                let fallible_getter =+                    quote::format_ident!("{}_or_err", field_name, span = field.span());++                (field_name, fallible_getter)+            })+            .unzip()+    }++    /// Generates the core::fmt::Debug impl if `#[derive(Debug)]` is included.+    pub fn generate_debug_impl(&self) -> Option<TokenStream2> {+        if self.should_derive_debug() {+            let span = self.item_struct.span();+            let ident = &self.item_struct.ident;+            let (field_strings, field_getters) = self.get_field_strings_and_getters();++            Some(quote_spanned!(span=>+                impl core::fmt::Debug for #ident {+                    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {+                        f.debug_struct(stringify!(#ident))+                            #(+                                .field(+                                    #field_strings,+                                    self.#field_getters()+                                        .as_ref()+                                        .map(|field| field as &dyn core::fmt::Debug)+                                        .unwrap_or_else(|err| err as &dyn core::fmt::Debug)+                                )+                            )*+                            .finish()+                    }+                }

proc. macro hygiene suggestion

jam1garner

comment created time in 3 days

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {         ))     } +    /// Get a list of fields, both in the form of a `String` as well as the corresponding faillible+    /// getter method+    fn get_field_strings_and_getters(&self) -> (Vec<String>, Vec<syn::Ident>) {+        self.item_struct+            .fields+            .iter()+            .enumerate()+            .map(|(i, field)| {+                let field_name = field+                    .ident+                    .as_ref()+                    .map(syn::Ident::to_string)+                    .unwrap_or_else(|| format!("get_{}", i));+                let fallible_getter =+                    quote::format_ident!("{}_or_err", field_name, span = field.span());++                (field_name, fallible_getter)+            })+            .unzip()+    }++    /// Generates the core::fmt::Debug impl if `#[derive(Debug)]` is included.+    pub fn generate_debug_impl(&self) -> Option<TokenStream2> {+        if self.should_derive_debug() {+            let span = self.item_struct.span();+            let ident = &self.item_struct.ident;+            let (field_strings, field_getters) = self.get_field_strings_and_getters();++            Some(quote_spanned!(span=>+                impl core::fmt::Debug for #ident {+                    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {+                        f.debug_struct(stringify!(#ident))+                            #(+                                .field(+                                    #field_strings,+                                    self.#field_getters()+                                        .as_ref()+                                        .map(|field| field as &dyn core::fmt::Debug)+                                        .unwrap_or_else(|err| err as &dyn core::fmt::Debug)+                                )+                            )*+                            .finish()+                    }+                }
                impl ::core::fmt::Debug for #ident {
                    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
                        f.debug_struct(::core::stringify!(#ident))
                            #(
                                .field(
                                    #field_strings,
                                    self.#field_getters()
                                        .as_ref()
                                        .map(|field| field as &dyn ::core::fmt::Debug)
                                        .unwrap_or_else(|err| err as &dyn ::core::fmt::Debug)
                                )
                            )*
                            .finish()
                    }
                }
jam1garner

comment created time in 3 days

Pull request review commentRobbepop/modular-bitfield

Handle deriving fmt::Debug impl for bitfields instead of std

 impl BitfieldStruct {     /// amount of bytes to compactly store the information of all its bit fields.     fn generate_struct(&self) -> TokenStream2 {         let span = self.item_struct.span();-        let attrs = &self.item_struct.attrs;+        let attrs = self.get_attrs_no_debug();         let vis = &self.item_struct.vis;         let ident = &self.item_struct.ident;         let size = self.generate_bitfield_size();         let next_divisible_by_8 = Self::next_divisible_by_8(&size);         quote_spanned!(span=>             #( #attrs )*             #[repr(transparent)]-            #[allow(clippy::identity_op)]+            #[allow(clippy::identity_op, unused_attributes)]             #vis struct #ident             {                 bytes: [::core::primitive::u8; #next_divisible_by_8 / 8usize],             }         )     } +    /// Get whether or not `derive(Debug)` is included in the attributes+    fn should_derive_debug(&self) -> bool {

We should also provide a conditional Debug impl for cases like

#[bitfield]
#[cfg_attr(test, derive(Debug))]
pub struct MyBitfield { ... }

In this case we'd like to also only implement Debug if the given conditional (in this case test) is true.

jam1garner

comment created time in 3 days

more