Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b335056
Turn `Cow::is_borrowed,is_owned` into associated functions.
theemathas Mar 8, 2025
f0c98c2
Allocate vec capacity upfront in coroutine layout computation
yotamofek Oct 18, 2025
a67c615
Reduce rightward drift in `locals_live_across_suspend_points`
yotamofek Oct 18, 2025
11b82e1
rustdoc: Rename unstable option `--nocapture` to `--no-capture`
fmease Oct 25, 2025
857a187
rustdoc search: Include attribute and derive macros when filtering on…
GuillaumeGomez Oct 27, 2025
52c99e6
Add regression test for including derive macros in macro filtering
GuillaumeGomez Oct 27, 2025
bd61985
Disable crt_static_allows_dylibs in redox targets
jackpot51 Oct 3, 2025
fa0f163
Add riscv64gc-unknown-redox
bjorn3 Oct 26, 2025
4d7c784
Handle default features and -Ctarget-features in the dummy backend
bjorn3 Oct 29, 2025
958d0a3
Align VEX V5 boot routine to 4 bytes
lewisfm Oct 29, 2025
e0b8dd3
Simplify rustc_public context handling
celinval Oct 20, 2025
f1a0dfd
Rollup merge of #138217 - theemathas:cow_is_owned_borrowed_associated…
jhpratt Oct 30, 2025
1ae00ba
Rollup merge of #147858 - yotamofek:pr/mir/coroutine-layout-opt, r=cj…
jhpratt Oct 30, 2025
2e4e4ab
Rollup merge of #147923 - celinval:rpub-remove-trait, r=oli-obk
jhpratt Oct 30, 2025
35fcb55
Rollup merge of #148115 - fmease:rustdoc-no-capture, r=notriddle
jhpratt Oct 30, 2025
a749188
Rollup merge of #148137 - bjorn3:redox_fixes, r=mati865
jhpratt Oct 30, 2025
645e41a
Rollup merge of #148176 - GuillaumeGomez:filter-macros, r=notriddle
jhpratt Oct 30, 2025
f76239c
Rollup merge of #148253 - bjorn3:dummy_backend_target_features, r=Jon…
jhpratt Oct 30, 2025
4796814
Rollup merge of #148272 - vexide:fix/linker-script-align, r=saethlin
jhpratt Oct 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use rustc_ast as ast;
use rustc_attr_parsing::{ShouldEmit, validate_attr};
use rustc_codegen_ssa::back::archive::ArArchiveBuilderBuilder;
use rustc_codegen_ssa::back::link::link_binary;
use rustc_codegen_ssa::target_features::{self, cfg_target_feature};
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_codegen_ssa::{CodegenResults, CrateInfo};
use rustc_codegen_ssa::{CodegenResults, CrateInfo, TargetConfig};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::jobserver::Proxy;
use rustc_data_structures::sync;
Expand Down Expand Up @@ -354,6 +355,33 @@ impl CodegenBackend for DummyCodegenBackend {
"dummy"
}

fn target_config(&self, sess: &Session) -> TargetConfig {
let (target_features, unstable_target_features) = cfg_target_feature(sess, |feature| {
// This is a standin for the list of features a backend is expected to enable.
// It would be better to parse target.features instead and handle implied features,
// but target.features is a list of LLVM target features, not Rust target features.
// The dummy backend doesn't know the mapping between LLVM and Rust target features.
sess.target.abi_required_features().required.contains(&feature)
});

// To report warnings about unknown features
target_features::flag_to_backend_features::<0>(
sess,
true,
|_| Default::default(),
|_, _| {},
);

TargetConfig {
target_features,
unstable_target_features,
has_reliable_f16: true,
has_reliable_f16_math: true,
has_reliable_f128: true,
has_reliable_f128_math: true,
}
}

fn supported_crate_types(&self, _sess: &Session) -> Vec<CrateType> {
// This includes bin despite failing on the link step to ensure that you
// can still get the frontend handling for binaries. For all library
Expand Down
122 changes: 62 additions & 60 deletions compiler/rustc_mir_transform/src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@

mod by_move_body;
mod drop;
use std::{iter, ops};
use std::ops;

pub(super) use by_move_body::coroutine_by_move_body_def_id;
use drop::{
cleanup_async_drops, create_coroutine_drop_shim, create_coroutine_drop_shim_async,
create_coroutine_drop_shim_proxy_async, elaborate_coroutine_drops, expand_async_drops,
has_expandable_async_drops, insert_clean_drop,
};
use itertools::izip;
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::pluralize;
Expand Down Expand Up @@ -752,53 +753,53 @@ fn locals_live_across_suspend_points<'tcx>(
let mut live_locals_at_any_suspension_point = DenseBitSet::new_empty(body.local_decls.len());

for (block, data) in body.basic_blocks.iter_enumerated() {
if let TerminatorKind::Yield { .. } = data.terminator().kind {
let loc = Location { block, statement_index: data.statements.len() };

liveness.seek_to_block_end(block);
let mut live_locals = liveness.get().clone();

if !movable {
// The `liveness` variable contains the liveness of MIR locals ignoring borrows.
// This is correct for movable coroutines since borrows cannot live across
// suspension points. However for immovable coroutines we need to account for
// borrows, so we conservatively assume that all borrowed locals are live until
// we find a StorageDead statement referencing the locals.
// To do this we just union our `liveness` result with `borrowed_locals`, which
// contains all the locals which has been borrowed before this suspension point.
// If a borrow is converted to a raw reference, we must also assume that it lives
// forever. Note that the final liveness is still bounded by the storage liveness
// of the local, which happens using the `intersect` operation below.
borrowed_locals_cursor2.seek_before_primary_effect(loc);
live_locals.union(borrowed_locals_cursor2.get());
}
let TerminatorKind::Yield { .. } = data.terminator().kind else { continue };

let loc = Location { block, statement_index: data.statements.len() };

liveness.seek_to_block_end(block);
let mut live_locals = liveness.get().clone();

if !movable {
// The `liveness` variable contains the liveness of MIR locals ignoring borrows.
// This is correct for movable coroutines since borrows cannot live across
// suspension points. However for immovable coroutines we need to account for
// borrows, so we conservatively assume that all borrowed locals are live until
// we find a StorageDead statement referencing the locals.
// To do this we just union our `liveness` result with `borrowed_locals`, which
// contains all the locals which has been borrowed before this suspension point.
// If a borrow is converted to a raw reference, we must also assume that it lives
// forever. Note that the final liveness is still bounded by the storage liveness
// of the local, which happens using the `intersect` operation below.
borrowed_locals_cursor2.seek_before_primary_effect(loc);
live_locals.union(borrowed_locals_cursor2.get());
}

// Store the storage liveness for later use so we can restore the state
// after a suspension point
storage_live.seek_before_primary_effect(loc);
storage_liveness_map[block] = Some(storage_live.get().clone());
// Store the storage liveness for later use so we can restore the state
// after a suspension point
storage_live.seek_before_primary_effect(loc);
storage_liveness_map[block] = Some(storage_live.get().clone());

// Locals live are live at this point only if they are used across
// suspension points (the `liveness` variable)
// and their storage is required (the `storage_required` variable)
requires_storage_cursor.seek_before_primary_effect(loc);
live_locals.intersect(requires_storage_cursor.get());
// Locals live are live at this point only if they are used across
// suspension points (the `liveness` variable)
// and their storage is required (the `storage_required` variable)
requires_storage_cursor.seek_before_primary_effect(loc);
live_locals.intersect(requires_storage_cursor.get());

// The coroutine argument is ignored.
live_locals.remove(SELF_ARG);
// The coroutine argument is ignored.
live_locals.remove(SELF_ARG);

debug!("loc = {:?}, live_locals = {:?}", loc, live_locals);
debug!(?loc, ?live_locals);

// Add the locals live at this suspension point to the set of locals which live across
// any suspension points
live_locals_at_any_suspension_point.union(&live_locals);
// Add the locals live at this suspension point to the set of locals which live across
// any suspension points
live_locals_at_any_suspension_point.union(&live_locals);

live_locals_at_suspension_points.push(live_locals);
source_info_at_suspension_points.push(data.terminator().source_info);
}
live_locals_at_suspension_points.push(live_locals);
source_info_at_suspension_points.push(data.terminator().source_info);
}

debug!("live_locals_anywhere = {:?}", live_locals_at_any_suspension_point);
debug!(?live_locals_at_any_suspension_point);
let saved_locals = CoroutineSavedLocals(live_locals_at_any_suspension_point);

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

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

Expand Down Expand Up @@ -1034,38 +1035,39 @@ fn compute_layout<'tcx>(
// In debuginfo, these will correspond to the beginning (UNRESUMED) or end
// (RETURNED, POISONED) of the function.
let body_span = body.source_scopes[OUTERMOST_SOURCE_SCOPE].span;
let mut variant_source_info: IndexVec<VariantIdx, SourceInfo> = [
let mut variant_source_info: IndexVec<VariantIdx, SourceInfo> = IndexVec::with_capacity(
CoroutineArgs::RESERVED_VARIANTS + live_locals_at_suspension_points.len(),
);
variant_source_info.extend([
SourceInfo::outermost(body_span.shrink_to_lo()),
SourceInfo::outermost(body_span.shrink_to_hi()),
SourceInfo::outermost(body_span.shrink_to_hi()),
]
.iter()
.copied()
.collect();
]);

// Build the coroutine variant field list.
// Create a map from local indices to coroutine struct indices.
let mut variant_fields: IndexVec<VariantIdx, IndexVec<FieldIdx, CoroutineSavedLocal>> =
iter::repeat(IndexVec::new()).take(CoroutineArgs::RESERVED_VARIANTS).collect();
let mut variant_fields: IndexVec<VariantIdx, _> = IndexVec::from_elem_n(
IndexVec::new(),
CoroutineArgs::RESERVED_VARIANTS + live_locals_at_suspension_points.len(),
);
let mut remap = IndexVec::from_elem_n(None, saved_locals.domain_size());
for (suspension_point_idx, live_locals) in live_locals_at_suspension_points.iter().enumerate() {
let variant_index =
VariantIdx::from(CoroutineArgs::RESERVED_VARIANTS + suspension_point_idx);
let mut fields = IndexVec::new();
for (idx, saved_local) in live_locals.iter().enumerate() {
fields.push(saved_local);
for (live_locals, &source_info_at_suspension_point, (variant_index, fields)) in izip!(
&live_locals_at_suspension_points,
&source_info_at_suspension_points,
variant_fields.iter_enumerated_mut().skip(CoroutineArgs::RESERVED_VARIANTS)
) {
*fields = live_locals.iter().collect();
for (idx, &saved_local) in fields.iter_enumerated() {
// Note that if a field is included in multiple variants, we will
// just use the first one here. That's fine; fields do not move
// around inside coroutines, so it doesn't matter which variant
// index we access them by.
let idx = FieldIdx::from_usize(idx);
remap[locals[saved_local]] = Some((tys[saved_local].ty, variant_index, idx));
}
variant_fields.push(fields);
variant_source_info.push(source_info_at_suspension_points[suspension_point_idx]);
variant_source_info.push(source_info_at_suspension_point);
}
debug!("coroutine variant_fields = {:?}", variant_fields);
debug!("coroutine storage_conflicts = {:#?}", storage_conflicts);
debug!(?variant_fields);
debug!(?storage_conflicts);

let mut field_names = IndexVec::from_elem(None, &tys);
for var in &body.var_debug_info {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/gvn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
}
}

if projection.is_owned() {
if Cow::is_owned(&projection) {
place.projection = self.tcx.mk_place_elems(&projection);
}

Expand Down
Loading
Loading