@eagleoutice/flowr 2.17.3 → 2.17.4

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 (97) hide show
  1. package/README.md +9 -9
  2. package/cli/repl/commands/repl-signature.d.ts +1 -1
  3. package/cli/repl/completion.d.ts +23 -0
  4. package/cli/repl/completion.js +9 -0
  5. package/cli/repl/core.d.ts +0 -23
  6. package/cli/repl/core.js +0 -5
  7. package/cli/repl/parser/slice-query-parser.d.ts +1 -1
  8. package/cli/repl/parser/slice-query-parser.js +3 -3
  9. package/dataflow/environments/built-in-props.d.ts +8 -1
  10. package/dataflow/environments/built-in-props.js +9 -1
  11. package/dataflow/environments/built-in.d.ts +5 -3
  12. package/dataflow/environments/built-in.js +5 -4
  13. package/dataflow/environments/default-builtin-config.d.ts +21 -3
  14. package/dataflow/environments/default-builtin-config.js +49 -47
  15. package/dataflow/eval/resolve/resolve-argument.js +11 -6
  16. package/dataflow/eval/resolve/resolve-numbers.d.ts +1 -178
  17. package/dataflow/eval/resolve/resolve-numbers.js +2 -13
  18. package/dataflow/eval/resolve/resolve-strings.d.ts +1 -93
  19. package/dataflow/eval/resolve/resolve-strings.js +2 -17
  20. package/dataflow/eval/resolve/resolve-working-directory.js +3 -4
  21. package/dataflow/extractor.js +44 -26
  22. package/dataflow/graph/df-helper.d.ts +2 -1
  23. package/dataflow/graph/df-helper.js +2 -1
  24. package/dataflow/internal/linker.js +2 -1
  25. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +8 -0
  26. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +44 -7
  27. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +3 -2
  28. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -1
  29. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +0 -9
  30. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +11 -21
  31. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -3
  32. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +2 -1
  33. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +13 -3
  34. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +15 -5
  35. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +1 -24
  36. package/dataflow/internal/process/functions/call/known-call-handling.js +8 -34
  37. package/dataflow/internal/process/functions/call/nse-kind.d.ts +24 -0
  38. package/dataflow/internal/process/functions/call/nse-kind.js +30 -0
  39. package/documentation/wiki-query.js +3 -2
  40. package/linter/rules/absolute-path.js +5 -5
  41. package/linter/rules/cmd-check/dependency-declaration.js +2 -2
  42. package/linter/rules/cmd-check/package-runtime.js +2 -2
  43. package/linter/rules/deprecated-functions.js +2 -2
  44. package/linter/rules/file-path-validity.js +5 -5
  45. package/linter/rules/function-finder-util.js +2 -2
  46. package/linter/rules/overwritten-file.js +2 -4
  47. package/linter/rules/secret-exfiltration.d.ts +3 -2
  48. package/linter/rules/secret-exfiltration.js +8 -3
  49. package/linter/rules/unused-import.js +20 -6
  50. package/package.json +1 -1
  51. package/project/cache/flowr-analyzer-controlflow-cache.d.ts +0 -6
  52. package/project/cache/flowr-analyzer-controlflow-cache.js +7 -27
  53. package/project/context/flowr-analyzer-context.d.ts +2 -2
  54. package/project/context/flowr-analyzer-context.js +2 -2
  55. package/project/context/flowr-analyzer-files-context.d.ts +8 -0
  56. package/project/context/flowr-analyzer-files-context.js +51 -6
  57. package/project/flowr-analyzer.d.ts +0 -9
  58. package/project/flowr-analyzer.js +7 -28
  59. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +0 -3
  60. package/project/plugins/file-plugins/files/flowr-namespace-file.js +57 -163
  61. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +2 -3
  62. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -3
  63. package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.js +3 -3
  64. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
  65. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -2
  66. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +0 -1
  67. package/project/plugins/package-version-plugins/package.js +1 -1
  68. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -3
  69. package/queries/catalog/absint-query/absint-query-format.d.ts +1 -1
  70. package/queries/catalog/config-query/config-query-format.d.ts +1 -1
  71. package/queries/catalog/config-query/config-query-format.js +4 -4
  72. package/queries/catalog/dependencies-query/dependencies-query-executor.js +6 -5
  73. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +1 -4
  74. package/queries/catalog/dependencies-query/dependencies-query-format.js +11 -11
  75. package/queries/catalog/dependencies-query/dependency-values.d.ts +9 -0
  76. package/queries/catalog/dependencies-query/dependency-values.js +13 -0
  77. package/queries/catalog/dependencies-query/function-info/remote-functions.js +2 -2
  78. package/queries/catalog/dependencies-query/function-info/write-functions.js +8 -7
  79. package/queries/catalog/dependencies-query/implicit-echo.js +2 -1
  80. package/queries/catalog/dependencies-query/plot-description.d.ts +1 -1
  81. package/queries/catalog/dependencies-query/plot-description.js +2 -2
  82. package/queries/catalog/dice-query/dice-query-format.d.ts +1 -1
  83. package/queries/catalog/files-query/files-query-format.d.ts +1 -1
  84. package/queries/catalog/linter-query/linter-query-format.d.ts +2 -2
  85. package/queries/catalog/linter-query/linter-query-format.js +13 -9
  86. package/queries/catalog/signature-query/signature-query-executor.d.ts +1 -1
  87. package/queries/catalog/taint-query/taint-query-format.d.ts +1 -1
  88. package/queries/query-function-filter.d.ts +1 -1
  89. package/queries/query.d.ts +2 -2
  90. package/r-bridge/init.js +1 -1
  91. package/search/flowr-search-filters.js +2 -2
  92. package/search/search-executor/search-generators.d.ts +0 -1
  93. package/search/search-executor/search-generators.js +5 -6
  94. package/search/search-logger.d.ts +1 -0
  95. package/search/search-logger.js +6 -0
  96. package/util/flowr-version.d.ts +1 -1
  97. package/util/flowr-version.js +2 -2
@@ -15,7 +15,7 @@ const write_functions_1 = require("../../queries/catalog/dependencies-query/func
15
15
  const search_enrichers_1 = require("../../search/search-executor/search-enrichers");
16
16
  const source_functions_1 = require("../../queries/catalog/dependencies-query/function-info/source-functions");
17
17
  const vertex_1 = require("../../dataflow/graph/vertex");
18
- const dependencies_query_format_1 = require("../../queries/catalog/dependencies-query/dependencies-query-format");
18
+ const dependency_values_1 = require("../../queries/catalog/dependencies-query/dependency-values");
19
19
  const resolve_argument_1 = require("../../dataflow/eval/resolve/resolve-argument");
20
20
  const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
21
21
  const other_path_functions_1 = require("../../queries/catalog/dependencies-query/function-info/other-path-functions");
@@ -55,13 +55,13 @@ function filePathStrings(graph, vtx, ctx) {
55
55
  // in the future we can access `.Platform$file.sep` here
56
56
  const fsep = (0, resolve_argument_1.getArgumentStringValue)(variables, graph, vtx, undefined, 'fsep', true, ctx);
57
57
  const seps = fsep?.values().flatMap(s => s.values().filter(assert_1.isNotUndefined)).toArray() ?? ['/'];
58
- if (seps.includes(dependencies_query_format_1.Unknown)) {
58
+ if (seps.includes(dependency_values_1.Unknown)) {
59
59
  // if we have no fsep, we cannot construct a path
60
60
  return undefined;
61
61
  }
62
62
  const unnamed = (0, resolve_argument_1.getArgumentStringValue)(variables, graph, vtx, 'unnamed', undefined, true, ctx);
63
63
  const args = [...unnamed?.values() ?? []].flatMap(v => [...v]);
64
- if (args.length === 0 || args.some(v => v === dependencies_query_format_1.Unknown || v === undefined)) {
64
+ if (args.length === 0 || args.some(v => v === dependency_values_1.Unknown || v === undefined)) {
65
65
  // if we have no arguments, we cannot construct a path
66
66
  return undefined;
67
67
  }
@@ -136,14 +136,14 @@ exports.ABSOLUTE_PATH = {
136
136
  const result = queryResults[query.query];
137
137
  const reads = result.read.filter(r => r.nodeId === node.info.id);
138
138
  const found = reads.flatMap(r => {
139
- if (r.value === undefined || r.value === dependencies_query_format_1.Unknown || r.nodeId === undefined) {
139
+ if (r.value === undefined || r.value === dependency_values_1.Unknown || r.nodeId === undefined) {
140
140
  return [];
141
141
  }
142
142
  const path = absolute(r.value);
143
143
  return path === undefined ? [] : [finding(linter_format_1.LintingResultCertainty.Certain, path, idMap.get(r.nodeId), wd, (0, file_path_validity_1.pathArgStringNode)(idMap, r.nodeId, r.value))];
144
144
  });
145
145
  // if we have no absolute paths, but all paths are known, we can return an empty array
146
- if (found.length > 0 || reads.every(r => r.value !== dependencies_query_format_1.Unknown)) {
146
+ if (found.length > 0 || reads.every(r => r.value !== dependency_values_1.Unknown)) {
147
147
  return found;
148
148
  }
149
149
  }
@@ -14,7 +14,7 @@ const df_helper_1 = require("../../../dataflow/graph/df-helper");
14
14
  const query_fn_props_1 = require("../../../dataflow/environments/query-fn-props");
15
15
  const built_in_props_1 = require("../../../dataflow/environments/built-in-props");
16
16
  const library_functions_1 = require("../../../queries/catalog/dependencies-query/function-info/library-functions");
17
- const dependencies_query_format_1 = require("../../../queries/catalog/dependencies-query/dependencies-query-format");
17
+ const dependency_values_1 = require("../../../queries/catalog/dependencies-query/dependency-values");
18
18
  const r_base_packages_1 = require("../../../util/r-base-packages");
19
19
  const cmd_check_util_1 = require("./cmd-check-util");
20
20
  const package_files_1 = require("./package-files");
@@ -157,7 +157,7 @@ exports.DEPENDENCY_DECLARATION = {
157
157
  const certain = infos.length === 1;
158
158
  for (const info of infos) {
159
159
  const name = info.value;
160
- if (name === undefined || name === dependencies_query_format_1.Unknown || !PackageName.test(name)) {
160
+ if (name === undefined || name === dependency_values_1.Unknown || !PackageName.test(name)) {
161
161
  unresolvedLoads++;
162
162
  continue;
163
163
  }
@@ -81,7 +81,7 @@ function definitionsOf(ast, pkg, data, declaring) {
81
81
  const NamespaceInternals = ['.packageName', '.__NAMESPACE__.', '.__S3MethodsTable__.'];
82
82
  /** whether a namespace exports anything: an export, a registered S3 method, or a pattern that `matches` a name */
83
83
  function exportsAnything(ns, matches) {
84
- return ns.exportedSymbols.length + ns.exportedFunctions.length + ns.exportedS4Methods.length + ns.exportedS4Classes.length + ns.exportS3Generics.size > 0
84
+ return ns.exportedSymbols.length + ns.exportedS4Methods.length + ns.exportedS4Classes.length + ns.exportS3Generics.size > 0
85
85
  || ns.exportedPatterns.some(matches)
86
86
  || [...ns.conditional?.values() ?? []].some(c => exportsAnything(c, matches));
87
87
  }
@@ -162,7 +162,7 @@ function namespaceChecks(files, pkg, defs, data, config, shipsData, add) {
162
162
  /* a package may export what it imports (`importFrom(magrittr, "%>%")` and `export("%>%")`) */
163
163
  const imported = new Set([...ns.importedPackages.values()].flatMap(v => v === 'all' ? [] : v));
164
164
  const importsWhole = [...ns.importedPackages.values()].includes('all');
165
- for (const name of config.checkExports ? [...ns.exportedSymbols, ...ns.exportedFunctions] : []) {
165
+ for (const name of config.checkExports ? ns.exportedSymbols : []) {
166
166
  if (!defs.names.has(name) && !imported.has(name) && !importsWhole) {
167
167
  add({ certainty, loc: files.locate(relative, lineOf(text, name)), kind: 'undefined-export', message: `undefined export: '${name}', installing the package fails` });
168
168
  }
@@ -17,7 +17,7 @@ const r_version_1 = require("../../util/r-version");
17
17
  const df_helper_1 = require("../../dataflow/graph/df-helper");
18
18
  const logic_1 = require("../../util/logic");
19
19
  const built_in_props_1 = require("../../dataflow/environments/built-in-props");
20
- const dependencies_query_format_1 = require("../../queries/catalog/dependencies-query/dependencies-query-format");
20
+ const dependency_values_1 = require("../../queries/catalog/dependencies-query/dependency-values");
21
21
  /** The entries by bare name, as a call names its package only when written `pkg::fn`. */
22
22
  function indexConditionals(conditionally) {
23
23
  const index = new Map();
@@ -64,7 +64,7 @@ function indexAlways(always) {
64
64
  async function librariesAttachedBy(analyzer) {
65
65
  const attached = new Set();
66
66
  for (const lib of (await analyzer.query([{ type: 'dependencies', enabledCategories: ['library'] }]))['dependencies'].library) {
67
- if (lib.value === undefined || lib.value === dependencies_query_format_1.Unknown) {
67
+ if (lib.value === undefined || lib.value === dependency_values_1.Unknown) {
68
68
  return undefined;
69
69
  }
70
70
  attached.add(lib.value);
@@ -7,7 +7,7 @@ const linter_format_1 = require("../linter-format");
7
7
  const strings_1 = require("../../util/text/strings");
8
8
  const flowr_search_builder_1 = require("../../search/flowr-search-builder");
9
9
  const range_1 = require("../../util/range");
10
- const dependencies_query_format_1 = require("../../queries/catalog/dependencies-query/dependencies-query-format");
10
+ const dependency_values_1 = require("../../queries/catalog/dependencies-query/dependency-values");
11
11
  const built_in_source_1 = require("../../dataflow/internal/process/functions/call/built-in/built-in-source");
12
12
  const logic_1 = require("../../util/logic");
13
13
  const happens_before_1 = require("../../control-flow/happens-before");
@@ -79,7 +79,7 @@ exports.FILE_PATH_VALIDITY = {
79
79
  const findings = await Promise.all(reads.map(async ({ element, matchingRead }) => {
80
80
  const { nodeId, value } = matchingRead;
81
81
  /* data built from constants, like `matrix(1:6, 2)`, reads no file */
82
- if (nodeId === undefined || value === dependencies_query_format_1.Constant) {
82
+ if (nodeId === undefined || value === dependency_values_1.Constant) {
83
83
  return [];
84
84
  }
85
85
  const { id, file } = element.node.info;
@@ -93,7 +93,7 @@ exports.FILE_PATH_VALIDITY = {
93
93
  return [{ involvedId: nodeId, loc: loc, filePath, certainty, ...(quickFix ? { quickFix } : {}) }];
94
94
  };
95
95
  if (namesOnly.has(identifier_1.Identifier.getName(matchingRead.functionName))) {
96
- if (!loc || typeof value !== 'string' || value === dependencies_query_format_1.Unknown
96
+ if (!loc || typeof value !== 'string' || value === dependency_values_1.Unknown
97
97
  || librariesLoadedBefore(id) || r_base_packages_1.BaseDatasets.has(value) || namesPackage(element.node)) {
98
98
  return [];
99
99
  }
@@ -107,9 +107,9 @@ exports.FILE_PATH_VALIDITY = {
107
107
  return [];
108
108
  }
109
109
  // check if we can't parse the file path statically
110
- if (value === dependencies_query_format_1.Unknown) {
110
+ if (value === dependency_values_1.Unknown) {
111
111
  metadata.totalUnknown++;
112
- return config.includeUnknown ? [{ involvedId: nodeId, loc, filePath: dependencies_query_format_1.Unknown, certainty: linter_format_1.LintingResultCertainty.Uncertain }] : [];
112
+ return config.includeUnknown ? [{ involvedId: nodeId, loc, filePath: dependency_values_1.Unknown, certainty: linter_format_1.LintingResultCertainty.Uncertain }] : [];
113
113
  }
114
114
  const path = value;
115
115
  // file:// URIs are local paths; resolve and check existence directly
@@ -11,7 +11,7 @@ const linter_format_1 = require("../linter-format");
11
11
  const assert_1 = require("../../util/assert");
12
12
  const resolve_argument_1 = require("../../dataflow/eval/resolve/resolve-argument");
13
13
  const vertex_1 = require("../../dataflow/graph/vertex");
14
- const dependencies_query_format_1 = require("../../queries/catalog/dependencies-query/dependencies-query-format");
14
+ const dependency_values_1 = require("../../queries/catalog/dependencies-query/dependency-values");
15
15
  const identifier_1 = require("../../dataflow/environments/identifier");
16
16
  const logic_1 = require("../../util/logic");
17
17
  /**
@@ -93,7 +93,7 @@ function hasArgumentValue(test, fnVertex, analyzer, dataflow, resolveValue, argN
93
93
  else if (argValues.some(v => test instanceof RegExp ? test.test(v) : v === test)) {
94
94
  return logic_1.Ternary.Always;
95
95
  }
96
- else if (argValues.includes(dependencies_query_format_1.Unknown)) {
96
+ else if (argValues.includes(dependency_values_1.Unknown)) {
97
97
  return logic_1.Ternary.Maybe;
98
98
  }
99
99
  return logic_1.Ternary.Never;
@@ -4,7 +4,7 @@ exports.OVERWRITTEN_FILE = void 0;
4
4
  const linter_format_1 = require("../linter-format");
5
5
  const flowr_search_builder_1 = require("../../search/flowr-search-builder");
6
6
  const range_1 = require("../../util/range");
7
- const dependencies_query_format_1 = require("../../queries/catalog/dependencies-query/dependencies-query-format");
7
+ const dependency_values_1 = require("../../queries/catalog/dependencies-query/dependency-values");
8
8
  const linter_tags_1 = require("../linter-tags");
9
9
  const search_enrichers_1 = require("../../search/search-executor/search-enrichers");
10
10
  const logic_1 = require("../../util/logic");
@@ -16,8 +16,6 @@ const identifier_1 = require("../../dataflow/environments/identifier");
16
16
  const query_fn_props_1 = require("../../dataflow/environments/query-fn-props");
17
17
  const function_semantics_1 = require("../../dataflow/fn/function-semantics");
18
18
  const built_in_props_1 = require("../../dataflow/environments/built-in-props");
19
- /** what goes to the console is printed, not written over */
20
- const ConsoleStreams = new Set(['stdout', 'stderr']);
21
19
  /** `append = TRUE`, or a connection opened in an append mode like `file(p, "a")` */
22
20
  function appends(id, idMap, opens) {
23
21
  const node = idMap.get(id);
@@ -34,7 +32,7 @@ function appends(id, idMap, opens) {
34
32
  * body when it names the same file, and the writes into a connection belong to the call opening it.
35
33
  */
36
34
  function writesPerFile(writes, idMap, opens) {
37
- const named = writes.filter((w) => w.nodeId !== undefined && typeof w.value === 'string' && w.value !== dependencies_query_format_1.Unknown && !ConsoleStreams.has(w.value));
35
+ const named = writes.filter((w) => w.nodeId !== undefined && typeof w.value === 'string' && w.value !== dependency_values_1.Unknown && !dependency_values_1.ConsoleStreams.has(w.value));
38
36
  const viaCalls = new Set(named.filter(w => w.via !== undefined).map(w => `${String(w.via)}\0${w.value}`));
39
37
  const opened = new Set(named.filter(w => opens(w.nodeId)).map(w => w.value));
40
38
  const perFile = new Map();
@@ -2,6 +2,7 @@ import { type LintingResult, LintingRuleCertainty } from '../linter-format';
2
2
  import type { MergeableRecord } from '../../util/objects';
3
3
  import { LintingRuleTag } from '../linter-tags';
4
4
  import { Identifier } from '../../dataflow/environments/identifier';
5
+ import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
6
  import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
6
7
  import { InputType } from '../../queries/catalog/input-sources-query/input-types';
7
8
  import { FileTrust, type SecretSink, SecretSinkClass } from '../../taint-analysis/predefined/secret-analysis';
@@ -48,8 +49,8 @@ export interface SecretExfiltrationMetadata extends MergeableRecord {
48
49
  readonly secretSinkCalls: number;
49
50
  }
50
51
  export declare const SECRET_EXFILTRATION: {
51
- 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>[]>>;
52
- 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: SecretExfiltrationConfig, data: ReadonlyFlowrAnalysisProvider<import("../..").KnownParser>) => Promise<{
52
+ readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"from", [], ParentInformation, import("../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>>;
53
+ readonly processSearchResult: (_elements: import("../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>, config: SecretExfiltrationConfig, data: ReadonlyFlowrAnalysisProvider<import("../..").KnownParser>) => Promise<{
53
54
  results: SecretExfiltrationResult[];
54
55
  '.meta': {
55
56
  secretSinkCalls: number;
@@ -10,7 +10,9 @@ const graph_1 = require("../../dataflow/graph/graph");
10
10
  const vertex_1 = require("../../dataflow/graph/vertex");
11
11
  const edge_1 = require("../../dataflow/graph/edge");
12
12
  const df_helper_1 = require("../../dataflow/graph/df-helper");
13
- const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
13
+ const function_semantics_1 = require("../../dataflow/fn/function-semantics");
14
+ const query_fn_props_1 = require("../../dataflow/environments/query-fn-props");
15
+ const built_in_props_1 = require("../../dataflow/environments/built-in-props");
14
16
  const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
15
17
  const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
16
18
  const arguments_1 = require("../../abstract-interpretation/data-frame/arguments");
@@ -44,7 +46,6 @@ const Leaks = {
44
46
  };
45
47
  /** request builders passing their destination on */
46
48
  const RequestBuilder = /^(?:request|req_\w+)$/;
47
- const StandardStreams = new Set(['stdout', 'stderr']);
48
49
  const MaxDestinationHops = 5;
49
50
  const argumentAt = (call, at, info) => at === undefined ? undefined : r_argument_1.RArgument.valueOf((0, arguments_1.getFunctionArgument)((0, arguments_1.getVertexArguments)(call, info.idMap), at, info))?.info.id;
50
51
  function requestBuilder(vertex) {
@@ -75,11 +76,15 @@ async function classifyDestination(data, id, controlled) {
75
76
  }
76
77
  return types.has(input_types_1.InputType.Parameter) && controlled.includes(input_types_1.InputType.Parameter) ? 'parameter' : 'trusted';
77
78
  }
79
+ /** whether the destination `file` is the console, `""` or a call flowR states {@link SemanticCallTag.Console} of */
80
+ function namesConsole(file, info) {
81
+ return file.lexeme === '""' || function_semantics_1.FunctionSemantics.call.props.hasAll((0, query_fn_props_1.callFnProps)(file.info.id, { graph: info.graph, environment: info.environment ?? info.ctx.env.cleanEnv() }), [built_in_props_1.SemanticCallTag.Console]);
82
+ }
78
83
  async function leakOf(data, call, untrusted, info, config) {
79
84
  const fixed = call.sink.class === secret_analysis_1.SecretSinkClass.Browser ? SecretLeak.Leakage : [SecretLeak.Files, SecretLeak.Process, SecretLeak.Llm].find(l => l === call.sink.class);
80
85
  const file = info.idMap.get(argumentAt(call.call, call.sink.file, info) ?? '');
81
86
  if (fixed !== undefined || call.sink.class === secret_analysis_1.SecretSinkClass.Logs) {
82
- return { leak: fixed ?? (file !== undefined && !r_function_call_1.RFunctionCall.isNamed(file, StandardStreams) && file.lexeme !== '""' ? SecretLeak.Files : SecretLeak.Leakage), certain: true };
87
+ return { leak: fixed ?? (file !== undefined && !namesConsole(file, info) ? SecretLeak.Files : SecretLeak.Leakage), certain: true };
83
88
  }
84
89
  const destination = destinationOf(call.call, call.sink, info);
85
90
  const trust = untrusted ? 'controlled' : destination === undefined ? 'trusted' : await classifyDestination(data, destination, config.controlledInputs);
@@ -13,7 +13,7 @@ const vertex_1 = require("../../dataflow/graph/vertex");
13
13
  const identifier_1 = require("../../dataflow/environments/identifier");
14
14
  const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
15
15
  const search_enrichers_1 = require("../../search/search-executor/search-enrichers");
16
- const dependencies_query_format_1 = require("../../queries/catalog/dependencies-query/dependencies-query-format");
16
+ const dependency_values_1 = require("../../queries/catalog/dependencies-query/dependency-values");
17
17
  const library_functions_1 = require("../../queries/catalog/dependencies-query/function-info/library-functions");
18
18
  const r_expression_list_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
19
19
  const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
@@ -27,14 +27,28 @@ function isUnbound(graph, id) {
27
27
  const origins = df_helper_1.Dataflow.origin(graph, id);
28
28
  return origins === undefined || origins.every(o => o.type === 3 /* OriginType.BuiltInFunctionOrigin */);
29
29
  }
30
- /** whether removing the call would empty a slot the syntax requires, as in an unbraced `if(c) library(x)` */
30
+ /**
31
+ * Whether removing the call would empty a slot the syntax requires: the attach is an operand or argument, as in
32
+ * `ok <- require(x)` or `suppressMessages(library(x))`, the lone statement of an unbraced `if(c) library(x)`, or in `(library(x))`.
33
+ */
31
34
  function removalWouldBreakSyntax(node, idMap) {
32
35
  const parent = model_1.RNode.directParent(node, idMap);
33
- return r_expression_list_1.RExpressionList.isImplicit(parent) && parent.children.length === 1 && parent.info.role !== "root" /* RoleInParent.Root */;
36
+ if (!r_expression_list_1.RExpressionList.is(parent)) {
37
+ return true;
38
+ }
39
+ if (r_expression_list_1.RExpressionList.isImplicit(parent)) {
40
+ return parent.children.length === 1 && parent.info.role !== "root" /* RoleInParent.Root */;
41
+ }
42
+ return r_expression_list_1.RExpressionList.groupStart(parent)?.lexeme !== '{';
43
+ }
44
+ /** a bare call nothing binds reads the whole search path; whether it is a use is up to the package exports */
45
+ function isUnboundCall(graph, id) {
46
+ const vertex = graph.getVertex(id);
47
+ return vertex_1.DfgVertex.isFunctionCall(vertex) && identifier_1.Identifier.getNamespace(vertex.name) === undefined && isUnbound(graph, id);
34
48
  }
35
49
  /** whether anything reads out of the attach itself */
36
50
  function isReadFrom(graph, id) {
37
- return graph.edgesTo(id).values().some(edge => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads));
51
+ return graph.edgesTo(id).entries().some(([from, edge]) => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && !isUnboundCall(graph, from));
38
52
  }
39
53
  /**
40
54
  * Which of the `attachments` the program never makes use of. A call that resolves names its package outright;
@@ -51,7 +65,7 @@ function unusedPackages(attachments, graph, src) {
51
65
  /* a call or a read of a name the code binds nowhere, like `percent` in `scale_y_continuous(labels = percent)` */
52
66
  const unbound = new Set();
53
67
  for (const [id, vertex] of graph.vertices(true)) {
54
- if (vertex_1.DfgVertex.isFunctionCall(vertex) && identifier_1.Identifier.getNamespace(vertex.name) === undefined && isUnbound(graph, id)) {
68
+ if (vertex_1.DfgVertex.isFunctionCall(vertex) && isUnboundCall(graph, id)) {
55
69
  unbound.add(identifier_1.Identifier.getName(vertex.name));
56
70
  }
57
71
  else if (vertex_1.DfgVertex.isUse(vertex) && isUnbound(graph, id)) {
@@ -115,7 +129,7 @@ exports.UNUSED_IMPORT = {
115
129
  continue;
116
130
  }
117
131
  const name = infos[0].value;
118
- if (name === undefined || name === dependencies_query_format_1.Unknown) {
132
+ if (name === undefined || name === dependency_values_1.Unknown) {
119
133
  metadata.totalUnresolved++;
120
134
  continue;
121
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eagleoutice/flowr",
3
- "version": "2.17.3",
3
+ "version": "2.17.4",
4
4
  "description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -19,12 +19,6 @@ export declare class FlowrAnalyzerControlFlowCache {
19
19
  private readonly cache;
20
20
  peek(simplifications: readonly CfgSimplificationPassName[] | undefined): ControlFlowInformation | undefined;
21
21
  get(force: boolean | undefined, cfgCacheInfo: CfgInfo, simplifications?: readonly CfgSimplificationPassName[]): Promise<ControlFlowInformation>;
22
- /**
23
- * Try to get a cached CFG with some of the requested simplifications already applied.
24
- * Matches the longest prefix of simplifications available.
25
- * @returns The cached CFG and the missing simplifications to be applied, or `undefined` if no cached CFG is available.
26
- */
27
- private tryGetCachedCfg;
28
22
  /**
29
23
  * Normalize the order of simplification passes.
30
24
  * Is currently an identity function, but may be extended in the future to enforce a specific order using heuristics.
@@ -19,39 +19,19 @@ class FlowrAnalyzerControlFlowCache {
19
19
  async get(force, cfgCacheInfo, simplifications) {
20
20
  simplifications ??= [];
21
21
  const orderedSimplifications = this.normalizeSimplificationOrder(simplifications);
22
- const cached = force ?
23
- { cfg: undefined, missingSimplifications: orderedSimplifications }
24
- : this.tryGetCachedCfg(orderedSimplifications);
25
- let cfg = cached.cfg;
26
- if (!cfg) {
27
- cfg = (0, control_flow_graph_1.extractCfg)(await cfgCacheInfo.dfg());
28
- this.cache.set([[]], cfg);
22
+ const known = force ? undefined : this.cache.get([orderedSimplifications]);
23
+ if (known !== undefined) {
24
+ return known;
29
25
  }
30
- if (cached.missingSimplifications.length > 0) {
26
+ /* passes like `analyze-dead-code` change the graph in place, so they start from a view of their own rather than one cached for fewer passes */
27
+ let cfg = (0, control_flow_graph_1.extractCfg)(await cfgCacheInfo.dfg());
28
+ if (orderedSimplifications.length > 0) {
31
29
  const cfgPassInfo = { dfg: (await cfgCacheInfo.dfg()).graph, ctx: cfgCacheInfo.ctx, ast: await cfgCacheInfo.ast() };
32
- cfg = (0, cfg_simplification_1.simplifyControlFlowInformation)(cfg, cfgPassInfo, cached.missingSimplifications);
30
+ cfg = (0, cfg_simplification_1.simplifyControlFlowInformation)(cfg, cfgPassInfo, orderedSimplifications);
33
31
  }
34
32
  this.cache.set([orderedSimplifications], cfg);
35
33
  return cfg;
36
34
  }
37
- /**
38
- * Try to get a cached CFG with some of the requested simplifications already applied.
39
- * Matches the longest prefix of simplifications available.
40
- * @returns The cached CFG and the missing simplifications to be applied, or `undefined` if no cached CFG is available.
41
- */
42
- tryGetCachedCfg(simplifications) {
43
- for (let prefixLen = simplifications.length; prefixLen >= 0; prefixLen--) {
44
- const prefix = simplifications.slice(0, prefixLen);
45
- const cached = this.cache.get([prefix]);
46
- if (cached !== undefined) {
47
- return {
48
- cfg: cached,
49
- missingSimplifications: simplifications.slice(prefixLen)
50
- };
51
- }
52
- }
53
- return { cfg: undefined, missingSimplifications: simplifications };
54
- }
55
35
  /**
56
36
  * Normalize the order of simplification passes.
57
37
  * Is currently an identity function, but may be extended in the future to enforce a specific order using heuristics.
@@ -6,7 +6,7 @@ import { type FlowrAnalyzerPlugin, PluginType } from '../plugins/flowr-analyzer-
6
6
  import type { fileProtocol, RParseRequestFromFile, RParseRequests } from '../../r-bridge/retriever';
7
7
  import { FlowrConfig } from '../../config';
8
8
  import type { DeepPartial } from 'ts-essentials';
9
- import type { FlowrFileProvider } from './flowr-file';
9
+ import type { FileRole, FlowrFileProvider } from './flowr-file';
10
10
  import type { ReadOnlyFlowrAnalyzerEnvironmentContext } from './flowr-analyzer-environment-context';
11
11
  import { FlowrAnalyzerEnvironmentContext } from './flowr-analyzer-environment-context';
12
12
  import type { ReadOnlyFlowrAnalyzerMetaContext } from './flowr-analyzer-meta-context';
@@ -160,7 +160,7 @@ export declare class FlowrAnalyzerContext implements ReadOnlyFlowrAnalyzerContex
160
160
  inferredRange(name: string): Range | undefined;
161
161
  /** delegate request addition */
162
162
  addRequests(requests: readonly RAnalysisRequest[]): void;
163
- addFile(f: string | FlowrFileProvider | RParseRequestFromFile): void;
163
+ addFile(f: string | FlowrFileProvider | RParseRequestFromFile, roles?: readonly FileRole[]): void;
164
164
  addFiles(f: (string | FlowrFileProvider | RParseRequestFromFile)[]): void;
165
165
  /**
166
166
  * Get a read-only version of this context.
@@ -212,8 +212,8 @@ class FlowrAnalyzerContext {
212
212
  this.files.addRequests(requests);
213
213
  this.gas.reset();
214
214
  }
215
- addFile(f) {
216
- this.files.addFile(f);
215
+ addFile(f, roles) {
216
+ this.files.addFile(f, roles);
217
217
  this.gas.reset();
218
218
  }
219
219
  addFiles(f) {
@@ -184,6 +184,7 @@ export declare class FlowrAnalyzerFilesContext extends AbstractFlowrAnalyzerCont
184
184
  private readonly readdirCache;
185
185
  constructor(context: FlowrAnalyzerContext, loadingOrder: FlowrAnalyzerLoadingOrderContext, plugins: readonly FlowrAnalyzerProjectDiscoveryPlugin[], fileLoaders: readonly FlowrAnalyzerFilePlugin[]);
186
186
  reset(): void;
187
+ private addRoot;
187
188
  /** The directory the analysis was asked about: a `project`'s folder, or the one holding the requested file(s). */
188
189
  root(): string | undefined;
189
190
  /** The path of `filePath` seen from the {@link root}, see {@link relativeTo}. */
@@ -226,15 +227,22 @@ export declare class FlowrAnalyzerFilesContext extends AbstractFlowrAnalyzerCont
226
227
  /**
227
228
  * Add a file to the context. If the file has a special role, it will be added to the corresponding list of special files.
228
229
  * This method also applies any registered {@link FlowrAnalyzerFilePlugin}s to the file before adding it to the context.
230
+ * A file already known under the same path (e.g., reached by both a request and implicit-source discovery) is kept, it only gains the new roles.
229
231
  */
230
232
  addFile(file: string | FlowrFileProvider | RParseRequestFromFile | undefined, roles?: readonly FileRole[]): FlowrFileProvider<{
231
233
  toString(): string;
232
234
  }> | undefined;
235
+ private forget;
236
+ private addRoles;
233
237
  hasCached(path: string): boolean;
234
238
  hasFile(path: string): boolean;
235
239
  private fileIndex;
236
240
  private readdir;
237
241
  exists(p: string, ignoreCase: boolean): string | undefined;
242
+ /**
243
+ * Runs the file loaders on `f`. They match the path below the folder `f` shares with the {@link root}, so the folders
244
+ * holding the project (say, a package checked out below a `test` folder) assign no role.
245
+ */
238
246
  private fileLoadPlugins;
239
247
  /** Resolve the file at `path`, loading it from disk through the {@link FlowrAnalyzerFilePlugin}s if unknown. */
240
248
  resolveFile(path: string): FlowrFileProvider | undefined;
@@ -88,6 +88,10 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
88
88
  this.caseIndex = undefined;
89
89
  this.readdirCache.clear();
90
90
  }
91
+ addRoot(root) {
92
+ this.requestedRoots.push(root);
93
+ this.rootResolved = false;
94
+ }
91
95
  /** The directory the analysis was asked about: a `project`'s folder, or the one holding the requested file(s). */
92
96
  root() {
93
97
  if (!this.rootResolved) {
@@ -165,6 +169,12 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
165
169
  * Add multiple requests to the context. This is just a convenience method that calls {@link addRequest} for each request.
166
170
  */
167
171
  addRequests(requests) {
172
+ /* every folder first, so that the files of one request are seen from the same root as those of the others */
173
+ for (const request of requests) {
174
+ if (request.request !== 'text') {
175
+ this.addRoot(request.request === 'file' ? path_1.default.dirname(request.content) : request.content);
176
+ }
177
+ }
168
178
  for (const request of requests) {
169
179
  this.addRequest(request);
170
180
  }
@@ -176,14 +186,14 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
176
186
  addRequest(request) {
177
187
  if (request.request !== 'project') {
178
188
  if (request.request === 'file') {
179
- this.requestedRoots.push(path_1.default.dirname(request.content));
180
189
  this.discoverImplicitSources(request.content);
190
+ /* registers the file with its roles now, so they do not depend on whether it was parsed yet */
191
+ this.resolveFile(request.content);
181
192
  }
182
193
  this.loadingOrder.addRequest(request);
183
194
  this.projectKindCache = undefined;
184
195
  return;
185
196
  }
186
- this.requestedRoots.push(request.content);
187
197
  for (const req of this.activeDiscoveryPlugins().flatMap(p => p.processor(this.ctx, request))) {
188
198
  this.addDiscovered(req);
189
199
  }
@@ -239,12 +249,24 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
239
249
  /**
240
250
  * Add a file to the context. If the file has a special role, it will be added to the corresponding list of special files.
241
251
  * This method also applies any registered {@link FlowrAnalyzerFilePlugin}s to the file before adding it to the context.
252
+ * A file already known under the same path (e.g., reached by both a request and implicit-source discovery) is kept, it only gains the new roles.
242
253
  */
243
254
  addFile(file, roles) {
244
255
  if (file === undefined) {
245
256
  return;
246
257
  }
247
- const f = this.fileLoadPlugins(wrapFile(file, roles));
258
+ const wrapped = wrapFile(file, roles);
259
+ const known = wrapped.path() === flowr_file_1.FlowrFile.INLINE_PATH ? undefined : this.files.get(files_1.RPath.of(wrapped.path()));
260
+ if (known !== undefined) {
261
+ /* the same file on disk again only adds its roles, a provider of its own replaces the known one */
262
+ if (known === file || wrapped instanceof flowr_file_1.FlowrTextFile) {
263
+ this.addRoles(known, [...wrapped.roles ?? [], ...roles ?? []]);
264
+ return known;
265
+ }
266
+ this.forget(known);
267
+ known.roles?.forEach(r => wrapped.assignRole(r));
268
+ }
269
+ const f = this.fileLoadPlugins(wrapped);
248
270
  f.addOnInvalidate(c => {
249
271
  this.context.analyzer?.receive(c);
250
272
  });
@@ -252,8 +274,6 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
252
274
  this.inlineFiles.push(f);
253
275
  }
254
276
  else {
255
- const exist = this.files.get(files_1.RPath.of(f.path()));
256
- (0, assert_1.guard)(exist === undefined || exist === f, `File ${f.path()} already added to the context.`);
257
277
  this.files.set(files_1.RPath.of(f.path()), f);
258
278
  this.caseIndex = undefined;
259
279
  }
@@ -265,6 +285,24 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
265
285
  this.projectKindCache = undefined;
266
286
  return f;
267
287
  }
288
+ forget(file) {
289
+ for (const r of file.roles ?? []) {
290
+ const files = this.byRole[r];
291
+ const at = files.indexOf(file);
292
+ if (at >= 0) {
293
+ files.splice(at, 1);
294
+ }
295
+ }
296
+ }
297
+ addRoles(file, roles) {
298
+ for (const r of roles) {
299
+ if (!file.roles?.includes(r)) {
300
+ file.assignRole(r);
301
+ this.byRole[r].push(file);
302
+ this.projectKindCache = undefined;
303
+ }
304
+ }
305
+ }
268
306
  hasCached(path) {
269
307
  return this.files.has(files_1.RPath.of(path));
270
308
  }
@@ -346,10 +384,17 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
346
384
  return undefined;
347
385
  }
348
386
  }
387
+ /**
388
+ * Runs the file loaders on `f`. They match the path below the folder `f` shares with the {@link root}, so the folders
389
+ * holding the project (say, a package checked out below a `test` folder) assign no role.
390
+ */
349
391
  fileLoadPlugins(f) {
350
392
  let fFinal = f;
393
+ const root = this.root();
394
+ const shared = root === undefined || f.path() === flowr_file_1.FlowrFile.INLINE_PATH ? undefined : (0, files_1.commonDirectory)([root, path_1.default.dirname(f.path())]);
395
+ const relative = shared === undefined ? f.path() : (0, files_1.relativeTo)(shared, f.path());
351
396
  for (const loader of this.fileLoaders) {
352
- if (loader.applies(f.path())) {
397
+ if (loader.applies(relative)) {
353
398
  fileLog.debug(`Applying file loader ${loader.name} to file ${f.path()}`);
354
399
  const res = loader.processor(this.ctx, fFinal);
355
400
  if (Array.isArray(res)) {
@@ -223,15 +223,6 @@ export declare class FlowrAnalyzer<Parser extends KnownParser = KnownParser> imp
223
223
  normalizeStandalone(data: `${typeof fileProtocol}${string}` | string | RParseRequest): NormalizedAst;
224
224
  addRequest(...request: (RAnalysisRequest | readonly RAnalysisRequest[] | `${typeof fileProtocol}${string}` | string)[]): this;
225
225
  addFile(...f: (string | FlowrFileProvider | RParseRequestFromFile)[]): this;
226
- /**
227
- * Add a request created from the given input.
228
- * This is a convenience method that uses {@link requestFromInput} internally.
229
- */
230
- private addRequestFromInput;
231
- /**
232
- * Add one or multiple requests to analyze the builder.
233
- */
234
- private addAnalysisRequest;
235
226
  parse(force?: boolean): Promise<NonNullable<AnalyzerCacheType<Parser>['parse']>>;
236
227
  peekParse(): NonNullable<AnalyzerCacheType<Parser>['parse']> | undefined;
237
228
  normalize(force?: boolean): Promise<NonNullable<AnalyzerCacheType<Parser>['normalize']>>;
@@ -90,41 +90,20 @@ class FlowrAnalyzer {
90
90
  return (0, decorate_1.decorateAst)((0, tree_sitter_normalize_1.normalizeTreeSitterTreeToAst)([{ parsed: parse, filePath: undefined }], true), {});
91
91
  }
92
92
  addRequest(...request) {
93
- for (const r of request) {
94
- if (typeof r === 'string') {
95
- const trimmed = r.slice(retriever_1.fileProtocol.length);
96
- if (r.startsWith(retriever_1.fileProtocol) && !(0, files_1.isFilePath)(trimmed)) {
97
- this.addAnalysisRequest({ request: 'project', content: trimmed });
98
- }
99
- else {
100
- this.addRequestFromInput(r);
101
- }
93
+ /* added at once, so that every request knows the folders of the others when its files are added */
94
+ this.ctx.addRequests(request.flatMap((r) => {
95
+ if (typeof r !== 'string') {
96
+ return r;
102
97
  }
103
- else {
104
- this.addAnalysisRequest(r);
105
- }
106
- }
98
+ const trimmed = r.slice(retriever_1.fileProtocol.length);
99
+ return r.startsWith(retriever_1.fileProtocol) && !(0, files_1.isFilePath)(trimmed) ? { request: 'project', content: trimmed } : (0, retriever_1.requestFromInput)(r);
100
+ }));
107
101
  return this;
108
102
  }
109
103
  addFile(...f) {
110
104
  this.ctx.addFiles(f);
111
105
  return this;
112
106
  }
113
- /**
114
- * Add a request created from the given input.
115
- * This is a convenience method that uses {@link requestFromInput} internally.
116
- */
117
- addRequestFromInput(input) {
118
- this.addAnalysisRequest((0, retriever_1.requestFromInput)(input));
119
- return this;
120
- }
121
- /**
122
- * Add one or multiple requests to analyze the builder.
123
- */
124
- addAnalysisRequest(request) {
125
- this.ctx.addRequests((Array.isArray(request) ? request : [request]));
126
- return this;
127
- }
128
107
  async parse(force) {
129
108
  return this.cache.parse(force);
130
109
  }