Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
401cec5
Model std::move and std::forward in C++ lowering (#293)
IvanTrofimov052 Nov 23, 2026
d08a2b4
Address C++ move and forward review findings
IvanTrofimov052 Nov 25, 2026
3680196
Preserve move viability and allocator overload bindings
IvanTrofimov052 Nov 25, 2026
7d7c581
Bind allocation returns to their call occurrence
IvanTrofimov052 Nov 25, 2026
bec18ac
Keep ADL allocator targets and volatile copy fallbacks
IvanTrofimov052 Nov 25, 2026
08b72fe
Preserve allocator ADL returns and volatile alias construction
IvanTrofimov052 Nov 25, 2026
5fa3a72
Preserve allocator return bindings and copy fallback
IvanTrofimov052 Nov 25, 2026
04d7602
Bind file-scope allocator arguments and cast types
IvanTrofimov052 Nov 26, 2026
f5be000
Bind file-scope initializer formals after parameter packs
IvanTrofimov052 Nov 26, 2026
3c3ce3a
Lower file-scope arguments against pack-aligned formals
IvanTrofimov052 Nov 26, 2026
e542c9d
Align file-scope arguments exactly for proven empty packs
IvanTrofimov052 Nov 26, 2026
4645a75
Filter file-scope allocator template candidates before ranking
IvanTrofimov052 Nov 26, 2026
40a59dc
Keep allocator template targets and explicit specializations
IvanTrofimov052 Nov 26, 2026
3aa83bc
Match allocator specializations by written template arguments
IvanTrofimov052 Nov 26, 2026
11d452a
Distinguish allocator specialization pack lengths and integral arguments
IvanTrofimov052 Nov 27, 2026
721cbd3
Preserve deduced allocator argument types and uncertain alternatives
IvanTrofimov052 Nov 27, 2026
0a1220c
Rank uncertain allocator specializations independently
IvanTrofimov052 Nov 27, 2026
428b286
Recognize abbreviated allocator function templates
IvanTrofimov052 Nov 27, 2026
89d50a6
Recognize abbreviated allocator member templates
IvanTrofimov052 Nov 27, 2026
d8bad58
Retain static allocator member specializations
IvanTrofimov052 Nov 27, 2026
d90846a
Preserve allocator specializations across class owners and TUs
IvanTrofimov052 Nov 27, 2026
a06117f
Resolve alias-spelled explicit specialization owners
IvanTrofimov052 Nov 27, 2026
9ef3702
Close forwarding and allocator review regressions
IvanTrofimov052 Nov 30, 2026
19e21ad
Keep allocator specializations deduced from trailing returns
IvanTrofimov052 Nov 30, 2026
8246675
Preserve the referent of dependent class rvalue references
IvanTrofimov052 Nov 30, 2026
c776587
Preserve forwarding categories and allocator specialization identity
IvanTrofimov052 Nov 30, 2026
e542565
Complete allocator identities from written template arguments
IvanTrofimov052 Nov 30, 2026
f90e817
Preserve pointer specialization identity and inherited defaults
IvanTrofimov052 Dec 1, 2026
47b0999
Preserve allocator reference deduction and legacy relinking
IvanTrofimov052 Dec 1, 2026
2c49fb9
Preserve const-reference allocator deduction and defaults
IvanTrofimov052 Dec 1, 2026
a71bcde
Preserve rvalue allocator deduction and defaults before packs
IvanTrofimov052 Dec 1, 2026
cb8fc93
Fix forwarding and allocator review regressions
IvanTrofimov052 Dec 1, 2026
a79b6a6
Keep allocator relinking conservative across signature versions
IvanTrofimov052 Dec 1, 2026
27c454e
Distinguish allocator pack slots from fixed-arity padding
IvanTrofimov052 Dec 1, 2026
a67bfcd
Preserve allocator pack provenance during relinking
IvanTrofimov052 Dec 2, 2026
a036a3f
Fix mixed-version allocator specialization relinking
IvanTrofimov052 Dec 2, 2026
80f28cd
Preserve allocator identities across database versions
IvanTrofimov052 Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ trace-merge [OPTIONS] <INPUT_DBS>... [-o <OUTPUT_DB>]
- Re-links `external` call edges (`functions.is_defined = 0` or `call_edges.resolution = 'external'`) against matching exported definitions (`is_defined = 1`, `linkage = 'external'`) from other repositories, updating edge resolution to `direct` or `ambiguous`, while preserving original non-direct resolutions (`indirect` and `ipc`).
- **May-analysis over-approximation**: External calls retain edges to every selected definition, including each image's copy of a shared header body. Distinct source origins make the call ambiguous; shared-origin copies retain a resolved classification. Deduplicates call edges per call site to eliminate duplicate edges.
- Keeps internal-linkage (`static`) functions file-scoped and preserves resolved definitions in known link images; see [merge linking rules](docs/ANALYSIS.md#invariants-and-linking-rules) for weak-symbol precedence and ambiguous matches.
- Uses normalized parameter signatures in `functions.signature` (`name(type1, type2)`) to disambiguate C++ overloads and avoid false collisions; falls back to all same-name candidates if exact signature matching misses.
- Uses normalized parameter types, known C++ reference bindings, and allocator template identity in `functions.signature` to disambiguate overloads. The ` <specialized-fixed<args>>` and ` <specialized-pack<args>>` markers preserve known primary provenance. Relinking accepts equivalent legacy spellings for definition selection and keeps shared-header copies reachable. See [function signature storage](docs/SQLITE_SCHEMA.md#functions) for matching, strength, and diagnostic rules.
- Prevents accidental overwriting of any input database when specifying `-o`.
- Opens inputs read-only and publishes through a unique temporary file beside the output. Failed merges clean up staging files and preserve the existing destination.
- Merger output supports call graphs, call chains, and editor call hierarchy. It omits variables, arg-flow, points-to, and all PAG/provenance tables; call-site variable bindings remain NULL. Dataflow inspection requires an original analysis database or a new analysis of the combined source tree; see the [merger schema contract](docs/SQLITE_SCHEMA.md#merger-inputs-and-output).
Expand Down
6 changes: 6 additions & 0 deletions crates/trace-analysis/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,11 +1114,17 @@ mod tests {
explicit_arity: None,
default_args: 0,
reference_params: Vec::new(),
parameter_references: Vec::new(),
owner_unresolved: false,
variadic: false,
pack_positions: Vec::new(),
non_deduced_pack: false,
is_explicit_constructor: false,
defaulted_in_class: false,
is_deleted: false,
declared_in_class: false,
is_free_function_template: false,
allocator_template: None,
is_member_template: false,
is_const_member: false,
ref_qualifier: None,
Expand Down
9 changes: 9 additions & 0 deletions crates/trace-analysis/src/linking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub struct LinkedMember {
pub site: CallSiteId,
pub caller: FnId,
pub callee: FnId,
/// Original declaration selected for this candidate's call-site variant.
pub selected: Option<FnId>,
}

// Keep source-specific guesses distinct from a namesake another provider
Expand Down Expand Up @@ -121,15 +123,21 @@ pub fn link_graph_facts_in_targets(
owner_unresolved: false,
variadic: f.variadic,
pack_positions: Vec::new(),
non_deduced_pack: false,
is_explicit_constructor: false,
defaulted_in_class: false,
is_deleted: false,
declared_in_class: true,
is_free_function_template: false,
allocator_template: None,
is_member_template: false,
is_const_member: false,
ref_qualifier: None,
return_cv: trace_ir::CvQualification::default(),
is_static_member: f.static_member,
default_args: 0,
reference_params: vec![],
parameter_references: Vec::new(),
is_virtual: f.virtual_member,
is_final: f.final_member,
is_cpp: true,
Expand Down Expand Up @@ -343,6 +351,7 @@ pub fn link_graph_facts_in_targets(
site: call.source_site,
caller: call.caller,
callee: id,
selected: call.callee,
});
}
}
Expand Down
128 changes: 84 additions & 44 deletions crates/trace-analysis/src/pag.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::constraints::{AbstractLocation, Constraint, ConstraintKind, LocKind};
use crate::ipc::detect_ipc_pairs_with_models;
use crate::summaries::{Effect, EffectGroup, FnModelSet, ModelLookup};
use crate::summaries::{AllocationTargets, Effect, EffectGroup, FnModelSet, ModelLookup};
use indexmap::IndexMap;
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
use std::borrow::Cow;
use std::sync::Arc;
use trace_ir::{
CallSite, ContainerOwner, FieldId, FlowConstraint, FnId, LocId, PagNodeId, Program, ReturnFlow,
StorageClass, TargetId, TypeDesc, TypeId, VarId,
CallReturnBinding, CallSite, ContainerOwner, FieldId, FlowConstraint, FnId, LocId, PagNodeId,
Program, ReturnFlow, StorageClass, TargetId, TypeDesc, TypeId, VarId,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -127,6 +129,7 @@ pub struct Pag {
pub indices: SolverIndices,
/// Call results produced by `return_field`, for transitive return expansion.
return_field_values: FxHashSet<VarId>,
allocation_targets: Arc<AllocationTargets>,
}

impl Pag {
Expand All @@ -145,6 +148,7 @@ impl Pag {
) -> Self {
let mut pag = Self {
ipc_enabled: enable_ipc,
allocation_targets: Arc::clone(models.allocation_targets()),
..Self::default()
};
pag.build_variables(program);
Expand All @@ -160,6 +164,20 @@ impl Pag {
pag
}

/// Resolve direct return facts using the same call selections as PAG
/// construction, so export can attribute the wiring to its occurrence.
pub fn return_candidates(
&self,
program: &Program,
name: &str,
caller: Option<FnId>,
dst: VarId,
binding: Option<&CallReturnBinding>,
) -> Cow<'_, [FnId]> {
self.allocation_targets
.candidates(program, name, caller, dst, binding)
}

fn alloc_node(&mut self, kind: PagNodeKind) -> PagNodeId {
let id = PagNodeId(self.nodes.len() as u32);
self.nodes.push(PagNode { id, kind });
Expand Down Expand Up @@ -896,31 +914,48 @@ impl Pag {
dst,
callee_name,
caller,
binding,
} => {
let dst_n = self.var_node_id(*dst);
let mut visited = FxHashSet::default();
let candidates =
program
.symbols
.call_return_candidates(*caller, *dst, callee_name);
let candidates = models.allocation_targets().candidates(
program,
callee_name,
*caller,
*dst,
binding.as_deref(),
);
let declared = matches!(
binding.as_deref(),
Some(CallReturnBinding::InitializerDeclarations(_)),
);
if declared {
for (callee, args) in program.symbols.initializer_call_targets(
*dst,
flow.initializer_calls(),
&program.types,
) {
self.wire_initializer_arguments(program, callee, args);
}
}
let mut any_real = false;
for callee in &candidates {
for callee in candidates.iter() {
if self.expand_return_flows(program, dst_n, *callee, models, &mut visited) {
any_real = true;
}
}
// Modeled return effects fire only when no real return
// flow exists (bodyless callees: libc realloc, vendor
// allocators). Synthesized externals never enter the
// name-resolution maps, so the model is consulted by
// call name directly.
if !any_real {
if let Some(model) = models.model(callee_name, EffectGroup::Return) {
let params = candidates
.iter()
.find(|c| !program.symbols.function(**c).params.is_empty())
.map(|c| program.symbols.function(*c).params.clone());
self.apply_return_model(program, dst_n, model, params.as_deref());
// name-resolution maps. Fall back to a return model
// using the selected targets and the call spelling.
if !any_real && (!declared || !candidates.is_empty()) {
if let Some((model, params)) = models.return_model(
callee_name,
&candidates,
declared || matches!(candidates, Cow::Borrowed(_)),
) {
self.apply_return_model(program, dst_n, model, params);
// A file-scope initializer has no call record.
if caller.is_none() {
self.apply_return_fields(program, *dst, model, &candidates, None);
Expand Down Expand Up @@ -952,14 +987,7 @@ impl Pag {
*callee,
&program.types,
) {
for (formal, actual) in program
.symbols
.initializer_argument_bindings(definition, args)
{
let dst = self.var_node_id(formal);
let src = self.var_node_id(actual);
self.add_copy(dst, src);
}
self.wire_initializer_arguments(program, definition, args);
self.expand_reference_returns(
program,
dst_node,
Expand Down Expand Up @@ -1089,11 +1117,10 @@ impl Pag {
}
if !any_real {
for cs in sites {
if let Some(model) = models.model(&cs.callee_name, EffectGroup::Return) {
let params = cs
.callee_fn_id
.map(|fid| program.symbols.function(fid).params.clone());
self.apply_return_model(program, dst_n, model, params.as_deref());
if let Some((model, params)) =
models.return_model(&cs.callee_name, &program.callees_of(cs), true)
{
self.apply_return_model(program, dst_n, model, params);
break;
}
}
Expand Down Expand Up @@ -1226,8 +1253,13 @@ impl Pag {
callee_name,
result,
} => {
let inner_candidates =
program.symbols.return_flow_candidates(callee, &callee_name);
let inner_candidates = models.allocation_targets().candidates(
program,
&callee_name,
Some(callee),
result,
None,
);
let mut inner_applied = false;
for inner in inner_candidates.iter().copied() {
if self.expand_returns_in_mode(
Expand All @@ -1240,18 +1272,13 @@ impl Pag {
// realloc has no tree body): fall back to the
// modeled return effects.
if !inner_applied && !address {
if let Some(model) = models.model(&callee_name, EffectGroup::Return)
{
let params = inner_candidates
.iter()
.find(|c| !program.symbols.function(**c).params.is_empty())
.map(|c| program.symbols.function(*c).params.clone());
inner_applied = self.apply_return_model(
program,
dst,
model,
params.as_deref(),
);
if let Some((model, params)) = models.return_model(
&callee_name,
&inner_candidates,
matches!(inner_candidates, Cow::Borrowed(_)),
) {
inner_applied =
self.apply_return_model(program, dst, model, params);
}
}
if !address && self.return_field_values.contains(&result) {
Expand Down Expand Up @@ -1539,6 +1566,19 @@ impl Pag {
id
}

fn wire_initializer_arguments(
&mut self,
program: &Program,
callee: FnId,
args: &[(u32, VarId)],
) {
for (formal, actual) in program.symbols.initializer_argument_bindings(callee, args) {
let dst = self.var_node_id(formal);
let src = self.var_node_id(actual);
self.add_copy(dst, src);
}
}

pub fn add_copy(&mut self, dst: PagNodeId, src: PagNodeId) {
self.constraints.push(Constraint {
kind: crate::constraints::ConstraintKind::Copy,
Expand Down
36 changes: 15 additions & 21 deletions crates/trace-analysis/src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ fn solve(
&mut st,
&mut scratch,
cs,
&f.name,
f,
models,
&mut terminator_events,
);
Expand Down Expand Up @@ -1662,7 +1662,7 @@ fn solve(
&mut st,
&mut scratch,
cs,
&program.symbols.function(callee).name,
program.symbols.function(callee),
models,
&mut terminator_events,
);
Expand Down Expand Up @@ -1825,11 +1825,11 @@ fn apply_fn_model(
st: &mut SolverState,
scratch: &mut Scratch,
cs: &trace_ir::CallSite,
callee_name: &str,
callee: &trace_ir::Function,
models: &ModelLookup,
terminator_events: &mut Vec<(CallSiteId, u32)>,
) {
let Some(model) = models.model(callee_name, EffectGroup::Args) else {
let Some(model) = models.argument_model(callee) else {
return;
};
// Unresolved member addresses may still name the base variable;
Expand Down Expand Up @@ -2664,23 +2664,15 @@ fn wire_actuals(
) {
let callee_fn = program.symbols.function(callee);
let this = u32::from(program.symbols.has_this_param(callee));
callee_fn.debug_assert_pack_positions(this as usize);
let mut packs = callee_fn
.pack_positions
.iter()
.map(|at| at + this)
.peekable();
let mut packs_before = 0;
for (i, formal) in callee_fn.params.iter().enumerate() {
for (i, (formal, first, is_pack)) in callee_fn.parameter_actual_starts(this).enumerate() {
let formal_idx = i as u32;
let is_pack = packs.next_if_eq(&formal_idx).is_some();
debug_assert_eq!(
is_pack,
program.pack_vars.contains(formal),
program.pack_vars.contains(&formal),
"{}: parameter pack metadata disagrees with formal {formal_idx}",
callee_fn.name
);
if is_pack || packs_before > 0 {
if is_pack || first < formal_idx {
// A pack formal takes every argument from its position on: the
// positions the site passes, mapped as the callee takes them,
// each wired once however many positions an expansion covers.
Expand All @@ -2689,9 +2681,6 @@ fn wire_actuals(
.max()
.map_or(1, |last| last + 1);
let mut taken: Vec<u32> = Vec::new();
// Earlier packs may all be empty. Omit each of their synthetic
// slots to find this formal's first possible actual position.
let first = formal_idx - packs_before;
for slot in first..first.saturating_add(reach) {
let Some(idx) = actual_of(slot) else {
continue;
Expand All @@ -2713,7 +2702,7 @@ fn wire_actuals(
cs,
st,
scratch,
*formal,
formal,
formal_idx,
at,
&mut on_wired,
Expand All @@ -2728,13 +2717,12 @@ fn wire_actuals(
cs,
st,
scratch,
*formal,
formal,
formal_idx,
at,
&mut on_wired,
);
}
packs_before += u32::from(is_pack);
}
}

Expand Down Expand Up @@ -4290,11 +4278,17 @@ mod tests {
explicit_arity: None,
default_args: 0,
reference_params: Vec::new(),
parameter_references: Vec::new(),
owner_unresolved: false,
variadic: false,
pack_positions: Vec::new(),
non_deduced_pack: false,
is_explicit_constructor: false,
defaulted_in_class: false,
is_deleted: false,
declared_in_class: false,
is_free_function_template: false,
allocator_template: None,
is_member_template: false,
is_const_member: false,
ref_qualifier: None,
Expand Down
Loading