Skip to content

Commit

Permalink
Rename flow models to stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Sep 4, 2024
1 parent 04a2365 commit 98ecbb3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions crates/paralegal-flow/src/ana/inline_judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_type_ir::TyKind;
use crate::{
ana::Print,
ann::db::MarkerDatabase,
args::{FlowModel, InliningDepth},
args::{InliningDepth, Stub},
Args, MarkerCtx, TyCtxt,
};

Expand All @@ -37,7 +37,7 @@ pub enum InlineJudgement {
/// Construct a graph for the called function and merge it
Inline,
/// Use a flow model to abstract the call
UseFlowModel(&'static FlowModel),
UseFlowModel(&'static Stub),
/// Abstract the call via type signature
AbstractViaType(&'static str),
}
Expand Down
10 changes: 5 additions & 5 deletions crates/paralegal-flow/src/ana/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use crate::{
ann::{Annotation, MarkerAnnotation},
args::FlowModel,
args::Stub,
desc::*,
discover::FnToAnalyze,
stats::{Stats, TimedStat},
Expand Down Expand Up @@ -412,7 +412,7 @@ struct MyCallback<'tcx> {
tcx: TyCtxt<'tcx>,
}

impl FlowModel {
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,
Expand All @@ -428,7 +428,7 @@ impl FlowModel {
at: RustSpan,
) -> Result<(Instance<'tcx>, CallingConvention<'tcx>), ErrorGuaranteed> {
match self {
FlowModel::SubClosure { generic_name } | FlowModel::SubFuture { generic_name } => {
Stub::SubClosure { generic_name } | Stub::SubFuture { generic_name } => {
let name = Symbol::intern(generic_name);
let generics = tcx.generics_of(function.def_id());
let Some(param_index) = (0..generics.count()).find(|&idx| {
Expand All @@ -448,7 +448,7 @@ impl FlowModel {
.unwrap();

let expect_indirect = match self {
FlowModel::SubClosure { .. } => {
Stub::SubClosure { .. } => {
use rustc_hir::def::DefKind;
match tcx.def_kind(def_id) {
DefKind::Closure => true,
Expand All @@ -461,7 +461,7 @@ impl FlowModel {
}
}
}
FlowModel::SubFuture { .. } => {
Stub::SubFuture { .. } => {
assert!(tcx.generator_is_async(def_id));
true
}
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 @@ -12,7 +12,7 @@

use crate::{
ann::{Annotation, MarkerAnnotation},
args::{Args, FlowModel},
args::{Args, Stub},
utils::{
func_of_term, resolve::expect_resolve_string_to_def_id, FunctionKind, InstanceExt,
IntoDefId, TyExt,
Expand Down Expand Up @@ -494,7 +494,7 @@ impl<'tcx> MarkerCtx<'tcx> {
cache.keys().copied().collect::<Vec<_>>()
}

pub fn has_flow_model(&self, def_id: DefId) -> Option<&'static FlowModel> {
pub fn has_flow_model(&self, def_id: DefId) -> Option<&'static Stub> {
[def_id]
.into_iter()
.chain(
Expand Down Expand Up @@ -566,7 +566,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 FlowModel>,
flow_models: FxHashMap<DefId, &'static Stub>,
}

impl<'tcx> MarkerDatabase<'tcx> {
Expand All @@ -579,7 +579,7 @@ impl<'tcx> MarkerDatabase<'tcx> {
) -> Self {
let flow_models = args
.build_config()
.flow_models
.stubs
.iter()
.filter_map(|(k, v)| {
let res = expect_resolve_string_to_def_id(tcx, k, args.relaxed());
Expand Down
4 changes: 2 additions & 2 deletions crates/paralegal-flow/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ pub struct DepConfig {

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[serde(tag = "mode", rename_all = "kebab-case")]
pub enum FlowModel {
pub enum Stub {
#[serde(rename_all = "kebab-case")]
/// Replaces the result of a call to a higher-order function with a call to
/// the input closure.
Expand All @@ -601,5 +601,5 @@ pub struct BuildConfig {
#[serde(default)]
pub include: Vec<String>,
#[serde(default)]
pub flow_models: HashMap<String, FlowModel>,
pub stubs: HashMap<String, Stub>,
}
6 changes: 3 additions & 3 deletions crates/paralegal-flow/tests/flow-models/Paralegal.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
rust-features = ["saturating_int_impl"]


[flow-models."std::thread::spawn"]
[stubs."std::thread::spawn"]
mode = "sub-closure"
generic-name = "F"

[flow-models."tokio::spawn"]
[stubs."tokio::spawn"]
mode = "sub-future"
generic-name = "F"

[flow-models."actix_web::web::block"]
[stubs."actix_web::web::block"]
mode = "sub-closure"
generic-name = "F"

0 comments on commit 98ecbb3

Please sign in to comment.