Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crate item lookup by import path for @optional import paths. #677

Merged
merged 1 commit into from
Dec 18, 2024
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
4 changes: 2 additions & 2 deletions src/adapter/optimizations/item_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub(crate) fn resolve_crate_items<'a, V: AsVertex<Vertex<'a>> + 'a>(
) -> ContextOutcomeIterator<'a, V, VertexIterator<'a, Vertex<'a>>> {
let destination = resolve_info.destination();

// Is the `importable_path` edge being resolved in a subsequent step?
// Is the `importable_path` edge being resolved in a mandatory fashion in a subsequent step?
if let Some(neighbor_info) = destination
.first_edge("importable_path")
.first_mandatory_edge("importable_path")
.as_ref()
.map(|x| x.destination())
{
Expand Down
60 changes: 60 additions & 0 deletions src/adapter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3941,3 +3941,63 @@ fn extern_fn() {
expected_results.sort_unstable();
similar_asserts::assert_eq!(expected_results, results);
}

#[test]
fn item_lookup_by_path_optimization() {
// Any test crate with non-public top-level items would work for this test.
get_test_data!(data, associated_consts);
let adapter = RustdocAdapter::new(&data, None);
let adapter = Arc::new(&adapter);

let query = r#"
{
Crate {
item {
... on Function {
name @output

# Since this edge is optional, this query matches:
# - functions with an importable path matching the filter, and
# - functions that *do not have* importable paths at all.
#
# Failure to return both of these means we have a bug in
# the "item lookup by importable path" optimization code path.
importable_path @optional {
public_api @output
path @output @filter(op: "=", value: ["$path"])
}
}
}
}
}
"#;

let variables = btreemap! {
"path" => vec!["associated_consts", "will_not_match", "anything"],
};

let schema =
Schema::parse(include_str!("../rustdoc_schema.graphql")).expect("schema failed to parse");

#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, serde::Deserialize)]
struct Output {
name: String,
public_api: Option<bool>,
path: Option<Vec<String>>,
}

let mut results: Vec<_> =
trustfall::execute_query(&schema, adapter.clone(), query, variables.clone())
.expect("failed to run query")
.map(|row| row.try_into_struct().expect("shape mismatch"))
.collect();
results.sort_unstable();

let mut expected_results = vec![Output {
name: "min_batch_size".into(),
public_api: None,
path: None,
}];
expected_results.sort_unstable();
similar_asserts::assert_eq!(expected_results, results);
}
Loading