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 .github/ci_generator/templates/job_steps/build_docs.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
lycheeVersion: v0.16.1
args: |
--base site
--accept 200,429
--exclude-loopback
--exclude-path="site/api_reference/pavex/http"
--exclude-path="site/api_reference/pavex/time"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,7 @@ jobs:
lycheeVersion: v0.16.1
args: |
--base site
--accept 200,429
--exclude-loopback
--exclude-path="site/api_reference/pavex/http"
--exclude-path="site/api_reference/pavex/time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::{
processing_pipeline::RequestHandlerPipeline,
},
computation::Computation,
framework_rustdoc::resolve_type_path,
traits::assert_trait_is_implemented,
utils::resolve_type_path,
},
diagnostic::{AnnotatedSource, CompilerDiagnostic, HelpWithSnippet},
language::Type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
computations::ComputationDb,
},
computation::Computation,
framework_rustdoc::resolve_type_path,
traits::{MissingTraitImplementationError, assert_trait_is_implemented},
utils::resolve_type_path,
},
diagnostic::{CompilerDiagnostic, ComponentKind},
language::Type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::compiler::analyses::components::{
use crate::compiler::analyses::computations::ComputationDb;
use crate::compiler::analyses::user_components::ScopeId;
use crate::compiler::computation::Computation;
use crate::compiler::utils::resolve_type_path;
use crate::compiler::framework_rustdoc::resolve_type_path;
use crate::language::{
Callable, CallableInput, FnHeader, Lifetime, PathType, RustIdentifier, TraitMethod,
TraitMethodPath, Type, TypeReference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
call_graph::{CallGraphNode, RawCallGraph},
computations::ComputationDb,
},
framework_rustdoc::resolve_type_path,
traits::assert_trait_is_implemented,
utils::resolve_type_path,
},
language::{PathType, Type},
rustdoc::CrateCollection,
Expand Down
2 changes: 1 addition & 1 deletion compiler/pavexc/src/compiler/analyses/cloning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
components::{ComponentDb, ComponentId, HydratedComponent},
computations::ComputationDb,
},
framework_rustdoc::resolve_type_path,
traits::{MissingTraitImplementationError, assert_trait_is_implemented},
utils::resolve_type_path,
},
diagnostic::{CompilerDiagnostic, ComponentKind},
language::Type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::compiler::component::{
PostProcessingMiddlewareValidationError, PreProcessingMiddlewareValidationError,
RequestHandlerValidationError, WrappingMiddlewareValidationError,
};
use crate::compiler::resolvers::CallableResolutionError;
use crate::compiler::traits::MissingTraitImplementationError;
use crate::diagnostic::{
self, AnnotatedSource, CallableDefSource, CompilerDiagnostic, ComponentKind, SourceSpanExt,
Expand Down Expand Up @@ -644,7 +643,7 @@ impl ComponentDb {
}

pub(super) fn cannot_handle_into_response_implementation(
e: CallableResolutionError,
e: anyhow::Error,
output_type: &Type,
id: UserComponentId,
db: &UserComponentDb,
Expand All @@ -655,7 +654,7 @@ impl ComponentDb {
db.registration_target(id),
format!("The {kind} was registered here"),
);
let error = anyhow::Error::from(e).context(format!(
let error = e.context(format!(
"Something went wrong when I tried to analyze the implementation of \
`pavex::IntoResponse` for {output_type:?}, the type returned by \
one of your {kind}s.\n\
Expand Down
53 changes: 22 additions & 31 deletions compiler/pavexc/src/compiler/analyses/components/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ use crate::compiler::component::{
PostProcessingMiddleware, PreProcessingMiddleware, RequestHandler, WrappingMiddleware,
};
use crate::compiler::computation::{Computation, MatchResult};
use crate::compiler::framework_rustdoc::{
resolve_framework_free_function, resolve_framework_inherent_method,
resolve_framework_trait_method, resolve_type_path,
};
use crate::compiler::interner::Interner;
use crate::compiler::traits::assert_trait_is_implemented;
use crate::compiler::utils::{
get_err_variant, get_ok_variant, resolve_framework_callable_path, resolve_type_path,
};
use crate::diagnostic::{ParsedSourceFile, Registration, TargetSpan};
use crate::language::{
Callable, FQPath, FQPathSegment, FQQualifiedSelf, Lifetime, PathTypeExt, Type, TypeReference,
};
use crate::language::{Callable, Lifetime, Type, TypeReference, get_err_variant, get_ok_variant};
use crate::rustdoc::{CrateCollection, CrateCollectionExt};
use ahash::{HashMap, HashMapExt, HashSet};
use guppy::graph::PackageGraph;
Expand Down Expand Up @@ -159,18 +158,17 @@ impl ComponentDb {
})
};
let pavex_error_fallback_id = {
let callable = resolve_framework_callable_path(
"pavex::Error::to_response",
package_graph,
let callable = resolve_framework_inherent_method(
&["pavex", "Error"],
"to_response",
krate_collection,
);
let computation = Computation::Callable(Cow::Owned(callable));
computation_db.get_or_intern(computation)
};
let pavex_noop_wrap_id = {
let callable = resolve_framework_callable_path(
"pavex::middleware::wrap_noop",
package_graph,
let callable = resolve_framework_free_function(
&["pavex", "middleware", "wrap_noop"],
krate_collection,
);
let computation = Computation::Callable(Cow::Owned(callable));
Expand Down Expand Up @@ -303,9 +301,9 @@ impl ComponentDb {

// Add a synthetic constructor for the `pavex::middleware::Next` type.
{
let callable = resolve_framework_callable_path(
"pavex::middleware::Next::new",
package_graph,
let callable = resolve_framework_inherent_method(
&["pavex", "middleware", "Next"],
"new",
krate_collection,
);
let computation = Computation::Callable(Cow::Owned(callable));
Expand Down Expand Up @@ -1275,7 +1273,6 @@ impl ComponentDb {
};
into_response
};
let into_response_path = into_response.resolved_path();
let iter: Vec<_> = self
.interner
.iter()
Expand Down Expand Up @@ -1341,21 +1338,15 @@ impl ComponentDb {
}
continue;
}
let mut transformer_segments = into_response_path.segments.clone();
transformer_segments.push(FQPathSegment {
ident: "into_response".into(),
generic_arguments: vec![],
});
let transformer_path = FQPath {
segments: transformer_segments,
qualified_self: Some(FQQualifiedSelf {
position: into_response_path.segments.len(),
type_: output.clone().into(),
}),
package_id: into_response_path.package_id.clone(),
};
match computation_db.resolve_and_intern(krate_collection, &transformer_path, None) {
Ok(callable_id) => {
match resolve_framework_trait_method(
&["pavex", "IntoResponse"],
"into_response",
output.clone(),
krate_collection,
) {
Ok(callable) => {
let computation = Computation::Callable(Cow::Owned(callable));
let callable_id = computation_db.get_or_intern(computation);
let transformer = UnregisteredComponent::Transformer {
computation_id: callable_id,
transformed_component_id: component_id,
Expand Down
16 changes: 1 addition & 15 deletions compiler/pavexc/src/compiler/analyses/computations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use ahash::HashMap;
use crate::compiler::analyses::user_components::UserComponentId;
use crate::compiler::computation::Computation;
use crate::compiler::interner::Interner;
use crate::compiler::resolvers::{CallableResolutionError, resolve_callable};
use crate::language::{Callable, FQPath};
use crate::rustdoc::CrateCollection;
use crate::language::Callable;

pub(crate) type ComputationId = la_arena::Idx<Computation<'static>>;

Expand Down Expand Up @@ -34,18 +32,6 @@ impl ComputationDb {
}
}

/// Try to resolve a callable from a resolved path.
/// Returns the callable's id in the interner if it succeeds, an error otherwise.
pub(crate) fn resolve_and_intern(
&mut self,
krate_collection: &CrateCollection,
resolved_path: &FQPath,
user_component_id: Option<UserComponentId>,
) -> Result<ComputationId, CallableResolutionError> {
let callable = resolve_callable(krate_collection, resolved_path)?;
Ok(self.get_or_intern_with_id(callable, user_component_id))
}

/// Intern a callable (or retrieve its id if it already exists).
///
/// Then associate it with the given user component id.
Expand Down
4 changes: 3 additions & 1 deletion compiler/pavexc/src/compiler/analyses/framework_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use bimap::BiHashMap;
use proc_macro2::Ident;
use quote::format_ident;

use crate::{compiler::utils::resolve_type_path, language::Type, rustdoc::CrateCollection};
use crate::{
compiler::framework_rustdoc::resolve_type_path, language::Type, rustdoc::CrateCollection,
};
use pavex_bp_schema::{CloningPolicy, Lifecycle};

/// The id for a framework item inside [`FrameworkItemDb`].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::compiler::analyses::constructibles::ConstructibleDb;
use crate::compiler::analyses::framework_items::FrameworkItemDb;
use crate::compiler::app::GENERATED_APP_PACKAGE_ID;
use crate::compiler::computation::Computation;
use crate::compiler::utils::LifetimeGenerator;
use crate::diagnostic::{AnnotatedSource, CompilerDiagnostic, HelpWithSnippet};
use crate::language::LifetimeGenerator;
use crate::language::{
Callable, CallableInput, CanonicalType, GenericArgument, GenericLifetimeParameter, Lifetime,
PathType, PathTypeExt, RustIdentifier, StructLiteralInit, Type, TypeReference,
Expand Down
2 changes: 1 addition & 1 deletion compiler/pavexc/src/compiler/analyses/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::compiler::analyses::components::HydratedComponent;
use crate::compiler::analyses::components::{ComponentDb, ComponentId};
use crate::compiler::analyses::computations::ComputationDb;
use crate::compiler::analyses::processing_pipeline::RequestHandlerPipeline;
use crate::compiler::utils::get_ok_variant;
use crate::diagnostic::{CompilerDiagnostic, DiagnosticSink};
use crate::language::get_ok_variant;
use indexmap::IndexSet;
use miette::Severity;
use pavex_bp_schema::{Lint, LintSetting};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
compiler::{
analyses::user_components::{UserComponentId, imports::UnresolvedImport},
component::{ConfigTypeValidationError, PrebuiltTypeValidationError},
resolvers::{TypeResolutionError, UnsupportedConstGeneric},
framework_rustdoc::{TypeResolutionError, UnsupportedConstGeneric},
},
diagnostic::{
self, CallableDefSource, ComponentKind, DiagnosticSink, OptionalLabeledSpanExt,
Expand Down Expand Up @@ -358,16 +358,6 @@ pub(super) fn cannot_resolve_callable_path(
let component = &db[id];
let kind = component.kind();
match e {
CallableResolutionError::UnknownCallable(_) => {
let source = diagnostics.annotated(
TargetSpan::RawIdentifiers(&db.id2registration[id], kind),
format!("The {kind} that we can't resolve"),
);
let diagnostic = CompilerDiagnostic::builder(e).optional_source(source)
.help("Check that the path is spelled correctly and that the function (or method) is public.".into())
.build();
diagnostics.push(diagnostic);
}
CallableResolutionError::InputParameterResolutionError(ref inner_error) => {
let definition_snippet =
CallableDefSource::compute_from_item(&inner_error.callable_item, package_graph)
Expand All @@ -388,22 +378,6 @@ pub(super) fn cannot_resolve_callable_path(
.build();
diagnostics.push(diagnostic);
}
CallableResolutionError::UnsupportedCallableKind(ref inner_error) => {
let source = diagnostics.annotated(
TargetSpan::RawIdentifiers(&db.id2registration[id], kind),
format!("It was registered as a {kind} here"),
);
let message = format!(
"I can work with functions and methods, but `{}` is neither.\nIt is {} and I don't know how to use it as a {}.",
inner_error.import_path, inner_error.item_kind, kind
);
let error = anyhow::anyhow!(e).context(message);
diagnostics.push(
CompilerDiagnostic::builder(error)
.optional_source(source)
.build(),
);
}
CallableResolutionError::OutputTypeResolutionError(ref inner_error) => {
let output_snippet =
CallableDefSource::compute_from_item(&inner_error.callable_item, package_graph)
Expand All @@ -426,16 +400,6 @@ pub(super) fn cannot_resolve_callable_path(
CallableResolutionError::CannotGetCrateData(_) => {
diagnostics.push(CompilerDiagnostic::builder(e).build());
}
CallableResolutionError::GenericParameterResolutionError(_) => {
let source = diagnostics.annotated(
db.registration_target(&id),
format!("The {kind} was registered here"),
);
let diagnostic = CompilerDiagnostic::builder(e)
.optional_source(source)
.build();
diagnostics.push(diagnostic);
}
CallableResolutionError::SelfResolutionError(_) => {
let source = diagnostics.annotated(
db.registration_target(&id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
compiler::{
analyses::{computations::ComputationDb, prebuilt_types::PrebuiltTypeDb},
component::{ConfigType, DefaultStrategy, PrebuiltType},
resolvers::CallableResolutionError,
framework_rustdoc::CallableResolutionError,
},
diagnostic::{ComponentKind, DiagnosticSink, Registration},
language::Type,
Expand Down
2 changes: 1 addition & 1 deletion compiler/pavexc/src/compiler/component/error_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::{Display, Formatter};

use crate::compiler::component::CannotTakeMutReferenceError;
use crate::compiler::utils::get_err_variant;
use crate::language::get_err_variant;
use ahash::HashMap;
use indexmap::IndexSet;
use itertools::Itertools;
Expand Down
Loading
Loading