Commit Graph

25773 Commits

Author SHA1 Message Date
klutzy
f30a9b3d5b rustc::driver: Capitalize structs and enums
driver::session::crate_metadata is unused; removed.
2014-01-17 13:27:47 +09:00
bors
58a15f3d5a auto merge of #11584 : alexcrichton/rust/issue-3862, r=brson
Turns out there is no documentation of a block expression in the rust manual currently! I deleted the "record expressions" section to make room for a "block expressions" section.

Closes #3862
2014-01-16 19:21:45 -08:00
bors
80a3f453db auto merge of #11151 : sfackler/rust/ext-crate, r=alexcrichton
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-16 16:36:53 -08:00
Niko Matsakis
5e7657fafb Distinguish zero-size types from those that we return as void 2014-01-16 19:10:17 -05:00
Niko Matsakis
76c90283ce Fix uninit() intrinsic when used with empty types 2014-01-16 18:47:42 -05:00
Niko Matsakis
fd318300cf Fix test to account for new temporary lifetime rules, which cause the channel to be dropped prematurely. 2014-01-16 18:47:22 -05:00
Steven Fackler
328b47d837 Load macros from external modules 2014-01-16 15:01:48 -08:00
Niko Matsakis
4b52d899ff Further refine treatment of voidish arrays 2014-01-16 16:29:52 -05:00
Alex Crichton
afa392a840 Forbid coercing unsafe functions to closures
Closes #9582
2014-01-16 12:20:59 -08:00
Alex Crichton
11dcd9a097 Don't run 'ar s' on OSX
Apparently this isn't necessary, and it's just causing problems.

Closes #11162
2014-01-16 12:18:22 -08:00
Niko Matsakis
14b0abfd82 Consider all zero-sized data structures to be voidish, bypassing some "quirky" parts of LLVM (see e.g. LLVM bug 9900) but also generating better code 2014-01-16 15:11:22 -05:00
bors
61416626ac auto merge of #11571 : derekchiang/rust/fix-task-docs, r=alexcrichton
There might be a reason, but I failed to see why these comments couldn't be proper rust docs.
2014-01-16 11:26:40 -08:00
Alex Crichton
421d24582d Document blocks and use statements a little more
Closes #3862
2014-01-16 09:48:59 -08:00
bors
9434e7c6cb auto merge of #11599 : sanxiyn/rust/accurate-span-3, r=luqmana 2014-01-16 09:01:49 -08:00
Derek Guenther
8f4edf9bf8 Update test run summary 2014-01-16 09:36:34 -06:00
bors
fa91446b2b auto merge of #11597 : sfackler/rust/err-enums, r=alexcrichton
An enum allows callers to deal with errors in a more reasonable way.
2014-01-16 07:06:58 -08:00
bors
f63a7f598a auto merge of #11596 : derekchiang/rust/fix-libnative-docs, r=alexcrichton 2014-01-16 05:51:44 -08:00
Seo Sanghyeon
1f5dc552d6 Correct span for ExprCall and ExprIndex 2014-01-16 22:45:01 +09:00
bors
e6a27424ad auto merge of #11590 : vadimcn/rust/llvm-tools, r=alexcrichton
Closes #10893 - because we'll no longer build llvm-c-test
2014-01-16 04:31:52 -08:00
bors
142ee5fc55 auto merge of #11588 : am0d/rust/dox, r=brson
This is a bit cleaner and means we don't need whitespace at the end of each line to force line breaks.
2014-01-16 03:06:48 -08:00
Niko Matsakis
7ff6b094fb Remove typo 2014-01-16 05:56:56 -05:00
bors
6361c1dee5 auto merge of #11579 : kballard/rust/windows-path-join, r=erickt
WindowsPath::new("C:").join("a") produces r"C:". This is incorrect.
It should produce "C:a".
2014-01-16 00:51:44 -08:00
Steven Fackler
9fe5d1620c Stop returning error strings in From{Base64,Hex}
An enum allows callers to deal with errors in a more reasonable way.
2014-01-15 23:15:04 -08:00
Derek Chiang
0e94ae4d8a Fix some docs in std::rt::task 2014-01-16 14:24:04 +08:00
Derek Chiang
f98f76e3a7 Fixing a typo: bookeeping -> bookkeeping 2014-01-16 14:17:56 +08:00
Div Shekhar
8f93d39c75 doc: add note below diagram about memory layout. 2014-01-15 22:02:48 -08:00
bors
793f740c0a auto merge of #11575 : pcwalton/rust/parse-substrs, r=alexcrichton
This was used by the quasiquoter.

r? @alexcrichton
2014-01-15 21:51:42 -08:00
Div Shekhar
065f936bf1 doc: Boxes diagram shows enum value inside box. 2014-01-15 21:46:02 -08:00
bors
6708558c34 auto merge of #11548 : bjz/rust/bitwise, r=alexcrichton
One less trait in `std::num` and three less exported in the prelude.

cc. #10387
2014-01-15 20:36:48 -08:00
bors
bf2ab22cd0 auto merge of #11574 : neeee/rust/master, r=alexcrichton
Reverted according to https://github.com/mozilla/rust/issues/11458#issuecomment-32269477. Fixes #11458.
2014-01-15 19:06:45 -08:00
a_m0d
c6268384a6 Update docs index to use lists
Also include a missing link to the rustdoc manual
2014-01-15 20:54:34 -05:00
Vadim Chugunov
62fbd00bed Only build LLVM tools Rust needs. 2014-01-15 17:47:48 -08:00
bors
a5ed0c58cb auto merge of #11565 : mozilla/rust/snapshot, r=huonw 2014-01-15 17:46:42 -08:00
Niko Matsakis
84f33fb134 Cleanup trait callees 2014-01-15 20:31:20 -05:00
Brendan Zabarauskas
1dd6906db2 Merge Bitwise and BitCount traits and remove from prelude, along with Bounded
One less trait in std::num, and three less exported in the prelude.
2014-01-16 11:51:33 +11:00
Niko Matsakis
6badef49fe Remove FIXMEs and add license 2014-01-15 19:44:38 -05:00
Niko Matsakis
e71571a3cd Use as_slice() method on option 2014-01-15 19:35:38 -05:00
bors
36971217aa auto merge of #11568 : FlaPer87/rust/even, r=alexcrichton
This implementation should be a bit more optimal than calling `self.is_multiple_of(&2)`
2014-01-15 16:02:01 -08:00
Niko Matsakis
419ac4a1b8 Issue #3511 - Rationalize temporary lifetimes.
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-15 18:34:38 -05:00
bors
149fc76698 auto merge of #11550 : alexcrichton/rust/noinline, r=thestinger
The failure functions are generic, meaning they're candidates for getting
inlined across crates. This has been happening, leading to monstrosities like
that found in #11549. I have verified that the codegen is *much* better now that
we're not inlining the failure path (the slow path).
2014-01-15 13:51:50 -08:00
Kevin Ballard
c57920b37b path: Fix joining Windows path when the receiver is "C:"
WindowsPath::new("C:").join("a") produces r"C:\a". This is incorrect.
It should produce "C:a".
2014-01-15 12:53:56 -08:00
bors
7ce3386511 auto merge of #11112 : alexcrichton/rust/issue-11087, r=brson
This should allow callers to know whether the channel was empty or disconnected
without having to block.

Closes #11087
2014-01-15 12:37:00 -08:00
Carl-Anton Ingmarsson
f4c9ed42aa fixup! ebml::extra: Optimize reader::vuint_at() 2014-01-15 20:58:41 +01:00
Alex Crichton
adb895a34f Allow more "error" values in try_recv()
This should allow callers to know whether the channel was empty or disconnected
without having to block.

Closes #11087
2014-01-15 11:21:56 -08:00
bors
f60d937dd9 auto merge of #11543 : thestinger/rust/gc, r=cmr
This type isn't yet very useful since it only pretends cycles won't be
a problem. Anyone using it should be made aware that they're going to
leak.
2014-01-15 11:21:45 -08:00
Patrick Walton
ff6c0af15b libsyntax: Remove the obsolete ability to parse from substrings.
This was used by the quasiquoter.
2014-01-15 10:59:48 -08:00
Flavio Percoco
515978d1bd Use the least significant beat to determine if int/uint is even 2014-01-15 19:11:00 +01:00
bors
7cb2aa2429 auto merge of #11523 : alexcrichton/rust/stage3, r=brson
This should go back to the old behavior while preserving the snapshot ease.
2014-01-15 09:51:46 -08:00
lucy
3b32ea8c93 Revert "show options for -W help and -W". Fixes #11458.
This reverts commit 1009c21ad7.
2014-01-15 18:38:10 +01:00
Alex Crichton
7a37294acc Add a configure to disable libstd version injection
We'll use this when building snapshots so we can upgrade freely, but all
compilers will inject a version by default.
2014-01-15 08:22:16 -08:00