Skip to content

Commit 3517ba9

Browse files
feat: Make the resolution behaviour for type aliases configurable by the caller
1 parent a0e5879 commit 3517ba9

19 files changed

Lines changed: 112 additions & 41 deletions

File tree

compiler/pavexc/src/compiler/analyses/application_state/cloning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) fn runtime_singletons_can_be_cloned_if_needed<'a>(
6161
| Type::FunctionPointer(_) => {
6262
return None;
6363
}
64-
Type::Path(_) | Type::Tuple(_) => {}
64+
Type::Path(_) | Type::TypeAlias(_) | Type::Tuple(_) => {}
6565
Type::Generic(_) => unreachable!(),
6666
};
6767
let InputParameterSource::Component(id) = source else {

compiler/pavexc/src/compiler/analyses/application_state/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn field_name_candidate(ty_: &Type, strategy: NamingStrategy) -> String {
226226

227227
fn _field_name_candidate(ty_: &Type, strategy: NamingStrategy, candidate: &mut String) {
228228
match ty_ {
229-
Type::Path(path_type) => match strategy {
229+
Type::Path(path_type) | Type::TypeAlias(path_type) => match strategy {
230230
NamingStrategy::LastSegment => {
231231
let last = path_type
232232
.base_type

compiler/pavexc/src/compiler/analyses/processing_pipeline/codegen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ impl CodegenedRequestHandlerPipeline {
393393
Type::Slice(_)
394394
| Type::Array(_)
395395
| Type::Path(_)
396+
| Type::TypeAlias(_)
396397
| Type::Tuple(_)
397398
| Type::ScalarPrimitive(_)
398399
| Type::RawPointer(_)

compiler/pavexc/src/compiler/analyses/processing_pipeline/pipeline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ impl RequestHandlerPipeline {
507507
}
508508
}
509509
Type::Path(_) |
510+
Type::TypeAlias(_) |
510511
Type::Tuple(_) |
511512
Type::Array(_) => {
512513
type2info.entry(ty.clone()).or_default().consumed_by.push(ConsumerInfo { middleware_index: index, component_id });

compiler/pavexc/src/compiler/analyses/user_components/annotations/coordinates.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::{
1414
use crate::compiler::analyses::user_components::{UserComponent, UserComponentId};
1515
use crate::compiler::component::{DefaultStrategy, PrebuiltType};
1616
use pavex_bp_schema::{CloningPolicy, Lint, LintSetting};
17-
use rustdoc_resolver::{resolve_free_function, rustdoc_method2callable};
17+
use rustdoc_resolver::{TypeAliasResolution, resolve_free_function, rustdoc_method2callable};
1818

1919
/// Resolve coordinates to the annotation they point to.
2020
/// Then process the corresponding item.
@@ -212,9 +212,9 @@ pub(crate) fn resolve_annotation_coordinates(
212212

213213
let outcome = match annotation.impl_ {
214214
Some(ImplInfo { attached_to, impl_ }) => {
215-
rustdoc_method2callable(attached_to, impl_, &item, krate, krate_collection)
215+
rustdoc_method2callable(attached_to, impl_, &item, krate, krate_collection, TypeAliasResolution::ResolveThrough)
216216
}
217-
None => resolve_free_function(&item, krate, krate_collection)
217+
None => resolve_free_function(&item, krate, krate_collection, TypeAliasResolution::ResolveThrough)
218218
.map(rustdoc_ir::Callable::FreeFunction),
219219
};
220220
let callable = match outcome {

compiler/pavexc/src/compiler/analyses/user_components/annotations/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use pavex_bp_schema::{CloningPolicy, Lifecycle, Lint, LintSetting};
3333
use pavexc_attr_parser::{AnnotationKind, AnnotationProperties};
3434
use rustdoc_ext::RustdocKindExt;
3535
use rustdoc_resolver::{
36-
resolve_free_function, rustdoc_method2callable, rustdoc_new_type_def2type,
37-
rustdoc_type_alias2type,
36+
TypeAliasResolution, resolve_free_function, rustdoc_method2callable,
37+
rustdoc_new_type_def2type, rustdoc_type_alias2type,
3838
};
3939
use rustdoc_types::{Item, ItemEnum};
4040

@@ -179,9 +179,9 @@ pub(super) fn register_imported_components(
179179

180180
let outcome = match annotation.impl_ {
181181
Some(ImplInfo { attached_to, impl_ }) => {
182-
rustdoc_method2callable(attached_to, impl_, &item, krate, krate_collection)
182+
rustdoc_method2callable(attached_to, impl_, &item, krate, krate_collection, TypeAliasResolution::ResolveThrough)
183183
}
184-
None => resolve_free_function(&item, krate, krate_collection)
184+
None => resolve_free_function(&item, krate, krate_collection, TypeAliasResolution::ResolveThrough)
185185
.map(rustdoc_ir::Callable::FreeFunction),
186186
};
187187
let callable = match outcome {
@@ -521,7 +521,7 @@ fn rustdoc_item_def2type(
521521
Err(())
522522
}
523523
},
524-
ItemEnum::TypeAlias(_) => match rustdoc_type_alias2type(item, krate, krate_collection) {
524+
ItemEnum::TypeAlias(_) => match rustdoc_type_alias2type(item, krate, krate_collection, TypeAliasResolution::ResolveThrough) {
525525
Ok(t) => Ok(t),
526526
Err(e) => {
527527
type_resolution_error(e, item, diagnostics);

compiler/pavexc/src/compiler/codegen/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ fn collect_callable_package_ids(package_ids: &mut IndexSet<PackageId>, c: &Calla
459459

460460
fn collect_type_package_ids(package_ids: &mut IndexSet<PackageId>, t: &Type) {
461461
match t {
462-
Type::Path(t) => {
462+
Type::Path(t) | Type::TypeAlias(t) => {
463463
package_ids.insert(t.package_id.clone());
464464
for generic in &t.generic_arguments {
465465
match generic {

compiler/pavexc/src/compiler/codegen/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub(super) fn get_application_state_new(
134134
Type::Slice(_)
135135
| Type::Array(_)
136136
| Type::Path(_)
137+
| Type::TypeAlias(_)
137138
| Type::Tuple(_)
138139
| Type::ScalarPrimitive(_)
139140
| Type::RawPointer(_)

compiler/pavexc/src/compiler/framework_rustdoc.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::rustdoc::{CannotGetCrateData, CrateCollection};
1010
use rustdoc_ext::GlobalItemId;
1111
use rustdoc_ir::{CallableInput, FnHeader, RustIdentifier, TraitMethod, TraitMethodPath};
1212
use rustdoc_processor::queries::Crate;
13-
use rustdoc_resolver::{GenericBindings, resolve_type};
13+
use rustdoc_resolver::{GenericBindings, TypeAliasResolution, resolve_type};
1414

1515
use super::app::PAVEX_VERSION;
1616

@@ -157,6 +157,7 @@ pub(crate) fn resolve_type_path(raw_path: &str, krate_collection: &CrateCollecti
157157
&global_id.package_id,
158158
krate_collection,
159159
&GenericBindings::default(),
160+
TypeAliasResolution::ResolveThrough,
160161
)
161162
.expect("Failed to resolve default generic type");
162163
GenericArgument::TypeParameter(default)
@@ -198,7 +199,7 @@ pub(crate) fn resolve_framework_free_function(
198199
.unwrap_or_else(|e| panic!("Unknown free function path {}: {e:?}", segments.join("::")));
199200

200201
let item = krate.get_item_by_local_type_id(&global_id.rustdoc_item_id);
201-
let free_fn = rustdoc_resolver::resolve_free_function(&item, krate, krate_collection)
202+
let free_fn = rustdoc_resolver::resolve_free_function(&item, krate, krate_collection, TypeAliasResolution::ResolveThrough)
202203
.expect("Failed to resolve free function");
203204
Callable::FreeFunction(free_fn)
204205
}
@@ -249,6 +250,7 @@ pub(crate) fn resolve_framework_inherent_method(
249250
&item,
250251
krate,
251252
krate_collection,
253+
TypeAliasResolution::ResolveThrough,
252254
)
253255
.expect("Failed to resolve inherent method");
254256
return callable;
@@ -334,6 +336,7 @@ pub(crate) fn resolve_framework_trait_method(
334336
&krate.core.package_id,
335337
krate_collection,
336338
&generic_bindings,
339+
TypeAliasResolution::ResolveThrough,
337340
)
338341
.map_err(|e| {
339342
anyhow::anyhow!(
@@ -357,6 +360,7 @@ pub(crate) fn resolve_framework_trait_method(
357360
&krate.core.package_id,
358361
krate_collection,
359362
&generic_bindings,
363+
TypeAliasResolution::ResolveThrough,
360364
)
361365
.map_err(|e| {
362366
anyhow::anyhow!(

compiler/pavexc/src/compiler/path_parameters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fn must_be_a_plain_struct(
266266
extracted_type: &Type,
267267
) -> Result<rustdoc_types::Item, ()> {
268268
let error_suffix = match extracted_type {
269-
Type::Path(t) => {
269+
Type::Path(t) | Type::TypeAlias(t) => {
270270
let Some(item_id) = t.rustdoc_id else {
271271
unreachable!()
272272
};

0 commit comments

Comments
 (0)