Re: [rust-dev] Goto statement missing

2014-03-24 Thread Daniel Micay
On 23/03/14 03:09 PM, Erick Tryzelaar wrote:
>
> I've been thinking of a couple alternatives that could make us as fast
> as a c state machine. The simplest night be to leverage the fact that
> llvm can optimize certain recursive function calls into tail calls, and
> lower those into jumps. If we go this route, we could only do this for
> internal functions with certain properties, so it could be nice to add a
> `#[tail_call] annotation that'll validate these conditions.

It varies per-target and has complex requirements, so checking it isn't
really a simple task.



signature.asc
Description: OpenPGP digital signature
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Erick Tryzelaar
Yep it uses the labeled break and continue. It's not quite as fast as goto
state machines because it has to use a state table to decide where to jump
to.

I've been thinking of a couple alternatives that could make us as fast as a
c state machine. The simplest night be to leverage the fact that llvm can
optimize certain recursive function calls into tail calls, and lower those
into jumps. If we go this route, we could only do this for internal
functions with certain properties, so it could be nice to add a
`#[tail_call] annotation that'll validate these conditions.

A little more complicated thing would be to add what I call constrained
computed gotos. This would allow labels to be placed on match arms as in:

match 'a {
  'a => { continue 'b; }
  'b => { ... }
  ...
}

The constraint is that we can only jump to well defined arms from inside
the match block. I really need to write it up as an RFC someday.

The most complicatedas is to use unsafe code embedded asm to jump around.

On Sunday, March 23, 2014, Tony Arcieri  wrote:

> On Sun, Mar 23, 2014 at 11:42 AM, Corey Richardson 
> 
> > wrote:
>
>> Note that there's Rust support for Ragel
>> (https://github.com/erickt/ragel), so you can just use that. It's much
>> easier than writing out your state machines by hand.
>
>
> What kind of code is the Rust backend(s) capable of emitting? Can it do
> labeled break/continue to generate jump-driven FSMs the same way it does
> with Java?
>
> --
> Tony Arcieri
>
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Tony Arcieri
On Sun, Mar 23, 2014 at 11:50 AM, Corey Richardson  wrote:

> Yes.


Cool! Who needs goto then? ;)

-- 
Tony Arcieri
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Corey Richardson
Yes.

On Sun, Mar 23, 2014 at 2:48 PM, Tony Arcieri  wrote:
> On Sun, Mar 23, 2014 at 11:42 AM, Corey Richardson  wrote:
>>
>> Note that there's Rust support for Ragel
>> (https://github.com/erickt/ragel), so you can just use that. It's much
>> easier than writing out your state machines by hand.
>
>
> What kind of code is the Rust backend(s) capable of emitting? Can it do
> labeled break/continue to generate jump-driven FSMs the same way it does
> with Java?
>
> --
> Tony Arcieri



-- 
http://octayn.net/
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Tony Arcieri
On Sun, Mar 23, 2014 at 11:42 AM, Corey Richardson  wrote:

> Note that there's Rust support for Ragel
> (https://github.com/erickt/ragel), so you can just use that. It's much
> easier than writing out your state machines by hand.


What kind of code is the Rust backend(s) capable of emitting? Can it do
labeled break/continue to generate jump-driven FSMs the same way it does
with Java?

-- 
Tony Arcieri
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Corey Richardson
Note that there's Rust support for Ragel
(https://github.com/erickt/ragel), so you can just use that. It's much
easier than writing out your state machines by hand.

On Sun, Mar 23, 2014 at 1:18 PM, Patrick Walton  wrote:
> On 3/23/14 9:04 AM, Clark Gaebel wrote:
>>
>> I think the biggest case for gotos is jumping out of nested loops. Does
>> rust have a nice way of doing that yet?
>
>
> There's labeled break and continue. Use `'foo:` to denote a label. (The
> reason that we use lifetime syntax there is that eventually it may be
> possible to denote lifetimes explicitly using labels.)
>
> Patrick
>
>
> ___
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev



-- 
http://octayn.net/
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Patrick Walton

On 3/23/14 9:04 AM, Clark Gaebel wrote:

I think the biggest case for gotos is jumping out of nested loops. Does
rust have a nice way of doing that yet?


There's labeled break and continue. Use `'foo:` to denote a label. (The 
reason that we use lifetime syntax there is that eventually it may be 
possible to denote lifetimes explicitly using labels.)


Patrick

___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Léo Testard
"Kang Seonghoon" 
>
> To be exact, it is `'g: ...` and `break 'g;` respectively. Its
> resemblance with the lifetime syntax is no coincidence.
>

Woops, indeed, sorry for the mistake. There's no syntax highlighting when
wirting code in emails, and I'm not very used to this new syntax. :)

Thanks for the correction, Kang.

Leo,
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Kang Seonghoon
2014-03-24 1:08 GMT+09:00 Léo Testard :
> On the other hand, I never felt gotos missing when writing FSM simulation
> code, but we do have a very nice syntax for jumping out of nested loops :
>
> g: for i in foo.iter() {
> // ...
> h: loop {
> if foo { break g; }
> continue h;
> }
> }
>
> This syntax only allows to jump at the beginning of a lexical block, and
> only to an larger scope, thus not infriging any static lexical rule.

To be exact, it is `'g: ...` and `break 'g;` respectively. Its
resemblance with the lifetime syntax is no coincidence.

-- 
-- Kang Seonghoon | Software Engineer, iPlateia Inc. | http://mearie.org/
-- Opinions expressed in this email do not necessarily represent the
views of my employer.
--
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Léo Testard
Hello

Gotos are considered harmful for a reason. They allow you to bypass every
static block scope rules. Rust is a language with many static analysis
concerning typing and scope rules. I don't think goto statements integrate
well in such languages.

On the other hand, I never felt gotos missing when writing FSM simulation
code, but we do have a very nice syntax for jumping out of nested loops :

g: for i in foo.iter() {
// ...
h: loop {
if foo { break g; }
continue h;
}
}

This syntax only allows to jump at the beginning of a lexical block, and
only to an larger scope, thus not infriging any static lexical rule.

Leo

Le 23 mars 2014 16:59, "Clark Gaebel"  a écrit :
>
> Use tail call recursion for your FSMs.
>
> On Mar 23, 2014 11:57 AM, "Jérôme Bartand"  wrote:
>>
>> Hello fellow Rustians,
>>
>> I noticed that there is no goto statement in Rust yet. Gotos are very
useful e.g. for writing FSMs or for code generation and can, if used
sensibly, often make code more readable than code with traditional control
structures and temporary variables.
>> Can we please have a goto statement in Rust?
>>
>> Please no stupid remarks like "goto fail" or "go to statement considered
harmful" or similar (the Apple bug was not caused by the goto and Rust has
unreachable code detection).
>>
>> Thanks
>>
>> ___
>> Rust-dev mailing list
>> Rust-dev@mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev
>>
>
> ___
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Clark Gaebel
I think the biggest case for gotos is jumping out of nested loops. Does
rust have a nice way of doing that yet?
On Mar 23, 2014 11:57 AM, "Jérôme Bartand"  wrote:

> Hello fellow Rustians,
>
> I noticed that there is no goto statement in Rust yet. Gotos are very
> useful e.g. for writing FSMs or for code generation and can, if used
> sensibly, often make code more readable than code with traditional control
> structures and temporary variables.
> Can we please have a goto statement in Rust?
>
> Please no stupid remarks like "goto fail" or "go to statement considered
> harmful" or similar (the Apple bug was not caused by the goto and Rust has
> unreachable code detection).
>
> Thanks
>
> ___
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


Re: [rust-dev] Goto statement missing

2014-03-23 Thread Clark Gaebel
Use tail call recursion for your FSMs.
On Mar 23, 2014 11:57 AM, "Jérôme Bartand"  wrote:

> Hello fellow Rustians,
>
> I noticed that there is no goto statement in Rust yet. Gotos are very
> useful e.g. for writing FSMs or for code generation and can, if used
> sensibly, often make code more readable than code with traditional control
> structures and temporary variables.
> Can we please have a goto statement in Rust?
>
> Please no stupid remarks like "goto fail" or "go to statement considered
> harmful" or similar (the Apple bug was not caused by the goto and Rust has
> unreachable code detection).
>
> Thanks
>
> ___
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev


[rust-dev] Goto statement missing

2014-03-23 Thread Jérôme Bartand
Hello fellow Rustians,

I noticed that there is no goto statement in Rust yet. Gotos are very
useful e.g. for writing FSMs or for code generation and can, if used
sensibly, often make code more readable than code with traditional control
structures and temporary variables.
Can we please have a goto statement in Rust?

Please no stupid remarks like "goto fail" or "go to statement considered
harmful" or similar (the Apple bug was not caused by the goto and Rust has
unreachable code detection).

Thanks
___
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev