1
Fork 0

Auto merge of #120089 - matthiaskrgr:rollup-xyfqrb5, r=matthiaskrgr

Rollup of 8 pull requests

Successful merges:

 - #119172 (Detect `NulInCStr` error earlier.)
 - #119833 (Make tcx optional from StableMIR run macro and extend it to accept closures)
 - #119967 (Add `PatKind::Err` to AST/HIR)
 - #119978 (Move async closure parameters into the resultant closure's future eagerly)
 - #120021 (don't store const var origins for known vars)
 - #120038 (Don't create a separate "basename" when naming and opening a MIR dump file)
 - #120057 (Don't ICE when deducing future output if other errors already occurred)
 - #120073 (Remove spastorino from users_on_vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2024-01-18 16:39:32 +00:00
commit 8424f8e8cd
75 changed files with 774 additions and 657 deletions

View file

@ -120,7 +120,7 @@ pub enum ConstVariableOriginKind {
#[derive(Copy, Clone, Debug)]
pub enum ConstVariableValue<'tcx> {
Known { value: ty::Const<'tcx> },
Unknown { universe: ty::UniverseIndex },
Unknown { origin: ConstVariableOrigin, universe: ty::UniverseIndex },
}
impl<'tcx> ConstVariableValue<'tcx> {
@ -134,12 +134,6 @@ impl<'tcx> ConstVariableValue<'tcx> {
}
}
#[derive(Copy, Clone, Debug)]
pub struct ConstVarValue<'tcx> {
pub origin: ConstVariableOrigin,
pub val: ConstVariableValue<'tcx>,
}
#[derive(PartialEq, Copy, Clone, Debug)]
pub struct ConstVidKey<'tcx> {
pub vid: ty::ConstVid,
@ -153,7 +147,7 @@ impl<'tcx> From<ty::ConstVid> for ConstVidKey<'tcx> {
}
impl<'tcx> UnifyKey for ConstVidKey<'tcx> {
type Value = ConstVarValue<'tcx>;
type Value = ConstVariableValue<'tcx>;
#[inline]
fn index(&self) -> u32 {
self.vid.as_u32()
@ -167,23 +161,23 @@ impl<'tcx> UnifyKey for ConstVidKey<'tcx> {
}
}
impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
impl<'tcx> UnifyValue for ConstVariableValue<'tcx> {
type Error = NoError;
fn unify_values(&value1: &Self, &value2: &Self) -> Result<Self, Self::Error> {
Ok(match (value1.val, value2.val) {
match (value1, value2) {
(ConstVariableValue::Known { .. }, ConstVariableValue::Known { .. }) => {
bug!("equating two const variables, both of which have known values")
}
// If one side is known, prefer that one.
(ConstVariableValue::Known { .. }, ConstVariableValue::Unknown { .. }) => value1,
(ConstVariableValue::Unknown { .. }, ConstVariableValue::Known { .. }) => value2,
(ConstVariableValue::Known { .. }, ConstVariableValue::Unknown { .. }) => Ok(value1),
(ConstVariableValue::Unknown { .. }, ConstVariableValue::Known { .. }) => Ok(value2),
// If both sides are *unknown*, it hardly matters, does it?
(
ConstVariableValue::Unknown { universe: universe1 },
ConstVariableValue::Unknown { universe: universe2 },
ConstVariableValue::Unknown { origin, universe: universe1 },
ConstVariableValue::Unknown { origin: _, universe: universe2 },
) => {
// If we unify two unbound variables, ?T and ?U, then whatever
// value they wind up taking (which must be the same value) must
@ -191,12 +185,9 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
// universe is the minimum of the two universes, because that is
// the one which contains the fewest names in scope.
let universe = cmp::min(universe1, universe2);
ConstVarValue {
val: ConstVariableValue::Unknown { universe },
origin: value1.origin,
}
Ok(ConstVariableValue::Unknown { origin, universe })
}
})
}
}
}

View file

@ -142,15 +142,17 @@ fn dump_matched_mir_node<'tcx, F>(
}
}
/// Returns the file basename portion (without extension) of a filename path
/// where we should dump a MIR representation output files.
fn dump_file_basename<'tcx>(
/// Returns the path to the filename where we should dump a given MIR.
/// Also used by other bits of code (e.g., NLL inference) that dump
/// graphviz data or other things.
fn dump_path<'tcx>(
tcx: TyCtxt<'tcx>,
extension: &str,
pass_num: bool,
pass_name: &str,
disambiguator: &dyn Display,
body: &Body<'tcx>,
) -> String {
) -> PathBuf {
let source = body.source;
let promotion_id = match source.promoted {
Some(id) => format!("-{id:?}"),
@ -186,45 +188,18 @@ fn dump_file_basename<'tcx>(
_ => String::new(),
};
format!(
"{crate_name}.{item_name}{shim_disambiguator}{promotion_id}{pass_num}.{pass_name}.{disambiguator}",
)
}
/// Returns the path to the filename where we should dump a given MIR.
/// Also used by other bits of code (e.g., NLL inference) that dump
/// graphviz data or other things.
fn dump_path(tcx: TyCtxt<'_>, basename: &str, extension: &str) -> PathBuf {
let mut file_path = PathBuf::new();
file_path.push(Path::new(&tcx.sess.opts.unstable_opts.dump_mir_dir));
let file_name = format!("{basename}.{extension}",);
let file_name = format!(
"{crate_name}.{item_name}{shim_disambiguator}{promotion_id}{pass_num}.{pass_name}.{disambiguator}.{extension}",
);
file_path.push(&file_name);
file_path
}
/// Attempts to open the MIR dump file with the given name and extension.
fn create_dump_file_with_basename(
tcx: TyCtxt<'_>,
file_basename: &str,
extension: &str,
) -> io::Result<io::BufWriter<fs::File>> {
let file_path = dump_path(tcx, file_basename, extension);
if let Some(parent) = file_path.parent() {
fs::create_dir_all(parent).map_err(|e| {
io::Error::new(
e.kind(),
format!("IO error creating MIR dump directory: {parent:?}; {e}"),
)
})?;
}
Ok(io::BufWriter::new(fs::File::create(&file_path).map_err(|e| {
io::Error::new(e.kind(), format!("IO error creating MIR dump file: {file_path:?}; {e}"))
})?))
}
/// Attempts to open a file where we should dump a given MIR or other
/// bit of MIR-related data. Used by `mir-dump`, but also by other
/// bits of code (e.g., NLL inference) that dump graphviz data or
@ -237,11 +212,18 @@ pub fn create_dump_file<'tcx>(
disambiguator: &dyn Display,
body: &Body<'tcx>,
) -> io::Result<io::BufWriter<fs::File>> {
create_dump_file_with_basename(
tcx,
&dump_file_basename(tcx, pass_num, pass_name, disambiguator, body),
extension,
)
let file_path = dump_path(tcx, extension, pass_num, pass_name, disambiguator, body);
if let Some(parent) = file_path.parent() {
fs::create_dir_all(parent).map_err(|e| {
io::Error::new(
e.kind(),
format!("IO error creating MIR dump directory: {parent:?}; {e}"),
)
})?;
}
Ok(io::BufWriter::new(fs::File::create(&file_path).map_err(|e| {
io::Error::new(e.kind(), format!("IO error creating MIR dump file: {file_path:?}; {e}"))
})?))
}
///////////////////////////////////////////////////////////////////////////