[patch] Add support for parsing "use"

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[patch] Add support for parsing "use"

Rafael Ávila de Espíndola
With the attached patch rustc can parse:

------------
use std;
use std();
use std(name = "foo");
use std(name = "foo", bar = "zed");

fn main() {
}
------------

I am setting up a github account and repo, but for now the patch is attached

Questions:

*) Are use and imports allowed anywhere in the file?
*) How do I add a test that uses rustc?
*) Is there a syntax only mode? I had to add the main function to
prevent a crash.

Cheers,
Rafael
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: use.patch
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20101222/1ce02fb1/attachment.pl>

Reply | Threaded
Open this post in threaded view
|

[patch] Add support for parsing "use"

Graydon Hoare
On 22/12/2010 11:35 AM, Rafael ?vila de Esp?ndola wrote:

> With the attached patch rustc can parse:
>
> ------------
> use std;
> use std();
> use std(name = "foo");
> use std(name = "foo", bar = "zed");
>
> fn main() {
> }

Great. Some comments on the patch:

  - in parse_meta_item, p.err("foobar") is no good; need a real error
    message. Or call unexpected(p, p.peek()).

  - parse_meta should use the parse_seq helper, rather than manually
    stepping through the commas.

  - It might be good to sink parse_use_and_imports down to the module
    level, as we at least support imports (possibly 'use' clasuses as
    well) within sub-modules. See below re: allowed locations.

> I am setting up a github account and repo, but for now the patch is
> attached

Ok. We'll need at least the mozilla foundation committer paperwork from
you as well, unless you've been vetted for a mozilla project commit
level yet. I'll file a bug if not.

> Questions:
>
> *) Are use and imports allowed anywhere in the file?

In the present grammar they're only accepted in a sort of "preamble"
section before any actual items are declared in a module. This is not
something everyone agrees with; some prefer to be able to toss imports
and 'use' clauses anywhere they like. I don't really care at this point,
trivial change.

I'm not sure if there'll be a big problem permitting imports in other
block forms, but for now at least please limit it to module bodies, not
any of the items within them.

> *) How do I add a test that uses rustc?

The Makefile contains test-driver logic based on files it finds in
test/*/*. So just drop a .rs or .rc file in one of the test
subdirectories, and it'll start doing something (with parallel testing
support via make -j as well):

   test/run-pass/  for tests you expect to run and exit ok

   test/run-fail/  for tests you expect to run and exit in failure

   test/compile-fail/  for tests you expect to fail compilation
                       (including an error-pattern comment in the file,
                        that tells the test driver logic what sort of
                        error to expect)

By default, the test driver logic runs all tests not listed in the
Makefile as XFAIL'ed, so it'll run the rustboot one automatically. If
you don't want to run the rustboot one, add the file name to
TEST_XFAILS_X86.

Since we have so few tests runnning on rustc at the moment, we currently
abuse the XFAIL concept and enumerate a list of the tests that *are*
passing in TEST_XFAILS_SELF, wrapping the whole thing in a $(filter-out
...) call. So by default rustc will not run a test until you list it in
TEST_XFAILS_SELF. At some point we'll invert this back and make it a
proper XFAIL list.

> *) Is there a syntax only mode? I had to add the main function to
> prevent a crash.

No, but I wouldn't object to one. Part of the point of moving to a more
functional form in rustc is to make the passes more independently
testable. Feel free to add command-line processing to
comp/driver/rustc.rs that supports partial pass-execution like that.

-Graydon

Reply | Threaded
Open this post in threaded view
|

[patch] Add support for parsing "use"

Rafael Ávila de Espíndola
> Great. Some comments on the patch:

I will reply on the patch itself in a second.

>> I am setting up a github account and repo, but for now the patch is
>> attached

I manged to reset my password *and* forget it at home today :-(. Will
make sure to have it tomorrow, but for now more attached patches.

> Ok. We'll need at least the mozilla foundation committer paperwork from
> you as well, unless you've been vetted for a mozilla project commit
> level yet. I'll file a bug if not.

I should have all the paperwork in place, but don't have any commit
access yet (as rust is my first project). How do I check if the
paperwork was already processed?

> Since we have so few tests runnning on rustc at the moment, we currently
> abuse the XFAIL concept and enumerate a list of the tests that *are*
> passing in TEST_XFAILS_SELF, wrapping the whole thing in a $(filter-out
> ...) call. So by default rustc will not run a test until you list it in
> TEST_XFAILS_SELF. At some point we'll invert this back and make it a
> proper XFAIL list.

I noticed that rustc was never being used and that was because I had the
bindings disabled. I assume this is from the days llvm was used via the
ocaml bindings. The attached patch should fix that.

>> *) Is there a syntax only mode? I had to add the main function to
>> prevent a crash.
>
> No, but I wouldn't object to one. Part of the point of moving to a more
> functional form in rustc is to make the passes more independently
> testable. Feel free to add command-line processing to
> comp/driver/rustc.rs that supports partial pass-execution like that.

Nice. For now I changed the test to use valid crates so that rustboot is
happy with it.

> -Graydon

Cheers,
Rafael
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: bind.patch
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20101223/504feced/attachment.pl>

Reply | Threaded
Open this post in threaded view
|

[patch] Add support for parsing "use"

Rafael Ávila de Espíndola
In reply to this post by Graydon Hoare
On 10-12-22 2:54 PM, Graydon Hoare wrote:
> Great. Some comments on the patch:
>

Thanks for complete review and explanation!

The attached patch should contain all your suggestions and a test.
Should I also add negative tests to check that uses are rejected in
other contexts?

> -Graydon

Cheers,
Rafael
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: use.patch
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20101223/c0bb1fdd/attachment.pl>