Skip to content

Commit 2e198d0

Browse files
committed
Auto merge of rust-lang#3419 - RalfJung:rustup, r=RalfJung
Rustup rust-lang#123081 landed so hopefully this works now.
2 parents 78d556e + 89a36c0 commit 2e198d0

File tree

169 files changed

+2338
-671
lines changed

Some content is hidden

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

169 files changed

+2338
-671
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,6 +3784,7 @@ dependencies = [
37843784
name = "rustc_driver_impl"
37853785
version = "0.0.0"
37863786
dependencies = [
3787+
"ctrlc",
37873788
"libc",
37883789
"rustc_ast",
37893790
"rustc_ast_lowering",

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ pub struct RegionInferenceContext<'tcx> {
9595
/// visible from this index.
9696
scc_universes: IndexVec<ConstraintSccIndex, ty::UniverseIndex>,
9797

98-
/// Contains a "representative" from each SCC. This will be the
99-
/// minimal RegionVid belonging to that universe. It is used as a
100-
/// kind of hacky way to manage checking outlives relationships,
98+
/// Contains the "representative" region of each SCC.
99+
/// It is defined as the one with the minimal RegionVid, favoring
100+
/// free regions, then placeholders, then existential regions.
101+
///
102+
/// It is a hacky way to manage checking regions for equality,
101103
/// since we can 'canonicalize' each region to the representative
102104
/// of its SCC and be sure that -- if they have the same repr --
103105
/// they *must* be equal (though not having the same repr does not
@@ -481,22 +483,28 @@ impl<'tcx> RegionInferenceContext<'tcx> {
481483
scc_universes
482484
}
483485

484-
/// For each SCC, we compute a unique `RegionVid` (in fact, the
485-
/// minimal one that belongs to the SCC). See
486+
/// For each SCC, we compute a unique `RegionVid`. See the
486487
/// `scc_representatives` field of `RegionInferenceContext` for
487488
/// more details.
488489
fn compute_scc_representatives(
489490
constraints_scc: &Sccs<RegionVid, ConstraintSccIndex>,
490491
definitions: &IndexSlice<RegionVid, RegionDefinition<'tcx>>,
491492
) -> IndexVec<ConstraintSccIndex, ty::RegionVid> {
492493
let num_sccs = constraints_scc.num_sccs();
493-
let next_region_vid = definitions.next_index();
494-
let mut scc_representatives = IndexVec::from_elem_n(next_region_vid, num_sccs);
495-
496-
for region_vid in definitions.indices() {
497-
let scc = constraints_scc.scc(region_vid);
498-
let prev_min = scc_representatives[scc];
499-
scc_representatives[scc] = region_vid.min(prev_min);
494+
let mut scc_representatives = IndexVec::from_elem_n(RegionVid::MAX, num_sccs);
495+
496+
// Iterate over all RegionVids *in-order* and pick the least RegionVid as the
497+
// representative of its SCC. This naturally prefers free regions over others.
498+
for (vid, def) in definitions.iter_enumerated() {
499+
let repr = &mut scc_representatives[constraints_scc.scc(vid)];
500+
if *repr == ty::RegionVid::MAX {
501+
*repr = vid;
502+
} else if matches!(def.origin, NllRegionVariableOrigin::Placeholder(_))
503+
&& matches!(definitions[*repr].origin, NllRegionVariableOrigin::Existential { .. })
504+
{
505+
// Pick placeholders over existentials even if they have a greater RegionVid.
506+
*repr = vid;
507+
}
500508
}
501509

502510
scc_representatives

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 210 additions & 169 deletions
Large diffs are not rendered by default.

compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::constraints::ConstraintSccIndex;
22
use crate::RegionInferenceContext;
3-
use itertools::Itertools;
43
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
54
use rustc_data_structures::graph::vec_graph::VecGraph;
65
use rustc_data_structures::graph::WithSuccessors;
@@ -48,16 +47,16 @@ impl RegionInferenceContext<'_> {
4847
.universal_regions
4948
.universal_regions()
5049
.map(|region| (self.constraint_sccs.scc(region), region))
51-
.collect_vec();
50+
.collect::<Vec<_>>();
5251
paired_scc_regions.sort();
5352
let universal_regions = paired_scc_regions.iter().map(|&(_, region)| region).collect();
5453

5554
let mut scc_regions = FxIndexMap::default();
5655
let mut start = 0;
57-
for (scc, group) in &paired_scc_regions.into_iter().group_by(|(scc, _)| *scc) {
58-
let group_size = group.count();
59-
scc_regions.insert(scc, start..start + group_size);
60-
start += group_size;
56+
for chunk in paired_scc_regions.chunk_by(|&(scc1, _), &(scc2, _)| scc1 == scc2) {
57+
let (scc, _) = chunk[0];
58+
scc_regions.insert(scc, start..start + chunk.len());
59+
start += chunk.len();
6160
}
6261

6362
self.rev_scc_graph = Some(ReverseSccGraph { graph, scc_regions, universal_regions });

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ impl UniversalRegionRelations<'_> {
164164
self.outlives.contains(fr1, fr2)
165165
}
166166

167+
/// Returns `true` if fr1 is known to equal fr2.
168+
///
169+
/// This will only ever be true for universally quantified regions.
170+
pub(crate) fn equal(&self, fr1: RegionVid, fr2: RegionVid) -> bool {
171+
self.outlives.contains(fr1, fr2) && self.outlives.contains(fr2, fr1)
172+
}
173+
167174
/// Returns a vector of free regions `x` such that `fr1: x` is
168175
/// known to hold.
169176
pub(crate) fn regions_outlived_by(&self, fr1: RegionVid) -> Vec<RegionVid> {

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@ pub(crate) fn type_check<'mir, 'tcx>(
229229
);
230230
}
231231

232+
// Convert all regions to nll vars.
233+
let (opaque_type_key, hidden_type) =
234+
infcx.tcx.fold_regions((opaque_type_key, hidden_type), |region, _| {
235+
match region.kind() {
236+
ty::ReVar(_) => region,
237+
ty::RePlaceholder(placeholder) => checker
238+
.borrowck_context
239+
.constraints
240+
.placeholder_region(infcx, placeholder),
241+
_ => ty::Region::new_var(
242+
infcx.tcx,
243+
checker.borrowck_context.universal_regions.to_region_vid(region),
244+
),
245+
}
246+
});
247+
232248
(opaque_type_key, hidden_type)
233249
})
234250
.collect();

compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,6 @@ rm tests/ui/parser/unclosed-delimiter-in-dep.rs # submodule contains //~ERROR
4141
# missing features
4242
# ================
4343

44-
# requires stack unwinding
45-
# FIXME add needs-unwind to these tests
46-
rm -r tests/run-make/libtest-junit
47-
rm tests/ui/asm/may_unwind.rs
48-
rm tests/ui/stable-mir-print/basic_function.rs
49-
50-
# extra warning about -Cpanic=abort for proc macros
51-
rm tests/ui/proc-macro/crt-static.rs
52-
rm tests/ui/proc-macro/proc-macro-deprecated-attr.rs
53-
rm tests/ui/proc-macro/quote-debug.rs
54-
rm tests/ui/proc-macro/no-missing-docs.rs
55-
rm tests/ui/rust-2018/proc-macro-crate-in-paths.rs
56-
rm tests/ui/proc-macro/allowed-signatures.rs
57-
rm tests/ui/proc-macro/no-mangle-in-proc-macro-issue-111888.rs
58-
5944
# vendor intrinsics
6045
rm tests/ui/simd/array-type.rs # "Index argument for `simd_insert` is not a constant"
6146
rm tests/ui/asm/x86_64/evex512-implicit-feature.rs # unimplemented AVX512 x86 vendor intrinsic
@@ -154,7 +139,6 @@ rm tests/ui/codegen/subtyping-enforces-type-equality.rs # assert_assignable bug
154139
# ======================
155140
rm tests/ui/backtrace.rs # TODO warning
156141
rm tests/ui/process/nofile-limit.rs # TODO some AArch64 linking issue
157-
rm tests/ui/async-await/async-closures/once.rs # FIXME bug in the rustc FnAbi calculation code
158142

159143
rm tests/ui/stdio-is-blocking.rs # really slow with unoptimized libstd
160144

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_middle::ty::layout::{
2020
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
2121
};
2222
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
23+
use rustc_session::config::OptLevel;
2324
use rustc_span::Span;
2425
use rustc_symbol_mangling::typeid::{
2526
kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
@@ -551,6 +552,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
551552
layout: TyAndLayout<'tcx>,
552553
offset: Size,
553554
) {
555+
if bx.cx.sess().opts.optimize == OptLevel::No {
556+
// Don't emit metadata we're not going to use
557+
return;
558+
}
559+
554560
if !scalar.is_uninit_valid() {
555561
bx.noundef_metadata(load);
556562
}
@@ -667,6 +673,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
667673
return;
668674
}
669675

676+
if self.cx.sess().opts.optimize == OptLevel::No {
677+
// Don't emit metadata we're not going to use
678+
return;
679+
}
680+
670681
unsafe {
671682
let llty = self.cx.val_ty(load);
672683
let v = [
@@ -1630,7 +1641,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16301641
}
16311642

16321643
let typeid = if let Some(instance) = instance {
1633-
typeid_for_instance(self.tcx, &instance, options)
1644+
typeid_for_instance(self.tcx, instance, options)
16341645
} else {
16351646
typeid_for_fnabi(self.tcx, fn_abi, options)
16361647
};
@@ -1678,7 +1689,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16781689
}
16791690

16801691
let kcfi_typeid = if let Some(instance) = instance {
1681-
kcfi_typeid_for_instance(self.tcx, &instance, options)
1692+
kcfi_typeid_for_instance(self.tcx, instance, options)
16821693
} else {
16831694
kcfi_typeid_for_fnabi(self.tcx, fn_abi, options)
16841695
};

compiler/rustc_codegen_llvm/src/declare.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
141141

142142
if self.tcx.sess.is_sanitizer_cfi_enabled() {
143143
if let Some(instance) = instance {
144-
let typeid = typeid_for_instance(self.tcx, &instance, TypeIdOptions::empty());
144+
let typeid = typeid_for_instance(self.tcx, instance, TypeIdOptions::empty());
145145
self.set_type_metadata(llfn, typeid);
146146
let typeid =
147-
typeid_for_instance(self.tcx, &instance, TypeIdOptions::GENERALIZE_POINTERS);
147+
typeid_for_instance(self.tcx, instance, TypeIdOptions::GENERALIZE_POINTERS);
148148
self.add_type_metadata(llfn, typeid);
149149
let typeid =
150-
typeid_for_instance(self.tcx, &instance, TypeIdOptions::NORMALIZE_INTEGERS);
150+
typeid_for_instance(self.tcx, instance, TypeIdOptions::NORMALIZE_INTEGERS);
151151
self.add_type_metadata(llfn, typeid);
152152
let typeid = typeid_for_instance(
153153
self.tcx,
154-
&instance,
154+
instance,
155155
TypeIdOptions::GENERALIZE_POINTERS | TypeIdOptions::NORMALIZE_INTEGERS,
156156
);
157157
self.add_type_metadata(llfn, typeid);
@@ -182,7 +182,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
182182
}
183183

184184
if let Some(instance) = instance {
185-
let kcfi_typeid = kcfi_typeid_for_instance(self.tcx, &instance, options);
185+
let kcfi_typeid = kcfi_typeid_for_instance(self.tcx, instance, options);
186186
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
187187
} else {
188188
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi, options);

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ fn produce_final_output_artifacts(
592592
.unwrap()
593593
.to_owned();
594594

595-
if crate_output.outputs.contains_key(&output_type) {
595+
if crate_output.outputs.contains_explicit_name(&output_type) {
596596
// 2) Multiple codegen units, with `--emit foo=some_name`. We have
597597
// no good solution for this case, so warn the user.
598598
sess.dcx().emit_warn(errors::IgnoringEmitPath { extension });

compiler/rustc_const_eval/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ const_eval_intern_kind = {$kind ->
146146
*[other] {""}
147147
}
148148
149+
const_eval_interrupted = compilation was interrupted
150+
149151
const_eval_invalid_align_details =
150152
invalid align passed to `{$name}`: {$align} is {$err_kind ->
151153
[not_power_of_two] not a power of 2

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::atomic::Ordering::Relaxed;
2+
13
use either::{Left, Right};
24

35
use rustc_hir::def::DefKind;
@@ -22,6 +24,7 @@ use crate::interpret::{
2224
InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking,
2325
StackPopCleanup,
2426
};
27+
use crate::CTRL_C_RECEIVED;
2528

2629
// Returns a pointer to where the result lives
2730
#[instrument(level = "trace", skip(ecx, body))]
@@ -79,7 +82,11 @@ fn eval_body_using_ecx<'mir, 'tcx, R: InterpretationResult<'tcx>>(
7982
ecx.storage_live_for_always_live_locals()?;
8083

8184
// The main interpreter loop.
82-
while ecx.step()? {}
85+
while ecx.step()? {
86+
if CTRL_C_RECEIVED.load(Relaxed) {
87+
throw_exhaust!(Interrupted);
88+
}
89+
}
8390

8491
// Intern the result
8592
intern_const_alloc_recursive(ecx, intern_kind, &ret)?;

compiler/rustc_const_eval/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ impl ReportErrorExt for ResourceExhaustionInfo {
884884
ResourceExhaustionInfo::StackFrameLimitReached => const_eval_stack_frame_limit_reached,
885885
ResourceExhaustionInfo::MemoryExhausted => const_eval_memory_exhausted,
886886
ResourceExhaustionInfo::AddressSpaceFull => const_eval_address_space_full,
887+
ResourceExhaustionInfo::Interrupted => const_eval_interrupted,
887888
}
888889
}
889890
fn add_args<G: EmissionGuarantee>(self, _: &mut Diag<'_, G>) {}

compiler/rustc_const_eval/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub mod interpret;
3232
pub mod transform;
3333
pub mod util;
3434

35+
use std::sync::atomic::AtomicBool;
36+
3537
pub use errors::ReportErrorExt;
3638

3739
use rustc_middle::{ty, util::Providers};
@@ -58,3 +60,8 @@ pub fn provide(providers: &mut Providers) {
5860
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
5961
};
6062
}
63+
64+
/// `rustc_driver::main` installs a handler that will set this to `true` if
65+
/// the compiler has been sent a request to shut down, such as by a Ctrl-C.
66+
/// This static lives here because it is only read by the interpreter.
67+
pub static CTRL_C_RECEIVED: AtomicBool = AtomicBool::new(false);

compiler/rustc_driver_impl/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
ctrlc = "3.4.4"
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_ast_lowering = { path = "../rustc_ast_lowering" }
1011
rustc_ast_passes = { path = "../rustc_ast_passes" }

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern crate tracing;
1919

2020
use rustc_ast as ast;
2121
use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
22+
use rustc_const_eval::CTRL_C_RECEIVED;
2223
use rustc_data_structures::profiling::{
2324
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
2425
};
@@ -1518,6 +1519,22 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
15181519
}
15191520
}
15201521

1522+
/// Install our usual `ctrlc` handler, which sets [`rustc_const_eval::CTRL_C_RECEIVED`].
1523+
/// Making this handler optional lets tools can install a different handler, if they wish.
1524+
pub fn install_ctrlc_handler() {
1525+
ctrlc::set_handler(move || {
1526+
// Indicate that we have been signaled to stop. If we were already signaled, exit
1527+
// immediately. In our interpreter loop we try to consult this value often, but if for
1528+
// whatever reason we don't get to that check or the cleanup we do upon finding that
1529+
// this bool has become true takes a long time, the exit here will promptly exit the
1530+
// process on the second Ctrl-C.
1531+
if CTRL_C_RECEIVED.swap(true, Ordering::Relaxed) {
1532+
std::process::exit(1);
1533+
}
1534+
})
1535+
.expect("Unable to install ctrlc handler");
1536+
}
1537+
15211538
pub fn main() -> ! {
15221539
let start_time = Instant::now();
15231540
let start_rss = get_resident_set_size();
@@ -1528,6 +1545,8 @@ pub fn main() -> ! {
15281545
signal_handler::install();
15291546
let mut callbacks = TimePassesCallbacks::default();
15301547
let using_internal_features = install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());
1548+
install_ctrlc_handler();
1549+
15311550
let exit_code = catch_with_exit_code(|| {
15321551
RunCompiler::new(&args::raw_args(&early_dcx)?, &mut callbacks)
15331552
.set_using_internal_features(using_internal_features)

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,12 +793,20 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
793793
fd: &'tcx hir::FnDecl<'tcx>,
794794
body_id: hir::BodyId,
795795
_: Span,
796-
_: LocalDefId,
796+
def_id: LocalDefId,
797797
) {
798798
let output = match fd.output {
799799
hir::FnRetTy::DefaultReturn(_) => None,
800800
hir::FnRetTy::Return(ty) => Some(ty),
801801
};
802+
if let Some(ty) = output
803+
&& let hir::TyKind::InferDelegation(sig_id, _) = ty.kind
804+
{
805+
let bound_vars: Vec<_> =
806+
self.tcx.fn_sig(sig_id).skip_binder().bound_vars().iter().collect();
807+
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
808+
self.map.late_bound_vars.insert(hir_id, bound_vars);
809+
}
802810
self.visit_fn_like_elision(fd.inputs, output, matches!(fk, intravisit::FnKind::Closure));
803811
intravisit::walk_fn_kind(self, fk);
804812
self.visit_nested_body(body_id)

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,13 +2492,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24922492
hir_ty: Option<&hir::Ty<'_>>,
24932493
) -> ty::PolyFnSig<'tcx> {
24942494
let tcx = self.tcx();
2495-
let bound_vars = if let hir::FnRetTy::Return(ret_ty) = decl.output
2496-
&& let hir::TyKind::InferDelegation(sig_id, _) = ret_ty.kind
2497-
{
2498-
tcx.fn_sig(sig_id).skip_binder().bound_vars()
2499-
} else {
2500-
tcx.late_bound_vars(hir_id)
2501-
};
2495+
let bound_vars = tcx.late_bound_vars(hir_id);
25022496
debug!(?bound_vars);
25032497

25042498
// We proactively collect all the inferred type params to emit a single error per fn def.

0 commit comments

Comments
 (0)