Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 2a75ad4

Browse files
Merge pull request #208 from github/friendly-getfile
2 parents edd96b3 + 05de46e commit 2a75ad4

11 files changed

+18
-11
lines changed

stack-graphs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- New `Defines` and `Refers` assertions test for the presence of definitions and references, respectively, without resolution.
13+
- A method `StackGraph::get_file` to look up an existing file.
1314

1415
### Changed
1516

1617
- The `IncorrectDefinitions` error is renamed to `IncorrectlyDefined`, and `IncorrectDefinitions` is the error used for the `Defines` assertion.
1718
- The `PartialPaths::find_all_partial_paths_in_file` method has been replaced by `PartialPaths::find_minimal_partial_path_set_in_file`, which computes a smaller set. The `ForwardPartialPathStitcher::find_locally_maximal_partial_path_set` function can be used to compute the set previously returned by `find_all_partial_paths_in_file` from the minimal partial path set.
1819

20+
### Removed
21+
22+
- The method `StackGraph::get_file_unchecked` is removed. Use the new `StackGraph::get_file` instead.
23+
1924
## v0.10.2 -- 2023-01-10
2025

2126
### Changed

stack-graphs/src/graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ impl StackGraph {
359359

360360
/// Returns the file with a particular name. Panics if there is no file with the requested
361361
/// name.
362-
pub fn get_file_unchecked<S: AsRef<str> + ?Sized>(&self, name: &S) -> Handle<File> {
362+
pub fn get_file<S: AsRef<str> + ?Sized>(&self, name: &S) -> Option<Handle<File>> {
363363
let name = name.as_ref();
364-
self.file_handles.get(name).copied().expect("Missing file")
364+
self.file_handles.get(name).copied()
365365
}
366366
}
367367

stack-graphs/tests/it/c/can_find_local_nodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::test_graphs;
2929

3030
fn check_local_nodes(graph: &TestGraph, file: &str, expected_local_nodes: &[&str]) {
3131
let rust_graph = unsafe { &(*graph.graph).inner };
32-
let file = rust_graph.get_file_unchecked(file);
32+
let file = rust_graph.get_file(file).expect("Missing file");
3333

3434
let partials = sg_partial_path_arena_new();
3535
let path_list = sg_partial_path_list_new();

stack-graphs/tests/it/c/can_find_partial_paths_in_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn partial_path_edge_list_available_in_both_directions(
7373

7474
fn check_partial_paths_in_file(graph: &TestGraph, file: &str, expected_paths: &[&str]) {
7575
let rust_graph = unsafe { &(*graph.graph).inner };
76-
let file = rust_graph.get_file_unchecked(file);
76+
let file = rust_graph.get_file(file).expect("Missing file");
7777

7878
let partials = sg_partial_path_arena_new();
7979
let path_list = sg_partial_path_list_new();

stack-graphs/tests/it/c/can_jump_to_definition_with_phased_partial_path_stitching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl StorageLayer {
104104

105105
fn check_jump_to_definition(graph: &TestGraph, file: &str, expected_partial_paths: &[&str]) {
106106
let rust_graph = unsafe { &(*graph.graph).inner };
107-
let file = rust_graph.get_file_unchecked(file);
107+
let file = rust_graph.get_file(file).expect("Missing file");
108108
let partials = sg_partial_path_arena_new();
109109
let rust_partials = unsafe { &mut (*partials).inner };
110110
let db = sg_partial_path_database_new();

stack-graphs/tests/it/c/can_jump_to_definition_with_phased_path_stitching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl StorageLayer {
107107

108108
fn check_jump_to_definition(graph: &TestGraph, file: &str, expected_paths: &[&str]) {
109109
let rust_graph = unsafe { &(*graph.graph).inner };
110-
let file = rust_graph.get_file_unchecked(file);
110+
let file = rust_graph.get_file(file).expect("Missing file");
111111
let paths = sg_path_arena_new();
112112
let rust_paths = unsafe { &mut (*paths).inner };
113113
let partials = sg_partial_path_arena_new();

stack-graphs/tests/it/can_find_local_nodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use stack_graphs::NoCancellation;
1616
use crate::test_graphs;
1717

1818
fn check_local_nodes(graph: &StackGraph, file: &str, expected_local_nodes: &[&str]) {
19-
let file = graph.get_file_unchecked(file);
19+
let file = graph.get_file(file).expect("Missing file");
2020
let mut partials = PartialPaths::new();
2121
let mut database = Database::new();
2222
partials

stack-graphs/tests/it/can_find_node_partial_paths_in_database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn check_node_partial_paths(
2323
id: (&str, u32),
2424
expected_partial_paths: &[&str],
2525
) {
26-
let file = graph.get_file_unchecked(id.0);
26+
let file = graph.get_file(id.0).expect("Missing file");
2727
let id = NodeID::new_in_file(file, id.1);
2828
let node = graph.node_for_id(id).expect("Cannot find node");
2929
let mut partials = PartialPaths::new();

stack-graphs/tests/it/can_find_partial_paths_in_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use stack_graphs::NoCancellation;
1515
use crate::test_graphs;
1616

1717
fn check_partial_paths_in_file(graph: &StackGraph, file: &str, expected_paths: &[&str]) {
18-
let file = graph.get_file_unchecked(file);
18+
let file = graph.get_file(file).expect("Missing file");
1919
let mut partials = PartialPaths::new();
2020
let mut results = BTreeSet::new();
2121
partials

stack-graphs/tests/it/can_find_root_partial_paths_in_database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn check_root_partial_paths(
2828
precondition: &[&str],
2929
expected_partial_paths: &[&str],
3030
) {
31-
let file = graph.get_file_unchecked(file);
31+
let file = graph.get_file(file).expect("Missing file");
3232
let mut paths = Paths::new();
3333
let mut partials = PartialPaths::new();
3434
let mut db = Database::new();

0 commit comments

Comments
 (0)