Skip to content

Commit debf88a

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 9ce95c3 + e2ef4e1 commit debf88a

File tree

381 files changed

+2830
-1407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

381 files changed

+2830
-1407
lines changed

compiler/rustc_ast/src/tokenstream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,11 @@ impl TokenStream {
661661
if attr_style == AttrStyle::Inner {
662662
vec![
663663
TokenTree::token_joint(token::Pound, span),
664-
TokenTree::token_alone(token::Not, span),
664+
TokenTree::token_joint_hidden(token::Not, span),
665665
body,
666666
]
667667
} else {
668-
vec![TokenTree::token_alone(token::Pound, span), body]
668+
vec![TokenTree::token_joint_hidden(token::Pound, span), body]
669669
}
670670
}
671671
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+29-11
Original file line numberDiff line numberDiff line change
@@ -681,22 +681,40 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
681681
}
682682
}
683683

684+
// The easiest way to implement token stream pretty printing would be to
685+
// print each token followed by a single space. But that would produce ugly
686+
// output, so we go to some effort to do better.
687+
//
688+
// First, we track whether each token that appears in source code is
689+
// followed by a space, with `Spacing`, and reproduce that in the output.
690+
// This works well in a lot of cases. E.g. `stringify!(x + y)` produces
691+
// "x + y" and `stringify!(x+y)` produces "x+y".
692+
//
693+
// But this doesn't work for code produced by proc macros (which have no
694+
// original source text representation) nor for code produced by decl
695+
// macros (which are tricky because the whitespace after tokens appearing
696+
// in macro rules isn't always what you want in the produced output). For
697+
// these we mostly use `Spacing::Alone`, which is the conservative choice.
698+
//
699+
// So we have a backup mechanism for when `Spacing::Alone` occurs between a
700+
// pair of tokens: we check if that pair of tokens can obviously go
701+
// together without a space between them. E.g. token `x` followed by token
702+
// `,` is better printed as `x,` than `x ,`. (Even if the original source
703+
// code was `x ,`.)
704+
//
705+
// Finally, we must be careful about changing the output. Token pretty
706+
// printing is used by `stringify!` and `impl Display for
707+
// proc_macro::TokenStream`, and some programs rely on the output having a
708+
// particular form, even though they shouldn't. In particular, some proc
709+
// macros do `format!({stream})` on a token stream and then "parse" the
710+
// output with simple string matching that can't handle whitespace changes.
711+
// E.g. we have seen cases where a proc macro can handle `a :: b` but not
712+
// `a::b`. See #117433 for some examples.
684713
fn print_tts(&mut self, tts: &TokenStream, convert_dollar_crate: bool) {
685714
let mut iter = tts.trees().peekable();
686715
while let Some(tt) = iter.next() {
687716
let spacing = self.print_tt(tt, convert_dollar_crate);
688717
if let Some(next) = iter.peek() {
689-
// Should we print a space after `tt`? There are two guiding
690-
// factors.
691-
// - `spacing` is the more important and accurate one. Most
692-
// tokens have good spacing information, and
693-
// `Joint`/`JointHidden` get used a lot.
694-
// - `space_between` is the backup. Code produced by proc
695-
// macros has worse spacing information, with no
696-
// `JointHidden` usage and too much `Alone` usage, which
697-
// would result in over-spaced output such as
698-
// `( x () , y . z )`. `space_between` avoids some of the
699-
// excess whitespace.
700718
if spacing == Spacing::Alone && space_between(tt, next) {
701719
self.space();
702720
}

compiler/rustc_builtin_macros/src/assert/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
153153
fn build_panic(&self, expr_str: &str, panic_path: Path) -> P<Expr> {
154154
let escaped_expr_str = escape_to_fmt(expr_str);
155155
let initial = [
156-
TokenTree::token_joint_hidden(
156+
TokenTree::token_joint(
157157
token::Literal(token::Lit {
158158
kind: token::LitKind::Str,
159159
symbol: Symbol::intern(&if self.fmt_string.is_empty() {
@@ -172,7 +172,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
172172
];
173173
let captures = self.capture_decls.iter().flat_map(|cap| {
174174
[
175-
TokenTree::token_joint_hidden(
175+
TokenTree::token_joint(
176176
token::Ident(cap.ident.name, IdentIsRaw::No),
177177
cap.ident.span,
178178
),

compiler/rustc_builtin_macros/src/deriving/default.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::deriving::generic::*;
33
use crate::errors;
44
use core::ops::ControlFlow;
55
use rustc_ast as ast;
6-
use rustc_ast::visit::walk_list;
6+
use rustc_ast::visit::visit_opt;
77
use rustc_ast::{attr, EnumDef, VariantData};
88
use rustc_expand::base::{Annotatable, DummyResult, ExtCtxt};
99
use rustc_span::symbol::Ident;
@@ -224,7 +224,7 @@ impl<'a, 'b> rustc_ast::visit::Visitor<'a> for DetectNonVariantDefaultAttr<'a, '
224224
self.visit_ident(v.ident);
225225
self.visit_vis(&v.vis);
226226
self.visit_variant_data(&v.data);
227-
walk_list!(self, visit_anon_const, &v.disr_expr);
227+
visit_opt!(self, visit_anon_const, &v.disr_expr);
228228
for attr in &v.attrs {
229229
rustc_ast::visit::walk_attribute(self, attr);
230230
}

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn produce_final_output_artifacts(
200200
// to get rid of it.
201201
for output_type in crate_output.outputs.keys() {
202202
match *output_type {
203-
OutputType::Bitcode => {
203+
OutputType::Bitcode | OutputType::ThinLinkBitcode => {
204204
// Cranelift doesn't have bitcode
205205
// user_wants_bitcode = true;
206206
// // Copy to .bc, but always keep the .0.bc. There is a later

compiler/rustc_codegen_gcc/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ impl ThinBufferMethods for ThinBuffer {
335335
fn data(&self) -> &[u8] {
336336
unimplemented!();
337337
}
338+
339+
fn thin_link_data(&self) -> &[u8] {
340+
unimplemented!();
341+
}
338342
}
339343

340344
pub struct GccContext {
@@ -414,7 +418,7 @@ impl WriteBackendMethods for GccCodegenBackend {
414418
back::write::codegen(cgcx, dcx, module, config)
415419
}
416420

417-
fn prepare_thin(_module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer) {
421+
fn prepare_thin(_module: ModuleCodegen<Self::Module>, _emit_summary: bool) -> (String, Self::ThinBuffer) {
418422
unimplemented!();
419423
}
420424

compiler/rustc_codegen_llvm/src/asm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_middle::{bug, span_bug, ty::Instance};
1616
use rustc_span::{Pos, Span};
1717
use rustc_target::abi::*;
1818
use rustc_target::asm::*;
19+
use tracing::debug;
1920

2021
use libc::{c_char, c_uint};
2122
use smallvec::SmallVec;

compiler/rustc_codegen_llvm/src/back/archive.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_codegen_ssa::back::archive::{
1818
get_native_object_symbols, try_extract_macho_fat_archive, ArArchiveBuilder,
1919
ArchiveBuildFailure, ArchiveBuilder, ArchiveBuilderBuilder, UnknownArchiveKind,
2020
};
21+
use tracing::trace;
2122

2223
use rustc_session::cstore::DllImport;
2324
use rustc_session::Session;

compiler/rustc_codegen_llvm/src/back/lto.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_middle::bug;
2020
use rustc_middle::dep_graph::WorkProduct;
2121
use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel};
2222
use rustc_session::config::{self, CrateType, Lto};
23+
use tracing::{debug, info};
2324

2425
use std::collections::BTreeMap;
2526
use std::ffi::{CStr, CString};
@@ -229,9 +230,12 @@ pub(crate) fn run_thin(
229230
thin_lto(cgcx, &dcx, modules, upstream_modules, cached_modules, &symbols_below_threshold)
230231
}
231232

232-
pub(crate) fn prepare_thin(module: ModuleCodegen<ModuleLlvm>) -> (String, ThinBuffer) {
233+
pub(crate) fn prepare_thin(
234+
module: ModuleCodegen<ModuleLlvm>,
235+
emit_summary: bool,
236+
) -> (String, ThinBuffer) {
233237
let name = module.name;
234-
let buffer = ThinBuffer::new(module.module_llvm.llmod(), true);
238+
let buffer = ThinBuffer::new(module.module_llvm.llmod(), true, emit_summary);
235239
(name, buffer)
236240
}
237241

@@ -671,9 +675,9 @@ unsafe impl Send for ThinBuffer {}
671675
unsafe impl Sync for ThinBuffer {}
672676

673677
impl ThinBuffer {
674-
pub fn new(m: &llvm::Module, is_thin: bool) -> ThinBuffer {
678+
pub fn new(m: &llvm::Module, is_thin: bool, emit_summary: bool) -> ThinBuffer {
675679
unsafe {
676-
let buffer = llvm::LLVMRustThinLTOBufferCreate(m, is_thin);
680+
let buffer = llvm::LLVMRustThinLTOBufferCreate(m, is_thin, emit_summary);
677681
ThinBuffer(buffer)
678682
}
679683
}
@@ -687,6 +691,14 @@ impl ThinBufferMethods for ThinBuffer {
687691
slice::from_raw_parts(ptr, len)
688692
}
689693
}
694+
695+
fn thin_link_data(&self) -> &[u8] {
696+
unsafe {
697+
let ptr = llvm::LLVMRustThinLTOBufferThinLinkDataPtr(self.0) as *const _;
698+
let len = llvm::LLVMRustThinLTOBufferThinLinkDataLen(self.0);
699+
slice::from_raw_parts(ptr, len)
700+
}
701+
}
690702
}
691703

692704
impl Drop for ThinBuffer {

compiler/rustc_codegen_llvm/src/back/write.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use rustc_session::Session;
3535
use rustc_span::symbol::sym;
3636
use rustc_span::InnerSpan;
3737
use rustc_target::spec::{CodeModel, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel};
38+
use tracing::debug;
3839

3940
use crate::llvm::diagnostic::OptimizationDiagnosticKind;
4041
use libc::{c_char, c_int, c_void, size_t};
@@ -708,13 +709,15 @@ pub(crate) unsafe fn codegen(
708709
// asm from LLVM and use `gcc` to create the object file.
709710

710711
let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
712+
let bc_summary_out =
713+
cgcx.output_filenames.temp_path(OutputType::ThinLinkBitcode, module_name);
711714
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, module_name);
712715

713716
if config.bitcode_needed() {
714717
let _timer = cgcx
715718
.prof
716719
.generic_activity_with_arg("LLVM_module_codegen_make_bitcode", &*module.name);
717-
let thin = ThinBuffer::new(llmod, config.emit_thin_lto);
720+
let thin = ThinBuffer::new(llmod, config.emit_thin_lto, config.emit_thin_lto_summary);
718721
let data = thin.data();
719722

720723
if let Some(bitcode_filename) = bc_out.file_name() {
@@ -725,6 +728,25 @@ pub(crate) unsafe fn codegen(
725728
);
726729
}
727730

731+
if config.emit_thin_lto_summary
732+
&& let Some(thin_link_bitcode_filename) = bc_summary_out.file_name()
733+
{
734+
let summary_data = thin.thin_link_data();
735+
cgcx.prof.artifact_size(
736+
"llvm_bitcode_summary",
737+
thin_link_bitcode_filename.to_string_lossy(),
738+
summary_data.len() as u64,
739+
);
740+
741+
let _timer = cgcx.prof.generic_activity_with_arg(
742+
"LLVM_module_codegen_emit_bitcode_summary",
743+
&*module.name,
744+
);
745+
if let Err(err) = fs::write(&bc_summary_out, summary_data) {
746+
dcx.emit_err(WriteBytecode { path: &bc_summary_out, err });
747+
}
748+
}
749+
728750
if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
729751
let _timer = cgcx
730752
.prof

compiler/rustc_codegen_llvm/src/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use std::borrow::Cow;
3030
use std::iter;
3131
use std::ops::Deref;
3232
use std::ptr;
33+
use tracing::{debug, instrument};
3334

3435
// All Builders must have an llfn associated with them
3536
#[must_use]

compiler/rustc_codegen_llvm/src/callee.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::value::Value;
1212

1313
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt};
1414
use rustc_middle::ty::{self, Instance, TypeVisitableExt};
15+
use tracing::debug;
1516

1617
/// Codegens a reference to a fn/method item, monomorphizing and
1718
/// inlining as it goes.

compiler/rustc_codegen_llvm/src/common.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_target::spec::Target;
1919

2020
use libc::{c_char, c_uint};
2121
use std::fmt::Write;
22+
use tracing::debug;
2223

2324
/*
2425
* A note on nomenclature of linking: "extern", "foreign", and "upcall".

compiler/rustc_codegen_llvm/src/consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc_target::abi::{
2525
Align, AlignFromBytesError, HasDataLayout, Primitive, Scalar, Size, WrappingRange,
2626
};
2727
use std::ops::Range;
28+
use tracing::{debug, instrument, trace};
2829

2930
pub fn const_alloc_to_llvm<'ll>(
3031
cx: &CodegenCx<'ll, '_>,

compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_middle::mir::coverage::{
99
};
1010
use rustc_middle::ty::Instance;
1111
use rustc_span::Symbol;
12+
use tracing::{debug, instrument};
1213

1314
/// Holds all of the coverage mapping data associated with a function instance,
1415
/// collected during traversal of `Coverage` statements in the function's MIR.

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_middle::mir;
1414
use rustc_middle::ty::{self, TyCtxt};
1515
use rustc_span::def_id::DefIdSet;
1616
use rustc_span::Symbol;
17+
use tracing::debug;
1718

1819
/// Generates and exports the Coverage Map.
1920
///

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_middle::mir::coverage::CoverageKind;
1717
use rustc_middle::ty::layout::HasTyCtxt;
1818
use rustc_middle::ty::Instance;
1919
use rustc_target::abi::{Align, Size};
20+
use tracing::{debug, instrument};
2021

2122
use std::cell::RefCell;
2223

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use rustc_symbol_mangling::typeid_for_trait_ref;
4141
use rustc_target::abi::{Align, Size};
4242
use rustc_target::spec::DebuginfoKind;
4343
use smallvec::smallvec;
44+
use tracing::{debug, instrument};
4445

4546
use libc::{c_char, c_longlong, c_uint};
4647
use std::borrow::Cow;

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use std::cell::OnceCell;
4242
use std::cell::RefCell;
4343
use std::iter;
4444
use std::ops::Range;
45+
use tracing::debug;
4546

4647
mod create_scope_map;
4748
pub mod gdb;

compiler/rustc_codegen_llvm/src/debuginfo/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::CodegenUnitDebugContext;
66
use rustc_hir::def_id::DefId;
77
use rustc_middle::ty::layout::{HasParamEnv, LayoutOf};
88
use rustc_middle::ty::{self, Ty};
9-
use trace;
9+
use tracing::trace;
1010

1111
use crate::common::CodegenCx;
1212
use crate::llvm;

compiler/rustc_codegen_llvm/src/declare.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_data_structures::fx::FxIndexSet;
2424
use rustc_middle::ty::{Instance, Ty};
2525
use rustc_sanitizers::{cfi, kcfi};
2626
use smallvec::SmallVec;
27+
use tracing::debug;
2728

2829
/// Declare a function.
2930
///

compiler/rustc_codegen_llvm/src/intrinsic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_middle::{bug, span_bug};
2121
use rustc_span::{sym, Span, Symbol};
2222
use rustc_target::abi::{self, Align, Float, HasDataLayout, Primitive, Size};
2323
use rustc_target::spec::{HasTargetSpec, PanicStrategy};
24+
use tracing::debug;
2425

2526
use std::cmp::Ordering;
2627

compiler/rustc_codegen_llvm/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#![feature(let_chains)]
1616
#![feature(impl_trait_in_assoc_type)]
1717

18-
#[macro_use]
19-
extern crate tracing;
20-
2118
use back::owned_target_machine::OwnedTargetMachine;
2219
use back::write::{create_informational_target_machine, create_target_machine};
2320

@@ -240,8 +237,11 @@ impl WriteBackendMethods for LlvmCodegenBackend {
240237
) -> Result<CompiledModule, FatalError> {
241238
back::write::codegen(cgcx, dcx, module, config)
242239
}
243-
fn prepare_thin(module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer) {
244-
back::lto::prepare_thin(module)
240+
fn prepare_thin(
241+
module: ModuleCodegen<Self::Module>,
242+
emit_summary: bool,
243+
) -> (String, Self::ThinBuffer) {
244+
back::lto::prepare_thin(module, emit_summary)
245245
}
246246
fn serialize_module(module: ModuleCodegen<Self::Module>) -> (String, Self::ModuleBuffer) {
247247
(module.name, back::lto::ModuleBuffer::new(module.module_llvm.llmod()))

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2350,10 +2350,16 @@ extern "C" {
23502350
#[allow(improper_ctypes)]
23512351
pub fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString);
23522352

2353-
pub fn LLVMRustThinLTOBufferCreate(M: &Module, is_thin: bool) -> &'static mut ThinLTOBuffer;
2353+
pub fn LLVMRustThinLTOBufferCreate(
2354+
M: &Module,
2355+
is_thin: bool,
2356+
emit_summary: bool,
2357+
) -> &'static mut ThinLTOBuffer;
23542358
pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
23552359
pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
23562360
pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
2361+
pub fn LLVMRustThinLTOBufferThinLinkDataPtr(M: &ThinLTOBuffer) -> *const c_char;
2362+
pub fn LLVMRustThinLTOBufferThinLinkDataLen(M: &ThinLTOBuffer) -> size_t;
23572363
pub fn LLVMRustCreateThinLTOData(
23582364
Modules: *const ThinLTOModule,
23592365
NumModules: c_uint,

compiler/rustc_codegen_llvm/src/mono_item.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
1313
use rustc_middle::ty::{self, Instance, TypeVisitableExt};
1414
use rustc_session::config::CrateType;
1515
use rustc_target::spec::RelocModel;
16+
use tracing::debug;
1617

1718
impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'_, 'tcx> {
1819
fn predefine_static(

0 commit comments

Comments
 (0)