Skip to content

Commit c117689

Browse files
Revert changes of moving resolve_path function. Add 2 new symbols to test the overhead caused by adding new symbols.
1 parent 35d282c commit c117689

File tree

6 files changed

+45
-46
lines changed

6 files changed

+45
-46
lines changed

compiler/rustc_builtin_macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod format;
3838
mod format_foreign;
3939
mod global_allocator;
4040
mod log_syntax;
41-
pub mod source_util;
41+
mod source_util;
4242
mod test;
4343
mod trace_macros;
4444
mod util;

compiler/rustc_builtin_macros/src/source_util.rs

+1-41
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@ use rustc_ast::ptr::P;
33
use rustc_ast::token;
44
use rustc_ast::tokenstream::TokenStream;
55
use rustc_ast_pretty::pprust;
6-
use rustc_errors::PResult;
76
use rustc_expand::base::{self, *};
87
use rustc_expand::module::DirOwnership;
98
use rustc_parse::parser::{ForceCollect, Parser};
109
use rustc_parse::{self, new_parser_from_file};
1110
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
12-
use rustc_session::parse::ParseSess;
1311
use rustc_span::symbol::Symbol;
14-
use rustc_span::{self, FileName, Pos, Span};
12+
use rustc_span::{self, Pos, Span};
1513

1614
use smallvec::SmallVec;
17-
use std::path::PathBuf;
1815
use std::rc::Rc;
1916

2017
// These macros all relate to the file system; they either return
@@ -226,40 +223,3 @@ pub fn expand_include_bytes(
226223
}
227224
}
228225
}
229-
230-
/// Resolves a `path` mentioned inside Rust code, returning an absolute path.
231-
///
232-
/// This unifies the logic used for resolving `include_X!`.
233-
pub fn resolve_path(
234-
parse_sess: &ParseSess,
235-
path: impl Into<PathBuf>,
236-
span: Span,
237-
) -> PResult<'_, PathBuf> {
238-
let path = path.into();
239-
240-
// Relative paths are resolved relative to the file in which they are found
241-
// after macro expansion (that is, they are unhygienic).
242-
if !path.is_absolute() {
243-
let callsite = span.source_callsite();
244-
let mut result = match parse_sess.source_map().span_to_filename(callsite) {
245-
FileName::Real(name) => name
246-
.into_local_path()
247-
.expect("attempting to resolve a file path in an external file"),
248-
FileName::DocTest(path, _) => path,
249-
other => {
250-
return Err(parse_sess.span_diagnostic.struct_span_err(
251-
span,
252-
&format!(
253-
"cannot resolve relative path in non-file source `{}`",
254-
parse_sess.source_map().filename_for_diagnostics(&other)
255-
),
256-
));
257-
}
258-
};
259-
result.pop();
260-
result.push(path);
261-
Ok(result)
262-
} else {
263-
Ok(path)
264-
}
265-
}

compiler/rustc_expand/src/base.rs

+39-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_ast::{self as ast, Attribute, HasAttrs, Item, NodeId, PatKind};
1010
use rustc_attr::{self as attr, Deprecation, Stability};
1111
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1212
use rustc_data_structures::sync::{self, Lrc};
13-
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
13+
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult};
1414
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
1515
use rustc_lint_defs::BuiltinLintDiagnostics;
1616
use rustc_parse::{self, parser, to_token_stream, MACRO_ARGUMENTS};
@@ -20,7 +20,7 @@ use rustc_span::edition::Edition;
2020
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
2121
use rustc_span::source_map::SourceMap;
2222
use rustc_span::symbol::{kw, sym, Ident, Symbol};
23-
use rustc_span::{Span, DUMMY_SP};
23+
use rustc_span::{FileName, Span, DUMMY_SP};
2424
use smallvec::{smallvec, SmallVec};
2525

2626
use std::default::Default;
@@ -1137,6 +1137,43 @@ impl<'a> ExtCtxt<'a> {
11371137
}
11381138
}
11391139

1140+
/// Resolves a `path` mentioned inside Rust code, returning an absolute path.
1141+
///
1142+
/// This unifies the logic used for resolving `include_X!`.
1143+
pub fn resolve_path(
1144+
parse_sess: &ParseSess,
1145+
path: impl Into<PathBuf>,
1146+
span: Span,
1147+
) -> PResult<'_, PathBuf> {
1148+
let path = path.into();
1149+
1150+
// Relative paths are resolved relative to the file in which they are found
1151+
// after macro expansion (that is, they are unhygienic).
1152+
if !path.is_absolute() {
1153+
let callsite = span.source_callsite();
1154+
let mut result = match parse_sess.source_map().span_to_filename(callsite) {
1155+
FileName::Real(name) => name
1156+
.into_local_path()
1157+
.expect("attempting to resolve a file path in an external file"),
1158+
FileName::DocTest(path, _) => path,
1159+
other => {
1160+
return Err(parse_sess.span_diagnostic.struct_span_err(
1161+
span,
1162+
&format!(
1163+
"cannot resolve relative path in non-file source `{}`",
1164+
parse_sess.source_map().filename_for_diagnostics(&other)
1165+
),
1166+
));
1167+
}
1168+
};
1169+
result.pop();
1170+
result.push(path);
1171+
Ok(result)
1172+
} else {
1173+
Ok(path)
1174+
}
1175+
}
1176+
11401177
/// Extracts a string literal from the macro expanded version of `expr`,
11411178
/// returning a diagnostic error of `err_msg` if `expr` is not a string literal.
11421179
/// The returned bool indicates whether an applicable suggestion has already been

compiler/rustc_passes/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rustc_middle = { path = "../rustc_middle" }
99
rustc_attr = { path = "../rustc_attr" }
1010
rustc_data_structures = { path = "../rustc_data_structures" }
1111
rustc_errors = { path = "../rustc_errors" }
12-
rustc_builtin_macros = { path = "../rustc_builtin_macros" }
12+
rustc_expand = { path = "../rustc_expand" }
1313
rustc_hir = { path = "../rustc_hir" }
1414
rustc_index = { path = "../rustc_index" }
1515
rustc_parse = { path = "../rustc_parse" }

compiler/rustc_passes/src/debugger_visualizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Detecting usage of the `#[debugger_visualizer]` attribute.
22
33
use hir::CRATE_HIR_ID;
4-
use rustc_builtin_macros::source_util::resolve_path;
54
use rustc_data_structures::fx::FxHashSet;
5+
use rustc_expand::base::resolve_path;
66
use rustc_hir as hir;
77
use rustc_hir::def_id::CrateNum;
88
use rustc_hir::itemlikevisit::ItemLikeVisitor;

compiler/rustc_span/src/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ symbols! {
557557
debug_trait_builder,
558558
debug_tuple,
559559
debugger_visualizer,
560+
debuggervisualizer,
560561
decl_macro,
561562
declare_lint_pass,
562563
decode,
@@ -929,6 +930,7 @@ symbols! {
929930
native_link_modifiers_verbatim,
930931
native_link_modifiers_whole_archive,
931932
natvis_file,
933+
natvisfile,
932934
ne,
933935
nearbyintf32,
934936
nearbyintf64,

0 commit comments

Comments
 (0)