Skip to content

Commit 2e6eace

Browse files
committed
Auto merge of #69118 - Dylan-DPC:rollup-7hpm1fj, r=Dylan-DPC
Rollup of 9 pull requests Successful merges: - #67642 (Relax bounds on HashMap/HashSet) - #68848 (Hasten macro parsing) - #69008 (Properly use parent generics for opaque types) - #69048 (Suggestion when encountering assoc types from hrtb) - #69049 (Optimize image sizes) - #69050 (Micro-optimize the heck out of LEB128 reading and writing.) - #69068 (Make the SGX arg cleanup implementation a NOP) - #69082 (When expecting `BoxFuture` and using `async {}`, suggest `Box::pin`) - #69104 (bootstrap: Configure cmake when building sanitizer runtimes) Failed merges: r? @ghost
2 parents ba18875 + 1ddf250 commit 2e6eace

36 files changed

+584
-253
lines changed

src/bootstrap/native.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl Step for Llvm {
262262
cfg.define("PYTHON_EXECUTABLE", python);
263263
}
264264

265-
configure_cmake(builder, target, &mut cfg);
265+
configure_cmake(builder, target, &mut cfg, true);
266266

267267
// FIXME: we don't actually need to build all LLVM tools and all LLVM
268268
// libraries here, e.g., we just want a few components and a few
@@ -301,7 +301,12 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
301301
panic!("\n\nbad LLVM version: {}, need >=7.0\n\n", version)
302302
}
303303

304-
fn configure_cmake(builder: &Builder<'_>, target: Interned<String>, cfg: &mut cmake::Config) {
304+
fn configure_cmake(
305+
builder: &Builder<'_>,
306+
target: Interned<String>,
307+
cfg: &mut cmake::Config,
308+
use_compiler_launcher: bool,
309+
) {
305310
// Do not print installation messages for up-to-date files.
306311
// LLVM and LLD builds can produce a lot of those and hit CI limits on log size.
307312
cfg.define("CMAKE_INSTALL_MESSAGE", "LAZY");
@@ -372,9 +377,11 @@ fn configure_cmake(builder: &Builder<'_>, target: Interned<String>, cfg: &mut cm
372377
} else {
373378
// If ccache is configured we inform the build a little differently how
374379
// to invoke ccache while also invoking our compilers.
375-
if let Some(ref ccache) = builder.config.ccache {
376-
cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache)
377-
.define("CMAKE_CXX_COMPILER_LAUNCHER", ccache);
380+
if use_compiler_launcher {
381+
if let Some(ref ccache) = builder.config.ccache {
382+
cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache)
383+
.define("CMAKE_CXX_COMPILER_LAUNCHER", ccache);
384+
}
378385
}
379386
cfg.define("CMAKE_C_COMPILER", sanitize_cc(cc))
380387
.define("CMAKE_CXX_COMPILER", sanitize_cc(cxx));
@@ -458,7 +465,7 @@ impl Step for Lld {
458465
t!(fs::create_dir_all(&out_dir));
459466

460467
let mut cfg = cmake::Config::new(builder.src.join("src/llvm-project/lld"));
461-
configure_cmake(builder, target, &mut cfg);
468+
configure_cmake(builder, target, &mut cfg, true);
462469

463470
// This is an awful, awful hack. Discovered when we migrated to using
464471
// clang-cl to compile LLVM/LLD it turns out that LLD, when built out of
@@ -595,10 +602,7 @@ impl Step for Sanitizers {
595602
let _time = util::timeit(&builder);
596603

597604
let mut cfg = cmake::Config::new(&compiler_rt_dir);
598-
cfg.target(&self.target);
599-
cfg.host(&builder.config.build);
600605
cfg.profile("Release");
601-
602606
cfg.define("CMAKE_C_COMPILER_TARGET", self.target);
603607
cfg.define("COMPILER_RT_BUILD_BUILTINS", "OFF");
604608
cfg.define("COMPILER_RT_BUILD_CRT", "OFF");
@@ -610,6 +614,12 @@ impl Step for Sanitizers {
610614
cfg.define("COMPILER_RT_USE_LIBCXX", "OFF");
611615
cfg.define("LLVM_CONFIG_PATH", &llvm_config);
612616

617+
// On Darwin targets the sanitizer runtimes are build as universal binaries.
618+
// Unfortunately sccache currently lacks support to build them successfully.
619+
// Disable compiler launcher on Darwin targets to avoid potential issues.
620+
let use_compiler_launcher = !self.target.contains("apple-darwin");
621+
configure_cmake(builder, self.target, &mut cfg, use_compiler_launcher);
622+
613623
t!(fs::create_dir_all(&out_dir));
614624
cfg.out_dir(out_dir);
615625

src/etc/installer/gfx/rust-logo.png

-1.89 KB
Loading

src/libcore/marker.rs

+4
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,10 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
727727
/// [`Pin<P>`]: ../pin/struct.Pin.html
728728
/// [`pin module`]: ../../std/pin/index.html
729729
#[stable(feature = "pin", since = "1.33.0")]
730+
#[rustc_on_unimplemented(
731+
on(_Self = "std::future::Future", note = "consider using `Box::pin`",),
732+
message = "`{Self}` cannot be unpinned"
733+
)]
730734
#[lang = "unpin"]
731735
pub auto trait Unpin {}
732736

src/librustc/traits/error_reporting/on_unimplemented.rs

+10
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
201201
}
202202
}
203203
}
204+
if let ty::Dynamic(traits, _) = self_ty.kind {
205+
for t in *traits.skip_binder() {
206+
match t {
207+
ty::ExistentialPredicate::Trait(trait_ref) => {
208+
flags.push((sym::_Self, Some(self.tcx.def_path_str(trait_ref.def_id))))
209+
}
210+
_ => {}
211+
}
212+
}
213+
}
204214

205215
if let Ok(Some(command)) =
206216
OnUnimplementedDirective::of_item(self.tcx, trait_ref.def_id, def_id)

src/librustc/traits/error_reporting/suggestions.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -701,10 +701,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
701701
})
702702
.collect::<Vec<_>>();
703703
// Add the suggestion for the return type.
704-
suggestions.push((
705-
ret_ty.span,
706-
format!("Box<{}{}>", if has_dyn { "" } else { "dyn " }, snippet),
707-
));
704+
suggestions.push((ret_ty.span, format!("Box<dyn {}>", trait_obj)));
708705
err.multipart_suggestion(
709706
"return a boxed trait object instead",
710707
suggestions,

src/librustc_expand/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(cow_is_borrowed)]
12
#![feature(crate_visibility_modifier)]
23
#![feature(decl_macro)]
34
#![feature(proc_macro_diagnostic)]

src/librustc_expand/mbe/macro_parser.rs

+14-34
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,19 @@ use crate::mbe::{self, TokenTree};
7878

7979
use rustc_ast_pretty::pprust;
8080
use rustc_parse::parser::{FollowedByType, Parser, PathStyle};
81-
use rustc_parse::Directory;
8281
use rustc_session::parse::ParseSess;
8382
use rustc_span::symbol::{kw, sym, Symbol};
8483
use syntax::ast::{Ident, Name};
8584
use syntax::ptr::P;
8685
use syntax::token::{self, DocComment, Nonterminal, Token};
87-
use syntax::tokenstream::TokenStream;
8886

8987
use rustc_errors::{FatalError, PResult};
9088
use rustc_span::Span;
9189
use smallvec::{smallvec, SmallVec};
9290

9391
use rustc_data_structures::fx::FxHashMap;
9492
use rustc_data_structures::sync::Lrc;
93+
use std::borrow::Cow;
9594
use std::collections::hash_map::Entry::{Occupied, Vacant};
9695
use std::mem;
9796
use std::ops::{Deref, DerefMut};
@@ -613,28 +612,9 @@ fn inner_parse_loop<'root, 'tt>(
613612
Success(())
614613
}
615614

616-
/// Use the given sequence of token trees (`ms`) as a matcher. Match the given token stream `tts`
617-
/// against it and return the match.
618-
///
619-
/// # Parameters
620-
///
621-
/// - `sess`: The session into which errors are emitted
622-
/// - `tts`: The tokenstream we are matching against the pattern `ms`
623-
/// - `ms`: A sequence of token trees representing a pattern against which we are matching
624-
/// - `directory`: Information about the file locations (needed for the black-box parser)
625-
/// - `recurse_into_modules`: Whether or not to recurse into modules (needed for the black-box
626-
/// parser)
627-
pub(super) fn parse(
628-
sess: &ParseSess,
629-
tts: TokenStream,
630-
ms: &[TokenTree],
631-
directory: Option<Directory<'_>>,
632-
recurse_into_modules: bool,
633-
) -> NamedParseResult {
634-
// Create a parser that can be used for the "black box" parts.
635-
let mut parser =
636-
Parser::new(sess, tts, directory, recurse_into_modules, true, rustc_parse::MACRO_ARGUMENTS);
637-
615+
/// Use the given sequence of token trees (`ms`) as a matcher. Match the token
616+
/// stream from the given `parser` against it and return the match.
617+
pub(super) fn parse_tt(parser: &mut Cow<'_, Parser<'_>>, ms: &[TokenTree]) -> NamedParseResult {
638618
// A queue of possible matcher positions. We initialize it with the matcher position in which
639619
// the "dot" is before the first token of the first token tree in `ms`. `inner_parse_loop` then
640620
// processes all of these possible matcher positions and produces possible next positions into
@@ -659,7 +639,7 @@ pub(super) fn parse(
659639
// parsing from the black-box parser done. The result is that `next_items` will contain a
660640
// bunch of possible next matcher positions in `next_items`.
661641
match inner_parse_loop(
662-
sess,
642+
parser.sess,
663643
&mut cur_items,
664644
&mut next_items,
665645
&mut eof_items,
@@ -684,7 +664,7 @@ pub(super) fn parse(
684664
if eof_items.len() == 1 {
685665
let matches =
686666
eof_items[0].matches.iter_mut().map(|dv| Lrc::make_mut(dv).pop().unwrap());
687-
return nameize(sess, ms, matches);
667+
return nameize(parser.sess, ms, matches);
688668
} else if eof_items.len() > 1 {
689669
return Error(
690670
parser.token.span,
@@ -709,9 +689,14 @@ pub(super) fn parse(
709689
// unnecessary implicit clone later in Rc::make_mut.
710690
drop(eof_items);
711691

692+
// If there are no possible next positions AND we aren't waiting for the black-box parser,
693+
// then there is a syntax error.
694+
if bb_items.is_empty() && next_items.is_empty() {
695+
return Failure(parser.token.clone(), "no rules expected this token in macro call");
696+
}
712697
// Another possibility is that we need to call out to parse some rust nonterminal
713698
// (black-box) parser. However, if there is not EXACTLY ONE of these, something is wrong.
714-
if (!bb_items.is_empty() && !next_items.is_empty()) || bb_items.len() > 1 {
699+
else if (!bb_items.is_empty() && !next_items.is_empty()) || bb_items.len() > 1 {
715700
let nts = bb_items
716701
.iter()
717702
.map(|item| match item.top_elts.get_tt(item.idx) {
@@ -733,16 +718,11 @@ pub(super) fn parse(
733718
),
734719
);
735720
}
736-
// If there are no possible next positions AND we aren't waiting for the black-box parser,
737-
// then there is a syntax error.
738-
else if bb_items.is_empty() && next_items.is_empty() {
739-
return Failure(parser.token.take(), "no rules expected this token in macro call");
740-
}
741721
// Dump all possible `next_items` into `cur_items` for the next iteration.
742722
else if !next_items.is_empty() {
743723
// Now process the next token
744724
cur_items.extend(next_items.drain(..));
745-
parser.bump();
725+
parser.to_mut().bump();
746726
}
747727
// Finally, we have the case where we need to call the black-box parser to get some
748728
// nonterminal.
@@ -754,7 +734,7 @@ pub(super) fn parse(
754734
let match_cur = item.match_cur;
755735
item.push_match(
756736
match_cur,
757-
MatchedNonterminal(Lrc::new(parse_nt(&mut parser, span, ident.name))),
737+
MatchedNonterminal(Lrc::new(parse_nt(parser.to_mut(), span, ident.name))),
758738
);
759739
item.idx += 1;
760740
item.match_cur += 1;

src/librustc_expand/mbe/macro_rules.rs

+47-17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::base::{DummyResult, ExtCtxt, MacResult, TTMacroExpander};
1+
use crate::base::{DummyResult, ExpansionData, ExtCtxt, MacResult, TTMacroExpander};
22
use crate::base::{SyntaxExtension, SyntaxExtensionKind};
33
use crate::expand::{ensure_complete_parse, parse_ast_fragment, AstFragment, AstFragmentKind};
44
use crate::mbe;
55
use crate::mbe::macro_check;
6-
use crate::mbe::macro_parser::parse;
6+
use crate::mbe::macro_parser::parse_tt;
77
use crate::mbe::macro_parser::{Error, Failure, Success};
8-
use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, NamedParseResult};
8+
use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq};
99
use crate::mbe::transcribe::transcribe;
1010

1111
use rustc_ast_pretty::pprust;
@@ -166,9 +166,9 @@ impl TTMacroExpander for MacroRulesMacroExpander {
166166
}
167167
}
168168

169-
fn trace_macros_note(cx: &mut ExtCtxt<'_>, sp: Span, message: String) {
169+
fn trace_macros_note(cx_expansions: &mut FxHashMap<Span, Vec<String>>, sp: Span, message: String) {
170170
let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
171-
cx.expansions.entry(sp).or_default().push(message);
171+
cx_expansions.entry(sp).or_default().push(message);
172172
}
173173

174174
/// Given `lhses` and `rhses`, this is the new macro we create
@@ -184,12 +184,36 @@ fn generic_extension<'cx>(
184184
) -> Box<dyn MacResult + 'cx> {
185185
if cx.trace_macros() {
186186
let msg = format!("expanding `{}! {{ {} }}`", name, pprust::tts_to_string(arg.clone()));
187-
trace_macros_note(cx, sp, msg);
187+
trace_macros_note(&mut cx.expansions, sp, msg);
188188
}
189189

190190
// Which arm's failure should we report? (the one furthest along)
191191
let mut best_failure: Option<(Token, &str)> = None;
192+
193+
// We create a base parser that can be used for the "black box" parts.
194+
// Every iteration needs a fresh copy of that base parser. However, the
195+
// parser is not mutated on many of the iterations, particularly when
196+
// dealing with macros like this:
197+
//
198+
// macro_rules! foo {
199+
// ("a") => (A);
200+
// ("b") => (B);
201+
// ("c") => (C);
202+
// // ... etc. (maybe hundreds more)
203+
// }
204+
//
205+
// as seen in the `html5ever` benchmark. We use a `Cow` so that the base
206+
// parser is only cloned when necessary (upon mutation). Furthermore, we
207+
// reinitialize the `Cow` with the base parser at the start of every
208+
// iteration, so that any mutated parsers are not reused. This is all quite
209+
// hacky, but speeds up the `html5ever` benchmark significantly. (Issue
210+
// 68836 suggests a more comprehensive but more complex change to deal with
211+
// this situation.)
212+
let base_parser = base_parser_from_cx(&cx.current_expansion, &cx.parse_sess, arg.clone());
213+
192214
for (i, lhs) in lhses.iter().enumerate() {
215+
let mut parser = Cow::Borrowed(&base_parser);
216+
193217
// try each arm's matchers
194218
let lhs_tt = match *lhs {
195219
mbe::TokenTree::Delimited(_, ref delim) => &delim.tts[..],
@@ -202,7 +226,7 @@ fn generic_extension<'cx>(
202226
// are not recorded. On the first `Success(..)`ful matcher, the spans are merged.
203227
let mut gated_spans_snaphot = mem::take(&mut *cx.parse_sess.gated_spans.spans.borrow_mut());
204228

205-
match parse_tt(cx, lhs_tt, arg.clone()) {
229+
match parse_tt(&mut parser, lhs_tt) {
206230
Success(named_matches) => {
207231
// The matcher was `Success(..)`ful.
208232
// Merge the gated spans from parsing the matcher with the pre-existing ones.
@@ -232,11 +256,11 @@ fn generic_extension<'cx>(
232256

233257
if cx.trace_macros() {
234258
let msg = format!("to `{}`", pprust::tts_to_string(tts.clone()));
235-
trace_macros_note(cx, sp, msg);
259+
trace_macros_note(&mut cx.expansions, sp, msg);
236260
}
237261

238262
let directory = Directory {
239-
path: Cow::from(cx.current_expansion.module.directory.as_path()),
263+
path: cx.current_expansion.module.directory.clone(),
240264
ownership: cx.current_expansion.directory_ownership,
241265
};
242266
let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), true, false, None);
@@ -269,6 +293,7 @@ fn generic_extension<'cx>(
269293
// Restore to the state before snapshotting and maybe try again.
270294
mem::swap(&mut gated_spans_snaphot, &mut cx.parse_sess.gated_spans.spans.borrow_mut());
271295
}
296+
drop(base_parser);
272297

273298
let (token, label) = best_failure.expect("ran no matchers");
274299
let span = token.span.substitute_dummy(sp);
@@ -286,7 +311,9 @@ fn generic_extension<'cx>(
286311
mbe::TokenTree::Delimited(_, ref delim) => &delim.tts[..],
287312
_ => continue,
288313
};
289-
match parse_tt(cx, lhs_tt, arg.clone()) {
314+
let base_parser =
315+
base_parser_from_cx(&cx.current_expansion, &cx.parse_sess, arg.clone());
316+
match parse_tt(&mut Cow::Borrowed(&base_parser), lhs_tt) {
290317
Success(_) => {
291318
if comma_span.is_dummy() {
292319
err.note("you might be missing a comma");
@@ -368,7 +395,8 @@ pub fn compile_declarative_macro(
368395
),
369396
];
370397

371-
let argument_map = match parse(sess, body, &argument_gram, None, true) {
398+
let base_parser = Parser::new(sess, body, None, true, true, rustc_parse::MACRO_ARGUMENTS);
399+
let argument_map = match parse_tt(&mut Cow::Borrowed(&base_parser), &argument_gram) {
372400
Success(m) => m,
373401
Failure(token, msg) => {
374402
let s = parse_failure_msg(&token);
@@ -1184,14 +1212,16 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
11841212
}
11851213
}
11861214

1187-
/// Use this token tree as a matcher to parse given tts.
1188-
fn parse_tt(cx: &ExtCtxt<'_>, mtch: &[mbe::TokenTree], tts: TokenStream) -> NamedParseResult {
1189-
// `None` is because we're not interpolating
1215+
fn base_parser_from_cx<'cx>(
1216+
current_expansion: &'cx ExpansionData,
1217+
sess: &'cx ParseSess,
1218+
tts: TokenStream,
1219+
) -> Parser<'cx> {
11901220
let directory = Directory {
1191-
path: Cow::from(cx.current_expansion.module.directory.as_path()),
1192-
ownership: cx.current_expansion.directory_ownership,
1221+
path: current_expansion.module.directory.clone(),
1222+
ownership: current_expansion.directory_ownership,
11931223
};
1194-
parse(cx.parse_sess(), tts, mtch, Some(directory), true)
1224+
Parser::new(sess, tts, Some(directory), true, true, rustc_parse::MACRO_ARGUMENTS)
11951225
}
11961226

11971227
/// Generates an appropriate parsing failure message. For EOF, this is "unexpected end...". For

0 commit comments

Comments
 (0)