Skip to content

Commit 294596a

Browse files
Change setting name and add comment explaining the consequences
1 parent 3d32fbb commit 294596a

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

languages/tree-sitter-stack-graphs-typescript/rust/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ pub fn try_language_configuration(
5757
lc.special_files
5858
.add("tsconfig.json".to_string(), TsConfigAnalyzer {})
5959
.add("package.json".to_string(), NpmPackageAnalyzer {});
60-
lc.has_similar_paths = false;
60+
lc.no_similar_paths_in_file = true;
6161
Ok(lc)
6262
}

stack-graphs/src/stitching.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ impl<H> ForwardPartialPathStitcher<H> {
870870
initial_paths: next_iteration.0.len(),
871871
next_iteration,
872872
appended_paths,
873+
// By default, all paths are checked for similarity
873874
similar_path_detector: Some(SimilarPathDetector::new()),
874875
// By default, all nodes are checked for cycles and (if enabled) similarity
875876
check_only_join_nodes: false,

tree-sitter-stack-graphs/src/cli/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl<'a> Indexer<'a> {
281281
Err(e) => return Err(IndexError::LoadError(e)),
282282
};
283283
let stitcher_config =
284-
StitcherConfig::default().with_detect_similar_paths(lcs.has_similar_paths());
284+
StitcherConfig::default().with_detect_similar_paths(!lcs.no_similar_paths_in_file());
285285

286286
let source = file_reader.get(source_path)?;
287287
let tag = sha1(source);

tree-sitter-stack-graphs/src/cli/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl TestArgs {
326326
}
327327
}
328328
let stitcher_config =
329-
StitcherConfig::default().with_detect_similar_paths(lc.has_similar_paths);
329+
StitcherConfig::default().with_detect_similar_paths(!lc.no_similar_paths_in_file);
330330
let mut partials = PartialPaths::new();
331331
let mut db = Database::new();
332332
for file in test.graph.iter_files() {

tree-sitter-stack-graphs/src/loader.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ pub struct LanguageConfiguration {
4444
pub sgl: StackGraphLanguage,
4545
pub builtins: StackGraph,
4646
pub special_files: FileAnalyzers,
47-
pub has_similar_paths: bool,
47+
/// Can be set to true if the stack graph rules ensure that there can be no similar
48+
/// paths in a file, in which case it is safe to turn of similar path detection. If
49+
/// incorrectly set to true, performance of path finding suffers from exponential
50+
/// blow up.
51+
pub no_similar_paths_in_file: bool,
4852
}
4953

5054
impl LanguageConfiguration {
@@ -98,7 +102,7 @@ impl LanguageConfiguration {
98102
sgl,
99103
builtins,
100104
special_files: FileAnalyzers::new(),
101-
has_similar_paths: true,
105+
no_similar_paths_in_file: false,
102106
})
103107
}
104108

@@ -369,18 +373,15 @@ impl FileLanguageConfigurations<'_> {
369373
self.primary.is_some() || !self.secondary.is_empty()
370374
}
371375

372-
pub fn has_similar_paths(&self) -> bool {
376+
pub fn no_similar_paths_in_file(&self) -> bool {
377+
let mut no_similar_paths_in_file = true;
373378
if let Some(lc) = &self.primary {
374-
if lc.has_similar_paths {
375-
return true;
376-
}
379+
no_similar_paths_in_file &= lc.no_similar_paths_in_file;
377380
}
378381
for (lc, _) in &self.secondary {
379-
if lc.has_similar_paths {
380-
return true;
381-
}
382+
no_similar_paths_in_file &= lc.no_similar_paths_in_file;
382383
}
383-
return false;
384+
return no_similar_paths_in_file;
384385
}
385386
}
386387

@@ -593,7 +594,7 @@ impl PathLoader {
593594
builtins,
594595
special_files: FileAnalyzers::new(),
595596
// always detect similar paths, we don't know the language configuration when loading from the file system
596-
has_similar_paths: true,
597+
no_similar_paths_in_file: false,
597598
};
598599
self.cache.push((language.language, lc));
599600

tree-sitter-stack-graphs/tests/it/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn can_load_from_provided_language_configuration() {
3535
sgl,
3636
builtins: StackGraph::new(),
3737
special_files: FileAnalyzers::new(),
38-
has_similar_paths: true,
38+
no_similar_paths_in_file: false,
3939
};
4040
let mut loader =
4141
Loader::from_language_configurations(vec![lc], None).expect("Expected loader to succeed");

0 commit comments

Comments
 (0)