@eagleoutice/flowr 2.17.1 → 2.17.2
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/control-flow/semantic-cfg-guided-visitor.js +2 -0
- package/dataflow/environments/ambient-state-name.d.ts +4 -0
- package/dataflow/environments/ambient-state-name.js +4 -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-props.d.ts +2 -0
- package/dataflow/environments/built-in-props.js +3 -1
- package/dataflow/environments/built-in.d.ts +16 -6
- package/dataflow/environments/built-in.js +45 -4
- package/dataflow/environments/default-builtin-config.d.ts +846 -21
- package/dataflow/environments/default-builtin-config.js +120 -26
- package/dataflow/environments/environment.d.ts +19 -2
- package/dataflow/environments/environment.js +90 -19
- package/dataflow/environments/identifier.d.ts +18 -0
- package/dataflow/environments/query-fn-props.js +4 -3
- package/dataflow/environments/resolve-by-name.js +5 -3
- package/dataflow/eval/resolve/node-value.d.ts +1 -1
- package/dataflow/eval/resolve/node-value.js +2 -2
- package/dataflow/eval/resolve/resolve-argument.js +1 -1
- package/dataflow/extractor.js +20 -4
- package/dataflow/graph/df-helper.d.ts +34 -1
- package/dataflow/graph/df-helper.js +60 -0
- package/dataflow/info.d.ts +2 -0
- package/dataflow/info.js +4 -0
- package/dataflow/internal/linker.js +21 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +4 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +3 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +18 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +144 -30
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +10 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +8 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +43 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-env-contents.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-env-contents.js +5 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +67 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +27 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +2 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +1 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +28 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +134 -88
- package/dataflow/internal/process/functions/call/built-in/built-in-load.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-load.js +87 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +8 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +23 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +7 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +28 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +7 -5
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +18 -15
- package/dataflow/internal/process/functions/call/named-call-handling.js +8 -4
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +8 -7
- package/documentation/wiki-dataflow-graph.js +20 -1
- package/linter/rules/undefined-symbol.js +2 -2
- package/package.json +1 -1
- package/project/attached-packages.d.ts +11 -6
- package/project/attached-packages.js +37 -9
- package/queries/catalog/signature-query/signature-query-executor.js +15 -1
- package/queries/catalog/signature-query/signature-query-format.d.ts +3 -2
- package/r-bridge/data/data.d.ts +2 -2
- package/r-bridge/data/data.js +2 -2
- package/r-bridge/lang-4.x/ast/model/model.d.ts +2 -0
- package/r-bridge/lang-4.x/ast/model/model.js +6 -1
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +6 -1
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +12 -1
- package/reconstruct/reconstruct.js +2 -5
- package/search/search-executor/search-enrichers.js +17 -2
- package/search/search-executor/search-generators.js +6 -2
- package/slicing/static/slice-call.d.ts +16 -0
- package/slicing/static/slice-call.js +42 -0
- package/slicing/static/static-slicer.js +6 -0
- package/util/flowr-version.d.ts +1 -1
- package/util/flowr-version.js +2 -2
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processLibrary = processLibrary;
|
|
4
4
|
exports.attachExportVertex = attachExportVertex;
|
|
5
|
+
exports.attachLibrary = attachLibrary;
|
|
5
6
|
exports.loadNodesForNamespace = loadNodesForNamespace;
|
|
7
|
+
exports.processPrefer = processPrefer;
|
|
6
8
|
exports.attachDependencyToEnvironment = attachDependencyToEnvironment;
|
|
7
9
|
exports.attachBaseRNamespaces = attachBaseRNamespaces;
|
|
8
10
|
exports.attachDeclaredDependencies = attachDeclaredDependencies;
|
|
@@ -11,7 +13,7 @@ exports.attachAssumedPackages = attachAssumedPackages;
|
|
|
11
13
|
exports.defineProjectSysdata = defineProjectSysdata;
|
|
12
14
|
exports.attachProject = attachProject;
|
|
13
15
|
const function_semantics_1 = require("../../../../../fn/function-semantics");
|
|
14
|
-
const
|
|
16
|
+
const info_1 = require("../../../../../info");
|
|
15
17
|
const known_call_handling_1 = require("../known-call-handling");
|
|
16
18
|
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
17
19
|
const r_access_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
|
|
@@ -20,6 +22,7 @@ const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/
|
|
|
20
22
|
const node_id_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
21
23
|
const logger_1 = require("../../../../../logger");
|
|
22
24
|
const r_string_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
25
|
+
const r_binary_op_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
|
|
23
26
|
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
|
|
24
27
|
const make_argument_1 = require("../argument/make-argument");
|
|
25
28
|
const frame_memory_1 = require("../../../../../environments/frame-memory");
|
|
@@ -29,8 +32,8 @@ const environment_1 = require("../../../../../environments/environment");
|
|
|
29
32
|
const edge_1 = require("../../../../../graph/edge");
|
|
30
33
|
const assert_1 = require("../../../../../../util/assert");
|
|
31
34
|
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
35
|
+
const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
|
|
32
36
|
const node_value_1 = require("../../../../../eval/resolve/node-value");
|
|
33
|
-
const string_constants_1 = require("../../../../../eval/values/string/string-constants");
|
|
34
37
|
const package_1 = require("../../../../../../project/plugins/package-version-plugins/package");
|
|
35
38
|
const attached_packages_1 = require("../../../../../../project/attached-packages");
|
|
36
39
|
const flowr_namespace_file_1 = require("../../../../../../project/plugins/file-plugins/files/flowr-namespace-file");
|
|
@@ -40,15 +43,10 @@ const r_base_packages_1 = require("../../../../../../util/r-base-packages");
|
|
|
40
43
|
const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
41
44
|
const arrays_1 = require("../../../../../../util/collections/arrays");
|
|
42
45
|
const built_in_load_1 = require("./built-in-load");
|
|
43
|
-
const built_in_ambient_state_1 = require("./built-in-ambient-state");
|
|
44
46
|
/**
|
|
45
47
|
* Process a library call like `library` or `require`
|
|
46
48
|
*/
|
|
47
49
|
function processLibrary(name, args, rootId, data, config = {}) {
|
|
48
|
-
const info = loadPackages(name, args, rootId, data, config);
|
|
49
|
-
return config.ambient === undefined ? info : (0, built_in_ambient_state_1.applyAmbientStateAccess)(info, args, rootId, data, config.ambient);
|
|
50
|
-
}
|
|
51
|
-
function loadPackages(name, args, rootId, data, config) {
|
|
52
50
|
/* we do not really know what loading the library does and what side effects it causes, hence we mark it as an unknown side effect */
|
|
53
51
|
if (args.length === 0) {
|
|
54
52
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, hasUnknownSideEffect: true, origin: 'default' }).information;
|
|
@@ -59,14 +57,16 @@ function loadPackages(name, args, rootId, data, config) {
|
|
|
59
57
|
/* parse the import selection before the library flow rewrites `args` below */
|
|
60
58
|
const parsedSpec = config.fromImports ? parseFromSpec(args) : { namespaceOnly: config.namespaceOnly };
|
|
61
59
|
// 'pos' last, so the positional fallback keeps its previous order; `import::from` has no `pos`, its extra arguments name exports
|
|
62
|
-
const
|
|
60
|
+
const formals = config.packagesInDots
|
|
61
|
+
? { '...': '...', 'character.only': 'char', ...config.evaluatedIn === undefined ? {} : { [config.evaluatedIn]: 'evaluated' } }
|
|
62
|
+
: config.formals !== undefined ? Object.fromEntries(config.formals.map((f, i) => [f, i === 0 ? 'pkg' : '...']))
|
|
63
|
+
: { 'package': 'pkg', 'character.only': 'char', 'pos': 'pos', 'include.only': 'only', 'exclude': 'except' };
|
|
64
|
+
const argMaps = function_semantics_1.FunctionSemantics.call.match.toSpec((0, common_1.convertFnArguments)(args), formals);
|
|
63
65
|
const charId = (0, arrays_1.uniqueArray)(argMaps.get('char') ?? []);
|
|
64
66
|
/* `library(pkg, include.only = "f")` and `exclude = "f"` attach only part of the exports, as `import::from` does */
|
|
65
67
|
const namesIn = (key) => {
|
|
66
68
|
const value = r_argument_1.RArgument.getValue(args, argMaps.get(key)?.[0] ?? '');
|
|
67
|
-
|
|
68
|
-
const elements = value === undefined ? undefined : node_value_1.NodeValue.setOf(value.info.id, data)?.elements.flatMap(v => v.type === 'vector' && (0, r_value_1.isValue)(v.elements) ? v.elements : [v]);
|
|
69
|
-
return elements === undefined ? undefined : (0, string_constants_1.collectStrings)(elements);
|
|
69
|
+
return value === undefined ? undefined : node_value_1.NodeValue.stringsOf(value.info.id, data);
|
|
70
70
|
};
|
|
71
71
|
const only = config.fromImports ? undefined : namesIn('only');
|
|
72
72
|
const except = config.fromImports ? undefined : namesIn('except');
|
|
@@ -76,11 +76,18 @@ function loadPackages(name, args, rootId, data, config) {
|
|
|
76
76
|
...(only !== undefined ? { include: new Map(only.map(n => [n, n])) } : {}),
|
|
77
77
|
...(except !== undefined ? { exclude: new Set(except), all: true } : {})
|
|
78
78
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const given = config.packagesInDots
|
|
80
|
+
? args.filter((a) => a !== r_function_call_1.EmptyArgument && (a.name === undefined || config.namesInDots === true))
|
|
81
|
+
.map(a => a.name ?? a.value)
|
|
82
|
+
: (0, arrays_1.uniqueArray)(argMaps.get('pkg') ?? []).map(v => r_argument_1.RArgument.getValue(args, v));
|
|
83
|
+
/* only a symbol or string literal names a package, `user/repo` names `repo` */
|
|
84
|
+
const namesToLoad = given
|
|
85
|
+
.map(v => config.stripRepo && r_binary_op_1.RBinaryOp.is(v) && v.operator === '/' ? v.rhs : v)
|
|
82
86
|
.filter((v) => v !== undefined && (r_symbol_1.RSymbol.is(v) || r_string_1.RString.is(v)));
|
|
83
|
-
|
|
87
|
+
/* an evaluated argument may be any expression, `c("a", "b")` included */
|
|
88
|
+
const evaluated = config.characterOnly ? given.filter(assert_1.isNotUndefined) : namesToLoad;
|
|
89
|
+
const alwaysEvaluated = (argMaps.get('evaluated') ?? []).map(v => r_argument_1.RArgument.getValue(args, v)).filter(assert_1.isNotUndefined);
|
|
90
|
+
if (evaluated.length === 0 && alwaysEvaluated.length === 0) {
|
|
84
91
|
logger_1.dataflowLogger.warn('No library name provided, skipping');
|
|
85
92
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, hasUnknownSideEffect: true, origin: 'default' }).information;
|
|
86
93
|
}
|
|
@@ -114,10 +121,9 @@ function loadPackages(name, args, rootId, data, config) {
|
|
|
114
121
|
isCharacterOnly = seenMaybe || seenTrue === seenFalse ? 'maybe' : seenTrue;
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}) : [];
|
|
124
|
+
const evaluatedNames = isCharacterOnly ? evaluated.map(n => node_value_1.NodeValue.stringsOf(n.info.id, data)) : [];
|
|
125
|
+
const alwaysEvaluatedNames = alwaysEvaluated.map(n => node_value_1.NodeValue.stringsOf(n.info.id, data));
|
|
126
|
+
const packetName = [...evaluatedNames, ...alwaysEvaluatedNames].flatMap(n => n ?? []);
|
|
121
127
|
if (!isCharacterOnly || isCharacterOnly === 'maybe') {
|
|
122
128
|
// treat as a function call but convert the argument(s) to a string; a quoted literal carries its name in `content.str`, not `lexeme`
|
|
123
129
|
packetName.push(...namesToLoad.map(n => r_string_1.RString.is(n) ? n.content.str : n.lexeme).filter(assert_1.isNotUndefined));
|
|
@@ -128,28 +134,18 @@ function loadPackages(name, args, rootId, data, config) {
|
|
|
128
134
|
location: n.location,
|
|
129
135
|
content: { quotes: 'none', str: identifier_1.Identifier.getName(n.content) }
|
|
130
136
|
});
|
|
131
|
-
args = (0, make_argument_1.wrapArgumentsUnnamed)([...newArgs, ...args.slice(1)], data.completeAst.idMap);
|
|
137
|
+
args = config.packagesInDots ? args : (0, make_argument_1.wrapArgumentsUnnamed)([...newArgs, ...args.slice(1)], data.completeAst.idMap);
|
|
132
138
|
}
|
|
133
139
|
const info = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, hasUnknownSideEffect: false, origin: built_in_proc_name_1.BuiltInProcName.Library }).information;
|
|
134
|
-
for (const p of packetName) {
|
|
140
|
+
for (const p of config.stripRepo ? packetName.map(p => p.replace(/^.*?\//, '')) : packetName) {
|
|
135
141
|
const dependency = data.ctx.deps.loadDependency(p);
|
|
136
|
-
if (dependency) {
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
else if (data.ctx.env.statedFor(p) !== undefined) {
|
|
140
|
-
/* nothing resolved the package's exports, but flowR states what some of its calls mean, so `library()` brings those into scope */
|
|
141
|
-
info.environment = attachStatedDefinitions(p, info.environment, data.ctx, spec, undefined, rootId, data.cds);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
if (!data.ctx.env.knowsPackage(p)) {
|
|
145
|
-
info.graph.markIdForUnknownSideEffects(rootId);
|
|
146
|
-
}
|
|
147
|
-
if (info.environment.level >= 0) {
|
|
148
|
-
info.environment = recordUnresolvedLibraryLoad(info.environment, p, rootId, spec.pos, data.cds);
|
|
149
|
-
}
|
|
142
|
+
if (dependency === undefined && data.ctx.env.statedFor(p) === undefined && !data.ctx.env.knowsPackage(p)) {
|
|
143
|
+
info.graph.markIdForUnknownSideEffects(rootId);
|
|
150
144
|
}
|
|
145
|
+
linkLibrary(p, dependency, info, rootId, data, spec);
|
|
151
146
|
}
|
|
152
|
-
|
|
147
|
+
/* some package we cannot name may be attached */
|
|
148
|
+
if (packetName.length === 0 || (isCharacterOnly === true && evaluatedNames.includes(undefined)) || alwaysEvaluatedNames.includes(undefined)) {
|
|
153
149
|
info.graph.markIdForUnknownSideEffects(rootId);
|
|
154
150
|
}
|
|
155
151
|
return info;
|
|
@@ -236,11 +232,8 @@ function processUse(name, args, rootId, data) {
|
|
|
236
232
|
const info = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, hasUnknownSideEffect: false, origin: built_in_proc_name_1.BuiltInProcName.Library }).information;
|
|
237
233
|
const parsed = parseUseSpec(name, r_argument_1.RArgument.valueOf(args[0]), args, data);
|
|
238
234
|
const dependency = parsed && data.ctx.deps.getDependency(parsed.pack);
|
|
239
|
-
if (parsed && dependency) {
|
|
240
|
-
linkLibrary(dependency, info, rootId, data, parsed.spec);
|
|
241
|
-
}
|
|
242
|
-
else if (parsed && data.ctx.env.statedFor(parsed.pack) !== undefined) {
|
|
243
|
-
info.environment = attachStatedDefinitions(parsed.pack, info.environment, data.ctx, parsed.spec, undefined, rootId, data.cds);
|
|
235
|
+
if (parsed && (dependency || data.ctx.env.statedFor(parsed.pack) !== undefined)) {
|
|
236
|
+
linkLibrary(parsed.pack, dependency, info, rootId, data, parsed.spec);
|
|
244
237
|
}
|
|
245
238
|
else {
|
|
246
239
|
info.graph.markIdForUnknownSideEffects(rootId);
|
|
@@ -284,15 +277,34 @@ function loadMarkerOf(pack, loadedAt, cds) {
|
|
|
284
277
|
}
|
|
285
278
|
/**
|
|
286
279
|
* Record a syntactically known but database-unresolved package load: a bare {@link EnvType.LoadedNamespace} layer
|
|
287
|
-
* carrying only the reserved {@link libraryLoadMarker}, so an explicit `pack::fn` still links back via {@link loadNodesForNamespace}.
|
|
280
|
+
* carrying only the reserved {@link libraryLoadMarker} (if `loadedAt` names the load), so an explicit `pack::fn` still links back via {@link loadNodesForNamespace}.
|
|
288
281
|
*/
|
|
289
|
-
function recordUnresolvedLibraryLoad(envInfo, pack,
|
|
290
|
-
const layer = new environment_1.Environment(envInfo.current).asLibrary(pack, environment_1.EnvType.LoadedNamespace)
|
|
291
|
-
|
|
282
|
+
function recordUnresolvedLibraryLoad(envInfo, pack, loadedAt, pos, cds) {
|
|
283
|
+
const layer = new environment_1.Environment(envInfo.current).asLibrary(pack, environment_1.EnvType.LoadedNamespace);
|
|
284
|
+
const marked = loadedAt === undefined ? layer : layer.define(loadMarkerOf(pack, loadedAt, cds));
|
|
285
|
+
return { level: envInfo.level, current: environment_1.REnvironment.attachAt(envInfo.current, marked, marked, pos) };
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Attaches `pack` as `library(pack)` does: its resolved exports, else what flowR states about it, else a bare
|
|
289
|
+
* {@link EnvType.LoadedNamespace} recording the load. The `library()` processor and `Dataflow.library` both use this.
|
|
290
|
+
*/
|
|
291
|
+
function attachLibrary(pack, dependency, envInfo, ctx, spec = {}, loadedAt, cds) {
|
|
292
|
+
return attachPackage(pack, dependency, envInfo, ctx, spec, loadedAt, cds, new Set());
|
|
293
|
+
}
|
|
294
|
+
/** {@link attachLibrary}; `attaching` holds the packages already being attached, which closes a `Depends` cycle */
|
|
295
|
+
function attachPackage(pack, dependency, envInfo, ctx, spec, loadedAt, cds, attaching) {
|
|
296
|
+
if (dependency?.namespaceInfo !== undefined) {
|
|
297
|
+
return attachResolved(dependency, envInfo, ctx, spec, loadedAt, attaching, cds);
|
|
298
|
+
}
|
|
299
|
+
if (ctx.env.statedFor(pack) !== undefined) {
|
|
300
|
+
return attachStatedDefinitions(pack, envInfo, ctx, spec, undefined, loadedAt, cds);
|
|
301
|
+
}
|
|
302
|
+
return recordUnresolvedLibraryLoad(envInfo, pack, loadedAt, spec.pos, cds);
|
|
292
303
|
}
|
|
293
304
|
/**
|
|
294
|
-
* The load calls (`library()`/`require()`) that brought package `pack` into scope without a
|
|
295
|
-
* the {@link libraryLoadMarker} of every matching {@link EnvType.LoadedNamespace} layer below the
|
|
305
|
+
* The load calls (`library()`/`require()`) that brought package `pack` (any package if not given) into scope without a
|
|
306
|
+
* database, collected from the {@link libraryLoadMarker} of every matching {@link EnvType.LoadedNamespace} layer below the
|
|
307
|
+
* global environment. A call nothing resolves may go to any of them.
|
|
296
308
|
*/
|
|
297
309
|
function loadNodesForNamespace(env, pack) {
|
|
298
310
|
const nodes = [];
|
|
@@ -303,7 +315,7 @@ function loadNodesForNamespace(env, pack) {
|
|
|
303
315
|
if (e.t === undefined) {
|
|
304
316
|
break;
|
|
305
317
|
}
|
|
306
|
-
if (e.n !== pack) {
|
|
318
|
+
if (pack !== undefined && e.n !== pack) {
|
|
307
319
|
continue;
|
|
308
320
|
}
|
|
309
321
|
for (const def of e.memory.get(libraryLoadMarker) ?? []) {
|
|
@@ -315,24 +327,45 @@ function loadNodesForNamespace(env, pack) {
|
|
|
315
327
|
}
|
|
316
328
|
return nodes;
|
|
317
329
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
330
|
+
/**
|
|
331
|
+
* Processes `conflicted::conflict_prefer(name, winner)` and `conflicts_prefer(pkg::fn, ...)`: the preferred function is
|
|
332
|
+
* put on top of the search path, as conflicted does with its `.conflicts` entry, so the name resolves to it from then on.
|
|
333
|
+
*/
|
|
334
|
+
function processPrefer(name, args, rootId, data,
|
|
335
|
+
/* the search path it writes is applied by the registration, see {@link AmbientConfig} */
|
|
336
|
+
_config = {}) {
|
|
337
|
+
const info = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Prefer }).information;
|
|
338
|
+
const values = args.map(a => r_argument_1.RArgument.valueOf(a === r_function_call_1.EmptyArgument ? undefined : a));
|
|
339
|
+
const preferred = values.every(v => r_symbol_1.RSymbol.is(v) && identifier_1.Identifier.getNamespace(v.content) !== undefined)
|
|
340
|
+
? values.map(v => [identifier_1.Identifier.getName(v.content), String(identifier_1.Identifier.getNamespace(v.content))])
|
|
341
|
+
: r_string_1.RString.is(values[0]) && r_string_1.RString.is(values[1]) ? [[values[0].content.str, values[1].content.str]] : [];
|
|
342
|
+
if (preferred.length === 0) {
|
|
343
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(info.graph, info.environment, rootId);
|
|
344
|
+
return info;
|
|
345
|
+
}
|
|
346
|
+
for (const [fn, pkg] of preferred) {
|
|
347
|
+
const conflicts = new environment_1.Environment(info.environment.current);
|
|
348
|
+
conflicts.adoptMap(lazyExports(pkg, [{ exported: fn, as: fn }], data.ctx, rootId, data.cds));
|
|
349
|
+
conflicts.t = environment_1.EnvType.Attached;
|
|
350
|
+
conflicts.n = '.conflicts';
|
|
351
|
+
info.environment = { ...info.environment, current: environment_1.REnvironment.attachAt(info.environment.current, conflicts, conflicts) };
|
|
321
352
|
}
|
|
322
|
-
|
|
353
|
+
return info;
|
|
354
|
+
}
|
|
355
|
+
function linkLibrary(pack, dependency, info, rootId, data, spec = {}) {
|
|
323
356
|
// re-loading an already attached package is a no-op, cf. R's `search()`
|
|
324
|
-
if (isAttached(info.environment.current, pack, spec.namespaceOnly)) {
|
|
357
|
+
if (isAttached(info.environment.current, pack, spec.namespaceOnly, data.cds)) {
|
|
325
358
|
return;
|
|
326
359
|
}
|
|
327
360
|
// by default only the environment carries the exports, materializing a vertex on demand (see attachExportVertex); eager mode registers them all upfront
|
|
328
|
-
if (data.ctx.config.solver.sigdb.eagerlyLoadExports) {
|
|
361
|
+
if (dependency?.namespaceInfo !== undefined && data.ctx.config.solver.sigdb.eagerlyLoadExports) {
|
|
329
362
|
for (const { exported: func } of selectExports((0, flowr_namespace_file_1.getCallables)(dependency.namespaceInfo), spec)) {
|
|
330
363
|
const builtInId = node_id_1.NodeId.fromPkgFn(pack, func);
|
|
331
364
|
attachExportVertex(info.graph, builtInId, info.environment, data.ctx, data.cds);
|
|
332
365
|
info.graph.addEdge(builtInId, rootId, edge_1.EdgeType.Reads | edge_1.EdgeType.Calls);
|
|
333
366
|
}
|
|
334
367
|
}
|
|
335
|
-
info.environment =
|
|
368
|
+
info.environment = attachLibrary(pack, dependency, info.environment, data.ctx, spec, rootId, data.cds);
|
|
336
369
|
}
|
|
337
370
|
/** The exports of `callables` to attach under `spec` (see {@link AttachSpec}), resolving selection and aliasing. */
|
|
338
371
|
function selectExports(callables, spec) {
|
|
@@ -346,21 +379,22 @@ function selectExports(callables, spec) {
|
|
|
346
379
|
* What a package's attached layer binds, built per name on the first lookup. An attach names thousands of exports
|
|
347
380
|
* and a script mentions a few dozen, so the definitions are only made for the ones something asks about.
|
|
348
381
|
*/
|
|
349
|
-
function lazyExports(pack, exports, ctx, definedAt) {
|
|
382
|
+
function lazyExports(pack, exports, ctx, definedAt, cds) {
|
|
350
383
|
const byName = new Map(exports.map(exp => [identifier_1.Identifier.getName(identifier_1.Identifier.make(exp.as, pack)), exp]));
|
|
351
384
|
const aliases = exports.filter(exp => exp.as !== exp.exported).map(exp => `${exp.as}=${exp.exported}`);
|
|
352
|
-
return new frame_memory_1.LazyBindings(new Set(byName.keys()), name => [exportDefinition(pack, byName.get(name), ctx, definedAt)], `${pack}|${String(definedAt)}|${aliases.join(',')}`);
|
|
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)}`);
|
|
353
386
|
}
|
|
354
387
|
/**
|
|
355
388
|
* The identifier definition binding a package export (or its alias) to its built-in function-definition.
|
|
356
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.
|
|
357
390
|
*/
|
|
358
|
-
function exportDefinition(pack, exp, ctx, definedAt = node_id_1.NodeId.toBuiltIn(pack)) {
|
|
391
|
+
function exportDefinition(pack, exp, ctx, definedAt = node_id_1.NodeId.toBuiltIn(pack), cds) {
|
|
359
392
|
const identity = {
|
|
360
393
|
name: identifier_1.Identifier.make(exp.as, pack),
|
|
361
394
|
type: identifier_1.ReferenceType.Function,
|
|
362
395
|
nodeId: node_id_1.NodeId.fromPkgFn(pack, exp.exported),
|
|
363
396
|
definedAt,
|
|
397
|
+
...(cds === undefined ? {} : { cds: cds.slice() })
|
|
364
398
|
};
|
|
365
399
|
/* an export named like a primitive is a method registered for it (lubridate's `$`), the primitive still evaluates the call */
|
|
366
400
|
const exported = identifier_1.Identifier.make(exp.exported);
|
|
@@ -377,39 +411,47 @@ function exportDefinition(pack, exp, ctx, definedAt = node_id_1.NodeId.toBuiltIn
|
|
|
377
411
|
* returns the enriched environment (graph untouched). Used by `library()`, `import::from`, `box::use`, `requireNamespace`, and transitive side-effect propagation.
|
|
378
412
|
*/
|
|
379
413
|
function attachDependencyToEnvironment(dependency, envInfo, ctx, spec = {}, definedAt) {
|
|
414
|
+
return attachResolved(dependency, envInfo, ctx, spec, definedAt, new Set(), undefined);
|
|
415
|
+
}
|
|
416
|
+
/** {@link attachDependencyToEnvironment}, see {@link attachPackage} for `attaching` */
|
|
417
|
+
function attachResolved(dependency, envInfo, ctx, spec, definedAt, attaching, cds) {
|
|
380
418
|
const pack = dependency.name;
|
|
381
|
-
if (isAttached(envInfo.current, pack, spec.namespaceOnly)) {
|
|
419
|
+
if (isAttached(envInfo.current, pack, spec.namespaceOnly, cds)) {
|
|
382
420
|
return envInfo;
|
|
383
421
|
}
|
|
384
|
-
if (spec.pos === undefined && !spec.namespaceOnly) {
|
|
385
|
-
const startup = startupAttachPosition(pack, envInfo.current);
|
|
386
|
-
if (startup !== undefined) {
|
|
387
|
-
spec = { ...spec, pos: startup };
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
422
|
if ((0, assert_1.isUndefined)(dependency.namespaceInfo)) {
|
|
391
423
|
/* nothing resolved the package's exports, but what flowR states about them is still what a call means, and `library()` brings it into scope */
|
|
392
|
-
return attachStatedDefinitions(pack, envInfo, ctx, spec);
|
|
424
|
+
return attachStatedDefinitions(pack, envInfo, ctx, withStartupPosition(pack, envInfo, spec), undefined, undefined, cds);
|
|
393
425
|
}
|
|
394
426
|
const exports = selectExports((0, flowr_namespace_file_1.getCallables)(dependency.namespaceInfo), spec);
|
|
395
|
-
// a subset import restricts the attached exports, so no imports layer is materialized
|
|
427
|
+
// a subset import restricts the attached exports, so no imports layer is materialized and, as in R, nothing is attached alongside
|
|
396
428
|
if (spec.namespaceOnly || (spec.include !== undefined && !spec.all)) {
|
|
429
|
+
spec = withStartupPosition(pack, envInfo, spec);
|
|
397
430
|
const layerType = spec.namespaceOnly ? environment_1.EnvType.LoadedNamespace : environment_1.EnvType.Namespace;
|
|
398
431
|
const layer = new environment_1.Environment(envInfo.current).asLibrary(pack, layerType);
|
|
399
|
-
layer.adoptMap(lazyExports(pack, exports, ctx, definedAt));
|
|
432
|
+
layer.adoptMap(lazyExports(pack, exports, ctx, definedAt, cds));
|
|
400
433
|
return { level: envInfo.level, current: environment_1.REnvironment.attachAt(envInfo.current, layer, layer, spec.pos) };
|
|
401
434
|
}
|
|
435
|
+
/* as R does: the Depends first (at the default position, whatever `pos` says), then `pack`, then what its `.onAttach` attaches */
|
|
436
|
+
const { depends, onAttach } = (0, attached_packages_1.attachedAlongside)(pack, ctx.deps.signatureSources(), dependency.resolvedVersion);
|
|
437
|
+
const within = new Set([...attaching, pack]);
|
|
438
|
+
const alongside = (env, packs) => packs.filter(p => !within.has(p))
|
|
439
|
+
.reduce((e, p) => attachPackage(p, ctx.deps.getDependency(p), e, ctx, {}, definedAt, cds, within), env);
|
|
440
|
+
const below = alongside(envInfo, depends);
|
|
402
441
|
// full attach: imports layer at the bottom, namespace (exports) layer on top
|
|
403
|
-
|
|
404
|
-
importsEnv = recImports(importsEnv, dependency.namespaceInfo, ctx, new Set());
|
|
442
|
+
const importsEnv = imports(new environment_1.Environment(below.current).asLibrary(pack, environment_1.EnvType.Imports), dependency.namespaceInfo, ctx);
|
|
405
443
|
const namespaceEnv = new environment_1.Environment(importsEnv).asLibrary(pack, environment_1.EnvType.Namespace);
|
|
406
|
-
namespaceEnv.adoptMap(lazyExports(pack, exports, ctx, definedAt));
|
|
407
|
-
const attached = { level:
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
444
|
+
namespaceEnv.adoptMap(lazyExports(pack, exports, ctx, definedAt, cds));
|
|
445
|
+
const attached = { level: below.level, current: environment_1.REnvironment.attachAt(below.current, namespaceEnv, importsEnv, withStartupPosition(pack, below, spec).pos) };
|
|
446
|
+
return alongside(attached, onAttach);
|
|
447
|
+
}
|
|
448
|
+
/** `spec` with the position R gives a startup package, unless a position is given, see {@link startupAttachPosition} */
|
|
449
|
+
function withStartupPosition(pack, envInfo, spec) {
|
|
450
|
+
if (spec.pos !== undefined || spec.namespaceOnly) {
|
|
451
|
+
return spec;
|
|
452
|
+
}
|
|
453
|
+
const startup = startupAttachPosition(pack, envInfo.current);
|
|
454
|
+
return startup === undefined ? spec : { ...spec, pos: startup };
|
|
413
455
|
}
|
|
414
456
|
/** A namespace-only load is subsumed by any layer for `pack`; a full attach ignores a mere {@link EnvType.LoadedNamespace}. */
|
|
415
457
|
function blocksAttach(layer, namespaceOnly) {
|
|
@@ -452,17 +494,23 @@ function startupAttachPosition(pack, env) {
|
|
|
452
494
|
return pos;
|
|
453
495
|
}
|
|
454
496
|
/** Whether package `pack` is already attached below the global env in a way that makes this (re-)attach a no-op. */
|
|
455
|
-
function isAttached(env, pack, namespaceOnly) {
|
|
497
|
+
function isAttached(env, pack, namespaceOnly, cds) {
|
|
456
498
|
for (const e of environment_1.REnvironment.searchPath(env)) {
|
|
457
499
|
if (e.t === undefined) {
|
|
458
500
|
break;
|
|
459
501
|
}
|
|
460
|
-
|
|
502
|
+
/* a sure attach repeats one that only maybe happened */
|
|
503
|
+
if (e.n === pack && e.t !== environment_1.EnvType.Imports && blocksAttach(e, namespaceOnly) && (attachedInEveryBranch(e) || !(0, info_1.happensInEveryBranch)(cds))) {
|
|
461
504
|
return true;
|
|
462
505
|
}
|
|
463
506
|
}
|
|
464
507
|
return false;
|
|
465
508
|
}
|
|
509
|
+
/** Whether the layer was attached unconditionally; all its bindings share the cds of the attach, so the first one tells. */
|
|
510
|
+
function attachedInEveryBranch(layer) {
|
|
511
|
+
const first = layer.memory.keys().next();
|
|
512
|
+
return first.done === true || (layer.memory.get(first.value)?.every(d => (0, info_1.happensInEveryBranch)(d.cds)) ?? true);
|
|
513
|
+
}
|
|
466
514
|
/** Immutable base-layer chains, shared across analyses (layers clone before mutating); building one is O(N^2) in exports, so cache and reparent. */
|
|
467
515
|
const baseNamespaceLayerCache = new Map();
|
|
468
516
|
function baseNamespaceCacheKey(ctx, basePackages) {
|
|
@@ -557,12 +605,13 @@ function attachStatedDefinitions(pack, envInfo, ctx, spec, as, loadedAt, cds) {
|
|
|
557
605
|
}
|
|
558
606
|
/* the same no-op R's `search()` makes of a second `library(pack)`; without it a project calling it once per
|
|
559
607
|
* file stacked one layer per call, which every later name resolution then walked through */
|
|
560
|
-
if (isAttached(envInfo.current, pack, spec.namespaceOnly)) {
|
|
608
|
+
if (isAttached(envInfo.current, pack, spec.namespaceOnly, cds)) {
|
|
561
609
|
return envInfo;
|
|
562
610
|
}
|
|
563
611
|
/* keyed as the configuration states them: a replacement is bound under `f<-`, which its `name` does not say */
|
|
564
|
-
const
|
|
565
|
-
: [...stated].filter(([key]) => (spec.all || spec.include === undefined || spec.include.has(key)) && !spec.exclude?.has(key))
|
|
612
|
+
const selected = spec.include === undefined && spec.exclude === undefined ? [...stated]
|
|
613
|
+
: [...stated].filter(([key]) => (spec.all || spec.include === undefined || spec.include.has(key)) && !spec.exclude?.has(key));
|
|
614
|
+
const memory = new Map(cds === undefined ? selected : selected.map(([key, defs]) => [key, defs.map(d => ({ ...d, cds: cds.slice() }))]));
|
|
566
615
|
if (loadedAt !== undefined) {
|
|
567
616
|
/* the marker an unresolved load leaves behind, so a call links back to the `library()` that made it resolve */
|
|
568
617
|
memory.set(libraryLoadMarker, [loadMarkerOf(pack, loadedAt, cds)]);
|
|
@@ -624,11 +673,12 @@ function defineProjectSysdata(env, ctx) {
|
|
|
624
673
|
function attachProject(env, ctx) {
|
|
625
674
|
return defineProjectSysdata(attachAssumedPackages(attachDeclaredDependencies(attachProjectImports(attachBaseRNamespaces(env, ctx), ctx), ctx), ctx), ctx);
|
|
626
675
|
}
|
|
627
|
-
function
|
|
676
|
+
function imports(importsEnv, namespaceInfo, ctx) {
|
|
677
|
+
/* only what the NAMESPACE imports, not what those packages import in turn */
|
|
628
678
|
for (const [pkg, imported] of namespaceInfo.importedPackages) {
|
|
629
679
|
const importedDependency = ctx.deps.getDependency(pkg);
|
|
630
680
|
const importedNs = importedDependency?.namespaceInfo;
|
|
631
|
-
if (importedDependency === undefined || importedNs === undefined
|
|
681
|
+
if (importedDependency === undefined || importedNs === undefined) {
|
|
632
682
|
continue;
|
|
633
683
|
}
|
|
634
684
|
/* collect first and define in one go, as defining one by one copies the (growing) memory every time */
|
|
@@ -652,10 +702,6 @@ function recImports(importsEnv, namespaceInfo, ctx, alreadyImportedAll) {
|
|
|
652
702
|
if (toDefine.length > 0) {
|
|
653
703
|
importsEnv = importsEnv.defineAll(toDefine);
|
|
654
704
|
}
|
|
655
|
-
if (imported === 'all') {
|
|
656
|
-
alreadyImportedAll.add(importedDependency.name);
|
|
657
|
-
importsEnv = recImports(importsEnv, importedNs, ctx, alreadyImportedAll);
|
|
658
|
-
}
|
|
659
705
|
}
|
|
660
706
|
return importsEnv;
|
|
661
707
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
|
|
2
2
|
import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
3
3
|
import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
4
4
|
import type { DataflowProcessorInformation } from '../../../../../processor';
|
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.processLoadCall = processLoadCall;
|
|
4
4
|
exports.sexpTypeToReferenceType = sexpTypeToReferenceType;
|
|
5
5
|
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
6
|
+
const r_symbol_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
7
|
+
const resolve_helper_1 = require("../../../../../environments/resolve-helper");
|
|
8
|
+
const ambient_state_name_1 = require("../../../../../environments/ambient-state-name");
|
|
9
|
+
const info_1 = require("../../../../../info");
|
|
10
|
+
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
6
11
|
const function_semantics_1 = require("../../../../../fn/function-semantics");
|
|
7
12
|
const known_call_handling_1 = require("../known-call-handling");
|
|
8
13
|
const identifier_1 = require("../../../../../environments/identifier");
|
|
@@ -79,20 +84,93 @@ function processLoadCall(name, args, rootId, data) {
|
|
|
79
84
|
if (variables.length === 0) {
|
|
80
85
|
return fn.information;
|
|
81
86
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
const named = variables.filter((v) => v.name !== undefined);
|
|
88
|
+
return withLoaded(named, rootId, fn, [...(data.cds ?? []), { id: rootId, when: true, file: filepath }], data, envirResolution);
|
|
89
|
+
}
|
|
90
|
+
/* a file the program saves itself holds the variables it saved */
|
|
91
|
+
const saved = savedInto(sourceFile, data);
|
|
92
|
+
if (saved !== undefined) {
|
|
93
|
+
const loaded = withLoaded(saved.names.map(n => ({ name: n })), rootId, fn, [...(data.cds ?? []), { id: rootId, when: true }], data, envirResolution);
|
|
94
|
+
if (!saved.complete) {
|
|
95
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(loaded.graph, loaded.environment, rootId);
|
|
89
96
|
}
|
|
90
|
-
return
|
|
97
|
+
return loaded;
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
100
|
(0, unknown_side_effect_1.handleUnknownSideEffect)(fn.information.graph, fn.information.environment, rootId);
|
|
94
101
|
return fn.information;
|
|
95
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* The variables the `save()` calls that wrote the files at `paths` stored, and whether that is all the files may hold
|
|
105
|
+
* (every writer surely ran, so no older content remains); `undefined` if another call may have written them or a
|
|
106
|
+
* name is unknown.
|
|
107
|
+
*/
|
|
108
|
+
function savedInto(paths, data) {
|
|
109
|
+
const names = new Set();
|
|
110
|
+
let complete = true;
|
|
111
|
+
for (const path of paths) {
|
|
112
|
+
const stem = r_string_1.RString.unquote(path).split(/[/\\]/).at(-1)?.split('.')[0];
|
|
113
|
+
const writers = stem ? resolve_helper_1.Resolve.byName(ambient_state_name_1.AmbientStateName.file(stem), data.environment) : undefined;
|
|
114
|
+
if (writers === undefined || writers.length === 0) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
for (const writer of writers) {
|
|
118
|
+
const call = data.completeAst.idMap.get(writer.nodeId);
|
|
119
|
+
const stored = r_function_call_1.RFunctionCall.isNamed(call, 'save') ? namesSavedBy(call.arguments, data) : undefined;
|
|
120
|
+
if (stored === undefined) {
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
stored.forEach(n => names.add(n));
|
|
124
|
+
complete &&= (0, info_1.happensInEveryBranch)(writer.cds);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { names: [...names], complete };
|
|
128
|
+
}
|
|
129
|
+
/** The variables `save(...)` names: its unnamed symbols and strings, and the strings `list` holds; `undefined` if one is unknown. */
|
|
130
|
+
function namesSavedBy(args, data) {
|
|
131
|
+
const names = [];
|
|
132
|
+
for (const arg of args) {
|
|
133
|
+
if (arg === r_function_call_1.EmptyArgument || arg.value === undefined) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const named = arg.name === undefined ? undefined : identifier_1.Identifier.getName(arg.name.content);
|
|
137
|
+
if (named === 'list') {
|
|
138
|
+
const listed = node_value_1.NodeValue.stringsOf(arg.value.info.id, data);
|
|
139
|
+
if (listed === undefined) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
names.push(...listed);
|
|
143
|
+
}
|
|
144
|
+
else if (named === undefined) {
|
|
145
|
+
if (r_symbol_1.RSymbol.is(arg.value)) {
|
|
146
|
+
names.push(identifier_1.Identifier.getName(arg.value.content));
|
|
147
|
+
}
|
|
148
|
+
else if (r_string_1.RString.is(arg.value)) {
|
|
149
|
+
names.push(arg.value.content.str);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return names;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The load call `rootId` with the `variables` it restores defined, in the caller's frame or, given `envir`, in the
|
|
160
|
+
* environment it names (routed there like any other write into it, so the caller keeps its own bindings).
|
|
161
|
+
*/
|
|
162
|
+
function withLoaded(variables, rootId, fn, loadCds, data, envir) {
|
|
163
|
+
const location = data.completeAst.idMap.get(rootId)?.location ?? range_1.SourceRange.invalid();
|
|
164
|
+
let environment = fn.information.environment;
|
|
165
|
+
const out = [...fn.information.out];
|
|
166
|
+
for (const variable of variables) {
|
|
167
|
+
const [next, defined] = defineLoadedVariable(variable, rootId, fn, environment, location, loadCds, data);
|
|
168
|
+
environment = next;
|
|
169
|
+
out.push(defined);
|
|
170
|
+
}
|
|
171
|
+
const result = { ...fn.information, environment, out };
|
|
172
|
+
return envir === undefined ? result : (0, built_in_envir_utils_1.routeWrittenToEnvir)(result, envir, rootId, data.environment, rootId);
|
|
173
|
+
}
|
|
96
174
|
function defineLoadedVariable(variable, rootId, fn, envir, loadLocation, loadCds, data) {
|
|
97
175
|
const syntheticId = `${rootId}:loaded:${variable.name}`;
|
|
98
176
|
const isClosure = variable.type === flowr_rda_file_1.SexpType.CloSxp;
|
|
@@ -127,8 +205,7 @@ function defineLoadedVariable(variable, rootId, fn, envir, loadLocation, loadCds
|
|
|
127
205
|
definedAt: rootId,
|
|
128
206
|
cds: loadCds,
|
|
129
207
|
};
|
|
130
|
-
|
|
131
|
-
return { ...envir, current: newCurrent };
|
|
208
|
+
return [{ ...envir, current: envir.current.define(nodeToDefine) }, nodeToDefine];
|
|
132
209
|
}
|
|
133
210
|
function defineLoadedClosure(syntheticId, variable, fn, envir, loadLocation, loadCds, data, rootInfo) {
|
|
134
211
|
const fdefId = `${syntheticId}:fdef`;
|
|
@@ -4,6 +4,8 @@ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/
|
|
|
4
4
|
import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
|
|
5
5
|
import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
|
|
6
6
|
import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
|
+
import { type EnvirResolution } from './built-in-envir-utils';
|
|
8
|
+
import type { RNode } from '../../../../../../r-bridge/lang-4.x/ast/model/model';
|
|
7
9
|
export interface LocalFunctionConfiguration {
|
|
8
10
|
args: {
|
|
9
11
|
/** The expression in `local(expr, env)` */
|
|
@@ -14,3 +16,9 @@ export interface LocalFunctionConfiguration {
|
|
|
14
16
|
}
|
|
15
17
|
/** Processes a built-in 'local' function call. */
|
|
16
18
|
export declare function processLocal<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config: LocalFunctionConfiguration): DataflowInformation;
|
|
19
|
+
/**
|
|
20
|
+
* Evaluates `expr` in the environment `envir` pins down, or in a fresh frame on top of the current one, as `local`
|
|
21
|
+
* and `eval(expr, envir)` do. The search path is global, so what `expr` attaches stays, and of a fresh frame only
|
|
22
|
+
* what escaped it (e.g., via `<<-`) remains.
|
|
23
|
+
*/
|
|
24
|
+
export declare function evaluateInEnvir<OtherInfo>(expr: RNode<OtherInfo & ParentInformation>, envir: EnvirResolution<OtherInfo> | undefined, rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
|