Skip to content

Rollup of 10 pull requests #61943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
45bb409
Only show methods that appear in the impl block for types in the Impl…
ebarnard Jun 3, 2019
5fa8b52
move stray run-pass const tests into const/ folder
RalfJung Jun 9, 2019
ea1bec3
Turn down the myriad-closures test
alexcrichton Jun 14, 2019
007aaba
Remove unnecessary lift calls
Zoxc Jun 14, 2019
56e30e1
Tweak transparent enums and unions diagnostic spans
estebank Jun 11, 2019
f06b761
review comments: move diagnostic code out of happy path
estebank Jun 12, 2019
961ba8f
syntax: Factor out common fields from `SyntaxExtension` variants
petrochenkov Jun 16, 2019
679000c
allow_internal_unstable: Avoid some more allocations
petrochenkov Jun 16, 2019
085a8d0
syntax: Remove `DummyResolver`
petrochenkov Jun 17, 2019
68e1141
resolve: Avoid creating fresh syntax extensions for all non-macro att…
petrochenkov Jun 17, 2019
8ec502e
syntax: Introduce `default`/`with_unstable` constructors for `ExpnInfo`
petrochenkov Jun 17, 2019
2de2278
syntax: Move `default_transparency` into `ExpnInfo`
petrochenkov Jun 17, 2019
1ff3bce
hygiene: Avoid some unnecessary `ExpnInfo` clones
petrochenkov Jun 17, 2019
e152554
resolve/expand: Move expansion info setting to a single earlier point
petrochenkov Jun 18, 2019
0f9dc6c
Make MaybeUninit #[repr(transparent)]
mjbshaw Jun 12, 2019
dedf2ed
rustc_typeck: correctly compute `Substs` for `Res::SelfCtor`.
eddyb Jun 16, 2019
831ddf7
ci: Add a script for generating CPU usage graphs
alexcrichton Jun 14, 2019
d8eea92
create an issue for miri even in status test-fail
RalfJung Jun 18, 2019
830d15d
Rollup merge of #61505 - ebarnard:doc-shrink, r=GuillaumeGomez
Centril Jun 18, 2019
26880f6
Rollup merge of #61701 - RalfJung:const-tests, r=cramertj
Centril Jun 18, 2019
43ebb35
Rollup merge of #61748 - estebank:transparent-span, r=Centril
Centril Jun 18, 2019
32254ac
Rollup merge of #61802 - mjbshaw:maybe-uninit-transparent, r=cramertj
Centril Jun 18, 2019
4301ebd
Rollup merge of #61839 - alexcrichton:pr-and-master-builds, r=pietroa…
Centril Jun 18, 2019
78f9399
Rollup merge of #61842 - Zoxc:trim-lift, r=eddyb
Centril Jun 18, 2019
ebf9696
Rollup merge of #61843 - alexcrichton:disable-myriad-closures, r=piet…
Centril Jun 18, 2019
f755231
Rollup merge of #61896 - eddyb:correct-self-ctor, r=petrochenkov
Centril Jun 18, 2019
0bb197c
Rollup merge of #61898 - petrochenkov:sekind, r=eddyb
Centril Jun 18, 2019
0b8da29
Rollup merge of #61938 - RalfJung:miri-toolstate, r=kennytm
Centril Jun 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
resolve/expand: Move expansion info setting to a single earlier point
  • Loading branch information
petrochenkov committed Jun 18, 2019
commit e152554e11ff44b1a08e21a8416e1fc18504764e
31 changes: 26 additions & 5 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ fn sub_namespace_match(candidate: Option<MacroKind>, requirement: Option<MacroKi
candidate.is_none() || requirement.is_none() || candidate == requirement
}

// We don't want to format a path using pretty-printing,
// `format!("{}", path)`, because that tries to insert
// line-breaks and is slow.
fn fast_print_path(path: &ast::Path) -> String {
let mut path_str = String::with_capacity(64);
for (i, segment) in path.segments.iter().enumerate() {
if i != 0 {
path_str.push_str("::");
}
if segment.ident.name != kw::PathRoot {
path_str.push_str(&segment.ident.as_str())
}
}
path_str
}

impl<'a> base::Resolver for Resolver<'a> {
fn next_node_id(&mut self) -> ast::NodeId {
self.session.next_node_id()
Expand Down Expand Up @@ -209,14 +225,19 @@ impl<'a> base::Resolver for Resolver<'a> {
let parent_scope = self.invoc_parent_scope(invoc_id, derives_in_scope);
let (res, ext) = match self.resolve_macro_to_res(path, kind, &parent_scope, true, force) {
Ok((res, ext)) => (res, ext),
Err(Determinacy::Determined) if kind == MacroKind::Attr => {
// Replace unresolved attributes with used inert attributes for better recovery.
return Ok(Some(self.non_macro_attr(true)));
}
// Replace unresolved attributes with used inert attributes for better recovery.
Err(Determinacy::Determined) if kind == MacroKind::Attr =>
(Res::Err, self.non_macro_attr(true)),
Err(determinacy) => return Err(determinacy),
};

if let Res::Def(DefKind::Macro(_), def_id) = res {
let format = match kind {
MacroKind::Derive => format!("derive({})", fast_print_path(path)),
_ => fast_print_path(path),
};
invoc.expansion_data.mark.set_expn_info(ext.expn_info(invoc.span(), &format));

if let Res::Def(_, def_id) = res {
if after_derive {
self.session.span_err(invoc.span(),
"macro attributes must be placed before `#[derive]`");
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ impl SyntaxExtension {
}
}

crate fn expn_info(&self, call_site: Span, format: &str) -> ExpnInfo {
pub fn expn_info(&self, call_site: Span, format: &str) -> ExpnInfo {
ExpnInfo {
call_site,
format: self.expn_format(Symbol::intern(format)),
Expand Down
32 changes: 3 additions & 29 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,6 @@ impl AstFragmentKind {
}
}

// We don't want to format a path using pretty-printing,
// `format!("{}", path)`, because that tries to insert
// line-breaks and is slow.
fn fast_print_path(path: &ast::Path) -> String {
let mut path_str = String::with_capacity(64);
for (i, segment) in path.segments.iter().enumerate() {
if i != 0 {
path_str.push_str("::");
}
if segment.ident.name != kw::PathRoot {
path_str.push_str(&segment.ident.as_str())
}
}
path_str
}

pub struct Invocation {
pub kind: InvocationKind,
fragment_kind: AstFragmentKind,
Expand Down Expand Up @@ -546,9 +530,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
_ => unreachable!(),
};

let expn_info = ext.expn_info(attr.span, &fast_print_path(&attr.path));
invoc.expansion_data.mark.set_expn_info(expn_info);

match &ext.kind {
SyntaxExtensionKind::NonMacroAttr { mark_used } => {
attr::mark_known(&attr);
Expand Down Expand Up @@ -682,15 +663,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
invoc: Invocation,
ext: &SyntaxExtension)
-> Option<AstFragment> {
let (mark, kind) = (invoc.expansion_data.mark, invoc.fragment_kind);
let kind = invoc.fragment_kind;
let (mac, ident, span) = match invoc.kind {
InvocationKind::Bang { mac, ident, span } => (mac, ident, span),
_ => unreachable!(),
};
let path = &mac.node.path;

let ident = ident.unwrap_or_else(|| Ident::invalid());
let validate_and_set_expn_info = |this: &mut Self| {
let validate = |this: &mut Self| {
// feature-gate the macro invocation
if let Some((feature, issue)) = ext.unstable_feature {
let crate_span = this.cx.current_expansion.crate_span.unwrap();
Expand All @@ -715,13 +696,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
this.cx.trace_macros_diag();
return Err(kind.dummy(span));
}
mark.set_expn_info(ext.expn_info(span, &fast_print_path(path)));
Ok(())
};

let opt_expanded = match &ext.kind {
SyntaxExtensionKind::LegacyBang(expander) => {
if let Err(dummy_span) = validate_and_set_expn_info(self) {
if let Err(dummy_span) = validate(self) {
dummy_span
} else {
kind.make_from(expander.expand(
Expand Down Expand Up @@ -757,8 +737,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
kind.dummy(span)
} else {
self.gate_proc_macro_expansion_kind(span, kind);
let expn_info = ext.expn_info(span, &fast_print_path(path));
invoc.expansion_data.mark.set_expn_info(expn_info);
let tok_result = expander.expand(self.cx, span, mac.node.stream());
let result = self.parse_ast_fragment(tok_result, kind, path, span);
self.gate_proc_macro_expansion(span, &result);
Expand Down Expand Up @@ -818,10 +796,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
match &ext.kind {
SyntaxExtensionKind::Derive(expander) |
SyntaxExtensionKind::LegacyDerive(expander) => {
let expn_info =
ext.expn_info(path.span, &format!("derive({})", fast_print_path(&path)));
invoc.expansion_data.mark.set_expn_info(expn_info);

let meta = ast::MetaItem { node: ast::MetaItemKind::Word, span: path.span, path };
let span = meta.span.with_ctxt(self.cx.backtrace());
let items = expander.expand(self.cx, span, &meta, item);
Expand Down