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

RFC: Proposal for bit data (Ver 2) #327

Closed
wants to merge 4 commits into from
Closed

Conversation

engstad
Copy link

@engstad engstad commented Sep 26, 2014

After having addressed most of the issues, here's the updated RFC.

manipulations to a satisfactory level. We support a macro `bitflags!` for
supporting individual bits, but there is no support for bit-ranges. Anyone
who has had to write disassemblers for the x86 instruction set would concur
to how error-prone it is to deal with shifts and masks.
Copy link
Member

Choose a reason for hiding this comment

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

s/to //

@eddyb
Copy link
Member

eddyb commented Sep 27, 2014

Is there a need to add keywords and syntax to Rust instead of building on top of the existing syntax?
This seems like it could be prototypable as a syntax extension, at least with methods for accessors.

@engstad
Copy link
Author

engstad commented Sep 27, 2014

@eddyb This was discussed before, but the short version is that no - a syntax extension is not possible.

What people have done instead is to run their own parser/external tool to just do the job, and that is not quite where you want to be (if you are supposed to be a systems language).

@bgamari
Copy link

bgamari commented Sep 28, 2014

@engstad I'm not sure I see why a syntax extension would not be possible here. Why can the error checking not be done in a syntax extension? Likewise, what prevents a type defined by a bitdata! syntax extension from using another bit-data type? Finally, the syntactic overhead of a syntax extension is merely the bitdata!( prefix and a closing paren; this could be made even more pleasing if syntax extension syntax can be made to accept blocks.

We've implemented similar functionality to that proposed here in the Zinc project. This involved a syntax extension and while we only handle the single constructor case (and adopt a rather different syntax than typical Rust) I believe this approach could be easily adapted.

@bgamari
Copy link

bgamari commented Sep 28, 2014

For the record, the first iteration of this RFC was #205.

@Ericson2314
Copy link
Contributor

Wouldn't it be better enhance enum and struct than add a new type of data (and keyword). odd-sized numerical types and mod types (like Ada) are fairly similar and could probably be implemented together.

Option<Type_With_Bits> could also be optimized if the discriminants aren't exhaustive. Integer (of the right size) casts to Option<Type_With_Bits> would correspondingly be safe no-ops.

@engstad
Copy link
Author

engstad commented Sep 29, 2014

@bgamari Yes, I checked the ioregs!() functionality. While it is an impressive syntax extension, it still doesn't cover match, which I feel is essential for clean operation on bit-data. In addition, having to use .set_xxx() and xxx() methods is tedious and unnecessary.

@Ericson2314 I think it is quite important to differentiate bit-data and byte-data, simply because with bit-data you don't have to consider alignment and endianess. Having said that, yes our struct construct can also be improved. I will probably follow up with an RFC that improves our handling of byte-data, where for example this would be possible:

bitdata StreamInfo {
    SI { 
         num_elements: u12, 
         stream_index: u4, 
         stride: u8, 
         format: u8, 
         typ: u8, 
         offset:  u8, 
         size: u8, 
         flags: u8 
    }
}
struct Mesh {
    num_indexes : u32,
    num_streams: u32,
    total_stream_size: u32,
    #[align(16)] indexes: [u16, ..num_indexes],
    #[align(16)] stream_info: [StreamInfo, ..num_streams],
    #[align(16)] stream_data: [u8, ..total_stream_size]
}

@bgamari
Copy link

bgamari commented Sep 30, 2014

engstad [email protected] writes:

@bgamari Yes, I checked the ioregs!() functionality. While it is an
impressive syntax extension, it still doesn't cover match, which I
feel is very essential for clean operation on bit-data. In addition,
having to use .set_xxx() and xxx() methods is tedious and unnecessary.

I agree that the lack of pattern matching is a bit unfortunate. I
wonder, however, whether it would be possible to generalize pattern
matching a bit, allowing this and similar use-cases to be implemented
without adding a whole new data type declaration to the language.

I believe there was some resistance in the past to allowing arbitrary
computation to take place during a pattern match, but this would
certainly be one way to acheive what you want.

As far as accessors goes, I agree that they are a bit onerous in the
your case. In the case of a register interface requiring explicit
accesses makes sense due to the potential side-effects that they may
trigger.

@zwarich
Copy link

zwarich commented Oct 2, 2014

Any proposal for bit data should have more details about the low-level representation of the bit data in memory, as it is important that the layout matches specific formats that are defined outside of Rust code. In this today's triage meeting we decided to postpone this RFC. I opened a tracking issue as #346.

@zwarich zwarich closed this Oct 2, 2014
withoutboats pushed a commit to withoutboats/rfcs that referenced this pull request Jan 15, 2017
UnboundedSender::send does not need to accept mut self
@Centril Centril added T-lang Relevant to the language team, which will review and decide on the RFC. A-data-types RFCs about data-types A-typesystem Type system related proposals & ideas A-patterns Pattern matching related proposals & ideas A-expressions Term language related proposals & ideas A-ffi FFI related proposals. A-machine Proposals relating to Rust's abstract machine. A-bitdata Proposals relating to bitdata / bitflags. labels Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bitdata Proposals relating to bitdata / bitflags. A-data-types RFCs about data-types A-expressions Term language related proposals & ideas A-ffi FFI related proposals. A-machine Proposals relating to Rust's abstract machine. A-patterns Pattern matching related proposals & ideas A-typesystem Type system related proposals & ideas T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants