Skip to content

Commit

Permalink
proc_macro: move the rustc server to syntax_ext.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Nov 30, 2018
1 parent 38fee30 commit 8cf463b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
6 changes: 0 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1599,12 +1599,6 @@ dependencies = [
[[package]]
name = "proc_macro"
version = "0.0.0"
dependencies = [
"rustc_data_structures 0.0.0",
"rustc_errors 0.0.0",
"syntax 0.0.0",
"syntax_pos 0.0.0",
]

[[package]]
name = "profiler_builtins"
Expand Down
5 changes: 0 additions & 5 deletions src/libproc_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@ version = "0.0.0"
path = "lib.rs"
crate-type = ["dylib"]

[dependencies]
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_errors = { path = "../librustc_errors" }
rustc_data_structures = { path = "../librustc_data_structures" }
10 changes: 0 additions & 10 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]

#![feature(nll)]
#![feature(rustc_private)]
#![feature(staged_api)]
#![feature(const_fn)]
#![feature(extern_types)]
Expand All @@ -39,19 +38,10 @@

#![recursion_limit="256"]

extern crate syntax;
extern crate syntax_pos;
extern crate rustc_errors;
extern crate rustc_data_structures;

#[unstable(feature = "proc_macro_internals", issue = "27812")]
#[doc(hidden)]
pub mod bridge;

#[unstable(feature = "proc_macro_internals", issue = "27812")]
#[doc(hidden)]
pub mod rustc;

mod diagnostic;

#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl MultiItemModifier for ProcMacroDerive {
let token = Token::interpolated(token::NtItem(item));
let input = tokenstream::TokenTree::Token(DUMMY_SP, token).into();

let server = ::proc_macro::rustc::Rustc::new(ecx);
let server = ::proc_macro_server::Rustc::new(ecx);
let stream = match self.client.run(&EXEC_STRATEGY, server, input) {
Ok(stream) => stream,
Err(e) => {
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax_ext/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")]

#![feature(in_band_lifetimes)]
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_internals)]
#![feature(proc_macro_span)]
#![feature(decl_macro)]
#![feature(nll)]
#![feature(str_escape)]
Expand Down Expand Up @@ -57,6 +60,7 @@ mod test_case;

pub mod proc_macro_decls;
pub mod proc_macro_impl;
mod proc_macro_server;

use rustc_data_structures::sync::Lrc;
use syntax::ast;
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/proc_macro_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl base::AttrProcMacro for AttrProcMacro {
annotation: TokenStream,
annotated: TokenStream)
-> TokenStream {
let server = ::proc_macro::rustc::Rustc::new(ecx);
let server = ::proc_macro_server::Rustc::new(ecx);
match self.client.run(&EXEC_STRATEGY, server, annotation, annotated) {
Ok(stream) => stream,
Err(e) => {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl base::ProcMacro for BangProcMacro {
span: Span,
input: TokenStream)
-> TokenStream {
let server = ::proc_macro::rustc::Rustc::new(ecx);
let server = ::proc_macro_server::Rustc::new(ecx);
match self.client.run(&EXEC_STRATEGY, server, input) {
Ok(stream) => stream,
Err(e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use bridge::{server, TokenTree};
use {Delimiter, Level, LineColumn, Spacing};
use errors::{self, Diagnostic, DiagnosticBuilder};
use std::panic;

use proc_macro::bridge::{server, TokenTree};
use proc_macro::{Delimiter, Level, LineColumn, Spacing};

use rustc_data_structures::sync::Lrc;
use rustc_errors::{self as errors, Diagnostic, DiagnosticBuilder};
use std::ascii;
use std::ops::Bound;
use syntax::ast;
Expand All @@ -24,7 +26,15 @@ use syntax_pos::hygiene::{SyntaxContext, Transparency};
use syntax_pos::symbol::{keywords, Symbol};
use syntax_pos::{BytePos, FileName, MultiSpan, Pos, SourceFile, Span};

impl Delimiter {
trait FromInternal<T> {
fn from_internal(x: T) -> Self;
}

trait ToInternal<T> {
fn to_internal(self) -> T;
}

impl FromInternal<token::DelimToken> for Delimiter {
fn from_internal(delim: token::DelimToken) -> Delimiter {
match delim {
token::Paren => Delimiter::Parenthesis,
Expand All @@ -33,7 +43,9 @@ impl Delimiter {
token::NoDelim => Delimiter::None,
}
}
}

impl ToInternal<token::DelimToken> for Delimiter {
fn to_internal(self) -> token::DelimToken {
match self {
Delimiter::Parenthesis => token::Paren,
Expand All @@ -44,8 +56,10 @@ impl Delimiter {
}
}

impl TokenTree<Group, Punct, Ident, Literal> {
fn from_internal(stream: TokenStream, sess: &ParseSess, stack: &mut Vec<Self>) -> Self {
impl FromInternal<(TokenStream, &'_ ParseSess, &'_ mut Vec<Self>)>
for TokenTree<Group, Punct, Ident, Literal>
{
fn from_internal((stream, sess, stack): (TokenStream, &ParseSess, &mut Vec<Self>)) -> Self {
use syntax::parse::token::*;

let (tree, joint) = stream.as_tree();
Expand Down Expand Up @@ -204,7 +218,9 @@ impl TokenTree<Group, Punct, Ident, Literal> {
Whitespace | Comment | Shebang(..) | Eof => unreachable!(),
}
}
}

impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
fn to_internal(self) -> TokenStream {
use syntax::parse::token::*;

Expand Down Expand Up @@ -292,13 +308,14 @@ impl TokenTree<Group, Punct, Ident, Literal> {
}
}

impl Level {
impl ToInternal<errors::Level> for Level {
fn to_internal(self) -> errors::Level {
match self {
Level::Error => errors::Level::Error,
Level::Warning => errors::Level::Warning,
Level::Note => errors::Level::Note,
Level::Help => errors::Level::Help,
_ => unreachable!("unknown proc_macro::Level variant: {:?}", self),
}
}
}
Expand Down Expand Up @@ -339,7 +356,7 @@ pub struct Literal {
span: Span,
}

pub struct Rustc<'a> {
pub(crate) struct Rustc<'a> {
sess: &'a ParseSess,
def_site: Span,
call_site: Span,
Expand Down Expand Up @@ -429,7 +446,7 @@ impl server::TokenStreamIter for Rustc<'_> {
loop {
let tree = iter.stack.pop().or_else(|| {
let next = iter.cursor.next_as_stream()?;
Some(TokenTree::from_internal(next, self.sess, &mut iter.stack))
Some(TokenTree::from_internal((next, self.sess, &mut iter.stack)))
})?;
// HACK: The condition "dummy span + group with empty delimiter" represents an AST
// fragment approximately converted into a token stream. This may happen, for
Expand Down

0 comments on commit 8cf463b

Please sign in to comment.