@eagleoutice/flowr 2.13.9 → 2.13.10

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 (138) hide show
  1. package/config.d.ts +50 -2
  2. package/config.js +37 -6
  3. package/dataflow/environments/apply-kill.js +4 -4
  4. package/dataflow/environments/built-in-props.d.ts +28 -4
  5. package/dataflow/environments/built-in-props.js +31 -8
  6. package/dataflow/environments/built-in.d.ts +7 -2
  7. package/dataflow/environments/built-in.js +10 -12
  8. package/dataflow/environments/default-builtin-config.d.ts +46 -6
  9. package/dataflow/environments/default-builtin-config.js +30 -16
  10. package/dataflow/environments/environment.d.ts +16 -0
  11. package/dataflow/environments/environment.js +70 -18
  12. package/dataflow/environments/identifier.d.ts +6 -0
  13. package/dataflow/environments/identifier.js +18 -5
  14. package/dataflow/environments/query-fn-props.js +34 -2
  15. package/dataflow/environments/reference-to-maybe.js +1 -1
  16. package/dataflow/eval/resolve/alias-tracking.js +45 -1
  17. package/dataflow/eval/resolve/resolve-argument.js +25 -17
  18. package/dataflow/eval/resolve/resolve-strings.d.ts +17 -0
  19. package/dataflow/eval/resolve/resolve-strings.js +16 -9
  20. package/dataflow/eval/resolve/resolve.js +3 -1
  21. package/dataflow/graph/call-graph.d.ts +7 -0
  22. package/dataflow/graph/call-graph.js +103 -0
  23. package/dataflow/graph/df-helper.d.ts +2 -0
  24. package/dataflow/graph/graph.d.ts +5 -8
  25. package/dataflow/internal/linker.d.ts +5 -5
  26. package/dataflow/internal/linker.js +31 -92
  27. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +2 -2
  28. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +3 -9
  29. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +4 -30
  30. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -1
  31. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +1 -1
  32. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +7 -1
  33. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +3 -3
  34. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.d.ts +1 -1
  35. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +5 -1
  36. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +2 -2
  37. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +5 -6
  38. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +32 -14
  39. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +16 -4
  40. package/dataflow/internal/process/functions/call/known-call-handling.js +29 -8
  41. package/documentation/doc-util/doc-sigdb.d.ts +9 -0
  42. package/documentation/doc-util/doc-sigdb.js +32 -0
  43. package/documentation/wiki-interface.js +13 -2
  44. package/documentation/wiki-query.js +3 -0
  45. package/documentation/wiki-signature-database.js +2 -5
  46. package/gas.d.ts +6 -0
  47. package/gas.js +7 -1
  48. package/package.json +1 -1
  49. package/project/attached-packages.d.ts +13 -0
  50. package/project/attached-packages.js +30 -0
  51. package/project/context/flowr-analyzer-context.d.ts +15 -0
  52. package/project/context/flowr-analyzer-context.js +14 -3
  53. package/project/context/flowr-analyzer-files-context.d.ts +11 -0
  54. package/project/context/flowr-analyzer-files-context.js +3 -0
  55. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +4 -0
  56. package/project/context/flowr-analyzer-incremental-analysis-context.js +69 -0
  57. package/project/dependency-version-space.d.ts +33 -11
  58. package/project/dependency-version-space.js +58 -32
  59. package/project/plugins/file-plugins/files/flowr-namespace-file.js +52 -24
  60. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.d.ts +22 -0
  61. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.js +101 -0
  62. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +30 -11
  63. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +79 -37
  64. package/project/plugins/plugin-registry.d.ts +2 -1
  65. package/project/plugins/plugin-registry.js +2 -0
  66. package/project/sigdb/manifest.js +9 -5
  67. package/project/sigdb/signature-match.d.ts +5 -18
  68. package/project/sigdb/signature-match.js +5 -18
  69. package/queries/catalog/call-graph-query/call-graph-query-executor.js +3 -1
  70. package/queries/catalog/call-graph-query/call-graph-query-format.d.ts +4 -0
  71. package/queries/catalog/call-graph-query/call-graph-query-format.js +4 -0
  72. package/queries/catalog/dependencies-query/dependencies-query-executor.js +10 -3
  73. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +19 -1
  74. package/queries/catalog/dependencies-query/dependencies-query-format.js +22 -2
  75. package/queries/catalog/dependencies-query/function-info/library-functions.js +7 -1
  76. package/queries/catalog/dependencies-query/function-info/read-functions.js +5 -5
  77. package/queries/catalog/dependencies-query/function-info/remote-functions.d.ts +18 -0
  78. package/queries/catalog/dependencies-query/function-info/remote-functions.js +46 -0
  79. package/queries/catalog/dependencies-query/function-info/visualize-functions.js +52 -2
  80. package/queries/catalog/dependencies-query/function-info/write-functions.js +8 -4
  81. package/queries/catalog/dependencies-query/link-devices.d.ts +12 -0
  82. package/queries/catalog/dependencies-query/link-devices.js +58 -0
  83. package/queries/catalog/dice-query/dice-query-format.d.ts +2 -0
  84. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +25 -6
  85. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +37 -6
  86. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +17 -4
  87. package/queries/catalog/input-sources-query/input-sources-query-format.js +4 -0
  88. package/queries/catalog/input-sources-query/input-types.d.ts +10 -0
  89. package/queries/catalog/input-sources-query/input-types.js +10 -0
  90. package/queries/catalog/location-map-query/location-map-query-executor.js +16 -6
  91. package/queries/catalog/location-map-query/location-map-query-format.d.ts +15 -1
  92. package/queries/catalog/location-map-query/location-map-query-format.js +22 -5
  93. package/queries/catalog/signature-query/signature-query-executor.js +3 -0
  94. package/queries/catalog/signature-query/signature-query-format.d.ts +5 -0
  95. package/queries/query.d.ts +1 -1
  96. package/r-bridge/lang-4.x/ast/model/model.d.ts +14 -2
  97. package/r-bridge/lang-4.x/ast/model/model.js +32 -0
  98. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +2 -0
  99. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +2 -0
  100. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +2 -0
  101. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +2 -0
  102. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +2 -0
  103. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +2 -0
  104. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +2 -0
  105. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +7 -8
  106. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +9 -46
  107. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +2 -0
  108. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +2 -0
  109. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +2 -0
  110. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +2 -0
  111. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +2 -0
  112. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +2 -0
  113. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +2 -0
  114. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +2 -0
  115. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +2 -0
  116. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +2 -0
  117. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +2 -0
  118. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +2 -0
  119. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +2 -0
  120. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +0 -5
  121. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +6 -3
  122. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +1 -1
  123. package/search/flowr-search-filters.d.ts +17 -1
  124. package/search/flowr-search-filters.js +23 -0
  125. package/slicing/criterion/parse.d.ts +5 -25
  126. package/slicing/criterion/parse.js +15 -20
  127. package/slicing/static/fingerprint.js +18 -6
  128. package/slicing/static/slicer-types.d.ts +10 -0
  129. package/slicing/static/static-slicer.d.ts +1 -1
  130. package/slicing/static/static-slicer.js +29 -6
  131. package/slicing/static/visiting-queue.d.ts +12 -2
  132. package/slicing/static/visiting-queue.js +28 -3
  133. package/util/arg-matching.d.ts +18 -0
  134. package/util/arg-matching.js +70 -0
  135. package/util/r-regex.js +19 -1
  136. package/util/range.d.ts +7 -8
  137. package/util/range.js +10 -11
  138. package/util/version.js +1 -1
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.FlowrAnalyzerIncrementalAnalysisContext = void 0;
4
7
  const assert_1 = require("../../util/assert");
8
+ const fs_1 = __importDefault(require("fs"));
5
9
  /**
6
10
  * Information to carry over for future incremental builds
7
11
  */
@@ -13,6 +17,7 @@ class FlowrAnalyzerIncrementalAnalysisContext {
13
17
  */
14
18
  changedFilesWithOldContent = new Map();
15
19
  oldParseResults = new Map();
20
+ lastKnownMtime = new Map();
16
21
  constructor(context) {
17
22
  this.context = context;
18
23
  }
@@ -27,6 +32,64 @@ class FlowrAnalyzerIncrementalAnalysisContext {
27
32
  }
28
33
  this.changedFilesWithOldContent.set(filePath, oldContent);
29
34
  }
35
+ handleShouldReparse(filePath, ctx) {
36
+ if (ctx.config.incremental.alwaysIncremental) {
37
+ return true;
38
+ }
39
+ if (!ctx.config.incremental.parsing.activated) {
40
+ return false;
41
+ }
42
+ const heuristics = ctx.config.incremental.parsing.heuristics;
43
+ if (!heuristics.activated || heuristics.alwaysWithEdits) {
44
+ return true;
45
+ }
46
+ const checks = [];
47
+ if (heuristics.mtime) {
48
+ checks.push((filePath, ctx) => {
49
+ let currentMtime;
50
+ try {
51
+ currentMtime = fs_1.default.statSync(filePath).mtimeMs;
52
+ }
53
+ catch {
54
+ return true;
55
+ }
56
+ const lastMtime = ctx.inc.getLastKnownMtime(filePath);
57
+ const mtimeChanged = !(lastMtime !== undefined && lastMtime === currentMtime);
58
+ if (mtimeChanged) {
59
+ ctx.inc.setLastKnownMtime(filePath, currentMtime);
60
+ }
61
+ return mtimeChanged;
62
+ });
63
+ }
64
+ if (heuristics.linesFrom !== undefined) {
65
+ checks.push((filePath, ctx) => {
66
+ const content = ctx.files.getFileByPath(filePath)?.content();
67
+ if (typeof content !== 'string') {
68
+ return false;
69
+ }
70
+ const lineCount = content.split('\n').length;
71
+ return lineCount >= heuristics.linesFrom;
72
+ });
73
+ }
74
+ if (heuristics.bytesFrom) {
75
+ checks.push((filePath) => {
76
+ try {
77
+ return fs_1.default.statSync(filePath).size >= heuristics.bytesFrom;
78
+ }
79
+ catch {
80
+ return true;
81
+ }
82
+ });
83
+ }
84
+ if (heuristics.minFiles !== undefined) {
85
+ checks.push((_filePath, ctx) => {
86
+ return ctx.files.getFileCount() >= heuristics.minFiles;
87
+ });
88
+ }
89
+ return checks.length === 0
90
+ ? true
91
+ : checks.every(check => check(filePath, ctx));
92
+ }
30
93
  receive(event) {
31
94
  const type = event.type;
32
95
  switch (type) {
@@ -58,6 +121,12 @@ class FlowrAnalyzerIncrementalAnalysisContext {
58
121
  deleteOldContentOf(filePath) {
59
122
  this.changedFilesWithOldContent.delete(filePath);
60
123
  }
124
+ getLastKnownMtime(filePath) {
125
+ return this.lastKnownMtime.get(filePath);
126
+ }
127
+ setLastKnownMtime(filePath, mtimeMs) {
128
+ this.lastKnownMtime.set(filePath, mtimeMs);
129
+ }
61
130
  }
62
131
  exports.FlowrAnalyzerIncrementalAnalysisContext = FlowrAnalyzerIncrementalAnalysisContext;
63
132
  //# sourceMappingURL=flowr-analyzer-incremental-analysis-context.js.map
@@ -12,6 +12,7 @@ import type { DecodedFunction, ResolvedDependency } from './sigdb/decode';
12
12
  import { FunctionArgument, type DataflowGraph } from '../dataflow/graph/graph';
13
13
  import type { ReadOnlyFlowrAnalyzerDependenciesContext } from './context/flowr-analyzer-dependencies-context';
14
14
  import type { ReadonlyFlowrAnalysisProvider } from './flowr-analyzer';
15
+ import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
15
16
  /** the pseudo-package standing for the analyzed project itself, never one of its own dependencies */
16
17
  export declare const ProjectPackage = "current";
17
18
  /** where a single bound on a dependency's version came from */
@@ -31,6 +32,8 @@ export interface DerivedConstraint {
31
32
  readonly function?: string;
32
33
  /** the argument/parameter that carried the evidence (for signature constraints) */
33
34
  readonly parameter?: string;
35
+ /** the call site that carried the evidence, so a bound can point at the line forcing it */
36
+ readonly at?: NodeId;
34
37
  /** the version bound this constraint establishes, if any (e.g. `>=1.1.0`, `<=2021-05-31`) */
35
38
  readonly bound?: string;
36
39
  /**
@@ -46,10 +49,12 @@ export type ConstraintObserver = (constraint: DerivedConstraint) => void;
46
49
  export type FnResolver = (fn: string, version: VersionString) => DecodedFunction | undefined;
47
50
  /** how a single function of a package is used in the code */
48
51
  interface FunctionUsage {
49
- /** the union of named argument names across all call sites (drives the lower-bound evidence) */
50
- readonly named: Set<string>;
52
+ /** per named argument used anywhere, the first call supplying it (drives the lower-bound evidence) */
53
+ readonly named: Map<string, NodeId>;
51
54
  /** one representative argument list per distinct call *shape* (drives signature compatibility) */
52
55
  readonly calls: Map<string, readonly FunctionArgument[]>;
56
+ /** the first call of the function, absent when only a class use implies it */
57
+ at?: NodeId;
53
58
  }
54
59
  /** per-package function usage, keyed by the function's (unqualified) name */
55
60
  export type PackageUsage = Map<string, FunctionUsage>;
@@ -116,8 +121,13 @@ export interface VersionExplodeOptions {
116
121
  /** a concrete, sigdb-available version choice for every resolvable dependency */
117
122
  export interface VersionAssignment {
118
123
  readonly versions: ReadonlyMap<string, VersionString>;
124
+ /**
125
+ * The requirements of the chosen versions that nothing here could settle, because they bear on a package the
126
+ * assignment does not choose (`dplyr 1.1.0 requires rlang >= 1.0.0`). Such an assignment holds for what it
127
+ * states and may still fail at `library()` time, so it is proposed but not verified.
128
+ */
129
+ readonly unverified?: readonly string[];
119
130
  }
120
- /** default safety cap on how many assignments {@link explodeDependencyVersions} yields */
121
131
  export declare const DefaultExplodeLimit = 256;
122
132
  /** the date cutoff (end of the named day/month/year) for a `YYYY.MM.DD` spec, or `undefined` if malformed */
123
133
  export declare function dateCutoff(spec: string): Date | undefined;
@@ -125,12 +135,21 @@ export declare function dateCutoff(spec: string): Date | undefined;
125
135
  export declare function isoDay(date: Date): string;
126
136
  /** scan the dataflow graph for every call that resolves (via {@link Dataflow.qualify}) to a package export */
127
137
  export declare function collectUsage(graph: DataflowGraph, deps?: ReadOnlyFlowrAnalyzerDependenciesContext): Map<string, PackageUsage>;
138
+ /** why one orphan call was attributed to its package, given that several may export the name */
139
+ export type OrphanReason = 'builtin' | 'sole exporter' | 'most downloaded';
140
+ /** one orphan call: the undefined name, where it is called, and why it was pinned on the package */
141
+ export interface OrphanCall {
142
+ readonly at: NodeId;
143
+ readonly reason: OrphanReason;
144
+ /** how many packages export the name, the field the {@link OrphanReason} picked from */
145
+ readonly exporters: number;
146
+ }
128
147
  /**
129
148
  * What the orphan calls of one analyzed program implicated, as {@link collectOrphanUsage} reports it.
130
149
  */
131
150
  export interface OrphanUsage {
132
- /** per package the project does not already know: the orphan function names that pointed at it */
133
- readonly attributed: Map<string, Set<string>>;
151
+ /** per package the project does not already know: the orphan calls that pointed at it, by function name */
152
+ readonly attributed: Map<string, Map<string, OrphanCall>>;
134
153
  /** per such package: the other exporters of those names that lost the pick, most downloaded first */
135
154
  readonly alternatives: Map<string, string[]>;
136
155
  /** the same calls recorded against every alternative, so a caller can ask which of its versions would fit */
@@ -284,15 +303,18 @@ export declare function timelinePackageKey(name: string, sources: readonly Packa
284
303
  export declare function orderedCandidatesOf(src: PackageSignatureSource | undefined, name: string, surviving: SurvivingEntries, prefer: string | undefined, order: 'newest' | 'oldest'): OrderedCandidates | undefined;
285
304
  /** the default explosion targets: every declared and used dependency (excluding `current`, the analyzed package's own namespace) */
286
305
  export declare function defaultTargets(deps: ReadOnlyFlowrAnalyzerDependenciesContext, usage: ReadonlyMap<string, PackageUsage>): string[];
287
- /** the requirements one concrete version declares, as {@link isCoInstallable} reads them */
306
+ /** the requirements one concrete version declares, as {@link coInstallability} reads them */
288
307
  export type DependencyResolver = (pkg: string, version: VersionString) => readonly ResolvedDependency[] | undefined;
289
308
  /**
290
- * Whether the chosen versions can be loaded together. The per-package candidates are narrowed by requirements
291
- * merged over *all* versions of the requiring package, so a combination can still pair a version with one that
292
- * the version it was actually chosen alongside rules out (`library()` then reports the conflict). Packages
293
- * outside the assignment and requirements without a version qualifier constrain nothing.
309
+ * Whether the chosen versions can be loaded together, checking every requirement the chosen versions declare
310
+ * against the version chosen for the required package (R itself against the chosen base-R version). A requirement
311
+ * on a package the assignment does not choose cannot be settled here and is reported as
312
+ * {@link VersionAssignment.unverified} instead of silently passing, as `library()` still enforces it.
294
313
  */
295
- export declare function isCoInstallable(versions: ReadonlyMap<string, VersionString>, declares: DependencyResolver): boolean;
314
+ export declare function coInstallability(versions: ReadonlyMap<string, VersionString>, declares: DependencyResolver): {
315
+ ok: boolean;
316
+ unverified?: readonly string[];
317
+ };
296
318
  /**
297
319
  * Lazily yield concrete version assignments (one version per package) in odometer order over the per-package lists.
298
320
  * With `declares`, a combination whose versions cannot be loaded together is skipped rather than proposed; `limit`
@@ -14,7 +14,7 @@ exports.survivingEntries = survivingEntries;
14
14
  exports.timelinePackageKey = timelinePackageKey;
15
15
  exports.orderedCandidatesOf = orderedCandidatesOf;
16
16
  exports.defaultTargets = defaultTargets;
17
- exports.isCoInstallable = isCoInstallable;
17
+ exports.coInstallability = coInstallability;
18
18
  exports.assignmentsOf = assignmentsOf;
19
19
  exports.declaredDependenciesOf = declaredDependenciesOf;
20
20
  exports.explodeDependencyVersions = explodeDependencyVersions;
@@ -44,6 +44,12 @@ const built_in_s_seven_new_generic_1 = require("../dataflow/internal/process/fun
44
44
  /** the pseudo-package standing for the analyzed project itself, never one of its own dependencies */
45
45
  exports.ProjectPackage = 'current';
46
46
  /** default safety cap on how many assignments {@link explodeDependencyVersions} yields */
47
+ /** the dependency kinds a load has to satisfy, as `Suggests`/`Enhances` are not enforced when a package is attached */
48
+ const LoadRelevantDeps = new Set([0 /* DepType.Depends */, 1 /* DepType.Imports */, 2 /* DepType.LinkingTo */]);
49
+ /** The requirements `pkg@version` places on other packages that a load has to satisfy (see {@link LoadRelevantDeps}). */
50
+ function loadRequirements(src, pkg, version) {
51
+ return (src?.dependencies(pkg, version) ?? []).filter(d => LoadRelevantDeps.has(d.type));
52
+ }
47
53
  exports.DefaultExplodeLimit = 256;
48
54
  /** the date cutoff (end of the named day/month/year) for a `YYYY.MM.DD` spec, or `undefined` if malformed */
49
55
  function dateCutoff(spec) {
@@ -157,7 +163,7 @@ function addClassOwnershipUsage(usage, deps, graph) {
157
163
  }
158
164
  // narrow by the same-named constructor's presence only when it actually resolves (else just mark used)
159
165
  if (!pkgUsage.has(cls) && src.functionByName(owner, cls) !== undefined) {
160
- pkgUsage.set(cls, { named: new Set(), calls: new Map([['#0', []]]) });
166
+ pkgUsage.set(cls, { named: new Map(), calls: new Map([['#0', []]]) });
161
167
  }
162
168
  return;
163
169
  }
@@ -177,19 +183,22 @@ function addClassOwnershipUsage(usage, deps, graph) {
177
183
  function isSyntheticArgument(arg) {
178
184
  return !graph_1.FunctionArgument.isEmpty(arg) && String(arg.nodeId).endsWith(built_in_s_seven_new_generic_1.S7SyntheticFunArgSuffix);
179
185
  }
180
- /** record one call of `fn` into `pkgUsage`: union its named argument names and keep one representative per call shape */
181
- function recordCallUsage(pkgUsage, fn, rawArgs) {
186
+ /** record one call of `fn` (made at `at`) into `pkgUsage`: union its named argument names and keep one representative per call shape */
187
+ function recordCallUsage(pkgUsage, fn, rawArgs, at) {
182
188
  let entry = pkgUsage.get(fn);
183
189
  if (entry === undefined) {
184
- entry = { named: new Set(), calls: new Map() };
190
+ entry = { named: new Map(), calls: new Map() };
185
191
  pkgUsage.set(fn, entry);
186
192
  }
193
+ entry.at ??= at;
187
194
  const args = rawArgs.some(isSyntheticArgument) ? rawArgs.filter(a => !isSyntheticArgument(a)) : rawArgs;
188
195
  const named = [];
189
196
  let positional = 0;
190
197
  for (const arg of args) {
191
198
  if (graph_1.FunctionArgument.isNamed(arg)) {
192
- entry.named.add(arg.name);
199
+ if (!entry.named.has(arg.name)) {
200
+ entry.named.set(arg.name, at);
201
+ }
193
202
  named.push(arg.name);
194
203
  }
195
204
  else if (graph_1.FunctionArgument.isPositional(arg)) {
@@ -220,7 +229,7 @@ function collectUsage(graph, deps) {
220
229
  pkgUsage = new Map();
221
230
  usage.set(pkg, pkgUsage);
222
231
  }
223
- recordCallUsage(pkgUsage, identifier_1.Identifier.getName(qualified), vertex.args);
232
+ recordCallUsage(pkgUsage, identifier_1.Identifier.getName(qualified), vertex.args, id);
224
233
  }
225
234
  if (deps) {
226
235
  addClassOwnershipUsage(usage, deps, graph);
@@ -282,23 +291,28 @@ function collectOrphanUsage(graph, deps, usage, isKnown, options = {}) {
282
291
  const mapped = builtinLibraryOf?.(name);
283
292
  const providers = deps.packagesExporting(name).filter(p => p !== self);
284
293
  const known = providers.filter(isKnown);
285
- const pkg = mapped !== undefined && mapped !== self ? mapped
294
+ const builtin = mapped !== undefined && mapped !== self;
295
+ const pkg = builtin ? mapped
286
296
  : known.length === 1 ? known[0]
287
297
  : known.length === 0 && providers.length > 0 && providers.length <= MaxOrphanProviders ? providers[0] : undefined;
288
298
  if (pkg === undefined) {
289
299
  continue;
290
300
  }
291
- recordCallUsage(atKey(usage, pkg, () => new Map()), name, vertex.args);
301
+ recordCallUsage(atKey(usage, pkg, () => new Map()), name, vertex.args, id);
292
302
  // a package the project already declares or loads is a normal target, not an orphan needing attachment
293
303
  if (isKnown(pkg)) {
294
304
  continue;
295
305
  }
296
- atKey(attributed, pkg, () => new Set()).add(name);
306
+ const reason = builtin ? 'builtin' : providers.length === 1 ? 'sole exporter' : 'most downloaded';
307
+ const calls = atKey(attributed, pkg, () => new Map());
308
+ if (!calls.has(name)) {
309
+ calls.set(name, { at: id, reason, exporters: providers.length });
310
+ }
297
311
  // the exporters that lost, with the same calls recorded, so the guess can report what each of them would fit
298
312
  const losers = providers.filter(p => p !== pkg);
299
313
  alternatives.set(pkg, [...new Set([...alternatives.get(pkg) ?? [], ...losers])]);
300
314
  for (const alt of losers) {
301
- recordCallUsage(atKey(alternativeUsage, alt, () => new Map()), name, vertex.args);
315
+ recordCallUsage(atKey(alternativeUsage, alt, () => new Map()), name, vertex.args, id);
302
316
  }
303
317
  }
304
318
  return { attributed, alternatives, alternativeUsage };
@@ -377,10 +391,10 @@ function latestSupporting(src, pkg, timeline, predicate) {
377
391
  return undefined;
378
392
  }
379
393
  /** emit one signature bound: `>=v` only when `v` is after the floor, `<=v` only when before the ceiling */
380
- function emitSignatureBound(observe, fn, v, op, ref, verb, parameter) {
394
+ function emitSignatureBound(observe, fn, v, op, ref, verb, from) {
381
395
  if (v !== undefined && (op === '>=' ? r_version_1.RVersion.compare(v, ref) > 0 : r_version_1.RVersion.compare(v, ref) < 0)) {
382
396
  const qualified = identifier_1.Identifier.toString(fn);
383
- observe({ source: 'signature', origin: qualified, detail: `${qualified} ${verb} ${v}`, bound: `${op}${v}`, function: qualified, parameter });
397
+ observe({ source: 'signature', origin: qualified, detail: `${qualified} ${verb} ${v}`, bound: `${op}${v}`, function: qualified, ...from });
384
398
  }
385
399
  }
386
400
  /** emit signature bounds from a package's version history: when functions/parameters appear or vanish */
@@ -393,12 +407,12 @@ function addSignatureEvidence(observe, src, getFn, pkg, usage, timeline) {
393
407
  for (const [fn, use] of usage) {
394
408
  const qualified = identifier_1.Identifier.make(fn, pkg);
395
409
  const present = (v) => getFn(fn, v) !== undefined;
396
- emitSignatureBound(observe, qualified, earliestSupporting(src, pkg, timeline, present), '>=', floor, 'exists only from');
397
- emitSignatureBound(observe, qualified, latestSupporting(src, pkg, timeline, present), '<=', ceiling, 'removed after');
398
- for (const arg of use.named) {
410
+ emitSignatureBound(observe, qualified, earliestSupporting(src, pkg, timeline, present), '>=', floor, 'exists only from', { at: use.at });
411
+ emitSignatureBound(observe, qualified, latestSupporting(src, pkg, timeline, present), '<=', ceiling, 'removed after', { at: use.at });
412
+ for (const [arg, at] of use.named) {
399
413
  const supported = (v) => argumentSupported(getFn(fn, v), arg);
400
- emitSignatureBound(observe, qualified, earliestSupporting(src, pkg, timeline, supported), '>=', floor, `has parameter '${arg}' only from`, arg);
401
- emitSignatureBound(observe, qualified, latestSupporting(src, pkg, timeline, supported), '<=', ceiling, `dropped parameter '${arg}' after`, arg);
414
+ emitSignatureBound(observe, qualified, earliestSupporting(src, pkg, timeline, supported), '>=', floor, `has parameter '${arg}' only from`, { at, parameter: arg });
415
+ emitSignatureBound(observe, qualified, latestSupporting(src, pkg, timeline, supported), '<=', ceiling, `dropped parameter '${arg}' after`, { at, parameter: arg });
402
416
  }
403
417
  }
404
418
  }
@@ -462,7 +476,7 @@ function collectTransitiveConstraints(deps, sources, versionsOf) {
462
476
  const perDep = new Map();
463
477
  for (const version of versions) {
464
478
  const seen = new Set();
465
- for (const dep of src.dependencies(pkg.name, version) ?? []) {
479
+ for (const dep of loadRequirements(src, pkg.name, version)) {
466
480
  const range = dep.constraint ? r_version_1.RRange.parse(dep.constraint) : undefined;
467
481
  if (!range || seen.has(dep.name)) {
468
482
  continue;
@@ -621,7 +635,7 @@ function factorRequirements(space, f) {
621
635
  const { src, key } = space.resolve(f.name);
622
636
  return f.survivors.map(v => {
623
637
  const out = new Map();
624
- for (const dep of src?.dependencies(key, v) ?? []) {
638
+ for (const dep of loadRequirements(src, key, v)) {
625
639
  const range = dep.constraint ? r_version_1.RRange.parse(dep.constraint) : undefined;
626
640
  if (range && !out.has(dep.name)) {
627
641
  out.set(dep.name, range);
@@ -721,7 +735,7 @@ function countOverForest(factors, tree) {
721
735
  }
722
736
  /** whether every requirement `pkg@ver` places on a co-guessed dependency is met by one of that partner's surviving versions */
723
737
  function versionMeetsPartners(src, pkg, ver, partnerSurvivors, selfName, onReject) {
724
- for (const dep of src.dependencies(pkg, ver) ?? []) {
738
+ for (const dep of loadRequirements(src, pkg, ver)) {
725
739
  if (dep.name === selfName || !dep.constraint) {
726
740
  continue;
727
741
  }
@@ -857,25 +871,33 @@ function defaultTargets(deps, usage) {
857
871
  return [...new Set([...deps.getDependencies().map(d => d.name), ...usage.keys()])].filter(name => name !== exports.ProjectPackage);
858
872
  }
859
873
  /**
860
- * Whether the chosen versions can be loaded together. The per-package candidates are narrowed by requirements
861
- * merged over *all* versions of the requiring package, so a combination can still pair a version with one that
862
- * the version it was actually chosen alongside rules out (`library()` then reports the conflict). Packages
863
- * outside the assignment and requirements without a version qualifier constrain nothing.
874
+ * Whether the chosen versions can be loaded together, checking every requirement the chosen versions declare
875
+ * against the version chosen for the required package (R itself against the chosen base-R version). A requirement
876
+ * on a package the assignment does not choose cannot be settled here and is reported as
877
+ * {@link VersionAssignment.unverified} instead of silently passing, as `library()` still enforces it.
864
878
  */
865
- function isCoInstallable(versions, declares) {
879
+ function coInstallability(versions, declares) {
880
+ const unverified = [];
866
881
  for (const [pkg, version] of versions) {
867
882
  for (const dep of declares(pkg, version) ?? []) {
868
- const chosen = versions.get(dep.name);
869
- if (chosen === undefined || dep.constraint === undefined) {
883
+ if (dep.constraint === undefined || !LoadRelevantDeps.has(dep.type)) {
870
884
  continue;
871
885
  }
886
+ /* R's own version is the version of the base packages, which is what the assignment names it by */
887
+ const chosen = versions.get(dep.name) ?? (dep.name === 'R' ? versions.get('base') : undefined);
872
888
  const range = r_version_1.RRange.parse(dep.constraint);
873
- if (range !== undefined && !r_version_1.RRange.satisfies(chosen, range)) {
874
- return false;
889
+ if (range === undefined) {
890
+ continue;
891
+ }
892
+ else if (chosen === undefined) {
893
+ unverified.push(`${pkg} ${version} requires ${dep.name} ${dep.constraint}`);
894
+ }
895
+ else if (!r_version_1.RRange.satisfies(chosen, range)) {
896
+ return { ok: false };
875
897
  }
876
898
  }
877
899
  }
878
- return true;
900
+ return { ok: true, ...(unverified.length > 0 ? { unverified } : {}) };
879
901
  }
880
902
  /**
881
903
  * Lazily yield concrete version assignments (one version per package) in odometer order over the per-package lists.
@@ -892,9 +914,13 @@ function* assignmentsOf(perPackage, limit, declares) {
892
914
  for (let i = 0; i < perPackage.length; i++) {
893
915
  versions.set(perPackage[i].pkg, perPackage[i].versions[idx[i]]);
894
916
  }
895
- if (declares === undefined || isCoInstallable(versions, declares)) {
917
+ const checked = declares === undefined ? undefined : coInstallability(versions, declares);
918
+ if (checked === undefined) {
896
919
  yield { versions };
897
920
  }
921
+ else if (checked.ok) {
922
+ yield { versions, ...(checked.unverified ? { unverified: checked.unverified } : {}) };
923
+ }
898
924
  // advance the odometer: the last package varies fastest
899
925
  let k = perPackage.length - 1;
900
926
  for (; k >= 0; k--) {
@@ -9,6 +9,7 @@ exports.setCallable = setCallable;
9
9
  const flowr_file_1 = require("../../../context/flowr-file");
10
10
  const resolve_args_1 = require("../../../../abstract-interpretation/data-frame/resolve-args");
11
11
  const retriever_1 = require("../../../../r-bridge/retriever");
12
+ const strings_1 = require("../../../../util/text/strings");
12
13
  const fold_1 = require("../../../../r-bridge/lang-4.x/ast/model/processing/fold");
13
14
  const identifier_1 = require("../../../../dataflow/environments/identifier");
14
15
  const assert_1 = require("../../../../util/assert");
@@ -244,8 +245,12 @@ function wrapRNodeInNotCall(node, idMap) {
244
245
  arguments: [(0, make_argument_1.toUnnamedArgument)(node, idMap)]
245
246
  };
246
247
  }
248
+ /** the name a NAMESPACE directive lists, without the quotes or backticks R allows around it */
249
+ function unquoteName(name) {
250
+ return (0, strings_1.startAndEndsWith)(name, '`') ? name.slice(1, -1) : (0, retriever_1.removeRQuotes)(name);
251
+ }
247
252
  function handleExportCall(g, args) {
248
- g.current.exportedSymbols.push(...args.filter(a => a !== r_function_call_1.EmptyArgument).map(a => a.lexeme ? (0, retriever_1.removeRQuotes)(a.lexeme) : undefined).filter(assert_1.isNotUndefined));
253
+ g.current.exportedSymbols.push(...args.filter(a => a !== r_function_call_1.EmptyArgument).map(a => a.lexeme ? unquoteName(a.lexeme) : undefined).filter(assert_1.isNotUndefined));
249
254
  return g;
250
255
  }
251
256
  function handleExportPatternCall(g, args) {
@@ -253,7 +258,8 @@ function handleExportPatternCall(g, args) {
253
258
  return g;
254
259
  }
255
260
  function handleS3MethodCall(g, args) {
256
- if (args.length !== 2) {
261
+ /* `S3method(generic, class)` and `S3method(generic, class, method)` both register the class */
262
+ if (args.length !== 2 && args.length !== 3) {
257
263
  return g;
258
264
  }
259
265
  const pkgArg = args[0];
@@ -261,8 +267,8 @@ function handleS3MethodCall(g, args) {
261
267
  if (pkgArg === r_function_call_1.EmptyArgument || funcArg === r_function_call_1.EmptyArgument || !pkgArg.lexeme || !funcArg.lexeme) {
262
268
  return g;
263
269
  }
264
- const pkg = (0, retriever_1.removeRQuotes)(pkgArg.lexeme);
265
- const func = (0, retriever_1.removeRQuotes)(funcArg.lexeme);
270
+ const pkg = unquoteName(pkgArg.lexeme);
271
+ const func = unquoteName(funcArg.lexeme);
266
272
  let arr = g.current.exportS3Generics.get(pkg);
267
273
  if (!arr) {
268
274
  arr = [];
@@ -272,15 +278,12 @@ function handleS3MethodCall(g, args) {
272
278
  return g;
273
279
  }
274
280
  function handleImportCall(g, args) {
275
- if (args.length !== 1) {
276
- return g;
277
- }
278
- const pkgArg = args[0];
279
- if (pkgArg === r_function_call_1.EmptyArgument || !pkgArg.lexeme) {
280
- return g;
281
+ /* `import(a, b)` imports both; a named argument like `except =` names no package */
282
+ for (const arg of args) {
283
+ if (arg !== r_function_call_1.EmptyArgument && arg.name === undefined && arg.lexeme) {
284
+ g.current.importedPackages?.set(unquoteName(arg.lexeme), 'all');
285
+ }
281
286
  }
282
- const pkg = (0, retriever_1.removeRQuotes)(pkgArg.lexeme);
283
- g.current.importedPackages?.set(pkg, 'all');
284
287
  return g;
285
288
  }
286
289
  function handleImportFromCall(g, args) {
@@ -291,7 +294,7 @@ function handleImportFromCall(g, args) {
291
294
  if (pkgArg === r_function_call_1.EmptyArgument || !pkgArg.lexeme) {
292
295
  return g;
293
296
  }
294
- const pkg = (0, retriever_1.removeRQuotes)(pkgArg.lexeme);
297
+ const pkg = unquoteName(pkgArg.lexeme);
295
298
  let arr = g.current.importedPackages?.get(pkg);
296
299
  if (!arr || arr === 'all') {
297
300
  arr = [];
@@ -302,7 +305,7 @@ function handleImportFromCall(g, args) {
302
305
  if (symArg === r_function_call_1.EmptyArgument || !symArg.lexeme) {
303
306
  continue;
304
307
  }
305
- const sym = (0, retriever_1.removeRQuotes)(symArg.lexeme);
308
+ const sym = unquoteName(symArg.lexeme);
306
309
  arr.push(sym);
307
310
  }
308
311
  return g;
@@ -315,7 +318,7 @@ function handleUseDynLibCall(g, args) {
315
318
  if (pkgArg === r_function_call_1.EmptyArgument || !pkgArg.lexeme) {
316
319
  return g;
317
320
  }
318
- const pkg = (0, retriever_1.removeRQuotes)(pkgArg.lexeme);
321
+ const pkg = unquoteName(pkgArg.lexeme);
319
322
  if (!g[pkg]) {
320
323
  g[pkg] = {
321
324
  exportedSymbols: [],
@@ -334,7 +337,7 @@ function handleExportClassesCall(g, args) {
334
337
  if (args.length !== 1) {
335
338
  return g;
336
339
  }
337
- const classArgs = args.filter(a => a !== r_function_call_1.EmptyArgument).map(a => a.lexeme ? (0, retriever_1.removeRQuotes)(a.lexeme) : undefined).filter(assert_1.isNotUndefined);
340
+ const classArgs = args.filter(a => a !== r_function_call_1.EmptyArgument).map(a => a.lexeme ? unquoteName(a.lexeme) : undefined).filter(assert_1.isNotUndefined);
338
341
  g.current.exportedFunctions.push(...classArgs);
339
342
  return g;
340
343
  }
@@ -421,9 +424,33 @@ function mergeNamespaceInfo(target, source) {
421
424
  conditional: mergedConditional.size > 0 ? mergedConditional : undefined,
422
425
  };
423
426
  }
424
- /** Split a NAMESPACE directive's argument list (`a, "b", c`) into individual, quote-stripped names. */
427
+ /** an argument given by name (`except = c(x)`), which names no symbol of its own */
428
+ const namedArgument = /^[\w.]+\s*=[^=]/;
429
+ /**
430
+ * Split a NAMESPACE directive's argument list (`a, "b", except = c(x)`) into its positional, quote-stripped
431
+ * names. Only top-level commas separate, so an argument that is itself a call stays in one piece.
432
+ */
425
433
  function splitNamespaceArgs(args) {
426
- return args.split(',').map(s => (0, retriever_1.removeRQuotes)(s.trim())).filter(s => s.length > 0);
434
+ const names = [];
435
+ let depth = 0;
436
+ let start = 0;
437
+ for (let i = 0; i <= args.length; i++) {
438
+ const c = args[i];
439
+ if (c === '(' || c === '[') {
440
+ depth++;
441
+ }
442
+ else if (c === ')' || c === ']') {
443
+ depth--;
444
+ }
445
+ else if (i === args.length || (c === ',' && depth === 0)) {
446
+ const part = args.slice(start, i).trim();
447
+ start = i + 1;
448
+ if (part.length > 0 && !namedArgument.test(part)) {
449
+ names.push(unquoteName(part));
450
+ }
451
+ }
452
+ }
453
+ return names;
427
454
  }
428
455
  /**
429
456
  * Parses the given NAMESPACE file
@@ -433,7 +460,7 @@ function parseNamespaceSimple(file) {
433
460
  const fileContent = file.content().toString().replaceAll(cleanLineCommentRegex, '').trim()
434
461
  .split(/\r?\n/).filter(Boolean);
435
462
  for (const line of fileContent) {
436
- const match = line.trim().match(/^(\w+)\(([^)]*)\)$/);
463
+ const match = line.trim().match(/^(\w+)\((.*)\)$/);
437
464
  if (!match) {
438
465
  continue;
439
466
  }
@@ -446,8 +473,8 @@ function parseNamespaceSimple(file) {
446
473
  break;
447
474
  case 'S3method':
448
475
  {
449
- const parts = args.split(',').map(s => (0, retriever_1.removeRQuotes)(s.trim()));
450
- if (parts.length !== 2) {
476
+ const parts = splitNamespaceArgs(args);
477
+ if (parts.length !== 2 && parts.length !== 3) {
451
478
  continue;
452
479
  }
453
480
  const [pkg, func] = parts;
@@ -485,14 +512,15 @@ function parseNamespaceSimple(file) {
485
512
  break;
486
513
  }
487
514
  case 'import': {
488
- const pkg = args.trim();
489
- result.current.importedPackages?.set(pkg, 'all');
515
+ for (const pkg of splitNamespaceArgs(args)) {
516
+ result.current.importedPackages?.set(pkg, 'all');
517
+ }
490
518
  break;
491
519
  }
492
520
  case 'importFrom':
493
521
  case 'importClassesFrom':
494
522
  case 'importMethodsFrom': {
495
- const parts = args.split(',').map(s => s.trim());
523
+ const parts = splitNamespaceArgs(args);
496
524
  if (parts.length < 2) {
497
525
  continue;
498
526
  }
@@ -0,0 +1,22 @@
1
+ import { FlowrAnalyzerPackageVersionsPlugin } from './flowr-analyzer-package-versions-plugin';
2
+ import { SemVer } from 'semver';
3
+ import type { FlowrAnalyzerContext } from '../../context/flowr-analyzer-context';
4
+ import type { FlowrConfig } from '../../../config';
5
+ export declare const libraryLog: import("tslog").Logger<import("tslog").ILogObj>;
6
+ /** How the fallback searches for an installed package, see `solver.sigdb.installedLibrary`. */
7
+ export type InstalledLibraryOptions = NonNullable<FlowrConfig['solver']['sigdb']['installedLibrary']>;
8
+ /**
9
+ * Fills in packages no signature database knows from the copy installed on this machine: a package that CRAN
10
+ * archived (`maptools`, `rgdal`, ...) is in no database, but if it is installed, its `NAMESPACE` states its
11
+ * exports just as well. Off unless `solver.sigdb.installedLibrary.enabled` says otherwise, and consulted only
12
+ * for a package nothing else could resolve, so it never overrides a database entry.
13
+ */
14
+ export declare class FlowrAnalyzerPackageVersionsLibraryPlugin extends FlowrAnalyzerPackageVersionsPlugin {
15
+ readonly name = "flowr-analyzer-package-version-library-plugin";
16
+ readonly description = "Recovers the exports of packages no database knows from their installed copy.";
17
+ readonly version: SemVer;
18
+ private readonly overrides?;
19
+ /** @param overrides - options replacing what `solver.sigdb.installedLibrary` states, `enabled` included */
20
+ constructor(overrides?: Partial<InstalledLibraryOptions>);
21
+ process(ctx: FlowrAnalyzerContext): void;
22
+ }