[rust-dev] Ragel support for Rust

Graydon Hoare graydon at mozilla.com
Tue Aug 7 10:06:25 PDT 2012

On 12-07-29 12:20 PM, Tim Chevalier wrote:

>> Unfortunately there are some pretty severe performance issues at the moment.
>> Ragel supports two state machine styles, table-driven and goto-driven. My
>> backend uses tables, but since Rust doesn't yet support global constant
>> vectors, I need to malloc the state machine table on every function call. This
>> results in the [ragel-based url
>> parser](https://github.com/erickt/ragel/blob/rust/examples/rust/url.rl)
>> being about
>> 10 times slower than the equivalent table-based parser in OCaml. You can see
>> the generated code [here](https://gist.github.com/3200980).
> There's an open bug on vector constants:
> https://github.com/mozilla/rust/issues/571
> It's assigned to me (though I haven't done anything on it yet), so
> feel free to bug me about it :-)

Yeah, I'm doing this (all the const-exprs) presently. There might be 
enough in there now to point ragel at. Constant records and tuples work, 
as do const vectors and &-ptrs to consts. No slices yet. Still lots to do.

> This sounds like the open bug on labelled break and continue, as Patrick said:
> https://github.com/mozilla/rust/issues/2216
> which is currently unassigned. As per #217, we decided not to support
> general tail calls, but that doesn't mean we can't support tail calls
> just for the special labelled break/continue form.

Yeah. I think that might be adequate, at least for building-atop with a 
macro or other extension. Assuming we permit a 'sideways again' that 
transfers from one labeled loop to another (at the same or higher 
nesting level).

The key thing you want is direct branching to your current state (rather 
than indirect off a 'current state' variable) and direct jumps from one 
state to another; the rest (argument passing etc.) can be encoded at no 
cost through local variables. The fast control transfers can't.

I do slightly wonder if the labeled break/again forms will mutate into 
general gotos. I hope not.


More information about the Rust-dev mailing list