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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) fn runtime_singletons_can_be_cloned_if_needed<'a>(
| Type::FunctionPointer(_) => {
return None;
}
Type::Path(_) | Type::Tuple(_) => {}
Type::Path(_) | Type::TypeAlias(_) | Type::Tuple(_) => {}
Type::Generic(_) => unreachable!(),
};
let InputParameterSource::Component(id) = source else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn field_name_candidate(ty_: &Type, strategy: NamingStrategy) -> String {

fn _field_name_candidate(ty_: &Type, strategy: NamingStrategy, candidate: &mut String) {
match ty_ {
Type::Path(path_type) => match strategy {
Type::Path(path_type) | Type::TypeAlias(path_type) => match strategy {
NamingStrategy::LastSegment => {
let last = path_type
.base_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ impl CodegenedRequestHandlerPipeline {
Type::Slice(_)
| Type::Array(_)
| Type::Path(_)
| Type::TypeAlias(_)
| Type::Tuple(_)
| Type::ScalarPrimitive(_)
| Type::RawPointer(_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ impl RequestHandlerPipeline {
}
}
Type::Path(_) |
Type::TypeAlias(_) |
Type::Tuple(_) |
Type::Array(_) => {
type2info.entry(ty.clone()).or_default().consumed_by.push(ConsumerInfo { middleware_index: index, component_id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use pavex_bp_schema::{CloningPolicy, Lifecycle, Lint, LintSetting};
use pavexc_attr_parser::{AnnotationKind, AnnotationProperties};
use rustdoc_ext::RustdocKindExt;
use rustdoc_resolver::{
resolve_free_function, rustdoc_method2callable, rustdoc_new_type_def2type,
rustdoc_type_alias2type,
TypeAliasResolution, resolve_free_function, rustdoc_method2callable,
rustdoc_new_type_def2type, rustdoc_type_alias2type,
};
use rustdoc_types::{Item, ItemEnum};

Expand Down Expand Up @@ -521,7 +521,7 @@ fn rustdoc_item_def2type(
Err(())
}
},
ItemEnum::TypeAlias(_) => match rustdoc_type_alias2type(item, krate, krate_collection) {
ItemEnum::TypeAlias(_) => match rustdoc_type_alias2type(item, krate, krate_collection, TypeAliasResolution::ResolveThrough) {
Ok(t) => Ok(t),
Err(e) => {
type_resolution_error(e, item, diagnostics);
Expand Down
2 changes: 1 addition & 1 deletion compiler/pavexc/src/compiler/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn collect_callable_package_ids(package_ids: &mut IndexSet<PackageId>, c: &Calla

fn collect_type_package_ids(package_ids: &mut IndexSet<PackageId>, t: &Type) {
match t {
Type::Path(t) => {
Type::Path(t) | Type::TypeAlias(t) => {
package_ids.insert(t.package_id.clone());
for generic in &t.generic_arguments {
match generic {
Expand Down
1 change: 1 addition & 0 deletions compiler/pavexc/src/compiler/codegen/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub(super) fn get_application_state_new(
Type::Slice(_)
| Type::Array(_)
| Type::Path(_)
| Type::TypeAlias(_)
| Type::Tuple(_)
| Type::ScalarPrimitive(_)
| Type::RawPointer(_)
Expand Down
5 changes: 4 additions & 1 deletion compiler/pavexc/src/compiler/framework_rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::rustdoc::{CannotGetCrateData, CrateCollection};
use rustdoc_ext::GlobalItemId;
use rustdoc_ir::{CallableInput, FnHeader, RustIdentifier, TraitMethod, TraitMethodPath};
use rustdoc_processor::queries::Crate;
use rustdoc_resolver::{GenericBindings, resolve_type};
use rustdoc_resolver::{GenericBindings, TypeAliasResolution, resolve_type};

use super::app::PAVEX_VERSION;

Expand Down Expand Up @@ -157,6 +157,7 @@ pub(crate) fn resolve_type_path(raw_path: &str, krate_collection: &CrateCollecti
&global_id.package_id,
krate_collection,
&GenericBindings::default(),
TypeAliasResolution::ResolveThrough,
)
.expect("Failed to resolve default generic type");
GenericArgument::TypeParameter(default)
Expand Down Expand Up @@ -334,6 +335,7 @@ pub(crate) fn resolve_framework_trait_method(
&krate.core.package_id,
krate_collection,
&generic_bindings,
TypeAliasResolution::ResolveThrough,
)
.map_err(|e| {
anyhow::anyhow!(
Expand All @@ -357,6 +359,7 @@ pub(crate) fn resolve_framework_trait_method(
&krate.core.package_id,
krate_collection,
&generic_bindings,
TypeAliasResolution::ResolveThrough,
)
.map_err(|e| {
anyhow::anyhow!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/pavexc/src/compiler/path_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn must_be_a_plain_struct(
extracted_type: &Type,
) -> Result<rustdoc_types::Item, ()> {
let error_suffix = match extracted_type {
Type::Path(t) => {
Type::Path(t) | Type::TypeAlias(t) => {
let Some(item_id) = t.rustdoc_id else {
unreachable!()
};
Expand Down
6 changes: 4 additions & 2 deletions compiler/pavexc/src/compiler/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustdoc_types::{GenericParamDefKind, ItemEnum, Type as RustdocType};

use crate::language::{PathType, Type};
use crate::rustdoc::{Crate, CrateCollection};
use rustdoc_resolver::{GenericBindings, resolve_type};
use rustdoc_resolver::{GenericBindings, TypeAliasResolution, resolve_type};

/// It returns an error if `type_` doesn't implement the specified trait.
///
Expand Down Expand Up @@ -81,7 +81,7 @@ pub(crate) fn implements_trait(
// We start by checking if there is a trait implementation for this type in the crate where the
// type was defined.
match type_ {
Type::Path(our_path_type) => {
Type::Path(our_path_type) | Type::TypeAlias(our_path_type) => {
let type_definition_crate =
get_crate_by_package_id(krate_collection, &our_path_type.package_id)?;
let type_id = type_definition_crate
Expand All @@ -102,6 +102,7 @@ pub(crate) fn implements_trait(
&our_path_type.package_id,
krate_collection,
&generic_bindings,
TypeAliasResolution::ResolveThrough,
)?;
generic_bindings
.types
Expand All @@ -122,6 +123,7 @@ pub(crate) fn implements_trait(
&our_path_type.package_id,
krate_collection,
&generic_bindings,
TypeAliasResolution::ResolveThrough,
)?;
if implements_trait(krate_collection, &type_, expected_trait)? {
return Ok(true);
Expand Down
3 changes: 3 additions & 0 deletions rustdoc/rustdoc_ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ pub enum Type {
FunctionPointer(FunctionPointer),
/// An unassigned generic type parameter, e.g. `T`.
Generic(Generic),
/// A type alias, preserving the alias identity rather than resolving through.
/// Contains the alias's path (package, base_type, generic arguments).
TypeAlias(PathType),
}
2 changes: 1 addition & 1 deletion rustdoc/rustdoc_ir/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Type {
/// [`Type::render_with_inferred_lifetimes_into`], and [`Type::display_for_error_into`].
pub(crate) fn render_into<W: fmt::Write>(&self, config: &RenderConfig<'_>, buffer: &mut W) {
match self {
Type::Path(t) => {
Type::Path(t) | Type::TypeAlias(t) => {
match config.path {
PathStyle::CrateLookup(id2name) => {
let crate_name = id2name
Expand Down
38 changes: 22 additions & 16 deletions rustdoc/rustdoc_ir/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ impl Type {
/// `t`. You are not required to bind all of them.
pub fn bind_generic_type_parameters(&self, bindings: &HashMap<String, Type>) -> Type {
match self {
Type::Path(t) => {
Type::Path(t) | Type::TypeAlias(t) => {
let is_alias = matches!(self, Type::TypeAlias(_));
let mut bound_generics = Vec::with_capacity(t.generic_arguments.len());
for generic in &t.generic_arguments {
let bound_generic = match generic {
Expand All @@ -71,13 +72,14 @@ impl Type {
};
bound_generics.push(bound_generic);
}
Type::Path(PathType {
let path = PathType {
package_id: t.package_id.clone(),
// Should we set this to `None`?
rustdoc_id: t.rustdoc_id,
base_type: t.base_type.clone(),
generic_arguments: bound_generics,
})
};
if is_alias { Type::TypeAlias(path) } else { Type::Path(path) }
}
Type::Reference(r) => Type::Reference(TypeReference {
is_mutable: r.is_mutable,
Expand Down Expand Up @@ -131,7 +133,7 @@ impl Type {
/// Check if a type can be used as a "template"—i.e. if it has any unassigned generic parameters.
pub fn is_a_template(&self) -> bool {
match self {
Type::Path(path) => path.generic_arguments.iter().any(|arg| match arg {
Type::Path(path) | Type::TypeAlias(path) => path.generic_arguments.iter().any(|arg| match arg {
GenericArgument::TypeParameter(g) => g.is_a_template(),
GenericArgument::Lifetime(
GenericLifetimeParameter::Static
Expand Down Expand Up @@ -164,7 +166,7 @@ impl Type {

fn _unassigned_generic_type_parameters(&self, set: &mut IndexSet<String>) {
match self {
Type::Path(path) => {
Type::Path(path) | Type::TypeAlias(path) => {
for arg in &path.generic_arguments {
match arg {
GenericArgument::TypeParameter(g) => {
Expand Down Expand Up @@ -225,7 +227,8 @@ impl Type {
}
use Type::*;
match (concrete_type, self) {
(Path(concrete_path), Path(templated_path)) => {
(Path(concrete_path), Path(templated_path))
| (TypeAlias(concrete_path), TypeAlias(templated_path)) => {
templated_path._is_a_resolved_path_type_template_for(concrete_path, bindings)
}
(Slice(concrete_slice), Slice(templated_slice)) => templated_slice
Expand Down Expand Up @@ -331,7 +334,8 @@ impl Type {
) -> bool {
use Type::*;
match (self, other) {
(Path(self_path), Path(other_path)) => {
(Path(self_path), Path(other_path))
| (TypeAlias(self_path), TypeAlias(other_path)) => {
self_path._is_equivalent_to(other_path, self_id_gen, other_id_gen)
}
(Slice(self_slice), Slice(other_slice)) => self_slice.element_type._is_equivalent_to(
Expand Down Expand Up @@ -404,7 +408,7 @@ impl Type {
/// E.g. `&'_ str` and `&str` would both return `true`. `&'static str` or `&'a str` wouldn't.
pub fn has_implicit_lifetime_parameters(&self) -> bool {
match self {
Type::Path(path) => path.generic_arguments.iter().any(|arg| match arg {
Type::Path(path) | Type::TypeAlias(path) => path.generic_arguments.iter().any(|arg| match arg {
GenericArgument::TypeParameter(g) => g.has_implicit_lifetime_parameters(),
GenericArgument::Lifetime(GenericLifetimeParameter::Inferred) => true,
GenericArgument::Lifetime(
Expand Down Expand Up @@ -448,7 +452,7 @@ impl Type {
/// the provided named lifetime.
pub fn set_implicit_lifetimes(&mut self, inferred_lifetime: String) {
match self {
Type::Path(path) => {
Type::Path(path) | Type::TypeAlias(path) => {
for arg in path.generic_arguments.iter_mut() {
match arg {
GenericArgument::Lifetime(lifetime) => {
Expand Down Expand Up @@ -499,7 +503,7 @@ impl Type {
/// You don't need to provide a mapping for lifetimes that you don't want to rename.
pub fn rename_lifetime_parameters(&mut self, original2renamed: &IndexMap<String, String>) {
match self {
Type::Path(t) => {
Type::Path(t) | Type::TypeAlias(t) => {
for arg in t.generic_arguments.iter_mut() {
match arg {
GenericArgument::TypeParameter(tp) => {
Expand Down Expand Up @@ -561,7 +565,7 @@ impl Type {

fn _lifetime_parameters(&self, set: &mut IndexSet<Lifetime>) {
match self {
Type::Path(path) => {
Type::Path(path) | Type::TypeAlias(path) => {
for arg in &path.generic_arguments {
match arg {
GenericArgument::TypeParameter(g) => {
Expand Down Expand Up @@ -606,7 +610,7 @@ impl Type {

fn _named_lifetime_parameters(&self, set: &mut IndexSet<String>) {
match self {
Type::Path(path) => {
Type::Path(path) | Type::TypeAlias(path) => {
for arg in &path.generic_arguments {
match arg {
GenericArgument::TypeParameter(g) => {
Expand Down Expand Up @@ -726,7 +730,8 @@ impl Type {
}

match self {
Type::Path(t) => {
Type::Path(t) | Type::TypeAlias(t) => {
let is_alias = matches!(self, Type::TypeAlias(_));
let generic_arguments = t
.generic_arguments
.iter()
Expand All @@ -743,12 +748,13 @@ impl Type {
),
})
.collect();
Type::Path(PathType {
let path = PathType {
package_id: t.package_id.clone(),
rustdoc_id: t.rustdoc_id,
base_type: t.base_type.clone(),
generic_arguments,
})
};
if is_alias { Type::TypeAlias(path) } else { Type::Path(path) }
}
Type::Reference(r) => Type::Reference(TypeReference {
is_mutable: r.is_mutable,
Expand Down Expand Up @@ -818,7 +824,7 @@ impl Type {
impl Debug for Type {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Type::Path(t) => write!(f, "{t:?}"),
Type::Path(t) | Type::TypeAlias(t) => write!(f, "{t:?}"),
Type::Reference(r) => write!(f, "{r:?}"),
Type::Tuple(t) => write!(f, "{t:?}"),
Type::ScalarPrimitive(s) => write!(f, "{s:?}"),
Expand Down
4 changes: 3 additions & 1 deletion rustdoc/rustdoc_resolver/src/free_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustdoc_processor::indexing::CrateIndexer;
use rustdoc_processor::queries::Crate;

use crate::errors::*;
use crate::resolve_type::resolve_type;
use crate::resolve_type::{TypeAliasResolution, resolve_type};

/// Convert a free function from `rustdoc_types` into a [`FreeFunction`].
pub fn resolve_free_function<I: CrateIndexer>(
Expand All @@ -35,6 +35,7 @@ pub fn resolve_free_function<I: CrateIndexer>(
&krate.core.package_id,
krate_collection,
&Default::default(),
TypeAliasResolution::ResolveThrough,
) {
Ok(t) => {
inputs.push(CallableInput {
Expand Down Expand Up @@ -62,6 +63,7 @@ pub fn resolve_free_function<I: CrateIndexer>(
&krate.core.package_id,
krate_collection,
&Default::default(),
TypeAliasResolution::ResolveThrough,
) {
Ok(t) => Some(t),
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion rustdoc/rustdoc_resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod type_def;
pub use errors::*;
pub use free_fn::resolve_free_function;
pub use method::rustdoc_method2callable;
pub use resolve_type::resolve_type;
pub use resolve_type::{TypeAliasResolution, resolve_type};
pub use type_def::{rustdoc_new_type_def2type, rustdoc_type_alias2type};

use ahash::HashMap;
Expand Down
6 changes: 5 additions & 1 deletion rustdoc/rustdoc_resolver/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustdoc_processor::queries::Crate;

use crate::GenericBindings;
use crate::errors::*;
use crate::resolve_type::resolve_type;
use crate::resolve_type::{TypeAliasResolution, resolve_type};

/// Convert a method item retrieved from `rustdoc`'s JSON output to Pavex's internal
/// representation for callables (i.e. methods and functions).
Expand Down Expand Up @@ -50,6 +50,7 @@ pub fn rustdoc_method2callable<I: CrateIndexer>(
&krate.core.package_id,
krate_collection,
&generic_bindings,
TypeAliasResolution::ResolveThrough,
) {
Ok(t) => t,
Err(e) => {
Expand Down Expand Up @@ -110,6 +111,7 @@ pub fn rustdoc_method2callable<I: CrateIndexer>(
&krate.core.package_id,
krate_collection,
&generic_bindings,
TypeAliasResolution::ResolveThrough,
) else {
todo!()
};
Expand Down Expand Up @@ -178,6 +180,7 @@ pub fn rustdoc_method2callable<I: CrateIndexer>(
&krate.core.package_id,
krate_collection,
&generic_bindings,
TypeAliasResolution::ResolveThrough,
) {
Ok(t) => {
inputs.push(CallableInput {
Expand Down Expand Up @@ -205,6 +208,7 @@ pub fn rustdoc_method2callable<I: CrateIndexer>(
&krate.core.package_id,
krate_collection,
&generic_bindings,
TypeAliasResolution::ResolveThrough,
) {
Ok(t) => Some(t),
Err(e) => {
Expand Down
Loading
Loading