Skip to content

Commit c880acd

Browse files
committed
Auto merge of #148931 - Zalathar:rollup-yfyhpcw, r=Zalathar
Rollup of 15 pull requests Successful merges: - #148543 (Correctly link to associated trait items in reexports) - #148808 (Some resolve cleanups) - #148812 (coverage: Associate hole spans with expansion tree nodes ) - #148826 (CStr docs: Fix CStr vs &CStr confusion) - #148850 (Implement `Read::read_array`) - #148867 (Refactor `Box::take`) - #148870 (Remove unused LLVMModuleRef argument) - #148878 (error when ABI does not support guaranteed tail calls) - #148901 (Disable rustdoc-test-builder test partially for SGX target.) - #148902 (add missing s390x target feature to std detect test) - #148904 (waffle: stop watching codegen ssa) - #148906 (Expose fmt::Arguments::from_str as unstable.) - #148907 (add assembly test for infinite recursion with `become`) - #148928 (Move & adjust some `!`-adjacent tests) - #148929 (ignore `build-rust-analyzer` even if it's a symlink) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6d41834 + f589579 commit c880acd

File tree

38 files changed

+426
-147
lines changed

38 files changed

+426
-147
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ no_llvm_build
4848
/llvm/
4949
/mingw-build/
5050
/build
51-
/build-rust-analyzer/
51+
/build-rust-analyzer
5252
/dist/
5353
/unicode-downloads
5454
/target

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,51 @@ impl ExternAbi {
276276
_ => CVariadicStatus::NotSupported,
277277
}
278278
}
279+
280+
/// Returns whether the ABI supports guaranteed tail calls.
281+
#[cfg(feature = "nightly")]
282+
pub fn supports_guaranteed_tail_call(self) -> bool {
283+
match self {
284+
Self::CmseNonSecureCall | Self::CmseNonSecureEntry => {
285+
// See https://godbolt.org/z/9jhdeqErv. The CMSE calling conventions clear registers
286+
// before returning, and hence cannot guarantee a tail call.
287+
false
288+
}
289+
Self::AvrInterrupt
290+
| Self::AvrNonBlockingInterrupt
291+
| Self::Msp430Interrupt
292+
| Self::RiscvInterruptM
293+
| Self::RiscvInterruptS
294+
| Self::X86Interrupt => {
295+
// See https://godbolt.org/z/Edfjnxxcq. Interrupts cannot be called directly.
296+
false
297+
}
298+
Self::GpuKernel | Self::PtxKernel => {
299+
// See https://godbolt.org/z/jq5TE5jK1.
300+
false
301+
}
302+
Self::Custom => {
303+
// This ABI does not support calls at all (except via assembly).
304+
false
305+
}
306+
Self::C { .. }
307+
| Self::System { .. }
308+
| Self::Rust
309+
| Self::RustCall
310+
| Self::RustCold
311+
| Self::RustInvalid
312+
| Self::Unadjusted
313+
| Self::EfiApi
314+
| Self::Aapcs { .. }
315+
| Self::Cdecl { .. }
316+
| Self::Stdcall { .. }
317+
| Self::Fastcall { .. }
318+
| Self::Thiscall { .. }
319+
| Self::Vectorcall { .. }
320+
| Self::SysV64 { .. }
321+
| Self::Win64 { .. } => true,
322+
}
323+
}
279324
}
280325

281326
pub fn all_names() -> Vec<&'static str> {

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ pub(crate) unsafe fn llvm_optimize(
683683
// Here we map the old arguments to the new arguments, with an offset of 1 to make sure
684684
// that we don't use the newly added `%dyn_ptr`.
685685
unsafe {
686-
llvm::LLVMRustOffloadMapper(cx.llmod(), old_fn, new_fn);
686+
llvm::LLVMRustOffloadMapper(old_fn, new_fn);
687687
}
688688

689689
llvm::set_linkage(new_fn, llvm::get_linkage(old_fn));

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,7 @@ unsafe extern "C" {
20252025
) -> &Attribute;
20262026

20272027
// Operations on functions
2028-
pub(crate) fn LLVMRustOffloadMapper<'a>(M: &'a Module, Fn: &'a Value, Fn: &'a Value);
2028+
pub(crate) fn LLVMRustOffloadMapper<'a>(Fn: &'a Value, Fn: &'a Value);
20292029
pub(crate) fn LLVMRustGetOrInsertFunction<'a>(
20302030
M: &'a Module,
20312031
Name: *const c_char,

compiler/rustc_expand/src/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,9 @@ pub struct Indeterminate;
10991099
pub struct DeriveResolution {
11001100
pub path: ast::Path,
11011101
pub item: Annotatable,
1102+
// FIXME: currently this field is only used in `is_none`/`is_some` conditions. However, the
1103+
// `Arc<SyntaxExtension>` will be used if the FIXME in `MacroExpander::fully_expand_fragment`
1104+
// is completed.
11021105
pub exts: Option<Arc<SyntaxExtension>>,
11031106
pub is_const: bool,
11041107
}

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ extern "C" void LLVMRustPrintStatistics(RustStringRef OutBuf) {
144144
llvm::PrintStatistics(OS);
145145
}
146146

147-
extern "C" void LLVMRustOffloadMapper(LLVMModuleRef M, LLVMValueRef OldFn,
148-
LLVMValueRef NewFn) {
149-
llvm::Module *module = llvm::unwrap(M);
147+
extern "C" void LLVMRustOffloadMapper(LLVMValueRef OldFn, LLVMValueRef NewFn) {
150148
llvm::Function *oldFn = llvm::unwrap<llvm::Function>(OldFn);
151149
llvm::Function *newFn = llvm::unwrap<llvm::Function>(NewFn);
152150

compiler/rustc_mir_build/src/check_tail_calls.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
135135
self.report_abi_mismatch(expr.span, caller_sig.abi, callee_sig.abi);
136136
}
137137

138+
if !callee_sig.abi.supports_guaranteed_tail_call() {
139+
self.report_unsupported_abi(expr.span, callee_sig.abi);
140+
}
141+
138142
// FIXME(explicit_tail_calls): this currently fails for cases where opaques are used.
139143
// e.g.
140144
// ```
@@ -358,6 +362,16 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
358362
self.found_errors = Err(err);
359363
}
360364

365+
fn report_unsupported_abi(&mut self, sp: Span, callee_abi: ExternAbi) {
366+
let err = self
367+
.tcx
368+
.dcx()
369+
.struct_span_err(sp, "ABI does not support guaranteed tail calls")
370+
.with_note(format!("`become` is not supported for `extern {callee_abi}` functions"))
371+
.emit();
372+
self.found_errors = Err(err);
373+
}
374+
361375
fn report_signature_mismatch(
362376
&mut self,
363377
sp: Span,

compiler/rustc_mir_transform/src/coverage/expansion.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet, IndexEntry};
2+
use rustc_middle::mir;
23
use rustc_middle::mir::coverage::BasicCoverageBlock;
34
use rustc_span::{ExpnId, ExpnKind, Span};
45

6+
use crate::coverage::from_mir;
7+
use crate::coverage::graph::CoverageGraph;
8+
use crate::coverage::hir_info::ExtractedHirInfo;
9+
510
#[derive(Clone, Copy, Debug)]
611
pub(crate) struct SpanWithBcb {
712
pub(crate) span: Span,
@@ -70,6 +75,10 @@ pub(crate) struct ExpnNode {
7075
pub(crate) spans: Vec<SpanWithBcb>,
7176
/// Expansions whose call-site is in this expansion.
7277
pub(crate) child_expn_ids: FxIndexSet<ExpnId>,
78+
79+
/// Hole spans belonging to this expansion, to be carved out from the
80+
/// code spans during span refinement.
81+
pub(crate) hole_spans: Vec<Span>,
7382
}
7483

7584
impl ExpnNode {
@@ -88,17 +97,27 @@ impl ExpnNode {
8897

8998
spans: vec![],
9099
child_expn_ids: FxIndexSet::default(),
100+
101+
hole_spans: vec![],
91102
}
92103
}
93104
}
94105

95-
/// Given a collection of span/BCB pairs from potentially-different syntax contexts,
106+
/// Extracts raw span/BCB pairs from potentially-different syntax contexts, and
96107
/// arranges them into an "expansion tree" based on their expansion call-sites.
97-
pub(crate) fn build_expn_tree(spans: impl IntoIterator<Item = SpanWithBcb>) -> ExpnTree {
108+
pub(crate) fn build_expn_tree(
109+
mir_body: &mir::Body<'_>,
110+
hir_info: &ExtractedHirInfo,
111+
graph: &CoverageGraph,
112+
) -> ExpnTree {
113+
let raw_spans = from_mir::extract_raw_spans_from_mir(mir_body, graph);
114+
98115
let mut nodes = FxIndexMap::default();
99116
let new_node = |&expn_id: &ExpnId| ExpnNode::new(expn_id);
100117

101-
for span_with_bcb in spans {
118+
for from_mir::RawSpanFromMir { raw_span, bcb } in raw_spans {
119+
let span_with_bcb = SpanWithBcb { span: raw_span, bcb };
120+
102121
// Create a node for this span's enclosing expansion, and add the span to it.
103122
let expn_id = span_with_bcb.span.ctxt().outer_expn();
104123
let node = nodes.entry(expn_id).or_insert_with_key(new_node);
@@ -123,5 +142,13 @@ pub(crate) fn build_expn_tree(spans: impl IntoIterator<Item = SpanWithBcb>) -> E
123142
}
124143
}
125144

145+
// Associate each hole span (extracted from HIR) with its corresponding
146+
// expansion tree node.
147+
for &hole_span in &hir_info.hole_spans {
148+
let expn_id = hole_span.ctxt().outer_expn();
149+
let Some(node) = nodes.get_mut(&expn_id) else { continue };
150+
node.hole_spans.push(hole_span);
151+
}
152+
126153
ExpnTree { nodes }
127154
}

compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs renamed to compiler/rustc_mir_transform/src/coverage/from_mir.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,3 @@ fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option<Span> {
142142
| TerminatorKind::InlineAsm { .. } => Some(terminator.source_info.span),
143143
}
144144
}
145-
146-
#[derive(Debug)]
147-
pub(crate) struct Hole {
148-
pub(crate) span: Span,
149-
}
150-
151-
impl Hole {
152-
pub(crate) fn merge_if_overlapping_or_adjacent(&mut self, other: &mut Self) -> bool {
153-
if !self.span.overlaps_or_adjacent(other.span) {
154-
return false;
155-
}
156-
157-
self.span = self.span.to(other.span);
158-
true
159-
}
160-
}

compiler/rustc_mir_transform/src/coverage/mappings.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_middle::mir::coverage::{
55
use rustc_middle::mir::{self, BasicBlock, StatementKind};
66
use rustc_middle::ty::TyCtxt;
77

8+
use crate::coverage::expansion;
89
use crate::coverage::graph::CoverageGraph;
910
use crate::coverage::hir_info::ExtractedHirInfo;
1011
use crate::coverage::spans::extract_refined_covspans;
@@ -23,10 +24,12 @@ pub(crate) fn extract_mappings_from_mir<'tcx>(
2324
hir_info: &ExtractedHirInfo,
2425
graph: &CoverageGraph,
2526
) -> ExtractedMappings {
27+
let expn_tree = expansion::build_expn_tree(mir_body, hir_info, graph);
28+
2629
let mut mappings = vec![];
2730

2831
// Extract ordinary code mappings from MIR statement/terminator spans.
29-
extract_refined_covspans(tcx, mir_body, hir_info, graph, &mut mappings);
32+
extract_refined_covspans(tcx, hir_info, graph, &expn_tree, &mut mappings);
3033

3134
extract_branch_mappings(mir_body, hir_info, graph, &mut mappings);
3235

0 commit comments

Comments
 (0)