@eagleoutice/flowr 2.13.10 → 2.13.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +33 -33
  2. package/dataflow/environments/default-builtin-config.d.ts +11 -4
  3. package/dataflow/environments/default-builtin-config.js +43 -5
  4. package/dataflow/environments/environment.js +56 -20
  5. package/dataflow/environments/resolve-by-name.js +16 -6
  6. package/dataflow/environments/resolve-helper.d.ts +43 -0
  7. package/dataflow/environments/resolve-helper.js +47 -0
  8. package/dataflow/graph/df-helper.d.ts +48 -1
  9. package/dataflow/graph/df-helper.js +63 -0
  10. package/dataflow/graph/graph.js +24 -13
  11. package/documentation/data/faq/faqs.js +1 -1
  12. package/documentation/data/faq/wiki-faq-store.js +3 -2
  13. package/documentation/data/server/doc-data-server-messages.js +1 -1
  14. package/documentation/doc-readme.js +1 -1
  15. package/documentation/doc-util/doc-files.d.ts +5 -0
  16. package/documentation/doc-util/doc-files.js +13 -3
  17. package/documentation/wiki-analyzer.js +10 -10
  18. package/documentation/wiki-core.js +1 -1
  19. package/documentation/wiki-dataflow-graph.js +3 -3
  20. package/documentation/wiki-linting-and-testing.js +13 -13
  21. package/documentation/wiki-mk/doc-context.d.ts +1 -1
  22. package/documentation/wiki-mk/doc-context.js +9 -5
  23. package/documentation/wiki-normalized-ast.js +1 -1
  24. package/documentation/wiki-overview.js +2 -2
  25. package/documentation/wiki-query.js +1 -1
  26. package/documentation/wiki-setup.js +3 -3
  27. package/linter/linter-rules.d.ts +1 -1
  28. package/linter/rules/syntactically-valid.d.ts +12 -1
  29. package/linter/rules/syntactically-valid.js +88 -17
  30. package/package.json +7 -8
  31. package/project/context/flowr-analyzer-loading-order-context.d.ts +8 -0
  32. package/project/context/flowr-analyzer-loading-order-context.js +23 -2
  33. package/project/sigdb/reader.d.ts +20 -0
  34. package/project/sigdb/reader.js +93 -10
  35. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
  36. package/queries/catalog/dependencies-query/dependencies-query-executor.js +3 -2
  37. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +6 -0
  38. package/queries/catalog/dependencies-query/link-devices.d.ts +7 -3
  39. package/queries/catalog/dependencies-query/link-devices.js +56 -10
  40. package/queries/catalog/happens-before-query/happens-before-query-executor.js +2 -1
  41. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +14 -0
  42. package/queries/catalog/happens-before-query/happens-before-query-format.js +18 -2
  43. package/queries/catalog/signature-query/signature-query-executor.js +5 -1
  44. package/queries/catalog/slice-query-options.d.ts +11 -1
  45. package/queries/catalog/slice-query-options.js +8 -4
  46. package/queries/catalog/static-slice-query/static-slice-query-executor.js +4 -1
  47. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +5 -1
  48. package/r-bridge/lang-4.x/ast/model/model.d.ts +9 -0
  49. package/r-bridge/lang-4.x/ast/model/model.js +12 -0
  50. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  51. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +1 -0
  52. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  53. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  54. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  55. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  56. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  57. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  58. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  59. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  60. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  61. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  62. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  63. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  64. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  65. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  66. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  67. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  68. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  69. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  70. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  71. package/reconstruct/reconstruct.d.ts +9 -0
  72. package/reconstruct/reconstruct.js +1 -0
  73. package/search/flowr-search-filters.d.ts +8 -0
  74. package/search/flowr-search-filters.js +19 -7
  75. package/search/search-executor/search-generators.js +7 -2
  76. package/search/search-executor/search-transformer.js +4 -1
  77. package/slicing/static/slice-call.js +2 -2
  78. package/util/collections/bimap.d.ts +21 -1
  79. package/util/collections/bimap.js +43 -7
  80. package/util/version.js +1 -1
@@ -38,7 +38,7 @@ Primarily, _flowR_ provides a dataflow analysis framework for the [*R*](https://
38
38
  Its subcomponents (like the custom ${ctx.link(shell_1.RShell)}) or the internals of the static ${ctx.link(graph_1.DataflowGraph)})
39
39
  are not important if you simply wish to use _flowR_.
40
40
  If you wish to use _flowR_, check out one of its extensions (e.g., the ${ctx.linkPage('flowr:vscode', 'VS Code extension')}),
41
- the [REPL and server interfaces](#using-_flowr_-from-the-outside) or its coding API with the
41
+ the [REPL and server interfaces](#using-flowr-from-the-outside) or its coding API with the
42
42
  ${ctx.link(flowr_analyzer_1.FlowrAnalyzer)}.
43
43
 
44
44
  The benchmark module is only of interest if you want to benchmark/measure the runtime performance and reduction of the slicer.
@@ -112,7 +112,7 @@ The supported requests are documented alongside the internal documentation, see
112
112
  <details>
113
113
  <summary>Small demonstration using netcat</summary>
114
114
 
115
- ![Example of a simple netcat session](gif/server-demo.gif)
115
+ ![Example of a simple netcat session](gif/server-demo-opt.gif)
116
116
 
117
117
  <details>
118
118
  <summary>Used <a href="https://github.com/charmbracelet/vhs">vhs</a> code</summary>
@@ -1064,7 +1064,7 @@ ${(0, doc_structure_1.block)({
1064
1064
  content: `
1065
1065
  There are many ways to query a dataflow graph created by flowR.
1066
1066
  For example, you can use the ${ctx.linkPage('wiki/Interface', '`request-query`', 'message-request-query')} message
1067
- with a running flowR server, or the ${(0, doc_cli_option_1.getReplCommand)('query')} command in the flowR ${ctx.linkPage('wiki/Interface', 'REPL', 'repl')}.
1067
+ with a running flowR server, or the ${(0, doc_cli_option_1.getReplCommand)('query')} command in the flowR ${ctx.linkPage('wiki/Interface', 'REPL', '-using-the-repl')}.
1068
1068
 
1069
1069
  Also, check out the [${doc_files_1.FlowrGithubGroupName}/sample-analyzer-project-query](${doc_files_1.FlowrGithubBaseRef}/sample-analyzer-project-query) repository for a complete example project using the query API.
1070
1070
  `.trim()
@@ -24,7 +24,7 @@ or use its ${ctx.linkPage('flowr:vscode', 'Visual Studio Code extension')} and $
24
24
 
25
25
 
26
26
  If you want to develop for _flowR_, you want to see how to [build from scratch](#-building-from-scratch) and have a
27
- look at the [Contributing Guidelines](${doc_files_1.RemoteFlowrFilePathBaseRef}/.github/CONTRIBUTING.md).
27
+ look at the [Contributing Guidelines](${doc_files_1.RemoteFlowrFilePathBaseRef}.github/CONTRIBUTING.md).
28
28
 
29
29
  ## 🗒️ Using the Visual Studio Code Extension
30
30
 
@@ -106,7 +106,7 @@ At the time of writing this, there is currently no page for frequently encounter
106
106
  ## 📜 Developing for _flowR_
107
107
 
108
108
  If you want to develop for _flowR_, explore the wiki.
109
- For details on _how_ to contribute, please refer to the [CONTRIBUTING.md](${doc_files_1.RemoteFlowrFilePathBaseRef}/.github/CONTRIBUTING.md) in the repository.
109
+ For details on _how_ to contribute, please refer to the [CONTRIBUTING.md](${doc_files_1.RemoteFlowrFilePathBaseRef}.github/CONTRIBUTING.md) in the repository.
110
110
 
111
111
  ### 📦 The Signature Database
112
112
 
@@ -116,7 +116,7 @@ _flowR_ resolves \`library(pkg)\`/\`pkg::fn\` calls from a downloaded signature
116
116
  <a id="note1" href="#note1ref">&lt;1&gt;</a>: Currently, _flowR_ is only tested with R versions \`4.x\` and \`3.6.x\`.
117
117
 
118
118
  <a id="note2" href="#note2ref">&lt;2&gt;</a>: We use
119
- [git-lfs](https://git-lfs.com/) to store larger files, especially for the wiki pages. So if you want to work on these parts, make sure to have it set-up (see the [CONTRIBUTING.md](${doc_files_1.RemoteFlowrFilePathBaseRef}/.github/CONTRIBUTING.md) in the repository for more information).
119
+ [git-lfs](https://git-lfs.com/) to store larger files, especially for the wiki pages. So if you want to work on these parts, make sure to have it set-up (see the [CONTRIBUTING.md](${doc_files_1.RemoteFlowrFilePathBaseRef}.github/CONTRIBUTING.md) in the repository for more information).
120
120
  `.trim();
121
121
  }
122
122
  }
@@ -379,7 +379,7 @@ export declare const LintingRules: {
379
379
  };
380
380
  };
381
381
  readonly 'syntactically-valid': {
382
- readonly createSearch: () => import("../search/flowr-search-builder").FlowrSearchBuilder<"all", [], import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>;
382
+ readonly createSearch: () => import("../search/flowr-search-builder").FlowrSearchBuilder<"from", [], import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>;
383
383
  readonly processSearchResult: (_elements: import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, config: import("./rules/syntactically-valid").SyntacticallyValidConfig, data: import("../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>) => Promise<{
384
384
  results: import("./rules/syntactically-valid").SyntacticallyValidResult[];
385
385
  ".meta": import("./rules/syntactically-valid").SyntacticallyValidMetadata;
@@ -19,10 +19,21 @@ export interface SyntacticallyValidMetadata extends MergeableRecord {
19
19
  readonly fixable: number;
20
20
  readonly parser: string;
21
21
  }
22
+ /** One pass over an error region, blind to strings and comments. */
23
+ export interface RegionScan {
24
+ /** The closing delimiters the region leaves open, innermost first. */
25
+ readonly closers: readonly string[];
26
+ /** Offset of every `%` outside a string or comment; an odd count means an unclosed `%...%` operator. */
27
+ readonly percentAt: readonly number[];
28
+ }
22
29
  /** A `missing` (parser-inserted, zero-width) or `error` (un-parseable) tree-sitter node. */
23
30
  export interface SyntaxErrorFinding {
24
31
  readonly kind: 'missing' | 'error';
25
32
  readonly node: SyntaxNode;
33
+ /** The source line the node starts on, for patterns judging a pasted line rather than a token. */
34
+ readonly line: string;
35
+ /** The region, scanned on first use. */
36
+ readonly scan: RegionScan;
26
37
  }
27
38
  /** An extensible auto-fix pattern; append to {@link SyntaxErrorFixPatterns} to teach the rule new repairs. */
28
39
  export interface SyntaxErrorFixPattern {
@@ -35,7 +46,7 @@ export interface SyntaxErrorFixPattern {
35
46
  /** The built-in auto-fix patterns; append a {@link SyntaxErrorFixPattern} to add repairs. */
36
47
  export declare const SyntaxErrorFixPatterns: SyntaxErrorFixPattern[];
37
48
  export declare const SYNTACTICALLY_VALID: {
38
- readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", [], import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>;
49
+ readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"from", [], import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>;
39
50
  readonly processSearchResult: (_elements: import("../../search/flowr-search").FlowrSearchElements<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../../search/flowr-search").FlowrSearchElement<import("../../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, config: SyntacticallyValidConfig, data: import("../../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>) => Promise<{
40
51
  results: SyntacticallyValidResult[];
41
52
  ".meta": SyntacticallyValidMetadata;
@@ -9,13 +9,20 @@ const DelimiterInsert = new Map([[')', ')'], ['}', '}'], [']', ']'], [']]', ']]'
9
9
  const KeywordInsert = new Map([['in', ' in '], ['else', ' else ']]);
10
10
  const OperatorToken = /^([-+*/^:~!<>=&|@$]+|<-|<<-|->|->>|\|>|%[^%]*%)$/;
11
11
  const KnownOperators = ['%%', '%/%', '%*%', '%o%', '%x%', '%in%', '%>%', '%<>%', '%+%', '%||%'];
12
+ /** Typographic quotes, as a word processor or a PDF leaves behind. */
13
+ const SmartQuote = new Map([['\u201C', '"'], ['\u201D', '"'], ['\u201E', '"'], ['\u2018', '\''], ['\u2019', '\'']]);
14
+ /** Closing brackets and whitespace only, so nothing there is worth keeping. */
15
+ const OnlyClosers = /^[)\]}\s]+$/;
16
+ /** How R prefixes printed values, never how a statement begins. */
17
+ const ConsoleOutput = /^\s*\[{1,2}\d+\]{1,2}(\s|$)/;
12
18
  // tree-sitter is 0-based with an exclusive end column (matching flowR), so only the 1-based start shifts
13
19
  const point = (p) => [p.row + 1, p.column + 1, p.row + 1, p.column];
14
20
  const span = (n) => [n.startPosition.row + 1, n.startPosition.column + 1, n.endPosition.row + 1, n.endPosition.column];
15
21
  const isDanglingOperator = (n) => !!n && !n.isNamed && OperatorToken.test(n.type);
16
- /** The closing delimiters an unbalanced error region is missing, innermost first (skips strings/comments; `({` needs `})`). */
17
- function bracketDeficit(text) {
22
+ /** Read an error region: what it leaves open, and where its operators sit. */
23
+ function scanRegion(text) {
18
24
  const stack = [];
25
+ const percentAt = [];
19
26
  let quote;
20
27
  for (let i = 0; i < text.length; i++) {
21
28
  const c = text[i];
@@ -35,6 +42,9 @@ function bracketDeficit(text) {
35
42
  i++;
36
43
  }
37
44
  }
45
+ else if (c === '%') {
46
+ percentAt.push(i);
47
+ }
38
48
  else if (c === '(') {
39
49
  stack.push(')');
40
50
  }
@@ -56,12 +66,12 @@ function bracketDeficit(text) {
56
66
  }
57
67
  }
58
68
  }
59
- return stack.reverse();
69
+ return { closers: stack.reverse(), percentAt };
60
70
  }
61
- /** Fuzzy-complete the unfinished `%...` operator in an error region to the nearest known operator (else just close it). */
62
- function operatorCompletion(node) {
63
- const at = node.text.lastIndexOf('%');
64
- const fragment = /^%[A-Za-z0-9]*/.exec(node.text.slice(at))?.[0] ?? '%';
71
+ /** Fuzzy-complete the `%...` operator at `at` to the nearest known one (else just close it). */
72
+ function operatorCompletion(node, at) {
73
+ // R allows anything between the percents; matching letters alone read `%>` as `%` and completed it to `%%`
74
+ const fragment = /^%[^%\s()[\]{},]*/.exec(node.text.slice(at))?.[0] ?? '%';
65
75
  const full = KnownOperators.find(op => op !== fragment && op.startsWith(fragment)) ?? fragment + '%';
66
76
  const column = node.startPosition.column + at;
67
77
  return { range: [node.startPosition.row + 1, column + 1, node.startPosition.row + 1, column + fragment.length], full };
@@ -69,6 +79,20 @@ function operatorCompletion(node) {
69
79
  const isMissingExpression = (f) => f.kind === 'missing' && !DelimiterInsert.has(f.node.type) && !KeywordInsert.has(f.node.type);
70
80
  /** The built-in auto-fix patterns; append a {@link SyntaxErrorFixPattern} to add repairs. */
71
81
  exports.SyntaxErrorFixPatterns = [
82
+ // first, because it judges the whole line: `[1] 1 2 3` errors on both `[` and `]`, and repairing those as
83
+ // brackets balances output text into the program instead of dropping it
84
+ {
85
+ name: 'comment-out-console-output',
86
+ description: 'Comment out a line of pasted R console output, which is missing its `#`.',
87
+ direction: 'comment',
88
+ appliesTo: f => f.kind === 'error' && ConsoleOutput.test(f.line),
89
+ quickFix: (f, file) => ({
90
+ type: 'replace',
91
+ loc: range_1.SourceLocation.from(point({ row: f.node.startPosition.row, column: 0 }), file),
92
+ description: 'Comment out the pasted console output',
93
+ replacement: '# '
94
+ })
95
+ },
72
96
  {
73
97
  name: 'insert-missing-token',
74
98
  description: 'Insert a delimiter, quote, or keyword the parser expected but did not find.',
@@ -99,9 +123,9 @@ exports.SyntaxErrorFixPatterns = [
99
123
  name: 'balance-brackets',
100
124
  description: 'Close an unbalanced region by appending the brackets that were left open.',
101
125
  direction: 'add',
102
- appliesTo: f => f.kind === 'error' && bracketDeficit(f.node.text).length > 0,
126
+ appliesTo: f => f.kind === 'error' && f.scan.closers.length > 0,
103
127
  quickFix: (f, file) => {
104
- const closers = bracketDeficit(f.node.text).join('');
128
+ const closers = f.scan.closers.join('');
105
129
  return { type: 'replace', loc: range_1.SourceLocation.from(point(f.node.endPosition), file), description: `Add missing closing \`${closers}\``, replacement: closers };
106
130
  }
107
131
  },
@@ -109,12 +133,42 @@ exports.SyntaxErrorFixPatterns = [
109
133
  name: 'complete-operator',
110
134
  description: 'Complete an unfinished `%...%` operator to the nearest known one.',
111
135
  direction: 'add',
112
- appliesTo: f => f.kind === 'error' && !f.node.text.includes('\n') && (f.node.text.match(/%/g)?.length ?? 0) % 2 === 1,
136
+ // single-line only: the completion derives its column from the offset within the region
137
+ appliesTo: f => f.kind === 'error' && !f.node.text.includes('\n') && f.scan.percentAt.length % 2 === 1,
113
138
  quickFix: (f, file) => {
114
- const { range, full } = operatorCompletion(f.node);
139
+ const { range, full } = operatorCompletion(f.node, f.scan.percentAt.at(-1));
115
140
  return { type: 'replace', loc: range_1.SourceLocation.from(range, file), description: `Complete operator to \`${full}\``, replacement: full };
116
141
  }
117
142
  },
143
+ {
144
+ name: 'replace-smart-quote',
145
+ description: 'Turn a typographic quote back into the straight quote R can read.',
146
+ direction: 'add',
147
+ appliesTo: f => f.kind === 'error' && SmartQuote.has(f.node.text),
148
+ quickFix: (f, file) => ({
149
+ type: 'replace',
150
+ loc: range_1.SourceLocation.from(span(f.node), file),
151
+ description: 'Replace the typographic quote with a straight one',
152
+ replacement: SmartQuote.get(f.node.text)
153
+ })
154
+ },
155
+ {
156
+ name: 'remove-repl-prompt',
157
+ description: 'Drop a `>` prompt copied in front of a line taken from the R console.',
158
+ direction: 'remove',
159
+ // must open the line: `a > b` parses, and a leading `>=` is a different token
160
+ appliesTo: f => f.kind === 'error' && f.node.text === '>'
161
+ && f.line.slice(0, f.node.startPosition.column).trim() === '',
162
+ quickFix: (f, file) => ({ type: 'remove', loc: range_1.SourceLocation.from(span(f.node), file), description: 'Remove the copied `>` prompt' })
163
+ },
164
+ {
165
+ name: 'remove-stray-closer',
166
+ description: 'Drop closing brackets that close nothing, as a partial copy leaves behind.',
167
+ direction: 'remove',
168
+ // the `]` of `[1]` is a closer too, but there the line goes, not the bracket
169
+ appliesTo: f => f.kind === 'error' && OnlyClosers.test(f.node.text) && !ConsoleOutput.test(f.line),
170
+ quickFix: (f, file) => ({ type: 'remove', loc: range_1.SourceLocation.from(span(f.node), file), description: `Remove the stray \`${f.node.text.replace(/\s+/g, '')}\`` })
171
+ },
118
172
  {
119
173
  name: 'comment-out',
120
174
  description: 'Comment out an un-parseable region so the rest of the file still parses.',
@@ -124,16 +178,27 @@ exports.SyntaxErrorFixPatterns = [
124
178
  }
125
179
  ];
126
180
  /** Collect the outermost `missing`/`error` nodes, pruning subtrees the parser reports as clean. */
127
- function collectFindings(node, out = []) {
181
+ function finding(kind, node, lines) {
182
+ let scan;
183
+ return {
184
+ kind, node,
185
+ line: lines[node.startPosition.row] ?? '',
186
+ // on demand and once: a `missing` node has no text, and two patterns want the same scan
187
+ get scan() {
188
+ return scan ??= scanRegion(node.text);
189
+ }
190
+ };
191
+ }
192
+ function collectFindings(node, lines, out = []) {
128
193
  if (node.isMissing) {
129
- out.push({ kind: 'missing', node });
194
+ out.push(finding('missing', node, lines));
130
195
  }
131
196
  else if (node.isError) {
132
- out.push({ kind: 'error', node });
197
+ out.push(finding('error', node, lines));
133
198
  }
134
199
  else if (node.hasError) {
135
200
  for (const child of node.children) {
136
- collectFindings(child, out);
201
+ collectFindings(child, lines, out);
137
202
  }
138
203
  }
139
204
  return out;
@@ -146,7 +211,8 @@ function describe(finding) {
146
211
  return `Unexpected \`${text.length > 30 ? text.slice(0, 27) + '...' : text}\``;
147
212
  }
148
213
  exports.SYNTACTICALLY_VALID = {
149
- createSearch: () => flowr_search_builder_1.Q.all(),
214
+ // reads the parse tree, not the normalized AST, so `Q.all()` would enumerate every node for nothing
215
+ createSearch: () => flowr_search_builder_1.Q.from([]),
150
216
  processSearchResult: async (_elements, config, data) => {
151
217
  const parser = data.parserInformation().name;
152
218
  const results = [];
@@ -158,7 +224,9 @@ exports.SYNTACTICALLY_VALID = {
158
224
  if (!root.hasError) {
159
225
  continue;
160
226
  }
161
- for (const finding of collectFindings(root)) {
227
+ // the root spans the file verbatim, so its rows index these lines
228
+ const lines = root.text.split('\n');
229
+ for (const finding of collectFindings(root, lines)) {
162
230
  // a single fix per error, favouring the preferred direction (alternatives are never emitted together)
163
231
  let fix;
164
232
  let best = 2;
@@ -167,6 +235,9 @@ exports.SYNTACTICALLY_VALID = {
167
235
  if (rank < best && p.appliesTo(finding)) {
168
236
  fix = p.quickFix(finding, file.filePath);
169
237
  best = rank;
238
+ if (best === 0) {
239
+ break;
240
+ }
170
241
  }
171
242
  }
172
243
  results.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eagleoutice/flowr",
3
- "version": "2.13.10",
3
+ "version": "2.13.12",
4
4
  "description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {
@@ -41,7 +41,7 @@
41
41
  "lint-local": "npm run typecheck && npx eslint --version && npx eslint src/ test/ scripts/ --concurrency=auto --cache --cache-location node_modules/.cache/eslint-local --rule \"no-warning-comments: off\"",
42
42
  "lint": "npm run license-compat -- --summary && npm run typecheck && npx eslint --version && npx eslint src/ test/ scripts/ --concurrency=auto --cache --cache-location node_modules/.cache/eslint",
43
43
  "license-compat": "license-checker-rseidelsohn --onlyAllow 'MIT;MPL-2.0;MIT OR X11;GPLv2;LGPL;GNUGPL;ISC;Apache-2.0;FreeBSD;BSD-2-Clause;clearbsd;ModifiedBSD;BSD-3-Clause;Python-2.0;Unlicense;WTFPL;BlueOak-1.0.0;CC-BY-4.0;CC-BY-3.0;CC0-1.0;0BSD' --clarificationsFile license-clarifications.json",
44
- "doc": "typedoc",
44
+ "doc": "node --max-old-space-size=8192 node_modules/typedoc/dist/cli.js",
45
45
  "test": "vitest --exclude \"test/system-tests/**\" --config test/vitest.config.mts",
46
46
  "test:verbose": "FLOWR_VERBOSE=true vitest --exclude \"test/system-tests/**\" --config test/vitest.config.mts",
47
47
  "test:system": "vitest --dir test/system-tests --config test/system-tests/vitest.config.mts",
@@ -69,8 +69,7 @@
69
69
  "includeVersion": true,
70
70
  "plugin": [
71
71
  "typedoc-umlclass",
72
- "typedoc-plugin-missing-exports",
73
- "typedoc-theme-hierarchy"
72
+ "typedoc-plugin-missing-exports"
74
73
  ],
75
74
  "entryPoints": [
76
75
  "src",
@@ -94,18 +93,19 @@
94
93
  "typescript",
95
94
  "r"
96
95
  ],
97
- "theme": "hierarchy",
98
96
  "out": "doc",
99
97
  "readme": "README.md",
100
98
  "umlClassDiagram": {
101
99
  "type": "detailed",
102
- "location": "embed",
100
+ "location": "local",
103
101
  "format": "svg",
104
102
  "position": "below",
105
103
  "legendType": "none",
106
- "hideEmptyMembers": false,
104
+ "hideEmptyMembers": true,
107
105
  "generatorProcessCount": 4
108
106
  },
107
+ "maxTypeConversionDepth": 4,
108
+ "skipErrorChecking": true,
109
109
  "lightHighlightTheme": "light-plus",
110
110
  "darkHighlightTheme": "dark-plus",
111
111
  "hideGenerator": false,
@@ -213,7 +213,6 @@
213
213
  "ts-node": "^10.9.2",
214
214
  "typedoc": "^0.28.17",
215
215
  "typedoc-plugin-missing-exports": "^4.1.2",
216
- "typedoc-theme-hierarchy": "^6.0.0",
217
216
  "typedoc-umlclass": "^0.10.2",
218
217
  "typescript": "^5.9.3",
219
218
  "vitest": "^4.1.8"
@@ -49,7 +49,15 @@ export declare class FlowrAnalyzerLoadingOrderContext extends AbstractFlowrAnaly
49
49
  private readonly guesses;
50
50
  /** just the base collection of requests we know nothing about the order! */
51
51
  private readonly unordered;
52
+ /** what {@link unordered} already holds, so the same file is never analyzed (and reconstructed) twice */
53
+ private readonly seen;
52
54
  reset(): void;
55
+ /**
56
+ * Registers `request` as unordered unless the same one is already there, reporting whether it was new.
57
+ * Project discovery and the implicit-source scan reach the same file from both ends, so a file otherwise
58
+ * lands in the loading order more than once and every later step repeats it.
59
+ */
60
+ private register;
53
61
  /**
54
62
  * Add one or multiple requests to the context.
55
63
  * These are considered unordered (i.e., ordered implicitly by the order of addition) until a plugin provides either a guess or a known order.
@@ -23,12 +23,29 @@ class FlowrAnalyzerLoadingOrderContext extends abstract_flowr_analyzer_context_1
23
23
  guesses = [];
24
24
  /** just the base collection of requests we know nothing about the order! */
25
25
  unordered = [];
26
+ /** what {@link unordered} already holds, so the same file is never analyzed (and reconstructed) twice */
27
+ seen = new Set();
26
28
  reset() {
27
29
  this.knownOrder = undefined;
28
30
  this.guesses.length = 0;
29
31
  this.unordered.length = 0;
32
+ this.seen.clear();
30
33
  this.rerunRequired = this.plugins.length > 0;
31
34
  }
35
+ /**
36
+ * Registers `request` as unordered unless the same one is already there, reporting whether it was new.
37
+ * Project discovery and the implicit-source scan reach the same file from both ends, so a file otherwise
38
+ * lands in the loading order more than once and every later step repeats it.
39
+ */
40
+ register(request) {
41
+ const key = `${request.request}\u0000${request.content}`;
42
+ if (this.seen.has(key)) {
43
+ return false;
44
+ }
45
+ this.seen.add(key);
46
+ this.unordered.push(request);
47
+ return true;
48
+ }
32
49
  /**
33
50
  * Add one or multiple requests to the context.
34
51
  * These are considered unordered (i.e., ordered implicitly by the order of addition) until a plugin provides either a guess or a known order.
@@ -36,7 +53,9 @@ class FlowrAnalyzerLoadingOrderContext extends abstract_flowr_analyzer_context_1
36
53
  * This is a batched version of {@link addRequest}.
37
54
  */
38
55
  addRequests(requests) {
39
- this.unordered.push(...requests);
56
+ if (!requests.map(r => this.register(r)).some(Boolean)) {
57
+ return;
58
+ }
40
59
  if (this.knownOrder || this.guesses.length > 0) {
41
60
  loadingOrderLog.warn(`Adding requests ${requests.map(r => r.request).join(', ')} after known order!`);
42
61
  this.rerunRequired = true;
@@ -49,7 +68,9 @@ class FlowrAnalyzerLoadingOrderContext extends abstract_flowr_analyzer_context_1
49
68
  * If you want to add multiple requests, consider using {@link addRequests} instead for efficiency.
50
69
  */
51
70
  addRequest(request) {
52
- this.unordered.push(request);
71
+ if (!this.register(request)) {
72
+ return;
73
+ }
53
74
  if (this.knownOrder || this.guesses.length > 0) {
54
75
  loadingOrderLog.warn(`Adding request ${request.request} ${request.content} after known order!`);
55
76
  this.rerunRequired = true;
@@ -133,6 +133,16 @@ export declare class SigDatabase implements PackageSignatureSource {
133
133
  /** parsed blobs by blob index so repeated lookups skip the re-read + JSON.parse; FIFO-bounded to cap memory */
134
134
  private readonly blobCache;
135
135
  private static readonly BlobCacheCap;
136
+ /** a version's function indices plus its `name -> index` view; FIFO-bounded like {@link blobCache} */
137
+ private readonly versionFnCache;
138
+ /**
139
+ * Which names a package can offer at all, as sorted dictionary ids -- integers, so the whole database of
140
+ * them costs a few MB where the parsed blobs cost hundreds. Filled for a package the first time its blob is
141
+ * read, so a later lookup for a name it does not have answers without touching the file again.
142
+ */
143
+ private readonly nameIdsOfBlob;
144
+ /** dictionary id per name asked for, so only the names someone actually queried are ever resolved */
145
+ private readonly nameIds;
136
146
  /** reverse index `S3 class -> owning package`, over every package's latest version; built once (see {@link classOwner}) */
137
147
  private classIndex;
138
148
  private readonly fd;
@@ -164,6 +174,16 @@ export declare class SigDatabase implements PackageSignatureSource {
164
174
  packageNames(): string[];
165
175
  /** load a single package's blob by seeking to its line (undefined if absent); cached by blob index */
166
176
  blob(pkg: string): PkgBlob | undefined;
177
+ /** the dictionary id of `name`, or `-1` if the dictionary does not hold it, so no package can offer it */
178
+ private nameId;
179
+ /**
180
+ * Whether `pkg` can offer `name` in any of its versions, answered from {@link nameIdsOfBlob} alone.
181
+ * `true` whenever nothing is known about the package yet, so this only ever skips work that would have
182
+ * found nothing: the ids cover every function record, of which a version selects a subset.
183
+ */
184
+ private mayOffer;
185
+ /** store `value` under `key`, dropping the oldest entry first once the cache sits at {@link BlobCacheCap} */
186
+ private static cache;
167
187
  /** seek to a byte range, read + decode the package blob there (no caching) */
168
188
  private readBlobAt;
169
189
  /** read every unique package blob in index order (used to re-hash a whole shard during verification) */
@@ -262,6 +262,16 @@ class SigDatabase {
262
262
  /** parsed blobs by blob index so repeated lookups skip the re-read + JSON.parse; FIFO-bounded to cap memory */
263
263
  blobCache = new Map();
264
264
  static BlobCacheCap = 2048;
265
+ /** a version's function indices plus its `name -> index` view; FIFO-bounded like {@link blobCache} */
266
+ versionFnCache = new Map();
267
+ /**
268
+ * Which names a package can offer at all, as sorted dictionary ids -- integers, so the whole database of
269
+ * them costs a few MB where the parsed blobs cost hundreds. Filled for a package the first time its blob is
270
+ * read, so a later lookup for a name it does not have answers without touching the file again.
271
+ */
272
+ nameIdsOfBlob = new Map();
273
+ /** dictionary id per name asked for, so only the names someone actually queried are ever resolved */
274
+ nameIds = new Map();
265
275
  /** reverse index `S3 class -> owning package`, over every package's latest version; built once (see {@link classOwner}) */
266
276
  classIndex;
267
277
  fd;
@@ -351,14 +361,59 @@ class SigDatabase {
351
361
  return undefined; // an in-memory database starts out with every blob cached
352
362
  }
353
363
  const blob = this.readBlobAt(this.index.blobs[blobIdx]);
354
- if (this.blobCache.size >= SigDatabase.BlobCacheCap) {
355
- const oldest = this.blobCache.keys().next().value;
364
+ if (!this.nameIdsOfBlob.has(blobIdx)) {
365
+ this.nameIdsOfBlob.set(blobIdx, Int32Array.from(new Set(blob.fns.map(fn => fn[0]))).sort());
366
+ }
367
+ return SigDatabase.cache(this.blobCache, blobIdx, blob);
368
+ }
369
+ /** the dictionary id of `name`, or `-1` if the dictionary does not hold it, so no package can offer it */
370
+ nameId(name) {
371
+ let id = this.nameIds.get(name);
372
+ if (id === undefined) {
373
+ this.nameIds.set(name, id = this.strings.indexOf(name));
374
+ }
375
+ return id;
376
+ }
377
+ /**
378
+ * Whether `pkg` can offer `name` in any of its versions, answered from {@link nameIdsOfBlob} alone.
379
+ * `true` whenever nothing is known about the package yet, so this only ever skips work that would have
380
+ * found nothing: the ids cover every function record, of which a version selects a subset.
381
+ */
382
+ mayOffer(pkg, name) {
383
+ const blobIdx = this.index.pkgs[pkg];
384
+ const ids = blobIdx === undefined ? undefined : this.nameIdsOfBlob.get(blobIdx);
385
+ if (ids === undefined) {
386
+ return true;
387
+ }
388
+ const id = this.nameId(name);
389
+ if (id < 0) {
390
+ return false;
391
+ }
392
+ let lo = 0, hi = ids.length - 1;
393
+ while (lo <= hi) {
394
+ const mid = (lo + hi) >> 1;
395
+ if (ids[mid] === id) {
396
+ return true;
397
+ }
398
+ else if (ids[mid] < id) {
399
+ lo = mid + 1;
400
+ }
401
+ else {
402
+ hi = mid - 1;
403
+ }
404
+ }
405
+ return false;
406
+ }
407
+ /** store `value` under `key`, dropping the oldest entry first once the cache sits at {@link BlobCacheCap} */
408
+ static cache(cache, key, value) {
409
+ if (cache.size >= SigDatabase.BlobCacheCap) {
410
+ const oldest = cache.keys().next().value;
356
411
  if (oldest !== undefined) {
357
- this.blobCache.delete(oldest);
412
+ cache.delete(oldest);
358
413
  }
359
414
  }
360
- this.blobCache.set(blobIdx, blob);
361
- return blob;
415
+ cache.set(key, value);
416
+ return value;
362
417
  }
363
418
  /** seek to a byte range, read + decode the package blob there (no caching) */
364
419
  readBlobAt([start, bytes]) {
@@ -414,19 +469,47 @@ class SigDatabase {
414
469
  if (!blob || !meta) {
415
470
  return undefined;
416
471
  }
472
+ // keyed on the resolved version, so `undefined` and the version it stands for share one entry
417
473
  const ver = (0, sigdb_version_1.resolveVersion)(blob, meta[0], version);
418
- const idxs = ver !== undefined ? (0, decode_1.versionFnIndices)(blob, ver) : undefined;
419
- return idxs !== undefined ? { blob, idxs } : undefined;
474
+ if (ver === undefined) {
475
+ return undefined;
476
+ }
477
+ const key = `${pkg}\0${ver}`;
478
+ const cached = this.versionFnCache.get(key);
479
+ if (cached !== undefined) {
480
+ return cached;
481
+ }
482
+ const idxs = (0, decode_1.versionFnIndices)(blob, ver);
483
+ if (idxs === undefined) {
484
+ return undefined;
485
+ }
486
+ return SigDatabase.cache(this.versionFnCache, key, { blob, idxs });
420
487
  }
421
488
  functions(pkg, version) {
422
489
  const r = this.versionFns(pkg, version);
423
490
  return r?.idxs.map(i => (0, decode_1.decodeFunction)(this.strings, r.blob, i));
424
491
  }
425
492
  functionByName(pkg, name, version) {
493
+ if (!this.mayOffer(pkg, name)) {
494
+ return undefined;
495
+ }
426
496
  const r = this.versionFns(pkg, version);
427
- // compare the stored name-string index and decode only the match, rather than the whole package
428
- const hit = r?.idxs.find(i => this.strings[r.blob.fns[i][0]] === name);
429
- return hit !== undefined && r !== undefined ? (0, decode_1.decodeFunction)(this.strings, r.blob, hit) : undefined;
497
+ if (r === undefined) {
498
+ return undefined;
499
+ }
500
+ if (r.byName === undefined) {
501
+ const byName = new Map();
502
+ for (const i of r.idxs) {
503
+ const fn = this.strings[r.blob.fns[i][0]];
504
+ // first record wins, as the linear scan did
505
+ if (!byName.has(fn)) {
506
+ byName.set(fn, i);
507
+ }
508
+ }
509
+ r.byName = byName;
510
+ }
511
+ const hit = r.byName.get(name);
512
+ return hit !== undefined ? (0, decode_1.decodeFunction)(this.strings, r.blob, hit) : undefined;
430
513
  }
431
514
  transitiveCallees(pkg, name, version) {
432
515
  const fns = this.functions(pkg, version);
@@ -55,7 +55,7 @@ function satisfiesCallTargets(info, graph, callTarget) {
55
55
  * for performance and scoping reasons, flowR will not identify the global linkage,
56
56
  * including any potential built-in mapping.
57
57
  */
58
- const reResolved = (0, resolve_by_name_1.resolveByName)(info.name, info.environment, identifier_1.ReferenceType.Unknown);
58
+ const reResolved = (0, resolve_by_name_1.resolveByNameAnyType)(info.name, info.environment);
59
59
  if (reResolved?.some(t => node_id_1.NodeId.isBuiltIn(t.definedAt))) {
60
60
  builtIn = true;
61
61
  }
@@ -65,8 +65,9 @@ async function executeDependenciesQuery({ analyzer, }, queries) {
65
65
  }
66
66
  return [c, results];
67
67
  })));
68
- if (results.visualize?.length && results.write?.length) {
69
- (0, link_devices_1.linkPlotsToDevices)(results.write, results.visualize, dataflow, normalize);
68
+ /* also without a device: a plot on screen has no file, but still has the addons drawn onto it */
69
+ if (results.visualize?.length) {
70
+ (0, link_devices_1.linkPlotsToDevices)(results.write ?? [], results.visualize, dataflow, normalize);
70
71
  }
71
72
  return {
72
73
  '.meta': {
@@ -91,6 +91,12 @@ export interface DependencyInfo extends Record<string, unknown> {
91
91
  /** the called name; an {@link Identifier}, so a namespaced call like `maps::map` keeps its package */
92
92
  functionName: Identifier;
93
93
  linkedIds?: readonly NodeId[];
94
+ /**
95
+ * The other statements that build this output: for a plot, the addons drawn onto it and, when it lands in a
96
+ * file, the device opener and closer around it. Answers *which statements produce this output* without
97
+ * rebuilding it from {@link linkedIds}.
98
+ */
99
+ parts?: readonly NodeId[];
94
100
  /**
95
101
  * the argument the value was read from, under the id the {@link InputSourcesQuery} reports it with: ask that
96
102
  * query about {@link nodeId} and this entry of its answer says whether the value is a glob, a prompt, ...