@eagleoutice/flowr 2.11.0 → 2.12.0
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.
- package/README.md +190 -260
- package/abstract-interpretation/data-frame/mappers/arguments.js +7 -1
- package/abstract-interpretation/domains/set-range-domain.js +1 -1
- package/abstract-interpretation/domains/set-upper-bound-domain.js +6 -2
- package/benchmark/slicer.d.ts +1 -1
- package/benchmark/slicer.js +3 -1
- package/benchmark/summarizer/second-phase/graph.js +5 -0
- package/cli/common/options.d.ts +8 -0
- package/cli/common/options.js +2 -0
- package/cli/common/scripts-info.d.ts +8 -0
- package/cli/flowr.js +1 -1
- package/cli/repl/commands/repl-commands.d.ts +1 -0
- package/cli/repl/commands/repl-commands.js +69 -17
- package/cli/repl/commands/repl-dataflow.js +48 -4
- package/cli/repl/commands/repl-main.d.ts +2 -0
- package/cli/repl/commands/repl-main.js +5 -0
- package/cli/repl/commands/repl-query.d.ts +4 -1
- package/cli/repl/commands/repl-query.js +72 -22
- package/cli/repl/commands/repl-signature.d.ts +7 -0
- package/cli/repl/commands/repl-signature.js +119 -0
- package/cli/repl/core.d.ts +8 -1
- package/cli/repl/core.js +46 -6
- package/cli/repl/ghost-hint.d.ts +37 -0
- package/cli/repl/ghost-hint.js +72 -0
- package/cli/repl/parser/slice-query-parser.d.ts +11 -1
- package/cli/repl/parser/slice-query-parser.js +45 -16
- package/cli/repl/print-version.d.ts +2 -4
- package/cli/repl/print-version.js +41 -23
- package/cli/repl/server/connection.js +19 -17
- package/cli/slicer-app.d.ts +2 -0
- package/cli/slicer-app.js +3 -3
- package/cli/wiki.d.ts +2 -2
- package/cli/wiki.js +2 -2
- package/config.d.ts +70 -13
- package/config.js +65 -7
- package/control-flow/cfg-dead-code.js +0 -1
- package/control-flow/control-flow-graph.js +6 -6
- package/control-flow/diff-cfg.js +2 -2
- package/control-flow/semantic-cfg-guided-visitor.js +2 -0
- package/core/print/slice-diff-ansi.js +8 -8
- package/core/steps/all/core/20-dataflow.d.ts +2 -2
- package/core/steps/all/static-slicing/00-slice.d.ts +5 -0
- package/core/steps/all/static-slicing/00-slice.js +1 -1
- package/core/steps/all/static-slicing/10-reconstruct.d.ts +7 -0
- package/core/steps/all/static-slicing/10-reconstruct.js +6 -2
- package/core/steps/pipeline/default-pipelines.d.ts +20 -16
- package/data/r-base-packages.generated.d.ts +44 -0
- package/data/r-base-packages.generated.js +32 -0
- package/data/r-base-primitives.generated.d.ts +1 -0
- package/data/r-base-primitives.generated.js +15 -0
- package/data/sigdb/sigdb.remote.json +112 -0
- package/dataflow/environments/built-in-proc-name.d.ts +4 -0
- package/dataflow/environments/built-in-proc-name.js +4 -0
- package/dataflow/environments/built-in.d.ts +14 -4
- package/dataflow/environments/built-in.js +13 -2
- package/dataflow/environments/data-masking-functions.d.ts +12 -0
- package/dataflow/environments/data-masking-functions.js +46 -0
- package/dataflow/environments/default-builtin-config.d.ts +72 -19
- package/dataflow/environments/default-builtin-config.js +48 -14
- package/dataflow/environments/diff.js +1 -1
- package/dataflow/environments/environment.js +1 -2
- package/dataflow/environments/identifier.d.ts +11 -4
- package/dataflow/environments/identifier.js +28 -10
- package/dataflow/environments/resolve-by-name.js +16 -2
- package/dataflow/extractor.js +6 -3
- package/dataflow/graph/call-graph.d.ts +2 -2
- package/dataflow/graph/df-helper.d.ts +4 -4
- package/dataflow/graph/diff-dataflow-graph.js +2 -2
- package/dataflow/graph/edge.d.ts +3 -3
- package/dataflow/graph/edge.js +3 -3
- package/dataflow/graph/graph-helper.d.ts +2 -2
- package/dataflow/internal/linker.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +7 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +20 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +1 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +2 -49
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +7 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +111 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +13 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +2 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +9 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +12 -4
- package/dataflow/internal/process/functions/call/common.js +8 -1
- package/dataflow/internal/process/functions/call/default-call-handling.js +6 -0
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +17 -0
- package/dataflow/internal/process/functions/call/known-call-handling.js +32 -0
- package/dataflow/internal/process/functions/call/named-call-handling.js +29 -7
- package/dataflow/internal/process/functions/process-argument.js +12 -1
- package/dataflow/internal/process/process-named-call.d.ts +18 -1
- package/dataflow/internal/process/process-named-call.js +94 -0
- package/dataflow/processor.d.ts +18 -0
- package/documentation/data/faq/faqs.js +5 -1
- package/documentation/doc-capabilities.js +1 -1
- package/documentation/doc-util/doc-cli-option.d.ts +10 -0
- package/documentation/doc-util/doc-cli-option.js +23 -0
- package/documentation/doc-util/doc-dfg.js +2 -1
- package/documentation/doc-util/doc-query.d.ts +9 -3
- package/documentation/doc-util/doc-query.js +9 -4
- package/documentation/wiki-dataflow-graph.js +8 -5
- package/documentation/wiki-interface.js +3 -2
- package/documentation/wiki-linter.js +1 -1
- package/documentation/wiki-linting-and-testing.js +4 -1
- package/documentation/wiki-mk/doc-context.d.ts +14 -0
- package/documentation/wiki-mk/doc-context.js +3 -0
- package/documentation/wiki-mk/doc-maker.js +3 -1
- package/documentation/wiki-query.js +19 -1
- package/documentation/wiki-setup.js +10 -7
- package/documentation/wiki-signature-database.d.ts +16 -0
- package/documentation/wiki-signature-database.js +293 -0
- package/linter/linter-format.d.ts +7 -0
- package/linter/linter-rules.d.ts +10 -9
- package/linter/rules/naming-convention.d.ts +1 -0
- package/linter/rules/naming-convention.js +2 -0
- package/linter/rules/no-leaked-credentials.js +1 -2
- package/linter/rules/roxygen-arguments.js +18 -5
- package/linter/rules/stop-with-call-arg.js +2 -2
- package/linter/rules/undefined-symbol-util.d.ts +36 -0
- package/linter/rules/undefined-symbol-util.js +149 -0
- package/linter/rules/undefined-symbol.d.ts +58 -17
- package/linter/rules/undefined-symbol.js +143 -33
- package/linter/rules/unused-definition.d.ts +8 -1
- package/linter/rules/unused-definition.js +126 -1
- package/package.json +23 -10
- package/project/context/abstract-flowr-analyzer-context.js +7 -1
- package/project/context/flowr-analyzer-context.d.ts +8 -0
- package/project/context/flowr-analyzer-context.js +10 -0
- package/project/context/flowr-analyzer-dependencies-context.d.ts +28 -4
- package/project/context/flowr-analyzer-dependencies-context.js +53 -1
- package/project/context/flowr-analyzer-files-context.d.ts +1 -0
- package/project/context/flowr-analyzer-files-context.js +2 -1
- package/project/context/flowr-analyzer-functions-context.js +1 -1
- package/project/context/flowr-file.d.ts +5 -0
- package/project/context/flowr-file.js +5 -0
- package/project/flowr-analyzer-builder.js +12 -2
- package/project/plugins/file-plugins/files/flowr-description-file.js +6 -3
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +9 -3
- package/project/plugins/file-plugins/files/flowr-news-file.js +1 -3
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +26 -0
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +39 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +1 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +18 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +19 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +120 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +518 -0
- package/project/plugins/package-version-plugins/package.d.ts +5 -3
- package/project/plugins/package-version-plugins/package.js +27 -25
- package/project/plugins/plugin-registry.d.ts +3 -2
- package/project/plugins/plugin-registry.js +4 -2
- package/project/plugins/project-discovery/flowr-analyzer-gitignore-project-discovery-plugin.js +7 -2
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +3 -1
- package/project/sigdb/build.d.ts +131 -0
- package/project/sigdb/build.js +628 -0
- package/project/sigdb/codec.d.ts +51 -0
- package/project/sigdb/codec.js +122 -0
- package/project/sigdb/decode.d.ts +58 -0
- package/project/sigdb/decode.js +129 -0
- package/project/sigdb/decompress.d.ts +44 -0
- package/project/sigdb/decompress.js +176 -0
- package/project/sigdb/hash.d.ts +9 -0
- package/project/sigdb/hash.js +54 -0
- package/project/sigdb/index-format.d.ts +40 -0
- package/project/sigdb/index-format.js +28 -0
- package/project/sigdb/manifest.d.ts +68 -0
- package/project/sigdb/manifest.js +146 -0
- package/project/sigdb/reader.d.ts +250 -0
- package/project/sigdb/reader.js +692 -0
- package/project/sigdb/schema.d.ts +196 -0
- package/project/sigdb/schema.js +33 -0
- package/project/sigdb/sigdb-download.d.ts +65 -0
- package/project/sigdb/sigdb-download.js +237 -0
- package/project/sigdb/signature-match.d.ts +26 -0
- package/project/sigdb/signature-match.js +40 -0
- package/project/sigdb/version.d.ts +20 -0
- package/project/sigdb/version.js +55 -0
- package/queries/catalog/call-context-query/call-context-query-executor.js +1 -3
- package/queries/catalog/config-query/config-query-format.d.ts +3 -1
- package/queries/catalog/config-query/config-query-format.js +68 -9
- package/queries/catalog/dataflow-query/dataflow-query-format.js +11 -1
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +1 -1
- package/queries/catalog/linter-query/linter-query-executor.d.ts +2 -0
- package/queries/catalog/linter-query/linter-query-executor.js +6 -1
- package/queries/catalog/linter-query/linter-query-format.d.ts +2 -1
- package/queries/catalog/linter-query/linter-query-format.js +40 -8
- package/queries/catalog/project-query/project-query-executor.d.ts +15 -0
- package/queries/catalog/project-query/project-query-executor.js +96 -4
- package/queries/catalog/project-query/project-query-format.d.ts +44 -0
- package/queries/catalog/project-query/project-query-format.js +33 -2
- package/queries/catalog/signature-query/signature-query-executor.d.ts +29 -0
- package/queries/catalog/signature-query/signature-query-executor.js +461 -0
- package/queries/catalog/signature-query/signature-query-format.d.ts +138 -0
- package/queries/catalog/signature-query/signature-query-format.js +76 -0
- package/queries/catalog/signature-query/signature-query-render.d.ts +15 -0
- package/queries/catalog/signature-query/signature-query-render.js +155 -0
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +9 -3
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +10 -0
- package/queries/catalog/static-slice-query/static-slice-query-format.js +19 -1
- package/queries/query-print.js +5 -0
- package/queries/query.d.ts +10 -1
- package/queries/query.js +5 -2
- package/r-bridge/init.js +5 -1
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +10 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +55 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +16 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +27 -0
- package/r-bridge/lang-4.x/ast/parser/json/format.js +89 -2
- package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -4
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +2 -1
- package/r-bridge/parser.d.ts +2 -0
- package/r-bridge/retriever.js +4 -1
- package/r-bridge/roxygen2/documentation-provider.js +2 -1
- package/r-bridge/shell.d.ts +5 -0
- package/r-bridge/shell.js +17 -1
- package/reconstruct/inline/source-inline-map.d.ts +48 -0
- package/reconstruct/inline/source-inline-map.js +94 -0
- package/reconstruct/reconstruct.d.ts +19 -2
- package/reconstruct/reconstruct.js +79 -16
- package/search/search-executor/search-generators.js +5 -22
- package/search/search-executor/search-transformer.js +10 -6
- package/slicing/criterion/parse.d.ts +22 -4
- package/slicing/criterion/parse.js +125 -18
- package/slicing/static/slice-call.d.ts +24 -1
- package/slicing/static/slice-call.js +90 -0
- package/slicing/static/static-slicer.d.ts +7 -0
- package/slicing/static/static-slicer.js +38 -3
- package/util/collections/arrays.d.ts +4 -5
- package/util/collections/arrays.js +7 -18
- package/util/hash.d.ts +14 -0
- package/util/hash.js +31 -0
- package/util/mermaid/dfg.d.ts +7 -2
- package/util/mermaid/dfg.js +53 -13
- package/util/r-base-packages.d.ts +19 -0
- package/util/r-base-packages.js +72 -0
- package/util/r-license.js +2 -10
- package/util/r-version.d.ts +45 -15
- package/util/r-version.js +97 -36
- package/util/range.d.ts +15 -0
- package/util/range.js +39 -0
- package/util/schema.d.ts +10 -0
- package/util/schema.js +22 -0
- package/util/text/ansi.d.ts +13 -1
- package/util/text/ansi.js +27 -4
- package/util/text/args.js +1 -2
- package/util/version.js +28 -8
- package/data/pkgdb/pkgdb-latest.json.br +0 -0
- package/data/pkgdb/pkgdb-tiny.json.br +0 -0
- package/documentation/wiki-package-database.d.ts +0 -9
- package/documentation/wiki-package-database.js +0 -63
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +0 -63
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +0 -174
- package/project/plugins/package-version-plugins/pkgdb.d.ts +0 -133
- package/project/plugins/package-version-plugins/pkgdb.js +0 -370
|
@@ -24,6 +24,11 @@ function staticSlice(options) {
|
|
|
24
24
|
const direction = options.direction ?? slice_direction_1.SliceDirection.Backward;
|
|
25
25
|
const threshold = options.threshold ?? 75;
|
|
26
26
|
(0, assert_1.guard)(ids.length > 0, 'must have at least one seed id to calculate slice');
|
|
27
|
+
// includeCallees only makes sense on the original (non-reduced) graph, backward
|
|
28
|
+
const trackCallees = (options.includeCallees ?? false) && direction === slice_direction_1.SliceDirection.Backward && sliceGraph === undefined;
|
|
29
|
+
// enclosing function definitions whose callees still need to be considered, mapped to the env to enqueue them in
|
|
30
|
+
const pendingCalleeBoundaries = new Map();
|
|
31
|
+
const resolvedCalleeBoundaries = new Set();
|
|
27
32
|
let graph;
|
|
28
33
|
if (sliceGraph !== undefined) {
|
|
29
34
|
graph = sliceGraph;
|
|
@@ -57,15 +62,31 @@ function staticSlice(options) {
|
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
|
-
|
|
65
|
+
do {
|
|
66
|
+
while (queue.nonEmpty()) {
|
|
67
|
+
processNode();
|
|
68
|
+
}
|
|
69
|
+
// the queue drained: only now do we know the full body slice, so decide per boundary whether the callers
|
|
70
|
+
// can actually influence the result (i.e., the slice reaches a parameter or a captured scope variable).
|
|
71
|
+
// resolving a boundary may enqueue new nodes, hence the surrounding do-while re-enters the traversal.
|
|
72
|
+
resolveCalleeBoundaries();
|
|
73
|
+
} while (queue.nonEmpty());
|
|
74
|
+
function processNode() {
|
|
61
75
|
const current = queue.next();
|
|
62
76
|
const { baseEnvironment, id, onlyForSideEffects, envFingerprint: baseEnvFingerprint } = current;
|
|
63
77
|
const currentInfo = graph.get(id, true);
|
|
64
78
|
if (currentInfo === undefined) {
|
|
65
79
|
exports.slicerLogger.warn(`id: ${id} must be in graph but can not be found, keep in slice to be sure`);
|
|
66
|
-
|
|
80
|
+
return;
|
|
67
81
|
}
|
|
68
82
|
const [currentVertex, currentEdges] = currentInfo;
|
|
83
|
+
// includeCallees: note the enclosing function definition (if any) so its callees can be considered once the body slice is complete
|
|
84
|
+
if (trackCallees) {
|
|
85
|
+
const enclosingFnDef = (0, slice_call_1.findEnclosingFunctionDefinition)(id, idMap);
|
|
86
|
+
if (enclosingFnDef !== undefined && !resolvedCalleeBoundaries.has(enclosingFnDef) && !pendingCalleeBoundaries.has(enclosingFnDef)) {
|
|
87
|
+
pendingCalleeBoundaries.set(enclosingFnDef, [baseEnvironment, baseEnvFingerprint]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
69
90
|
// we only add control dependencies iff 1) we are in different function call or 2) they have, at least, the same nesting as the slicing seed
|
|
70
91
|
if (currentVertex.cds && currentVertex.cds.length > 0) {
|
|
71
92
|
const topLevel = graph.isRoot(id) || sliceSeedIds.has(id);
|
|
@@ -81,7 +102,7 @@ function staticSlice(options) {
|
|
|
81
102
|
}
|
|
82
103
|
const ret = (0, slice_call_1.handleReturns)(id, queue, currentEdges, baseEnvFingerprint, baseEnvironment);
|
|
83
104
|
if (ret) {
|
|
84
|
-
|
|
105
|
+
return;
|
|
85
106
|
}
|
|
86
107
|
}
|
|
87
108
|
for (const [target, e] of currentEdges) {
|
|
@@ -103,6 +124,20 @@ function staticSlice(options) {
|
|
|
103
124
|
}
|
|
104
125
|
}
|
|
105
126
|
}
|
|
127
|
+
function resolveCalleeBoundaries() {
|
|
128
|
+
if (pendingCalleeBoundaries.size === 0) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const boundaries = [...pendingCalleeBoundaries];
|
|
132
|
+
pendingCalleeBoundaries.clear();
|
|
133
|
+
for (const [fnDefId, [env, fingerprint]] of boundaries) {
|
|
134
|
+
resolvedCalleeBoundaries.add(fnDefId);
|
|
135
|
+
// only continue past the boundary if the callers can actually influence the sliced result
|
|
136
|
+
if ((0, slice_call_1.sliceReachesFunctionInterface)(fnDefId, info.graph, queue, idMap, ctx)) {
|
|
137
|
+
(0, slice_call_1.includeCalleesOfDefinition)(fnDefId, info.graph, queue, env, fingerprint);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
106
141
|
if (ctx.config.solver.slicer?.autoExtend) {
|
|
107
142
|
return { ...queue.status(), slicedFor: ids, result: extendSlices(queue.status().result, idMap) };
|
|
108
143
|
}
|
|
@@ -35,17 +35,16 @@ export declare function splitArrayOn<T>(arr: readonly T[], predicate: (elem: T)
|
|
|
35
35
|
* and the second one contains all elements for which the predicate returned false.
|
|
36
36
|
*/
|
|
37
37
|
export declare function partitionArray<T>(arr: readonly T[], predicate: (elem: T) => boolean): [T[], T[]];
|
|
38
|
+
/**
|
|
39
|
+
* {@link partitionArray} for a mutable array.
|
|
40
|
+
*/
|
|
41
|
+
export declare function partition<T>(arr: T[], predicate: (elem: T) => boolean): [T[], T[]];
|
|
38
42
|
/**
|
|
39
43
|
* Generate all permutations of the given array using Heap's algorithm (with its non-recursive variant).
|
|
40
44
|
* @param arr - The array to permute
|
|
41
45
|
* @see getUniqueCombinationsOfSize
|
|
42
46
|
*/
|
|
43
47
|
export declare function allPermutations<T>(arr: T[]): Generator<T[], void, void>;
|
|
44
|
-
/**
|
|
45
|
-
* Returns a tuple of two arrays, where the first one contains all elements for which the predicate returned true,
|
|
46
|
-
* and the second one contains all elements for which the predicate returned false.
|
|
47
|
-
*/
|
|
48
|
-
export declare function partition<T>(arr: T[], predicate: (elem: T) => boolean): [T[], T[]];
|
|
49
48
|
/**
|
|
50
49
|
* Generate all unique combinations of the array with the given size.
|
|
51
50
|
* In other words, given `[a,b,c]`, as well as `minSize=2` and `maxSize=2`, this will generate `[a,b]`, `[a,c]` and `[b,c]`,
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.splitArrayOn = splitArrayOn;
|
|
4
4
|
exports.partitionArray = partitionArray;
|
|
5
|
-
exports.allPermutations = allPermutations;
|
|
6
5
|
exports.partition = partition;
|
|
6
|
+
exports.allPermutations = allPermutations;
|
|
7
7
|
exports.getUniqueCombinationsOfSize = getUniqueCombinationsOfSize;
|
|
8
8
|
exports.arraySum = arraySum;
|
|
9
9
|
exports.array2bag = array2bag;
|
|
@@ -64,6 +64,12 @@ function partitionArray(arr, predicate) {
|
|
|
64
64
|
}
|
|
65
65
|
return [left, right];
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* {@link partitionArray} for a mutable array.
|
|
69
|
+
*/
|
|
70
|
+
function partition(arr, predicate) {
|
|
71
|
+
return partitionArray(arr, predicate);
|
|
72
|
+
}
|
|
67
73
|
/**
|
|
68
74
|
* Generate all permutations of the given array using Heap's algorithm (with its non-recursive variant).
|
|
69
75
|
* @param arr - The array to permute
|
|
@@ -90,23 +96,6 @@ function* allPermutations(arr) {
|
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Returns a tuple of two arrays, where the first one contains all elements for which the predicate returned true,
|
|
95
|
-
* and the second one contains all elements for which the predicate returned false.
|
|
96
|
-
*/
|
|
97
|
-
function partition(arr, predicate) {
|
|
98
|
-
const left = [];
|
|
99
|
-
const right = [];
|
|
100
|
-
for (const elem of arr) {
|
|
101
|
-
if (predicate(elem)) {
|
|
102
|
-
left.push(elem);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
right.push(elem);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return [left, right];
|
|
109
|
-
}
|
|
110
99
|
/**
|
|
111
100
|
* Generate all unique combinations of the array with the given size.
|
|
112
101
|
* In other words, given `[a,b,c]`, as well as `minSize=2` and `maxSize=2`, this will generate `[a,b]`, `[a,c]` and `[b,c]`,
|
package/util/hash.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable, streaming, non-cryptographic 64-bit hash (cyrb53), emitted as 16 hex chars. Feed it in
|
|
3
|
+
* chunks with {@link update} (so callers can hash data larger than a single string) and read the result
|
|
4
|
+
* with {@link digest}. Used for content/update detection where a stable, fast digest is enough; browser-safe
|
|
5
|
+
* (no node `crypto`, so it also works in the bundled/web build).
|
|
6
|
+
*
|
|
7
|
+
* cyrb53 is a public-domain hash by `bryc`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Hash53 {
|
|
10
|
+
private h1;
|
|
11
|
+
private h2;
|
|
12
|
+
update(str: string): this;
|
|
13
|
+
digest(): string;
|
|
14
|
+
}
|
package/util/hash.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Hash53 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Portable, streaming, non-cryptographic 64-bit hash (cyrb53), emitted as 16 hex chars. Feed it in
|
|
6
|
+
* chunks with {@link update} (so callers can hash data larger than a single string) and read the result
|
|
7
|
+
* with {@link digest}. Used for content/update detection where a stable, fast digest is enough; browser-safe
|
|
8
|
+
* (no node `crypto`, so it also works in the bundled/web build).
|
|
9
|
+
*
|
|
10
|
+
* cyrb53 is a public-domain hash by `bryc`.
|
|
11
|
+
*/
|
|
12
|
+
class Hash53 {
|
|
13
|
+
h1 = 0xdeadbeef;
|
|
14
|
+
h2 = 0x41c6ce57;
|
|
15
|
+
update(str) {
|
|
16
|
+
for (let i = 0; i < str.length; i++) {
|
|
17
|
+
const ch = str.charCodeAt(i);
|
|
18
|
+
this.h1 = Math.imul(this.h1 ^ ch, 2654435761);
|
|
19
|
+
this.h2 = Math.imul(this.h2 ^ ch, 1597334677);
|
|
20
|
+
}
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
digest() {
|
|
24
|
+
const h1 = Math.imul(this.h1 ^ (this.h1 >>> 16), 2246822507) ^ Math.imul(this.h2 ^ (this.h2 >>> 13), 3266489909);
|
|
25
|
+
const h2 = Math.imul(this.h2 ^ (this.h2 >>> 16), 2246822507) ^ Math.imul(this.h1 ^ (this.h1 >>> 13), 3266489909);
|
|
26
|
+
// `^` yields a *signed* int32, so coerce each half to unsigned (`>>> 0`) before hex, else a high bit prints a `-`
|
|
27
|
+
return (h2 >>> 0).toString(16).padStart(8, '0') + (h1 >>> 0).toString(16).padStart(8, '0');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Hash53 = Hash53;
|
|
31
|
+
//# sourceMappingURL=hash.js.map
|
package/util/mermaid/dfg.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface MermaidGraph {
|
|
|
19
19
|
rootGraph: DataflowGraph;
|
|
20
20
|
/** if given, the dataflow graph will only focus on the "important" parts */
|
|
21
21
|
simplified?: boolean;
|
|
22
|
+
/** show the edge-free base-R qualification (`acf` as `stats::acf`); `false` when the signature database is disabled */
|
|
23
|
+
qualifyBaseR?: boolean;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* Translates a vertex tag to the corresponding mermaid node brackets.
|
|
@@ -42,6 +44,8 @@ export interface MermaidGraphConfiguration {
|
|
|
42
44
|
presentEdges?: Set<string>;
|
|
43
45
|
simplified?: boolean;
|
|
44
46
|
includeOnlyIds?: ReadonlySet<NodeId>;
|
|
47
|
+
/** show the edge-free base-R package qualification (`acf` as `stats::acf`); pass `false` when the signature database is disabled. Default `true`. */
|
|
48
|
+
qualifyBaseR?: boolean;
|
|
45
49
|
}
|
|
46
50
|
export interface LabeledDiffGraph {
|
|
47
51
|
label: string;
|
|
@@ -70,7 +74,7 @@ export declare const DataflowMermaid: {
|
|
|
70
74
|
/**
|
|
71
75
|
* This is a simplified version of {@link DataflowMermaid.convert}
|
|
72
76
|
*/
|
|
73
|
-
readonly raw: (this: void, graph: DataflowGraph | DataflowInformation, includeEnvironments?: boolean, mark?: ReadonlySet<NodeId>, simplified?: boolean) => string;
|
|
77
|
+
readonly raw: (this: void, graph: DataflowGraph | DataflowInformation, includeEnvironments?: boolean, mark?: ReadonlySet<NodeId>, simplified?: boolean, qualifyBaseR?: boolean) => string;
|
|
74
78
|
/**
|
|
75
79
|
* Converts a dataflow graph to a mermaid url that visualizes the graph.
|
|
76
80
|
* This is basically a combination of {@link DataflowMermaid.raw} and {@link Mermaid.codeToUrl}.
|
|
@@ -78,6 +82,7 @@ export declare const DataflowMermaid: {
|
|
|
78
82
|
* @param includeEnvironments - whether to include the environment content in the output
|
|
79
83
|
* @param mark - which vertices to highlight in the visualization
|
|
80
84
|
* @param simplified - whether to show a simplified use of the graph with fewer details on the vertices and edges
|
|
85
|
+
* @param qualifyBaseR - show the edge-free base-R qualification (`stats::acf`); `false` when the signature database is disabled
|
|
81
86
|
*/
|
|
82
|
-
readonly url: (this: void, graph: DataflowGraph | DataflowInformation, includeEnvironments?: boolean, mark?: ReadonlySet<NodeId>, simplified?: boolean) => string;
|
|
87
|
+
readonly url: (this: void, graph: DataflowGraph | DataflowInformation, includeEnvironments?: boolean, mark?: ReadonlySet<NodeId>, simplified?: boolean, qualifyBaseR?: boolean) => string;
|
|
83
88
|
};
|
package/util/mermaid/dfg.js
CHANGED
|
@@ -12,6 +12,7 @@ const identifier_1 = require("../../dataflow/environments/identifier");
|
|
|
12
12
|
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
13
13
|
const edge_1 = require("../../dataflow/graph/edge");
|
|
14
14
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
15
|
+
const dfg_get_origin_1 = require("../../dataflow/origin/dfg-get-origin");
|
|
15
16
|
const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
|
|
16
17
|
const info_1 = require("./info");
|
|
17
18
|
const range_1 = require("../range");
|
|
@@ -40,7 +41,8 @@ function subflowToMermaid(nodeId, subflow, mermaid, idPrefix = '') {
|
|
|
40
41
|
includeEnvironments: mermaid.includeEnvironments,
|
|
41
42
|
mark: mermaid.mark,
|
|
42
43
|
prefix: null,
|
|
43
|
-
simplified: mermaid.simplified
|
|
44
|
+
simplified: mermaid.simplified,
|
|
45
|
+
qualifyBaseR: mermaid.qualifyBaseR
|
|
44
46
|
});
|
|
45
47
|
mermaid.nodeLines.push(...subgraph.nodeLines);
|
|
46
48
|
mermaid.edgeLines.push(...subgraph.edgeLines);
|
|
@@ -85,11 +87,24 @@ function displayFunctionArgMapping(argMapping) {
|
|
|
85
87
|
for (const arg of argMapping) {
|
|
86
88
|
result.push(mermaid_1.Mermaid.escape(printArg(arg)));
|
|
87
89
|
}
|
|
88
|
-
return result.length === 0 ? '' : `\n (${result.join(', ')})`;
|
|
90
|
+
return result.length === 0 ? '' : `\n arg: (${result.join(', ')})`;
|
|
89
91
|
}
|
|
90
92
|
function encodeEdge(from, to, types) {
|
|
91
93
|
return `${from}->${to}["${Array.from(types).join(':')}"]`;
|
|
92
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Renders the (mermaid-escaped) node name with only the *lexeme* -- what the source actually wrote -- in bold.
|
|
97
|
+
* When the displayed name was extended by package qualification (e.g. the code wrote `acf` but we show
|
|
98
|
+
* `stats::acf`), the added `stats::` prefix stays non-bold so it is visually distinct from the written token. A
|
|
99
|
+
* namespace written in the source (`stats::acf` verbatim) is part of the lexeme and is therefore bold as a whole.
|
|
100
|
+
*/
|
|
101
|
+
function boldLexeme(lexeme, display) {
|
|
102
|
+
if (display !== lexeme && display.endsWith(lexeme)) {
|
|
103
|
+
const addedPrefix = display.slice(0, display.length - lexeme.length); // the qualification we added, e.g. `stats::`
|
|
104
|
+
return `${mermaid_1.Mermaid.escape(addedPrefix)}**${mermaid_1.Mermaid.escape(lexeme)}**`;
|
|
105
|
+
}
|
|
106
|
+
return `**${mermaid_1.Mermaid.escape(display)}**`;
|
|
107
|
+
}
|
|
93
108
|
/**
|
|
94
109
|
* Translates a vertex tag to the corresponding mermaid node brackets.
|
|
95
110
|
*/
|
|
@@ -135,11 +150,27 @@ function printEnvironmentToLines(env) {
|
|
|
135
150
|
}
|
|
136
151
|
return lines;
|
|
137
152
|
}
|
|
153
|
+
/** label a built-in node: a package export shows as `pkg::fn` (`built-in:stats:acf` becomes `stats::acf`), everything else as its bare name */
|
|
154
|
+
function builtInDisplayName(builtInId) {
|
|
155
|
+
const pkgFn = node_id_1.NodeId.toPkgFn(builtInId);
|
|
156
|
+
return pkgFn ? `${pkgFn[0]}::${pkgFn[1]}` : String(builtInId).replace('built-in:', '');
|
|
157
|
+
}
|
|
138
158
|
function vertexToMermaid(info, mermaid, id, idPrefix, mark, includeOnlyIds) {
|
|
139
159
|
const fCall = info.tag === vertex_1.VertexType.FunctionCall;
|
|
140
160
|
const { open, close } = mermaidNodeBrackets(info.tag);
|
|
141
161
|
const origId = id;
|
|
142
162
|
id = mermaid_1.Mermaid.escapeId(id);
|
|
163
|
+
// a vertex with a built-in id (e.g. a base-R export attached via `linkBaseR`) has no AST node, so it would
|
|
164
|
+
// otherwise render as a bogus `?? *??-??* (id: built-in:...)` box; draw it as the gray Built-In placeholder
|
|
165
|
+
// instead -- the same node an edge to it produces, which also dedups the two renderings
|
|
166
|
+
if (node_id_1.NodeId.isBuiltIn(origId)) {
|
|
167
|
+
if (!mermaid.presentVertices.has(id)) {
|
|
168
|
+
mermaid.nodeLines.push(` ${idPrefix}${id}["\`Built-In:\n${mermaid_1.Mermaid.escape(builtInDisplayName(origId))}\`"]`);
|
|
169
|
+
mermaid.nodeLines.push(` style ${idPrefix}${id} stroke:gray,fill:gray,stroke-width:2px,opacity:.8;`);
|
|
170
|
+
mermaid.presentVertices.add(id);
|
|
171
|
+
}
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
143
174
|
if (info.environment && mermaid.includeEnvironments) {
|
|
144
175
|
if (info.environment.level > 0 || info.environment.current.memory.size !== 0) {
|
|
145
176
|
mermaid.nodeLines.push(` %% Environment of ${id} [level: ${info.environment.level}]:`, printEnvironmentToLines(info.environment.current).map(x => ` %% ${x}`).join('\n'));
|
|
@@ -147,18 +178,26 @@ function vertexToMermaid(info, mermaid, id, idPrefix, mark, includeOnlyIds) {
|
|
|
147
178
|
}
|
|
148
179
|
const node = mermaid.rootGraph.idMap?.get(info.id);
|
|
149
180
|
const lexeme = node?.lexeme ?? (node?.type === type_1.RType.ExpressionList ? node?.grouping?.[0]?.lexeme : '') ?? '??';
|
|
181
|
+
let display = lexeme;
|
|
182
|
+
if (fCall && (0, vertex_1.isFunctionCallVertex)(info)) {
|
|
183
|
+
const q = identifier_1.Identifier.toQualified((0, dfg_get_origin_1.getOriginInDfg)(mermaid.rootGraph, origId), mermaid.qualifyBaseR === false ? undefined : info.name);
|
|
184
|
+
const qs = q !== undefined ? identifier_1.Identifier.toString(q) : undefined;
|
|
185
|
+
if (qs !== undefined && qs !== lexeme) {
|
|
186
|
+
display = qs;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
150
189
|
if (mermaid.simplified) {
|
|
151
190
|
const location = node?.location?.[0] ? ` (L. ${node?.location?.[0]})` : '';
|
|
152
|
-
const escapedName =
|
|
191
|
+
const escapedName = (node ? boldLexeme(lexeme, display) : '**??**') + location + (node ? `\n*${node.type}*` : '');
|
|
153
192
|
mermaid.nodeLines.push(` ${idPrefix}${id}${open}"\`${escapedName}\`"${close}`);
|
|
154
193
|
}
|
|
155
194
|
else {
|
|
156
|
-
const escapedName = mermaid_1.Mermaid.escape(
|
|
195
|
+
const escapedName = node ? `*${mermaid_1.Mermaid.escape(`[${node.type}]`)}* ${boldLexeme(lexeme, display)}` : '??';
|
|
157
196
|
const deps = info.cds ? ', :may:' + info.cds.map(c => c.id + (c.when ? '+' : '-')).join(',') : '';
|
|
158
197
|
const lnks = info.link?.origin ? ', :links:' + info.link.origin.join(',') : '';
|
|
159
|
-
const sources = info.source ? ',
|
|
198
|
+
const sources = info.source ? ', v: ' + JSON.stringify(info.source) : '';
|
|
160
199
|
const n = node?.info.fullRange ?? node?.location ?? (node?.type === type_1.RType.ExpressionList ? node?.grouping?.[0].location : undefined);
|
|
161
|
-
mermaid.nodeLines.push(` ${idPrefix}${id}${open}"\`${escapedName}
|
|
200
|
+
mermaid.nodeLines.push(` ${idPrefix}${id}${open}"\`${escapedName}\n *${range_1.SourceRange.format(n)}* (**id: ${id}**${deps}${lnks}${sources})${fCall ? displayFunctionArgMapping(info.args) : '' + (info.tag === vertex_1.VertexType.FunctionDefinition && info.mode && info.mode.length > 0 ? mermaid_1.Mermaid.escape(JSON.stringify(info.mode)) : '')}\`"${close}`);
|
|
162
201
|
}
|
|
163
202
|
if (mark?.has(id)) {
|
|
164
203
|
mermaid.nodeLines.push(` style ${idPrefix}${id} ${mermaid.markStyle.vertex} `);
|
|
@@ -198,7 +237,7 @@ function vertexToMermaid(info, mermaid, id, idPrefix, mark, includeOnlyIds) {
|
|
|
198
237
|
if (node_id_1.NodeId.isBuiltIn(target)) {
|
|
199
238
|
mermaid.edgeLines.push(` linkStyle ${mermaid.presentEdges.size - 1} stroke:gray;`);
|
|
200
239
|
if (!mermaid.presentVertices.has(target)) {
|
|
201
|
-
mermaid.nodeLines.push(` ${idPrefix}${target}["\`Built-In:\n${mermaid_1.Mermaid.escape(
|
|
240
|
+
mermaid.nodeLines.push(` ${idPrefix}${target}["\`Built-In:\n${mermaid_1.Mermaid.escape(builtInDisplayName(originalTarget))}\`"]`);
|
|
202
241
|
mermaid.nodeLines.push(` style ${idPrefix}${target} stroke:gray,fill:gray,stroke-width:2px,opacity:.8;`);
|
|
203
242
|
mermaid.presentVertices.add(target);
|
|
204
243
|
}
|
|
@@ -207,8 +246,8 @@ function vertexToMermaid(info, mermaid, id, idPrefix, mark, includeOnlyIds) {
|
|
|
207
246
|
}
|
|
208
247
|
}
|
|
209
248
|
// make the passing of root ids more performant again
|
|
210
|
-
function graphToMermaidGraph(rootIds, { simplified, graph, prefix = 'flowchart BT', idPrefix = '', includeEnvironments = !simplified, mark, rootGraph, presentEdges = new Set(), markStyle = info_1.MermaidDefaultMarkStyle, includeOnlyIds }) {
|
|
211
|
-
const mermaid = { nodeLines: prefix === null ? [] : [prefix], edgeLines: [], presentEdges, presentVertices: new Set(), mark, rootGraph: rootGraph ?? graph, includeEnvironments, markStyle, simplified };
|
|
249
|
+
function graphToMermaidGraph(rootIds, { simplified, graph, prefix = 'flowchart BT', idPrefix = '', includeEnvironments = !simplified, mark, rootGraph, presentEdges = new Set(), markStyle = info_1.MermaidDefaultMarkStyle, includeOnlyIds, qualifyBaseR = true }) {
|
|
250
|
+
const mermaid = { nodeLines: prefix === null ? [] : [prefix], edgeLines: [], presentEdges, presentVertices: new Set(), mark, rootGraph: rootGraph ?? graph, includeEnvironments, markStyle, simplified, qualifyBaseR };
|
|
212
251
|
for (const [id, info] of graph.vertices(true)) {
|
|
213
252
|
if (rootIds.has(id)) {
|
|
214
253
|
vertexToMermaid(info, mermaid, id, idPrefix, mark, includeOnlyIds);
|
|
@@ -245,9 +284,9 @@ exports.DataflowMermaid = {
|
|
|
245
284
|
/**
|
|
246
285
|
* This is a simplified version of {@link DataflowMermaid.convert}
|
|
247
286
|
*/
|
|
248
|
-
raw(graph, includeEnvironments, mark, simplified = false) {
|
|
287
|
+
raw(graph, includeEnvironments, mark, simplified = false, qualifyBaseR = true) {
|
|
249
288
|
graph = info_2.DataflowInformation.is(graph) ? graph.graph : graph;
|
|
250
|
-
return exports.DataflowMermaid.convert({ graph, includeEnvironments, mark, simplified }).string;
|
|
289
|
+
return exports.DataflowMermaid.convert({ graph, includeEnvironments, mark, simplified, qualifyBaseR }).string;
|
|
251
290
|
},
|
|
252
291
|
/**
|
|
253
292
|
* Converts a dataflow graph to a mermaid url that visualizes the graph.
|
|
@@ -256,9 +295,10 @@ exports.DataflowMermaid = {
|
|
|
256
295
|
* @param includeEnvironments - whether to include the environment content in the output
|
|
257
296
|
* @param mark - which vertices to highlight in the visualization
|
|
258
297
|
* @param simplified - whether to show a simplified use of the graph with fewer details on the vertices and edges
|
|
298
|
+
* @param qualifyBaseR - show the edge-free base-R qualification (`stats::acf`); `false` when the signature database is disabled
|
|
259
299
|
*/
|
|
260
|
-
url(graph, includeEnvironments, mark, simplified = false) {
|
|
261
|
-
return mermaid_1.Mermaid.codeToUrl(exports.DataflowMermaid.raw(graph, includeEnvironments, mark, simplified));
|
|
300
|
+
url(graph, includeEnvironments, mark, simplified = false, qualifyBaseR = true) {
|
|
301
|
+
return mermaid_1.Mermaid.codeToUrl(exports.DataflowMermaid.raw(graph, includeEnvironments, mark, simplified, qualifyBaseR));
|
|
262
302
|
}
|
|
263
303
|
};
|
|
264
304
|
//# sourceMappingURL=dfg.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base packages available at the assumed R version (all of them if omitted). A package counts as
|
|
3
|
+
* available when that R release lies within the range it was part of core; e.g. `parallel` (added in R
|
|
4
|
+
* 2.14.0) is absent for an assumed R 2.10, and long-merged packages like `ctest` are absent for modern R.
|
|
5
|
+
*
|
|
6
|
+
* The newest release is served from the precomputed {@link RBasePackageStore.current} array.
|
|
7
|
+
* Every other version is computed once and memoized, so this never recomputes on repeated calls.
|
|
8
|
+
*/
|
|
9
|
+
export declare function baseRPackages(rVersion?: string): readonly string[];
|
|
10
|
+
/**
|
|
11
|
+
* The base-R package that exports `name` (e.g. `sd` yields `stats`, `plot` yields `base`), or `undefined`.
|
|
12
|
+
* Backed by the bundle-time store, so it needs no loaded database and no runtime resolution: the
|
|
13
|
+
* export-to-package index is inverted from {@link RBasePackageStore.exportsByPackage} once on first use.
|
|
14
|
+
* Base primitives/internals and base data constants (`is.na`, `.Machine`, ...) are not in the sigdb
|
|
15
|
+
* export list, so they are answered from {@link RBasePrimitives} and owned by `base`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function baseRExportOwner(name: string): string | undefined;
|
|
18
|
+
/** whether `name` is an R-core / base package at the assumed R version (see {@link baseRPackages}). */
|
|
19
|
+
export declare function isBaseRPackage(name: string, rVersion?: string): boolean;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.baseRPackages = baseRPackages;
|
|
4
|
+
exports.baseRExportOwner = baseRExportOwner;
|
|
5
|
+
exports.isBaseRPackage = isBaseRPackage;
|
|
6
|
+
const r_base_packages_generated_1 = require("../data/r-base-packages.generated");
|
|
7
|
+
const r_base_primitives_generated_1 = require("../data/r-base-primitives.generated");
|
|
8
|
+
const r_version_1 = require("./r-version");
|
|
9
|
+
/** clamp `rVersion` to the newest R release the store knows about (so a future R version stays answerable) */
|
|
10
|
+
function effective(rVersion) {
|
|
11
|
+
return r_version_1.RVersion.compare(rVersion, r_base_packages_generated_1.RBasePackageStore.newestRVersion) > 0 ? r_base_packages_generated_1.RBasePackageStore.newestRVersion : rVersion;
|
|
12
|
+
}
|
|
13
|
+
/** memoized results per assumed R version, so the list is computed at most once per version (never per lookup) */
|
|
14
|
+
const cache = new Map();
|
|
15
|
+
/**
|
|
16
|
+
* The base packages available at the assumed R version (all of them if omitted). A package counts as
|
|
17
|
+
* available when that R release lies within the range it was part of core; e.g. `parallel` (added in R
|
|
18
|
+
* 2.14.0) is absent for an assumed R 2.10, and long-merged packages like `ctest` are absent for modern R.
|
|
19
|
+
*
|
|
20
|
+
* The newest release is served from the precomputed {@link RBasePackageStore.current} array.
|
|
21
|
+
* Every other version is computed once and memoized, so this never recomputes on repeated calls.
|
|
22
|
+
*/
|
|
23
|
+
function baseRPackages(rVersion) {
|
|
24
|
+
// fast path: no version, or the exact newest-release string, avoids the (regex-based) version compare entirely
|
|
25
|
+
if (rVersion === undefined || rVersion === r_base_packages_generated_1.RBasePackageStore.newestRVersion || r_version_1.RVersion.compare(rVersion, r_base_packages_generated_1.RBasePackageStore.newestRVersion) >= 0) {
|
|
26
|
+
return r_base_packages_generated_1.RBasePackageStore.current; // the current base set, precomputed at bundle time
|
|
27
|
+
}
|
|
28
|
+
const cached = cache.get(rVersion);
|
|
29
|
+
if (cached !== undefined) {
|
|
30
|
+
return cached;
|
|
31
|
+
}
|
|
32
|
+
const eff = effective(rVersion);
|
|
33
|
+
const result = Object.entries(r_base_packages_generated_1.RBasePackageStore.packages)
|
|
34
|
+
.filter(([, [first, last]]) => r_version_1.RVersion.compare(first, eff) <= 0 && r_version_1.RVersion.compare(last, eff) >= 0)
|
|
35
|
+
.map(([name]) => name);
|
|
36
|
+
cache.set(rVersion, result);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
/** the base export to owning-package map, materialised once from the grouped store (never per lookup) */
|
|
40
|
+
let exportOwners;
|
|
41
|
+
/**
|
|
42
|
+
* The base-R package that exports `name` (e.g. `sd` yields `stats`, `plot` yields `base`), or `undefined`.
|
|
43
|
+
* Backed by the bundle-time store, so it needs no loaded database and no runtime resolution: the
|
|
44
|
+
* export-to-package index is inverted from {@link RBasePackageStore.exportsByPackage} once on first use.
|
|
45
|
+
* Base primitives/internals and base data constants (`is.na`, `.Machine`, ...) are not in the sigdb
|
|
46
|
+
* export list, so they are answered from {@link RBasePrimitives} and owned by `base`.
|
|
47
|
+
*/
|
|
48
|
+
function baseRExportOwner(name) {
|
|
49
|
+
if (exportOwners === undefined) {
|
|
50
|
+
exportOwners = new Map();
|
|
51
|
+
for (const [pkg, names] of Object.entries(r_base_packages_generated_1.RBasePackageStore.exportsByPackage)) {
|
|
52
|
+
for (const exported of names) {
|
|
53
|
+
exportOwners.set(exported, pkg);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return exportOwners.get(name) ?? (r_base_primitives_generated_1.RBasePrimitives.has(name) ? 'base' : undefined);
|
|
58
|
+
}
|
|
59
|
+
/** whether `name` is an R-core / base package at the assumed R version (see {@link baseRPackages}). */
|
|
60
|
+
function isBaseRPackage(name, rVersion) {
|
|
61
|
+
// the store is `as const`, so it carries no string index signature; read it as a record for the dynamic lookup
|
|
62
|
+
const range = r_base_packages_generated_1.RBasePackageStore.packages[name];
|
|
63
|
+
if (range === undefined) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (rVersion === undefined) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
const eff = effective(rVersion);
|
|
70
|
+
return r_version_1.RVersion.compare(range[0], eff) <= 0 && r_version_1.RVersion.compare(range[1], eff) >= 0;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=r-base-packages.js.map
|
package/util/r-license.js
CHANGED
|
@@ -92,14 +92,6 @@ function consumeLicenseName(info) {
|
|
|
92
92
|
}
|
|
93
93
|
return { ...newInfo, element: licenseName?.trim() ?? '' };
|
|
94
94
|
}
|
|
95
|
-
function makeRange(rangeStr) {
|
|
96
|
-
try {
|
|
97
|
-
return (0, r_version_1.parseRRange)(rangeStr);
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
95
|
function parseLicenseElement(info) {
|
|
104
96
|
const licenseName = consumeLicenseName(info);
|
|
105
97
|
info = skipWhitespace(licenseName);
|
|
@@ -113,7 +105,7 @@ function parseLicenseElement(info) {
|
|
|
113
105
|
info = skipWhitespace(openParen);
|
|
114
106
|
// consume until closing parenthesis
|
|
115
107
|
const versionStr = consumeUntilString(info, ')');
|
|
116
|
-
versionConstraint =
|
|
108
|
+
versionConstraint = r_version_1.RRange.parse(versionStr.element);
|
|
117
109
|
const closeParen = consumeString(versionStr, ')');
|
|
118
110
|
(0, assert_1.guard)(closeParen.element, `Expected ), but found ${versionStr.remInput[0]} at position ${versionStr.position}`);
|
|
119
111
|
info = skipWhitespace(closeParen);
|
|
@@ -121,7 +113,7 @@ function parseLicenseElement(info) {
|
|
|
121
113
|
else {
|
|
122
114
|
// consume until whitespace or special character
|
|
123
115
|
const versionStr = consumeRegexp(info, /^[\d<>=!~.\s]+/);
|
|
124
|
-
versionConstraint = versionStr.element ?
|
|
116
|
+
versionConstraint = versionStr.element ? r_version_1.RRange.parse(versionStr.element) : undefined;
|
|
125
117
|
info = skipWhitespace(versionStr);
|
|
126
118
|
}
|
|
127
119
|
}
|
package/util/r-version.d.ts
CHANGED
|
@@ -1,19 +1,49 @@
|
|
|
1
1
|
import { Range, SemVer } from 'semver';
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
* In contrast to just using `new SemVer(version)`, this function also tries to
|
|
5
|
-
* normalize R's much free-er versioning scheme into valid SemVer versions.
|
|
6
|
-
* You can always access the original version string via the `str` property on the returned object.
|
|
7
|
-
*/
|
|
8
|
-
export declare function parseRVersion(version: string): SemVer & {
|
|
2
|
+
/** A parsed R package version: a comparable {@link SemVer} that also keeps its original string as `.str`. */
|
|
3
|
+
export type RVersion = SemVer & {
|
|
9
4
|
str: string;
|
|
10
5
|
};
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
/** Helpers for R package versions (`1.2-3` style), which are freer than SemVer. */
|
|
7
|
+
export declare const RVersion: {
|
|
8
|
+
/**
|
|
9
|
+
* Parse an R version string into a {@link SemVer}, normalizing R's freer scheme (e.g. `0.4-9`). Unlike
|
|
10
|
+
* `new SemVer(version)` this coerces where needed; the original string is available via `.str`. Returns
|
|
11
|
+
* undefined (never throws) when the string cannot be coerced to a version at all.
|
|
12
|
+
* @see {@link RVersion.parseOrZero}
|
|
13
|
+
*/
|
|
14
|
+
readonly parse: (this: void, version: string) => RVersion | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Compare two R version strings following R's `numeric_version` scheme: split on `.` and `-`, compare
|
|
17
|
+
* numerically, shorter versions padded with zeros (`0.4-9 < 0.4.10 < 1.0`). Negative/zero/positive for
|
|
18
|
+
* `a` less than/equal to/greater than `b`.
|
|
19
|
+
*/
|
|
20
|
+
readonly compare: (this: void, a: string, b: string) => number;
|
|
21
|
+
/**
|
|
22
|
+
* Like {@link parse} but never undefined: a truly un-coercible version sorts as `0.0.0` while keeping its
|
|
23
|
+
* original string as `.str`, so it stays usable as a sort key.
|
|
24
|
+
* @see {@link RVersion.parse}
|
|
25
|
+
*/
|
|
26
|
+
readonly parseOrZero: (this: void, version: string) => RVersion;
|
|
27
|
+
/** The highest of some version strings by R's `numeric_version` order (`0.9.0 < 0.10.0`); undefined if none. */
|
|
28
|
+
readonly highest: (this: void, versions: Iterable<string>) => string | undefined;
|
|
29
|
+
};
|
|
30
|
+
/** Helpers for R package version ranges (DESCRIPTION constraints like `>= 0.4-9`). */
|
|
31
|
+
export declare const RRange: {
|
|
32
|
+
/**
|
|
33
|
+
* Parse an R version range string into a {@link Range}, normalizing R's freer scheme. The original range
|
|
34
|
+
* string is available via `.str`.
|
|
35
|
+
*
|
|
36
|
+
* This never throws: an unparseable constraint (e.g. `>= abc`, or a git/URL "version" from a lockfile) yields
|
|
37
|
+
* `undefined` rather than aborting the caller, so a malformed constraint is *detectable* and simply contributes
|
|
38
|
+
* no version bound. Parsing is attempted first verbatim, then after normalizing R's scheme to SemVer.
|
|
39
|
+
*/
|
|
40
|
+
readonly parse: (this: void, range: string) => (Range & {
|
|
41
|
+
str: string;
|
|
42
|
+
}) | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Whether an R version string satisfies a range constraint, normalizing R's freer scheme on both sides.
|
|
45
|
+
* `range` may be a parsed {@link Range} or a raw constraint string. Returns `false` if either is unparseable
|
|
46
|
+
* (never throws), so a malformed version/constraint simply does not match.
|
|
47
|
+
*/
|
|
48
|
+
readonly satisfies: (this: void, version: string, range: Range | string) => boolean;
|
|
19
49
|
};
|