@eagleoutice/flowr 2.17.2 → 2.17.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -9
- package/cli/repl/commands/repl-signature.d.ts +1 -1
- package/cli/repl/completion.d.ts +23 -0
- package/cli/repl/completion.js +9 -0
- package/cli/repl/core.d.ts +0 -23
- package/cli/repl/core.js +0 -5
- package/cli/repl/parser/slice-query-parser.d.ts +1 -1
- package/cli/repl/parser/slice-query-parser.js +3 -3
- package/data/r-reexports.generated.d.ts +4 -0
- package/data/r-reexports.generated.js +43 -0
- package/dataflow/environments/built-in-props.d.ts +8 -1
- package/dataflow/environments/built-in-props.js +9 -1
- package/dataflow/environments/built-in.d.ts +5 -3
- package/dataflow/environments/built-in.js +5 -4
- package/dataflow/environments/default-builtin-config.d.ts +21 -3
- package/dataflow/environments/default-builtin-config.js +49 -47
- package/dataflow/eval/resolve/resolve-argument.js +11 -6
- package/dataflow/eval/resolve/resolve-numbers.d.ts +1 -178
- package/dataflow/eval/resolve/resolve-numbers.js +2 -13
- package/dataflow/eval/resolve/resolve-strings.d.ts +1 -93
- package/dataflow/eval/resolve/resolve-strings.js +2 -17
- package/dataflow/eval/resolve/resolve-working-directory.js +3 -4
- package/dataflow/extractor.js +44 -26
- package/dataflow/graph/df-helper.d.ts +10 -1
- package/dataflow/graph/df-helper.js +27 -3
- package/dataflow/internal/linker.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +8 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +44 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +3 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +9 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +0 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +11 -21
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +13 -3
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +15 -5
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +1 -24
- package/dataflow/internal/process/functions/call/known-call-handling.js +8 -34
- package/dataflow/internal/process/functions/call/nse-kind.d.ts +24 -0
- package/dataflow/internal/process/functions/call/nse-kind.js +30 -0
- package/documentation/wiki-dataflow-graph.js +7 -2
- package/documentation/wiki-query.js +3 -2
- package/linter/rules/absolute-path.js +5 -5
- package/linter/rules/cmd-check/dependency-declaration.js +2 -2
- package/linter/rules/cmd-check/package-runtime.js +2 -2
- package/linter/rules/deprecated-functions.js +2 -2
- package/linter/rules/file-path-validity.js +5 -5
- package/linter/rules/function-finder-util.js +2 -2
- package/linter/rules/overwritten-file.js +2 -4
- package/linter/rules/secret-exfiltration.d.ts +3 -2
- package/linter/rules/secret-exfiltration.js +8 -3
- package/linter/rules/unused-import.js +20 -6
- package/package.json +1 -1
- package/project/cache/flowr-analyzer-controlflow-cache.d.ts +0 -6
- package/project/cache/flowr-analyzer-controlflow-cache.js +7 -27
- package/project/context/flowr-analyzer-context.d.ts +2 -2
- package/project/context/flowr-analyzer-context.js +2 -2
- package/project/context/flowr-analyzer-files-context.d.ts +8 -0
- package/project/context/flowr-analyzer-files-context.js +51 -6
- package/project/flowr-analyzer.d.ts +0 -9
- package/project/flowr-analyzer.js +7 -28
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +5 -3
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +70 -163
- package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +2 -3
- package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -3
- package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.js +3 -3
- 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 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +1 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +25 -3
- package/project/plugins/package-version-plugins/package.js +1 -1
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -3
- package/project/sigdb/build.js +7 -6
- package/project/sigdb/decode.d.ts +2 -0
- package/project/sigdb/decode.js +9 -3
- package/project/sigdb/schema.d.ts +8 -3
- package/queries/catalog/absint-query/absint-query-format.d.ts +1 -1
- package/queries/catalog/config-query/config-query-format.d.ts +1 -1
- package/queries/catalog/config-query/config-query-format.js +4 -4
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +6 -5
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +1 -4
- package/queries/catalog/dependencies-query/dependencies-query-format.js +11 -11
- package/queries/catalog/dependencies-query/dependency-values.d.ts +9 -0
- package/queries/catalog/dependencies-query/dependency-values.js +13 -0
- package/queries/catalog/dependencies-query/function-info/remote-functions.js +2 -2
- package/queries/catalog/dependencies-query/function-info/write-functions.js +8 -7
- package/queries/catalog/dependencies-query/implicit-echo.js +2 -1
- package/queries/catalog/dependencies-query/plot-description.d.ts +1 -1
- package/queries/catalog/dependencies-query/plot-description.js +2 -2
- package/queries/catalog/dice-query/dice-query-format.d.ts +1 -1
- package/queries/catalog/files-query/files-query-format.d.ts +1 -1
- package/queries/catalog/linter-query/linter-query-format.d.ts +2 -2
- package/queries/catalog/linter-query/linter-query-format.js +13 -9
- package/queries/catalog/signature-query/signature-query-executor.d.ts +1 -1
- package/queries/catalog/taint-query/taint-query-format.d.ts +1 -1
- package/queries/query-function-filter.d.ts +1 -1
- package/queries/query.d.ts +2 -2
- package/r-bridge/init.js +1 -1
- package/search/flowr-search-filters.js +2 -2
- package/search/search-executor/search-generators.d.ts +0 -1
- package/search/search-executor/search-generators.js +5 -6
- package/search/search-logger.d.ts +1 -0
- package/search/search-logger.js +6 -0
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PrintingOptions = void 0;
|
|
4
|
+
exports.isAssumedWrite = isAssumedWrite;
|
|
4
5
|
exports.hidesBody = hidesBody;
|
|
6
|
+
exports.reachesBuiltInLate = reachesBuiltInLate;
|
|
5
7
|
exports.readsAllAmbientState = readsAllAmbientState;
|
|
6
8
|
exports.ambientWritesOfAssignment = ambientWritesOfAssignment;
|
|
7
9
|
exports.ambientWritesOfRelease = ambientWritesOfRelease;
|
|
@@ -50,6 +52,7 @@ const assert_1 = require("../../../../../../util/assert");
|
|
|
50
52
|
const resolve_helper_1 = require("../../../../../environments/resolve-helper");
|
|
51
53
|
const r_access_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
|
|
52
54
|
const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
55
|
+
const convert_values_1 = require("../../../../../../r-bridge/lang-4.x/convert-values");
|
|
53
56
|
const r_if_then_else_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-if-then-else");
|
|
54
57
|
const arrays_1 = require("../../../../../../util/collections/arrays");
|
|
55
58
|
const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
|
|
@@ -60,6 +63,10 @@ const Accumulating = new Set([
|
|
|
60
63
|
...DeviceStates, ambient_state_name_1.AmbientStateName.palette, ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.unknownOption,
|
|
61
64
|
ambient_state_name_1.AmbientStateName.warnsAsErrors, ambient_state_name_1.AmbientStateName.files, ambient_state_name_1.AmbientStateName.rngKind, ambient_state_name_1.AmbientStateName.finalizers, ...ambient_state_name_1.KeyedAccumulators
|
|
62
65
|
]);
|
|
66
|
+
/** Whether `definition` is a write only assumed of a body flowR cannot see, like `#rng` for `function(f) f()`, other than the one of `set.seed(1)`. */
|
|
67
|
+
function isAssumedWrite(definition) {
|
|
68
|
+
return definition.assumed === true;
|
|
69
|
+
}
|
|
63
70
|
/** a write that may not happen: it reads what was there, so it can still replace the state and keep everything before reachable */
|
|
64
71
|
function maybe(name) {
|
|
65
72
|
return { name, mode: 'maybe' };
|
|
@@ -72,13 +79,21 @@ function optionReads(keys) {
|
|
|
72
79
|
function hidesBody(definition) {
|
|
73
80
|
return node_id_1.NodeId.isBuiltIn(definition.nodeId) || (0, identifier_1.isReferenceType)(definition.type, identifier_1.ReferenceType.Parameter | identifier_1.ReferenceType.Argument);
|
|
74
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Whether the call `call` of a function body reaches a built-in only once linked where the function is called, through a parameter
|
|
84
|
+
* or a name the body cannot resolve. Through a variable (`p <- par; p(...)`) the body applied the built-in already, see {@link applyAmbientStateOfCalledBuiltIns}.
|
|
85
|
+
*/
|
|
86
|
+
function reachesBuiltInLate(call) {
|
|
87
|
+
const definitions = call.environment === undefined ? [] : resolve_helper_1.Resolve.byNameAndType(call.name, call.environment, identifier_1.ReferenceType.Function) ?? [];
|
|
88
|
+
return definitions.length === 0 || definitions.some(hidesBody);
|
|
89
|
+
}
|
|
75
90
|
/** A call into code flowR cannot see may read any option, draw random numbers (with `draws` advancing the generator), and with `graphics` draw on the device. */
|
|
76
91
|
function readsAllAmbientState(res, rootId, data, graphics, draws = true) {
|
|
77
92
|
const reads = [ambient_state_name_1.AmbientStateName.allOptions, ambient_state_name_1.AmbientStateName.rng, ambient_state_name_1.AmbientStateName.allOf(ambient_state_name_1.KeyedState.Env)];
|
|
78
93
|
if (graphics) {
|
|
79
94
|
reads.push(ambient_state_name_1.AmbientStateName.graphics, ambient_state_name_1.AmbientStateName.palette);
|
|
80
95
|
}
|
|
81
|
-
return withAccess(res, rootId, data, reads, draws ? [maybe(ambient_state_name_1.AmbientStateName.rng)] : []);
|
|
96
|
+
return withAccess(res, rootId, data, reads, draws ? [{ ...maybe(ambient_state_name_1.AmbientStateName.rng), assumed: true }] : []);
|
|
82
97
|
}
|
|
83
98
|
/** Adds the reads and writes of the ambient state to what a call does, see {@link AmbientStateName}. */
|
|
84
99
|
function withAccess(res, rootId, data, reads, writes = []) {
|
|
@@ -98,9 +113,10 @@ function withAccess(res, rootId, data, reads, writes = []) {
|
|
|
98
113
|
/** Applies the writes of the call `rootId` to the environment, see {@link withAccess}. */
|
|
99
114
|
function defineAmbient(environment, rootId, cds, writes) {
|
|
100
115
|
for (const write of writes) {
|
|
101
|
-
const { name, mode } = typeof write === 'string' ? { name: write, mode: undefined } : write;
|
|
116
|
+
const { name, mode, assumed } = typeof write === 'string' ? { name: write, mode: undefined, assumed: undefined } : write;
|
|
102
117
|
const accumulates = Accumulating.has(name) || name.startsWith(ambient_state_name_1.AmbientStateName.file(''));
|
|
103
|
-
|
|
118
|
+
/* an assumed write keeps what the body wrote before, which, other than it, surely happened */
|
|
119
|
+
const keep = (accumulates && (mode === undefined || mode === 'maybe')) || assumed === true;
|
|
104
120
|
/* an accumulating state only ever grows, its definitions are maybe so merging environments keeps them all; a reset is definite */
|
|
105
121
|
const isMaybe = keep || (accumulates && mode !== 'reset');
|
|
106
122
|
const def = {
|
|
@@ -108,7 +124,8 @@ function defineAmbient(environment, rootId, cds, writes) {
|
|
|
108
124
|
name,
|
|
109
125
|
type: identifier_1.ReferenceType.Variable,
|
|
110
126
|
definedAt: rootId,
|
|
111
|
-
cds: isMaybe ? cds ?? [] : cds
|
|
127
|
+
cds: isMaybe ? cds ?? [] : cds,
|
|
128
|
+
...assumed ? { assumed } : {}
|
|
112
129
|
};
|
|
113
130
|
/* the state is global, wherever the call happens, unless the call or an earlier one (`local_seed`) scopes it to the current frame */
|
|
114
131
|
const local = mode === 'local' || (environment.level > 0 && environment.current.memory.has(name));
|
|
@@ -323,6 +340,9 @@ function applyAmbientStateAccess(res, args, rootId, data, access) {
|
|
|
323
340
|
break;
|
|
324
341
|
case "read-files" /* AmbientStateAccessType.ReadFiles */: {
|
|
325
342
|
const stems = fileStems(res, rootId, data, access);
|
|
343
|
+
if (stems?.length === 0) {
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
326
346
|
reads.push(ambient_state_name_1.AmbientStateName.workingDirectory, ...stems === undefined ? [ambient_state_name_1.AmbientStateName.files] : [...stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.anyFile]);
|
|
327
347
|
/* a read through a connection the program holds moves its position, so the next read depends on this one */
|
|
328
348
|
if (readsThroughHandle(res, rootId, data, access.sig)) {
|
|
@@ -332,6 +352,9 @@ function applyAmbientStateAccess(res, args, rootId, data, access) {
|
|
|
332
352
|
}
|
|
333
353
|
case "write-files" /* AmbientStateAccessType.WriteFiles */: {
|
|
334
354
|
const stems = fileStems(res, rootId, data, access);
|
|
355
|
+
if (stems?.length === 0) {
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
335
358
|
reads.push(ambient_state_name_1.AmbientStateName.workingDirectory);
|
|
336
359
|
writes.push(...stems === undefined ? [ambient_state_name_1.AmbientStateName.anyFile] : stems.map(ambient_state_name_1.AmbientStateName.file), ambient_state_name_1.AmbientStateName.files);
|
|
337
360
|
break;
|
|
@@ -409,7 +432,7 @@ function readsThroughHandle(res, rootId, data, sig) {
|
|
|
409
432
|
function boundValues(id, data, direct = true) {
|
|
410
433
|
const arg = data.completeAst.idMap.get(id);
|
|
411
434
|
const node = r_argument_1.RArgument.is(arg) ? r_argument_1.RArgument.valueOf(arg) : arg;
|
|
412
|
-
if (!r_symbol_1.RSymbol.is(node)) {
|
|
435
|
+
if (!r_symbol_1.RSymbol.is(node) || node.content === convert_values_1.RNull) {
|
|
413
436
|
return direct && node !== undefined ? [node] : [];
|
|
414
437
|
}
|
|
415
438
|
return (resolve_helper_1.Resolve.byName(node.content, data.environment) ?? []).flatMap(d => d.value ?? [])
|
|
@@ -420,18 +443,32 @@ function callsTagged(node, data, tag) {
|
|
|
420
443
|
return r_function_call_1.RFunctionCall.isNamed(node) && (resolve_helper_1.Resolve.byNameAndType(node.functionName.content, data.environment, identifier_1.ReferenceType.Function) ?? [])
|
|
421
444
|
.some(d => d.type === identifier_1.ReferenceType.BuiltInFunction && d.config?.tags?.includes(tag) === true);
|
|
422
445
|
}
|
|
423
|
-
/**
|
|
446
|
+
/** Whether the resource argument `id` names no file: `""` (the console for `cat`), `NULL`, or a console connection like `stdout()`. */
|
|
447
|
+
function namesNoFile(id, data) {
|
|
448
|
+
const values = boundValues(id, data);
|
|
449
|
+
return values.length > 0 && values.every(v => (r_string_1.RString.is(v) && v.content.str === '') || (r_symbol_1.RSymbol.is(v) && v.content === convert_values_1.RNull)
|
|
450
|
+
|| callsTagged(v, data, built_in_props_1.SemanticCallTag.Console));
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* The stems of the files the call names, `undefined` unless every file argument is a known path to a file with an extension (a device's `plot%03d.png` or a directory may stand for others).
|
|
454
|
+
* Empty if the call names no file, as `cat(x)` and `writeLines(x, stdout())`, which print, do.
|
|
455
|
+
*/
|
|
424
456
|
function fileStems(res, rootId, data, { sig, numbered }) {
|
|
425
457
|
const call = res.graph.getVertex(rootId);
|
|
426
458
|
if (sig === undefined || !vertex_1.DfgVertex.isFunctionCall(call)) {
|
|
427
459
|
return undefined;
|
|
428
460
|
}
|
|
429
461
|
const named = match_args_1.MatchArgs.findWithProps((0, applied_arguments_1.appliedArguments)(res.graph, call, data.completeAst.idMap).args, sig, built_in_props_1.ArgProp.Resource);
|
|
430
|
-
|
|
462
|
+
const resources = sig.filter(([, p]) => (p & built_in_props_1.ArgProp.Resource) !== 0);
|
|
463
|
+
if (named.length === 0 ? resources.length === 0 || resources.some(([, p]) => (p & built_in_props_1.ArgProp.Optional) === 0)
|
|
464
|
+
: named.length < resources.filter(([n, p]) => n !== '...' && (p & (built_in_props_1.ArgProp.Forced | built_in_props_1.ArgProp.Optional)) === built_in_props_1.ArgProp.Forced).length) {
|
|
431
465
|
return undefined;
|
|
432
466
|
}
|
|
433
467
|
const stems = [];
|
|
434
468
|
for (const id of named) {
|
|
469
|
+
if (namesNoFile(id, data)) {
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
435
472
|
/* every `tempfile()` names a file no other call names */
|
|
436
473
|
const fresh = boundValues(id, data);
|
|
437
474
|
if (fresh.length > 0 && fresh.every(v => callsTagged(v, data, built_in_props_1.SemanticCallTag.TempFile))) {
|
|
@@ -6,6 +6,7 @@ exports.processDefineArgument = processDefineArgument;
|
|
|
6
6
|
exports.markAsAssignment = markAsAssignment;
|
|
7
7
|
const function_semantics_1 = require("../../../../../fn/function-semantics");
|
|
8
8
|
const known_call_handling_1 = require("../known-call-handling");
|
|
9
|
+
const nse_kind_1 = require("../nse-kind");
|
|
9
10
|
const nse_1 = require("../nse");
|
|
10
11
|
const data_masking_functions_1 = require("../../../../../environments/data-masking-functions");
|
|
11
12
|
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
@@ -125,8 +126,8 @@ function isMaskedNamePair(name, rootId, data) {
|
|
|
125
126
|
function processMaskedNamePair(name, args, rootId, data) {
|
|
126
127
|
const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default', keepArgumentGraphs: true });
|
|
127
128
|
const target = args[0];
|
|
128
|
-
(0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments,
|
|
129
|
-
kind:
|
|
129
|
+
(0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments, nse_kind_1.NseArguments.First, {
|
|
130
|
+
kind: nse_kind_1.NseKind.DataMasked,
|
|
130
131
|
evaluated: function_semantics_1.FunctionSemantics.call.nse.unquoted(r_argument_1.RArgument.valueOf(target), nse_1.Unquote.Rlang)
|
|
131
132
|
});
|
|
132
133
|
return information;
|
|
@@ -379,16 +379,16 @@ function selectExports(callables, spec) {
|
|
|
379
379
|
* What a package's attached layer binds, built per name on the first lookup. An attach names thousands of exports
|
|
380
380
|
* and a script mentions a few dozen, so the definitions are only made for the ones something asks about.
|
|
381
381
|
*/
|
|
382
|
-
function lazyExports(pack, exports, ctx, definedAt, cds) {
|
|
382
|
+
function lazyExports(pack, exports, ctx, definedAt, cds, ns) {
|
|
383
383
|
const byName = new Map(exports.map(exp => [identifier_1.Identifier.getName(identifier_1.Identifier.make(exp.as, pack)), exp]));
|
|
384
384
|
const aliases = exports.filter(exp => exp.as !== exp.exported).map(exp => `${exp.as}=${exp.exported}`);
|
|
385
|
-
return new frame_memory_1.LazyBindings(new Set(byName.keys()), name => [exportDefinition(pack, byName.get(name), ctx, definedAt, cds)], `${pack}|${String(definedAt)}|${aliases.join(',')}|${info_1.ControlDependency.key(cds)}`);
|
|
385
|
+
return new frame_memory_1.LazyBindings(new Set(byName.keys()), name => [exportDefinition(pack, byName.get(name), ctx, definedAt, cds, ns)], `${pack}|${String(definedAt)}|${aliases.join(',')}|${info_1.ControlDependency.key(cds)}`);
|
|
386
386
|
}
|
|
387
387
|
/**
|
|
388
388
|
* The identifier definition binding a package export (or its alias) to its built-in function-definition.
|
|
389
389
|
* The identity stays the plain export (so a call still materializes its `built-in:pkg:fn` vertex); whatever the configuration states about that name (processor, config, eval handler) rides along on top.
|
|
390
390
|
*/
|
|
391
|
-
function exportDefinition(pack, exp, ctx, definedAt = node_id_1.NodeId.toBuiltIn(pack), cds) {
|
|
391
|
+
function exportDefinition(pack, exp, ctx, definedAt = node_id_1.NodeId.toBuiltIn(pack), cds, ns) {
|
|
392
392
|
const identity = {
|
|
393
393
|
name: identifier_1.Identifier.make(exp.as, pack),
|
|
394
394
|
type: identifier_1.ReferenceType.Function,
|
|
@@ -398,7 +398,10 @@ function exportDefinition(pack, exp, ctx, definedAt = node_id_1.NodeId.toBuiltIn
|
|
|
398
398
|
};
|
|
399
399
|
/* an export named like a primitive is a method registered for it (lubridate's `$`), the primitive still evaluates the call */
|
|
400
400
|
const exported = identifier_1.Identifier.make(exp.exported);
|
|
401
|
-
|
|
401
|
+
/* a re-export stays the export of `pack`, but means what its origin states about it */
|
|
402
|
+
const origin = ns === undefined ? undefined : (0, flowr_namespace_file_1.importOrigin)(exp.exported, ns);
|
|
403
|
+
const stated = ctx.env.statedFor(pack)?.get(exported)?.[0] ?? (origin === undefined ? undefined : ctx.env.statedFor(origin)?.get(exported)?.[0])
|
|
404
|
+
?? ctx.env.emptyBuiltInEnvironment.memory.get(exported)?.[0];
|
|
402
405
|
if (stated === undefined) {
|
|
403
406
|
return identity;
|
|
404
407
|
}
|
|
@@ -429,7 +432,7 @@ function attachResolved(dependency, envInfo, ctx, spec, definedAt, attaching, cd
|
|
|
429
432
|
spec = withStartupPosition(pack, envInfo, spec);
|
|
430
433
|
const layerType = spec.namespaceOnly ? environment_1.EnvType.LoadedNamespace : environment_1.EnvType.Namespace;
|
|
431
434
|
const layer = new environment_1.Environment(envInfo.current).asLibrary(pack, layerType);
|
|
432
|
-
layer.adoptMap(lazyExports(pack, exports, ctx, definedAt, cds));
|
|
435
|
+
layer.adoptMap(lazyExports(pack, exports, ctx, definedAt, cds, dependency.namespaceInfo));
|
|
433
436
|
return { level: envInfo.level, current: environment_1.REnvironment.attachAt(envInfo.current, layer, layer, spec.pos) };
|
|
434
437
|
}
|
|
435
438
|
/* as R does: the Depends first (at the default position, whatever `pos` says), then `pack`, then what its `.onAttach` attaches */
|
|
@@ -441,7 +444,7 @@ function attachResolved(dependency, envInfo, ctx, spec, definedAt, attaching, cd
|
|
|
441
444
|
// full attach: imports layer at the bottom, namespace (exports) layer on top
|
|
442
445
|
const importsEnv = imports(new environment_1.Environment(below.current).asLibrary(pack, environment_1.EnvType.Imports), dependency.namespaceInfo, ctx);
|
|
443
446
|
const namespaceEnv = new environment_1.Environment(importsEnv).asLibrary(pack, environment_1.EnvType.Namespace);
|
|
444
|
-
namespaceEnv.adoptMap(lazyExports(pack, exports, ctx, definedAt, cds));
|
|
447
|
+
namespaceEnv.adoptMap(lazyExports(pack, exports, ctx, definedAt, cds, dependency.namespaceInfo));
|
|
445
448
|
const attached = { level: below.level, current: environment_1.REnvironment.attachAt(below.current, namespaceEnv, importsEnv, withStartupPosition(pack, below, spec).pos) };
|
|
446
449
|
return alongside(attached, onAttach);
|
|
447
450
|
}
|
|
@@ -12,6 +12,7 @@ const convert_values_1 = require("../../../../../../r-bridge/lang-4.x/convert-va
|
|
|
12
12
|
const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
13
13
|
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
14
14
|
const environment_2 = require("../../../../../environments/environment");
|
|
15
|
+
const identifier_1 = require("../../../../../environments/identifier");
|
|
15
16
|
const EmptyParentEnvFunctions = new Set(['emptyenv', 'baseenv']);
|
|
16
17
|
/**
|
|
17
18
|
* Processes `new.env()` and `rlang::new_environment()`.
|
|
@@ -60,7 +61,7 @@ function resolveNewEnvParentArg(args, data) {
|
|
|
60
61
|
return (0, built_in_envir_utils_1.resolveSymbolToEnvir)(node.content, node.info.id, data)?.envDef.envState;
|
|
61
62
|
}
|
|
62
63
|
if (r_function_call_1.RFunctionCall.isNamed(node) && r_symbol_1.RSymbol.is(node.functionName)
|
|
63
|
-
&& EmptyParentEnvFunctions.has(node.functionName.content)) {
|
|
64
|
+
&& EmptyParentEnvFunctions.has(identifier_1.Identifier.getName(node.functionName.content))) {
|
|
64
65
|
return createIsolatedEnvState(data);
|
|
65
66
|
}
|
|
66
67
|
return undefined;
|
|
@@ -15,15 +15,6 @@ import type { FnSig } from '../../../../../environments/built-in-props';
|
|
|
15
15
|
* Infers working directories based on the given option and reference chain
|
|
16
16
|
*/
|
|
17
17
|
export declare function inferWdFromScript(option: InferWorkingDirectory, referenceChain: readonly (string | undefined)[]): string[];
|
|
18
|
-
/**
|
|
19
|
-
* Return the basename of a path in a platform-agnostic way
|
|
20
|
-
* @see {@link platformDirname} - for the dirname counterpart
|
|
21
|
-
*/
|
|
22
|
-
export declare function platformBasename(p: string): string;
|
|
23
|
-
/**
|
|
24
|
-
* Return the dirname of a path in a platform-agnostic way
|
|
25
|
-
*/
|
|
26
|
-
export declare function platformDirname(p: string): string;
|
|
27
18
|
/**
|
|
28
19
|
* Tries to find sourced by a source request and returns the first path that exists
|
|
29
20
|
* @param resolveSource - options for lax file sourcing
|
|
@@ -4,8 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.inferWdFromScript = inferWdFromScript;
|
|
7
|
-
exports.platformBasename = platformBasename;
|
|
8
|
-
exports.platformDirname = platformDirname;
|
|
9
7
|
exports.findSource = findSource;
|
|
10
8
|
exports.processSourceCall = processSourceCall;
|
|
11
9
|
exports.sourceRequest = sourceRequest;
|
|
@@ -35,37 +33,29 @@ const environment_1 = require("../../../../../environments/environment");
|
|
|
35
33
|
const function_semantics_1 = require("../../../../../fn/function-semantics");
|
|
36
34
|
const r_logical_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-logical");
|
|
37
35
|
const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
36
|
+
let parserForSource;
|
|
37
|
+
/** parses what is sourced while an asynchronous shell analyzes: a fresh R per call, without the default packages, which parsing does not need, so it starts in a third of the time */
|
|
38
|
+
function sourceParser() {
|
|
39
|
+
return parserForSource ??= new shell_executor_1.RShellExecutor({ env: { R_DEFAULT_PACKAGES: 'NULL' } });
|
|
40
|
+
}
|
|
38
41
|
/**
|
|
39
42
|
* Infers working directories based on the given option and reference chain
|
|
40
43
|
*/
|
|
41
44
|
function inferWdFromScript(option, referenceChain) {
|
|
42
45
|
switch (option) {
|
|
43
46
|
case config_1.InferWorkingDirectory.MainScript:
|
|
44
|
-
return referenceChain[0] ? [
|
|
47
|
+
return referenceChain[0] ? [files_1.RPath.dirname(referenceChain[0])] : [];
|
|
45
48
|
case config_1.InferWorkingDirectory.ActiveScript: {
|
|
46
49
|
const active = referenceChain.at(-1);
|
|
47
|
-
return active ? [
|
|
50
|
+
return active ? [files_1.RPath.dirname(active)] : [];
|
|
48
51
|
}
|
|
49
52
|
case config_1.InferWorkingDirectory.AnyScript:
|
|
50
|
-
return referenceChain.filter(assert_1.isNotUndefined).map(
|
|
53
|
+
return referenceChain.filter(assert_1.isNotUndefined).map(files_1.RPath.dirname);
|
|
51
54
|
default:
|
|
52
55
|
return [];
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
const AnyPathSeparator = /[/\\]/g;
|
|
56
|
-
/**
|
|
57
|
-
* Return the basename of a path in a platform-agnostic way
|
|
58
|
-
* @see {@link platformDirname} - for the dirname counterpart
|
|
59
|
-
*/
|
|
60
|
-
function platformBasename(p) {
|
|
61
|
-
return files_1.RPath.basename(p);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Return the dirname of a path in a platform-agnostic way
|
|
65
|
-
*/
|
|
66
|
-
function platformDirname(p) {
|
|
67
|
-
return files_1.RPath.dirname(p);
|
|
68
|
-
}
|
|
69
59
|
function returnPlatformPath(p) {
|
|
70
60
|
return p.replaceAll(AnyPathSeparator, path_1.default.sep);
|
|
71
61
|
}
|
|
@@ -86,10 +76,10 @@ function candidatePaths(seed, dropPaths) {
|
|
|
86
76
|
if (dropPaths !== config_1.DropPathsOption.Once && dropPaths !== config_1.DropPathsOption.All) {
|
|
87
77
|
return [seed];
|
|
88
78
|
}
|
|
89
|
-
const basename =
|
|
79
|
+
const basename = files_1.RPath.basename(seed);
|
|
90
80
|
const tryPaths = [seed, basename];
|
|
91
81
|
if (dropPaths === config_1.DropPathsOption.All) {
|
|
92
|
-
const dirs =
|
|
82
|
+
const dirs = files_1.RPath.dirname(seed).split(AnyPathSeparator);
|
|
93
83
|
if (dirs.length !== 1 || dirs[0] !== '.') {
|
|
94
84
|
for (let i = 0; i < dirs.length; i++) {
|
|
95
85
|
tryPaths.push(path_1.default.join(...dirs.slice(i), basename));
|
|
@@ -239,7 +229,7 @@ function sourceRequest(rootId, request, data, information, makeMaybe, getId, eva
|
|
|
239
229
|
fst = requested;
|
|
240
230
|
}
|
|
241
231
|
else {
|
|
242
|
-
const parsed = (!data.parser.async ? data.parser :
|
|
232
|
+
const parsed = (!data.parser.async ? data.parser : sourceParser()).parse(textRequest.r, data.ctx);
|
|
243
233
|
const normalized = (typeof parsed !== 'string' ?
|
|
244
234
|
(0, parser_1.normalizeTreeSitter)({ files: [{ parsed, filePath: textRequest.path }] }, getId, data.ctx.config)
|
|
245
235
|
: (0, parser_1.normalize)({ files: [{ parsed, filePath: textRequest.path }] }, getId));
|
|
@@ -46,7 +46,7 @@ function fixedStackEnv(kind, data) {
|
|
|
46
46
|
function stackEnvKindOf(node, data) {
|
|
47
47
|
const symbol = r_symbol_1.RSymbol.is(node) ? node.content
|
|
48
48
|
: r_function_call_1.RFunctionCall.calledName(node);
|
|
49
|
-
const kind = symbol !== undefined ? stackEnvKind(
|
|
49
|
+
const kind = symbol !== undefined ? stackEnvKind(identifier_1.Identifier.getName(symbol)) : undefined;
|
|
50
50
|
if (kind === undefined || !resolve_helper_1.Resolve.isBuiltIn(symbol, data.environment, r_symbol_1.RSymbol.is(node) ? identifier_1.ReferenceType.Constant : identifier_1.ReferenceType.Function)) {
|
|
51
51
|
return undefined;
|
|
52
52
|
}
|
|
@@ -105,7 +105,7 @@ function stackEnvStateFromSource(sourceInfo, data, entryPoint = sourceInfo.entry
|
|
|
105
105
|
if (!vertex_1.DfgVertex.isFunctionCall(vertex) || vertex.name === undefined) {
|
|
106
106
|
return undefined;
|
|
107
107
|
}
|
|
108
|
-
const kind = stackEnvKind(
|
|
108
|
+
const kind = stackEnvKind(identifier_1.Identifier.getName(vertex.name));
|
|
109
109
|
if (vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.StackEnv)) {
|
|
110
110
|
return fixedStackEnv(kind, data);
|
|
111
111
|
}
|
|
@@ -119,6 +119,6 @@ function stackEnvStateFromSource(sourceInfo, data, entryPoint = sourceInfo.entry
|
|
|
119
119
|
* Only the rlang pronoun `.env` does: it names the surrounding scope, while `$` on a real environment stays in its frame.
|
|
120
120
|
*/
|
|
121
121
|
function stackEnvInheritsFields(node) {
|
|
122
|
-
return r_symbol_1.RSymbol.is(node) &&
|
|
122
|
+
return r_symbol_1.RSymbol.is(node) && identifier_1.Identifier.getName(node.content) === EnvPronoun;
|
|
123
123
|
}
|
|
124
124
|
//# sourceMappingURL=built-in-stack-env.js.map
|
|
@@ -6,6 +6,7 @@ const function_semantics_1 = require("../../../../../fn/function-semantics");
|
|
|
6
6
|
const processor_1 = require("../../../../../processor");
|
|
7
7
|
const info_1 = require("../../../../../info");
|
|
8
8
|
const known_call_handling_1 = require("../known-call-handling");
|
|
9
|
+
const nse_kind_1 = require("../nse-kind");
|
|
9
10
|
const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
10
11
|
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
11
12
|
const resolve_helper_1 = require("../../../../../environments/resolve-helper");
|
|
@@ -23,7 +24,7 @@ const withParamsFallback = ['data', 'expr'];
|
|
|
23
24
|
function markAsMaskedFallback(name, args, rootId, data, expr) {
|
|
24
25
|
const patchData = expr === undefined ? undefined : (d, i) => r_argument_1.RArgument.valueOf(args[i]) === expr ? { ...d, environment: environment_1.REnvironment.pushLocal(d.environment) } : d;
|
|
25
26
|
const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.With, keepArgumentGraphs: true, patchData });
|
|
26
|
-
(0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments,
|
|
27
|
+
(0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments, nse_kind_1.NseArguments.AllButFirst, { kind: nse_kind_1.NseKind.DataMasked });
|
|
27
28
|
return expr === undefined ? information : { ...information, environment: environment_1.REnvironment.popLocal(information.environment) };
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
@@ -21,16 +21,26 @@ export declare function computeCallGraphSummaries<T>(this: void, graph: Dataflow
|
|
|
21
21
|
export declare function linkMaterializedExportsToLoaders(graph: DataflowGraph, environment: REnvironmentInformation, ctx: FlowrAnalyzerContext): void;
|
|
22
22
|
/** Re-resolves still-open reads whose name is one of the transitively escaped `<<-` definitions in `escapedNames`, adding {@link EdgeType.Reads} edges. */
|
|
23
23
|
export declare function reResolveOpenReferences(this: void, graph: DataflowGraph, environment: REnvironmentInformation, references: readonly IdentifierReference[], escapedNames: ReadonlySet<string>): void;
|
|
24
|
+
/** What calling a function may leave changed, see {@link ambientWritesOfFunctions}. */
|
|
25
|
+
export interface FunctionAmbientWrites {
|
|
26
|
+
/** the pseudo variables of the state it may change (see {@link AmbientStateName}), like `#option:digits` */
|
|
27
|
+
readonly state: ReadonlySet<string>;
|
|
28
|
+
/** the state only assumed changed by a body flowR cannot see and changed by nothing else, like `#rng` for `function(f) f()` */
|
|
29
|
+
readonly assumed: ReadonlySet<string>;
|
|
30
|
+
/** the global variables it may bind, by `x <<- 1` reaching the global frame or `assign("x", 1, envir = .GlobalEnv)` */
|
|
31
|
+
readonly variables: ReadonlySet<string>;
|
|
32
|
+
}
|
|
24
33
|
/**
|
|
25
34
|
* The global state each function may leave changed when it is called, as the names of the pseudo variables it changes
|
|
26
|
-
* (see {@link AmbientStateName}): `#option:digits` for `options(digits = 3)`, `#env:PATH` for `Sys.setenv(PATH = "")`, or `#sink
|
|
35
|
+
* (see {@link AmbientStateName}): `#option:digits` for `options(digits = 3)`, `#env:PATH` for `Sys.setenv(PATH = "")`, or `#sink`,
|
|
36
|
+
* and the global variables it binds.
|
|
27
37
|
* A function reports what its callees report as well, so with `a01 <- function() options(digits = 3)` and `a22 <- function() a01()`,
|
|
28
38
|
* both set `#option:digits`. What a function only changes within its own frame (`withr::local_options`) is left out.
|
|
29
39
|
* @param info - the dataflow information of the whole program
|
|
30
|
-
* @returns per function-definition vertex
|
|
40
|
+
* @returns per function-definition vertex what it may change, which is empty for a function changing nothing
|
|
31
41
|
* @useInstead {@link Dataflow.sideEffects.ambientWrites}
|
|
32
42
|
*/
|
|
33
|
-
export declare function ambientWritesOfFunctions(this: void, info: Pick<DataflowInformation, 'graph' | 'environment'>): Map<NodeId,
|
|
43
|
+
export declare function ambientWritesOfFunctions(this: void, info: Pick<DataflowInformation, 'graph' | 'environment'>): Map<NodeId, FunctionAmbientWrites>;
|
|
34
44
|
/**
|
|
35
45
|
* Propagates every function's escaped side effects (attached packages and `<<-` definitions) to its transitive callers.
|
|
36
46
|
* @returns the enriched top-level environment and whether it grew (so the extractor can re-link and re-run to a fixpoint).
|
|
@@ -213,7 +213,7 @@ function hiddenBuiltInAccess(graph, environment) {
|
|
|
213
213
|
const writesOf = new defaultmap_1.DefaultMap(() => [], writes);
|
|
214
214
|
const readsOf = new defaultmap_1.DefaultMap(() => [], reads);
|
|
215
215
|
for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
216
|
-
if (graph.isRoot(id)) {
|
|
216
|
+
if (graph.isRoot(id) || !(0, built_in_ambient_state_1.reachesBuiltInLate)(vertex)) {
|
|
217
217
|
continue;
|
|
218
218
|
}
|
|
219
219
|
const own = vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Function) ? undefined : vertex.name;
|
|
@@ -339,7 +339,7 @@ function linkReadsAfter(graph, call, def, open, definitionsNamed) {
|
|
|
339
339
|
/** Re-resolves still-open reads whose name is one of the transitively escaped `<<-` definitions in `escapedNames`, adding {@link EdgeType.Reads} edges. */
|
|
340
340
|
function reResolveOpenReferences(graph, environment, references, escapedNames) {
|
|
341
341
|
for (const ref of references) {
|
|
342
|
-
if (ref.name === undefined || !escapedNames.has(
|
|
342
|
+
if (ref.name === undefined || !escapedNames.has(identifier_1.Identifier.toString(ref.name))) {
|
|
343
343
|
continue;
|
|
344
344
|
}
|
|
345
345
|
for (const { nodeId } of resolve_helper_1.Resolve.byNameAndType(ref.name, environment, ref.type) ?? []) {
|
|
@@ -351,18 +351,28 @@ function reResolveOpenReferences(graph, environment, references, escapedNames) {
|
|
|
351
351
|
}
|
|
352
352
|
/**
|
|
353
353
|
* The global state each function may leave changed when it is called, as the names of the pseudo variables it changes
|
|
354
|
-
* (see {@link AmbientStateName}): `#option:digits` for `options(digits = 3)`, `#env:PATH` for `Sys.setenv(PATH = "")`, or `#sink
|
|
354
|
+
* (see {@link AmbientStateName}): `#option:digits` for `options(digits = 3)`, `#env:PATH` for `Sys.setenv(PATH = "")`, or `#sink`,
|
|
355
|
+
* and the global variables it binds.
|
|
355
356
|
* A function reports what its callees report as well, so with `a01 <- function() options(digits = 3)` and `a22 <- function() a01()`,
|
|
356
357
|
* both set `#option:digits`. What a function only changes within its own frame (`withr::local_options`) is left out.
|
|
357
358
|
* @param info - the dataflow information of the whole program
|
|
358
|
-
* @returns per function-definition vertex
|
|
359
|
+
* @returns per function-definition vertex what it may change, which is empty for a function changing nothing
|
|
359
360
|
* @useInstead {@link Dataflow.sideEffects.ambientWrites}
|
|
360
361
|
*/
|
|
361
362
|
function ambientWritesOfFunctions(info) {
|
|
362
363
|
const hidden = hiddenBuiltInAccess(info.graph, info.environment).writes;
|
|
363
364
|
const names = escapedDefinitionMap(info.graph, hidden);
|
|
364
365
|
const summary = computeCallGraphSummaries(info.graph, escapedDefinitions(hidden));
|
|
365
|
-
return new Map(summary.entries().map(([id, definitions]) => [id,
|
|
366
|
+
return new Map(summary.entries().map(([id, definitions]) => [id, writesOf(definitions.values().flatMap(d => names.get(d) ?? []))]));
|
|
367
|
+
}
|
|
368
|
+
function writesOf(definitions) {
|
|
369
|
+
const state = new Set();
|
|
370
|
+
const assumed = new Set();
|
|
371
|
+
const variables = new Set();
|
|
372
|
+
for (const d of definitions) {
|
|
373
|
+
(!ambient_state_name_1.AmbientStateName.is(d.name) ? variables : (0, built_in_ambient_state_1.isAssumedWrite)(d) ? assumed : state).add(d.name);
|
|
374
|
+
}
|
|
375
|
+
return { state, assumed: assumed.difference(state), variables };
|
|
366
376
|
}
|
|
367
377
|
/**
|
|
368
378
|
* Propagates every function's escaped side effects (attached packages and `<<-` definitions) to its transitive callers.
|
|
@@ -9,6 +9,7 @@ import type { RNode } from '../../../../../r-bridge/lang-4.x/ast/model/model';
|
|
|
9
9
|
import { type IdentifierReference } from '../../../../environments/identifier';
|
|
10
10
|
import type { FunctionArgument } from '../../../../graph/graph';
|
|
11
11
|
import { DataflowGraph } from '../../../../graph/graph';
|
|
12
|
+
import { NseArguments, NseKind } from './nse-kind';
|
|
12
13
|
import { type FunctionOriginInformation } from '../../../../graph/vertex';
|
|
13
14
|
export interface ProcessKnownFunctionCallInput<OtherInfo> {
|
|
14
15
|
/** the signature of the called function, the one place stating which arguments it evaluates */
|
|
@@ -61,30 +62,6 @@ export interface ProcessKnownFunctionCallResult {
|
|
|
61
62
|
*/
|
|
62
63
|
readonly callArgs: readonly FunctionArgument[];
|
|
63
64
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Which arguments of a call {@link markArgumentsAsNonStandardEvaluation|are non-standardly evaluated}:
|
|
66
|
-
* every argument, all but the (data) first one, or only the first one.
|
|
67
|
-
*/
|
|
68
|
-
export declare enum NseArguments {
|
|
69
|
-
/** every argument, e.g. the operands of a formula `~` or `aes(x, y)` */
|
|
70
|
-
All = "all",
|
|
71
|
-
/** all but the first, e.g. `subset(data, col > 1)` where the first argument is the data object */
|
|
72
|
-
AllButFirst = "all-but-first",
|
|
73
|
-
/** only the first, e.g. the native routine name in `.C(routine, ...)` */
|
|
74
|
-
First = "first"
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* How an argument escapes standard evaluation, which decides what is marked
|
|
78
|
-
* {@link EdgeType.NonStandardEvaluation}.
|
|
79
|
-
*/
|
|
80
|
-
export declare enum NseKind {
|
|
81
|
-
/** the argument is not evaluated at all (`quote(x + y)`), so nothing within it is */
|
|
82
|
-
Quoted = "quoted",
|
|
83
|
-
/** the argument is evaluated in a data mask (`subset(d, a > k)`), where only its symbols may name columns */
|
|
84
|
-
DataMasked = "data-masked",
|
|
85
|
-
/** evaluated, just not exactly once (a loop body), so only the argument itself is marked */
|
|
86
|
-
Reevaluated = "reevaluated"
|
|
87
|
-
}
|
|
88
65
|
export interface NseMarkOptions {
|
|
89
66
|
readonly kind?: NseKind;
|
|
90
67
|
/** ids an unquote escape splices back in, see {@link FunctionSemantics.call.nse.unquoted} */
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NseKind = exports.NseArguments = void 0;
|
|
4
3
|
exports.nseArgumentPositions = nseArgumentPositions;
|
|
5
4
|
exports.markArgumentsAsNonStandardEvaluation = markArgumentsAsNonStandardEvaluation;
|
|
6
5
|
exports.processKnownFunctionCall = processKnownFunctionCall;
|
|
@@ -14,6 +13,7 @@ const r_string_1 = require("../../../../../r-bridge/lang-4.x/ast/model/nodes/r-s
|
|
|
14
13
|
const identifier_1 = require("../../../../environments/identifier");
|
|
15
14
|
const graph_1 = require("../../../../graph/graph");
|
|
16
15
|
const edge_1 = require("../../../../graph/edge");
|
|
16
|
+
const nse_kind_1 = require("./nse-kind");
|
|
17
17
|
const control_flow_1 = require("../../../control-flow");
|
|
18
18
|
const logic_1 = require("../../../../../util/logic");
|
|
19
19
|
const assert_1 = require("../../../../../util/assert");
|
|
@@ -21,32 +21,6 @@ const logger_1 = require("../../../../logger");
|
|
|
21
21
|
const vertex_1 = require("../../../../graph/vertex");
|
|
22
22
|
const unknown_side_effect_1 = require("../../../../graph/unknown-side-effect");
|
|
23
23
|
const built_in_proc_name_1 = require("../../../../environments/built-in-proc-name");
|
|
24
|
-
/**
|
|
25
|
-
* Which arguments of a call {@link markArgumentsAsNonStandardEvaluation|are non-standardly evaluated}:
|
|
26
|
-
* every argument, all but the (data) first one, or only the first one.
|
|
27
|
-
*/
|
|
28
|
-
var NseArguments;
|
|
29
|
-
(function (NseArguments) {
|
|
30
|
-
/** every argument, e.g. the operands of a formula `~` or `aes(x, y)` */
|
|
31
|
-
NseArguments["All"] = "all";
|
|
32
|
-
/** all but the first, e.g. `subset(data, col > 1)` where the first argument is the data object */
|
|
33
|
-
NseArguments["AllButFirst"] = "all-but-first";
|
|
34
|
-
/** only the first, e.g. the native routine name in `.C(routine, ...)` */
|
|
35
|
-
NseArguments["First"] = "first";
|
|
36
|
-
})(NseArguments || (exports.NseArguments = NseArguments = {}));
|
|
37
|
-
/**
|
|
38
|
-
* How an argument escapes standard evaluation, which decides what is marked
|
|
39
|
-
* {@link EdgeType.NonStandardEvaluation}.
|
|
40
|
-
*/
|
|
41
|
-
var NseKind;
|
|
42
|
-
(function (NseKind) {
|
|
43
|
-
/** the argument is not evaluated at all (`quote(x + y)`), so nothing within it is */
|
|
44
|
-
NseKind["Quoted"] = "quoted";
|
|
45
|
-
/** the argument is evaluated in a data mask (`subset(d, a > k)`), where only its symbols may name columns */
|
|
46
|
-
NseKind["DataMasked"] = "data-masked";
|
|
47
|
-
/** evaluated, just not exactly once (a loop body), so only the argument itself is marked */
|
|
48
|
-
NseKind["Reevaluated"] = "reevaluated";
|
|
49
|
-
})(NseKind || (exports.NseKind = NseKind = {}));
|
|
50
24
|
/**
|
|
51
25
|
* The positions of the arguments `which` names among `count` arguments, where `first` is the position of the
|
|
52
26
|
* argument filling the first parameter (`-1` if none does), as a named one may come later (`mutate(z = 1, .data = d)`).
|
|
@@ -56,17 +30,17 @@ function nseArgumentPositions(which, count, first = 0) {
|
|
|
56
30
|
return which ?? [];
|
|
57
31
|
}
|
|
58
32
|
const all = Array.from({ length: count }, (_, i) => i);
|
|
59
|
-
if (which === NseArguments.First) {
|
|
33
|
+
if (which === nse_kind_1.NseArguments.First) {
|
|
60
34
|
return first >= 0 && first < count ? [first] : [];
|
|
61
35
|
}
|
|
62
|
-
return which === NseArguments.AllButFirst ? all.filter(i => i !== first) : all;
|
|
36
|
+
return which === nse_kind_1.NseArguments.AllButFirst ? all.filter(i => i !== first) : all;
|
|
63
37
|
}
|
|
64
38
|
/**
|
|
65
39
|
* Marks the selected arguments as {@link EdgeType.NonStandardEvaluation}: a {@link NseKind.Quoted|quoted} one
|
|
66
40
|
* entirely, a {@link NseKind.DataMasked|data-masked} one only where {@link FunctionSemantics.call.nse.suppliedByMask} holds, and a
|
|
67
41
|
* {@link NseKind.Reevaluated|reevaluated} one as a whole but not within.
|
|
68
42
|
*/
|
|
69
|
-
function markArgumentsAsNonStandardEvaluation(graph, rootId, processedArguments, which, { kind = NseKind.Quoted, evaluated, first } = {}) {
|
|
43
|
+
function markArgumentsAsNonStandardEvaluation(graph, rootId, processedArguments, which, { kind = nse_kind_1.NseKind.Quoted, evaluated, first } = {}) {
|
|
70
44
|
for (const i of nseArgumentPositions(which, processedArguments.length, first)) {
|
|
71
45
|
if (i < processedArguments.length) {
|
|
72
46
|
markArgument(graph, rootId, processedArguments[i], kind, evaluated);
|
|
@@ -80,10 +54,10 @@ function markArgument(graph, rootId, arg, kind, evaluated) {
|
|
|
80
54
|
if (arg === undefined) {
|
|
81
55
|
return;
|
|
82
56
|
}
|
|
83
|
-
if (kind !== NseKind.DataMasked) {
|
|
57
|
+
if (kind !== nse_kind_1.NseKind.DataMasked) {
|
|
84
58
|
graph.addEdge(rootId, arg.entryPoint, edge_1.EdgeType.NonStandardEvaluation);
|
|
85
59
|
}
|
|
86
|
-
if (kind === NseKind.Reevaluated) {
|
|
60
|
+
if (kind === nse_kind_1.NseKind.Reevaluated) {
|
|
87
61
|
return;
|
|
88
62
|
}
|
|
89
63
|
for (const [vtx, info] of arg.graph.vertices(true)) {
|
|
@@ -93,7 +67,7 @@ function markArgument(graph, rootId, arg, kind, evaluated) {
|
|
|
93
67
|
/* every name in a mask is a candidate column, even one the caller binds: R asks the data first.
|
|
94
68
|
{@link FunctionSemantics.call.nse.dropResolvedMask} takes the mark off the bound ones again, and keeps them as the
|
|
95
69
|
names that mean both */
|
|
96
|
-
if (kind === NseKind.Quoted || function_semantics_1.FunctionSemantics.call.nse.maskCandidate(info)) {
|
|
70
|
+
if (kind === nse_kind_1.NseKind.Quoted || function_semantics_1.FunctionSemantics.call.nse.maskCandidate(info)) {
|
|
97
71
|
graph.addEdge(rootId, vtx, edge_1.EdgeType.NonStandardEvaluation);
|
|
98
72
|
}
|
|
99
73
|
}
|
|
@@ -120,7 +94,7 @@ function processKnownFunctionCall({ name, args, rootId, data, reverseOrder = fal
|
|
|
120
94
|
nonFunction,
|
|
121
95
|
alternativesFrom: reverseOrder ? undefined : alternativeArgsFrom
|
|
122
96
|
});
|
|
123
|
-
markArgumentsAsNonStandardEvaluation(finalGraph, rootId, processedArguments, markAsNSE, { kind: NseKind.Reevaluated });
|
|
97
|
+
markArgumentsAsNonStandardEvaluation(finalGraph, rootId, processedArguments, markAsNSE, { kind: nse_kind_1.NseKind.Reevaluated });
|
|
124
98
|
const onlyBuiltin = data.builtInNoEnv === rootId;
|
|
125
99
|
finalGraph.addVertex({
|
|
126
100
|
tag: vertex_1.VertexType.FunctionCall,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which arguments of a call {@link markArgumentsAsNonStandardEvaluation|are non-standardly evaluated}:
|
|
3
|
+
* every argument, all but the (data) first one, or only the first one.
|
|
4
|
+
*/
|
|
5
|
+
export declare enum NseArguments {
|
|
6
|
+
/** every argument, e.g. the operands of a formula `~` or `aes(x, y)` */
|
|
7
|
+
All = "all",
|
|
8
|
+
/** all but the first, e.g. `subset(data, col > 1)` where the first argument is the data object */
|
|
9
|
+
AllButFirst = "all-but-first",
|
|
10
|
+
/** only the first, e.g. the native routine name in `.C(routine, ...)` */
|
|
11
|
+
First = "first"
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* How an argument escapes standard evaluation, which decides what is marked
|
|
15
|
+
* {@link EdgeType.NonStandardEvaluation}.
|
|
16
|
+
*/
|
|
17
|
+
export declare enum NseKind {
|
|
18
|
+
/** the argument is not evaluated at all (`quote(x + y)`), so nothing within it is */
|
|
19
|
+
Quoted = "quoted",
|
|
20
|
+
/** the argument is evaluated in a data mask (`subset(d, a > k)`), where only its symbols may name columns */
|
|
21
|
+
DataMasked = "data-masked",
|
|
22
|
+
/** evaluated, just not exactly once (a loop body), so only the argument itself is marked */
|
|
23
|
+
Reevaluated = "reevaluated"
|
|
24
|
+
}
|