Skip to content

Commit

Permalink
flow-model -> stub
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Sep 9, 2024
1 parent c9707f4 commit 6683ad3
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 24 deletions.
19 changes: 5 additions & 14 deletions crates/paralegal-flow/src/ana/inline_judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions crates/paralegal-flow/src/ana/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ fn src_loc_for_span(span: RustSpan, tcx: TyCtxt) -> Span {
fn default_index() -> <SPDGImpl as GraphBase>::NodeId {
<SPDGImpl as GraphBase>::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`].
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions crates/paralegal-flow/src/ann/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -579,7 +579,7 @@ pub struct MarkerDatabase<'tcx> {
type_markers: Cache<ty::Ty<'tcx>, Box<TypeMarkers>>,
body_cache: Rc<BodyCache<'tcx>>,
included_crates: FxHashSet<CrateNum>,
flow_models: FxHashMap<DefId, &'static Stub>,
stubs: FxHashMap<DefId, &'static Stub>,
}

impl<'tcx> MarkerDatabase<'tcx> {
Expand All @@ -590,7 +590,7 @@ impl<'tcx> MarkerDatabase<'tcx> {
body_cache: Rc<BodyCache<'tcx>>,
included_crates: FxHashSet<CrateNum>,
) -> Self {
let flow_models = args
let stubs = args
.build_config()
.stubs
.iter()
Expand All @@ -609,7 +609,7 @@ impl<'tcx> MarkerDatabase<'tcx> {
type_markers: Default::default(),
body_cache,
included_crates,
flow_models,
stubs,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "flow-model-tests"
name = "stub-tests"
version = "0.1.0"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6683ad3

Please sign in to comment.