Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl ApplicationState {
framework_item_db,
constructibles_db,
component_db,
krate_collection,
);
runtime_singletons_are_thread_safe(
&type2id,
Expand Down Expand Up @@ -331,6 +332,7 @@ fn extract_runtime_singletons<'a>(
framework_item_db: &FrameworkItemDb,
constructibles_db: &ConstructibleDb,
component_db: &ComponentDb,
krate_collection: &CrateCollection,
) -> IndexSet<(Type, ComponentId)> {
let mut type2id = IndexSet::new();
for handler_pipeline in handler_pipelines {
Expand Down Expand Up @@ -363,6 +365,7 @@ fn extract_runtime_singletons<'a>(
root_component_scope_id,
required_input,
component_db.scope_graph(),
krate_collection,
) {
let lifecycle = component_db.lifecycle(component_id);
#[cfg(debug_assertions)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub(crate) fn application_state_call_graph(
CloningPolicy::NeverClone,
computation_db,
framework_item_db,
krate_collection,
None,
)
.unwrap();
Expand All @@ -77,6 +78,7 @@ pub(crate) fn application_state_call_graph(
computation_db,
component_db,
constructible_db,
krate_collection,
lifecycle2invocations,
diagnostics,
)
Expand Down Expand Up @@ -296,6 +298,7 @@ pub(crate) fn application_state_call_graph(
computation_db,
component_db,
constructible_db,
krate_collection,
lifecycle2invocations,
diagnostics,
) else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::compiler::analyses::components::{ComponentDb, ComponentId};
use crate::compiler::analyses::computations::ComputationDb;
use crate::compiler::computation::Computation;
use crate::language::Type;
use crate::rustdoc::CrateCollection;

/// A [`CallGraph`] with nodes globally ordered according to their node index.
/// Walking the graph according to the specified ordering guarantees that the generated code will
Expand Down Expand Up @@ -43,11 +44,18 @@ impl OrderedCallGraph {
package_id2name: &BiHashMap<PackageId, String>,
component_db: &ComponentDb,
computation_db: &ComputationDb,
krate_collection: &CrateCollection,
) -> Result<ItemFn, anyhow::Error> {
if tracing::event_enabled!(tracing::Level::TRACE) {
self.print_debug_dot("Application state", component_db, computation_db);
}
codegen_callable_closure(self, package_id2name, component_db, computation_db)
codegen_callable_closure(
self,
package_id2name,
component_db,
computation_db,
krate_collection,
)
}

/// Return the set of types that must be provided as input to (recursively) build the handler's
Expand Down
16 changes: 13 additions & 3 deletions compiler/pavexc/src/compiler/analyses/call_graph/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::compiler::codegen_utils::{Fragment, VariableNameGenerator};
use crate::compiler::component::Constructor;
use crate::compiler::computation::{Computation, MatchResultVariant};
use crate::language::{CanonicalType, Type};
use crate::rustdoc::CrateCollection;

/// Generate the dependency closure of the [`OrderedCallGraph`]'s root callable.
///
Expand All @@ -35,6 +36,7 @@ pub(crate) fn codegen_callable_closure(
package_id2name: &BiHashMap<PackageId, String>,
component_db: &ComponentDb,
computation_db: &ComputationDb,
krate_collection: &CrateCollection,
) -> Result<ItemFn, anyhow::Error> {
let input_parameter_types = call_graph.required_input_types();
let mut variable_generator = VariableNameGenerator::new();
Expand All @@ -43,7 +45,7 @@ pub(crate) fn codegen_callable_closure(
.iter()
.map(|type_| {
let parameter_name = variable_generator.generate();
(type_.canonicalize(), parameter_name)
(type_.canonicalize(krate_collection), parameter_name)
})
.collect();
let body = codegen_callable_closure_body(
Expand All @@ -53,11 +55,12 @@ pub(crate) fn codegen_callable_closure(
component_db,
computation_db,
&mut variable_generator,
krate_collection,
)?;

let function = {
let inputs = input_parameter_types.into_iter().map(|mut type_| {
let variable_name = &parameter_bindings[&type_.canonicalize()];
let variable_name = &parameter_bindings[&type_.canonicalize(krate_collection)];
// We can set all the non-'static lifetimes to implied (i.e. '_) in function signatures.
let original2renamed = type_
.named_lifetime_parameters()
Expand Down Expand Up @@ -209,6 +212,7 @@ fn codegen_callable_closure_body(
component_db: &ComponentDb,
computation_db: &ComputationDb,
variable_name_generator: &mut VariableNameGenerator,
krate_collection: &CrateCollection,
) -> Result<TokenStream, anyhow::Error> {
let mut at_most_once_constructor_blocks = IndexMap::<NodeIndex, TokenStream>::new();
let mut blocks = BTreeMap::<NodeIndex, Fragment>::new();
Expand All @@ -224,6 +228,7 @@ fn codegen_callable_closure_body(
component_db,
computation_db,
variable_name_generator,
krate_collection,
&mut at_most_once_constructor_blocks,
&mut blocks,
&mut dfs,
Expand Down Expand Up @@ -272,6 +277,7 @@ fn _codegen_callable_closure_body(
component_db: &ComponentDb,
computation_db: &ComputationDb,
variable_name_generator: &mut VariableNameGenerator,
krate_collection: &CrateCollection,
at_most_once_constructor_blocks: &mut IndexMap<NodeIndex, TokenStream>,
blocks: &mut BTreeMap<NodeIndex, Fragment>,
dfs: &mut BasicBlockVisitor,
Expand Down Expand Up @@ -310,6 +316,7 @@ fn _codegen_callable_closure_body(
blocks,
variable_name_generator,
package_id2name,
krate_collection,
)?;
// This is the last node!
// We don't need to assign its value to a variable.
Expand Down Expand Up @@ -348,7 +355,9 @@ fn _codegen_callable_closure_body(
CallGraphNode::InputParameter {
type_: input_type, ..
} => {
let parameter_name = parameter_bindings[&input_type.canonicalize()].clone();
let parameter_name = parameter_bindings
[&input_type.canonicalize(krate_collection)]
.clone();
blocks.insert(current_index, Fragment::VariableReference(parameter_name));
}
CallGraphNode::MatchBranching => {
Expand Down Expand Up @@ -395,6 +404,7 @@ fn _codegen_callable_closure_body(
component_db,
computation_db,
&mut variant_name_generator,
krate_collection,
&mut at_most_once_constructor_blocks,
&mut variant_blocks,
&mut new_dfs,
Expand Down
12 changes: 9 additions & 3 deletions compiler/pavexc/src/compiler/analyses/call_graph/core_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::compiler::analyses::constructibles::ConstructibleDb;
use crate::compiler::analyses::user_components::ScopeId;
use crate::compiler::computation::{Computation, MatchResultVariant};
use crate::language::{Lifetime, Type, TypeReference};
use crate::rustdoc::CrateCollection;

use super::dependency_graph::DependencyGraph;

Expand Down Expand Up @@ -66,6 +67,7 @@ pub(super) fn build_call_graph<F>(
computation_db: &ComputationDb,
component_db: &ComponentDb,
constructible_db: &ConstructibleDb,
krate_collection: &CrateCollection,
lifecycle2n_allowed_invocations: F,
diagnostics: &crate::diagnostic::DiagnosticSink,
) -> Result<CallGraph, ()>
Expand All @@ -78,6 +80,7 @@ where
computation_db,
component_db,
constructible_db,
krate_collection,
error_observer_ids,
lifecycle2n_allowed_invocations.clone(),
)
Expand Down Expand Up @@ -233,9 +236,12 @@ where
}
};
for input_type in input_types {
if let Some((constructor_id, consumption_mode)) =
constructible_db.get(root_scope_id, &input_type, component_db.scope_graph())
{
if let Some((constructor_id, consumption_mode)) = constructible_db.get(
root_scope_id,
&input_type,
component_db.scope_graph(),
krate_collection,
) {
nodes_to_be_visited.insert(VisitorStackElement {
node_index: add_node_for_component(
&mut call_graph,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use pavex_bp_schema::Lifecycle;
use petgraph::stable_graph::{NodeIndex, StableDiGraph};

use crate::compiler::analyses::components::{ComponentDb, ComponentId};
use crate::rustdoc::CrateCollection;
use crate::{
compiler::{
analyses::{
Expand Down Expand Up @@ -37,6 +38,7 @@ impl DependencyGraph {
computation_db: &ComputationDb,
component_db: &ComponentDb,
constructible_db: &ConstructibleDb,
krate_collection: &CrateCollection,
error_observer_ids: &[ComponentId],
lifecycle2n_allowed_invocations: F,
) -> Self
Expand Down Expand Up @@ -175,6 +177,7 @@ impl DependencyGraph {
component_scope,
&input_type,
component_db.scope_graph(),
krate_collection,
) {
nodes_to_be_visited.insert(VisitorStackElement {
component_id: constructor_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub(crate) fn request_scoped_ordered_call_graph(
computation_db,
component_db,
constructible_db,
krate_collection,
diagnostics,
)
else {
Expand Down Expand Up @@ -78,6 +79,7 @@ pub(crate) fn request_scoped_call_graph(
computation_db: &mut ComputationDb,
component_db: &mut ComponentDb,
constructible_db: &ConstructibleDb,
krate_collection: &CrateCollection,
diagnostics: &crate::diagnostic::DiagnosticSink,
) -> Result<CallGraph, ()> {
let mut graph_root = String::new();
Expand All @@ -100,6 +102,7 @@ pub(crate) fn request_scoped_call_graph(
computation_db,
component_db,
constructible_db,
krate_collection,
diagnostics,
)?;
if component_db.is_pre_processing_middleware(root_component_id) {
Expand All @@ -111,6 +114,7 @@ pub(crate) fn request_scoped_call_graph(
computation_db,
component_db,
constructible_db,
krate_collection,
diagnostics,
)
} else {
Expand All @@ -127,6 +131,7 @@ fn _request_scoped_call_graph(
computation_db: &mut ComputationDb,
component_db: &mut ComponentDb,
constructible_db: &ConstructibleDb,
krate_collection: &CrateCollection,
diagnostics: &crate::diagnostic::DiagnosticSink,
) -> Result<CallGraph, ()> {
fn lifecycle2invocations(l: Lifecycle) -> Option<NumberOfAllowedInvocations> {
Expand All @@ -143,6 +148,7 @@ fn _request_scoped_call_graph(
computation_db,
component_db,
constructible_db,
krate_collection,
lifecycle2invocations,
diagnostics,
)
Expand All @@ -161,6 +167,7 @@ fn augment_preprocessing_graph(
computation_db: &mut ComputationDb,
component_db: &mut ComponentDb,
constructible_db: &ConstructibleDb,
krate_collection: &CrateCollection,
diagnostics: &crate::diagnostic::DiagnosticSink,
) -> Result<CallGraph, ()> {
assert!(component_db.is_pre_processing_middleware(root_component_id));
Expand Down Expand Up @@ -235,6 +242,7 @@ fn augment_preprocessing_graph(
computation_db,
component_db,
constructible_db,
krate_collection,
diagnostics,
)
}
Loading
Loading