Skip to content

Commit

Permalink
Toolchain Upgrade to nightly 2024-12-15 (#171)
Browse files Browse the repository at this point in the history
## What Changed?

Bumps the rustc toolchain linked against from 2023-08-25 to 2024-12-15

## Why Does It Need To?

Better compatibility with newer rust projects

## Checklist

- [x] Above description has been filled out so that upon quash merge we
have a
  good record of what changed.
- [x] New functions, methods, types are documented. Old documentation is
updated
  if necessary
- [ ] Documentation in Notion has been updated
- [ ] Tests for new behaviors are provided
  - [ ] New test suites (if any) ave been added to the CI tests (in
`.github/workflows/rust.yml`) either as compiler test or integration
test.
*Or* justification for their omission from CI has been provided in this
PR
    description.
  • Loading branch information
JustusAdam authored Dec 26, 2024
1 parent 0a5c628 commit 7d5c521
Show file tree
Hide file tree
Showing 66 changed files with 1,214 additions and 1,131 deletions.
837 changes: 413 additions & 424 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,34 @@ exclude = [
resolver = "2"

[workspace.dependencies]
indexical = "0.3.1"
serde = "1.0.188"
indexical = "0.6.1"
serde = "1.0.216"
petgraph = { version = "0.6", features = ["serde-1"] }
strum = { version = "0.25", features = ["derive"] }
anyhow = { version = "1.0.72", features = ["backtrace"] }

rustc_utils = { version = "=0.7.4-nightly-2023-08-25", features = [
rustc_utils = { version = "=0.12.0-nightly-2024-12-15", features = [
"indexical",
] }
rustc_plugin = "=0.7.4-nightly-2023-08-25"
#flowistry = { path = "../flowistry/crates/flowistry", default-features = false }
rustc_plugin = "=0.12.0-nightly-2024-12-15"

[workspace.dependencies.flowistry]
# path = "../flowistry/crates/flowistry"
git = "https://github.com/brownsys/flowistry"
rev = "57627ed24802cb76c745118bbc46f83f402a1e88"
rev = "f271637d65a21a2785b87ef52ede8bdeb560948c"
default-features = false


[profile.release]
debug = true


[replace."rustc_utils:0.7.4-nightly-2023-08-25"]
[replace."rustc_utils:0.12.0-nightly-2024-12-15"]
# path = "../rustc_plugin/crates/rustc_utils"
git = "https://github.com/JustusAdam/rustc_plugin"
rev = "e413907b2ae9a03d2c8e9aca3b72dd451a16b1db"
rev = "901641910d536f00f1a6b6b2766778ac0a5bad64"

[replace."rustc_plugin:0.7.4-nightly-2023-08-25"]
[replace."rustc_plugin:0.12.0-nightly-2024-12-15"]
# path = "../rustc_plugin/crates/rustc_plugin"
git = "https://github.com/JustusAdam/rustc_plugin"
rev = "e413907b2ae9a03d2c8e9aca3b72dd451a16b1db"
rev = "901641910d536f00f1a6b6b2766778ac0a5bad64"
16 changes: 13 additions & 3 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ description = """\
This is bit ugly, because we want to reuse this tasks
- In different directories (controlled by the `FORMAT_WD` env variable)
- With different base comamnds (`cargo clippy` vs `cargo fmt`)
- With different base commands (`cargo clippy` vs `cargo fmt`)
- With different goals (check vs fix)
The last two are both done via the `FORMAT_ARGS` command.
Expand Down Expand Up @@ -175,6 +175,16 @@ run_task = "format-base"
[tasks.format-tests]
private = true
condition = { env_set = ["INCLUDE_TESTS"] }
env = { COMMAND = "cargo", COMMAND_ARGS = "${FORMAT_ARGS}" }
run_task = "run-for-tests"

[tasks.clean-tests]
env = { COMMAND = "cargo", COMMAND_ARGS = "clean" }
run_task = "run-for-tests"

[tasks.run-for-tests]
private = true
description = "A basic helper that lets you run a COMMAND with COMMAND_ARGS for each crate we use for tests"
script_runner = "@duckscript"
script = '''
wd = pwd
Expand All @@ -184,12 +194,12 @@ for dir in ${test_dirs}
cargo_toml_path = concat ${dir} /Cargo.toml
if is_path_exists ${cargo_toml_path}
cd ${dir}
exec --fail-on-error cargo %{FORMAT_ARGS}
exec --fail-on-error %{COMMAND} %{COMMAND_ARGS}
cd ${wd}
end
end
cd crates/paralegal-policy/tests/test-crate
exec cargo %{FORMAT_ARGS}
exec --fail-on-error %{COMMAND} %{COMMAND_ARGS}
'''

[tasks.populate-doc-dir]
Expand Down
5 changes: 3 additions & 2 deletions crates/flowistry_pdg_construction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ fluid-let = "1.0"
cfg-if = "1.0"
rustc_utils = { workspace = true, features = ["indexical"] }
indexical = { workspace = true }
itertools = "0.12.0"
itertools = "0.13.0"
petgraph = { version = "0.6.4" }
internment = { version = "0.7.4" }
internment = { version = "0.8.6" }
flowistry_pdg = { version = "0.1.0", path = "../flowistry_pdg", features = [
"rustc",
] }
#flowistry = { path = "../../../flowistry/crates/flowistry", default-features = false }
flowistry = { workspace = true }
serde = { workspace = true, features = ["derive"] }
strum = { workspace = true }
#rustc-hash = { version = "=2.1.0" }

[dev-dependencies]
rustc_utils = { workspace = true, features = ["indexical", "test"] }
Expand Down
14 changes: 7 additions & 7 deletions crates/flowistry_pdg_construction/src/approximation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use rustc_abi::VariantIdx;
use rustc_hir::def_id::DefId;
use rustc_index::IndexVec;
use rustc_middle::{
mir::{visit::Visitor, AggregateKind, Location, Operand, Place, Rvalue},
mir::{visit::Visitor, AggregateKind, Location, Place, Rvalue},
ty::TyKind,
};

use crate::local_analysis::LocalAnalysis;
use crate::{local_analysis::LocalAnalysis, utils::ArgSlice};

pub(crate) type ApproximationHandler<'tcx, 'a> =
fn(&LocalAnalysis<'tcx, 'a>, &mut dyn Visitor<'tcx>, &[Operand<'tcx>], Place<'tcx>, Location);
fn(&LocalAnalysis<'tcx, 'a>, &mut dyn Visitor<'tcx>, ArgSlice<'a, 'tcx>, Place<'tcx>, Location);

impl<'tcx, 'a> LocalAnalysis<'tcx, 'a> {
/// Special case behavior for calls to functions used in desugaring async functions.
Expand All @@ -38,21 +38,21 @@ impl<'tcx, 'a> LocalAnalysis<'tcx, 'a> {
fn approximate_into_future(
&self,
vis: &mut dyn Visitor<'tcx>,
args: &[Operand<'tcx>],
args: ArgSlice<'_, 'tcx>,
destination: Place<'tcx>,
location: Location,
) {
trace!("Handling into_future as assign for {destination:?}");
let [op] = args else {
unreachable!();
};
vis.visit_assign(&destination, &Rvalue::Use(op.clone()), location);
vis.visit_assign(&destination, &Rvalue::Use(op.node.clone()), location);
}

fn approximate_new_unchecked(
&self,
vis: &mut dyn Visitor<'tcx>,
args: &[Operand<'tcx>],
args: ArgSlice<'_, 'tcx>,
destination: Place<'tcx>,
location: Location,
) {
Expand All @@ -61,7 +61,7 @@ impl<'tcx, 'a> LocalAnalysis<'tcx, 'a> {
unreachable!();
};
let mut operands = IndexVec::new();
operands.push(op.clone());
operands.push(op.node.clone());
let TyKind::Adt(adt_id, generics) = destination.ty(&self.mono_body, self.tcx()).ty.kind()
else {
unreachable!()
Expand Down
41 changes: 23 additions & 18 deletions crates/flowistry_pdg_construction/src/async_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_middle::{
ty::{GenericArgsRef, Instance, TyCtxt},
};

use crate::utils::is_async;
use crate::utils::{is_async, ArgSlice};

use super::{
local_analysis::{CallKind, LocalAnalysis},
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn match_async_trait_assign<'tcx>(
match &statement.kind {
StatementKind::Assign(box (
_,
Rvalue::Aggregate(box AggregateKind::Generator(def_id, generic_args, _), _args),
Rvalue::Aggregate(box AggregateKind::Coroutine(def_id, generic_args), _args),
)) => Some((*def_id, *generic_args)),
_ => None,
}
Expand All @@ -112,7 +112,7 @@ pub fn is_async_trait_fn(tcx: TyCtxt, def_id: DefId, body: &Body<'_>) -> bool {
fn has_async_trait_signature(tcx: TyCtxt, def_id: DefId) -> bool {
if let Some(assoc_item) = tcx.opt_associated_item(def_id) {
let sig = tcx.fn_sig(def_id).skip_binder();
assoc_item.container == ty::AssocItemContainer::ImplContainer
assoc_item.container == ty::AssocItemContainer::Impl
&& assoc_item.trait_item_def_id.is_some()
&& match_pin_box_dyn_ty(tcx.lang_items(), sig.output().skip_binder())
} else {
Expand All @@ -132,10 +132,10 @@ fn match_pin_box_dyn_ty(lang_items: &rustc_hir::LanguageItems, t: ty::Ty) -> boo
let Some(t_a) = arg.as_type() else {
return false;
};
if !t_a.is_box() {
let Some(box_t) = t_a.boxed_ty() else {
return false;
};
let ty::TyKind::Dynamic(pred, _, ty::DynKind::Dyn) = t_a.boxed_ty().kind() else {
let ty::TyKind::Dynamic(pred, _, ty::DynKind::Dyn) = box_t.kind() else {
return false;
};
pred.iter().any(|p| {
Expand All @@ -157,7 +157,7 @@ fn get_async_generator<'tcx>(body: &Body<'tcx>) -> (DefId, GenericArgsRef<'tcx>,
.expect_left("Async fn should have a statement");
let StatementKind::Assign(box (
_,
Rvalue::Aggregate(box AggregateKind::Generator(def_id, generic_args, _), _args),
Rvalue::Aggregate(box AggregateKind::Coroutine(def_id, generic_args), _args),
)) = &stmt.kind
else {
panic!("Async fn should assign to a generator")
Expand All @@ -183,8 +183,8 @@ pub fn determine_async<'tcx>(
AsyncType::Trait,
)
};
let param_env = tcx.param_env_reveal_all_normalized(def_id);
let generator_fn = utils::try_resolve_function(tcx, generator_def_id, param_env, args)?;
let typing_env = body.typing_env(tcx).with_post_analysis_normalized(tcx);
let generator_fn = utils::try_resolve_function(tcx, generator_def_id, typing_env, args)?;
Some((generator_fn, loc, asyncness))
}

Expand All @@ -201,10 +201,10 @@ fn is_async_fn_or_block(tcx: TyCtxt, instance: Instance) -> bool {
// impl for an `async fn` or async block is the same as the `DefId` of the
// generator itself. That means after resolution (e.g. on the `Instance`) we
// only need to call `tcx.generator_is_async`.
tcx.generator_is_async(instance.def_id())
tcx.coroutine_is_async(instance.def_id())
}

impl<'tcx, 'mir> LocalAnalysis<'tcx, 'mir> {
impl<'tcx> LocalAnalysis<'tcx, '_> {
/// Checks whether the function call, described by the unresolved `def_id`
/// and the resolved instance `resolved_fn` is a call to [`<T as
/// Future>::poll`](std::future::Future::poll) where `T` is the type of an
Expand All @@ -215,7 +215,7 @@ impl<'tcx, 'mir> LocalAnalysis<'tcx, 'mir> {
&'a self,
def_id: DefId,
resolved_fn: Instance<'tcx>,
original_args: &'a [Operand<'tcx>],
original_args: ArgSlice<'a, 'tcx>,
) -> AsyncDeterminationResult<CallKind<'tcx>> {
let lang_items = self.tcx().lang_items();
if lang_items.future_poll_fn() == Some(def_id)
Expand All @@ -233,7 +233,7 @@ impl<'tcx, 'mir> LocalAnalysis<'tcx, 'mir> {
/// body to find the original future being polled, and get the arguments to the future.
fn find_async_args<'a>(
&'a self,
args: &'a [Operand<'tcx>],
args: ArgSlice<'a, 'tcx>,
) -> Result<AsyncFnPollEnv<'tcx>, String> {
macro_rules! let_assert {
($p:pat = $e:expr, $($arg:tt)*) => {
Expand Down Expand Up @@ -270,13 +270,16 @@ impl<'tcx, 'mir> LocalAnalysis<'tcx, 'mir> {
..
},
..
}) = &self.mono_body.stmt_at(get_def_for_op(&args[0])?),
}) = &self.mono_body.stmt_at(get_def_for_op(&args[0].node)?),
"Pinned assignment is not a call"
);
debug_assert!(new_pin_args.len() == 1);

let future_aliases = self
.aliases(self.tcx().mk_place_deref(new_pin_args[0].place().unwrap()))
.aliases(
self.tcx()
.mk_place_deref(new_pin_args[0].node.place().unwrap()),
)
.collect_vec();
debug_assert!(future_aliases.len() == 1);
let future = *future_aliases.first().unwrap();
Expand All @@ -301,7 +304,7 @@ impl<'tcx, 'mir> LocalAnalysis<'tcx, 'mir> {
);

let target = &into_future_args[0];
let creation_loc = get_def_for_op(target)?;
let creation_loc = get_def_for_op(&target.node)?;
let stmt = &self.mono_body.stmt_at(creation_loc);
let (op, generics, generator_data) = match stmt {
Either::Right(Terminator {
Expand All @@ -317,9 +320,9 @@ impl<'tcx, 'mir> LocalAnalysis<'tcx, 'mir> {
Either::Left(Statement { kind, .. }) => match kind {
StatementKind::Assign(box (
lhs,
Rvalue::Aggregate(box AggregateKind::Generator(def_id, generic_args, _), _args),
Rvalue::Aggregate(box AggregateKind::Coroutine(def_id, generic_args), _args),
)) => {
assert!(self.tcx().generator_is_async(*def_id));
assert!(self.tcx().coroutine_is_async(*def_id));
(None, *generic_args, *lhs)
}
StatementKind::Assign(box (_, Rvalue::Use(target))) => {
Expand All @@ -343,7 +346,9 @@ impl<'tcx, 'mir> LocalAnalysis<'tcx, 'mir> {
utils::try_resolve_function(
self.tcx(),
def_id,
self.tcx().param_env_reveal_all_normalized(self.def_id),
self.mono_body
.typing_env(self.tcx())
.with_post_analysis_normalized(self.tcx()),
generics,
)
.ok_or_else(|| "Instance resolution failed".to_string())
Expand Down
31 changes: 11 additions & 20 deletions crates/flowistry_pdg_construction/src/body_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rustc_middle::{
ty::TyCtxt,
};

use rustc_type_ir::RegionVid;
use rustc_utils::cache::Cache;

use crate::encoder::{decode_from_file, encode_to_file};
Expand All @@ -41,7 +42,7 @@ impl<'tcx> CachedBody<'tcx> {
let mut body_with_facts = rustc_borrowck::consumers::get_body_with_borrowck_facts(
tcx,
local_def_id,
ConsumerOptions::RegionInferenceContext,
ConsumerOptions::PoloniusInputFacts,
);

clean_undecodable_data_from_body(&mut body_with_facts.body);
Expand All @@ -50,9 +51,11 @@ impl<'tcx> CachedBody<'tcx> {
body: body_with_facts.body,
input_facts: FlowistryFacts {
subset_base: body_with_facts
.region_inference_context
.outlives_constraints()
.map(|constraint| (constraint.sup, constraint.sub))
.input_facts
.expect("polonius input must exist")
.subset_base
.iter()
.map(|&(v1, v2, _)| (v1.into(), v2.into()))
.collect(),
},
}
Expand All @@ -64,16 +67,7 @@ impl<'tcx> FlowistryInput<'tcx, 'tcx> for &'tcx CachedBody<'tcx> {
&self.body
}

fn input_facts_subset_base(
self,
) -> Box<
dyn Iterator<
Item = (
<RustcFacts as FactTypes>::Origin,
<RustcFacts as FactTypes>::Origin,
),
> + 'tcx,
> {
fn input_facts_subset_base(self) -> Box<dyn Iterator<Item = (RegionVid, RegionVid)> + 'tcx> {
Box::new(self.input_facts.subset_base.iter().copied())
}
}
Expand All @@ -82,10 +76,7 @@ impl<'tcx> FlowistryInput<'tcx, 'tcx> for &'tcx CachedBody<'tcx> {
/// needs.
#[derive(Debug, Encodable, Decodable)]
pub struct FlowistryFacts {
pub subset_base: Vec<(
<RustcFacts as FactTypes>::Origin,
<RustcFacts as FactTypes>::Origin,
)>,
pub subset_base: Vec<(RegionVid, RegionVid)>,
}

pub type LocationIndex = <RustcFacts as FactTypes>::Point;
Expand Down Expand Up @@ -122,15 +113,15 @@ impl<'tcx> BodyCache<'tcx> {
/// Returns `None` if the policy forbids loading from this crate.
pub fn get(&self, key: DefId) -> &'tcx CachedBody<'tcx> {
let body = if let Some(local) = key.as_local() {
self.local_cache.get(local.local_def_index, |_| {
self.local_cache.get(&local.local_def_index, |_| {
let start = Instant::now();
let res = CachedBody::retrieve(self.tcx, local);
*self.timer.borrow_mut() += start.elapsed();
res
})
} else {
self.cache
.get(key.krate, |_| load_body_and_facts(self.tcx, key.krate))
.get(&key.krate, |_| load_body_and_facts(self.tcx, key.krate))
.get(&key.index)
.expect("Invariant broken, body for this is should exist")
};
Expand Down
Loading

0 comments on commit 7d5c521

Please sign in to comment.