summary refs log tree commit diff
path: root/src/libsyntax
AgeCommit message (Collapse)AuthorLines
2014-01-16auto merge of #11151 : sfackler/rust/ext-crate, r=alexcrichtonbors-89/+240
This is a first pass on support for procedural macros that aren't hardcoded into libsyntax. It is **not yet ready to merge** but I've opened a PR to have a chance to discuss some open questions and implementation issues. Example ======= Here's a silly example showing off the basics: my_synext.rs ```rust #[feature(managed_boxes, globs, macro_registrar, macro_rules)]; extern mod syntax; use syntax::ast::{Name, token_tree}; use syntax::codemap::Span; use syntax::ext::base::*; use syntax::parse::token; #[macro_export] macro_rules! exported_macro (() => (2)) #[macro_registrar] pub fn macro_registrar(register: |Name, SyntaxExtension|) { register(token::intern(&"make_a_1"), NormalTT(@SyntaxExpanderTT { expander: SyntaxExpanderTTExpanderWithoutContext(expand_make_a_1), span: None, } as @SyntaxExpanderTTTrait, None)); } pub fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[token_tree]) -> MacResult { if !tts.is_empty() { cx.span_fatal(sp, "make_a_1 takes no arguments"); } MRExpr(quote_expr!(cx, 1i)) } ``` main.rs: ```rust #[feature(phase)]; #[phase(syntax)] extern mod my_synext; fn main() { assert_eq!(1, make_a_1!()); assert_eq!(2, exported_macro!()); } ``` Overview ======= Crates that contain syntax extensions need to define a function with the following signature and annotation: ```rust #[macro_registrar] pub fn registrar(register: |ast::Name, ext::base::SyntaxExtension|) { ... } ``` that should call the `register` closure with each extension it defines. `macro_rules!` style macros can be tagged with `#[macro_export]` to be exported from the crate as well. Crates that wish to use externally loadable syntax extensions load them by adding the `#[phase(syntax)]` attribute to an `extern mod`. All extensions registered by the specified crate are loaded with the same scoping rules as `macro_rules!` macros. If you want to use a crate both for syntax extensions and normal linkage, you can use `#[phase(syntax, link)]`. Open questions =========== * ~~Does the `macro_crate` syntax make sense? It wraps an entire `extern mod` declaration which looks a bit weird but is nice in the sense that the crate lookup logic can be identical between normal external crates and external macro crates. If the `extern mod` syntax, changes, this will get it for free, etc.~~ Changed to a `phase` attribute. * ~~Is the magic name `macro_crate_registration` the right way to handle extension registration? It could alternatively be handled by a function annotated with `#[macro_registration]` I guess.~~ Switched to an attribute. * The crate loading logic lives inside of librustc, which means that the syntax extension infrastructure can't directly access it. I've worked around this by passing a `CrateLoader` trait object from the driver to libsyntax that can call back into the crate loading logic. It should be possible to pull things apart enough that this isn't necessary anymore, but it will be an enormous refactoring project. I think we'll need to create a couple of new libraries: libsynext libmetadata/ty and libmiddle. * Item decorator extensions can be loaded but the `deriving` decorator itself can't be extended so you'd need to do e.g. `#[deriving_MyTrait] #[deriving(Clone)]` instead of `#[deriving(MyTrait, Clone)]`. Is this something worth bothering with for now? Remaining work =========== - [x] ~~There is not yet support for rustdoc downloading and compiling referenced macro crates as it does for other referenced crates. This shouldn't be too hard I think.~~ - [x] ~~This is not testable at stage1 and sketchily testable at stages above that. The stage *n* rustc links against the stage *n-1* libsyntax and librustc. Unfortunately, crates in the test/auxiliary directory link against the stage *n* libstd, libextra, libsyntax, etc. This causes macro crates to fail to properly dynamically link into rustc since names end up being mangled slightly differently. In addition, when rustc is actually installed onto a system, there are actually do copies of libsyntax, libstd, etc: the ones that user code links against and a separate set from the previous stage that rustc itself uses. By this point in the bootstrap process, the two library versions *should probably* be binary compatible, but it doesn't seem like a sure thing. Fixing this is apparently hard, but necessary to properly cross compile as well and is being tracked in #11145.~~ The offending tests are ignored during `check-stage1-rpass` and `check-stage1-cfail`. When we get a snapshot that has this commit, I'll look into how feasible it'll be to get them working on stage1. - [x] ~~`macro_rules!` style macros aren't being exported. Now that the crate loading infrastructure is there, this should just require serializing the AST of the macros into the crate metadata and yanking them out again, but I'm not very familiar with that part of the compiler.~~ - [x] ~~The `macro_crate_registration` function isn't type-checked when it's loaded. I poked around in the `csearch` infrastructure a bit but didn't find any super obvious ways of checking the type of an item with a certain name. Fixing this may also eliminate the need to `#[no_mangle]` the registration function.~~ Now that the registration function is identified by an attribute, typechecking this will be like typechecking other annotated functions. - [x] ~~The dynamic libraries that are loaded are never unloaded. It shouldn't require too much work to tie the lifetime of the `DynamicLibrary` object to the `MapChain` that its extensions are loaded into.~~ - [x] ~~The compiler segfaults sometimes when loading external crates. The `DynamicLibrary` reference and code objects from that library are both put into the same hash table. When the table drops, due to the random ordering the library sometimes drops before the objects do. Once #11228 lands it'll be easy to fix this.~~
2014-01-16Load macros from external modulesSteven Fackler-89/+240
2014-01-16auto merge of #11599 : sanxiyn/rust/accurate-span-3, r=luqmanabors-2/+2
2014-01-16Correct span for ExprCall and ExprIndexSeo Sanghyeon-2/+2
2014-01-15auto merge of #11575 : pcwalton/rust/parse-substrs, r=alexcrichtonbors-82/+9
This was used by the quasiquoter. r? @alexcrichton
2014-01-15Issue #3511 - Rationalize temporary lifetimes.Niko Matsakis-13/+66
Major changes: - Define temporary scopes in a syntax-based way that basically defaults to the innermost statement or conditional block, except for in a `let` initializer, where we default to the innermost block. Rules are documented in the code, but not in the manual (yet). See new test run-pass/cleanup-value-scopes.rs for examples. - Refactors Datum to better define cleanup roles. - Refactor cleanup scopes to not be tied to basic blocks, permitting us to have a very large number of scopes (one per AST node). - Introduce nascent documentation in trans/doc.rs covering datums and cleanup in a more comprehensive way.
2014-01-15libsyntax: Remove the obsolete ability to parse from substrings.Patrick Walton-82/+9
This was used by the quasiquoter.
2014-01-15register snapshotsDaniel Micay-7/+0
2014-01-14auto merge of #11485 : eddyb/rust/sweep-old-rust, r=nikomatsakisbors-66/+50
2014-01-13librustc: Remove `@` pointer patterns from the languagePatrick Walton-137/+151
2014-01-13libsyntax: Make managed box `@` patterns obsoletePatrick Walton-3/+12
2014-01-12Bump version to 0.10-preBrian Anderson-1/+1
2014-01-12Removed remnants of `@mut` and `~mut` from comments and the type system.Eduard Burtescu-66/+50
2014-01-11auto merge of #11480 : SiegeLord/rust/float_base, r=cmrbors-11/+16
This fixes the incorrect lexing of things like: ~~~rust let b = 0o2f32; let d = 0o4e6; let f = 0o6e6f32; ~~~ and brings the float literal lexer in line with the description of the float literals in the manual.
2014-01-11auto merge of #11477 : adridu59/rust/bug-report, r=cmrbors-1/+1
Mostly cleanups for doc and READMEs. Fixes the bug reporting link.
2014-01-11Tighten up float literal lexing.SiegeLord-11/+16
Specifically, dissallow setting the number base for every type of float literal, not only those that contain the decimal point. This is in line with the description in the manual.
2014-01-11Various READMEs and docs cleanupAdrien Tétar-1/+1
Noticeably closes #11428.
2014-01-11auto merge of #11252 : eddyb/rust/ty-cleanup, r=pcwaltonbors-4/+4
2014-01-11Removed obsolete 'e' prefix on ty_evec and ty_estr.Eduard Burtescu-4/+4
2014-01-11auto merge of #11463 : brson/rust/envcaps, r=huonwbors-6/+6
Death to caps.
2014-01-10auto merge of #11416 : bjz/rust/remove-print-fns, r=alexcrichtonbors-7/+7
The `print!` and `println!` macros are now the preferred method of printing, and so there is no reason to export the `stdio` functions in the prelude. The functions have also been replaced by their macro counterparts in the tutorial and other documentation so that newcomers don't get confused about what they should be using.
2014-01-10syntax: Fix capitalization in macro_parser errorsBrian Anderson-5/+5
2014-01-10rustc: Fix formatting of env! error messageBrian Anderson-1/+1
Death to caps.
2014-01-11Remove re-exports of std::io::stdio::{print, println} in the prelude.Brendan Zabarauskas-7/+7
The `print!` and `println!` macros are now the preferred method of printing, and so there is no reason to export the `stdio` functions in the prelude. The functions have also been replaced by their macro counterparts in the tutorial and other documentation so that newcomers don't get confused about what they should be using.
2014-01-10item_impl holds an Option<> to the trait ref, not a list of trait refs. ↵Nick Cameron-5/+6
Therefore, we should not iterate over it.
2014-01-09auto merge of #11055 : pcwalton/rust/placement-box, r=pcwaltonbors-1/+31
r? @nikomatsakis
2014-01-09librustc: Implement placement `box` for GC and unique pointers.Patrick Walton-1/+31
2014-01-09libsyntax: Renamed types, traits and enum variants to CamelCase.Eduard Burtescu-2430/+2369
2014-01-09auto merge of #11414 : nick29581/rust/span, r=alexcrichtonbors-1/+2
...at the start of the path, rather than at the start of the view_path. Fixes #11317
2014-01-09auto merge of #11402 : bjz/rust/remove-approx, r=alexcrichtonbors-37/+0
This trait seems to stray too far from the mandate of a standard library as implementations may vary between use cases. Third party libraries should implement their own if they need something like it. This closes #5316. r? @alexcrichton, @pcwalton
2014-01-08Remove the io::Decorator traitAlex Crichton-4/+2
This is just an unnecessary trait that no one's ever going to parameterize over and it's more useful to just define the methods directly on the types themselves. The implementors of this type almost always don't want inner_mut_ref() but they're forced to define it as well.
2014-01-09Start the span for a path in a view_path at the correct place (at the start ↵Nick Cameron-1/+2
of the path, rather than at the start of the view_path).
2014-01-09Remove ApproxEq and assert_approx_eq!Brendan Zabarauskas-37/+0
This trait seems to stray too far from the mandate of a standard library as implementations may vary between use cases.
2014-01-08auto merge of #11401 : michaelwoerister/rust/issue11322, r=alexcrichtonbors-13/+6
`expand_include_str()` in libsyntax seems to have corrupted the CodeMap by always setting the BytePos of any included files to zero. It now uses `CodeMap::new_filemap()` which should set everything properly. This should fix issue #11322 but I don't want to close it before I have confirmation from the reporters that the problem is indeed fixed.
2014-01-08auto merge of #11370 : alexcrichton/rust/issue-10465, r=pwaltonbors-1/+1
Turned out to be a 2-line fix, but the compiler fallout was huge.
2014-01-08Fix CodeMap issue in expand_include_str()Michael Woerister-13/+6
2014-01-08auto merge of #11405 : huonw/rust/moredocs, r=huonwbors-7/+15
Various documentation changes, change the 'borrowed pointer' terminology to 'reference', fix a problem with 'make dist' on windows.
2014-01-07Fixup the rest of the tests in the compilerAlex Crichton-0/+1
2014-01-07Fix remaining cases of leaking importsAlex Crichton-1/+0
2014-01-07doc: Add rustc and syntax to the indexBrian Anderson-4/+12
2014-01-07'borrowed pointer' -> 'reference'Brian Anderson-3/+3
2014-01-08Renamed Option::map_default and mutate_default to map_or and mutate_or_setMarvin Löbel-4/+3
2014-01-06auto merge of #11332 : sfackler/rust/de-at-se, r=huonwbors-61/+60
This is necessary for #11151 to make sure dtors run before the libraries are unloaded.
2014-01-06Disowned the Visitor.Eduard Burtescu-483/+396
2014-01-05Use ~-objects instead of @-objects for syntax extsSteven Fackler-61/+60
This is necessary for #11151 to make sure dtors run before the libraries are unloaded.
2014-01-04auto merge of #11314 : adridu59/rust/patch-license, r=brsonbors-2/+2
- don't check for an hardcoded copyright claim year, check the 2 surrounding strings instead - logic: if either the `//` or `#`-style copyright patterns are found, don't invalidate - cleanup hardcoded content and streamline the few files with different line breaks r? @brson
2014-01-04Don't allow newtype structs to be dereferenced. #6246Brian Anderson-6/+6
2014-01-04etc: licenseck: don't hardcode a specific yearAdrien Tétar-2/+2
2014-01-03libsyntax: Fix tests.Patrick Walton-16/+11
2014-01-03librustc: Remove `@mut` support from the parserPatrick Walton-34/+26