pub struct CodegenContext {Show 21 fields
pub items: Vec<TopLevel>,
pub fn_sigs: HashMap<String, (Vec<Type>, Type, Vec<String>)>,
pub memo_fns: HashSet<String>,
pub memo_safe_types: HashSet<String>,
pub type_defs: Vec<TypeDef>,
pub fn_defs: Vec<FnDef>,
pub project_name: String,
pub modules: Vec<ModuleInfo>,
pub module_prefixes: HashSet<String>,
pub policy: Option<ProjectConfig>,
pub emit_replay_runtime: bool,
pub runtime_policy_from_env: bool,
pub guest_entry: Option<String>,
pub emit_self_host_support: bool,
pub extra_fn_defs: Vec<FnDef>,
pub mutual_tco_members: HashSet<String>,
pub recursive_fns: HashSet<String>,
pub fn_analyses: HashMap<String, FnAnalysis>,
pub buffer_build_sinks: HashMap<String, BufferBuildShape>,
pub buffer_fusion_sites: Vec<FusionSite>,
pub synthesized_buffered_fns: Vec<FnDef>,
}Expand description
Collected context from the Aver program, shared across all backends.
Fields§
§items: Vec<TopLevel>All top-level items (post-TCO transform, post-typecheck).
fn_sigs: HashMap<String, (Vec<Type>, Type, Vec<String>)>Function signatures: name → (param_types, return_type, effects).
memo_fns: HashSet<String>Functions eligible for auto-memoization.
memo_safe_types: HashSet<String>Set of type names whose values are memo-safe.
type_defs: Vec<TypeDef>User-defined type definitions (for struct/enum generation).
fn_defs: Vec<FnDef>User-defined function definitions.
project_name: StringProject/binary name.
modules: Vec<ModuleInfo>Dependent modules loaded for inlining.
module_prefixes: HashSet<String>Set of module prefixes for qualified name resolution (e.g. “Models.User”).
policy: Option<ProjectConfig>Embedded runtime policy from aver.toml for generated code.
emit_replay_runtime: boolEmit generated scoped runtime support (replay and/or runtime-loaded policy).
runtime_policy_from_env: boolLoad runtime policy from the active module root instead of embedding it.
guest_entry: Option<String>Explicit guest entry boundary for scoped replay/policy.
emit_self_host_support: boolEmit extra generated helpers needed only by the cached self-host helper.
extra_fn_defs: Vec<FnDef>Extra fn_defs visible during current module emission (not in fn_defs or modules).
Set temporarily by the Rust backend when emitting a dependent module so that
find_fn_def_by_name can resolve same-module calls.
mutual_tco_members: HashSet<String>Functions that are part of a mutual-TCO SCC group (emitted as trampoline + wrappers). Functions NOT in this set but with TailCalls are emitted as plain self-TCO loops.
recursive_fns: HashSet<String>Functions that call themselves directly or transitively. Set-form
union of entry_analysis.recursive_fns plus each module’s
analysis.recursive_fns. Used by codegen sites that previously
called call_graph::find_recursive_fns ad-hoc (Lean recursion
planning, type checker flow, etc.).
fn_analyses: HashMap<String, FnAnalysis>Per-fn analysis facts unioned from entry + every dep module’s
AnalysisResult.fn_analyses. WASM emitter / VM compiler /
future inliner read allocates, thin_kind, body_shape,
local_count, etc. from here instead of recomputing.
buffer_build_sinks: HashMap<String, BufferBuildShape>Buffer-build sink fns (List.prepend/reverse builders consumed
by String.join). The Rust backend emits a <fn>__buffered
variant alongside each entry; the WASM backend rewrites bodies
to call rt_buffer_* helpers. Detection lives in ir::buffer_build.
buffer_fusion_sites: Vec<FusionSite>Fusion sites detected for String.join(<sink>(...), sep) calls.
Each entry pairs an enclosing fn + line + sink fn name; the
emitter rewrites these call expressions to use buffered variants
in place of the producer + consumer chain.
synthesized_buffered_fns: Vec<FnDef>Synthesized <fn>__buffered variants for every buffer-build
sink, produced by ir::synthesize_buffered_variants. These are
real FnDefs with proper body AST; backends iterate over them
alongside fn_defs so they reach codegen through the same
pipeline (TCO / no-alloc / mutual-recursion all apply
identically). Empty when no sinks are detected.
Implementations§
Source§impl CodegenContext
impl CodegenContext
Sourcepub fn refresh_facts(&mut self)
pub fn refresh_facts(&mut self)
Recompute mutual_tco_members and recursive_fns from current
items + modules. Used by test helpers that build the context
piecewise (push items in-place, bypass build_context) so the
derived sets stay in sync. Idempotent — production callers go
through build_context, where these are already populated from
the analyze stage; calling refresh_facts again is a no-op for
them (computes the same answer).