Skip to content

Commit

Permalink
fix: Pavex will correctly set the name of the defining crate when res…
Browse files Browse the repository at this point in the history
…olving local type aliases that refer to remote types
  • Loading branch information
LukeMathWalker committed Oct 24, 2024
1 parent 6804790 commit 97cdaf3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
37 changes: 14 additions & 23 deletions libs/pavexc/src/compiler/resolvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,12 @@ pub(crate) fn resolve_callable(
Some((parent, parent_path)) => {
match krate_collection.get_canonical_path_by_global_type_id(&parent.item_id) {
Ok(canonical_segments) => {
let segments =
canonical_segments
.into_iter()
.skip(1)
.map(|s| ResolvedPathSegment {
ident: s.into(),
generic_arguments: vec![],
});
// We use the first segment from the original path, since that's been resolved to the name of the defining crate
// and we want to keep that information.
let mut segments: Vec<_> = std::iter::once(parent_path.segments[0].clone())
.chain(segments)
let mut segments: Vec<_> = canonical_segments
.into_iter()
.map(|s| ResolvedPathSegment {
ident: s.into(),
generic_arguments: vec![],
})
.collect();
// The canonical path doesn't include the (populated or omitted) generic arguments from the user-provided path,
// so we need to add them back in.
Expand Down Expand Up @@ -490,24 +484,21 @@ pub(crate) fn resolve_callable(
ResolvedPath {
segments,
qualified_self: callable_path.qualified_self.clone(),
package_id: callable_path.package_id.clone(),
package_id: p.package_id.clone(),
}
}
None => {
// There was no parent, it's a free function or a straight struct/enum. We need to go through the same process
// we applied for the parent.
match krate_collection.get_canonical_path_by_global_type_id(&callable.item_id) {
Ok(p) => {
let segments = p.into_iter().skip(1).map(|s| ResolvedPathSegment {
ident: s.into(),
generic_arguments: vec![],
});
// We use the first segment from the original callable path, since that's been resolved to the defining crate
// and we want to keep that information.
let mut segments: Vec<_> =
std::iter::once(callable_path.segments[0].clone())
.chain(segments)
.collect();
let mut segments: Vec<_> = p
.into_iter()
.map(|s| ResolvedPathSegment {
ident: s.into(),
generic_arguments: vec![],
})
.collect();
// The canonical path doesn't include the (populated or omitted) generic arguments from the user-provided callable path,
// so we need to add them back in.
segments.last_mut().unwrap().generic_arguments = callable_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ digraph "* /home - 1" {
digraph app_state {
0 [ label = "crate::ApplicationState((bool, char, u8), dep_f8f62968::ActualType) -> crate::ApplicationState"]
1 [ label = "app_f8f62968::constructor_with_output_tuple() -> (bool, char, u8)"]
2 [ label = "app_f8f62968::RemoteAlias::new() -> dep_f8f62968::ActualType"]
2 [ label = "dep_f8f62968::ActualType::new() -> dep_f8f62968::ActualType"]
2 -> 0 [ ]
1 -> 0 [ ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct ApplicationState {
s1: dep_f8f62968::ActualType,
}
pub async fn build_application_state() -> crate::ApplicationState {
let v0 = app::RemoteAlias::new();
let v0 = dep_f8f62968::ActualType::new();
let v1 = app::constructor_with_output_tuple();
crate::ApplicationState {
s0: v1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ digraph "* /home - 1" {
digraph app_state {
0 [ label = "crate::ApplicationState((bool, char, u8), dep_f8f62968::ActualType) -> crate::ApplicationState"]
1 [ label = "app::constructor_with_output_tuple() -> (bool, char, u8)"]
2 [ label = "app::RemoteAlias::new() -> dep_f8f62968::ActualType"]
2 [ label = "dep_f8f62968::ActualType::new() -> dep_f8f62968::ActualType"]
2 -> 0 [ ]
1 -> 0 [ ]
}

0 comments on commit 97cdaf3

Please sign in to comment.