Skip to content

Commit 97e8d67

Browse files
committed
Break dependencies between syntax_ext and some other crates
Move `source_uitil` macros into `syntax_ext` Cleanup dependencies of `rustc_driver`
1 parent f69b071 commit 97e8d67

File tree

12 files changed

+48
-83
lines changed

12 files changed

+48
-83
lines changed

Cargo.lock

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,34 +2877,21 @@ dependencies = [
28772877
name = "rustc_driver"
28782878
version = "0.0.0"
28792879
dependencies = [
2880-
"arena 0.0.0",
28812880
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
28822881
"graphviz 0.0.0",
28832882
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
28842883
"rustc 0.0.0",
2885-
"rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
2886-
"rustc_allocator 0.0.0",
28872884
"rustc_ast_borrowck 0.0.0",
28882885
"rustc_codegen_utils 0.0.0",
28892886
"rustc_data_structures 0.0.0",
28902887
"rustc_errors 0.0.0",
2891-
"rustc_incremental 0.0.0",
28922888
"rustc_interface 0.0.0",
2893-
"rustc_lint 0.0.0",
28942889
"rustc_metadata 0.0.0",
28952890
"rustc_mir 0.0.0",
2896-
"rustc_passes 0.0.0",
2897-
"rustc_plugin 0.0.0",
2898-
"rustc_privacy 0.0.0",
2899-
"rustc_resolve 0.0.0",
29002891
"rustc_save_analysis 0.0.0",
29012892
"rustc_target 0.0.0",
2902-
"rustc_traits 0.0.0",
2903-
"rustc_typeck 0.0.0",
29042893
"serialize 0.0.0",
2905-
"smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
29062894
"syntax 0.0.0",
2907-
"syntax_ext 0.0.0",
29082895
"syntax_pos 0.0.0",
29092896
]
29102897

@@ -3076,7 +3063,6 @@ dependencies = [
30763063
"rustc_errors 0.0.0",
30773064
"rustc_mir 0.0.0",
30783065
"syntax 0.0.0",
3079-
"syntax_ext 0.0.0",
30803066
"syntax_pos 0.0.0",
30813067
]
30823068

@@ -3635,7 +3621,6 @@ name = "syntax_ext"
36353621
version = "0.0.0"
36363622
dependencies = [
36373623
"fmt_macros 0.0.0",
3638-
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
36393624
"rustc_data_structures 0.0.0",
36403625
"rustc_errors 0.0.0",
36413626
"rustc_target 0.0.0",

src/librustc_driver/Cargo.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,19 @@ path = "lib.rs"
1010
crate-type = ["dylib"]
1111

1212
[dependencies]
13-
arena = { path = "../libarena" }
1413
graphviz = { path = "../libgraphviz" }
1514
log = "0.4"
1615
env_logger = { version = "0.5", default-features = false }
17-
rayon = { version = "0.2.0", package = "rustc-rayon" }
1816
rustc = { path = "../librustc" }
19-
rustc_allocator = { path = "../librustc_allocator" }
2017
rustc_target = { path = "../librustc_target" }
2118
rustc_ast_borrowck = { path = "../librustc_ast_borrowck" }
2219
rustc_data_structures = { path = "../librustc_data_structures" }
2320
errors = { path = "../librustc_errors", package = "rustc_errors" }
24-
rustc_incremental = { path = "../librustc_incremental" }
25-
rustc_lint = { path = "../librustc_lint" }
2621
rustc_metadata = { path = "../librustc_metadata" }
2722
rustc_mir = { path = "../librustc_mir" }
28-
rustc_passes = { path = "../librustc_passes" }
29-
rustc_plugin = { path = "../librustc_plugin" }
30-
rustc_privacy = { path = "../librustc_privacy" }
31-
rustc_resolve = { path = "../librustc_resolve" }
3223
rustc_save_analysis = { path = "../librustc_save_analysis" }
33-
rustc_traits = { path = "../librustc_traits" }
3424
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
35-
rustc_typeck = { path = "../librustc_typeck" }
3625
rustc_interface = { path = "../librustc_interface" }
3726
serialize = { path = "../libserialize" }
3827
syntax = { path = "../libsyntax" }
39-
smallvec = { version = "0.6.7", features = ["union", "may_dangle"] }
40-
syntax_ext = { path = "../libsyntax_ext" }
4128
syntax_pos = { path = "../libsyntax_pos" }

src/librustc_passes/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ rustc = { path = "../librustc" }
1414
rustc_mir = { path = "../librustc_mir"}
1515
rustc_data_structures = { path = "../librustc_data_structures" }
1616
syntax = { path = "../libsyntax" }
17-
syntax_ext = { path = "../libsyntax_ext" }
1817
syntax_pos = { path = "../libsyntax_pos" }
1918
errors = { path = "../librustc_errors", package = "rustc_errors" }

src/librustc_passes/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ use rustc::session::Session;
1414
use rustc_data_structures::fx::FxHashMap;
1515
use syntax::ast::*;
1616
use syntax::attr;
17+
use syntax::ext::proc_macro::is_proc_macro_attr;
1718
use syntax::feature_gate::is_builtin_attr;
1819
use syntax::source_map::Spanned;
1920
use syntax::symbol::{kw, sym};
2021
use syntax::visit::{self, Visitor};
2122
use syntax::{span_err, struct_span_err, walk_list};
22-
use syntax_ext::proc_macro_decls::is_proc_macro_attr;
2323
use syntax_pos::{Span, MultiSpan};
2424
use errors::{Applicability, FatalError};
2525

src/libsyntax/ext/base.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::tokenstream::{self, TokenStream, TokenTree};
1414

1515
use errors::{DiagnosticBuilder, DiagnosticId};
1616
use smallvec::{smallvec, SmallVec};
17-
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
17+
use syntax_pos::{FileName, Span, MultiSpan, DUMMY_SP};
1818
use syntax_pos::hygiene::{ExpnInfo, ExpnKind};
1919

2020
use rustc_data_structures::fx::FxHashMap;
@@ -889,6 +889,27 @@ impl<'a> ExtCtxt<'a> {
889889
pub fn check_unused_macros(&self) {
890890
self.resolver.check_unused_macros();
891891
}
892+
893+
// resolve a file-system path to an absolute file-system path (if it
894+
// isn't already)
895+
pub fn res_rel_file(&self, sp: syntax_pos::Span, arg: String) -> PathBuf {
896+
let arg = PathBuf::from(arg);
897+
// Relative paths are resolved relative to the file in which they are found
898+
// after macro expansion (that is, they are unhygienic).
899+
if !arg.is_absolute() {
900+
let callsite = sp.source_callsite();
901+
let mut path = match self.source_map().span_to_unmapped_path(callsite) {
902+
FileName::Real(path) => path,
903+
FileName::DocTest(path, _) => path,
904+
other => panic!("cannot resolve relative path in non-file source `{}`", other),
905+
};
906+
path.pop();
907+
path.push(arg);
908+
path
909+
} else {
910+
arg
911+
}
912+
}
892913
}
893914

894915
/// Extracts a string literal from the macro expanded version of `expr`,

src/libsyntax/ext/proc_macro.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use crate::ast::Attribute;
2+
use crate::symbol::sym;
3+
4+
pub fn is_proc_macro_attr(attr: &Attribute) -> bool {
5+
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
6+
.iter().any(|kind| attr.check_name(*kind))
7+
}

src/libsyntax/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const MACRO_ARGUMENTS: Option<&'static str> = Some("macro arguments");
4040
// way towards a non-panic!-prone parser. It should be used for fatal parsing
4141
// errors; eventually we plan to convert all code using panictry to just use
4242
// normal try.
43+
#[macro_export]
4344
macro_rules! panictry {
4445
($e:expr) => ({
4546
use std::result::Result::{Ok, Err};
@@ -170,7 +171,7 @@ pub mod ext {
170171
pub mod derive;
171172
pub mod expand;
172173
pub mod placeholders;
173-
pub mod source_util;
174+
pub mod proc_macro;
174175

175176
pub mod tt {
176177
pub mod transcribe;

src/libsyntax_ext/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ syntax_pos = { path = "../libsyntax_pos" }
1717
rustc_data_structures = { path = "../librustc_data_structures" }
1818
rustc_target = { path = "../librustc_target" }
1919
smallvec = { version = "0.6.7", features = ["union", "may_dangle"] }
20-
log = "0.4"

src/libsyntax_ext/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mod format_foreign;
3131
mod global_asm;
3232
mod log_syntax;
3333
mod proc_macro_server;
34+
mod source_util;
3435
mod test;
3536
mod test_case;
3637
mod trace_macros;
@@ -93,7 +94,7 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
9394
)* }
9495
}
9596

96-
use syntax::ext::source_util::*;
97+
use source_util::*;
9798
register! {
9899
line: expand_line,
99100
column: expand_column,

src/libsyntax_ext/proc_macro_decls.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,15 @@ use syntax::ext::base::{ExtCtxt, MacroKind};
99
use syntax::ext::build::AstBuilder;
1010
use syntax::ext::expand::ExpansionConfig;
1111
use syntax::ext::hygiene::ExpnId;
12+
use syntax::ext::proc_macro::is_proc_macro_attr;
1213
use syntax::mut_visit::MutVisitor;
1314
use syntax::parse::ParseSess;
1415
use syntax::ptr::P;
15-
use syntax::symbol::Symbol;
1616
use syntax::symbol::{kw, sym};
1717
use syntax::visit::{self, Visitor};
1818

1919
use syntax_pos::{Span, DUMMY_SP};
2020

21-
const PROC_MACRO_KINDS: [Symbol; 3] = [
22-
sym::proc_macro_derive,
23-
sym::proc_macro_attribute,
24-
sym::proc_macro
25-
];
26-
2721
struct ProcMacroDerive {
2822
trait_name: ast::Name,
2923
function_name: Ident,
@@ -90,10 +84,6 @@ pub fn modify(sess: &ParseSess,
9084
krate
9185
}
9286

93-
pub fn is_proc_macro_attr(attr: &ast::Attribute) -> bool {
94-
PROC_MACRO_KINDS.iter().any(|kind| attr.check_name(*kind))
95-
}
96-
9787
impl<'a> CollectProcMacros<'a> {
9888
fn check_not_pub_in_root(&self, vis: &ast::Visibility, sp: Span) {
9989
if self.is_proc_macro_crate && self.in_root && vis.node.is_pub() {

0 commit comments

Comments
 (0)