Skip to content
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

Update to nightly-2024-01-06 #16

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion crates/rustc_plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustc_plugin"
version = "0.7.4-nightly-2023-08-25"
version = "0.8.0-nightly-2023-12-04"
edition = "2021"
authors = ["Will Crichton <[email protected]>"]
description = "A framework for writing plugins that integrate with the Rust compiler"
Expand Down
1 change: 0 additions & 1 deletion crates/rustc_plugin/examples/print-all-items/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ impl rustc_driver::Callbacks for PrintAllItemsCallbacks {
// all the type-checking has completed.
fn after_analysis<'tcx>(
&mut self,
_handler: &rustc_session::EarlyErrorHandler,
_compiler: &rustc_interface::interface::Compiler,
queries: &'tcx rustc_interface::Queries<'tcx>,
) -> rustc_driver::Compilation {
Expand Down
6 changes: 3 additions & 3 deletions crates/rustc_plugin/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
process::{exit, Command},
};

use rustc_session::{config::ErrorOutputType, EarlyErrorHandler};
use rustc_session::{config::ErrorOutputType, EarlyDiagCtxt};
use rustc_tools_util::VersionInfo;

use super::plugin::{RustcPlugin, PLUGIN_ARGS};
Expand Down Expand Up @@ -100,8 +100,8 @@ impl rustc_driver::Callbacks for DefaultCallbacks {}

/// The top-level function that should be called by your internal driver binary.
pub fn driver_main<T: RustcPlugin>(plugin: T) {
let handler = EarlyErrorHandler::new(ErrorOutputType::default());
rustc_driver::init_rustc_env_logger(&handler);
let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
rustc_driver::init_rustc_env_logger(&early_dcx);

exit(rustc_driver::catch_with_exit_code(move || {
let mut orig_args: Vec<String> = env::args().collect();
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustc_utils"
version = "0.7.4-nightly-2023-08-25"
version = "0.8.0-nightly-2023-12-04"
edition = "2021"
authors = ["Will Crichton <[email protected]>"]
description = "Utilities for working with the Rust compiler"
Expand Down
1 change: 0 additions & 1 deletion crates/rustc_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ extern crate rustc_index;
extern crate rustc_infer;
extern crate rustc_interface;
extern crate rustc_macros;
#[macro_use]
extern crate rustc_middle;
extern crate rustc_mir_dataflow;
extern crate rustc_mir_transform;
Expand Down
53 changes: 5 additions & 48 deletions crates/rustc_utils/src/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ use std::{
};

use anyhow::{ensure, Result};
use cfg_if::cfg_if;
use rustc_data_structures::{captures::Captures, fx::FxHashMap as HashMap};
use rustc_hir::{def_id::DefId, GeneratorKind, HirId};
use rustc_hir::{def_id::DefId, CoroutineDesugaring, CoroutineKind, HirId};
use rustc_middle::{
mir::{pretty::write_mir_fn, *},
ty::{Region, Ty, TyCtxt},
};
use rustc_mir_dataflow::{fmt::DebugWithContext, Analysis, Results};
use smallvec::SmallVec;

use super::control_dependencies::ControlDependencies;
Expand Down Expand Up @@ -83,18 +81,6 @@ pub trait BodyExt<'tcx> {

/// Returns an iterator over all the regions that appear in the body's return type.
fn regions_in_return(&self) -> Self::ReturnRegionsIter;

/// Visualizes analysis results using graphviz/dot and writes them to
/// a file in the `target/` directory named `<function name>.pdf`.
fn write_analysis_results<A>(
&self,
results: &mut Results<'tcx, A>,
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> Result<()>
where
A: Analysis<'tcx>,
A::Domain: DebugWithContext<A>;
}

impl<'tcx> BodyExt<'tcx> for Body<'tcx> {
Expand Down Expand Up @@ -170,7 +156,10 @@ impl<'tcx> BodyExt<'tcx> for Body<'tcx> {
}

fn async_context(&self, tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Ty<'tcx>> {
if matches!(tcx.generator_kind(def_id), Some(GeneratorKind::Async(..))) {
if matches!(
tcx.coroutine_kind(def_id),
Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, _))
) {
Some(self.local_decls[Local::from_usize(2)].ty)
} else {
None
Expand Down Expand Up @@ -204,38 +193,6 @@ impl<'tcx> BodyExt<'tcx> for Body<'tcx> {
Place::from_local(local, tcx).interior_paths(tcx, self, def_id)
})
}

#[allow(unused)]
fn write_analysis_results<A>(
&self,
results: &mut Results<'tcx, A>,
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> Result<()>
where
A: Analysis<'tcx>,
A::Domain: DebugWithContext<A>,
{
cfg_if! {
if #[cfg(feature = "graphviz")] {
use rustc_graphviz as dot;
use rustc_mir_dataflow::graphviz;

let graphviz =
graphviz::Formatter::new(self, results, graphviz::OutputStyle::AfterOnly);
let mut buf = Vec::new();
dot::render(&graphviz, &mut buf)?;

let output_dir = Path::new("target");
let fname = tcx.def_path_debug_str(def_id);
let output_path = output_dir.join(format!("{fname}.pdf"));

run_dot(&output_path, buf)
} else {
anyhow::bail!("graphviz feature is not enabled")
}
}
}
}

pub fn run_dot(path: &Path, buf: Vec<u8>) -> Result<()> {
Expand Down
8 changes: 2 additions & 6 deletions crates/rustc_utils/src/mir/borrowck_facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use rustc_data_structures::fx::FxHashSet as HashSet;
use rustc_hir::def_id::LocalDefId;
use rustc_middle::{
mir::{Body, BorrowCheckResult, MirPass, StatementKind, TerminatorKind},
query::{ExternProviders, Providers},
ty::TyCtxt,
util::Providers,
};

use crate::{block_timer, cache::Cache, BodyExt};
Expand Down Expand Up @@ -65,11 +65,7 @@ pub fn enable_mir_simplification() {
///
/// For why we need to do override mir_borrowck, see:
/// <https://github.com/rust-lang/rust/blob/485ced56b8753ec86936903f2a8c95e9be8996a1/src/test/run-make-fulldeps/obtain-borrowck/driver.rs>
pub fn override_queries(
_session: &rustc_session::Session,
local: &mut Providers,
_external: &mut ExternProviders,
) {
pub fn override_queries(_session: &rustc_session::Session, local: &mut Providers) {
local.mir_borrowck = mir_borrowck;
}

Expand Down
31 changes: 19 additions & 12 deletions crates/rustc_utils/src/mir/control_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

use std::fmt;

use rustc_data_structures::graph::{
dominators::{Dominators, Iter as DominatorsIter},
vec_graph::VecGraph,
*,
};
use rustc_data_structures::graph::{dominators::Dominators, vec_graph::VecGraph, *};
use rustc_index::{
bit_set::{BitSet, HybridBitSet, SparseBitMatrix},
Idx,
Expand Down Expand Up @@ -77,15 +73,19 @@ impl<G: ControlFlowGraph> WithPredecessors for ReversedGraph<'_, G> {
}

/// Represents the post-dominators of a graph's nodes with respect to a particular exit.
pub struct PostDominators<Node: Idx>(Dominators<Node>);
pub struct PostDominators<Node: Idx> {
dominators: Dominators<Node>,
num_nodes: usize,
}

impl<Node: Idx> PostDominators<Node> {
/// Constructs the post-dominators by computing the dominators on a reversed graph.
pub fn build<G: ControlFlowGraph<Node = Node>>(graph: &G, exit: Node) -> Self {
let num_nodes = graph.num_nodes();
let mut reversed = ReversedGraph {
graph,
exit,
unreachable: BitSet::new_empty(graph.num_nodes()),
unreachable: BitSet::new_empty(num_nodes),
};

let reachable = iterate::post_order_from(&reversed, exit);
Expand All @@ -95,18 +95,25 @@ impl<Node: Idx> PostDominators<Node> {
}

let dominators = dominators::dominators(&reversed);
PostDominators::<Node>(dominators)
PostDominators {
dominators,
num_nodes,
}
}

/// Gets the node that immediately post-dominators `node`, if one exists.
pub fn immediate_post_dominator(&self, node: Node) -> Option<Node> {
self.0.immediate_dominator(node)
self.dominators.immediate_dominator(node)
}

/// Gets all nodes that post-dominate `node`, if they exist.
pub fn post_dominators(&self, node: Node) -> Option<DominatorsIter<'_, Node>> {
let reachable = self.0.is_reachable(node);
reachable.then(|| self.0.dominators(node))
pub fn post_dominators(&self, node: Node) -> Option<impl Iterator<Item = Node> + '_> {
let reachable = self.dominators.is_reachable(node);
reachable.then(move || {
(0 .. self.num_nodes)
.map(Node::new)
.filter(move |other| self.dominators.dominates(*other, node))
})
}
}

Expand Down
3 changes: 0 additions & 3 deletions crates/rustc_utils/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ pub mod location_or_arg;
pub mod mutability;
pub mod operand;
pub mod place;

#[allow(clippy::all, clippy::pedantic)]
pub mod places_conflict;
4 changes: 2 additions & 2 deletions crates/rustc_utils/src/mir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CollectRegions<'tcx> {
StoppingCondition::BeforeRefs => {}
},

TyKind::Closure(_, substs) | TyKind::Generator(_, substs, _) => {
TyKind::Closure(_, substs) | TyKind::Coroutine(_, substs) => {
self.visit_ty(substs.as_closure().tupled_upvars_ty());
}

Expand Down Expand Up @@ -595,7 +595,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CollectRegions<'tcx> {
let region = match region.kind() {
RegionKind::ReVar(region) => region,
RegionKind::ReStatic => RegionVid::from_usize(0),
RegionKind::ReErased | RegionKind::ReLateBound(_, _) => {
RegionKind::ReErased | RegionKind::ReLateParam(_) => {
return ControlFlow::Continue(());
}
_ => unreachable!("{:?}: {:?}", self.ty_stack.first().unwrap(), region),
Expand Down
Loading
Loading