Skip to content

Commit 72fe2ff

Browse files
committed
Auto merge of #148280 - jhpratt:rollup-um01cgu, r=jhpratt
Rollup of 8 pull requests Successful merges: - #138217 (Turn `Cow::is_borrowed,is_owned` into associated functions.) - #147858 (Micro-optimization attempt in coroutine layout computation) - #147923 (Simplify rustc_public context handling) - #148115 (rustdoc: Rename unstable option `--nocapture` to `--no-capture` in accordance with `libtest`) - #148137 (Couple of changes for Redox OS) - #148176 ([rustdoc] Include attribute and derive macros when filtering on "macros") - #148253 (Handle default features and -Ctarget-features in the dummy backend) - #148272 (Align VEX V5 boot routine to 4 bytes) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 292be5c + 4796814 commit 72fe2ff

File tree

31 files changed

+302
-470
lines changed

31 files changed

+302
-470
lines changed

compiler/rustc_interface/src/util.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use rustc_ast as ast;
99
use rustc_attr_parsing::{ShouldEmit, validate_attr};
1010
use rustc_codegen_ssa::back::archive::ArArchiveBuilderBuilder;
1111
use rustc_codegen_ssa::back::link::link_binary;
12+
use rustc_codegen_ssa::target_features::{self, cfg_target_feature};
1213
use rustc_codegen_ssa::traits::CodegenBackend;
13-
use rustc_codegen_ssa::{CodegenResults, CrateInfo};
14+
use rustc_codegen_ssa::{CodegenResults, CrateInfo, TargetConfig};
1415
use rustc_data_structures::fx::FxIndexMap;
1516
use rustc_data_structures::jobserver::Proxy;
1617
use rustc_data_structures::sync;
@@ -354,6 +355,33 @@ impl CodegenBackend for DummyCodegenBackend {
354355
"dummy"
355356
}
356357

358+
fn target_config(&self, sess: &Session) -> TargetConfig {
359+
let (target_features, unstable_target_features) = cfg_target_feature(sess, |feature| {
360+
// This is a standin for the list of features a backend is expected to enable.
361+
// It would be better to parse target.features instead and handle implied features,
362+
// but target.features is a list of LLVM target features, not Rust target features.
363+
// The dummy backend doesn't know the mapping between LLVM and Rust target features.
364+
sess.target.abi_required_features().required.contains(&feature)
365+
});
366+
367+
// To report warnings about unknown features
368+
target_features::flag_to_backend_features::<0>(
369+
sess,
370+
true,
371+
|_| Default::default(),
372+
|_, _| {},
373+
);
374+
375+
TargetConfig {
376+
target_features,
377+
unstable_target_features,
378+
has_reliable_f16: true,
379+
has_reliable_f16_math: true,
380+
has_reliable_f128: true,
381+
has_reliable_f128_math: true,
382+
}
383+
}
384+
357385
fn supported_crate_types(&self, _sess: &Session) -> Vec<CrateType> {
358386
// This includes bin despite failing on the link step to ensure that you
359387
// can still get the frontend handling for binaries. For all library

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@
5252
5353
mod by_move_body;
5454
mod drop;
55-
use std::{iter, ops};
55+
use std::ops;
5656

5757
pub(super) use by_move_body::coroutine_by_move_body_def_id;
5858
use drop::{
5959
cleanup_async_drops, create_coroutine_drop_shim, create_coroutine_drop_shim_async,
6060
create_coroutine_drop_shim_proxy_async, elaborate_coroutine_drops, expand_async_drops,
6161
has_expandable_async_drops, insert_clean_drop,
6262
};
63+
use itertools::izip;
6364
use rustc_abi::{FieldIdx, VariantIdx};
6465
use rustc_data_structures::fx::FxHashSet;
6566
use rustc_errors::pluralize;
@@ -752,53 +753,53 @@ fn locals_live_across_suspend_points<'tcx>(
752753
let mut live_locals_at_any_suspension_point = DenseBitSet::new_empty(body.local_decls.len());
753754

754755
for (block, data) in body.basic_blocks.iter_enumerated() {
755-
if let TerminatorKind::Yield { .. } = data.terminator().kind {
756-
let loc = Location { block, statement_index: data.statements.len() };
757-
758-
liveness.seek_to_block_end(block);
759-
let mut live_locals = liveness.get().clone();
760-
761-
if !movable {
762-
// The `liveness` variable contains the liveness of MIR locals ignoring borrows.
763-
// This is correct for movable coroutines since borrows cannot live across
764-
// suspension points. However for immovable coroutines we need to account for
765-
// borrows, so we conservatively assume that all borrowed locals are live until
766-
// we find a StorageDead statement referencing the locals.
767-
// To do this we just union our `liveness` result with `borrowed_locals`, which
768-
// contains all the locals which has been borrowed before this suspension point.
769-
// If a borrow is converted to a raw reference, we must also assume that it lives
770-
// forever. Note that the final liveness is still bounded by the storage liveness
771-
// of the local, which happens using the `intersect` operation below.
772-
borrowed_locals_cursor2.seek_before_primary_effect(loc);
773-
live_locals.union(borrowed_locals_cursor2.get());
774-
}
756+
let TerminatorKind::Yield { .. } = data.terminator().kind else { continue };
757+
758+
let loc = Location { block, statement_index: data.statements.len() };
759+
760+
liveness.seek_to_block_end(block);
761+
let mut live_locals = liveness.get().clone();
762+
763+
if !movable {
764+
// The `liveness` variable contains the liveness of MIR locals ignoring borrows.
765+
// This is correct for movable coroutines since borrows cannot live across
766+
// suspension points. However for immovable coroutines we need to account for
767+
// borrows, so we conservatively assume that all borrowed locals are live until
768+
// we find a StorageDead statement referencing the locals.
769+
// To do this we just union our `liveness` result with `borrowed_locals`, which
770+
// contains all the locals which has been borrowed before this suspension point.
771+
// If a borrow is converted to a raw reference, we must also assume that it lives
772+
// forever. Note that the final liveness is still bounded by the storage liveness
773+
// of the local, which happens using the `intersect` operation below.
774+
borrowed_locals_cursor2.seek_before_primary_effect(loc);
775+
live_locals.union(borrowed_locals_cursor2.get());
776+
}
775777

776-
// Store the storage liveness for later use so we can restore the state
777-
// after a suspension point
778-
storage_live.seek_before_primary_effect(loc);
779-
storage_liveness_map[block] = Some(storage_live.get().clone());
778+
// Store the storage liveness for later use so we can restore the state
779+
// after a suspension point
780+
storage_live.seek_before_primary_effect(loc);
781+
storage_liveness_map[block] = Some(storage_live.get().clone());
780782

781-
// Locals live are live at this point only if they are used across
782-
// suspension points (the `liveness` variable)
783-
// and their storage is required (the `storage_required` variable)
784-
requires_storage_cursor.seek_before_primary_effect(loc);
785-
live_locals.intersect(requires_storage_cursor.get());
783+
// Locals live are live at this point only if they are used across
784+
// suspension points (the `liveness` variable)
785+
// and their storage is required (the `storage_required` variable)
786+
requires_storage_cursor.seek_before_primary_effect(loc);
787+
live_locals.intersect(requires_storage_cursor.get());
786788

787-
// The coroutine argument is ignored.
788-
live_locals.remove(SELF_ARG);
789+
// The coroutine argument is ignored.
790+
live_locals.remove(SELF_ARG);
789791

790-
debug!("loc = {:?}, live_locals = {:?}", loc, live_locals);
792+
debug!(?loc, ?live_locals);
791793

792-
// Add the locals live at this suspension point to the set of locals which live across
793-
// any suspension points
794-
live_locals_at_any_suspension_point.union(&live_locals);
794+
// Add the locals live at this suspension point to the set of locals which live across
795+
// any suspension points
796+
live_locals_at_any_suspension_point.union(&live_locals);
795797

796-
live_locals_at_suspension_points.push(live_locals);
797-
source_info_at_suspension_points.push(data.terminator().source_info);
798-
}
798+
live_locals_at_suspension_points.push(live_locals);
799+
source_info_at_suspension_points.push(data.terminator().source_info);
799800
}
800801

801-
debug!("live_locals_anywhere = {:?}", live_locals_at_any_suspension_point);
802+
debug!(?live_locals_at_any_suspension_point);
802803
let saved_locals = CoroutineSavedLocals(live_locals_at_any_suspension_point);
803804

804805
// Renumber our liveness_map bitsets to include only the locals we are
@@ -999,8 +1000,8 @@ fn compute_layout<'tcx>(
9991000
} = liveness;
10001001

10011002
// Gather live local types and their indices.
1002-
let mut locals = IndexVec::<CoroutineSavedLocal, _>::new();
1003-
let mut tys = IndexVec::<CoroutineSavedLocal, _>::new();
1003+
let mut locals = IndexVec::<CoroutineSavedLocal, _>::with_capacity(saved_locals.domain_size());
1004+
let mut tys = IndexVec::<CoroutineSavedLocal, _>::with_capacity(saved_locals.domain_size());
10041005
for (saved_local, local) in saved_locals.iter_enumerated() {
10051006
debug!("coroutine saved local {:?} => {:?}", saved_local, local);
10061007

@@ -1034,38 +1035,39 @@ fn compute_layout<'tcx>(
10341035
// In debuginfo, these will correspond to the beginning (UNRESUMED) or end
10351036
// (RETURNED, POISONED) of the function.
10361037
let body_span = body.source_scopes[OUTERMOST_SOURCE_SCOPE].span;
1037-
let mut variant_source_info: IndexVec<VariantIdx, SourceInfo> = [
1038+
let mut variant_source_info: IndexVec<VariantIdx, SourceInfo> = IndexVec::with_capacity(
1039+
CoroutineArgs::RESERVED_VARIANTS + live_locals_at_suspension_points.len(),
1040+
);
1041+
variant_source_info.extend([
10381042
SourceInfo::outermost(body_span.shrink_to_lo()),
10391043
SourceInfo::outermost(body_span.shrink_to_hi()),
10401044
SourceInfo::outermost(body_span.shrink_to_hi()),
1041-
]
1042-
.iter()
1043-
.copied()
1044-
.collect();
1045+
]);
10451046

10461047
// Build the coroutine variant field list.
10471048
// Create a map from local indices to coroutine struct indices.
1048-
let mut variant_fields: IndexVec<VariantIdx, IndexVec<FieldIdx, CoroutineSavedLocal>> =
1049-
iter::repeat(IndexVec::new()).take(CoroutineArgs::RESERVED_VARIANTS).collect();
1049+
let mut variant_fields: IndexVec<VariantIdx, _> = IndexVec::from_elem_n(
1050+
IndexVec::new(),
1051+
CoroutineArgs::RESERVED_VARIANTS + live_locals_at_suspension_points.len(),
1052+
);
10501053
let mut remap = IndexVec::from_elem_n(None, saved_locals.domain_size());
1051-
for (suspension_point_idx, live_locals) in live_locals_at_suspension_points.iter().enumerate() {
1052-
let variant_index =
1053-
VariantIdx::from(CoroutineArgs::RESERVED_VARIANTS + suspension_point_idx);
1054-
let mut fields = IndexVec::new();
1055-
for (idx, saved_local) in live_locals.iter().enumerate() {
1056-
fields.push(saved_local);
1054+
for (live_locals, &source_info_at_suspension_point, (variant_index, fields)) in izip!(
1055+
&live_locals_at_suspension_points,
1056+
&source_info_at_suspension_points,
1057+
variant_fields.iter_enumerated_mut().skip(CoroutineArgs::RESERVED_VARIANTS)
1058+
) {
1059+
*fields = live_locals.iter().collect();
1060+
for (idx, &saved_local) in fields.iter_enumerated() {
10571061
// Note that if a field is included in multiple variants, we will
10581062
// just use the first one here. That's fine; fields do not move
10591063
// around inside coroutines, so it doesn't matter which variant
10601064
// index we access them by.
1061-
let idx = FieldIdx::from_usize(idx);
10621065
remap[locals[saved_local]] = Some((tys[saved_local].ty, variant_index, idx));
10631066
}
1064-
variant_fields.push(fields);
1065-
variant_source_info.push(source_info_at_suspension_points[suspension_point_idx]);
1067+
variant_source_info.push(source_info_at_suspension_point);
10661068
}
1067-
debug!("coroutine variant_fields = {:?}", variant_fields);
1068-
debug!("coroutine storage_conflicts = {:#?}", storage_conflicts);
1069+
debug!(?variant_fields);
1070+
debug!(?storage_conflicts);
10691071

10701072
let mut field_names = IndexVec::from_elem(None, &tys);
10711073
for var in &body.var_debug_info {

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
921921
}
922922
}
923923

924-
if projection.is_owned() {
924+
if Cow::is_owned(&projection) {
925925
place.projection = self.tcx.mk_place_elems(&projection);
926926
}
927927

0 commit comments

Comments
 (0)