Skip to content

Rollup of 14 pull requests #137339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2445dd7
Persist target features used for codegen beyond tcx
Feb 9, 2025
831d9f3
Pass through of target features to llvm-bitcode-linker and handling them
Feb 5, 2025
40ecda6
Remove obsolete MinGW ThinLTO+TLS workaround
kornelski Feb 17, 2025
35febd7
Fix `*-win7-windows-msvc` target since 26eeac1a1e9fe46ffd80dd0d3dafdd…
QianNangong Feb 19, 2025
78ddabf
Create a generic AVR target: avr-none
Patryk27 Oct 13, 2024
c9fbaab
Reflow `MirPhase` comments.
nnethercote Feb 18, 2025
c039533
Improve MIR phase comments.
nnethercote Feb 18, 2025
83a7fb6
Improve how the MIR dialect/phase index is reported.
nnethercote Feb 18, 2025
a1a8df2
Tweak error code for sized checks of const/static
compiler-errors Feb 18, 2025
bb7b912
Check signature WF when lowering MIR body
compiler-errors Feb 20, 2025
cae9ebb
Simplify `Postorder` customization.
nnethercote Feb 19, 2025
81ab20f
Update references to cc_detect.rs
jmqd Feb 20, 2025
ea71808
Create safe helper for LLVMSetDLLStorageClass
oli-obk Feb 14, 2025
ce7f58b
Merge two operations that were always performed together
oli-obk Feb 14, 2025
c23bf48
infer linker flavor by linker name if it's sufficiently specific
usamoi Feb 3, 2025
d5128f9
avr-rjmp-offset: Explain `.target_cpu()`
Patryk27 Feb 20, 2025
18c210c
Workaround Cranelift not yet properly supporting vectors smaller than…
bjorn3 Feb 20, 2025
c2aed39
Update docs for default features of wasm targets
alexcrichton Feb 20, 2025
32a1ff1
Make x86 QNX target name consistent with other Rust targets
flba-eb Feb 20, 2025
7ba3d7b
Remove `BackendRepr::Uninhabited`, replaced with an `uninhabited: boo…
zachs18 Jan 26, 2025
c33fb5a
Update ui tests with `LayoutData { uninhabited: ... }` etc
zachs18 Jan 26, 2025
bcfde13
Update check to reflect that non-ZST uninhabited types should not be …
zachs18 Jan 28, 2025
58ebf6a
Add test that uninhabited repr(transparent) type has same function re…
zachs18 Feb 13, 2025
6493cd8
Adjust LayoutData::uninhabited doc comment.
zachs18 Feb 18, 2025
e3f5db0
fine-tune comment
RalfJung Feb 18, 2025
750472b
Rollup merge of #131651 - Patryk27:avr-unknown-unknown, r=tgross35
workingjubilee Feb 20, 2025
473787b
Rollup merge of #136473 - usamoi:infer_linker_hints, r=petrochenkov
workingjubilee Feb 20, 2025
7481769
Rollup merge of #136608 - kulst:ptx_target_features, r=bjorn3
workingjubilee Feb 20, 2025
fe1ce30
Rollup merge of #136985 - zachs18:backend-repr-remove-uninhabited, r=…
workingjubilee Feb 20, 2025
cd0b8e9
Rollup merge of #137192 - kornelski:windows-tls-lto, r=ChrisDenton
workingjubilee Feb 20, 2025
16f0f35
Rollup merge of #137204 - nnethercote:clarify-MIR-dialects-and-phases…
workingjubilee Feb 20, 2025
32330eb
Rollup merge of #137270 - QianNangong:master, r=ChrisDenton
workingjubilee Feb 20, 2025
a6414b1
Rollup merge of #137298 - compiler-errors:mir-wf, r=lcnr
workingjubilee Feb 20, 2025
44e7269
Rollup merge of #137299 - nnethercote:simplify-PostOrder-customizatio…
workingjubilee Feb 20, 2025
fc339be
Rollup merge of #137312 - jmqd:master, r=clubby789
workingjubilee Feb 20, 2025
9a0e823
Rollup merge of #137313 - oli-obk:push-ywvuqkxuqyom, r=petrochenkov
workingjubilee Feb 20, 2025
2b5570b
Rollup merge of #137318 - bjorn3:cg_clif_abi_workaround, r=workingjub…
workingjubilee Feb 20, 2025
48dbbe2
Rollup merge of #137322 - alexcrichton:update-wasm-docs, r=jieyouxu
workingjubilee Feb 20, 2025
f6941de
Rollup merge of #137324 - flba-eb:rename_qnx_target_name_i586, r=work…
workingjubilee Feb 20, 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
Prev Previous commit
Next Next commit
Simplify Postorder customization.
`Postorder` has a `C: Customization<'tcx>` parameter, that gives it
flexibility about how it computes successors. But in practice, there are
only two `impls` of `Customization`, and one is for the unit type.

This commit simplifies things by removing the generic parameter and
replacing it with an `Option`.
  • Loading branch information
nnethercote committed Feb 20, 2025
commit cae9ebbe1e09c2878d56ab1425d3765f450fd5fe
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/basic_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'tcx> BasicBlocks<'tcx> {
#[inline]
pub fn reverse_postorder(&self) -> &[BasicBlock] {
self.cache.reverse_postorder.get_or_init(|| {
let mut rpo: Vec<_> = Postorder::new(&self.basic_blocks, START_BLOCK, ()).collect();
let mut rpo: Vec<_> = Postorder::new(&self.basic_blocks, START_BLOCK, None).collect();
rpo.reverse();
rpo
})
Expand Down
47 changes: 13 additions & 34 deletions compiler/rustc_middle/src/mir/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,21 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
/// ```
///
/// A Postorder traversal of this graph is `D B C A` or `D C B A`
pub struct Postorder<'a, 'tcx, C> {
pub struct Postorder<'a, 'tcx> {
basic_blocks: &'a IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
visited: DenseBitSet<BasicBlock>,
visit_stack: Vec<(BasicBlock, Successors<'a>)>,
root_is_start_block: bool,
extra: C,
/// A non-empty `extra` allows for a precise calculation of the successors.
extra: Option<(TyCtxt<'tcx>, Instance<'tcx>)>,
}

impl<'a, 'tcx, C> Postorder<'a, 'tcx, C>
where
C: Customization<'tcx>,
{
impl<'a, 'tcx> Postorder<'a, 'tcx> {
pub fn new(
basic_blocks: &'a IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
root: BasicBlock,
extra: C,
) -> Postorder<'a, 'tcx, C> {
extra: Option<(TyCtxt<'tcx>, Instance<'tcx>)>,
) -> Postorder<'a, 'tcx> {
let mut po = Postorder {
basic_blocks,
visited: DenseBitSet::new_empty(basic_blocks.len()),
Expand All @@ -140,7 +138,11 @@ where
return;
}
let data = &self.basic_blocks[bb];
let successors = C::successors(data, self.extra);
let successors = if let Some(extra) = self.extra {
data.mono_successors(extra.0, extra.1)
} else {
data.terminator().successors()
};
self.visit_stack.push((bb, successors));
}

Expand Down Expand Up @@ -198,10 +200,7 @@ where
}
}

impl<'tcx, C> Iterator for Postorder<'_, 'tcx, C>
where
C: Customization<'tcx>,
{
impl<'tcx> Iterator for Postorder<'_, 'tcx> {
type Item = BasicBlock;

fn next(&mut self) -> Option<BasicBlock> {
Expand Down Expand Up @@ -241,32 +240,12 @@ pub fn postorder<'a, 'tcx>(
reverse_postorder(body).rev()
}

/// Lets us plug in some additional logic and data into a Postorder traversal. Or not.
pub trait Customization<'tcx>: Copy {
fn successors<'a>(_: &'a BasicBlockData<'tcx>, _: Self) -> Successors<'a>;
}

impl<'tcx> Customization<'tcx> for () {
fn successors<'a>(data: &'a BasicBlockData<'tcx>, _: ()) -> Successors<'a> {
data.terminator().successors()
}
}

impl<'tcx> Customization<'tcx> for (TyCtxt<'tcx>, Instance<'tcx>) {
fn successors<'a>(
data: &'a BasicBlockData<'tcx>,
(tcx, instance): (TyCtxt<'tcx>, Instance<'tcx>),
) -> Successors<'a> {
data.mono_successors(tcx, instance)
}
}

pub fn mono_reachable_reverse_postorder<'a, 'tcx>(
body: &'a Body<'tcx>,
tcx: TyCtxt<'tcx>,
instance: Instance<'tcx>,
) -> Vec<BasicBlock> {
let mut iter = Postorder::new(&body.basic_blocks, START_BLOCK, (tcx, instance));
let mut iter = Postorder::new(&body.basic_blocks, START_BLOCK, Some((tcx, instance)));
let mut items = Vec::with_capacity(body.basic_blocks.len());
while let Some(block) = iter.next() {
items.push(block);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_utils/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn visit_local_usage(locals: &[Local], mir: &Body<'_>, location: Location) -
locals.len()
];

traversal::Postorder::new(&mir.basic_blocks, location.block, ())
traversal::Postorder::new(&mir.basic_blocks, location.block, None)
.collect::<Vec<_>>()
.into_iter()
.rev()
Expand Down
Loading