From 6683ad35de8cb235dcfad95d853fdc44266094ae Mon Sep 17 00:00:00 2001 From: Justus Adam Date: Mon, 9 Sep 2024 08:37:22 -0700 Subject: [PATCH] flow-model -> stub --- crates/paralegal-flow/src/ana/inline_judge.rs | 19 +++++-------------- crates/paralegal-flow/src/ana/mod.rs | 6 ++++-- crates/paralegal-flow/src/ann/db.rs | 8 ++++---- .../tests/{flow-models.rs => stub-tests.rs} | 4 ++-- .../{flow-models => stub-tests}/Cargo.lock | 0 .../{flow-models => stub-tests}/Cargo.toml | 2 +- .../Paralegal.toml | 0 .../{flow-models => stub-tests}/src/main.rs | 2 +- 8 files changed, 17 insertions(+), 24 deletions(-) rename crates/paralegal-flow/tests/{flow-models.rs => stub-tests.rs} (95%) rename crates/paralegal-flow/tests/{flow-models => stub-tests}/Cargo.lock (100%) rename crates/paralegal-flow/tests/{flow-models => stub-tests}/Cargo.toml (91%) rename crates/paralegal-flow/tests/{flow-models => stub-tests}/Paralegal.toml (100%) rename crates/paralegal-flow/tests/{flow-models => stub-tests}/src/main.rs (97%) diff --git a/crates/paralegal-flow/src/ana/inline_judge.rs b/crates/paralegal-flow/src/ana/inline_judge.rs index 72ebf94998..a6d8bac233 100644 --- a/crates/paralegal-flow/src/ana/inline_judge.rs +++ b/crates/paralegal-flow/src/ana/inline_judge.rs @@ -36,8 +36,8 @@ pub struct InlineJudge<'tcx> { pub enum InlineJudgement { /// Construct a graph for the called function and merge it Inline, - /// Use a flow model to abstract the call - UseFlowModel(&'static Stub), + /// Use a stub instead of the call + UseStub(&'static Stub), /// Abstract the call via type signature AbstractViaType(&'static str), } @@ -84,16 +84,14 @@ impl<'tcx> InlineJudge<'tcx> { // // I tried to have it replace the poll call only but that didn't seem to work. return if info.async_parent.is_some() { - InlineJudgement::AbstractViaType("async parent of flow model") + InlineJudgement::AbstractViaType("async parent of stub") } else { - InlineJudgement::UseFlowModel(model) + InlineJudgement::UseStub(model) }; } let is_marked = self.marker_ctx.is_marked(marker_target_def_id); let judgement = match self.opts.anactrl().inlining_depth() { - _ if !self.included_crates.contains(&marker_target_def_id.krate) - && !self.is_exception(marker_target_def_id) => - { + _ if !self.included_crates.contains(&marker_target_def_id.krate) => { InlineJudgement::AbstractViaType("inlining for crate disabled") } _ if is_marked => InlineJudgement::AbstractViaType("marked"), @@ -123,13 +121,6 @@ impl<'tcx> InlineJudge<'tcx> { judgement } - fn is_exception(&self, def_id: DefId) -> bool { - if let Some(parent) = self.tcx.trait_of_item(def_id) { - return self.tcx.is_fn_trait(parent); - } - false - } - pub fn marker_ctx(&self) -> &MarkerCtx<'tcx> { &self.marker_ctx } diff --git a/crates/paralegal-flow/src/ana/mod.rs b/crates/paralegal-flow/src/ana/mod.rs index d6f39db3fb..a34b7ed6c5 100644 --- a/crates/paralegal-flow/src/ana/mod.rs +++ b/crates/paralegal-flow/src/ana/mod.rs @@ -333,6 +333,7 @@ fn src_loc_for_span(span: RustSpan, tcx: TyCtxt) -> Span { fn default_index() -> ::NodeId { ::NodeId::end() } + /// Checks the invariant that [`SPDGGenerator::collect_type_info`] should /// produce a map that is a superset of the types found in all the `types` maps /// on [`SPDG`]. @@ -348,6 +349,7 @@ fn type_info_sanity_check(controllers: &ControllerMap, types: &TypeInfoMap) { ); }) } + fn def_kind_for_item(id: DefId, tcx: TyCtxt) -> DefKind { match tcx.def_kind(id) { def::DefKind::Closure => DefKind::Closure, @@ -473,7 +475,7 @@ impl Stub { /// Performs the effects of this model on the provided function. /// - /// `function` is what was to be called but for which a flow model exists, + /// `function` is what was to be called but for which a stub exists, /// `arguments` are the arguments to that call. /// /// Returns a new instance to call instead and how it should be called. @@ -531,7 +533,7 @@ impl<'tcx> CallChangeCallback<'tcx> for MyCallback<'tcx> { let skip = match self.judge.should_inline(&info) { InlineJudgement::AbstractViaType(_) => SkipCall::Skip, - InlineJudgement::UseFlowModel(model) => { + InlineJudgement::UseStub(model) => { if let Ok((instance, calling_convention)) = model.apply( self.tcx, info.callee, diff --git a/crates/paralegal-flow/src/ann/db.rs b/crates/paralegal-flow/src/ann/db.rs index 1d25ae7ed6..440f7aff70 100644 --- a/crates/paralegal-flow/src/ann/db.rs +++ b/crates/paralegal-flow/src/ann/db.rs @@ -515,7 +515,7 @@ impl<'tcx> MarkerCtx<'tcx> { .then(|| self.tcx().associated_item(def_id).trait_item_def_id) .flatten(), ) - .find_map(|def_id| self.0.flow_models.get(&def_id)) + .find_map(|def_id| self.0.stubs.get(&def_id)) .copied() } } @@ -579,7 +579,7 @@ pub struct MarkerDatabase<'tcx> { type_markers: Cache, Box>, body_cache: Rc>, included_crates: FxHashSet, - flow_models: FxHashMap, + stubs: FxHashMap, } impl<'tcx> MarkerDatabase<'tcx> { @@ -590,7 +590,7 @@ impl<'tcx> MarkerDatabase<'tcx> { body_cache: Rc>, included_crates: FxHashSet, ) -> Self { - let flow_models = args + let stubs = args .build_config() .stubs .iter() @@ -609,7 +609,7 @@ impl<'tcx> MarkerDatabase<'tcx> { type_markers: Default::default(), body_cache, included_crates, - flow_models, + stubs, } } } diff --git a/crates/paralegal-flow/tests/flow-models.rs b/crates/paralegal-flow/tests/stub-tests.rs similarity index 95% rename from crates/paralegal-flow/tests/flow-models.rs rename to crates/paralegal-flow/tests/stub-tests.rs index a15f2af319..ab5577a225 100644 --- a/crates/paralegal-flow/tests/flow-models.rs +++ b/crates/paralegal-flow/tests/stub-tests.rs @@ -11,7 +11,7 @@ extern crate lazy_static; use paralegal_flow::{define_flow_test_template, test_utils::*}; use paralegal_spdg::Identifier; -const TEST_CRATE_NAME: &str = "tests/flow-models"; +const TEST_CRATE_NAME: &str = "tests/stub-tests"; lazy_static! { static ref TEST_CRATE_ANALYZED: bool = run_paralegal_flow_with_flow_graph_dump(TEST_CRATE_NAME); @@ -63,7 +63,7 @@ define_test!(block_fn: graph -> { simple_source_target_flow(graph) }); -define_test!(test_blocking: graph -> { +define_test!(test_blocking_with_let_bound_closure: graph -> { simple_source_target_flow(graph) }); diff --git a/crates/paralegal-flow/tests/flow-models/Cargo.lock b/crates/paralegal-flow/tests/stub-tests/Cargo.lock similarity index 100% rename from crates/paralegal-flow/tests/flow-models/Cargo.lock rename to crates/paralegal-flow/tests/stub-tests/Cargo.lock diff --git a/crates/paralegal-flow/tests/flow-models/Cargo.toml b/crates/paralegal-flow/tests/stub-tests/Cargo.toml similarity index 91% rename from crates/paralegal-flow/tests/flow-models/Cargo.toml rename to crates/paralegal-flow/tests/stub-tests/Cargo.toml index 1d51edf813..6f190b36c8 100644 --- a/crates/paralegal-flow/tests/flow-models/Cargo.toml +++ b/crates/paralegal-flow/tests/stub-tests/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "flow-model-tests" +name = "stub-tests" version = "0.1.0" edition = "2021" diff --git a/crates/paralegal-flow/tests/flow-models/Paralegal.toml b/crates/paralegal-flow/tests/stub-tests/Paralegal.toml similarity index 100% rename from crates/paralegal-flow/tests/flow-models/Paralegal.toml rename to crates/paralegal-flow/tests/stub-tests/Paralegal.toml diff --git a/crates/paralegal-flow/tests/flow-models/src/main.rs b/crates/paralegal-flow/tests/stub-tests/src/main.rs similarity index 97% rename from crates/paralegal-flow/tests/flow-models/src/main.rs rename to crates/paralegal-flow/tests/stub-tests/src/main.rs index cd30ebd16b..6e7a0e5320 100644 --- a/crates/paralegal-flow/tests/flow-models/src/main.rs +++ b/crates/paralegal-flow/tests/stub-tests/src/main.rs @@ -55,7 +55,7 @@ where } #[paralegal::analyze] -async fn test_blocking(to_close_over: &str) { +async fn test_blocking_with_let_bound_closure(to_close_over: &str) { let from_scope = 10; let the_closure = move |u| u + source() + from_scope; target(blocking(to_close_over, the_closure).await);