Commit Graph

56812 Commits

Author SHA1 Message Date
Alex Crichton
ecc6c39e87 rustc: Implement custom derive (macros 1.1)
This commit is an implementation of [RFC 1681] which adds support to the
compiler for first-class user-define custom `#[derive]` modes with a far more
stable API than plugins have today.

[RFC 1681]: https://github.com/rust-lang/rfcs/blob/master/text/1681-macros-1.1.md

The main features added by this commit are:

* A new `rustc-macro` crate-type. This crate type represents one which will
  provide custom `derive` implementations and perhaps eventually flower into the
  implementation of macros 2.0 as well.

* A new `rustc_macro` crate in the standard distribution. This crate will
  provide the runtime interface between macro crates and the compiler. The API
  here is particularly conservative right now but has quite a bit of room to
  expand into any manner of APIs required by macro authors.

* The ability to load new derive modes through the `#[macro_use]` annotations on
  other crates.

All support added here is gated behind the `rustc_macro` feature gate, both for
the library support (the `rustc_macro` crate) as well as the language features.

There are a few minor differences from the implementation outlined in the RFC,
such as the `rustc_macro` crate being available as a dylib and all symbols are
`dlsym`'d directly instead of having a shim compiled. These should only affect
the implementation, however, not the public interface.

This commit also ended up touching a lot of code related to `#[derive]`, making
a few notable changes:

* Recognized derive attributes are no longer desugared to `derive_Foo`. Wasn't
  sure how to keep this behavior and *not* expose it to custom derive.

* Derive attributes no longer have access to unstable features by default, they
  have to opt in on a granular level.

* The `derive(Copy,Clone)` optimization is now done through another "obscure
  attribute" which is just intended to ferry along in the compiler that such an
  optimization is possible. The `derive(PartialEq,Eq)` optimization was also
  updated to do something similar.

---

One part of this PR which needs to be improved before stabilizing are the errors
and exact interfaces here. The error messages are relatively poor quality and
there are surprising spects of this such as `#[derive(PartialEq, Eq, MyTrait)]`
not working by default. The custom attributes added by the compiler end up
becoming unstable again when going through a custom impl.

Hopefully though this is enough to start allowing experimentation on crates.io!

syntax-[breaking-change]
2016-09-02 12:52:56 -07:00
johnthagen
eb1c7161dd Update supported Windows versions to match Getting Started page. 2016-09-02 15:32:13 -04:00
Jared Roesch
9510add6a3 Remove illegal bound from doc test 2016-09-02 11:58:02 -07:00
Jared Roesch
6eb06e6770 Forget to update tests to use new error message 2016-09-02 11:58:02 -07:00
Jared Roesch
ed5843bcc6 Address feedback on secondary changes 2016-09-02 11:58:02 -07:00
Jared Roesch
90d1a53551 Address feedback, and remove invalid tests 2016-09-02 11:58:02 -07:00
Jared Roesch
352fac95ad Reject certain auto trait declarations
Fixes #29859
2016-09-02 11:58:02 -07:00
Jared Roesch
f18c99072e Add tests for #29859 2016-09-02 11:58:02 -07:00
Federico Ravasio
059094f3f2 Moved test on E0493 from compile-fail to ui. 2016-09-02 19:55:14 +02:00
Corey Farwell
3a96fe3275 Transition Travis CI to use rustbuild. 2016-09-02 12:48:55 -04:00
bors
ef9786ce0e Auto merge of #36084 - apasel422:counter, r=bluss
Address FIXME in libcollectionstest/btree/set.rs
2016-09-02 09:13:00 -07:00
bors
689c6c48ec Auto merge of #36024 - japaric:mips64, r=alexcrichton
add mips64-gnu and mips64el-gnu targets

With this commit one can build no_core (and probably no_std as well)
Rust programs for these targets. It's not yet possible to cross compile
std for these targets because rust-lang/libc doesn't know about the
mips64 architecture.

These targets have been tested by cross compiling the "smallest hello"
program (see code below) and then running it under QEMU.

``` rust

extern {
    fn puts(_: *const u8);
}

fn start(_: isize, _: *const *const u8) -> isize {
    unsafe {
        let msg = b"Hello, world!\0";
        puts(msg as *const _ as *const u8);
    }
    0
}

trait Copy {}

trait Sized {}
```

cc #36015
r? @alexcrichton
cc @brson

The cabi stuff is likely wrong. I just copied cabi_mips source and changed some `4`s to `8`s and `32`s to `64`s. It was enough to get libc's `puts` to work but I'd like someone familiar with this module to check it.
2016-09-02 03:01:48 -07:00
Federico Ravasio
ed5e5df596 E0493: showing a label where the destructor is defined. 2016-09-02 11:44:46 +02:00
Ahmed Charles
cd8f0aa7f2 Remove --{enable|disable}-orbit from configure.
Fixes #35956.
2016-09-02 01:57:31 -07:00
bors
022cb6d11d Auto merge of #35915 - llogiq:rfc-1623, r=nikomatsakis
implementing RFC 1623. This fixes #35897.

This is a work in progress. In particular, I want to add more tests,
especially the compile-fail test is very bare-bones.
2016-09-01 22:24:36 -07:00
Eugene R Gonzalez
7f95bb0dbd Fixed E0529's label and unit test 2016-09-01 22:35:25 -04:00
bors
8aeb15acc7 Auto merge of #35894 - jseyfried:new_import_semantics, r=nrc
Implement RFC 1560 behind `#![feature(item_like_imports)]`

This implements https://github.com/rust-lang/rfcs/pull/1560 (cc #35120) behind the `item_like_imports` feature gate.

The [RFC text](https://github.com/rust-lang/rfcs/blob/master/text/1560-name-resolution.md#changes-to-name-resolution-rules) describes the changes to name resolution enabled by `#![feature(item_like_imports)` in detail. To summarize,
 - Items and named imports shadow glob imports.
 - Multiple globs can import the same name if the name is unused or the imports are shadowed.
 - Multiple globs can import the same name if the imports are of the same item (following re-exports).
  - The visibility of such a name is the maximum visibility of the imports.
  - Equivalently, adding a glob import will never reduce the visibility of a name, nor will removing one increase it.
 - Non-prelude private imports can be used wherever we currently allow private items to be used.
  - Prelude-imported names are unaffected, i.e. they continue to be usable only in lexical scopes.
 - Globs import all visible names, not just public names.
  - Equivalently, glob importing from an ancestor module imports all of the ancestor's names, and glob importing from other modules is unchanged.

r? @nrc
2016-09-01 19:03:27 -07:00
Jeffrey Seyfried
90ce504c1c Address comments. 2016-09-02 00:35:16 +00:00
Alex Crichton
96283fc083 test: Add a min-llvm-version directive
We've got tests which require a particular version of LLVM to run as they're
testing bug fixes. Our build system, however, supports multiple LLVM versions,
so we can't run these tests on all LLVM versions.

This adds a new `min-llvm-version` directive for tests so they can opt out of
being run on older versions of LLVM. This then namely applies that logic to the
`issue-36023.rs` test case and...

Closes #36138
2016-09-01 16:14:17 -07:00
Eugene R Gonzalez
7cd4e7ff0b Fixed E0528 label and unit test 2016-09-01 19:08:07 -04:00
Jeffrey Seyfried
4f5616e3c4 Avoid cascading name resolution errors caused by an ambiguous module. 2016-09-01 22:30:29 +00:00
Jeffrey Seyfried
32a0cfeb48 Avoid reporting multiple ambiguity errors for a single use of a name. 2016-09-01 22:30:28 +00:00
Jeffrey Seyfried
681a14f29b item_like_imports: Allow unused ambiguous glob imports. 2016-09-01 22:30:27 +00:00
Jeffrey Seyfried
f582fa327e item_like_imports: Allow multiple glob imports of the same item. 2016-09-01 22:30:26 +00:00
Jeffrey Seyfried
245a0c5530 item_like_imports: Make all visible items glob importable. 2016-09-01 22:30:26 +00:00
Jeffrey Seyfried
097b6d62fc item_like_imports: Allow glob imports with a given visibility
to reexport some (but not all) names with less visibility.
2016-09-01 22:30:25 +00:00
Jeffrey Seyfried
c56a5afd4d item_like_imports: Allow single imports with a given visibility
to reexport some (but not all) namespaces with less visibility.
2016-09-01 22:30:24 +00:00
Jeffrey Seyfried
aad1f3cbf3 item_like_imports: Allow glob imports to be shadowed by items and single imports. 2016-09-01 22:30:24 +00:00
Jeffrey Seyfried
efc0bea687 item_like_imports: Treat private imports like private items. 2016-09-01 22:30:21 +00:00
Jeffrey Seyfried
5ba22c0ed6 Add item_like_imports feature. 2016-09-01 22:29:50 +00:00
Jeffrey Seyfried
513e955a18 Add field dummy_binding to Resolver. 2016-09-01 22:29:30 +00:00
Jeffrey Seyfried
95528d1a98 Refactor away resolver.current_vis and add module.normal_ancestor_id. 2016-09-01 22:29:29 +00:00
Jeffrey Seyfried
1e4c8173e1 Improve diagnostics and remove dead code. 2016-09-01 22:29:28 +00:00
Jeffrey Seyfried
87ae68c1d6 Refactor binding.def() to return a Def instead of an Option<Def>. 2016-09-01 22:29:27 +00:00
Jeffrey Seyfried
691d10c3c9 Rename new_binding -> binding. 2016-09-01 22:29:27 +00:00
Jeffrey Seyfried
5dc1196191 Refactor away binding.is_pseudo_public(). 2016-09-01 22:29:26 +00:00
Jeffrey Seyfried
48a435a90f Fix test compile-fail/task-rng-isnt-sendable.rs. 2016-09-01 22:29:25 +00:00
bors
497d67d708 Auto merge of #35761 - nikomatsakis:faster-trans-fulfill-obligation, r=eddyb
Cache projections in trans

This introduces a cache for the results of projection and normalization in trans. This is in addition to the existing cache that is per-inference-context. Trans is an easy place to put the cache because we are guaranteed not to have type parameters and also we don't expect any failures or inference variables, so there is no need to cache or follow-up on obligations that come along with.  (As evidenced by the fact that this particular code would panic if any error occurred.)

That said, I am not sure this is 100% the best place for it; I sort of wanted a cache like we have in the fulfillment context for global names; but that cache only triggers when all subsequent obligations are satisfied, and since projections don't have an entry in the obligation jungle there is no easy place to put it. I considered caching both the result and obligations globally, but haven't really tried implementing it. It might be a good next step.

Regardless, this cache seems to have no real effect on bootstrap time (maybe a slight improvement), but on [the futures.rs test case I was looking at](https://github.com/rust-lang-nursery/rustc-benchmarks/pull/6), it improves performance quite a bit:

| phase | before | after |
| ----- | ------ | ----- |
| collection | 0.79s | 0.46s |
| translation | 6.8s | 3.2s |
| total | 11.92s | 7.15s |

r? @arielb1
2016-09-01 15:25:58 -07:00
c4rlo
66ae481055 README.md: fix a "\" in table heading to be "/" 2016-09-01 22:42:51 +01:00
bors
933f471710 Auto merge of #34494 - CensoredUsername:allow_sysV64_abi, r=nagisa
Allow specification of the system V AMD64 ABI constraint.

This can be specified using `extern "sysV64" fn` on all platforms.

This ABI is used as the C ABI on unix platforms, but can only be specified there using extern "C". It was impossible to specify on other platforms. Meanwhile the win64 ABI, which was the extern "C" ABI on the windows platform could be specified on other platforms using extern "win64".

This pull request adds the the "sysV64" ABI constraint which exposes this calling convention on platforms where it is not the C ABI.
2016-09-01 11:56:51 -07:00
Michael Woerister
7310a8ffea ICH: Adapt to changes in the MetaItem AST representation. 2016-09-01 14:39:31 -04:00
Florian Gilcher
0f8eb81011 Document try!'s error conversion behaviour 2016-09-01 19:16:19 +02:00
Michael Woerister
8cbd6fe331 ICH: Share codemap cache between subsequent runs of the ICH visitor. 2016-09-01 09:43:44 -04:00
Michael Woerister
2faca22bd3 ICH: Fix codemap lookup caching. 2016-09-01 09:43:44 -04:00
Michael Woerister
a142d2ff02 ICH: Fix bug in hash_discriminant() and visit_vis(). 2016-09-01 09:43:44 -04:00
Michael Woerister
0310e3444b ICH: Take CaptureClause of closure expressions into account. 2016-09-01 09:43:44 -04:00
Michael Woerister
500ab357c2 ICH: Cleanup some comments. 2016-09-01 09:43:44 -04:00
Michael Woerister
6785256557 ICH: Don't hash span expansion kind twice. 2016-09-01 09:43:44 -04:00
Michael Woerister
5dd36bd486 Rename CacheCodemapView to CachingCodemapView. 2016-09-01 09:43:44 -04:00
Michael Woerister
1cfd7c3654 incr.comp.: Ignore doc-comments when computing the ICH. 2016-09-01 09:43:44 -04:00