pub struct L2Context {
pub project: PathBuf,
pub language: Language,
pub changed_files: Vec<PathBuf>,
pub function_diff: FunctionDiff,
pub baseline_contents: HashMap<PathBuf, String>,
pub current_contents: HashMap<PathBuf, String>,
pub ast_changes: HashMap<PathBuf, Vec<ASTChange>>,
pub is_first_run: bool,
pub base_ref: String,
/* private fields */
}Expand description
Shared context for all L2 analysis engines.
Carries the project root, detected language, lists of changed/inserted/deleted functions, and the full file contents for both revisions. Includes lazy-initialized DashMap caches for per-function CFG, DFG, SSA, and contracts data, plus OnceLock-backed project-level call graph and change impact report.
The daemon client routes IR queries through the daemon’s QueryCache when available, falling back to on-the-fly construction via the local caches.
Fields§
§project: PathBufAbsolute path to the project root.
language: LanguageDetected (or user-specified) programming language.
changed_files: Vec<PathBuf>Files that have changes between baseline and current.
function_diff: FunctionDiffFunction-level diff between baseline and current revisions.
baseline_contents: HashMap<PathBuf, String>Full file contents for the baseline revision, keyed by path.
current_contents: HashMap<PathBuf, String>Full file contents for the current revision, keyed by path.
ast_changes: HashMap<PathBuf, Vec<ASTChange>>AST-level changes per file from the diff phase.
Maps each changed file to its list of ASTChange entries (Insert, Update,
Delete). Used by DeltaEngine for finding extractors that need node-level
diff data (e.g., param-renamed, signature-regression).
is_first_run: boolWhether this is the first run (no prior .bugbot/state.db).
When true, delta engines that require prior state (guard-removed, contract-regression) should suppress their findings because there is no baseline to compare against (PM-34 baseline policy).
base_ref: StringGit base reference for baseline comparison (e.g. “HEAD”, “main”). Used by flow engines to create baseline worktrees for project-wide diffing.
Implementations§
Source§impl L2Context
impl L2Context
Sourcepub fn new(
project: PathBuf,
language: Language,
changed_files: Vec<PathBuf>,
function_diff: FunctionDiff,
baseline_contents: HashMap<PathBuf, String>,
current_contents: HashMap<PathBuf, String>,
ast_changes: HashMap<PathBuf, Vec<ASTChange>>,
) -> Self
pub fn new( project: PathBuf, language: Language, changed_files: Vec<PathBuf>, function_diff: FunctionDiff, baseline_contents: HashMap<PathBuf, String>, current_contents: HashMap<PathBuf, String>, ast_changes: HashMap<PathBuf, Vec<ASTChange>>, ) -> Self
Create a new L2Context with the provided data.
All cache fields (CFG, DFG, SSA, contracts, call graph, change impact)
are initialized empty and populated lazily on first access. The daemon
client defaults to NoDaemon (local-only computation).
Sourcepub fn with_first_run(self, is_first_run: bool) -> Self
pub fn with_first_run(self, is_first_run: bool) -> Self
Set whether this context represents a first-run analysis.
When is_first_run is true, delta engines that require prior state
(guard-removed, contract-regression) suppress their findings because
there is no baseline to compare against (PM-34 baseline policy).
Sourcepub fn with_base_ref(self, base_ref: String) -> Self
pub fn with_base_ref(self, base_ref: String) -> Self
Set the git base reference for baseline comparison.
Used by flow engines (e.g. TldrDifferentialEngine) to create baseline worktrees for project-wide diffing of call graphs, dependencies, coupling, and cohesion.
Sourcepub fn with_daemon(self, daemon: Box<dyn DaemonClient>) -> Self
pub fn with_daemon(self, daemon: Box<dyn DaemonClient>) -> Self
Attach a daemon client to this context.
When the daemon client reports is_available() == true, IR cache
methods (cfg_for, dfg_for, ssa_for, call_graph) will check the daemon
first before falling back to local computation. The daemon is also
notified of changed_files for cache invalidation.
Sourcepub fn daemon_available(&self) -> bool
pub fn daemon_available(&self) -> bool
Check whether a daemon is available for this context.
Sourcepub fn daemon(&self) -> &dyn DaemonClient
pub fn daemon(&self) -> &dyn DaemonClient
Get a reference to the daemon client.
Sourcepub fn changed_functions(&self) -> &[FunctionChange]
pub fn changed_functions(&self) -> &[FunctionChange]
Convenience accessor: functions whose bodies changed between revisions.
Sourcepub fn inserted_functions(&self) -> &[InsertedFunction]
pub fn inserted_functions(&self) -> &[InsertedFunction]
Convenience accessor: functions present in current but not in baseline.
Sourcepub fn deleted_functions(&self) -> &[DeletedFunction]
pub fn deleted_functions(&self) -> &[DeletedFunction]
Convenience accessor: functions present in baseline but not in current.
Sourcepub fn cfg_for(
&self,
file_contents: &str,
function_id: &FunctionId,
language: Language,
) -> Result<Ref<'_, FunctionId, CfgInfo>>
pub fn cfg_for( &self, file_contents: &str, function_id: &FunctionId, language: Language, ) -> Result<Ref<'_, FunctionId, CfgInfo>>
Get or build the CFG for a function.
Checks the local cache first, then queries the daemon if available.
On miss, builds via ir::build_cfg_for_function() and stores the result.
Sourcepub fn dfg_for(
&self,
file_contents: &str,
function_id: &FunctionId,
language: Language,
) -> Result<Ref<'_, FunctionId, DfgInfo>>
pub fn dfg_for( &self, file_contents: &str, function_id: &FunctionId, language: Language, ) -> Result<Ref<'_, FunctionId, DfgInfo>>
Get or build the DFG for a function.
Checks the local cache first, then queries the daemon if available.
On miss, builds via ir::build_dfg_for_function() and stores the result.
Sourcepub fn ssa_for(
&self,
file_contents: &str,
function_id: &FunctionId,
language: Language,
) -> Result<Ref<'_, FunctionId, SsaFunction>>
pub fn ssa_for( &self, file_contents: &str, function_id: &FunctionId, language: Language, ) -> Result<Ref<'_, FunctionId, SsaFunction>>
Get or build the SSA for a function.
Checks the local cache first, then queries the daemon if available.
On miss, builds via ir::build_ssa_for_function() and stores the result.
Sourcepub fn contracts_for(
&self,
function_id: &FunctionId,
version: ContractVersion,
build_fn: impl FnOnce() -> Result<ContractsReport>,
) -> Result<Ref<'_, (FunctionId, ContractVersion), ContractsReport>>
pub fn contracts_for( &self, function_id: &FunctionId, version: ContractVersion, build_fn: impl FnOnce() -> Result<ContractsReport>, ) -> Result<Ref<'_, (FunctionId, ContractVersion), ContractsReport>>
Get or insert a contracts report for a (function, version) pair.
Checks the cache first; on miss, calls build_fn to produce the report
and stores it.
Sourcepub fn call_graph(&self) -> Option<&ProjectCallGraph>
pub fn call_graph(&self) -> Option<&ProjectCallGraph>
Get the cached call graph, if available.
Checks the local OnceLock cache first. If empty and a daemon is available, queries the daemon for a cached call graph and stores it locally for subsequent accesses.
Sourcepub fn set_call_graph(
&self,
cg: ProjectCallGraph,
) -> Result<(), ProjectCallGraph>
pub fn set_call_graph( &self, cg: ProjectCallGraph, ) -> Result<(), ProjectCallGraph>
Set the call graph (can only be set once).
Sourcepub fn change_impact(&self) -> Option<&ChangeImpactReport>
pub fn change_impact(&self) -> Option<&ChangeImpactReport>
Get the cached change impact report, if available.
Sourcepub fn set_change_impact(
&self,
report: ChangeImpactReport,
) -> Result<(), Box<ChangeImpactReport>>
pub fn set_change_impact( &self, report: ChangeImpactReport, ) -> Result<(), Box<ChangeImpactReport>>
Set the change impact report (can only be set once).
Returns Err with the boxed report if the value was already set.
Auto Trait Implementations§
impl !Freeze for L2Context
impl !RefUnwindSafe for L2Context
impl Send for L2Context
impl Sync for L2Context
impl Unpin for L2Context
impl UnsafeUnpin for L2Context
impl !UnwindSafe for L2Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.