Re: [rust-dev] Cap'n Proto and region variables

2013-07-24 Thread Niko Matsakis
On Sun, Jul 21, 2013 at 12:44:24PM -0400, David Renshaw wrote: Hello everyone, I'm playing around with a Rust implementation for Cap'n Proto. Check it out: http://github.com/dwrensha/capnproto-rust . I welcome any comments or contributions. The reason I'm sharing this project with you now

[rust-dev] read_byte and sentinel values

2013-07-24 Thread Evan Martin
Hello, Sorry for the bikesheddy question, but coming from a Haskell perspective it's strange that io::Reader::read_byte returns (1) an int, when the value you're reading is a byte, and (2) a negative value on error/EOF. The unspecified sentinel value means the pattern match needs to look like:

Re: [rust-dev] read_byte and sentinel values

2013-07-24 Thread Corey Richardson
On Wed, Jul 24, 2013 at 12:15 PM, Evan Martin mart...@danga.com wrote: It would seem more natural to me for it to return an Optionu8, but that leads to two questions: 1) Is it more Rusty to use types like this instead of sentinels? My aesthetics aren't adapted to Rust yet. Yes. Optionu8 is

Re: [rust-dev] read_byte and sentinel values

2013-07-24 Thread Brendan Zabarauskas
On 25/07/2013, at 2:15 AM, Evan Martin mart...@danga.com wrote: Is an Optionu8 implemented as a pair of (type, value) or is it packed into a single word? A quick test shows: rusti std::sys::size_of::Optionu8() 16 ~Brendan___ Rust-dev

Re: [rust-dev] read_byte and sentinel values

2013-07-24 Thread Matthieu Monrocq
Given that all values of u8 are meanginful, there is no space for an extra bit, so it is no surprise that it cannot be packed. For pointers, for example, it is typical to exploit the fact that the null pointer is a meaningless value and thus rely on this sentinel value to encode the absence of

Re: [rust-dev] read_byte and sentinel values

2013-07-24 Thread Corey Richardson
On Wed, Jul 24, 2013 at 12:42 PM, Matthieu Monrocq matthieu.monr...@gmail.com wrote: Given that all values of u8 are meanginful, there is no space for an extra bit, so it is no surprise that it cannot be packed. For pointers, for example, it is typical to exploit the fact that the null

Re: [rust-dev] read_byte and sentinel values

2013-07-24 Thread Matthieu Monrocq
It could be. If it is not, it may be that Option needs some love at the CodeGen level to make it so :) -- Matthieu. On Wed, Jul 24, 2013 at 6:46 PM, Corey Richardson co...@octayn.net wrote: On Wed, Jul 24, 2013 at 12:42 PM, Matthieu Monrocq matthieu.monr...@gmail.com wrote: Given that all

Re: [rust-dev] read_byte and sentinel values

2013-07-24 Thread Daniel Micay
On Wed, Jul 24, 2013 at 12:33 PM, Brendan Zabarauskas bjz...@yahoo.com.au wrote: On 25/07/2013, at 2:15 AM, Evan Martin mart...@danga.com wrote: Is an Optionu8 implemented as a pair of (type, value) or is it packed into a single word? A quick test shows: rusti

Re: [rust-dev] read_byte and sentinel values

2013-07-24 Thread Daniel Micay
On Wed, Jul 24, 2013 at 12:51 PM, Matthieu Monrocq matthieu.monr...@gmail.com wrote: It could be. If it is not, it may be that Option needs some love at the CodeGen level to make it so :) -- Matthieu. It's a known issue for enums in general. The `Option` type is entirely a library feature,

Re: [rust-dev] read_byte and sentinel values

2013-07-24 Thread Graydon Hoare
On 13-07-24 09:33 AM, Brendan Zabarauskas wrote: On 25/07/2013, at 2:15 AM, Evan Martin mart...@danga.com mailto:mart...@danga.com wrote: Is an Optionu8 implemented as a pair of (type, value) or is it packed into a single word? A quick test shows: rusti std::sys::size_of::Optionu8()

Re: [rust-dev] read_byte and sentinel values

2013-07-24 Thread Niko Matsakis
The existence of ref patterns somewhat limits what one can do here as well, since you must be able to create a pointer to the value being matched, which implies that it can't be too disguised. For example, this prevents us from optimizing something like `Either~A,~B` to use a 0 or 1 in the low

Re: [rust-dev] read_byte and sentinel values

2013-07-24 Thread Corey Richardson
On Wed, Jul 24, 2013 at 3:18 PM, Jed Davis j...@panix.com wrote: It's not quite as simple as it sounds, because there's unsafe code that's transmuting ints to C-like enums, and passing C-like enums to C functions that expect an actual C enum (or some other integral type). So this more or less

Re: [rust-dev] Cap'n Proto and region variables

2013-07-24 Thread David Renshaw
Looks like it's broken at the moment. If I try to compile this program: trait Constructable'self { fn construct(v : 'self[u8]) - Self; } fn main() { } I get this error: error: internal compiler error: ty::Region#subst(): Reference to self region when given substs with no self region:

[rust-dev] 'in' for for loops and alloc exprs

2013-07-24 Thread Graydon Hoare
Hi, We had some discussion recently about reforming the for-loop syntax since we'll be switching it to external iterators and it's a bit deceptive to the user to be writing a lambda-pattern there. Many people have suggested we use a simple and familiar: for pattern in expr { ... } form.

Re: [rust-dev] 'in' for for loops and alloc exprs

2013-07-24 Thread Jeaye
We had some discussion recently about reforming the for-loop syntax since we'll be switching it to external iterators and it's a bit deceptive to the user to be writing a lambda-pattern there. Have we yet considered C++11's approach to this? for name : expr { ... } This seems pretty

Re: [rust-dev] 'in' for for loops and alloc exprs

2013-07-24 Thread Corey Richardson
On Wed, Jul 24, 2013 at 10:59 PM, Jeaye je...@arrownext.com wrote: We had some discussion recently about reforming the for-loop syntax since we'll be switching it to external iterators and it's a bit deceptive to the user to be writing a lambda-pattern there. Have we yet considered C++11's

Re: [rust-dev] 'in' for for loops and alloc exprs

2013-07-24 Thread Jack Moffitt
- No-pattern form now requires a dummy pattern. That is, we can't do: for 10.times { ... } anymore, rather we have to write: for _ in 10.times() { ... } I will not cry much if this happens; it is a bit clever, but maybe we could save it by using loop: loop 10.times { ...