From c2df61c71ff098bd99a34d297d0cfb6def48f4ef Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Tue, 10 Dec 2024 14:51:39 +0100 Subject: [PATCH 01/15] Upgrade tree-sitter dependency to 0.24 --- .../CHANGELOG.md | 6 + .../tree-sitter-stack-graphs-java/Cargo.toml | 6 +- .../tree-sitter-stack-graphs-java/README.md | 2 +- .../tree-sitter-stack-graphs-java/rust/lib.rs | 2 +- .../src/stack-graphs.tsg | 5 - .../CHANGELOG.md | 6 + .../Cargo.toml | 8 +- .../README.md | 2 +- .../rust/lib.rs | 2 +- .../CHANGELOG.md | 6 + .../Cargo.toml | 6 +- .../tree-sitter-stack-graphs-python/README.md | 2 +- .../rust/lib.rs | 2 +- .../Cargo.toml | 4 +- .../rust/lib.rs | 4 +- .../src/stack-graphs.tsg | 163 ++++++++---------- ...e_name.tsx => jsx_namespace_name.tsx.skip} | 0 ...mespace.ts => very-deep-namespace.ts.skip} | 0 ...namespace-by-fully-qualified-name.ts.skip} | 0 ...namespace-by-fully-qualified-name.ts.skip} | 0 lsp-positions/CHANGELOG.md | 4 + lsp-positions/Cargo.toml | 4 +- tree-sitter-stack-graphs/CHANGELOG.md | 5 +- tree-sitter-stack-graphs/Cargo.toml | 14 +- tree-sitter-stack-graphs/README.md | 2 +- tree-sitter-stack-graphs/src/cli/init.rs | 2 +- tree-sitter-stack-graphs/src/cli/load.rs | 2 +- tree-sitter-stack-graphs/src/cli/lsp.rs | 19 -- tree-sitter-stack-graphs/src/cli/match.rs | 2 +- tree-sitter-stack-graphs/src/cli/parse.rs | 4 +- tree-sitter-stack-graphs/src/cli/test.rs | 2 +- tree-sitter-stack-graphs/src/lib.rs | 10 +- tree-sitter-stack-graphs/src/loader.rs | 32 ++-- tree-sitter-stack-graphs/tests/it/builder.rs | 4 +- tree-sitter-stack-graphs/tests/it/loader.rs | 11 +- tree-sitter-stack-graphs/tests/it/main.rs | 2 +- tree-sitter-stack-graphs/tests/it/test.rs | 2 +- 37 files changed, 169 insertions(+), 178 deletions(-) rename languages/tree-sitter-stack-graphs-typescript/test/jsx/{jsx_namespace_name.tsx => jsx_namespace_name.tsx.skip} (100%) rename languages/tree-sitter-stack-graphs-typescript/test/modules/{very-deep-namespace.ts => very-deep-namespace.ts.skip} (100%) rename languages/tree-sitter-stack-graphs-typescript/test/statements/{refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts => refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts.skip} (100%) rename languages/tree-sitter-stack-graphs-typescript/test/statements/{refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts => refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts.skip} (100%) diff --git a/languages/tree-sitter-stack-graphs-java/CHANGELOG.md b/languages/tree-sitter-stack-graphs-java/CHANGELOG.md index 5691a4985..23400faf0 100644 --- a/languages/tree-sitter-stack-graphs-java/CHANGELOG.md +++ b/languages/tree-sitter-stack-graphs-java/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v0.5.0 -- Unreleased + +- The `tree-sitter-stack-graphs` dependency is updated to version 0.10. + +- The `tree-sitter-java` dependency is updated to version 0.23.4. + ## v0.4.0 -- 2024-07-09 ### Added diff --git a/languages/tree-sitter-stack-graphs-java/Cargo.toml b/languages/tree-sitter-stack-graphs-java/Cargo.toml index 96a44ab0f..0ad8cb687 100644 --- a/languages/tree-sitter-stack-graphs-java/Cargo.toml +++ b/languages/tree-sitter-stack-graphs-java/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tree-sitter-stack-graphs-java" -version = "0.4.0" +version = "0.5.0" description = "Stack graphs for the Java programming language" homepage = "https://github.com/github/stack-graphs/tree/main/languages/tree-sitter-stack-graphs-java" @@ -40,8 +40,8 @@ cli = ["anyhow", "clap", "tree-sitter-stack-graphs/cli"] [dependencies] anyhow = { version = "1.0", optional = true } clap = { version = "4", features = ["derive"], optional = true } -tree-sitter-java = { version = "=0.20.2" } -tree-sitter-stack-graphs = { version = "0.9", path = "../../tree-sitter-stack-graphs" } # explicit version is required to be able to publish crate +tree-sitter-java = { version = "=0.23.4" } +tree-sitter-stack-graphs = { version = "0.10", path = "../../tree-sitter-stack-graphs" } # explicit version is required to be able to publish crate [dev-dependencies] anyhow = { version = "1.0" } diff --git a/languages/tree-sitter-stack-graphs-java/README.md b/languages/tree-sitter-stack-graphs-java/README.md index 69d276118..97820ed3f 100644 --- a/languages/tree-sitter-stack-graphs-java/README.md +++ b/languages/tree-sitter-stack-graphs-java/README.md @@ -13,7 +13,7 @@ To use this library, add the following to your `Cargo.toml`: ```toml [dependencies] -tree-sitter-stack-graphs-java = "0.4" +tree-sitter-stack-graphs-java = "0.5" ``` Check out our [documentation](https://docs.rs/tree-sitter-stack-graphs-java/*/) for more details on how to use this library. diff --git a/languages/tree-sitter-stack-graphs-java/rust/lib.rs b/languages/tree-sitter-stack-graphs-java/rust/lib.rs index 14016b614..9b2cb39c8 100644 --- a/languages/tree-sitter-stack-graphs-java/rust/lib.rs +++ b/languages/tree-sitter-stack-graphs-java/rust/lib.rs @@ -25,7 +25,7 @@ pub fn try_language_configuration( cancellation_flag: &dyn CancellationFlag, ) -> Result { LanguageConfiguration::from_sources( - tree_sitter_java::language(), + tree_sitter_java::LANGUAGE.into(), Some(String::from("source.java")), None, vec![String::from("java")], diff --git a/languages/tree-sitter-stack-graphs-java/src/stack-graphs.tsg b/languages/tree-sitter-stack-graphs-java/src/stack-graphs.tsg index cfeab55de..5f3c72466 100644 --- a/languages/tree-sitter-stack-graphs-java/src/stack-graphs.tsg +++ b/languages/tree-sitter-stack-graphs-java/src/stack-graphs.tsg @@ -1078,10 +1078,6 @@ attribute node_symbol = node => symbol = (source-text node), source_n edge @child.lexical_scope -> @expr.lexical_scope } -(condition (_) @child) @expr { - edge @child.lexical_scope -> @expr.lexical_scope -} - ;; ============= ;; Expressions ;; ============= @@ -1111,7 +1107,6 @@ attribute node_symbol = node => symbol = (source-text node), source_n (this) ; (identifier) (parenthesized_expression) - (condition) (object_creation_expression) (field_access) (array_access) diff --git a/languages/tree-sitter-stack-graphs-javascript/CHANGELOG.md b/languages/tree-sitter-stack-graphs-javascript/CHANGELOG.md index 19730aeab..10f85abdd 100644 --- a/languages/tree-sitter-stack-graphs-javascript/CHANGELOG.md +++ b/languages/tree-sitter-stack-graphs-javascript/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v0.3.0 -- Unreleased + +- The `tree-sitter-stack-graphs` dependency is updated to version 0.10. + +- The `tree-sitter-javascript` dependency is updated to version 0.23.1. + ## v0.2.0 -- 2024-07-09 ### Removed diff --git a/languages/tree-sitter-stack-graphs-javascript/Cargo.toml b/languages/tree-sitter-stack-graphs-javascript/Cargo.toml index ca03e2f9b..d1206c6e5 100644 --- a/languages/tree-sitter-stack-graphs-javascript/Cargo.toml +++ b/languages/tree-sitter-stack-graphs-javascript/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tree-sitter-stack-graphs-javascript" -version = "0.2.0" +version = "0.3.0" description = "Stack graphs definition for JavaScript using tree-sitter-javascript" readme = "README.md" keywords = ["tree-sitter", "stack-graphs", "javascript"] @@ -31,9 +31,9 @@ clap = { version = "4", optional = true } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" stack-graphs = { version = "0.14", path = "../../stack-graphs" } # explicit version is required to be able to publish crate -tree-sitter-graph = "0.11.2" -tree-sitter-javascript = "=0.20.4" -tree-sitter-stack-graphs = { version = "0.9", path = "../../tree-sitter-stack-graphs" } # explicit version is required to be able to publish crate +tree-sitter-graph = "0.12" +tree-sitter-javascript = "=0.23.1" +tree-sitter-stack-graphs = { version = "0.10", path = "../../tree-sitter-stack-graphs" } # explicit version is required to be able to publish crate [dev-dependencies] anyhow = "1.0" diff --git a/languages/tree-sitter-stack-graphs-javascript/README.md b/languages/tree-sitter-stack-graphs-javascript/README.md index 099e633e9..c7eefa955 100644 --- a/languages/tree-sitter-stack-graphs-javascript/README.md +++ b/languages/tree-sitter-stack-graphs-javascript/README.md @@ -13,7 +13,7 @@ To use this library, add the following to your `Cargo.toml`: ```toml [dependencies] -tree-sitter-stack-graphs-javascript = "0.2" +tree-sitter-stack-graphs-javascript = "0.3" ``` Check out our [documentation](https://docs.rs/tree-sitter-stack-graphs-javascript/*/) for more details on how to use this library. diff --git a/languages/tree-sitter-stack-graphs-javascript/rust/lib.rs b/languages/tree-sitter-stack-graphs-javascript/rust/lib.rs index 718db8a2e..cbf80e5cd 100644 --- a/languages/tree-sitter-stack-graphs-javascript/rust/lib.rs +++ b/languages/tree-sitter-stack-graphs-javascript/rust/lib.rs @@ -37,7 +37,7 @@ pub fn try_language_configuration( cancellation_flag: &dyn CancellationFlag, ) -> Result { let mut lc = LanguageConfiguration::from_sources( - tree_sitter_javascript::language(), + tree_sitter_javascript::LANGUAGE.into(), Some(String::from("source.js")), None, vec![String::from("js")], diff --git a/languages/tree-sitter-stack-graphs-python/CHANGELOG.md b/languages/tree-sitter-stack-graphs-python/CHANGELOG.md index 61e6ca4e9..8ec44913d 100644 --- a/languages/tree-sitter-stack-graphs-python/CHANGELOG.md +++ b/languages/tree-sitter-stack-graphs-python/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v0.3.0 -- Unreleased + +- The `tree-sitter-stack-graphs` dependency is updated to version 0.10. + +- The `tree-sitter-python` dependency is updated to version 0.23.5. + ## v0.2.0 -- 2024-07-09 ### Added diff --git a/languages/tree-sitter-stack-graphs-python/Cargo.toml b/languages/tree-sitter-stack-graphs-python/Cargo.toml index 53d714719..afdfe6091 100644 --- a/languages/tree-sitter-stack-graphs-python/Cargo.toml +++ b/languages/tree-sitter-stack-graphs-python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tree-sitter-stack-graphs-python" -version = "0.2.0" +version = "0.3.0" description = "Stack graphs definition for Python using tree-sitter-python" readme = "README.md" keywords = ["tree-sitter", "stack-graphs", "python"] @@ -30,8 +30,8 @@ cli = ["anyhow", "clap", "tree-sitter-stack-graphs/cli"] [dependencies] anyhow = { version = "1.0", optional = true } clap = { version = "4", optional = true, features = ["derive"] } -tree-sitter-stack-graphs = { version = "0.9", path = "../../tree-sitter-stack-graphs" } # explicit version is required to be able to publish crate -tree-sitter-python = "=0.20.4" +tree-sitter-stack-graphs = { version = "0.10", path = "../../tree-sitter-stack-graphs" } # explicit version is required to be able to publish crate +tree-sitter-python = "=0.23.5" [dev-dependencies] anyhow = "1.0" diff --git a/languages/tree-sitter-stack-graphs-python/README.md b/languages/tree-sitter-stack-graphs-python/README.md index a313a3799..7ec9ded72 100644 --- a/languages/tree-sitter-stack-graphs-python/README.md +++ b/languages/tree-sitter-stack-graphs-python/README.md @@ -13,7 +13,7 @@ To use this library, add the following to your `Cargo.toml`: ```toml [dependencies] -tree-sitter-stack-graphs-python = "0.2" +tree-sitter-stack-graphs-python = "0.3" ``` Check out our [documentation](https://docs.rs/tree-sitter-stack-graphs-python/*/) for more details on how to use this library. diff --git a/languages/tree-sitter-stack-graphs-python/rust/lib.rs b/languages/tree-sitter-stack-graphs-python/rust/lib.rs index e0ffb40ec..332250511 100644 --- a/languages/tree-sitter-stack-graphs-python/rust/lib.rs +++ b/languages/tree-sitter-stack-graphs-python/rust/lib.rs @@ -29,7 +29,7 @@ pub fn try_language_configuration( cancellation_flag: &dyn CancellationFlag, ) -> Result { LanguageConfiguration::from_sources( - tree_sitter_python::language(), + tree_sitter_python::LANGUAGE.into(), Some(String::from("source.py")), None, vec![String::from("py")], diff --git a/languages/tree-sitter-stack-graphs-typescript/Cargo.toml b/languages/tree-sitter-stack-graphs-typescript/Cargo.toml index 86feee2a1..379d4d3fe 100644 --- a/languages/tree-sitter-stack-graphs-typescript/Cargo.toml +++ b/languages/tree-sitter-stack-graphs-typescript/Cargo.toml @@ -33,8 +33,8 @@ glob = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" stack-graphs = { version = "0.14", path = "../../stack-graphs" } # explicit version is required to be able to publish crate -tree-sitter-stack-graphs = { version = "0.9", path = "../../tree-sitter-stack-graphs" } # explicit version is required to be able to publish crate -tree-sitter-typescript = "=0.20.2" +tree-sitter-stack-graphs = { version = "0.10", path = "../../tree-sitter-stack-graphs" } # explicit version is required to be able to publish crate +tree-sitter-typescript = "=0.23.2" tsconfig = "0.1.0" [dev-dependencies] diff --git a/languages/tree-sitter-stack-graphs-typescript/rust/lib.rs b/languages/tree-sitter-stack-graphs-typescript/rust/lib.rs index 2fa484a0a..8fd63881d 100644 --- a/languages/tree-sitter-stack-graphs-typescript/rust/lib.rs +++ b/languages/tree-sitter-stack-graphs-typescript/rust/lib.rs @@ -44,7 +44,7 @@ pub fn try_language_configuration_typescript( cancellation_flag: &dyn CancellationFlag, ) -> Result { let mut lc = LanguageConfiguration::from_sources( - tree_sitter_typescript::language_typescript(), + tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into(), Some(String::from("source.ts")), None, vec![String::from("ts")], @@ -74,7 +74,7 @@ pub fn try_language_configuration_tsx( cancellation_flag: &dyn CancellationFlag, ) -> Result { let mut lc = LanguageConfiguration::from_sources( - tree_sitter_typescript::language_tsx(), + tree_sitter_typescript::LANGUAGE_TSX.into(), Some(String::from("source.tsx")), None, vec![String::from("tsx")], diff --git a/languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg b/languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg index b7478b4e4..a32c717f5 100644 --- a/languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg +++ b/languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg @@ -1469,6 +1469,8 @@ if none @is_async { edge @dec.lexical_scope -> @class_decl.lexical_scope } + + ; definitions [ (abstract_class_declaration name:(_)@name) @@ -1626,6 +1628,7 @@ if none @is_async { [ (abstract_class_declaration body:(_)@body) (class_declaration body:(_)@body) + (interface_declaration body:(_)@body) ]@class_decl { ; propagate lexical scope ; FIXME the static members have access to type variables like this @@ -1639,16 +1642,6 @@ if none @is_async { edge @class_decl.static_type -> @body.static_members attr (@class_decl.static_type -> @body.static_members) precedence = 2 } -[ - (interface_declaration body:(_)@body) -]@class_decl { - ; propagate lexical scope - edge @body.lexical_scope -> @class_decl.generic_inner_lexical_scope - - ; interface type equals body type - edge @class_decl.generic_inner_type -> @body.type -} - ;; Class Body @@ -1662,23 +1655,35 @@ if none @is_async { ; (public_field_definition)] ; ) -(class_body)@class_body { - node @class_body.lexical_scope - node @class_body.type_members - node @class_body.static_members +[ + (class_body) + (interface_body) +]@body { + node @body.lexical_scope + node @body.type_members + node @body.static_members } -(class_body - (_)@mem -)@class_body { +; decorators +[ + (class_body decorator:(_)@dec) +]@class_body { + ; connect lexical scope + edge @dec.lexical_scope -> @class_body.lexical_scope +} + +[ + (class_body (_)@mem) + (interface_body (_)@mem) +]@body { ; propagate lexical scope - edge @mem.lexical_scope -> @class_body.lexical_scope + edge @mem.lexical_scope -> @body.lexical_scope ; body members are member definitions - edge @class_body.type_members -> @mem.type_members + edge @body.type_members -> @mem.type_members ; body static members are static member definitions - edge @class_body.static_members -> @mem.static_members + edge @body.static_members -> @mem.static_members } @@ -2334,7 +2339,7 @@ if none @is_async { (import_statement (import_clause (namespace_import (identifier)@name))) (ambient_declaration (module name:(string) @name)) ; X._ - (nested_identifier (identifier)@name) + (nested_identifier object:(identifier)@name) ] { node @name.expr_def node expr_def_typeof @@ -2357,7 +2362,7 @@ if none @is_async { edge @name.type_def -> @name.type_def_member } -(nested_identifier . (_) @mod) @nested { +(nested_identifier object:(_)@mod) @nested { node @nested.expr_def node @nested.type_def @@ -2365,12 +2370,12 @@ if none @is_async { edge @nested.type_def -> @mod.type_def } -(nested_identifier . (_) @mod . (_) @name .) { +(nested_identifier object:(_)@mod property:(_)@name) { edge @mod.expr_def_member -> @name.expr_def edge @mod.type_def_member -> @name.type_def } -(nested_identifier (_) @name .) @nested { +(nested_identifier property:(_)@name)@nested { node @nested.expr_def_member node @nested.type_def_member @@ -2644,7 +2649,7 @@ if none @is_async { (call_expression) (class) (false) - (function) + (function_expression) (generator_function) (import) (member_expression) @@ -2814,8 +2819,7 @@ if none @is_async { (decorator (call_expression function:(member_expression object:(member_expression object:(identifier)@name)))) (decorator (call_expression function:(member_expression object:(member_expression object:(member_expression object:(identifier)@name))))) ; #dialect tsx - (nested_identifier (identifier)@name) - (nested_identifier (nested_identifier)@name) + (nested_identifier object:(_)@name) (nested_type_identifier module:(nested_identifier)@name) (internal_module name:(_)@name) (jsx_opening_element name: (_)@name) @@ -2870,7 +2874,7 @@ if none @is_def { (decorator (call_expression function:(member_expression object:(member_expression object:(identifier)@name)))) (decorator (call_expression function:(member_expression object:(member_expression object:(member_expression object:(identifier)@name))))) ; #dialect tsx - (nested_identifier (identifier)@name (identifier)) ; to pick up foo in JSX: +; (nested_identifier object:(identifier)@name property:(identifier)) ; to pick up foo in JSX: ; FIXME never matched (jsx_opening_element name: (identifier)@name) (jsx_closing_element name: (identifier)@name) (jsx_self_closing_element name: (identifier)@name) @@ -3259,20 +3263,20 @@ if none @is_def { ; function (x) {}; -; (function +; (function_expression ; (formal_parameters (identifier)) ; (statement_block)) ; this captures the parameters -; (function +; (function_expression ; parameters: (_)@params) ; this captures the body -; (function +; (function_expression ; body:(_)@body)@function ; functions with names -; (function +; (function_expression ; name:(_)@name ; parameters:(_)@call_sig)@fun { ; } @@ -3307,7 +3311,7 @@ if none @is_def { ; } [ - (function) + (function_expression) (arrow_function) (generator_function) ]@fun { @@ -3334,9 +3338,9 @@ if none @is_def { } [ - (function parameters:(_)@call_sig) - (arrow_function parameters:(_)@call_sig) - (generator_function parameters:(_)@call_sig) + (function_expression parameters:(_)@call_sig) + (arrow_function parameters:(_)@call_sig) + (generator_function parameters:(_)@call_sig) ]@fun { ; propagate lexical scope edge @call_sig.lexical_scope -> @fun.lexical_scope @@ -3385,9 +3389,9 @@ if none @is_def { } [ - (function body:(_)@body) - (arrow_function body:(_)@body) - (generator_function body:(_)@body) + (function_expression body:(_)@body) + (arrow_function body:(_)@body) + (generator_function body:(_)@body) ]@fun { ; propagate lexical scope edge @body.lexical_scope -> @fun.lexical_scope @@ -3396,8 +3400,8 @@ if none @is_def { ;;;; specified return type [ - (function return_type:(_)@return_type) - (arrow_function return_type:(_)@return_type) + (function_expression return_type:(_)@return_type) + (arrow_function return_type:(_)@return_type) ]@fun { ; propagate lexical scope edge @return_type.lexical_scope -> @fun.lexical_scope @@ -3409,8 +3413,8 @@ if none @is_def { ;;;; inferred return type [ - (function "async"?@is_async !return_type body:(_)@body) - (arrow_function "async"?@is_async !return_type body:(statement_block)@body) + (function_expression "async"?@is_async !return_type body:(_)@body) + (arrow_function "async"?@is_async !return_type body:(statement_block)@body) ]@fun { if none @is_async { ; callable is type of return statement @@ -3428,8 +3432,8 @@ if none @is_async { ;;;; inferred async return type [ - (function "async" !return_type body:(_)@body) - (arrow_function "async" body:(statement_block)@body) + (function_expression "async" !return_type body:(_)@body) + (arrow_function "async" body:(statement_block)@body) ]@fun_decl { ; function returns body return type edge @fun_decl.callable__return -> @fun_decl.async_type @@ -3548,19 +3552,9 @@ if none @is_async { ; (subscript_expression (identifier) (string)) [ - (member_expression - object: (_)@object - property: (_)@prop - )@member_expr + (member_expression object:(_)@object property:(_)@prop)@member_expr ; #dialect tsx - (nested_identifier - (nested_identifier)@object - (identifier)@prop - )@member_expr - (nested_identifier - (identifier)@object - (identifier)@prop - )@member_expr +; (nested_identifier object:(_)@object property:(identifier)@prop)@member_expr ; FIXME this never matched anything! ; #end ] { node @member_expr.member @@ -3890,15 +3884,13 @@ if none @is_async { ; (sequence_expression (number) (number)) -(sequence_expression - left: (_)@left - right: (_)@right -)@sequence_expr { +(sequence_expression (_)@expr)@sequence_expr { ; propagate lexical scope - edge @left.lexical_scope -> @sequence_expr.lexical_scope - edge @right.lexical_scope -> @sequence_expr.lexical_scope + edge @expr.lexical_scope -> @sequence_expr.lexical_scope +} - ; FIXME @sequence_expr.type is type of last, but cannot express because of nesting +(sequence_expression (_)@last .)@sequence_expr { + edge @sequence_expr.type -> @last.type } @@ -4040,6 +4032,12 @@ if none @is_async { edge @class_expr.this__type_def -> @class_expr.generic_inner_type } +; decorators +(class decorator:(_)@dec)@class_expr { + ; connect lexical scope + edge @dec.lexical_scope -> @class_expr.lexical_scope +} + ; default constructor ; FIXME only if no other constructor is defined (class)@class_expr { @@ -4571,6 +4569,12 @@ if none @is_async { ; value:(_)@value ; opt ; )@def +; decorators +(public_field_definition decorator:(_)@dec)@def { + ; connect lexical scope + edge @dec.lexical_scope -> @def.lexical_scope +} + (public_field_definition name:(_)@name )@def { @@ -4956,6 +4960,7 @@ if none @is_acc { [ (array_type) (asserts) + (asserts_annotation) (conditional_type) (constraint) (constructor_type) @@ -5071,6 +5076,9 @@ if none @is_acc { edge @type.lexical_scope -> @asserts.lexical_scope } +(asserts_annotation (_)@asserts)@asserts_annotation { + edge @asserts.lexical_scope -> @asserts_annotation.lexical_scope +} ;; Optional Type @@ -5596,7 +5604,7 @@ if none @is_acc { ; X (nested_type_identifier module:(identifier)@name) ; X._, _.X._ - (nested_identifier (identifier)@name) + (nested_identifier object:(identifier)@name) ] { node @name.type_ref attr (@name.type_ref) node_reference = @name @@ -5607,7 +5615,7 @@ if none @is_acc { edge @name.type_ref_member -> @name.type_ref } -(nested_identifier . (_)@mod) @nested { +(nested_identifier object:(_)@mod) @nested { node @nested.type_ref edge @mod.type_ref -> @nested.type_ref } @@ -5616,7 +5624,7 @@ if none @is_acc { edge @name.type_ref -> @mod.type_ref_member } -(nested_identifier (_)@name .) @nested { +(nested_identifier property:(_)@name) @nested { node @nested.type_ref_member edge @nested.type_ref_member -> @name.type_ref_member } @@ -6159,7 +6167,7 @@ if none @is_acc { [ (arrow_function "async") - (function "async") + (function_expression "async") (function_declaration "async") (generator_function "async") (generator_function_declaration "async") @@ -6221,7 +6229,6 @@ if none @is_acc { [ (jsx_text) (jsx_element) - (jsx_fragment) (jsx_self_closing_element) (jsx_expression) ]@child @@ -6229,24 +6236,6 @@ if none @is_acc { edge @child.lexical_scope -> @parent.lexical_scope } -(jsx_fragment)@fragment { - node @fragment.lexical_scope - node @fragment.value - node @fragment.type -} - -(jsx_fragment - [ - (jsx_text) - (jsx_element) - (jsx_fragment) - (jsx_self_closing_element) - (jsx_expression) - ]@child -) @parent { - edge @child.lexical_scope -> @parent.lexical_scope -} - (jsx_text)@jsx_text { node @jsx_text.lexical_scope } diff --git a/languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_namespace_name.tsx b/languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_namespace_name.tsx.skip similarity index 100% rename from languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_namespace_name.tsx rename to languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_namespace_name.tsx.skip diff --git a/languages/tree-sitter-stack-graphs-typescript/test/modules/very-deep-namespace.ts b/languages/tree-sitter-stack-graphs-typescript/test/modules/very-deep-namespace.ts.skip similarity index 100% rename from languages/tree-sitter-stack-graphs-typescript/test/modules/very-deep-namespace.ts rename to languages/tree-sitter-stack-graphs-typescript/test/modules/very-deep-namespace.ts.skip diff --git a/languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts b/languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts.skip similarity index 100% rename from languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts rename to languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts.skip diff --git a/languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts b/languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts.skip similarity index 100% rename from languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts rename to languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts.skip diff --git a/lsp-positions/CHANGELOG.md b/lsp-positions/CHANGELOG.md index a9e17c13f..84aa962b4 100644 --- a/lsp-positions/CHANGELOG.md +++ b/lsp-positions/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v0.3.4 -- Unreleased + +Upgraded the `tree-sitter` dependency to version 0.24. + ## v0.3.3 -- 2024-03-05 The `tree-sitter` dependency version was updated to fix install problems. diff --git a/lsp-positions/Cargo.toml b/lsp-positions/Cargo.toml index 7054def14..a9f7acb20 100644 --- a/lsp-positions/Cargo.toml +++ b/lsp-positions/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lsp-positions" -version = "0.3.3" +version = "0.3.4" description = "LSP-compatible character positions" homepage = "https://github.com/github/stack-graphs/tree/main/lsp-positions" repository = "https://github.com/github/stack-graphs/" @@ -22,7 +22,7 @@ tree-sitter = ["dep:tree-sitter"] [dependencies] memchr = "2.4" -tree-sitter = { version = "0.20", optional = true } # keep the same minor version as the tree-sitter +tree-sitter = { version = "0.24", optional = true } # keep the same minor version as the tree-sitter # dependency of tree-sitter-stack-graphs to prevent # install problems unicode-segmentation = { version = "1.8" } diff --git a/tree-sitter-stack-graphs/CHANGELOG.md b/tree-sitter-stack-graphs/CHANGELOG.md index 6f6e86f25..b45b69b64 100644 --- a/tree-sitter-stack-graphs/CHANGELOG.md +++ b/tree-sitter-stack-graphs/CHANGELOG.md @@ -5,8 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## v0.9.0 -- 2024-07-09 +## v0.10.0 -- Unreleased + +Upgraded `tree-sitter` dependency to version 0.24. +## v0.9.0 -- 2024-07-09 ### Library diff --git a/tree-sitter-stack-graphs/Cargo.toml b/tree-sitter-stack-graphs/Cargo.toml index 0ac84d012..3c1c01a80 100644 --- a/tree-sitter-stack-graphs/Cargo.toml +++ b/tree-sitter-stack-graphs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tree-sitter-stack-graphs" -version = "0.9.0" +version = "0.10.0" description = "Create stack graphs using tree-sitter parsers" homepage = "https://github.com/github/stack-graphs/tree/main/tree-sitter-stack-graphs" repository = "https://github.com/github/stack-graphs/" @@ -62,7 +62,7 @@ env_logger = { version = "0.9", optional = true } indoc = { version = "1.0", optional = true } itertools = "0.10" log = "0.4" -lsp-positions = { version="0.3", path="../lsp-positions", features=["tree-sitter"] } # explicit version is required to be able to publish crate +lsp-positions = { version="0.3.4", path="../lsp-positions", features=["tree-sitter"] } # explicit version is required to be able to publish crate once_cell = "1" pathdiff = { version = "0.2.1", optional = true } regex = "1" @@ -74,13 +74,13 @@ thiserror = "1.0" time = { version = "0.3", optional = true } tokio = { version = "1.26", optional = true, features = ["io-std", "rt", "rt-multi-thread"] } tower-lsp = { version = "0.19", optional = true } -tree-sitter = "0.20" # keep the same minor version as the tree-sitter dependency +tree-sitter = "0.24" # keep the same minor version as the tree-sitter dependency # of tree-sitter-graph to prevent install problems -tree-sitter-config = { version = "0.19", optional = true } -tree-sitter-graph = "0.11" -tree-sitter-loader = "0.20" +tree-sitter-config = { version = "0.24", optional = true } +tree-sitter-graph = "0.12" +tree-sitter-loader = "0.24" walkdir = { version = "2.3", optional = true } [dev-dependencies] pretty_assertions = "0.7" -tree-sitter-python = "=0.19.1" +tree-sitter-python = "=0.23.5" diff --git a/tree-sitter-stack-graphs/README.md b/tree-sitter-stack-graphs/README.md index a4e52add3..56f61e131 100644 --- a/tree-sitter-stack-graphs/README.md +++ b/tree-sitter-stack-graphs/README.md @@ -14,7 +14,7 @@ To use this library, add the following to your `Cargo.toml`: ```toml [dependencies] -tree-sitter-stack-graphs = "0.9" +tree-sitter-stack-graphs = "0.10" ``` Check out our [documentation](https://docs.rs/tree-sitter-stack-graphs/*/) for more details on how to use this library. diff --git a/tree-sitter-stack-graphs/src/cli/init.rs b/tree-sitter-stack-graphs/src/cli/init.rs index f71890390..e513e5acd 100644 --- a/tree-sitter-stack-graphs/src/cli/init.rs +++ b/tree-sitter-stack-graphs/src/cli/init.rs @@ -778,7 +778,7 @@ impl ProjectSettings<'_> { cancellation_flag: &dyn CancellationFlag, ) -> Result {{ LanguageConfiguration::from_sources( - {}::language(), + {}::LANGUAGE.into(), Some(String::from("source.{}")), None, vec![String::from("{}")], diff --git a/tree-sitter-stack-graphs/src/cli/load.rs b/tree-sitter-stack-graphs/src/cli/load.rs index b32332f9d..1fd22fa2b 100644 --- a/tree-sitter-stack-graphs/src/cli/load.rs +++ b/tree-sitter-stack-graphs/src/cli/load.rs @@ -67,7 +67,7 @@ impl PathLoaderArgs { builtins_paths, )? } else { - let loader_config = TsConfig::load() + let loader_config = TsConfig::load(None) .and_then(|v| v.get()) .map_err(LoadError::TreeSitter)?; Loader::from_tree_sitter_configuration( diff --git a/tree-sitter-stack-graphs/src/cli/lsp.rs b/tree-sitter-stack-graphs/src/cli/lsp.rs index 03f1c8060..57ed770bb 100644 --- a/tree-sitter-stack-graphs/src/cli/lsp.rs +++ b/tree-sitter-stack-graphs/src/cli/lsp.rs @@ -560,25 +560,6 @@ impl FromStdError for std::result::Result { } } -trait FromAnyhowError { - #[must_use] - fn from_error(self) -> Result; -} - -impl FromAnyhowError for std::result::Result { - #[must_use] - fn from_error(self) -> Result { - match self { - Ok(value) => Ok(value), - Err(err) => Err(Error { - code: ErrorCode::ServerError(-1), - message: err.to_string(), - data: None, - }), - } - } -} - #[derive(Debug)] pub enum Job { IndexPath(PathBuf), diff --git a/tree-sitter-stack-graphs/src/cli/match.rs b/tree-sitter-stack-graphs/src/cli/match.rs index 108c8450e..889d2374a 100644 --- a/tree-sitter-stack-graphs/src/cli/match.rs +++ b/tree-sitter-stack-graphs/src/cli/match.rs @@ -49,7 +49,7 @@ impl MatchArgs { None => return Err(anyhow!("No stack graph language found")), }; let source = file_reader.get(&self.source_path)?; - let tree = parse(lc.language, &self.source_path, source)?; + let tree = parse(&lc.language, &self.source_path, source)?; if self.stanza.is_empty() { lc.sgl.tsg.try_visit_matches(&tree, source, true, |mat| { print_matches(lc.sgl.tsg_path(), &self.source_path, source, mat) diff --git a/tree-sitter-stack-graphs/src/cli/parse.rs b/tree-sitter-stack-graphs/src/cli/parse.rs index aff7681b1..64275b915 100644 --- a/tree-sitter-stack-graphs/src/cli/parse.rs +++ b/tree-sitter-stack-graphs/src/cli/parse.rs @@ -40,14 +40,14 @@ impl ParseArgs { None => return Err(anyhow!("No stack graph language found")), }; let source = file_reader.get(&self.source_path)?; - let tree = parse(lang, &self.source_path, source)?; + let tree = parse(&lang, &self.source_path, source)?; print_tree(tree); Ok(()) } } pub(super) fn parse( - language: tree_sitter::Language, + language: &tree_sitter::Language, path: &Path, source: &str, ) -> anyhow::Result { diff --git a/tree-sitter-stack-graphs/src/cli/test.rs b/tree-sitter-stack-graphs/src/cli/test.rs index 1bff78a48..e3034cbbf 100644 --- a/tree-sitter-stack-graphs/src/cli/test.rs +++ b/tree-sitter-stack-graphs/src/cli/test.rs @@ -432,7 +432,7 @@ impl TestArgs { .add_from_graph(&lc.builtins) .map_err(|h| anyhow!("Duplicate builtin file {}", &graph[h]))?; let files = files.into_iter().collect::>(); - match cache.entry(lc.language) { + match cache.entry(lc.language.clone()) { Entry::Occupied(o) => { o.get().load_into(graph, partials, db)?; } diff --git a/tree-sitter-stack-graphs/src/lib.rs b/tree-sitter-stack-graphs/src/lib.rs index 717214832..3c560fb56 100644 --- a/tree-sitter-stack-graphs/src/lib.rs +++ b/tree-sitter-stack-graphs/src/lib.rs @@ -324,7 +324,7 @@ //! import sys //! print(sys.path) //! "#; -//! let grammar = tree_sitter_python::language(); +//! let grammar = tree_sitter_python::LANGUAGE.into(); //! let tsg_source = STACK_GRAPH_RULES; //! let mut language = StackGraphLanguage::from_str(grammar, tsg_source)?; //! let mut stack_graph = StackGraph::new(); @@ -479,7 +479,7 @@ impl StackGraphLanguage { language: tree_sitter::Language, tsg_source: &str, ) -> Result { - let tsg = tree_sitter_graph::ast::File::from_str(language, tsg_source)?; + let tsg = tree_sitter_graph::ast::File::from_str(language.clone(), tsg_source)?; Ok(StackGraphLanguage { language, tsg, @@ -518,8 +518,8 @@ impl StackGraphLanguage { &mut self.functions } - pub fn language(&self) -> tree_sitter::Language { - self.language + pub fn language(&self) -> &tree_sitter::Language { + &self.language } /// Returns the original TSG path, if it was provided at construction or set with @@ -624,7 +624,7 @@ impl<'a> Builder<'a> { ) -> Result<(), BuildError> { let tree = { let mut parser = Parser::new(); - parser.set_language(self.sgl.language)?; + parser.set_language(&self.sgl.language)?; let ts_cancellation_flag = TreeSitterCancellationFlag::from(cancellation_flag); // The parser.set_cancellation_flag` is unsafe, because it does not tie the // lifetime of the parser to the lifetime of the cancellation flag in any way. diff --git a/tree-sitter-stack-graphs/src/loader.rs b/tree-sitter-stack-graphs/src/loader.rs index 14aa97916..861e4ff95 100644 --- a/tree-sitter-stack-graphs/src/loader.rs +++ b/tree-sitter-stack-graphs/src/loader.rs @@ -68,13 +68,12 @@ impl LanguageConfiguration { builtins_config: Option<&str>, cancellation_flag: &dyn CancellationFlag, ) -> Result> { - let sgl = StackGraphLanguage::from_source(language, tsg_path.clone(), tsg_source).map_err( - |err| LoadError::SglParse { - inner: err, - tsg_path, - tsg: Cow::from(tsg_source), - }, - )?; + let sgl = StackGraphLanguage::from_source(language.clone(), tsg_path.clone(), tsg_source) + .map_err(|err| LoadError::SglParse { + inner: err, + tsg_path, + tsg: Cow::from(tsg_source), + })?; let mut builtins = StackGraph::new(); if let Some((builtins_path, builtins_source)) = builtins_source { let mut builtins_globals = Variables::new(); @@ -273,7 +272,7 @@ impl Loader { &mut self, path: &Path, content: &mut dyn ContentProvider, - ) -> Result, LoadError<'static>> { + ) -> Result, LoadError<'static>> { match &mut self.0 { LoaderImpl::Paths(loader) => loader.load_tree_sitter_language_for_file(path, content), LoaderImpl::Provided(loader) => { @@ -496,10 +495,10 @@ impl LanguageConfigurationsLoader { &mut self, path: &Path, content: &mut dyn ContentProvider, - ) -> Result, LoadError<'static>> { + ) -> Result, LoadError<'static>> { for configuration in self.configurations.iter() { if configuration.matches_file(path, content)? { - return Ok(Some(configuration.language)); + return Ok(Some(&configuration.language)); } } Ok(None) @@ -567,9 +566,9 @@ impl PathLoader { &mut self, path: &Path, content: &mut dyn ContentProvider, - ) -> Result, LoadError<'static>> { + ) -> Result, LoadError<'static>> { if let Some(selected_language) = self.select_language_for_file(path, content)? { - return Ok(Some(selected_language.language)); + return Ok(Some(&selected_language.language)); } Ok(None) } @@ -591,7 +590,7 @@ impl PathLoader { Some(index) => index, None => { let tsg = self.load_tsg_from_paths(&language)?; - let sgl = StackGraphLanguage::new(language.language, tsg); + let sgl = StackGraphLanguage::new(language.language.clone(), tsg); let mut builtins = StackGraph::new(); self.load_builtins_from_paths_into( @@ -602,7 +601,7 @@ impl PathLoader { )?; let lc = LanguageConfiguration { - language: language.language, + language: language.language.clone(), scope: language.scope, content_regex: language.content_regex, file_types: language.file_types, @@ -696,7 +695,7 @@ impl PathLoader { } if tsg_path.exists() { let tsg_source = std::fs::read_to_string(tsg_path)?; - return Loader::load_tsg(language.language, Cow::from(tsg_source)); + return Loader::load_tsg(language.language.clone(), Cow::from(tsg_source)); } } return Err(LoadError::NoTsgFound); @@ -786,10 +785,11 @@ impl SupplementedTsLoader { .map_err(LoadError::TreeSitter)?; let configurations = self .0 - .find_language_configurations_at_path(&path) + .find_language_configurations_at_path(&path, true) .map_err(LoadError::TreeSitter)?; let languages = languages .into_iter() + .map(|(l, _)| l) .zip(configurations.into_iter()) .map(SupplementedLanguage::from) .filter(|language| scope.map_or(true, |scope| language.matches_scope(scope))) diff --git a/tree-sitter-stack-graphs/tests/it/builder.rs b/tree-sitter-stack-graphs/tests/it/builder.rs index 14476111e..719e25d71 100644 --- a/tree-sitter-stack-graphs/tests/it/builder.rs +++ b/tree-sitter-stack-graphs/tests/it/builder.rs @@ -35,7 +35,7 @@ fn can_support_preexisting_nodes() { .add(FILE_PATH_VAR.into(), file_name.into()) .expect("failed to add file path variable"); - let language = StackGraphLanguage::from_str(tree_sitter_python::language(), tsg).unwrap(); + let language = StackGraphLanguage::from_str(tree_sitter_python::LANGUAGE.into(), tsg).unwrap(); language .build_stack_graph_into(&mut graph, file, python, &globals, &NoCancellation) .expect("Failed to build graph"); @@ -59,7 +59,7 @@ fn can_support_injected_nodes() { let node_id = graph.new_node_id(file); let _preexisting_node = graph.add_scope_node(node_id, true).unwrap(); - let language = StackGraphLanguage::from_str(tree_sitter_python::language(), tsg).unwrap(); + let language = StackGraphLanguage::from_str(tree_sitter_python::LANGUAGE.into(), tsg).unwrap(); let mut builder = language.builder_into_stack_graph(&mut graph, file, python); let mut globals = Variables::new(); diff --git a/tree-sitter-stack-graphs/tests/it/loader.rs b/tree-sitter-stack-graphs/tests/it/loader.rs index 257326952..401af46e5 100644 --- a/tree-sitter-stack-graphs/tests/it/loader.rs +++ b/tree-sitter-stack-graphs/tests/it/loader.rs @@ -9,6 +9,7 @@ use once_cell::sync::Lazy; use pretty_assertions::assert_eq; use stack_graphs::graph::StackGraph; use std::path::PathBuf; +use tree_sitter::Language; use tree_sitter_stack_graphs::loader::FileAnalyzers; use tree_sitter_stack_graphs::loader::LanguageConfiguration; use tree_sitter_stack_graphs::loader::Loader; @@ -25,10 +26,10 @@ static TSG: Lazy = Lazy::new(|| { #[test] fn can_load_from_provided_language_configuration() { - let language = tree_sitter_python::language(); - let sgl = StackGraphLanguage::from_str(language, &TSG).unwrap(); + let language: Language = tree_sitter_python::LANGUAGE.into(); + let sgl = StackGraphLanguage::from_str(language.clone(), &TSG).unwrap(); let lc = LanguageConfiguration { - language: language, + language: language.clone(), scope: Some("source.py".into()), content_regex: None, file_types: vec!["py".into()], @@ -43,10 +44,10 @@ fn can_load_from_provided_language_configuration() { let tsl = loader .load_tree_sitter_language_for_file(&PATH, &mut None) .expect("Expected loading tree-sitter language to succeed"); - assert_eq!(tsl, Some(language)); + assert_eq!(tsl, Some(&language)); let lc = loader .load_for_file(&PATH, &mut None, &NoCancellation) .expect("Expected loading stack graph language to succeed"); - assert_eq!(lc.primary.map(|lc| lc.language), Some(language)); + assert_eq!(lc.primary.map(|lc| &lc.language), Some(&language)); } diff --git a/tree-sitter-stack-graphs/tests/it/main.rs b/tree-sitter-stack-graphs/tests/it/main.rs index 33ee19241..01cfd9754 100644 --- a/tree-sitter-stack-graphs/tests/it/main.rs +++ b/tree-sitter-stack-graphs/tests/it/main.rs @@ -28,7 +28,7 @@ pub(self) fn build_stack_graph( ) -> Result<(StackGraph, Handle), BuildError> { let file_name = "test.py"; let language = - StackGraphLanguage::from_str(tree_sitter_python::language(), tsg_source).unwrap(); + StackGraphLanguage::from_str(tree_sitter_python::LANGUAGE.into(), tsg_source).unwrap(); let mut graph = StackGraph::new(); let file = graph.get_or_create_file(file_name); let mut globals = Variables::new(); diff --git a/tree-sitter-stack-graphs/tests/it/test.rs b/tree-sitter-stack-graphs/tests/it/test.rs index cb1efff4f..fae14fe76 100644 --- a/tree-sitter-stack-graphs/tests/it/test.rs +++ b/tree-sitter-stack-graphs/tests/it/test.rs @@ -73,7 +73,7 @@ fn build_stack_graph_into( globals: &Variables, ) -> Result<(), BuildError> { let language = - StackGraphLanguage::from_str(tree_sitter_python::language(), tsg_source).unwrap(); + StackGraphLanguage::from_str(tree_sitter_python::LANGUAGE.into(), tsg_source).unwrap(); language.build_stack_graph_into(graph, file, python_source, globals, &NoCancellation)?; Ok(()) } From c0ecac035f0905831ee8e328a1658b96c8ed704e Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Tue, 10 Dec 2024 19:18:15 +0100 Subject: [PATCH 02/15] Handle additional case --- .../tree-sitter-stack-graphs-javascript/src/stack-graphs.tsg | 4 ++-- .../test/expressions/member_expression.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/languages/tree-sitter-stack-graphs-javascript/src/stack-graphs.tsg b/languages/tree-sitter-stack-graphs-javascript/src/stack-graphs.tsg index a9167c3a1..7ca4eee88 100644 --- a/languages/tree-sitter-stack-graphs-javascript/src/stack-graphs.tsg +++ b/languages/tree-sitter-stack-graphs-javascript/src/stack-graphs.tsg @@ -2435,7 +2435,7 @@ inherit .containing_class_value [ (primary_expression/identifier)@variable - (member_expression . (identifier)@variable) + (member_expression object:(identifier)@variable) ] { ; value is a lookup, ie a push attr (@variable.value) node_reference = @variable @@ -3189,7 +3189,7 @@ inherit .containing_class_value ;; ##### Member Expressions (member_expression - (_)@object . (_)@property)@member_expr + object:(_)@object property:(_)@property)@member_expr { node member_push diff --git a/languages/tree-sitter-stack-graphs-javascript/test/expressions/member_expression.js b/languages/tree-sitter-stack-graphs-javascript/test/expressions/member_expression.js index b397d747a..438cf9dd6 100644 --- a/languages/tree-sitter-stack-graphs-javascript/test/expressions/member_expression.js +++ b/languages/tree-sitter-stack-graphs-javascript/test/expressions/member_expression.js @@ -15,4 +15,8 @@ let x = 1; // Flow around /**/ x; +// ^ defined: 1 + +// Optional chain +/**/ x?.foo // ^ defined: 1 \ No newline at end of file From ba2117d75ff56dd4adf7032f18d07ed9c1dac26a Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Tue, 10 Dec 2024 19:32:18 +0100 Subject: [PATCH 03/15] Fix panic --- stack-graphs/CHANGELOG.md | 6 ++++++ stack-graphs/Cargo.toml | 2 +- stack-graphs/src/graph.rs | 5 ++++- stack-graphs/tests/it/graph.rs | 21 ++++++++++++++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/stack-graphs/CHANGELOG.md b/stack-graphs/CHANGELOG.md index eeaae0730..aae6a2998 100644 --- a/stack-graphs/CHANGELOG.md +++ b/stack-graphs/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v0.14.1 -- Unpublished + +### Fixed + +- A panic when using `StackGraph::incoming_edge_degree` on some nodes without incoming edges. + ## v0.14.0 -- 2024-07-09 ### Changed diff --git a/stack-graphs/Cargo.toml b/stack-graphs/Cargo.toml index f114fffdb..e542f4163 100644 --- a/stack-graphs/Cargo.toml +++ b/stack-graphs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stack-graphs" -version = "0.14.0" +version = "0.14.1" description = "Name binding for arbitrary programming languages" homepage = "https://github.com/github/stack-graphs/tree/main/stack-graphs" repository = "https://github.com/github/stack-graphs/" diff --git a/stack-graphs/src/graph.rs b/stack-graphs/src/graph.rs index 686344ee5..d55dfc48a 100644 --- a/stack-graphs/src/graph.rs +++ b/stack-graphs/src/graph.rs @@ -1334,7 +1334,10 @@ impl StackGraph { /// Returns the number of edges that end at a particular sink node. pub fn incoming_edge_degree(&self, sink: Handle) -> Degree { - self.incoming_edges[sink] + self.incoming_edges + .get(sink) + .cloned() + .unwrap_or(Degree::Zero) } } diff --git a/stack-graphs/tests/it/graph.rs b/stack-graphs/tests/it/graph.rs index f19bb2c30..620d066c9 100644 --- a/stack-graphs/tests/it/graph.rs +++ b/stack-graphs/tests/it/graph.rs @@ -8,7 +8,7 @@ use std::collections::HashSet; use maplit::hashset; -use stack_graphs::graph::StackGraph; +use stack_graphs::graph::{Degree, StackGraph}; use crate::test_graphs; use crate::test_graphs::CreateStackGraph; @@ -196,3 +196,22 @@ fn can_add_graph_to_empty_graph() { ); } } + +#[test] +fn can_get_incoming_edges() { + let mut graph = StackGraph::new(); + let file = graph.get_or_create_file("test.py"); + let h1 = graph.internal_scope(file, 0); + let h2 = graph.internal_scope(file, 1); + let h3 = graph.internal_scope(file, 2); + assert_eq!(Degree::Zero, graph.incoming_edge_degree(h1)); + assert_eq!(Degree::Zero, graph.incoming_edge_degree(h2)); + assert_eq!(Degree::Zero, graph.incoming_edge_degree(h3)); + graph.add_edge(h1, h2, 0); + graph.add_edge(h3, h2, 0); + assert_eq!(Degree::Zero, graph.incoming_edge_degree(h1)); + assert_eq!(Degree::Multiple, graph.incoming_edge_degree(h2)); + assert_eq!(Degree::Zero, graph.incoming_edge_degree(h3)); + graph.add_edge(h3, h1, 0); + assert_eq!(Degree::One, graph.incoming_edge_degree(h1)); +} From ba182ad26c0a70b2580070e7c61ca254e1cf9aa4 Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Wed, 11 Dec 2024 15:24:54 +0100 Subject: [PATCH 04/15] Fix previously skipped tests --- .../src/stack-graphs.tsg | 235 ++++++++---------- ...e_name.tsx.skip => jsx_namespace_name.tsx} | 0 ...mespace.ts.skip => very-deep-namespace.ts} | 0 ...sted-namespace-by-fully-qualified-name.ts} | 0 ...fied-namespace-by-fully-qualified-name.ts} | 0 5 files changed, 106 insertions(+), 129 deletions(-) rename languages/tree-sitter-stack-graphs-typescript/test/jsx/{jsx_namespace_name.tsx.skip => jsx_namespace_name.tsx} (100%) rename languages/tree-sitter-stack-graphs-typescript/test/modules/{very-deep-namespace.ts.skip => very-deep-namespace.ts} (100%) rename languages/tree-sitter-stack-graphs-typescript/test/statements/{refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts.skip => refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts} (100%) rename languages/tree-sitter-stack-graphs-typescript/test/statements/{refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts.skip => refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts} (100%) diff --git a/languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg b/languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg index a32c717f5..773abde7c 100644 --- a/languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg +++ b/languages/tree-sitter-stack-graphs-typescript/src/stack-graphs.tsg @@ -627,16 +627,6 @@ attribute node_symbol = node => symbol = (source-text node), source_n (import_statement "type"?@is_type (import_clause (named_imports (import_specifier name:(_)@name))@clause)) ] { if none @is_type { - node @name.expr_def - node @name.expr_def__ns - node @name.expr_ref - node @name.expr_ref__ns - - ; expr reference - attr (@name.expr_ref) node_reference = @name - edge @name.expr_ref -> @name.expr_ref__ns - ; - attr (@name.expr_ref__ns) push_symbol = "%E" edge @name.expr_ref__ns -> @clause.lexical_scope } } @@ -646,6 +636,9 @@ if none @is_type { (import_statement "type"?@is_type (import_clause (named_imports (import_specifier name:(_)@name !alias))@clause)) ] { if none @is_type { + node @name.expr_def + node @name.expr_def__ns + ; expr definition edge @clause.defs -> @name.expr_def__ns ; FIXME defs, lexical_defs? ; @@ -664,7 +657,6 @@ if none @is_type { if none @is_type { node @alias.expr_def node @alias.expr_def__ns - node @alias.expr_ref ; expr definition edge @clause.defs -> @alias.expr_def__ns @@ -2340,6 +2332,12 @@ if none @is_async { (ambient_declaration (module name:(string) @name)) ; X._ (nested_identifier object:(identifier)@name) + ; _.X._ + (member_expression object:(identifier)@name) + ; _.X + (nested_identifier property:(_)@name) + ; _._.X + (member_expression property:(_)@name) ] { node @name.expr_def node expr_def_typeof @@ -2362,7 +2360,10 @@ if none @is_async { edge @name.type_def -> @name.type_def_member } -(nested_identifier object:(_)@mod) @nested { +[ + (nested_identifier object:(_)@mod) + (member_expression object:[(member_expression) (identifier)]@mod) +]@nested { node @nested.expr_def node @nested.type_def @@ -2370,12 +2371,18 @@ if none @is_async { edge @nested.type_def -> @mod.type_def } -(nested_identifier object:(_)@mod property:(_)@name) { +[ + (nested_identifier object:(_)@mod property:(_)@name) + (member_expression object:[(member_expression) (identifier)]@mod property:(_)@name) +] { edge @mod.expr_def_member -> @name.expr_def edge @mod.type_def_member -> @name.type_def } -(nested_identifier property:(_)@name)@nested { +[ + (nested_identifier property:(_)@name) + (member_expression property:(_)@name) +]@nested { node @nested.expr_def_member node @nested.type_def_member @@ -2782,105 +2789,13 @@ if none @is_async { ; x; -[ - (primary_expression/identifier)@name - ; FIXME expansion of _lhs_expression/identifier and _augmented_assignment_lhs - (for_in_statement ["var" "let" "const"]?@is_def left:(identifier)@name) - (assignment_expression left:(identifier)@name) - (augmented_assignment_expression left:(identifier)@name) - (asserts (identifier)@name) - (type_predicate name:(identifier)@name) - ; FIXME type_query has its own restricted expression production - ; we need to do this for every (identifier) inside a type query - ; this cannot be expressed, so we manually unroll three levels here - (type_query (identifier)@name) - (type_query (member_expression object:(identifier)@name)) - (type_query (member_expression object:(member_expression object:(identifier)@name))) - (type_query (member_expression object:(member_expression object:(member_expression object:(identifier)@name)))) - (type_query (subscript_expression object:(identifier)@name)) - (type_query (subscript_expression object:(member_expression object:(identifier)@name))) - (type_query (subscript_expression object:(member_expression object:(member_expression object:(identifier)@name)))) - (type_query (call_expression function:(identifier)@name)) - (type_query (call_expression function:(member_expression object:(identifier)@name))) - (type_query (call_expression function:(member_expression object:(member_expression object:(identifier)@name)))) - (type_query (call_expression function:(member_expression object:(member_expression object:(member_expression object:(identifier)@name))))) - (type_query (call_expression function:(subscript_expression object:(identifier)@name))) - (type_query (call_expression function:(subscript_expression object:(member_expression object:(identifier)@name)))) - (type_query (call_expression function:(subscript_expression object:(member_expression object:(member_expression object:(identifier)@name))))) - ; FIXME decorator has its own restricted expression production - ; we need to do this for every (identifier) inside a decorator - ; this cannot be expressed, so we manually unroll three levels here - (decorator (identifier)@name) - (decorator (member_expression object:(identifier)@name)) - (decorator (member_expression object:(member_expression object:(identifier)@name))) - (decorator (member_expression object:(member_expression object:(member_expression object:(identifier)@name)))) - (decorator (call_expression function:(identifier)@name)) - (decorator (call_expression function:(member_expression object:(identifier)@name))) - (decorator (call_expression function:(member_expression object:(member_expression object:(identifier)@name)))) - (decorator (call_expression function:(member_expression object:(member_expression object:(member_expression object:(identifier)@name))))) -; #dialect tsx - (nested_identifier object:(_)@name) - (nested_type_identifier module:(nested_identifier)@name) - (internal_module name:(_)@name) - (jsx_opening_element name: (_)@name) - (jsx_closing_element name: (_)@name) - (jsx_self_closing_element name: (_)@name) -; #end -] { -if none @is_def { +(identifier)@name { node @name.cotype node @name.lexical_defs node @name.lexical_scope node @name.type node @name.var_defs -} -} -[ - (primary_expression/identifier)@name - (decorator (identifier)@name) - ; FIXME expansion of _lhs_expression/identifier and _augmented_assignment_lhs - ; we need to do this for every (identifier) inside a type query - ; this cannot be expressed, so we manually unroll three levels here - (for_in_statement ["var" "let" "const"]?@is_def left:(identifier)@name) - (assignment_expression left:(identifier)@name) - (augmented_assignment_expression left:(identifier)@name) - (asserts (identifier)@name) - (type_predicate name:(identifier)@name) - ; FIXME type_query has its own restricted expression production - (type_query (identifier)@name) - (type_query (member_expression object:(identifier)@name)) - (type_query (member_expression object:(member_expression object:(identifier)@name))) - (type_query (member_expression object:(member_expression object:(member_expression object:(identifier)@name)))) - (type_query (subscript_expression object:(identifier)@name)) - (type_query (subscript_expression object:(member_expression object:(identifier)@name))) - (type_query (subscript_expression object:(member_expression object:(member_expression object:(identifier)@name)))) - (type_query (call_expression function:(identifier)@name)) - (type_query (call_expression function:(member_expression object:(identifier)@name))) - (type_query (call_expression function:(member_expression object:(member_expression object:(identifier)@name)))) - (type_query (call_expression function:(member_expression object:(member_expression object:(member_expression object:(identifier)@name))))) - (type_query (call_expression function:(subscript_expression object:(identifier)@name))) - (type_query (call_expression function:(subscript_expression object:(member_expression object:(identifier)@name)))) - (type_query (call_expression function:(subscript_expression object:(member_expression object:(member_expression object:(identifier)@name))))) - ; FIXME decorator has its own restricted expression production - ; we need to do this for every (identifier) inside a decorator - ; this cannot be expressed, so we manually unroll three levels here - (decorator (identifier)@name) - (decorator (member_expression object:(identifier)@name)) - (decorator (member_expression object:(member_expression object:(identifier)@name))) - (decorator (member_expression object:(member_expression object:(member_expression object:(identifier)@name)))) - (decorator (call_expression function:(identifier)@name)) - (decorator (call_expression function:(member_expression object:(identifier)@name))) - (decorator (call_expression function:(member_expression object:(member_expression object:(identifier)@name)))) - (decorator (call_expression function:(member_expression object:(member_expression object:(member_expression object:(identifier)@name))))) -; #dialect tsx -; (nested_identifier object:(identifier)@name property:(identifier)) ; to pick up foo in JSX: ; FIXME never matched - (jsx_opening_element name: (identifier)@name) - (jsx_closing_element name: (identifier)@name) - (jsx_self_closing_element name: (identifier)@name) -; #end -] { -if none @is_def { node @name.expr_ref node @name.expr_ref__ns node @name.expr_ref__typeof @@ -2898,7 +2813,67 @@ if none @is_def { attr (@name.expr_ref__typeof) push_symbol = ":" edge @name.expr_ref__typeof -> @name.expr_ref } -} + +; [ +; (primary_expression/identifier)@name +; ; FIXME expansion of _lhs_expression/identifier and _augmented_assignment_lhs +; ; we need to do this for every (identifier) inside a type query +; ; this cannot be expressed, so we manually unroll three levels here +; (for_in_statement ["var" "let" "const"]?@is_def left:(identifier)@name) +; (assignment_expression left:(identifier)@name) +; (augmented_assignment_expression left:(identifier)@name) +; (asserts (identifier)@name) +; (type_predicate name:(identifier)@name) +; ; FIXME type_query has its own restricted expression production +; ; we need to do this for every (identifier) inside a type query +; ; this cannot be expressed, so we manually unroll three levels here +; (type_query (identifier)@name) +; (type_query (member_expression object:(identifier)@name)) +; (type_query (member_expression object:(member_expression object:(identifier)@name))) +; (type_query (member_expression object:(member_expression object:(member_expression object:(identifier)@name)))) +; (type_query (subscript_expression object:(identifier)@name)) +; (type_query (subscript_expression object:(member_expression object:(identifier)@name))) +; (type_query (subscript_expression object:(member_expression object:(member_expression object:(identifier)@name)))) +; (type_query (call_expression function:(identifier)@name)) +; (type_query (call_expression function:(member_expression object:(identifier)@name))) +; (type_query (call_expression function:(member_expression object:(member_expression object:(identifier)@name)))) +; (type_query (call_expression function:(member_expression object:(member_expression object:(member_expression object:(identifier)@name))))) +; (type_query (call_expression function:(subscript_expression object:(identifier)@name))) +; (type_query (call_expression function:(subscript_expression object:(member_expression object:(identifier)@name)))) +; (type_query (call_expression function:(subscript_expression object:(member_expression object:(member_expression object:(identifier)@name))))) +; ; FIXME decorator has its own restricted expression production +; ; we need to do this for every (identifier) inside a decorator +; ; this cannot be expressed, so we manually unroll three levels here +; (decorator (identifier)@name) +; (decorator (member_expression object:(identifier)@name)) +; (decorator (member_expression object:(member_expression object:(identifier)@name))) +; (decorator (member_expression object:(member_expression object:(member_expression object:(identifier)@name)))) +; (decorator (call_expression function:(identifier)@name)) +; (decorator (call_expression function:(member_expression object:(identifier)@name))) +; (decorator (call_expression function:(member_expression object:(member_expression object:(identifier)@name)))) +; (decorator (call_expression function:(member_expression object:(member_expression object:(member_expression object:(identifier)@name))))) +; ; FIXME nested_identifier has its own restricted expression production +; ; we need to do this for every (identifier) inside a decorator +; ; this cannot be expressed, so we manually unroll three levels here +; (nested_identifier object:(identifier)@name) +; (nested_identifier object:(member_expression object:(identifier)@name)) +; (nested_identifier object:(member_expression object:(member_expression object:(identifier)@name))) +; (nested_identifier object:(member_expression object:(member_expression object:(member_expression object:(identifier)@name)))) +; ; #dialect tsx +; (jsx_opening_element name: (identifier)@name) +; (jsx_closing_element name: (identifier)@name) +; (jsx_self_closing_element name: (identifier)@name) +; ; #end +; ] { +; if none @is_def { +; ; node @name.cotype +; ; node @name.lexical_defs +; ; node @name.lexical_scope +; ; node @name.type +; ; node @name.var_defs + +; } +; } @@ -3551,12 +3526,10 @@ if none @is_async { ; (member_expression (identifier) (property_identifier)) ; (subscript_expression (identifier) (string)) -[ - (member_expression object:(_)@object property:(_)@prop)@member_expr -; #dialect tsx -; (nested_identifier object:(_)@object property:(identifier)@prop)@member_expr ; FIXME this never matched anything! -; #end - ] { +(member_expression + object:(_)@object + property:(_)@prop +)@member_expr { node @member_expr.member node @prop.expr_ref node @prop.expr_ref__typeof @@ -3578,7 +3551,6 @@ if none @is_async { edge @prop.expr_ref__typeof -> @prop.expr_ref } - (subscript_expression object: (_)@object index: (_)@index @@ -4158,16 +4130,6 @@ if none @is_async { node @pat.defs } -[ ; NOTE these are the ones not also variables - (for_in_statement ["var" "let" "const"] left:(identifier)@name) - (variable_declarator name:(identifier)@name) - (pattern/identifier)@name - (rest_pattern (identifier)@name) -] { - node @name.cotype - node @name.lexical_scope -} - [ (for_in_statement ["var" "let" "const"] left:(identifier)@name) (variable_declarator name:(identifier)@name) @@ -5603,8 +5565,14 @@ if none @is_acc { [ ; X (nested_type_identifier module:(identifier)@name) - ; X._, _.X._ + ; X._ (nested_identifier object:(identifier)@name) + ; _.X._ + (member_expression object:(identifier)@name) + ; _.X + (nested_identifier property:(_)@name) + ; _._.X + (member_expression property:(_)@name) ] { node @name.type_ref attr (@name.type_ref) node_reference = @name @@ -5615,16 +5583,25 @@ if none @is_acc { edge @name.type_ref_member -> @name.type_ref } -(nested_identifier object:(_)@mod) @nested { +[ + (nested_identifier object:(_)@mod) + (member_expression object:[(member_expression) (identifier)]@mod) +]@nested { node @nested.type_ref edge @mod.type_ref -> @nested.type_ref } -(nested_identifier . (_)@mod . (_)@name .) { +[ + (nested_identifier object:(_)@mod property:(_)@name) + (member_expression object:[(member_expression) (identifier)]@mod property:(_)@name) +] { edge @name.type_ref -> @mod.type_ref_member } -(nested_identifier property:(_)@name) @nested { +[ + (nested_identifier property:(_)@name) + (member_expression property:(_)@name) +]@nested { node @nested.type_ref_member edge @nested.type_ref_member -> @name.type_ref_member } diff --git a/languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_namespace_name.tsx.skip b/languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_namespace_name.tsx similarity index 100% rename from languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_namespace_name.tsx.skip rename to languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_namespace_name.tsx diff --git a/languages/tree-sitter-stack-graphs-typescript/test/modules/very-deep-namespace.ts.skip b/languages/tree-sitter-stack-graphs-typescript/test/modules/very-deep-namespace.ts similarity index 100% rename from languages/tree-sitter-stack-graphs-typescript/test/modules/very-deep-namespace.ts.skip rename to languages/tree-sitter-stack-graphs-typescript/test/modules/very-deep-namespace.ts diff --git a/languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts.skip b/languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts similarity index 100% rename from languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts.skip rename to languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-nested-namespace-by-fully-qualified-name.ts diff --git a/languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts.skip b/languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts similarity index 100% rename from languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts.skip rename to languages/tree-sitter-stack-graphs-typescript/test/statements/refer-to-interface-in-qualified-namespace-by-fully-qualified-name.ts From bba2dc482d1206209837f699f49527895c48619e Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 12:32:35 +0100 Subject: [PATCH 05/15] Try updated runner image to fix valgrind problem --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d6ec91bb..f217e8140 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,9 @@ concurrency: jobs: test-rust: - runs-on: ubuntu-latest + # We force a newer runner version to fix a problem with Valgrind. + # Currently, ubuntu-latest is set to 22.04. Revert this back to ubuntu-latest once it is set to 24.04. + runs-on: ubuntu-24.04 strategy: matrix: rust: [stable] From aea8b85a19746326c8e707f6b10ea724b6f78c74 Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 12:06:30 +0000 Subject: [PATCH 06/15] Ignore Valgrind warnings introduced by Rust 1.83 --- .github/workflows/ci.yml | 4 +++ stack-graphs/valgrind.supp | 74 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 stack-graphs/valgrind.supp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f217e8140..36cab862c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,6 +57,10 @@ jobs: - name: Run test suite under valgrind (default features) # We only need to use valgrind to test the crates that have C bindings. run: cargo valgrind test -p stack-graphs + env: + # Since Rust 1.83, Valgrind reports some possible leaks that cargo-valgrind + # treats as fatal. The given suppressions file makes sure these are ignored. + VALGRINDFLAGS: --suppressions=valgrind.supp - name: Ensure C headers are up to date run: | script/cbindgen diff --git a/stack-graphs/valgrind.supp b/stack-graphs/valgrind.supp new file mode 100644 index 000000000..3986abc5b --- /dev/null +++ b/stack-graphs/valgrind.supp @@ -0,0 +1,74 @@ +{ + rust-1.83-false-positive-1 + Memcheck:Param + statx(file_name) + fun:statx + fun:statx + fun:_ZN3std3sys3pal4unix2fs9try_statx17h2609435043bb8525E + fun:{closure#0} + fun:run_with_cstr_stack + fun:run_with_cstr + fun:run_path_with_cstr + fun:_ZN3std3sys3pal4unix2fs4stat17ha588398797a44835E + fun:metadata<&std::path::PathBuf> + fun:get_dbpath_for_term + fun:from_name + fun:_ZN4test4term8terminfo8TermInfo8from_env17h9b3ad5763ddd396cE + fun:new + fun:_ZN4test4term6stdout17hf274a19176f765bcE + fun:_ZN4test7console17run_tests_console17h3d81643311f50681E + fun:_ZN4test9test_main17h6c0fc3221ed0faa4E + fun:_ZN4test16test_main_static17h897b969e33229363E + fun:_ZN2it4main17hfbc3179ed1c35941E + fun:_ZN4core3ops8function6FnOnce9call_once17h945f64a17647f84cE + fun:_ZN3std3sys9backtrace28__rust_begin_short_backtrace17h41138d0332b09746E + fun:_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h98fa5fc32f9b0a38E +} +{ + rust-1.83-false-positive-2 + Memcheck:Param + statx(buf) + fun:statx + fun:statx + fun:_ZN3std3sys3pal4unix2fs9try_statx17h2609435043bb8525E + fun:{closure#0} + fun:run_with_cstr_stack + fun:run_with_cstr + fun:run_path_with_cstr + fun:_ZN3std3sys3pal4unix2fs4stat17ha588398797a44835E + fun:metadata<&std::path::PathBuf> + fun:get_dbpath_for_term + fun:from_name + fun:_ZN4test4term8terminfo8TermInfo8from_env17h9b3ad5763ddd396cE + fun:new + fun:_ZN4test4term6stdout17hf274a19176f765bcE + fun:_ZN4test7console17run_tests_console17h3d81643311f50681E + fun:_ZN4test9test_main17h6c0fc3221ed0faa4E + fun:_ZN4test16test_main_static17h897b969e33229363E + fun:_ZN2it4main17hfbc3179ed1c35941E + fun:_ZN4core3ops8function6FnOnce9call_once17h945f64a17647f84cE + fun:_ZN3std3sys9backtrace28__rust_begin_short_backtrace17h41138d0332b09746E + fun:_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h98fa5fc32f9b0a38E +} +{ + rust-1.83-false-positive-3 + Memcheck:Leak + match-leak-kinds: possible + fun:malloc + fun:alloc + fun:alloc_impl + fun:allocate + fun:{closure#0} + fun:allocate_for_layout, alloc::sync::{impl#14}::new_uninit::{closure_env#0}, fn(*mut u8) -> *mut alloc::sync::ArcInner>> + fun:new_uninit + fun:new_inner + fun:new_main + fun:init + fun:{closure#0} + fun:do_call + fun:try<(), std::rt::lang_start_internal::{closure_env#0}> + fun:catch_unwind + fun:_ZN3std2rt19lang_start_internal17h1c66660c99c8424cE + fun:_ZN3std2rt10lang_start17hb778ad044944e8a4E + fun:main +} From af722227cfdffc9823bb40c39be89cfcc763b5ef Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 13:14:42 +0100 Subject: [PATCH 07/15] Set release dates --- languages/tree-sitter-stack-graphs-java/CHANGELOG.md | 2 +- languages/tree-sitter-stack-graphs-javascript/CHANGELOG.md | 2 +- languages/tree-sitter-stack-graphs-python/CHANGELOG.md | 2 +- lsp-positions/CHANGELOG.md | 2 +- stack-graphs/CHANGELOG.md | 2 +- tree-sitter-stack-graphs/CHANGELOG.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/languages/tree-sitter-stack-graphs-java/CHANGELOG.md b/languages/tree-sitter-stack-graphs-java/CHANGELOG.md index 23400faf0..d295d8ce0 100644 --- a/languages/tree-sitter-stack-graphs-java/CHANGELOG.md +++ b/languages/tree-sitter-stack-graphs-java/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## v0.5.0 -- Unreleased +## v0.5.0 -- 2024-12-12 - The `tree-sitter-stack-graphs` dependency is updated to version 0.10. diff --git a/languages/tree-sitter-stack-graphs-javascript/CHANGELOG.md b/languages/tree-sitter-stack-graphs-javascript/CHANGELOG.md index 10f85abdd..ae90a2f01 100644 --- a/languages/tree-sitter-stack-graphs-javascript/CHANGELOG.md +++ b/languages/tree-sitter-stack-graphs-javascript/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## v0.3.0 -- Unreleased +## v0.3.0 -- 2024-12-12 - The `tree-sitter-stack-graphs` dependency is updated to version 0.10. diff --git a/languages/tree-sitter-stack-graphs-python/CHANGELOG.md b/languages/tree-sitter-stack-graphs-python/CHANGELOG.md index 8ec44913d..f21aecc9f 100644 --- a/languages/tree-sitter-stack-graphs-python/CHANGELOG.md +++ b/languages/tree-sitter-stack-graphs-python/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## v0.3.0 -- Unreleased +## v0.3.0 -- 2024-12-12 - The `tree-sitter-stack-graphs` dependency is updated to version 0.10. diff --git a/lsp-positions/CHANGELOG.md b/lsp-positions/CHANGELOG.md index 84aa962b4..f80bc5c5d 100644 --- a/lsp-positions/CHANGELOG.md +++ b/lsp-positions/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## v0.3.4 -- Unreleased +## v0.3.4 -- 2024-12-12 Upgraded the `tree-sitter` dependency to version 0.24. diff --git a/stack-graphs/CHANGELOG.md b/stack-graphs/CHANGELOG.md index aae6a2998..802275fc2 100644 --- a/stack-graphs/CHANGELOG.md +++ b/stack-graphs/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## v0.14.1 -- Unpublished +## v0.14.1 -- 2024-12-12 ### Fixed diff --git a/tree-sitter-stack-graphs/CHANGELOG.md b/tree-sitter-stack-graphs/CHANGELOG.md index b45b69b64..e1df552e4 100644 --- a/tree-sitter-stack-graphs/CHANGELOG.md +++ b/tree-sitter-stack-graphs/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## v0.10.0 -- Unreleased +## v0.10.0 -- 2024-12-12 Upgraded `tree-sitter` dependency to version 0.24. From 0bd07ba011ac7ae519e246af395e0c80d85eec8f Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 13:19:48 +0100 Subject: [PATCH 08/15] Update test dependency version --- script/ci-test-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/ci-test-init b/script/ci-test-init index c58532fd5..0ecc60788 100755 --- a/script/ci-test-init +++ b/script/ci-test-init @@ -7,7 +7,7 @@ cargo run --bin tree-sitter-stack-graphs --features cli -- init \ --language-id init_test \ --language-file-extension it \ --grammar-crate-name tree-sitter-python \ - --grammar-crate-version 0.20.0 \ + --grammar-crate-version 0.23.2 \ --internal \ --non-interactive From 68ce497b225fdccf34347d87b6458aca41b8bb5e Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 13:51:20 +0100 Subject: [PATCH 09/15] Bump actions versions --- .github/workflows/ci.yml | 18 +++++------ .github/workflows/perf.yml | 30 +++++++++---------- .github/workflows/publish-lsp-positions.yml | 4 +-- .github/workflows/publish-stack-graphs.yml | 4 +-- .../publish-tree-sitter-stack-graphs-java.yml | 4 +-- ...sh-tree-sitter-stack-graphs-javascript.yml | 4 +-- ...ublish-tree-sitter-stack-graphs-python.yml | 4 +-- ...sh-tree-sitter-stack-graphs-typescript.yml | 4 +-- .../publish-tree-sitter-stack-graphs.yml | 4 +-- 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36cab862c..41105a33c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,11 +31,11 @@ jobs: - name: Install cargo-hack run: cargo install cargo-hack - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Check formatting run: cargo fmt --all -- --check - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo @@ -79,9 +79,9 @@ jobs: with: rust-version: ${{ matrix.rust }} - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo @@ -99,7 +99,7 @@ jobs: working-directory: languages steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: List languages id: language-list run: echo "languages=$(find -mindepth 1 -maxdepth 1 -type d -printf '%P\n' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT @@ -122,7 +122,7 @@ jobs: - name: Install cargo-hack run: cargo install cargo-hack - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo @@ -131,7 +131,7 @@ jobs: restore-keys: | ${{ runner.OS }}-cargo- - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build (all feature combinations) run: cargo hack -p ${{ matrix.language }} --feature-powerset build - name: Test (all features) @@ -152,7 +152,7 @@ jobs: with: rust-version: ${{ matrix.rust }} - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo @@ -161,7 +161,7 @@ jobs: restore-keys: | ${{ runner.OS }}-cargo- - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: lfs: true - name: Build diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index 5c4288c84..7da0f9ef8 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -37,7 +37,7 @@ jobs: done: ${{ steps.done.outputs.cache-hit }} steps: - name: "Checkout base code" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{ env.BASE_REPO }} ref: ${{ env.BASE_SHA }} @@ -49,7 +49,7 @@ jobs: printf 'BASE_SHA=%s\n' "$(git rev-list -1 ${{ env.BASE_SHA }} -- stack-graphs)" >> $GITHUB_ENV working-directory: ${{ env.BASE_DIR }} - name: "Checkout head code" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{ env.HEAD_REPO }} ref: ${{ env.HEAD_SHA }} @@ -62,7 +62,7 @@ jobs: working-directory: ${{ env.HEAD_DIR }} - name: "Check cached status" id: done - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 with: path: done key: ${{ runner.os }}-perf-tested-${{ env.BASE_REPO }}@${{ env.BASE_SHA }}-${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }}-${{ env.TEST_NAME }} @@ -83,7 +83,7 @@ jobs: with: rust-version: stable - name: Cache Rust dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo @@ -94,7 +94,7 @@ jobs: sudo apt-get install -y valgrind - name: "Cache base result" id: cache-base-result - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ${{ env.MASSIF_OUT }} @@ -102,7 +102,7 @@ jobs: key: ${{ runner.os }}-perf-result-${{ env.BASE_REPO }}@${{ env.BASE_SHA }}-${{ env.TEST_NAME }} - name: "Checkout base code" if: steps.cache-base-result.outputs.cache-hit != 'true' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{ env.BASE_REPO }} ref: ${{ env.BASE_SHA }} @@ -130,7 +130,7 @@ jobs: ${{ env.BASE_DIR }}/data/${{ env.TEST_NAME }} ms_print ${{ env.MASSIF_OUT }} > ${{ env.MASSIF_REPORT }} - name: Upload results - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ env.BASE_ARTIFACT }} path: | @@ -152,7 +152,7 @@ jobs: with: rust-version: stable - name: Cache Rust dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo @@ -163,7 +163,7 @@ jobs: sudo apt-get install -y valgrind - name: "Cache head result" id: cache-head-result - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ${{ env.MASSIF_OUT }} @@ -171,7 +171,7 @@ jobs: key: ${{ runner.os }}-perf-result-${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }}-${{ env.TEST_NAME }} - name: "Checkout head code" if: steps.cache-head-result.outputs.cache-hit != 'true' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: ${{ env.HEAD_REPO }} ref: ${{ env.HEAD_SHA }} @@ -199,7 +199,7 @@ jobs: ${{ env.HEAD_DIR }}/data/${{ env.TEST_NAME }} ms_print ${{ env.MASSIF_OUT }} > ${{ env.MASSIF_REPORT }} - name: Upload results - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ env.HEAD_ARTIFACT }} path: | @@ -233,12 +233,12 @@ jobs: # Download results # - name: Download base results - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ env.BASE_ARTIFACT }} path: ${{ env.BASE_ARTIFACT }} - name: Download head results - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ env.HEAD_ARTIFACT }} path: ${{ env.HEAD_ARTIFACT }} @@ -246,7 +246,7 @@ jobs: # Create report # - name: "Checkout code" - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: ${{ env.SRC_DIR }} - name: Generate summary @@ -268,7 +268,7 @@ jobs: - name: Create status marker run: touch done - name: "Cache status" - uses: actions/cache/save@v3 + uses: actions/cache/save@v4 with: path: done key: ${{ runner.os }}-perf-tested-${{ env.BASE_REPO }}@${{ env.BASE_SHA }}-${{ env.HEAD_REPO }}@${{ env.HEAD_SHA }}-${{ env.TEST_NAME }} diff --git a/.github/workflows/publish-lsp-positions.yml b/.github/workflows/publish-lsp-positions.yml index 210662a00..dd021646b 100644 --- a/.github/workflows/publish-lsp-positions.yml +++ b/.github/workflows/publish-lsp-positions.yml @@ -16,7 +16,7 @@ jobs: - name: Install Rust environment uses: hecrj/setup-rust-action@v1 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # TODO Verify the crate version matches the tag - name: Test crate run: cargo test --all-features @@ -36,7 +36,7 @@ jobs: contents: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create GitHub release uses: ncipollo/release-action@v1 with: diff --git a/.github/workflows/publish-stack-graphs.yml b/.github/workflows/publish-stack-graphs.yml index 641a93488..b94e0337f 100644 --- a/.github/workflows/publish-stack-graphs.yml +++ b/.github/workflows/publish-stack-graphs.yml @@ -16,7 +16,7 @@ jobs: - name: Install Rust environment uses: hecrj/setup-rust-action@v1 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # TODO Verify the crate version matches the tag - name: Test crate run: cargo test --all-features @@ -36,7 +36,7 @@ jobs: contents: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create GitHub release uses: ncipollo/release-action@v1 with: diff --git a/.github/workflows/publish-tree-sitter-stack-graphs-java.yml b/.github/workflows/publish-tree-sitter-stack-graphs-java.yml index 6d7afb769..64e9f3bf2 100644 --- a/.github/workflows/publish-tree-sitter-stack-graphs-java.yml +++ b/.github/workflows/publish-tree-sitter-stack-graphs-java.yml @@ -16,7 +16,7 @@ jobs: - name: Install Rust environment uses: hecrj/setup-rust-action@v1 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # TODO Verify the crate version matches the tag - name: Test crate run: cargo test --all-features @@ -36,7 +36,7 @@ jobs: contents: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create GitHub release uses: ncipollo/release-action@v1 with: diff --git a/.github/workflows/publish-tree-sitter-stack-graphs-javascript.yml b/.github/workflows/publish-tree-sitter-stack-graphs-javascript.yml index ff6826770..48375d9d4 100644 --- a/.github/workflows/publish-tree-sitter-stack-graphs-javascript.yml +++ b/.github/workflows/publish-tree-sitter-stack-graphs-javascript.yml @@ -16,7 +16,7 @@ jobs: - name: Install Rust environment uses: hecrj/setup-rust-action@v1 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # TODO Verify the crate version matches the tag - name: Test crate run: cargo test --all-features @@ -36,7 +36,7 @@ jobs: contents: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create GitHub release uses: ncipollo/release-action@v1 with: diff --git a/.github/workflows/publish-tree-sitter-stack-graphs-python.yml b/.github/workflows/publish-tree-sitter-stack-graphs-python.yml index 5d6c83ba2..77804c28e 100644 --- a/.github/workflows/publish-tree-sitter-stack-graphs-python.yml +++ b/.github/workflows/publish-tree-sitter-stack-graphs-python.yml @@ -16,7 +16,7 @@ jobs: - name: Install Rust environment uses: hecrj/setup-rust-action@v1 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # TODO Verify the crate version matches the tag - name: Test crate run: cargo test --all-features @@ -36,7 +36,7 @@ jobs: contents: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create GitHub release uses: ncipollo/release-action@v1 with: diff --git a/.github/workflows/publish-tree-sitter-stack-graphs-typescript.yml b/.github/workflows/publish-tree-sitter-stack-graphs-typescript.yml index a3409f397..3fdbe17e2 100644 --- a/.github/workflows/publish-tree-sitter-stack-graphs-typescript.yml +++ b/.github/workflows/publish-tree-sitter-stack-graphs-typescript.yml @@ -16,7 +16,7 @@ jobs: - name: Install Rust environment uses: hecrj/setup-rust-action@v1 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # TODO Verify the crate version matches the tag - name: Test crate run: cargo test --all-features @@ -36,7 +36,7 @@ jobs: contents: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create GitHub release uses: ncipollo/release-action@v1 with: diff --git a/.github/workflows/publish-tree-sitter-stack-graphs.yml b/.github/workflows/publish-tree-sitter-stack-graphs.yml index 031289464..2dfb743a1 100644 --- a/.github/workflows/publish-tree-sitter-stack-graphs.yml +++ b/.github/workflows/publish-tree-sitter-stack-graphs.yml @@ -16,7 +16,7 @@ jobs: - name: Install Rust environment uses: hecrj/setup-rust-action@v1 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # TODO Verify the crate version matches the tag - name: Test crate run: cargo test --all-features @@ -36,7 +36,7 @@ jobs: contents: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create GitHub release uses: ncipollo/release-action@v1 with: From b3409fca73900d01656d02ddea86084a37b25e8d Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 13:59:37 +0100 Subject: [PATCH 10/15] Revert "Try updated runner image to fix valgrind problem" This reverts commit bba2dc482d1206209837f699f49527895c48619e. --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41105a33c..0b025b26d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,9 +13,7 @@ concurrency: jobs: test-rust: - # We force a newer runner version to fix a problem with Valgrind. - # Currently, ubuntu-latest is set to 22.04. Revert this back to ubuntu-latest once it is set to 24.04. - runs-on: ubuntu-24.04 + runs-on: ubuntu-latest strategy: matrix: rust: [stable] From 11c05cb0b49c9330ad077fdfce13768d016e449d Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 13:19:15 +0000 Subject: [PATCH 11/15] Simplify suppresion traces --- stack-graphs/valgrind.supp | 56 ++++---------------------------------- 1 file changed, 6 insertions(+), 50 deletions(-) diff --git a/stack-graphs/valgrind.supp b/stack-graphs/valgrind.supp index 3986abc5b..dbccaa257 100644 --- a/stack-graphs/valgrind.supp +++ b/stack-graphs/valgrind.supp @@ -3,72 +3,28 @@ Memcheck:Param statx(file_name) fun:statx - fun:statx - fun:_ZN3std3sys3pal4unix2fs9try_statx17h2609435043bb8525E - fun:{closure#0} - fun:run_with_cstr_stack - fun:run_with_cstr - fun:run_path_with_cstr - fun:_ZN3std3sys3pal4unix2fs4stat17ha588398797a44835E - fun:metadata<&std::path::PathBuf> + ... fun:get_dbpath_for_term - fun:from_name - fun:_ZN4test4term8terminfo8TermInfo8from_env17h9b3ad5763ddd396cE - fun:new - fun:_ZN4test4term6stdout17hf274a19176f765bcE - fun:_ZN4test7console17run_tests_console17h3d81643311f50681E - fun:_ZN4test9test_main17h6c0fc3221ed0faa4E - fun:_ZN4test16test_main_static17h897b969e33229363E - fun:_ZN2it4main17hfbc3179ed1c35941E - fun:_ZN4core3ops8function6FnOnce9call_once17h945f64a17647f84cE - fun:_ZN3std3sys9backtrace28__rust_begin_short_backtrace17h41138d0332b09746E - fun:_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h98fa5fc32f9b0a38E + ... } { rust-1.83-false-positive-2 Memcheck:Param statx(buf) fun:statx - fun:statx - fun:_ZN3std3sys3pal4unix2fs9try_statx17h2609435043bb8525E - fun:{closure#0} - fun:run_with_cstr_stack - fun:run_with_cstr - fun:run_path_with_cstr - fun:_ZN3std3sys3pal4unix2fs4stat17ha588398797a44835E - fun:metadata<&std::path::PathBuf> + ... fun:get_dbpath_for_term - fun:from_name - fun:_ZN4test4term8terminfo8TermInfo8from_env17h9b3ad5763ddd396cE - fun:new - fun:_ZN4test4term6stdout17hf274a19176f765bcE - fun:_ZN4test7console17run_tests_console17h3d81643311f50681E - fun:_ZN4test9test_main17h6c0fc3221ed0faa4E - fun:_ZN4test16test_main_static17h897b969e33229363E - fun:_ZN2it4main17hfbc3179ed1c35941E - fun:_ZN4core3ops8function6FnOnce9call_once17h945f64a17647f84cE - fun:_ZN3std3sys9backtrace28__rust_begin_short_backtrace17h41138d0332b09746E - fun:_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h98fa5fc32f9b0a38E + ... } { rust-1.83-false-positive-3 Memcheck:Leak match-leak-kinds: possible fun:malloc - fun:alloc - fun:alloc_impl - fun:allocate - fun:{closure#0} - fun:allocate_for_layout, alloc::sync::{impl#14}::new_uninit::{closure_env#0}, fn(*mut u8) -> *mut alloc::sync::ArcInner>> + ... fun:new_uninit fun:new_inner fun:new_main fun:init - fun:{closure#0} - fun:do_call - fun:try<(), std::rt::lang_start_internal::{closure_env#0}> - fun:catch_unwind - fun:_ZN3std2rt19lang_start_internal17h1c66660c99c8424cE - fun:_ZN3std2rt10lang_start17hb778ad044944e8a4E - fun:main + ... } From e3b1afea05c5c32244c5fee06a5bfe649fc4d505 Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 14:33:36 +0100 Subject: [PATCH 12/15] Save valgrind logs on failure --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b025b26d..1c2c613d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,13 @@ jobs: env: # Since Rust 1.83, Valgrind reports some possible leaks that cargo-valgrind # treats as fatal. The given suppressions file makes sure these are ignored. - VALGRINDFLAGS: --suppressions=valgrind.supp + VALGRINDFLAGS: --suppressions=valgrind.supp --gen-suppressions=all --log-file=${{ runner.temp }}/valgrind.log + - name: Upload valgrind log + if: ${{ failure() }} + uses: actions/upload-artifact@v4 + with: + name: valgrind logs + path: ${{ runner.temp }}/valgrind.log - name: Ensure C headers are up to date run: | script/cbindgen From 9998fbd2f42b1665475aa2cbf71515d4fa8abf2c Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 14:21:27 +0000 Subject: [PATCH 13/15] Custom valgrind runner to allow capturing logs --- .github/workflows/ci.yml | 12 ++++------- script/ci-test-valgrind | 23 +++++++++++++++++++++ stack-graphs/valgrind.supp => valgrind.supp | 0 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100755 script/ci-test-valgrind rename stack-graphs/valgrind.supp => valgrind.supp (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c2c613d9..adc70b3c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,20 +47,16 @@ jobs: run: ${{ env.CARGO_HACK }} test - name: Run test suite with all optimizations (default features) run: cargo test --release - - name: Install cargo-valgrind + - name: Install valgrind run: | sudo apt-get update sudo apt-get install -y valgrind - cargo install cargo-valgrind - name: Run test suite under valgrind (default features) + id: valgrind # We only need to use valgrind to test the crates that have C bindings. - run: cargo valgrind test -p stack-graphs - env: - # Since Rust 1.83, Valgrind reports some possible leaks that cargo-valgrind - # treats as fatal. The given suppressions file makes sure these are ignored. - VALGRINDFLAGS: --suppressions=valgrind.supp --gen-suppressions=all --log-file=${{ runner.temp }}/valgrind.log + run: script/ci-test-valgrind -p stack-graphs - name: Upload valgrind log - if: ${{ failure() }} + if: ${{ failure() && steps.valgrind.outcome == 'failure' }} uses: actions/upload-artifact@v4 with: name: valgrind logs diff --git a/script/ci-test-valgrind b/script/ci-test-valgrind new file mode 100755 index 000000000..3f5e3dae6 --- /dev/null +++ b/script/ci-test-valgrind @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -eu + +# Start by building the test binary, before we try to get its filename +cargo test "$@" --no-run + +# Cargo does not have a clean way to get the test binary, so we do some text processing here to get it +test="$(cargo test "$@" --no-run 2>&1 | grep 'Executable' | head -1 | sed -e 's/[^(]*(\(.*\)).*$/\1/')" +log="${RUNNER_TEMP-.}/valgrind.log" + +# Run the test binary under valgrind +if ! valgrind \ + --leak-check=full \ + --show-leak-kinds=all \ + --error-exitcode=1 \ + --suppressions=valgrind.supp \ + --gen-suppressions=all \ + --log-file="$log" \ + "$test"; then + echo "Valgrind detected errors! See logs: $log" + exit 1 +fi diff --git a/stack-graphs/valgrind.supp b/valgrind.supp similarity index 100% rename from stack-graphs/valgrind.supp rename to valgrind.supp From d2fd2281ef18af9c822e6cdcbc20f971c09be276 Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 14:28:15 +0000 Subject: [PATCH 14/15] Update suppressions from CI log --- valgrind.supp | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/valgrind.supp b/valgrind.supp index dbccaa257..19b8bb400 100644 --- a/valgrind.supp +++ b/valgrind.supp @@ -1,30 +1,9 @@ { rust-1.83-false-positive-1 - Memcheck:Param - statx(file_name) - fun:statx - ... - fun:get_dbpath_for_term - ... -} -{ - rust-1.83-false-positive-2 - Memcheck:Param - statx(buf) - fun:statx - ... - fun:get_dbpath_for_term - ... -} -{ - rust-1.83-false-positive-3 Memcheck:Leak match-leak-kinds: possible fun:malloc - ... - fun:new_uninit - fun:new_inner - fun:new_main - fun:init - ... + fun:_ZN3std2rt19lang_start_internal17h1c66660c99c8424cE + fun:_ZN3std2rt10lang_start17hb778ad044944e8a4E + fun:main } From 6223c06da3344bd5336cc61c70633985c4c73860 Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Thu, 12 Dec 2024 14:40:17 +0000 Subject: [PATCH 15/15] Remove mangled entries --- valgrind.supp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/valgrind.supp b/valgrind.supp index 19b8bb400..25c3cfbda 100644 --- a/valgrind.supp +++ b/valgrind.supp @@ -3,7 +3,6 @@ Memcheck:Leak match-leak-kinds: possible fun:malloc - fun:_ZN3std2rt19lang_start_internal17h1c66660c99c8424cE - fun:_ZN3std2rt10lang_start17hb778ad044944e8a4E + ... fun:main }