2019-08-17 20:49:00 +03:00
|
|
|
use crate::ast::{self, NodeId, Attribute, Name, PatKind};
|
2019-08-20 21:22:32 +03:00
|
|
|
use crate::attr::{self, HasAttrs, Stability, Deprecation};
|
2019-08-15 01:56:44 +03:00
|
|
|
use crate::source_map::SourceMap;
|
2019-02-07 02:33:01 +09:00
|
|
|
use crate::edition::Edition;
|
|
|
|
use crate::ext::expand::{self, AstFragment, Invocation};
|
2019-08-28 12:41:29 +03:00
|
|
|
use crate::ext::hygiene::ExpnId;
|
2019-02-07 02:33:01 +09:00
|
|
|
use crate::mut_visit::{self, MutVisitor};
|
2019-08-20 21:22:32 +03:00
|
|
|
use crate::parse::{self, parser, ParseSess, DirectoryOwnership};
|
2019-02-07 02:33:01 +09:00
|
|
|
use crate::parse::token;
|
|
|
|
use crate::ptr::P;
|
2019-05-11 17:41:37 +03:00
|
|
|
use crate::symbol::{kw, sym, Ident, Symbol};
|
2019-05-21 22:17:53 -07:00
|
|
|
use crate::{ThinVec, MACRO_ARGUMENTS};
|
2019-08-31 20:08:06 +03:00
|
|
|
use crate::tokenstream::{self, TokenStream};
|
2019-08-24 21:12:13 +03:00
|
|
|
use crate::visit::Visitor;
|
2019-02-07 02:33:01 +09:00
|
|
|
|
2019-02-09 11:24:02 +09:00
|
|
|
use errors::{DiagnosticBuilder, DiagnosticId};
|
2019-02-07 02:33:01 +09:00
|
|
|
use smallvec::{smallvec, SmallVec};
|
2019-07-18 01:49:10 +03:00
|
|
|
use syntax_pos::{FileName, Span, MultiSpan, DUMMY_SP};
|
2019-08-25 20:58:03 +01:00
|
|
|
use syntax_pos::hygiene::{AstPass, ExpnData, ExpnKind};
|
2012-12-23 17:41:37 -05:00
|
|
|
|
2018-08-18 13:55:43 +03:00
|
|
|
use rustc_data_structures::fx::FxHashMap;
|
2019-02-07 02:33:01 +09:00
|
|
|
use rustc_data_structures::sync::{self, Lrc};
|
2017-12-06 10:50:55 -08:00
|
|
|
use std::iter;
|
2016-08-31 09:02:45 +00:00
|
|
|
use std::path::PathBuf;
|
2014-07-19 21:34:24 +02:00
|
|
|
use std::rc::Rc;
|
2016-08-29 16:16:43 +12:00
|
|
|
use std::default::Default;
|
2011-06-04 15:41:45 -04:00
|
|
|
|
2019-06-19 01:00:49 +03:00
|
|
|
pub use syntax_pos::hygiene::MacroKind;
|
2014-02-27 23:49:25 -08:00
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Debug,Clone)]
|
2014-12-02 10:07:41 -08:00
|
|
|
pub enum Annotatable {
|
|
|
|
Item(P<ast::Item>),
|
2015-03-10 12:28:44 +02:00
|
|
|
TraitItem(P<ast::TraitItem>),
|
|
|
|
ImplItem(P<ast::ImplItem>),
|
2018-03-10 18:16:26 -08:00
|
|
|
ForeignItem(P<ast::ForeignItem>),
|
2018-03-15 23:20:56 -07:00
|
|
|
Stmt(P<ast::Stmt>),
|
|
|
|
Expr(P<ast::Expr>),
|
2019-09-09 09:26:25 -03:00
|
|
|
Arm(ast::Arm),
|
|
|
|
Field(ast::Field),
|
|
|
|
FieldPat(ast::FieldPat),
|
|
|
|
GenericParam(ast::GenericParam),
|
|
|
|
Param(ast::Param),
|
|
|
|
StructField(ast::StructField),
|
|
|
|
Variant(ast::Variant),
|
2014-12-02 10:07:41 -08:00
|
|
|
}
|
|
|
|
|
2016-06-12 12:45:16 +00:00
|
|
|
impl HasAttrs for Annotatable {
|
2016-09-07 23:21:59 +00:00
|
|
|
fn attrs(&self) -> &[Attribute] {
|
2014-12-02 10:07:41 -08:00
|
|
|
match *self {
|
2016-06-12 12:45:16 +00:00
|
|
|
Annotatable::Item(ref item) => &item.attrs,
|
|
|
|
Annotatable::TraitItem(ref trait_item) => &trait_item.attrs,
|
|
|
|
Annotatable::ImplItem(ref impl_item) => &impl_item.attrs,
|
2018-03-10 18:16:26 -08:00
|
|
|
Annotatable::ForeignItem(ref foreign_item) => &foreign_item.attrs,
|
2018-03-15 23:20:56 -07:00
|
|
|
Annotatable::Stmt(ref stmt) => stmt.attrs(),
|
|
|
|
Annotatable::Expr(ref expr) => &expr.attrs,
|
2019-09-09 09:26:25 -03:00
|
|
|
Annotatable::Arm(ref arm) => &arm.attrs,
|
|
|
|
Annotatable::Field(ref field) => &field.attrs,
|
|
|
|
Annotatable::FieldPat(ref fp) => &fp.attrs,
|
|
|
|
Annotatable::GenericParam(ref gp) => &gp.attrs,
|
|
|
|
Annotatable::Param(ref p) => &p.attrs,
|
|
|
|
Annotatable::StructField(ref sf) => &sf.attrs,
|
|
|
|
Annotatable::Variant(ref v) => &v.attrs(),
|
2014-12-02 10:07:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn visit_attrs<F: FnOnce(&mut Vec<Attribute>)>(&mut self, f: F) {
|
2014-12-02 10:07:41 -08:00
|
|
|
match self {
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
Annotatable::Item(item) => item.visit_attrs(f),
|
|
|
|
Annotatable::TraitItem(trait_item) => trait_item.visit_attrs(f),
|
|
|
|
Annotatable::ImplItem(impl_item) => impl_item.visit_attrs(f),
|
|
|
|
Annotatable::ForeignItem(foreign_item) => foreign_item.visit_attrs(f),
|
|
|
|
Annotatable::Stmt(stmt) => stmt.visit_attrs(f),
|
|
|
|
Annotatable::Expr(expr) => expr.visit_attrs(f),
|
2019-09-09 09:26:25 -03:00
|
|
|
Annotatable::Arm(arm) => arm.visit_attrs(f),
|
|
|
|
Annotatable::Field(field) => field.visit_attrs(f),
|
|
|
|
Annotatable::FieldPat(fp) => fp.visit_attrs(f),
|
|
|
|
Annotatable::GenericParam(gp) => gp.visit_attrs(f),
|
|
|
|
Annotatable::Param(p) => p.visit_attrs(f),
|
|
|
|
Annotatable::StructField(sf) => sf.visit_attrs(f),
|
|
|
|
Annotatable::Variant(v) => v.visit_attrs(f),
|
2014-12-02 10:07:41 -08:00
|
|
|
}
|
|
|
|
}
|
2016-06-12 12:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Annotatable {
|
2017-03-17 04:04:41 +00:00
|
|
|
pub fn span(&self) -> Span {
|
|
|
|
match *self {
|
|
|
|
Annotatable::Item(ref item) => item.span,
|
|
|
|
Annotatable::TraitItem(ref trait_item) => trait_item.span,
|
|
|
|
Annotatable::ImplItem(ref impl_item) => impl_item.span,
|
2018-03-10 18:16:26 -08:00
|
|
|
Annotatable::ForeignItem(ref foreign_item) => foreign_item.span,
|
2018-03-15 23:20:56 -07:00
|
|
|
Annotatable::Stmt(ref stmt) => stmt.span,
|
|
|
|
Annotatable::Expr(ref expr) => expr.span,
|
2019-09-09 09:26:25 -03:00
|
|
|
Annotatable::Arm(ref arm) => arm.span,
|
|
|
|
Annotatable::Field(ref field) => field.span,
|
|
|
|
Annotatable::FieldPat(ref fp) => fp.pat.span,
|
|
|
|
Annotatable::GenericParam(ref gp) => gp.ident.span,
|
|
|
|
Annotatable::Param(ref p) => p.span,
|
|
|
|
Annotatable::StructField(ref sf) => sf.span,
|
|
|
|
Annotatable::Variant(ref v) => v.span,
|
2017-03-17 04:04:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 21:12:13 +03:00
|
|
|
pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) {
|
|
|
|
match self {
|
|
|
|
Annotatable::Item(item) => visitor.visit_item(item),
|
|
|
|
Annotatable::TraitItem(trait_item) => visitor.visit_trait_item(trait_item),
|
|
|
|
Annotatable::ImplItem(impl_item) => visitor.visit_impl_item(impl_item),
|
|
|
|
Annotatable::ForeignItem(foreign_item) => visitor.visit_foreign_item(foreign_item),
|
|
|
|
Annotatable::Stmt(stmt) => visitor.visit_stmt(stmt),
|
|
|
|
Annotatable::Expr(expr) => visitor.visit_expr(expr),
|
2019-09-09 09:26:25 -03:00
|
|
|
Annotatable::Arm(arm) => visitor.visit_arm(arm),
|
|
|
|
Annotatable::Field(field) => visitor.visit_field(field),
|
|
|
|
Annotatable::FieldPat(fp) => visitor.visit_field_pattern(fp),
|
|
|
|
Annotatable::GenericParam(gp) => visitor.visit_generic_param(gp),
|
|
|
|
Annotatable::Param(p) => visitor.visit_param(p),
|
|
|
|
Annotatable::StructField(sf) =>visitor.visit_struct_field(sf),
|
|
|
|
Annotatable::Variant(v) => visitor.visit_variant(v),
|
2019-08-24 21:12:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 10:07:41 -08:00
|
|
|
pub fn expect_item(self) -> P<ast::Item> {
|
|
|
|
match self {
|
|
|
|
Annotatable::Item(i) => i,
|
|
|
|
_ => panic!("expected Item")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 17:34:39 +12:00
|
|
|
pub fn map_item_or<F, G>(self, mut f: F, mut or: G) -> Annotatable
|
|
|
|
where F: FnMut(P<ast::Item>) -> P<ast::Item>,
|
|
|
|
G: FnMut(Annotatable) -> Annotatable
|
|
|
|
{
|
|
|
|
match self {
|
|
|
|
Annotatable::Item(i) => Annotatable::Item(f(i)),
|
|
|
|
_ => or(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 23:33:09 +03:00
|
|
|
pub fn expect_trait_item(self) -> ast::TraitItem {
|
2014-12-02 10:07:41 -08:00
|
|
|
match self {
|
2017-12-17 02:21:29 +03:00
|
|
|
Annotatable::TraitItem(i) => i.into_inner(),
|
2014-12-02 10:07:41 -08:00
|
|
|
_ => panic!("expected Item")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 23:33:09 +03:00
|
|
|
pub fn expect_impl_item(self) -> ast::ImplItem {
|
2014-12-02 10:07:41 -08:00
|
|
|
match self {
|
2017-12-17 02:21:29 +03:00
|
|
|
Annotatable::ImplItem(i) => i.into_inner(),
|
2014-12-02 10:07:41 -08:00
|
|
|
_ => panic!("expected Item")
|
|
|
|
}
|
|
|
|
}
|
2017-12-26 16:47:32 +09:00
|
|
|
|
2018-03-10 18:16:26 -08:00
|
|
|
pub fn expect_foreign_item(self) -> ast::ForeignItem {
|
|
|
|
match self {
|
|
|
|
Annotatable::ForeignItem(i) => i.into_inner(),
|
|
|
|
_ => panic!("expected foreign item")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 23:19:21 -07:00
|
|
|
pub fn expect_stmt(self) -> ast::Stmt {
|
|
|
|
match self {
|
|
|
|
Annotatable::Stmt(stmt) => stmt.into_inner(),
|
|
|
|
_ => panic!("expected statement"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expect_expr(self) -> P<ast::Expr> {
|
|
|
|
match self {
|
|
|
|
Annotatable::Expr(expr) => expr,
|
|
|
|
_ => panic!("expected expression"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 09:26:25 -03:00
|
|
|
pub fn expect_arm(self) -> ast::Arm {
|
|
|
|
match self {
|
|
|
|
Annotatable::Arm(arm) => arm,
|
|
|
|
_ => panic!("expected match arm")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expect_field(self) -> ast::Field {
|
|
|
|
match self {
|
|
|
|
Annotatable::Field(field) => field,
|
|
|
|
_ => panic!("expected field")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expect_field_pattern(self) -> ast::FieldPat {
|
|
|
|
match self {
|
|
|
|
Annotatable::FieldPat(fp) => fp,
|
|
|
|
_ => panic!("expected field pattern")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expect_generic_param(self) -> ast::GenericParam {
|
|
|
|
match self {
|
|
|
|
Annotatable::GenericParam(gp) => gp,
|
|
|
|
_ => panic!("expected generic parameter")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expect_param(self) -> ast::Param {
|
|
|
|
match self {
|
|
|
|
Annotatable::Param(param) => param,
|
|
|
|
_ => panic!("expected parameter")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expect_struct_field(self) -> ast::StructField {
|
|
|
|
match self {
|
|
|
|
Annotatable::StructField(sf) => sf,
|
|
|
|
_ => panic!("expected struct field")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expect_variant(self) -> ast::Variant {
|
|
|
|
match self {
|
|
|
|
Annotatable::Variant(v) => v,
|
|
|
|
_ => panic!("expected variant")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-26 16:47:32 +09:00
|
|
|
pub fn derive_allowed(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
Annotatable::Item(ref item) => match item.node {
|
|
|
|
ast::ItemKind::Struct(..) |
|
|
|
|
ast::ItemKind::Enum(..) |
|
|
|
|
ast::ItemKind::Union(..) => true,
|
|
|
|
_ => false,
|
|
|
|
},
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2014-12-02 10:07:41 -08:00
|
|
|
}
|
|
|
|
|
2016-06-12 16:05:19 +00:00
|
|
|
// `meta_item` is the annotation, and `item` is the item being modified.
|
2014-12-02 10:07:41 -08:00
|
|
|
// FIXME Decorators should follow the same pattern too.
|
|
|
|
pub trait MultiItemModifier {
|
|
|
|
fn expand(&self,
|
2019-02-07 02:33:01 +09:00
|
|
|
ecx: &mut ExtCtxt<'_>,
|
2014-12-02 10:07:41 -08:00
|
|
|
span: Span,
|
|
|
|
meta_item: &ast::MetaItem,
|
|
|
|
item: Annotatable)
|
2016-06-12 16:05:19 +00:00
|
|
|
-> Vec<Annotatable>;
|
2014-12-02 10:07:41 -08:00
|
|
|
}
|
|
|
|
|
2016-06-12 16:05:19 +00:00
|
|
|
impl<F, T> MultiItemModifier for F
|
2019-02-07 02:33:01 +09:00
|
|
|
where F: Fn(&mut ExtCtxt<'_>, Span, &ast::MetaItem, Annotatable) -> T,
|
2016-06-12 16:05:19 +00:00
|
|
|
T: Into<Vec<Annotatable>>,
|
2014-12-02 10:07:41 -08:00
|
|
|
{
|
|
|
|
fn expand(&self,
|
2019-02-07 02:33:01 +09:00
|
|
|
ecx: &mut ExtCtxt<'_>,
|
2014-12-02 10:07:41 -08:00
|
|
|
span: Span,
|
|
|
|
meta_item: &ast::MetaItem,
|
|
|
|
item: Annotatable)
|
2016-06-12 16:05:19 +00:00
|
|
|
-> Vec<Annotatable> {
|
|
|
|
(*self)(ecx, span, meta_item, item).into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<Vec<Annotatable>> for Annotatable {
|
|
|
|
fn into(self) -> Vec<Annotatable> {
|
|
|
|
vec![self]
|
2014-12-02 10:07:41 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 16:16:43 +12:00
|
|
|
pub trait ProcMacro {
|
|
|
|
fn expand<'cx>(&self,
|
2019-02-07 02:33:01 +09:00
|
|
|
ecx: &'cx mut ExtCtxt<'_>,
|
2016-08-29 16:16:43 +12:00
|
|
|
span: Span,
|
|
|
|
ts: TokenStream)
|
2016-09-06 17:57:58 +12:00
|
|
|
-> TokenStream;
|
2016-08-29 16:16:43 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<F> ProcMacro for F
|
|
|
|
where F: Fn(TokenStream) -> TokenStream
|
|
|
|
{
|
|
|
|
fn expand<'cx>(&self,
|
2019-02-07 02:33:01 +09:00
|
|
|
_ecx: &'cx mut ExtCtxt<'_>,
|
2016-09-06 17:57:58 +12:00
|
|
|
_span: Span,
|
2016-08-29 16:16:43 +12:00
|
|
|
ts: TokenStream)
|
2016-09-06 17:57:58 +12:00
|
|
|
-> TokenStream {
|
2016-08-29 16:16:43 +12:00
|
|
|
// FIXME setup implicit context in TLS before calling self.
|
2016-09-06 17:57:58 +12:00
|
|
|
(*self)(ts)
|
2016-08-29 16:16:43 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait AttrProcMacro {
|
|
|
|
fn expand<'cx>(&self,
|
2019-02-07 02:33:01 +09:00
|
|
|
ecx: &'cx mut ExtCtxt<'_>,
|
2016-08-29 16:16:43 +12:00
|
|
|
span: Span,
|
|
|
|
annotation: TokenStream,
|
|
|
|
annotated: TokenStream)
|
2016-09-06 17:57:58 +12:00
|
|
|
-> TokenStream;
|
2016-08-29 16:16:43 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<F> AttrProcMacro for F
|
|
|
|
where F: Fn(TokenStream, TokenStream) -> TokenStream
|
|
|
|
{
|
|
|
|
fn expand<'cx>(&self,
|
2019-02-07 02:33:01 +09:00
|
|
|
_ecx: &'cx mut ExtCtxt<'_>,
|
2016-09-06 17:57:58 +12:00
|
|
|
_span: Span,
|
2016-08-29 16:16:43 +12:00
|
|
|
annotation: TokenStream,
|
|
|
|
annotated: TokenStream)
|
2016-09-06 17:57:58 +12:00
|
|
|
-> TokenStream {
|
2016-08-29 16:16:43 +12:00
|
|
|
// FIXME setup implicit context in TLS before calling self.
|
2016-09-06 17:57:58 +12:00
|
|
|
(*self)(annotation, annotated)
|
2016-08-29 16:16:43 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 12:09:56 -07:00
|
|
|
/// Represents a thing that maps token trees to Macro Results
|
|
|
|
pub trait TTMacroExpander {
|
2018-10-23 17:18:14 -07:00
|
|
|
fn expand<'cx>(
|
|
|
|
&self,
|
2019-02-07 02:33:01 +09:00
|
|
|
ecx: &'cx mut ExtCtxt<'_>,
|
2018-10-23 17:18:14 -07:00
|
|
|
span: Span,
|
|
|
|
input: TokenStream,
|
|
|
|
) -> Box<dyn MacResult+'cx>;
|
2013-08-30 14:40:05 -07:00
|
|
|
}
|
|
|
|
|
2014-01-25 13:34:26 -08:00
|
|
|
pub type MacroExpanderFn =
|
2019-08-31 20:08:06 +03:00
|
|
|
for<'cx> fn(&'cx mut ExtCtxt<'_>, Span, TokenStream)
|
2018-07-10 21:06:26 +02:00
|
|
|
-> Box<dyn MacResult+'cx>;
|
2013-08-30 14:40:05 -07:00
|
|
|
|
2014-11-26 05:52:16 -05:00
|
|
|
impl<F> TTMacroExpander for F
|
2019-08-31 20:08:06 +03:00
|
|
|
where F: for<'cx> Fn(&'cx mut ExtCtxt<'_>, Span, TokenStream)
|
2018-07-10 21:58:16 +02:00
|
|
|
-> Box<dyn MacResult+'cx>
|
2014-11-26 05:52:16 -05:00
|
|
|
{
|
2018-10-23 17:18:14 -07:00
|
|
|
fn expand<'cx>(
|
|
|
|
&self,
|
2019-02-07 02:33:01 +09:00
|
|
|
ecx: &'cx mut ExtCtxt<'_>,
|
2018-10-23 17:18:14 -07:00
|
|
|
span: Span,
|
2019-08-31 20:08:06 +03:00
|
|
|
mut input: TokenStream,
|
2018-10-23 17:18:14 -07:00
|
|
|
) -> Box<dyn MacResult+'cx> {
|
2017-03-29 07:17:18 +00:00
|
|
|
struct AvoidInterpolatedIdents;
|
|
|
|
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
impl MutVisitor for AvoidInterpolatedIdents {
|
|
|
|
fn visit_tt(&mut self, tt: &mut tokenstream::TokenTree) {
|
2019-06-04 20:42:43 +03:00
|
|
|
if let tokenstream::TokenTree::Token(token) = tt {
|
|
|
|
if let token::Interpolated(nt) = &token.kind {
|
|
|
|
if let token::NtIdent(ident, is_raw) = **nt {
|
2019-06-05 13:25:26 +03:00
|
|
|
*tt = tokenstream::TokenTree::token(
|
|
|
|
token::Ident(ident.name, is_raw), ident.span
|
|
|
|
);
|
2019-06-04 20:42:43 +03:00
|
|
|
}
|
2017-03-29 07:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
mut_visit::noop_visit_tt(tt, self)
|
2017-03-29 07:17:18 +00:00
|
|
|
}
|
|
|
|
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
fn visit_mac(&mut self, mac: &mut ast::Mac) {
|
|
|
|
mut_visit::noop_visit_mac(mac, self)
|
2017-03-29 07:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-31 20:08:06 +03:00
|
|
|
AvoidInterpolatedIdents.visit_tts(&mut input);
|
|
|
|
(*self)(ecx, span, input)
|
2013-08-30 14:40:05 -07:00
|
|
|
}
|
|
|
|
}
|
2013-07-08 15:55:14 -07:00
|
|
|
|
2015-02-27 11:14:42 -08:00
|
|
|
// Use a macro because forwarding to a simple function has type system issues
|
2015-04-07 08:21:18 -05:00
|
|
|
macro_rules! make_stmts_default {
|
2015-02-27 11:14:42 -08:00
|
|
|
($me:expr) => {
|
2018-08-13 22:15:16 +03:00
|
|
|
$me.make_expr().map(|e| smallvec![ast::Stmt {
|
2016-06-17 02:30:01 +00:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
|
|
|
span: e.span,
|
|
|
|
node: ast::StmtKind::Expr(e),
|
2018-08-13 22:15:16 +03:00
|
|
|
}])
|
2015-02-27 11:14:42 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 22:00:14 +10:00
|
|
|
/// The result of a macro expansion. The return values of the various
|
2015-02-27 11:14:42 -08:00
|
|
|
/// methods are spliced into the AST at the callsite of the macro.
|
2014-04-15 22:00:14 +10:00
|
|
|
pub trait MacResult {
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates an expression.
|
2014-09-13 19:06:01 +03:00
|
|
|
fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
|
2014-04-15 22:00:14 +10:00
|
|
|
None
|
|
|
|
}
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates zero or more items.
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_items(self: Box<Self>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
|
2014-04-15 22:00:14 +10:00
|
|
|
None
|
|
|
|
}
|
2014-07-10 17:46:09 -07:00
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates zero or more impl items.
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[ast::ImplItem; 1]>> {
|
2014-07-10 17:46:09 -07:00
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates zero or more trait items.
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[ast::TraitItem; 1]>> {
|
2016-06-11 02:00:07 +01:00
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates zero or more items in an `extern {}` block
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[ast::ForeignItem; 1]>> { None }
|
2018-03-10 18:16:26 -08:00
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates a pattern.
|
2014-09-13 19:06:01 +03:00
|
|
|
fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> {
|
2014-05-19 13:32:51 -07:00
|
|
|
None
|
|
|
|
}
|
2014-04-15 22:00:14 +10:00
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates zero or more statements.
|
2014-04-15 22:00:14 +10:00
|
|
|
///
|
|
|
|
/// By default this attempts to create an expression statement,
|
|
|
|
/// returning None if that fails.
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_stmts(self: Box<Self>) -> Option<SmallVec<[ast::Stmt; 1]>> {
|
2015-04-07 08:21:18 -05:00
|
|
|
make_stmts_default!(self)
|
2014-04-15 22:00:14 +10:00
|
|
|
}
|
2015-07-25 21:54:19 -07:00
|
|
|
|
|
|
|
fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
|
|
|
|
None
|
|
|
|
}
|
2019-09-09 09:26:25 -03:00
|
|
|
|
|
|
|
fn make_arms(self: Box<Self>) -> Option<SmallVec<[ast::Arm; 1]>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_fields(self: Box<Self>) -> Option<SmallVec<[ast::Field; 1]>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_field_patterns(self: Box<Self>) -> Option<SmallVec<[ast::FieldPat; 1]>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_generic_params(self: Box<Self>) -> Option<SmallVec<[ast::GenericParam; 1]>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_params(self: Box<Self>) -> Option<SmallVec<[ast::Param; 1]>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_struct_fields(self: Box<Self>) -> Option<SmallVec<[ast::StructField; 1]>> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_variants(self: Box<Self>) -> Option<SmallVec<[ast::Variant; 1]>> {
|
|
|
|
None
|
|
|
|
}
|
2013-08-30 14:40:05 -07:00
|
|
|
}
|
2013-07-08 15:55:14 -07:00
|
|
|
|
2015-02-27 11:14:42 -08:00
|
|
|
macro_rules! make_MacEager {
|
|
|
|
( $( $fld:ident: $t:ty, )* ) => {
|
|
|
|
/// `MacResult` implementation for the common case where you've already
|
|
|
|
/// built each form of AST that you might return.
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct MacEager {
|
|
|
|
$(
|
|
|
|
pub $fld: Option<$t>,
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MacEager {
|
|
|
|
$(
|
2018-07-10 21:06:26 +02:00
|
|
|
pub fn $fld(v: $t) -> Box<dyn MacResult> {
|
2015-04-15 20:56:16 -07:00
|
|
|
Box::new(MacEager {
|
2015-02-27 11:14:42 -08:00
|
|
|
$fld: Some(v),
|
|
|
|
..Default::default()
|
2015-04-15 20:56:16 -07:00
|
|
|
})
|
2015-02-27 11:14:42 -08:00
|
|
|
}
|
|
|
|
)*
|
2014-08-31 01:45:11 +03:00
|
|
|
}
|
|
|
|
}
|
2014-04-15 22:00:14 +10:00
|
|
|
}
|
2015-02-27 11:14:42 -08:00
|
|
|
|
|
|
|
make_MacEager! {
|
|
|
|
expr: P<ast::Expr>,
|
|
|
|
pat: P<ast::Pat>,
|
2018-08-30 11:42:16 +02:00
|
|
|
items: SmallVec<[P<ast::Item>; 1]>,
|
|
|
|
impl_items: SmallVec<[ast::ImplItem; 1]>,
|
|
|
|
trait_items: SmallVec<[ast::TraitItem; 1]>,
|
|
|
|
foreign_items: SmallVec<[ast::ForeignItem; 1]>,
|
|
|
|
stmts: SmallVec<[ast::Stmt; 1]>,
|
2015-07-25 21:54:19 -07:00
|
|
|
ty: P<ast::Ty>,
|
2014-05-19 13:32:51 -07:00
|
|
|
}
|
2015-02-27 11:14:42 -08:00
|
|
|
|
|
|
|
impl MacResult for MacEager {
|
|
|
|
fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
|
|
|
|
self.expr
|
2014-05-19 13:32:51 -07:00
|
|
|
}
|
2015-02-27 11:14:42 -08:00
|
|
|
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_items(self: Box<Self>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
|
2015-02-27 11:14:42 -08:00
|
|
|
self.items
|
2014-05-19 13:32:51 -07:00
|
|
|
}
|
2014-09-13 12:55:00 +02:00
|
|
|
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[ast::ImplItem; 1]>> {
|
2015-03-11 23:38:58 +02:00
|
|
|
self.impl_items
|
2015-02-27 11:14:42 -08:00
|
|
|
}
|
|
|
|
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[ast::TraitItem; 1]>> {
|
2016-06-11 02:00:07 +01:00
|
|
|
self.trait_items
|
|
|
|
}
|
|
|
|
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[ast::ForeignItem; 1]>> {
|
2018-03-10 18:16:26 -08:00
|
|
|
self.foreign_items
|
|
|
|
}
|
|
|
|
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_stmts(self: Box<Self>) -> Option<SmallVec<[ast::Stmt; 1]>> {
|
2015-04-07 08:21:18 -05:00
|
|
|
match self.stmts.as_ref().map_or(0, |s| s.len()) {
|
|
|
|
0 => make_stmts_default!(self),
|
|
|
|
_ => self.stmts,
|
2015-02-27 11:14:42 -08:00
|
|
|
}
|
2014-04-15 22:00:14 +10:00
|
|
|
}
|
2014-09-13 12:55:00 +02:00
|
|
|
|
2015-02-27 11:14:42 -08:00
|
|
|
fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> {
|
|
|
|
if let Some(p) = self.pat {
|
|
|
|
return Some(p);
|
|
|
|
}
|
|
|
|
if let Some(e) = self.expr {
|
2019-09-26 14:39:48 +01:00
|
|
|
if let ast::ExprKind::Lit(_) = e.kind {
|
2015-02-27 11:14:42 -08:00
|
|
|
return Some(P(ast::Pat {
|
|
|
|
id: ast::DUMMY_NODE_ID,
|
|
|
|
span: e.span,
|
2019-09-26 16:18:31 +01:00
|
|
|
kind: PatKind::Lit(e),
|
2015-02-27 11:14:42 -08:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None
|
2014-04-15 22:00:14 +10:00
|
|
|
}
|
2015-07-25 21:54:19 -07:00
|
|
|
|
|
|
|
fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
|
|
|
|
self.ty
|
|
|
|
}
|
2014-04-15 22:00:14 +10:00
|
|
|
}
|
2014-02-18 16:14:12 +00:00
|
|
|
|
2014-04-15 22:00:14 +10:00
|
|
|
/// Fill-in macro expansion result, to allow compilation to continue
|
|
|
|
/// after hitting errors.
|
2015-03-30 09:38:59 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2014-04-15 22:00:14 +10:00
|
|
|
pub struct DummyResult {
|
2018-12-20 03:57:48 +03:00
|
|
|
is_error: bool,
|
|
|
|
span: Span,
|
2012-07-06 14:29:50 -07:00
|
|
|
}
|
2014-04-15 22:00:14 +10:00
|
|
|
|
|
|
|
impl DummyResult {
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates a default MacResult that can be anything.
|
2014-04-15 22:00:14 +10:00
|
|
|
///
|
|
|
|
/// Use this as a return value after hitting any errors and
|
|
|
|
/// calling `span_err`.
|
2018-12-20 03:57:48 +03:00
|
|
|
pub fn any(span: Span) -> Box<dyn MacResult+'static> {
|
2019-08-13 20:51:54 +03:00
|
|
|
Box::new(DummyResult { is_error: true, span })
|
2018-12-20 03:57:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Same as `any`, but must be a valid fragment, not error.
|
|
|
|
pub fn any_valid(span: Span) -> Box<dyn MacResult+'static> {
|
2019-08-13 20:51:54 +03:00
|
|
|
Box::new(DummyResult { is_error: false, span })
|
2014-04-15 22:00:14 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A plain dummy expression.
|
2018-12-20 03:57:48 +03:00
|
|
|
pub fn raw_expr(sp: Span, is_error: bool) -> P<ast::Expr> {
|
2014-09-13 19:06:01 +03:00
|
|
|
P(ast::Expr {
|
2014-02-18 16:14:12 +00:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2019-09-26 14:39:48 +01:00
|
|
|
kind: if is_error { ast::ExprKind::Err } else { ast::ExprKind::Tup(Vec::new()) },
|
2014-03-18 23:14:08 +11:00
|
|
|
span: sp,
|
2018-08-05 12:04:56 +02:00
|
|
|
attrs: ThinVec::new(),
|
2014-09-13 19:06:01 +03:00
|
|
|
})
|
2014-02-18 16:14:12 +00:00
|
|
|
}
|
2014-05-19 13:32:51 -07:00
|
|
|
|
|
|
|
/// A plain dummy pattern.
|
2014-09-13 19:06:01 +03:00
|
|
|
pub fn raw_pat(sp: Span) -> ast::Pat {
|
|
|
|
ast::Pat {
|
2014-05-19 13:32:51 -07:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2019-09-26 16:18:31 +01:00
|
|
|
kind: PatKind::Wild,
|
2014-05-19 13:32:51 -07:00
|
|
|
span: sp,
|
|
|
|
}
|
|
|
|
}
|
2014-07-10 17:46:09 -07:00
|
|
|
|
2018-12-16 20:23:27 +03:00
|
|
|
/// A plain dummy type.
|
2018-12-20 03:57:48 +03:00
|
|
|
pub fn raw_ty(sp: Span, is_error: bool) -> P<ast::Ty> {
|
2015-07-25 21:54:19 -07:00
|
|
|
P(ast::Ty {
|
2015-07-25 22:17:43 -07:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2018-12-20 03:57:48 +03:00
|
|
|
node: if is_error { ast::TyKind::Err } else { ast::TyKind::Tup(Vec::new()) },
|
2015-07-25 21:54:19 -07:00
|
|
|
span: sp
|
|
|
|
})
|
2015-07-25 22:17:43 -07:00
|
|
|
}
|
2014-03-18 23:14:08 +11:00
|
|
|
}
|
2014-04-15 22:00:14 +10:00
|
|
|
|
|
|
|
impl MacResult for DummyResult {
|
2014-09-13 19:06:01 +03:00
|
|
|
fn make_expr(self: Box<DummyResult>) -> Option<P<ast::Expr>> {
|
2018-12-20 03:57:48 +03:00
|
|
|
Some(DummyResult::raw_expr(self.span, self.is_error))
|
2014-03-18 23:14:08 +11:00
|
|
|
}
|
2015-07-25 22:17:43 -07:00
|
|
|
|
2014-09-13 19:06:01 +03:00
|
|
|
fn make_pat(self: Box<DummyResult>) -> Option<P<ast::Pat>> {
|
|
|
|
Some(P(DummyResult::raw_pat(self.span)))
|
2014-05-19 13:32:51 -07:00
|
|
|
}
|
2015-07-25 22:17:43 -07:00
|
|
|
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
|
2019-08-13 20:51:54 +03:00
|
|
|
Some(SmallVec::new())
|
2014-07-10 17:46:09 -07:00
|
|
|
}
|
2015-07-25 22:17:43 -07:00
|
|
|
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[ast::ImplItem; 1]>> {
|
2019-08-13 20:51:54 +03:00
|
|
|
Some(SmallVec::new())
|
2014-03-18 23:14:08 +11:00
|
|
|
}
|
2015-07-25 22:17:43 -07:00
|
|
|
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_trait_items(self: Box<DummyResult>) -> Option<SmallVec<[ast::TraitItem; 1]>> {
|
2019-08-13 20:51:54 +03:00
|
|
|
Some(SmallVec::new())
|
2018-03-10 18:16:26 -08:00
|
|
|
}
|
|
|
|
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[ast::ForeignItem; 1]>> {
|
2019-08-13 20:51:54 +03:00
|
|
|
Some(SmallVec::new())
|
2016-06-11 02:00:07 +01:00
|
|
|
}
|
|
|
|
|
2018-08-30 11:42:16 +02:00
|
|
|
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVec<[ast::Stmt; 1]>> {
|
2018-08-13 22:15:16 +03:00
|
|
|
Some(smallvec![ast::Stmt {
|
2016-06-17 02:30:01 +00:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
2018-12-20 03:57:48 +03:00
|
|
|
node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span, self.is_error)),
|
2016-06-17 02:30:01 +00:00
|
|
|
span: self.span,
|
2018-08-13 22:15:16 +03:00
|
|
|
}])
|
2014-03-18 23:14:08 +11:00
|
|
|
}
|
2016-06-17 11:02:42 +00:00
|
|
|
|
|
|
|
fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> {
|
2018-12-20 03:57:48 +03:00
|
|
|
Some(DummyResult::raw_ty(self.span, self.is_error))
|
2016-06-17 11:02:42 +00:00
|
|
|
}
|
2019-09-09 09:26:25 -03:00
|
|
|
|
|
|
|
fn make_arms(self: Box<DummyResult>) -> Option<SmallVec<[ast::Arm; 1]>> {
|
|
|
|
Some(SmallVec::new())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_fields(self: Box<DummyResult>) -> Option<SmallVec<[ast::Field; 1]>> {
|
|
|
|
Some(SmallVec::new())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_field_patterns(self: Box<DummyResult>) -> Option<SmallVec<[ast::FieldPat; 1]>> {
|
|
|
|
Some(SmallVec::new())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_generic_params(self: Box<DummyResult>) -> Option<SmallVec<[ast::GenericParam; 1]>> {
|
|
|
|
Some(SmallVec::new())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_params(self: Box<DummyResult>) -> Option<SmallVec<[ast::Param; 1]>> {
|
|
|
|
Some(SmallVec::new())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_struct_fields(self: Box<DummyResult>) -> Option<SmallVec<[ast::StructField; 1]>> {
|
|
|
|
Some(SmallVec::new())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_variants(self: Box<DummyResult>) -> Option<SmallVec<[ast::Variant; 1]>> {
|
|
|
|
Some(SmallVec::new())
|
|
|
|
}
|
2014-01-18 01:53:10 +11:00
|
|
|
}
|
2012-07-05 12:10:33 -07:00
|
|
|
|
2019-06-16 18:58:39 +03:00
|
|
|
/// A syntax extension kind.
|
|
|
|
pub enum SyntaxExtensionKind {
|
2019-06-07 01:59:27 +03:00
|
|
|
/// A token-based function-like macro.
|
2019-06-16 18:58:39 +03:00
|
|
|
Bang(
|
2019-06-07 01:59:27 +03:00
|
|
|
/// An expander with signature TokenStream -> TokenStream.
|
2019-06-16 18:58:39 +03:00
|
|
|
Box<dyn ProcMacro + sync::Sync + sync::Send>,
|
|
|
|
),
|
2016-08-29 16:16:43 +12:00
|
|
|
|
2019-06-07 01:59:27 +03:00
|
|
|
/// An AST-based function-like macro.
|
2019-06-16 18:58:39 +03:00
|
|
|
LegacyBang(
|
2019-06-07 01:59:27 +03:00
|
|
|
/// An expander with signature TokenStream -> AST.
|
2019-06-16 18:58:39 +03:00
|
|
|
Box<dyn TTMacroExpander + sync::Sync + sync::Send>,
|
|
|
|
),
|
2013-02-26 10:15:29 -08:00
|
|
|
|
2019-06-07 01:59:27 +03:00
|
|
|
/// A token-based attribute macro.
|
2019-06-07 02:30:01 +03:00
|
|
|
Attr(
|
2019-06-07 01:59:27 +03:00
|
|
|
/// An expander with signature (TokenStream, TokenStream) -> TokenStream.
|
|
|
|
/// The first TokenSteam is the attribute itself, the second is the annotated item.
|
|
|
|
/// The produced TokenSteam replaces the input TokenSteam.
|
|
|
|
Box<dyn AttrProcMacro + sync::Sync + sync::Send>,
|
|
|
|
),
|
|
|
|
|
|
|
|
/// An AST-based attribute macro.
|
2019-06-07 02:30:01 +03:00
|
|
|
LegacyAttr(
|
2019-06-07 01:59:27 +03:00
|
|
|
/// An expander with signature (AST, AST) -> AST.
|
|
|
|
/// The first AST fragment is the attribute itself, the second is the annotated item.
|
|
|
|
/// The produced AST fragment replaces the input AST fragment.
|
|
|
|
Box<dyn MultiItemModifier + sync::Sync + sync::Send>,
|
|
|
|
),
|
|
|
|
|
|
|
|
/// A trivial attribute "macro" that does nothing,
|
2019-06-16 18:58:39 +03:00
|
|
|
/// only keeps the attribute and marks it as inert,
|
|
|
|
/// thus making it ineligible for further expansion.
|
2019-06-07 01:59:27 +03:00
|
|
|
NonMacroAttr {
|
|
|
|
/// Suppresses the `unused_attributes` lint for this attribute.
|
|
|
|
mark_used: bool,
|
|
|
|
},
|
2017-01-24 01:31:49 +10:30
|
|
|
|
2019-06-07 01:59:27 +03:00
|
|
|
/// A token-based derive macro.
|
2019-06-07 02:30:01 +03:00
|
|
|
Derive(
|
2019-06-07 01:59:27 +03:00
|
|
|
/// An expander with signature TokenStream -> TokenStream (not yet).
|
|
|
|
/// The produced TokenSteam is appended to the input TokenSteam.
|
|
|
|
Box<dyn MultiItemModifier + sync::Sync + sync::Send>,
|
|
|
|
),
|
|
|
|
|
|
|
|
/// An AST-based derive macro.
|
2019-06-07 02:30:01 +03:00
|
|
|
LegacyDerive(
|
2019-06-07 01:59:27 +03:00
|
|
|
/// An expander with signature AST -> AST.
|
|
|
|
/// The produced AST fragment is appended to the input AST fragment.
|
|
|
|
Box<dyn MultiItemModifier + sync::Sync + sync::Send>,
|
|
|
|
),
|
2011-06-20 17:26:17 -07:00
|
|
|
}
|
2011-06-04 15:41:45 -04:00
|
|
|
|
2019-06-16 18:58:39 +03:00
|
|
|
/// A struct representing a macro definition in "lowered" form ready for expansion.
|
|
|
|
pub struct SyntaxExtension {
|
|
|
|
/// A syntax extension kind.
|
|
|
|
pub kind: SyntaxExtensionKind,
|
2019-06-20 11:52:31 +03:00
|
|
|
/// Span of the macro definition.
|
|
|
|
pub span: Span,
|
2019-06-16 18:58:39 +03:00
|
|
|
/// Whitelist of unstable features that are treated as stable inside this macro.
|
|
|
|
pub allow_internal_unstable: Option<Lrc<[Symbol]>>,
|
|
|
|
/// Suppresses the `unsafe_code` lint for code produced by this macro.
|
|
|
|
pub allow_internal_unsafe: bool,
|
|
|
|
/// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro.
|
|
|
|
pub local_inner_macros: bool,
|
2019-06-22 02:44:45 +03:00
|
|
|
/// The macro's stability info.
|
2019-06-21 11:50:30 +03:00
|
|
|
pub stability: Option<Stability>,
|
2019-06-22 02:44:45 +03:00
|
|
|
/// The macro's deprecation info.
|
|
|
|
pub deprecation: Option<Deprecation>,
|
2019-06-16 18:58:39 +03:00
|
|
|
/// Names of helper attributes registered by this macro.
|
|
|
|
pub helper_attrs: Vec<Symbol>,
|
|
|
|
/// Edition of the crate in which this macro is defined.
|
|
|
|
pub edition: Edition,
|
2019-08-10 18:38:27 +03:00
|
|
|
/// Built-in macros have a couple of special properties like availability
|
|
|
|
/// in `#[no_implicit_prelude]` modules, so we have to keep this flag.
|
2019-06-20 11:52:31 +03:00
|
|
|
pub is_builtin: bool,
|
2019-08-03 04:22:44 +03:00
|
|
|
/// We have to identify macros providing a `Copy` impl early for compatibility reasons.
|
|
|
|
pub is_derive_copy: bool,
|
2019-06-16 18:58:39 +03:00
|
|
|
}
|
|
|
|
|
2017-02-06 22:14:38 +10:30
|
|
|
impl SyntaxExtension {
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Returns which kind of macro calls this syntax extension.
|
2019-06-16 18:58:39 +03:00
|
|
|
pub fn macro_kind(&self) -> MacroKind {
|
|
|
|
match self.kind {
|
|
|
|
SyntaxExtensionKind::Bang(..) |
|
|
|
|
SyntaxExtensionKind::LegacyBang(..) => MacroKind::Bang,
|
|
|
|
SyntaxExtensionKind::Attr(..) |
|
|
|
|
SyntaxExtensionKind::LegacyAttr(..) |
|
|
|
|
SyntaxExtensionKind::NonMacroAttr { .. } => MacroKind::Attr,
|
|
|
|
SyntaxExtensionKind::Derive(..) |
|
|
|
|
SyntaxExtensionKind::LegacyDerive(..) => MacroKind::Derive,
|
2017-02-06 22:14:38 +10:30
|
|
|
}
|
|
|
|
}
|
2017-03-22 08:39:51 +00:00
|
|
|
|
2019-06-16 18:58:39 +03:00
|
|
|
/// Constructs a syntax extension with default properties.
|
|
|
|
pub fn default(kind: SyntaxExtensionKind, edition: Edition) -> SyntaxExtension {
|
|
|
|
SyntaxExtension {
|
2019-06-20 11:52:31 +03:00
|
|
|
span: DUMMY_SP,
|
2019-06-16 18:58:39 +03:00
|
|
|
allow_internal_unstable: None,
|
|
|
|
allow_internal_unsafe: false,
|
|
|
|
local_inner_macros: false,
|
2019-06-21 11:50:30 +03:00
|
|
|
stability: None,
|
2019-06-22 02:44:45 +03:00
|
|
|
deprecation: None,
|
2019-06-16 18:58:39 +03:00
|
|
|
helper_attrs: Vec::new(),
|
|
|
|
edition,
|
2019-06-20 11:52:31 +03:00
|
|
|
is_builtin: false,
|
2019-08-03 04:22:44 +03:00
|
|
|
is_derive_copy: false,
|
2019-06-16 18:58:39 +03:00
|
|
|
kind,
|
2018-06-24 19:54:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-20 21:22:32 +03:00
|
|
|
/// Constructs a syntax extension with the given properties
|
|
|
|
/// and other properties converted from attributes.
|
|
|
|
pub fn new(
|
|
|
|
sess: &ParseSess,
|
|
|
|
kind: SyntaxExtensionKind,
|
|
|
|
span: Span,
|
|
|
|
helper_attrs: Vec<Symbol>,
|
|
|
|
edition: Edition,
|
|
|
|
name: Name,
|
|
|
|
attrs: &[ast::Attribute],
|
|
|
|
) -> SyntaxExtension {
|
2019-08-21 02:23:46 +02:00
|
|
|
let allow_internal_unstable = attr::allow_internal_unstable(
|
|
|
|
&attrs, &sess.span_diagnostic,
|
|
|
|
).map(|features| features.collect::<Vec<Symbol>>().into());
|
2019-08-20 21:22:32 +03:00
|
|
|
|
|
|
|
let mut local_inner_macros = false;
|
|
|
|
if let Some(macro_export) = attr::find_by_name(attrs, sym::macro_export) {
|
|
|
|
if let Some(l) = macro_export.meta_item_list() {
|
|
|
|
local_inner_macros = attr::list_contains_name(&l, sym::local_inner_macros);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let is_builtin = attr::contains_name(attrs, sym::rustc_builtin_macro);
|
|
|
|
|
|
|
|
SyntaxExtension {
|
|
|
|
kind,
|
|
|
|
span,
|
|
|
|
allow_internal_unstable,
|
|
|
|
allow_internal_unsafe: attr::contains_name(attrs, sym::allow_internal_unsafe),
|
|
|
|
local_inner_macros,
|
|
|
|
stability: attr::find_stability(&sess, attrs, span),
|
|
|
|
deprecation: attr::find_deprecation(&sess, attrs, span),
|
|
|
|
helper_attrs,
|
|
|
|
edition,
|
|
|
|
is_builtin,
|
|
|
|
is_derive_copy: is_builtin && name == sym::Copy,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 01:44:04 +03:00
|
|
|
pub fn dummy_bang(edition: Edition) -> SyntaxExtension {
|
2019-08-31 20:08:06 +03:00
|
|
|
fn expander<'cx>(_: &'cx mut ExtCtxt<'_>, span: Span, _: TokenStream)
|
2019-07-03 01:44:04 +03:00
|
|
|
-> Box<dyn MacResult + 'cx> {
|
|
|
|
DummyResult::any(span)
|
|
|
|
}
|
|
|
|
SyntaxExtension::default(SyntaxExtensionKind::LegacyBang(Box::new(expander)), edition)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dummy_derive(edition: Edition) -> SyntaxExtension {
|
|
|
|
fn expander(_: &mut ExtCtxt<'_>, _: Span, _: &ast::MetaItem, _: Annotatable)
|
|
|
|
-> Vec<Annotatable> {
|
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
SyntaxExtension::default(SyntaxExtensionKind::Derive(Box::new(expander)), edition)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn non_macro_attr(mark_used: bool, edition: Edition) -> SyntaxExtension {
|
|
|
|
SyntaxExtension::default(SyntaxExtensionKind::NonMacroAttr { mark_used }, edition)
|
|
|
|
}
|
|
|
|
|
2019-08-13 23:56:42 +03:00
|
|
|
pub fn expn_data(&self, parent: ExpnId, call_site: Span, descr: Symbol) -> ExpnData {
|
|
|
|
ExpnData {
|
2019-06-30 15:58:56 +03:00
|
|
|
kind: ExpnKind::Macro(self.macro_kind(), descr),
|
2019-08-13 03:34:46 +03:00
|
|
|
parent,
|
|
|
|
call_site,
|
2019-06-30 03:05:52 +03:00
|
|
|
def_site: self.span,
|
2019-06-16 18:58:39 +03:00
|
|
|
allow_internal_unstable: self.allow_internal_unstable.clone(),
|
|
|
|
allow_internal_unsafe: self.allow_internal_unsafe,
|
|
|
|
local_inner_macros: self.local_inner_macros,
|
|
|
|
edition: self.edition,
|
2018-05-13 03:51:46 +03:00
|
|
|
}
|
|
|
|
}
|
2017-02-06 22:14:38 +10:30
|
|
|
}
|
|
|
|
|
2014-05-24 16:16:10 -07:00
|
|
|
pub type NamedSyntaxExtension = (Name, SyntaxExtension);
|
|
|
|
|
2019-08-24 21:12:13 +03:00
|
|
|
/// Result of resolving a macro invocation.
|
|
|
|
pub enum InvocationRes {
|
|
|
|
Single(Lrc<SyntaxExtension>),
|
|
|
|
DeriveContainer(Vec<Lrc<SyntaxExtension>>),
|
|
|
|
}
|
|
|
|
|
2019-07-03 11:44:57 +03:00
|
|
|
/// Error type that denotes indeterminacy.
|
|
|
|
pub struct Indeterminate;
|
|
|
|
|
2019-08-03 04:22:44 +03:00
|
|
|
bitflags::bitflags! {
|
|
|
|
/// Built-in derives that need some extra tracking beyond the usual macro functionality.
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct SpecialDerives: u8 {
|
|
|
|
const PARTIAL_EQ = 1 << 0;
|
|
|
|
const EQ = 1 << 1;
|
|
|
|
const COPY = 1 << 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-05 03:46:05 +00:00
|
|
|
pub trait Resolver {
|
2019-08-17 20:49:00 +03:00
|
|
|
fn next_node_id(&mut self) -> NodeId;
|
2019-04-06 00:15:49 +02:00
|
|
|
|
2019-07-05 03:09:24 +03:00
|
|
|
fn resolve_dollar_crates(&mut self);
|
2019-07-16 01:42:58 +03:00
|
|
|
fn visit_ast_fragment_with_placeholders(&mut self, expn_id: ExpnId, fragment: &AstFragment,
|
2019-08-17 20:49:00 +03:00
|
|
|
extra_placeholders: &[NodeId]);
|
2019-06-20 11:52:31 +03:00
|
|
|
fn register_builtin_macro(&mut self, ident: ast::Ident, ext: SyntaxExtension);
|
2016-09-07 23:21:59 +00:00
|
|
|
|
2019-08-28 12:41:29 +03:00
|
|
|
fn expansion_for_ast_pass(
|
2019-08-25 20:58:03 +01:00
|
|
|
&mut self,
|
2019-08-28 12:41:29 +03:00
|
|
|
call_site: Span,
|
2019-08-25 20:58:03 +01:00
|
|
|
pass: AstPass,
|
|
|
|
features: &[Symbol],
|
|
|
|
parent_module_id: Option<NodeId>,
|
2019-08-28 12:41:29 +03:00
|
|
|
) -> ExpnId;
|
2019-08-25 20:58:03 +01:00
|
|
|
|
2016-11-10 10:11:25 +00:00
|
|
|
fn resolve_imports(&mut self);
|
2018-04-17 23:19:21 -07:00
|
|
|
|
2019-08-20 00:24:28 +03:00
|
|
|
fn resolve_macro_invocation(
|
|
|
|
&mut self, invoc: &Invocation, eager_expansion_root: ExpnId, force: bool
|
2019-08-24 21:12:13 +03:00
|
|
|
) -> Result<InvocationRes, Indeterminate>;
|
2018-08-15 03:51:12 +03:00
|
|
|
|
2017-05-11 10:26:07 +02:00
|
|
|
fn check_unused_macros(&self);
|
2019-08-03 04:22:44 +03:00
|
|
|
|
|
|
|
fn has_derives(&self, expn_id: ExpnId, derives: SpecialDerives) -> bool;
|
|
|
|
fn add_derives(&mut self, expn_id: ExpnId, derives: SpecialDerives);
|
2016-06-02 01:14:33 +00:00
|
|
|
}
|
|
|
|
|
2016-09-07 23:21:59 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct ModuleData {
|
|
|
|
pub mod_path: Vec<ast::Ident>,
|
|
|
|
pub directory: PathBuf,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct ExpansionData {
|
2019-07-16 01:42:58 +03:00
|
|
|
pub id: ExpnId,
|
2016-09-07 23:21:59 +00:00
|
|
|
pub depth: usize,
|
|
|
|
pub module: Rc<ModuleData>,
|
2016-11-05 04:16:26 +00:00
|
|
|
pub directory_ownership: DirectoryOwnership,
|
2019-07-18 18:36:19 -07:00
|
|
|
pub prior_type_ascription: Option<(Span, bool)>,
|
2016-06-02 01:14:33 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 13:12:30 -07:00
|
|
|
/// One of these is made during expansion and incrementally updated as we go;
|
2017-05-13 21:40:06 +02:00
|
|
|
/// when a macro expansion occurs, the resulting nodes have the `backtrace()
|
2019-08-13 23:56:42 +03:00
|
|
|
/// -> expn_data` of their expansion context stored into their span.
|
2013-12-25 11:10:33 -07:00
|
|
|
pub struct ExtCtxt<'a> {
|
2014-03-27 15:39:48 -07:00
|
|
|
pub parse_sess: &'a parse::ParseSess,
|
2015-02-15 21:30:45 +01:00
|
|
|
pub ecfg: expand::ExpansionConfig<'a>,
|
2017-09-21 22:37:00 -05:00
|
|
|
pub root_path: PathBuf,
|
2018-07-10 21:06:26 +02:00
|
|
|
pub resolver: &'a mut dyn Resolver,
|
2016-09-07 23:21:59 +00:00
|
|
|
pub current_expansion: ExpansionData,
|
2018-08-18 13:55:43 +03:00
|
|
|
pub expansions: FxHashMap<Span, Vec<String>>,
|
2013-05-17 20:10:26 +10:00
|
|
|
}
|
2013-03-15 15:24:24 -04:00
|
|
|
|
2013-12-25 11:10:33 -07:00
|
|
|
impl<'a> ExtCtxt<'a> {
|
2016-10-27 06:36:56 +00:00
|
|
|
pub fn new(parse_sess: &'a parse::ParseSess,
|
2015-07-13 17:10:44 -07:00
|
|
|
ecfg: expand::ExpansionConfig<'a>,
|
2018-07-10 21:06:26 +02:00
|
|
|
resolver: &'a mut dyn Resolver)
|
2016-06-02 01:14:33 +00:00
|
|
|
-> ExtCtxt<'a> {
|
2013-12-27 17:17:36 -07:00
|
|
|
ExtCtxt {
|
2017-08-06 22:54:09 -07:00
|
|
|
parse_sess,
|
|
|
|
ecfg,
|
2017-09-21 22:37:00 -05:00
|
|
|
root_path: PathBuf::new(),
|
2017-08-06 22:54:09 -07:00
|
|
|
resolver,
|
2016-09-07 23:21:59 +00:00
|
|
|
current_expansion: ExpansionData {
|
2019-07-16 01:42:58 +03:00
|
|
|
id: ExpnId::root(),
|
2016-09-07 23:21:59 +00:00
|
|
|
depth: 0,
|
|
|
|
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
|
2017-11-27 18:14:24 -08:00
|
|
|
directory_ownership: DirectoryOwnership::Owned { relative: None },
|
2019-07-18 18:36:19 -07:00
|
|
|
prior_type_ascription: None,
|
2016-09-07 23:21:59 +00:00
|
|
|
},
|
2018-08-18 13:55:43 +03:00
|
|
|
expansions: FxHashMap::default(),
|
2013-05-17 21:27:17 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-07 23:11:25 +01:00
|
|
|
/// Returns a `Folder` for deeply expanding all macros in an AST node.
|
2014-07-20 16:25:35 +02:00
|
|
|
pub fn expander<'b>(&'b mut self) -> expand::MacroExpander<'b, 'a> {
|
2016-09-06 05:42:45 +00:00
|
|
|
expand::MacroExpander::new(self, false)
|
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Returns a `Folder` that deeply expands all macros and assigns all `NodeId`s in an AST node.
|
|
|
|
/// Once `NodeId`s are assigned, the node may not be expanded, removed, or otherwise modified.
|
2016-09-06 05:42:45 +00:00
|
|
|
pub fn monotonic_expander<'b>(&'b mut self) -> expand::MacroExpander<'b, 'a> {
|
|
|
|
expand::MacroExpander::new(self, true)
|
2013-10-05 21:15:46 -07:00
|
|
|
}
|
2019-08-31 20:08:06 +03:00
|
|
|
pub fn new_parser_from_tts(&self, stream: TokenStream) -> parser::Parser<'a> {
|
|
|
|
parse::stream_to_parser(self.parse_sess, stream, MACRO_ARGUMENTS)
|
2014-07-03 11:42:24 +02:00
|
|
|
}
|
2018-08-18 12:14:09 +02:00
|
|
|
pub fn source_map(&self) -> &'a SourceMap { self.parse_sess.source_map() }
|
2014-03-09 16:54:34 +02:00
|
|
|
pub fn parse_sess(&self) -> &'a parse::ParseSess { self.parse_sess }
|
2016-10-27 06:36:56 +00:00
|
|
|
pub fn cfg(&self) -> &ast::CrateConfig { &self.parse_sess.config }
|
2013-08-31 18:13:04 +02:00
|
|
|
pub fn call_site(&self) -> Span {
|
2019-08-13 23:56:42 +03:00
|
|
|
self.current_expansion.id.expn_data().call_site
|
2017-03-17 04:04:41 +00:00
|
|
|
}
|
2019-08-21 21:28:22 +03:00
|
|
|
|
|
|
|
/// Equivalent of `Span::def_site` from the proc macro API,
|
|
|
|
/// except that the location is taken from the span passed as an argument.
|
|
|
|
pub fn with_def_site_ctxt(&self, span: Span) -> Span {
|
2019-08-28 12:41:29 +03:00
|
|
|
span.with_def_site_ctxt(self.current_expansion.id)
|
2019-08-21 21:28:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Equivalent of `Span::call_site` from the proc macro API,
|
|
|
|
/// except that the location is taken from the span passed as an argument.
|
|
|
|
pub fn with_call_site_ctxt(&self, span: Span) -> Span {
|
2019-08-28 12:41:29 +03:00
|
|
|
span.with_call_site_ctxt(self.current_expansion.id)
|
2019-08-21 21:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-16 21:47:09 +03:00
|
|
|
/// Returns span for the macro which originally caused the current expansion to happen.
|
|
|
|
///
|
|
|
|
/// Stops backtracing at include! boundary.
|
2017-05-15 09:41:05 +00:00
|
|
|
pub fn expansion_cause(&self) -> Option<Span> {
|
2019-08-21 21:28:22 +03:00
|
|
|
let mut expn_id = self.current_expansion.id;
|
2015-06-16 21:47:09 +03:00
|
|
|
let mut last_macro = None;
|
2014-09-17 19:01:33 +03:00
|
|
|
loop {
|
2019-08-21 21:28:22 +03:00
|
|
|
let expn_data = expn_id.expn_data();
|
2019-08-11 03:00:05 +03:00
|
|
|
// Stop going up the backtrace once include! is encountered
|
2019-08-13 23:56:42 +03:00
|
|
|
if expn_data.is_root() || expn_data.kind.descr() == sym::include {
|
2019-08-11 03:00:05 +03:00
|
|
|
break;
|
2014-09-17 19:01:33 +03:00
|
|
|
}
|
2019-08-21 21:28:22 +03:00
|
|
|
expn_id = expn_data.call_site.ctxt().outer_expn();
|
2019-08-13 23:56:42 +03:00
|
|
|
last_macro = Some(expn_data.call_site);
|
2014-09-17 19:01:33 +03:00
|
|
|
}
|
2017-05-15 09:41:05 +00:00
|
|
|
last_macro
|
2014-09-17 19:01:33 +03:00
|
|
|
}
|
|
|
|
|
2018-01-15 21:38:12 -08:00
|
|
|
pub fn struct_span_warn<S: Into<MultiSpan>>(&self,
|
|
|
|
sp: S,
|
|
|
|
msg: &str)
|
|
|
|
-> DiagnosticBuilder<'a> {
|
2015-12-21 10:00:43 +13:00
|
|
|
self.parse_sess.span_diagnostic.struct_span_warn(sp, msg)
|
|
|
|
}
|
2018-01-15 21:38:12 -08:00
|
|
|
pub fn struct_span_err<S: Into<MultiSpan>>(&self,
|
|
|
|
sp: S,
|
|
|
|
msg: &str)
|
|
|
|
-> DiagnosticBuilder<'a> {
|
2015-12-21 10:00:43 +13:00
|
|
|
self.parse_sess.span_diagnostic.struct_span_err(sp, msg)
|
|
|
|
}
|
2018-01-15 21:38:12 -08:00
|
|
|
pub fn struct_span_fatal<S: Into<MultiSpan>>(&self,
|
|
|
|
sp: S,
|
|
|
|
msg: &str)
|
|
|
|
-> DiagnosticBuilder<'a> {
|
2015-12-21 10:00:43 +13:00
|
|
|
self.parse_sess.span_diagnostic.struct_span_fatal(sp, msg)
|
|
|
|
}
|
|
|
|
|
2014-01-18 01:53:10 +11:00
|
|
|
/// Emit `msg` attached to `sp`, and stop compilation immediately.
|
|
|
|
///
|
2014-07-02 21:27:07 -04:00
|
|
|
/// `span_err` should be strongly preferred where-ever possible:
|
2017-12-31 17:17:01 +01:00
|
|
|
/// this should *only* be used when:
|
|
|
|
///
|
2018-11-27 02:59:49 +00:00
|
|
|
/// - continuing has a high risk of flow-on errors (e.g., errors in
|
2014-01-18 01:53:10 +11:00
|
|
|
/// declaring a macro would cause all uses of that macro to
|
|
|
|
/// complain about "undefined macro"), or
|
|
|
|
/// - there is literally nothing else that can be done (however,
|
|
|
|
/// in most cases one can construct a dummy expression/item to
|
|
|
|
/// substitute; we never hit resolve/type-checking so the dummy
|
|
|
|
/// value doesn't have to match anything)
|
2018-01-15 21:38:12 -08:00
|
|
|
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
|
2018-01-21 12:47:58 +01:00
|
|
|
self.parse_sess.span_diagnostic.span_fatal(sp, msg).raise();
|
2013-05-17 20:10:26 +10:00
|
|
|
}
|
2014-01-18 01:53:10 +11:00
|
|
|
|
|
|
|
/// Emit `msg` attached to `sp`, without immediately stopping
|
|
|
|
/// compilation.
|
|
|
|
///
|
|
|
|
/// Compilation will be stopped in the near future (at the end of
|
|
|
|
/// the macro expansion phase).
|
2018-01-15 21:38:12 -08:00
|
|
|
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
2013-05-17 20:10:26 +10:00
|
|
|
self.parse_sess.span_diagnostic.span_err(sp, msg);
|
|
|
|
}
|
2018-02-12 23:21:20 +01:00
|
|
|
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
|
|
|
|
self.parse_sess.span_diagnostic.span_err_with_code(sp, msg, code);
|
|
|
|
}
|
2018-01-15 21:38:12 -08:00
|
|
|
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
2013-05-17 20:10:26 +10:00
|
|
|
self.parse_sess.span_diagnostic.span_warn(sp, msg);
|
|
|
|
}
|
2018-01-15 21:38:12 -08:00
|
|
|
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
|
2013-05-17 20:10:26 +10:00
|
|
|
self.parse_sess.span_diagnostic.span_bug(sp, msg);
|
|
|
|
}
|
2017-09-02 18:13:25 +02:00
|
|
|
pub fn trace_macros_diag(&mut self) {
|
2017-05-05 21:49:59 -07:00
|
|
|
for (sp, notes) in self.expansions.iter() {
|
2017-05-12 20:05:39 +02:00
|
|
|
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, "trace_macro");
|
2017-05-05 21:49:59 -07:00
|
|
|
for note in notes {
|
2017-05-12 20:05:39 +02:00
|
|
|
db.note(note);
|
2017-05-05 21:49:59 -07:00
|
|
|
}
|
|
|
|
db.emit();
|
|
|
|
}
|
2017-09-02 18:13:25 +02:00
|
|
|
// Fixme: does this result in errors?
|
|
|
|
self.expansions.clear();
|
2017-04-24 16:27:07 -07:00
|
|
|
}
|
2013-05-31 15:17:22 -07:00
|
|
|
pub fn bug(&self, msg: &str) -> ! {
|
2015-12-14 11:17:55 +13:00
|
|
|
self.parse_sess.span_diagnostic.bug(msg);
|
2013-05-17 20:10:26 +10:00
|
|
|
}
|
2013-05-31 15:17:22 -07:00
|
|
|
pub fn trace_macros(&self) -> bool {
|
2015-04-14 15:36:38 +02:00
|
|
|
self.ecfg.trace_mac
|
2013-05-17 20:10:26 +10:00
|
|
|
}
|
2013-12-28 22:35:38 -07:00
|
|
|
pub fn set_trace_macros(&mut self, x: bool) {
|
2015-04-14 15:36:38 +02:00
|
|
|
self.ecfg.trace_mac = x
|
2013-05-17 20:10:26 +10:00
|
|
|
}
|
2019-09-14 21:16:51 +01:00
|
|
|
pub fn ident_of(&self, st: &str, sp: Span) -> ast::Ident {
|
|
|
|
ast::Ident::from_str_and_span(st, sp)
|
2013-05-17 20:10:26 +10:00
|
|
|
}
|
2019-05-22 14:41:15 +10:00
|
|
|
pub fn std_path(&self, components: &[Symbol]) -> Vec<ast::Ident> {
|
2019-08-21 21:28:22 +03:00
|
|
|
let def_site = self.with_def_site_ctxt(DUMMY_SP);
|
2019-05-11 17:41:37 +03:00
|
|
|
iter::once(Ident::new(kw::DollarCrate, def_site))
|
2019-08-11 02:20:18 +03:00
|
|
|
.chain(components.iter().map(|&s| Ident::with_dummy_span(s)))
|
2017-12-06 10:50:55 -08:00
|
|
|
.collect()
|
2014-09-07 14:57:26 -07:00
|
|
|
}
|
2014-07-06 01:17:59 -07:00
|
|
|
pub fn name_of(&self, st: &str) -> ast::Name {
|
2016-11-16 08:21:52 +00:00
|
|
|
Symbol::intern(st)
|
2014-07-06 01:17:59 -07:00
|
|
|
}
|
2017-05-11 10:26:07 +02:00
|
|
|
|
|
|
|
pub fn check_unused_macros(&self) {
|
|
|
|
self.resolver.check_unused_macros();
|
|
|
|
}
|
2019-06-22 21:51:51 +02:00
|
|
|
|
2019-09-06 03:56:45 +01:00
|
|
|
/// Resolves a path mentioned inside Rust code.
|
2019-06-22 21:51:51 +02:00
|
|
|
///
|
|
|
|
/// This unifies the logic used for resolving `include_X!`, and `#[doc(include)]` file paths.
|
|
|
|
///
|
|
|
|
/// Returns an absolute path to the file that `path` refers to.
|
|
|
|
pub fn resolve_path(&self, path: impl Into<PathBuf>, span: Span) -> PathBuf {
|
|
|
|
let path = path.into();
|
|
|
|
|
|
|
|
// Relative paths are resolved relative to the file in which they are found
|
|
|
|
// after macro expansion (that is, they are unhygienic).
|
|
|
|
if !path.is_absolute() {
|
|
|
|
let callsite = span.source_callsite();
|
|
|
|
let mut result = match self.source_map().span_to_unmapped_path(callsite) {
|
|
|
|
FileName::Real(path) => path,
|
|
|
|
FileName::DocTest(path, _) => path,
|
|
|
|
other => panic!("cannot resolve relative path in non-file source `{}`", other),
|
|
|
|
};
|
|
|
|
result.pop();
|
|
|
|
result.push(path);
|
|
|
|
result
|
|
|
|
} else {
|
|
|
|
path
|
|
|
|
}
|
|
|
|
}
|
2013-05-17 20:10:26 +10:00
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Extracts a string literal from the macro expanded version of `expr`,
|
2014-03-02 13:38:44 -08:00
|
|
|
/// emitting `err_msg` if `expr` is not a string literal. This does not stop
|
2019-02-08 14:53:55 +01:00
|
|
|
/// compilation on error, merely emits a non-fatal error and returns `None`.
|
2018-07-14 20:50:30 -07:00
|
|
|
pub fn expr_to_spanned_string<'a>(
|
2019-02-07 02:33:01 +09:00
|
|
|
cx: &'a mut ExtCtxt<'_>,
|
2019-08-19 23:44:57 +03:00
|
|
|
expr: P<ast::Expr>,
|
2018-07-14 20:50:30 -07:00
|
|
|
err_msg: &str,
|
2019-08-15 01:56:44 +03:00
|
|
|
) -> Result<(Symbol, ast::StrStyle, Span), Option<DiagnosticBuilder<'a>>> {
|
2019-08-14 02:30:09 +03:00
|
|
|
// Perform eager expansion on the expression.
|
|
|
|
// We want to be able to handle e.g., `concat!("foo", "bar")`.
|
|
|
|
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();
|
|
|
|
|
2019-09-26 14:39:48 +01:00
|
|
|
Err(match expr.kind {
|
2019-09-26 16:56:53 +01:00
|
|
|
ast::ExprKind::Lit(ref l) => match l.kind {
|
2019-08-15 01:56:44 +03:00
|
|
|
ast::LitKind::Str(s, style) => return Ok((s, style, expr.span)),
|
2019-05-02 20:56:07 +03:00
|
|
|
ast::LitKind::Err(_) => None,
|
2018-12-30 00:56:55 +03:00
|
|
|
_ => Some(cx.struct_span_err(l.span, err_msg))
|
2014-01-09 15:05:33 +02:00
|
|
|
},
|
2018-12-30 00:56:55 +03:00
|
|
|
ast::ExprKind::Err => None,
|
|
|
|
_ => Some(cx.struct_span_err(expr.span, err_msg))
|
2018-07-14 20:50:30 -07:00
|
|
|
})
|
2011-06-20 17:26:17 -07:00
|
|
|
}
|
|
|
|
|
2019-02-07 02:33:01 +09:00
|
|
|
pub fn expr_to_string(cx: &mut ExtCtxt<'_>, expr: P<ast::Expr>, err_msg: &str)
|
2016-11-16 10:52:37 +00:00
|
|
|
-> Option<(Symbol, ast::StrStyle)> {
|
2018-07-14 20:50:30 -07:00
|
|
|
expr_to_spanned_string(cx, expr, err_msg)
|
2018-12-30 00:56:55 +03:00
|
|
|
.map_err(|err| err.map(|mut err| err.emit()))
|
2018-07-14 20:50:30 -07:00
|
|
|
.ok()
|
2019-08-15 01:56:44 +03:00
|
|
|
.map(|(symbol, style, _)| (symbol, style))
|
2016-09-02 22:01:35 +00:00
|
|
|
}
|
|
|
|
|
2014-01-18 01:53:10 +11:00
|
|
|
/// Non-fatally assert that `tts` is empty. Note that this function
|
|
|
|
/// returns even when `tts` is non-empty, macros that *need* to stop
|
|
|
|
/// compilation should call
|
|
|
|
/// `cx.parse_sess.span_diagnostic.abort_if_errors()` (this should be
|
|
|
|
/// done as rarely as possible).
|
2019-02-07 02:33:01 +09:00
|
|
|
pub fn check_zero_tts(cx: &ExtCtxt<'_>,
|
2014-01-10 14:02:36 -08:00
|
|
|
sp: Span,
|
2019-08-31 20:08:06 +03:00
|
|
|
tts: TokenStream,
|
2013-01-29 14:41:40 -08:00
|
|
|
name: &str) {
|
2015-03-24 16:54:09 -07:00
|
|
|
if !tts.is_empty() {
|
2015-02-20 14:08:14 -05:00
|
|
|
cx.span_err(sp, &format!("{} takes no arguments", name));
|
2012-12-12 17:08:09 -08:00
|
|
|
}
|
2012-05-14 15:32:32 -07:00
|
|
|
}
|
|
|
|
|
2018-02-07 09:32:26 -05:00
|
|
|
/// Interpreting `tts` as a comma-separated sequence of expressions,
|
2019-02-08 14:53:55 +01:00
|
|
|
/// expect exactly one string literal, or emit an error and return `None`.
|
2019-02-07 02:33:01 +09:00
|
|
|
pub fn get_single_str_from_tts(cx: &mut ExtCtxt<'_>,
|
2013-08-31 18:13:04 +02:00
|
|
|
sp: Span,
|
2019-08-31 20:08:06 +03:00
|
|
|
tts: TokenStream,
|
2013-08-07 09:47:28 -07:00
|
|
|
name: &str)
|
2014-05-22 16:57:53 -07:00
|
|
|
-> Option<String> {
|
2014-10-20 23:04:16 -07:00
|
|
|
let mut p = cx.new_parser_from_tts(tts);
|
2014-11-02 23:10:09 -08:00
|
|
|
if p.token == token::Eof {
|
2015-02-20 14:08:14 -05:00
|
|
|
cx.span_err(sp, &format!("{} takes 1 argument", name));
|
2014-11-02 23:10:09 -08:00
|
|
|
return None
|
|
|
|
}
|
2016-09-02 22:01:35 +00:00
|
|
|
let ret = panictry!(p.parse_expr());
|
2018-02-07 09:32:26 -05:00
|
|
|
let _ = p.eat(&token::Comma);
|
|
|
|
|
2014-10-20 23:04:16 -07:00
|
|
|
if p.token != token::Eof {
|
2015-02-20 14:08:14 -05:00
|
|
|
cx.span_err(sp, &format!("{} takes 1 argument", name));
|
2012-01-31 23:50:12 -07:00
|
|
|
}
|
2014-10-20 23:04:16 -07:00
|
|
|
expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| {
|
2015-02-03 23:31:06 +01:00
|
|
|
s.to_string()
|
2014-10-20 23:04:16 -07:00
|
|
|
})
|
2012-01-31 23:50:12 -07:00
|
|
|
}
|
2011-06-20 17:26:17 -07:00
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Extracts comma-separated expressions from `tts`. If there is a
|
|
|
|
/// parsing error, emit a non-fatal error and return `None`.
|
2019-02-07 02:33:01 +09:00
|
|
|
pub fn get_exprs_from_tts(cx: &mut ExtCtxt<'_>,
|
2013-08-31 18:13:04 +02:00
|
|
|
sp: Span,
|
2019-08-31 20:08:06 +03:00
|
|
|
tts: TokenStream) -> Option<Vec<P<ast::Expr>>> {
|
2014-07-03 11:42:24 +02:00
|
|
|
let mut p = cx.new_parser_from_tts(tts);
|
2014-02-28 13:09:09 -08:00
|
|
|
let mut es = Vec::new();
|
2014-10-27 19:22:52 +11:00
|
|
|
while p.token != token::Eof {
|
2019-08-14 02:30:09 +03:00
|
|
|
let expr = panictry!(p.parse_expr());
|
|
|
|
|
|
|
|
// Perform eager expansion on the expression.
|
|
|
|
// We want to be able to handle e.g., `concat!("foo", "bar")`.
|
|
|
|
let expr = cx.expander().fully_expand_fragment(AstFragment::Expr(expr)).make_expr();
|
|
|
|
|
Overhaul `syntax::fold::Folder`.
This commit changes `syntax::fold::Folder` from a functional style
(where most methods take a `T` and produce a new `T`) to a more
imperative style (where most methods take and modify a `&mut T`), and
renames it `syntax::mut_visit::MutVisitor`.
The first benefit is speed. The functional style does not require any
reallocations, due to the use of `P::map` and
`MoveMap::move_{,flat_}map`. However, every field in the AST must be
overwritten; even those fields that are unchanged are overwritten with
the same value. This causes a lot of unnecessary memory writes. The
imperative style reduces instruction counts by 1--3% across a wide range
of workloads, particularly incremental workloads.
The second benefit is conciseness; the imperative style is usually more
concise. E.g. compare the old functional style:
```
fn fold_abc(&mut self, abc: ABC) {
ABC {
a: fold_a(abc.a),
b: fold_b(abc.b),
c: abc.c,
}
}
```
with the imperative style:
```
fn visit_abc(&mut self, ABC { a, b, c: _ }: &mut ABC) {
visit_a(a);
visit_b(b);
}
```
(The reductions get larger in more complex examples.)
Overall, the patch removes over 200 lines of code -- even though the new
code has more comments -- and a lot of the remaining lines have fewer
characters.
Some notes:
- The old style used methods called `fold_*`. The new style mostly uses
methods called `visit_*`, but there are a few methods that map a `T`
to something other than a `T`, which are called `flat_map_*` (`T` maps
to multiple `T`s) or `filter_map_*` (`T` maps to 0 or 1 `T`s).
- `move_map.rs`/`MoveMap`/`move_map`/`move_flat_map` are renamed
`map_in_place.rs`/`MapInPlace`/`map_in_place`/`flat_map_in_place` to
reflect their slightly changed signatures.
- Although this commit renames the `fold` module as `mut_visit`, it
keeps it in the `fold.rs` file, so as not to confuse git. The next
commit will rename the file.
2019-02-05 15:20:55 +11:00
|
|
|
es.push(expr);
|
2015-12-31 12:11:53 +13:00
|
|
|
if p.eat(&token::Comma) {
|
2014-06-23 15:51:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-10-27 19:22:52 +11:00
|
|
|
if p.token != token::Eof {
|
2014-01-18 01:53:10 +11:00
|
|
|
cx.span_err(sp, "expected token: `,`");
|
|
|
|
return None;
|
2012-12-12 17:08:09 -08:00
|
|
|
}
|
2012-07-12 17:59:59 -07:00
|
|
|
}
|
2014-01-18 01:53:10 +11:00
|
|
|
Some(es)
|
2012-07-12 17:59:59 -07:00
|
|
|
}
|