Improve tree queries' ability to handle large numbers of nested matches (#624)

* query: Acquire capture lists lazily, allow more concurrent states

* Fix some static analysis warnings
This commit is contained in:
Max Brunsfeld 2020-05-18 13:40:24 -07:00 committed by GitHub
parent 7b39420de3
commit 462c86903f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 165 additions and 88 deletions

View file

@ -339,7 +339,7 @@ fn test_query_matches_with_nesting_and_no_fields() {
}
#[test]
fn test_query_matches_with_many() {
fn test_query_matches_with_many_results() {
allocations::record(|| {
let language = get_language("javascript");
let query = Query::new(language, "(array (identifier) @element)").unwrap();
@ -353,6 +353,47 @@ fn test_query_matches_with_many() {
});
}
#[test]
fn test_query_matches_with_many_overlapping_results() {
allocations::record(|| {
let language = get_language("javascript");
let query = Query::new(
language,
r#"
(call_expression
function: (member_expression
property: (property_identifier) @method))
(call_expression
function: (identifier) @function)
((identifier) @constant
(#match? @constant "[A-Z\\d_]+"))
"#
).unwrap();
let count = 80;
// Deeply nested chained function calls:
// a
// .foo(bar(BAZ))
// .foo(bar(BAZ))
// .foo(bar(BAZ))
// ...
let mut source = "a".to_string();
source += &"\n .foo(bar(BAZ))".repeat(count);
assert_query_matches(
language,
&query,
&source,
&[
(0, vec![("method", "foo")]),
(1, vec![("function", "bar")]),
(2, vec![("constant", "BAZ")])
].iter().cloned().cycle().take(3 * count).collect::<Vec<_>>(),
);
});
}
#[test]
fn test_query_matches_capturing_error_nodes() {
allocations::record(|| {