about summary refs log tree commit diff
path: root/src/libsyntax/ext
AgeCommit message (Collapse)AuthorLines
2016-09-07Strip unconfigured nodes in the `InvocationCollector` fold.Jeffrey Seyfried-13/+60
2016-09-05Load macros from `extern crate`s in the `InvocationCollector` fold.Jeffrey Seyfried-62/+22
2016-09-05Implement stackless expansion.Jeffrey Seyfried-173/+189
2016-09-05Add module `ext::placeholders` with `placeholder()` and `PlaceholderExpander`.Jeffrey Seyfried-39/+181
2016-09-05Refactor `expand_invoc(.., fld)` -> `self.expand_invoc(..)`.Jeffrey Seyfried-207/+212
2016-09-05Refactor `SyntaxEnv`.Jeffrey Seyfried-126/+119
2016-09-05Refactor `expand_*` into `expander.fold_*`.Jeffrey Seyfried-214/+194
2016-09-05Clean up module processing.Jeffrey Seyfried-34/+20
2016-09-05Refactor out `expand_item` (with better semantics than before).Jeffrey Seyfried-36/+39
2016-09-05Refactor away `expand_item`.Jeffrey Seyfried-7/+3
2016-09-05Generalize `Invocation` to include modifiers/decorators.Jeffrey Seyfried-95/+138
2016-09-05Refactor `with_exts_frame` from a macro to a function.Jeffrey Seyfried-16/+10
2016-09-05Add `Invocation` and `Expansion`, remove `MacroGenerable`.Jeffrey Seyfried-212/+240
2016-09-05Remove `syntax::config::strip_unconfigured`, add `syntax::config::features`.Jeffrey Seyfried-2/+3
2016-09-05Improve `expand_type`.Jeffrey Seyfried-5/+8
2016-09-05In `Parser` and `ExtCtxt`, replace fields `filename` and `mod_path_stack`Jeffrey Seyfried-31/+22
with a single field `directory: PathBuf`.
2016-09-04Replace `_, _` with `..`Vadim Petrochenkov-2/+2
2016-09-02rustc: Implement custom derive (macros 1.1)Alex Crichton-6/+38
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-08-29Remove inherent methods `Annotatable::attrs` and `Annotatable::fold_attrs`.Jeffrey Seyfried-7/+0
2016-08-28Rollup merge of #35917 - jseyfried:remove_attr_ext_traits, r=nrcJeffrey Seyfried-1/+0
syntax: Remove traits `AttrMetaMethods`, `AttributeMethods`, and `AttrNestedMetaItemMethods`
2016-08-28Rollup merge of #35850 - SergioBenitez:master, r=nrcJeffrey Seyfried-2/+11
Implement RFC#1559: allow all literals in attributes Implemented rust-lang/rfcs#1559, tracked by #34981.
2016-08-28Rollup merge of #35728 - petrochenkov:empderive, r=manishearthJeffrey Seyfried-20/+20
Fix #[derive] for empty tuple structs/variants This was missing from https://github.com/rust-lang/rust/pull/35138
2016-08-28Rollup merge of #35480 - KiChjang:e0379-bonus, r=nikomatsakisJeffrey Seyfried-2/+2
Move E0379 check from typeck to ast validation Part of #35233. Extension of #35338, #35364. Fixes #35404.
2016-08-28Rollup merge of #35618 - jseyfried:ast_view_path_refactor, r=eddybJeffrey Seyfried-1/+1
Refactor `PathListItem`s This refactors away variant `Mod` of `ast::PathListItemKind` and refactors the remaining variant `Ident` to a struct `ast::PathListItem_`.
2016-08-27Change Constness to Spanned<Constness>Keith Yeung-2/+2
2016-08-26Stabilize type-macrosDaniele Baracchi-12/+1
Closes #27245
2016-08-25Refactor away `AttrMetaMethods`.Jeffrey Seyfried-1/+0
2016-08-25Implement RFC#1559: allow all literals in attributes.Sergio Benitez-2/+11
2016-08-21Refactor away variant `ast::PathListItemKind::Mod`Jeffrey Seyfried-1/+1
and refactor `ast::PathListItemKind::Ident` -> `ast::PathListItem_`.
2016-08-18Split `AstBuilder::pat_enum` into `pat_tuple_struct` and `pat_path`Vadim Petrochenkov-20/+20
2016-08-18Fix #[derive] for empty tuple structs/variantsVadim Petrochenkov-1/+1
2016-08-16Auto merge of #35538 - cgswords:libproc_macro, r=nrcbors-0/+69
Kicking off libproc_macro This PR introduces `libproc_macro`, which is currently quite bare-bones (just a few macro construction tools and an initial `quote!` macro). This PR also introduces a few test cases for it, and an additional `shim` file (at `src/libsyntax/ext/proc_macro_shim.rs` to allow a facsimile usage of Macros 2.0 *today*!
2016-08-16Proc_macro is alivecgswords-0/+69
2016-08-13Auto merge of #35453 - jseyfried:hygienize_metavariables, r=nrcbors-12/+12
macros: Make metavariables hygienic This PR makes metavariables hygienic. For example, consider: ```rust macro_rules! foo { ($x:tt) => { // Suppose that this token tree argument is always a metavariable. macro_rules! bar { ($x:expr, $y:expr) => { ($x, $y) } } } } fn main() { foo!($z); // This currently compiles. foo!($y); // This is an error today but compiles after this PR. } ``` Today, the `macro_rules! bar { ... }` definition is only valid when the metavariable passed to `foo` is not `$y` (since it unhygienically conflicts with the `$y` in the definition of `bar`) or `$x` (c.f. #35450). After this PR, the definition of `bar` is always valid (and `bar!(a, b)` always expands to `(a, b)` as expected). This can break code that was allowed in #34925 (landed two weeks ago). For example, ```rust macro_rules! outer { ($t:tt) => { macro_rules! inner { ($i:item) => { $t } } } } outer!($i); // This `$i` should not interact with the `$i` in the definition of `inner!`. inner!(fn main() {}); // After this PR, this is an error ("unknown macro variable `i`"). ``` Due to the severe limitations on nested `macro_rules!` before #34925, this is not a breaking change for stable/beta. Fixes #35450. r? @nrc
2016-08-11Auto merge of #34811 - DanielJCampbell:Expander, r=jseyfriedbors-42/+80
Extended expand.rs to support alternate expansion behaviours (eg. stepwise expansion) r? nrc
2016-08-10Extended expand.rs to support alternate expansion behavioursDaniel Campbell-42/+80
Added single_step & keep_macs flags and functionality to expander
2016-08-07Make metavariables hygienic.Jeffrey Seyfried-12/+12
2016-07-29Auto merge of #34842 - cgswords:attr_enc, r=nrcbors-20/+8
Better attribute and metaitem encapsulation throughout the compiler This PR refactors most (hopefully all?) of the `MetaItem` interactions outside of `libsyntax` (and a few inside) to interact with MetaItems through the provided traits instead of directly creating / destruct / matching against them. This is a necessary first step to eventually converting `MetaItem`s to internally use `TokenStream` representations (which will make `MetaItem` interactions much nicer for macro writers once the new macro system is in place). r? @nrc
2016-07-25General MetaItem encapsulation rewrites.cgswords-20/+8
2016-07-23macros: Improve `tt` fragmentsJeffrey Seyfried-3/+13
2016-07-19Introduced `NoDelim` and modified the compiler to support it.cgswords-3/+4
2016-07-17Auto merge of #34860 - jseyfried:encapsulate_hygiene, r=nrcbors-183/+131
Clean up and encapsulate `syntax::ext::mtwt`, rename `mtwt` to `hygiene` r? @nrc
2016-07-17Remove some unit tests and that are redundant with `run-pass/hygiene.rs`Jeffrey Seyfried-35/+0
and that would be painful to rewrite.
2016-07-17Rename `mtwt` to `hygiene`Jeffrey Seyfried-2/+2
2016-07-17Clean up and encapsulate `syntax::ext::mtwt`Jeffrey Seyfried-108/+91
2016-07-16Auto merge of #34816 - jseyfried:fix_include_path, r=nrcbors-0/+6
Fix `include!()`s inside `asm!()` invocations Fixes #34812, a regression caused by #33749 that was not fixed in #34450. r? @nrc
2016-07-15Auto merge of #34570 - jseyfried:no_rename, r=nrcbors-654/+62
Simplify the macro hygiene algorithm This PR removes renaming from the hygiene algorithm and treats differently marked identifiers as unequal. This change makes the scope of identifiers in `macro_rules!` items empty. That is, identifiers in `macro_rules!` definitions do not inherit any semantics from the `macro_rules!`'s scope. Since `macro_rules!` macros are items, the scope of their identifiers "should" be the same as that of other items; in particular, the scope should contain only items. Since all items are unhygienic today, this would mean the scope should be empty. However, the scope of an identifier in a `macro_rules!` statement today is the scope that the identifier would have if it replaced the `macro_rules!` (excluding anything unhygienic, i.e. locals only). To continue to support this, this PR tracks the scope of each `macro_rules!` and uses it in `resolve` to ensure that an identifier expanded from a `macro_rules!` gets a chance to resolve to the locals in the `macro_rules!`'s scope. This PR is a pure refactoring. After this PR, - `syntax::ext::expand` is much simpler. - We can expand macros in any order without causing problems for hygiene (needed for macro modularization). - We can deprecate or remove today's `macro_rules!` scope easily. - Expansion performance improves by 25%, post-expansion memory usage decreases by ~5%. - Expanding a block is no longer quadratic in the number of `let` statements (fixes #10607). r? @nrc
2016-07-14Make `ext::base::expr_to_string` work correctly with `include!` macro ↵Jeffrey Seyfried-0/+6
invocations
2016-07-14Remove irrelevant testsJeffrey Seyfried-151/+3
2016-07-14Implement `macro_rules!` placeholders and the macro scope mapJeffrey Seyfried-7/+42