Skip to content

Commit

Permalink
Auto merge of rust-lang#137176 - matthiaskrgr:rollup-eht05gr, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#136959 (Simplify switch sources)
 - rust-lang#137020 (Pass vendored sources from bootstrap to generate-copyright)
 - rust-lang#137073 (boostrap: skip no_std targets in Std doc step)
 - rust-lang#137165 (Use `tell` for `<File as Seek>::stream_position`)
 - rust-lang#137166 (Update default loongarch code model in docs)
 - rust-lang#137168 (correct comment)
 - rust-lang#137169 (CI: rfl: move job forward to Linux v6.14-rc3)
 - rust-lang#137170 (Allow configuring jemalloc per target)
 - rust-lang#137173 (Subtree update of `rust-analyzer`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 18, 2025
2 parents ce36a96 + fc82903 commit de91711
Show file tree
Hide file tree
Showing 142 changed files with 9,812 additions and 3,088 deletions.
31 changes: 26 additions & 5 deletions compiler/rustc_middle/src/mir/basic_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ pub struct BasicBlocks<'tcx> {
// Typically 95%+ of basic blocks have 4 or fewer predecessors.
type Predecessors = IndexVec<BasicBlock, SmallVec<[BasicBlock; 4]>>;

type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[Option<u128>; 1]>>;
/// Each `(target, switch)` entry in the map contains a list of switch values
/// that lead to a `target` block from a `switch` block.
///
/// Note: this type is currently never instantiated, because it's only used for
/// `BasicBlocks::switch_sources`, which is only called by backwards analyses
/// that do `SwitchInt` handling, and we don't have any of those, not even in
/// tests. See #95120 and #94576.
type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[SwitchTargetValue; 1]>>;

#[derive(Debug, Clone, Copy)]
pub enum SwitchTargetValue {
// A normal switch value.
Normal(u128),
// The final "otherwise" fallback value.
Otherwise,
}

#[derive(Clone, Default, Debug)]
struct Cache {
Expand Down Expand Up @@ -70,8 +85,8 @@ impl<'tcx> BasicBlocks<'tcx> {
})
}

/// `switch_sources()[&(target, switch)]` returns a list of switch
/// values that lead to a `target` block from a `switch` block.
/// Returns info about switch values that lead from one block to another
/// block. See `SwitchSources`.
#[inline]
pub fn switch_sources(&self) -> &SwitchSources {
self.cache.switch_sources.get_or_init(|| {
Expand All @@ -82,9 +97,15 @@ impl<'tcx> BasicBlocks<'tcx> {
}) = &data.terminator
{
for (value, target) in targets.iter() {
switch_sources.entry((target, bb)).or_default().push(Some(value));
switch_sources
.entry((target, bb))
.or_default()
.push(SwitchTargetValue::Normal(value));
}
switch_sources.entry((targets.otherwise(), bb)).or_default().push(None);
switch_sources
.entry((targets.otherwise(), bb))
.or_default()
.push(SwitchTargetValue::Otherwise);
}
}
switch_sources
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fmt::{self, Debug, Formatter};
use std::ops::{Index, IndexMut};
use std::{iter, mem};

pub use basic_blocks::BasicBlocks;
pub use basic_blocks::{BasicBlocks, SwitchTargetValue};
use either::Either;
use polonius_engine::Atom;
use rustc_abi::{FieldIdx, VariantIdx};
Expand Down
30 changes: 19 additions & 11 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,22 +1015,30 @@ impl TerminatorKind<'_> {

#[derive(Debug, Clone, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
pub struct SwitchTargets {
/// Possible values. The locations to branch to in each case
/// are found in the corresponding indices from the `targets` vector.
/// Possible values. For each value, the location to branch to is found in
/// the corresponding element in the `targets` vector.
pub(super) values: SmallVec<[Pu128; 1]>,

/// Possible branch sites. The last element of this vector is used
/// for the otherwise branch, so targets.len() == values.len() + 1
/// should hold.
/// Possible branch targets. The last element of this vector is used for
/// the "otherwise" branch, so `targets.len() == values.len() + 1` always
/// holds.
//
// This invariant is quite non-obvious and also could be improved.
// One way to make this invariant is to have something like this instead:
// Note: This invariant is non-obvious and easy to violate. This would be a
// more rigorous representation:
//
// branches: Vec<(ConstInt, BasicBlock)>,
// otherwise: Option<BasicBlock> // exhaustive if None
// normal: SmallVec<[(Pu128, BasicBlock); 1]>,
// otherwise: BasicBlock,
//
// However we’ve decided to keep this as-is until we figure a case
// where some other approach seems to be strictly better than other.
// But it's important to have the targets in a sliceable type, because
// target slices show up elsewhere. E.g. `TerminatorKind::InlineAsm` has a
// boxed slice, and `TerminatorKind::FalseEdge` has a single target that
// can be converted to a slice with `slice::from_ref`.
//
// Why does this matter? In functions like `TerminatorKind::successors` we
// return `impl Iterator` and a non-slice-of-targets representation here
// causes problems because multiple different concrete iterator types would
// be involved and we would need a boxed trait object, which requires an
// allocation, which is expensive if done frequently.
pub(super) targets: SmallVec<[BasicBlock; 2]>,
}

Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/ty/typeck_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ pub struct TypeckResults<'tcx> {
coercion_casts: ItemLocalSet,

/// Set of trait imports actually used in the method resolution.
/// This is used for warning unused imports. During type
/// checking, this `Arc` should not be cloned: it must have a ref-count
/// of 1 so that we can insert things into the set mutably.
/// This is used for warning unused imports.
pub used_trait_imports: UnordSet<LocalDefId>,

/// If any errors occurred while type-checking this body,
Expand Down
27 changes: 11 additions & 16 deletions compiler/rustc_mir_dataflow/src/framework/direction.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::ops::RangeInclusive;

use rustc_middle::mir::{self, BasicBlock, CallReturnPlaces, Location, TerminatorEdges};
use rustc_middle::mir::{
self, BasicBlock, CallReturnPlaces, Location, SwitchTargetValue, TerminatorEdges,
};

use super::visitor::ResultsVisitor;
use super::{Analysis, Effect, EffectIndex, Results, SwitchIntTarget};
use super::{Analysis, Effect, EffectIndex, Results};

pub trait Direction {
const IS_FORWARD: bool;
Expand Down Expand Up @@ -112,14 +114,10 @@ impl Direction for Backward {

mir::TerminatorKind::SwitchInt { targets: _, ref discr } => {
if let Some(mut data) = analysis.get_switch_int_data(block, discr) {
let values = &body.basic_blocks.switch_sources()[&(block, pred)];
let targets =
values.iter().map(|&value| SwitchIntTarget { value, target: block });

let mut tmp = analysis.bottom_value(body);
for target in targets {
tmp.clone_from(&exit_state);
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, target);
for &value in &body.basic_blocks.switch_sources()[&(block, pred)] {
tmp.clone_from(exit_state);
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, value);
propagate(pred, &tmp);
}
} else {
Expand Down Expand Up @@ -292,12 +290,9 @@ impl Direction for Forward {
if let Some(mut data) = analysis.get_switch_int_data(block, discr) {
let mut tmp = analysis.bottom_value(body);
for (value, target) in targets.iter() {
tmp.clone_from(&exit_state);
analysis.apply_switch_int_edge_effect(
&mut data,
&mut tmp,
SwitchIntTarget { value: Some(value), target },
);
tmp.clone_from(exit_state);
let value = SwitchTargetValue::Normal(value);
analysis.apply_switch_int_edge_effect(&mut data, &mut tmp, value);
propagate(target, &tmp);
}

Expand All @@ -308,7 +303,7 @@ impl Direction for Forward {
analysis.apply_switch_int_edge_effect(
&mut data,
exit_state,
SwitchIntTarget { value: None, target: otherwise },
SwitchTargetValue::Otherwise,
);
propagate(otherwise, exit_state);
} else {
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_mir_dataflow/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ use rustc_data_structures::work_queue::WorkQueue;
use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
use rustc_index::{Idx, IndexVec};
use rustc_middle::bug;
use rustc_middle::mir::{self, BasicBlock, CallReturnPlaces, Location, TerminatorEdges, traversal};
use rustc_middle::mir::{
self, BasicBlock, CallReturnPlaces, Location, SwitchTargetValue, TerminatorEdges, traversal,
};
use rustc_middle::ty::TyCtxt;
use tracing::error;

Expand Down Expand Up @@ -220,7 +222,7 @@ pub trait Analysis<'tcx> {
&mut self,
_data: &mut Self::SwitchIntData,
_state: &mut Self::Domain,
_edge: SwitchIntTarget,
_value: SwitchTargetValue,
) {
unreachable!();
}
Expand Down Expand Up @@ -430,10 +432,5 @@ impl EffectIndex {
}
}

pub struct SwitchIntTarget {
pub value: Option<u128>,
pub target: BasicBlock,
}

#[cfg(test)]
mod tests;
13 changes: 7 additions & 6 deletions compiler/rustc_mir_dataflow/src/impls/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use rustc_abi::VariantIdx;
use rustc_index::Idx;
use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
use rustc_middle::bug;
use rustc_middle::mir::{self, Body, CallReturnPlaces, Location, TerminatorEdges};
use rustc_middle::mir::{
self, Body, CallReturnPlaces, Location, SwitchTargetValue, TerminatorEdges,
};
use rustc_middle::ty::util::Discr;
use rustc_middle::ty::{self, TyCtxt};
use tracing::{debug, instrument};

use crate::drop_flag_effects::DropFlagState;
use crate::framework::SwitchIntTarget;
use crate::move_paths::{HasMoveData, InitIndex, InitKind, LookupResult, MoveData, MovePathIndex};
use crate::{
Analysis, GenKill, MaybeReachable, drop_flag_effects, drop_flag_effects_for_function_entry,
Expand Down Expand Up @@ -422,9 +423,9 @@ impl<'tcx> Analysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
&mut self,
data: &mut Self::SwitchIntData,
state: &mut Self::Domain,
edge: SwitchIntTarget,
value: SwitchTargetValue,
) {
if let Some(value) = edge.value {
if let SwitchTargetValue::Normal(value) = value {
// Kill all move paths that correspond to variants we know to be inactive along this
// particular outgoing edge of a `SwitchInt`.
drop_flag_effects::on_all_inactive_variants(
Expand Down Expand Up @@ -535,9 +536,9 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
&mut self,
data: &mut Self::SwitchIntData,
state: &mut Self::Domain,
edge: SwitchIntTarget,
value: SwitchTargetValue,
) {
if let Some(value) = edge.value {
if let SwitchTargetValue::Normal(value) = value {
// Mark all move paths that correspond to variants other than this one as maybe
// uninitialized (in reality, they are *definitely* uninitialized).
drop_flag_effects::on_all_inactive_variants(
Expand Down
7 changes: 6 additions & 1 deletion config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@
#remap-debuginfo = false

# Link the compiler and LLVM against `jemalloc` instead of the default libc allocator.
# This option is only tested on Linux and OSX.
# This option is only tested on Linux and OSX. It can also be configured per-target in the
# [target.<tuple>] section.
#jemalloc = false

# Run tests in various test suites with the "nll compare mode" in addition to
Expand Down Expand Up @@ -927,6 +928,10 @@
# order to run `x check`.
#optimized-compiler-builtins = build.optimized-compiler-builtins (bool)

# Link the compiler and LLVM against `jemalloc` instead of the default libc allocator.
# This overrides the global `rust.jemalloc` option. See that option for more info.
#jemalloc = rust.jemalloc (bool)

# =============================================================================
# Distribution options
#
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,9 @@ impl Seek for &File {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
self.inner.seek(pos)
}
fn stream_position(&mut self) -> io::Result<u64> {
self.inner.tell()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -1275,6 +1278,9 @@ impl Seek for File {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
(&*self).seek(pos)
}
fn stream_position(&mut self) -> io::Result<u64> {
(&*self).stream_position()
}
}

#[stable(feature = "io_traits_arc", since = "1.73.0")]
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/hermit/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ impl File {
Err(Error::from_raw_os_error(22))
}

pub fn tell(&self) -> io::Result<u64> {
self.seek(SeekFrom::Current(0))
}

pub fn duplicate(&self) -> io::Result<File> {
Err(Error::from_raw_os_error(22))
}
Expand Down
5 changes: 4 additions & 1 deletion library/std/src/sys/pal/solid/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,11 @@ impl File {
abi::SOLID_FS_Lseek(self.fd.raw(), pos, whence)
})
.map_err(|e| e.as_io_error())?;

// Get the new offset
self.tell()
}

pub fn tell(&self) -> io::Result<u64> {
unsafe {
let mut out_offset = MaybeUninit::uninit();
error::SolidError::err_if_negative(abi::SOLID_FS_Ftell(
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/uefi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ impl File {
self.0
}

pub fn tell(&self) -> io::Result<u64> {
self.0
}

pub fn duplicate(&self) -> io::Result<File> {
self.0
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,10 @@ impl File {
Ok(n as u64)
}

pub fn tell(&self) -> io::Result<u64> {
self.seek(SeekFrom::Current(0))
}

pub fn duplicate(&self) -> io::Result<File> {
self.0.duplicate().map(File)
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/unsupported/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ impl File {
self.0
}

pub fn tell(&self) -> io::Result<u64> {
self.0
}

pub fn duplicate(&self) -> io::Result<File> {
self.0
}
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/wasi/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ impl File {
self.fd.seek(pos)
}

pub fn tell(&self) -> io::Result<u64> {
self.fd.tell()
}

pub fn duplicate(&self) -> io::Result<File> {
// https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-rationale.md#why-no-dup
unsupported()
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ impl File {
Ok(newpos as u64)
}

pub fn tell(&self) -> io::Result<u64> {
self.seek(SeekFrom::Current(0))
}

pub fn duplicate(&self) -> io::Result<File> {
Ok(Self { handle: self.handle.try_clone()? })
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ pub fn rustc_cargo_env(

// Build jemalloc on AArch64 with support for page sizes up to 64K
// See: https://github.com/rust-lang/rust/pull/135081
if builder.config.jemalloc
if builder.config.jemalloc(target)
&& target.starts_with("aarch64")
&& env::var_os("JEMALLOC_SYS_WITH_LG_PAGE").is_none()
{
Expand Down
Loading

0 comments on commit de91711

Please sign in to comment.