@eagleoutice/flowr 2.15.2 → 2.15.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 +20 -20
- package/dataflow/environments/environment.d.ts +28 -13
- package/dataflow/environments/environment.js +62 -23
- package/dataflow/environments/frame-memory.d.ts +84 -0
- package/dataflow/environments/frame-memory.js +241 -0
- package/dataflow/environments/query-fn-props.d.ts +39 -2
- package/dataflow/environments/query-fn-props.js +98 -12
- package/dataflow/environments/resolve-by-name.js +28 -9
- package/dataflow/graph/graph.d.ts +18 -4
- package/dataflow/graph/graph.js +101 -64
- package/dataflow/graph/vertex.js +1 -1
- package/dataflow/internal/linker.js +9 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +19 -5
- package/dataflow/internal/process/functions/call/common.js +6 -2
- package/dataflow/internal/process/functions/call/known-call-handling.js +1 -1
- package/dataflow/internal/process/functions/call/quoted.js +1 -1
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +1 -1
- package/dataflow/internal/process/functions/process-argument.js +1 -1
- package/dataflow/internal/process/process-symbol.js +1 -1
- package/index.d.ts +2 -0
- package/index.js +4 -1
- package/linter/linter-rules.d.ts +9 -9
- package/package.json +1 -1
- package/project/context/flowr-analyzer-environment-context.d.ts +6 -0
- package/project/context/flowr-analyzer-environment-context.js +4 -2
- package/project/flowr-analyzer.d.ts +13 -0
- package/project/flowr-analyzer.js +5 -0
- package/project/sigdb/reader.js +44 -13
- package/project/sigdb/signature-db.d.ts +3 -0
- package/project/sigdb/signature-db.js +5 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.js +4 -5
- package/queries/catalog/signature-query/signature-query-format.d.ts +1 -2
- package/slicing/static/fingerprint.js +7 -2
- package/util/collections/bimap.d.ts +2 -1
- package/util/collections/bimap.js +4 -4
- package/util/version.js +2 -2
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ It offers a wide variety of features, for example:
|
|
|
47
47
|
|
|
48
48
|
```shell
|
|
49
49
|
$ docker run -it --rm eagleoutice/flowr # or npm run flowr
|
|
50
|
-
flowR repl v2.15.
|
|
50
|
+
flowR repl v2.15.2, R grammar v14 (tree-sitter engine)
|
|
51
51
|
R> :query @linter "read.csv(\"/root/x.txt\")"
|
|
52
52
|
```
|
|
53
53
|
|
|
@@ -56,7 +56,7 @@ It offers a wide variety of features, for example:
|
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
```text
|
|
59
|
-
Query: linter (
|
|
59
|
+
Query: linter (9 ms)
|
|
60
60
|
╰ Deprecated Functions (deprecated-functions): no findings
|
|
61
61
|
╰ File Path Validity (file-path-validity): no findings
|
|
62
62
|
╰ Seeded Randomness (seeded-randomness): no findings
|
|
@@ -74,7 +74,7 @@ It offers a wide variety of features, for example:
|
|
|
74
74
|
╰ Unused Import (unused-import): no findings
|
|
75
75
|
╰ Unclosed Connection (unclosed-connection): no findings
|
|
76
76
|
╰ Unescaped Arguments (unescaped-arguments): no findings
|
|
77
|
-
All queries together required ≈
|
|
77
|
+
All queries together required ≈9 ms (1ms accuracy, total 9 ms)
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
|
|
@@ -96,7 +96,7 @@ It offers a wide variety of features, for example:
|
|
|
96
96
|
|
|
97
97
|
_Results (prettified and summarized):_
|
|
98
98
|
|
|
99
|
-
Query: **linter** (
|
|
99
|
+
Query: **linter** (16 ms)\
|
|
100
100
|
╰ **Deprecated Functions** (deprecated-functions): _no findings_\
|
|
101
101
|
╰ **File Path Validity** (file-path-validity):\
|
|
102
102
|
╰ certain:\
|
|
@@ -106,7 +106,7 @@ It offers a wide variety of features, for example:
|
|
|
106
106
|
╰ **Absolute Paths** (absolute-file-paths):\
|
|
107
107
|
╰ certain:\
|
|
108
108
|
╰ Path `/root/x.txt` at 1.1-23\
|
|
109
|
-
╰ _Metadata_: totalConsidered: 1, totalUnknown: 0, searchTimeMs:
|
|
109
|
+
╰ _Metadata_: totalConsidered: 1, totalUnknown: 0, searchTimeMs: 1, processTimeMs: 0\
|
|
110
110
|
╰ **Unused Definitions** (unused-definitions): _no findings_\
|
|
111
111
|
╰ **Network Functions** (network-functions): _no findings_\
|
|
112
112
|
╰ **Dataframe Access Validation** (dataframe-access-validation): _no findings_\
|
|
@@ -120,11 +120,11 @@ It offers a wide variety of features, for example:
|
|
|
120
120
|
╰ **Unused Import** (unused-import): _no findings_\
|
|
121
121
|
╰ **Unclosed Connection** (unclosed-connection): _no findings_\
|
|
122
122
|
╰ **Unescaped Arguments** (unescaped-arguments): _no findings_\
|
|
123
|
-
_All queries together required ≈
|
|
123
|
+
_All queries together required ≈16 ms (1ms accuracy, total 17 ms)_
|
|
124
124
|
|
|
125
125
|
<details> <summary style="color:gray">Show Detailed Results as Json</summary>
|
|
126
126
|
|
|
127
|
-
The analysis required
|
|
127
|
+
The analysis required _17.1 ms_ (including parsing and normalization and the query) within the generation environment.
|
|
128
128
|
|
|
129
129
|
In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR.
|
|
130
130
|
Please consult the [Interface](https://github.com/flowr-analysis/flowr/wiki/Interface) wiki page for more information on how to get those.
|
|
@@ -141,7 +141,7 @@ It offers a wide variety of features, for example:
|
|
|
141
141
|
".meta": {
|
|
142
142
|
"builtin": 0,
|
|
143
143
|
"sigdb": 0,
|
|
144
|
-
"searchTimeMs":
|
|
144
|
+
"searchTimeMs": 1,
|
|
145
145
|
"processTimeMs": 1
|
|
146
146
|
}
|
|
147
147
|
},
|
|
@@ -176,7 +176,7 @@ It offers a wide variety of features, for example:
|
|
|
176
176
|
"callsWithAssignmentProducers": 0,
|
|
177
177
|
"callsWithNonConstantProducers": 0,
|
|
178
178
|
"callsWithOtherBranchProducers": 0,
|
|
179
|
-
"searchTimeMs":
|
|
179
|
+
"searchTimeMs": 0,
|
|
180
180
|
"processTimeMs": 0
|
|
181
181
|
}
|
|
182
182
|
},
|
|
@@ -196,7 +196,7 @@ It offers a wide variety of features, for example:
|
|
|
196
196
|
".meta": {
|
|
197
197
|
"totalConsidered": 1,
|
|
198
198
|
"totalUnknown": 0,
|
|
199
|
-
"searchTimeMs":
|
|
199
|
+
"searchTimeMs": 1,
|
|
200
200
|
"processTimeMs": 0
|
|
201
201
|
}
|
|
202
202
|
},
|
|
@@ -224,13 +224,13 @@ It offers a wide variety of features, for example:
|
|
|
224
224
|
"numAccesses": 0,
|
|
225
225
|
"totalAccessed": 0,
|
|
226
226
|
"searchTimeMs": 0,
|
|
227
|
-
"processTimeMs":
|
|
227
|
+
"processTimeMs": 0
|
|
228
228
|
}
|
|
229
229
|
},
|
|
230
230
|
"dead-code": {
|
|
231
231
|
"results": [],
|
|
232
232
|
".meta": {
|
|
233
|
-
"searchTimeMs":
|
|
233
|
+
"searchTimeMs": 1,
|
|
234
234
|
"processTimeMs": 0
|
|
235
235
|
}
|
|
236
236
|
},
|
|
@@ -285,7 +285,7 @@ It offers a wide variety of features, for example:
|
|
|
285
285
|
"subscript": 0
|
|
286
286
|
},
|
|
287
287
|
"searchTimeMs": 0,
|
|
288
|
-
"processTimeMs":
|
|
288
|
+
"processTimeMs": 8
|
|
289
289
|
}
|
|
290
290
|
},
|
|
291
291
|
"unused-import": {
|
|
@@ -319,11 +319,11 @@ It offers a wide variety of features, for example:
|
|
|
319
319
|
}
|
|
320
320
|
},
|
|
321
321
|
".meta": {
|
|
322
|
-
"timing":
|
|
322
|
+
"timing": 16
|
|
323
323
|
}
|
|
324
324
|
},
|
|
325
325
|
".meta": {
|
|
326
|
-
"timing":
|
|
326
|
+
"timing": 16
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
```
|
|
@@ -389,7 +389,7 @@ It offers a wide variety of features, for example:
|
|
|
389
389
|
|
|
390
390
|
```shell
|
|
391
391
|
$ docker run -it --rm eagleoutice/flowr # or npm run flowr
|
|
392
|
-
flowR repl v2.15.
|
|
392
|
+
flowR repl v2.15.2, R grammar v14 (tree-sitter engine)
|
|
393
393
|
R> :query @static-slice (11@sum) file://test/testfiles/example.R
|
|
394
394
|
```
|
|
395
395
|
|
|
@@ -403,7 +403,7 @@ It offers a wide variety of features, for example:
|
|
|
403
403
|
N <- 10
|
|
404
404
|
for(i in 1:(N-1)) sum <- sum + i + w
|
|
405
405
|
sum
|
|
406
|
-
All queries together required ≈
|
|
406
|
+
All queries together required ≈4 ms (1ms accuracy, total 4 ms)
|
|
407
407
|
```
|
|
408
408
|
|
|
409
409
|
|
|
@@ -418,7 +418,7 @@ It offers a wide variety of features, for example:
|
|
|
418
418
|
</details>
|
|
419
419
|
|
|
420
420
|
* 🚀 **fast call-graph, data-, and control-flow graphs**\
|
|
421
|
-
Within just [<i><span title="This measurement is automatically fetched from the latest benchmark!">
|
|
421
|
+
Within just [<i><span title="This measurement is automatically fetched from the latest benchmark!">101.9 ms</span></i> (as of Aug 26, 2026)](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark),
|
|
422
422
|
_flowR_ can analyze the data- and control-flow of the average real-world R script. See the [benchmarks](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark) for more information,
|
|
423
423
|
and consult the [wiki pages](https://github.com/flowr-analysis/flowr/wiki/Dataflow-Graph) for more details on the [dataflow graphs](https://github.com/flowr-analysis/flowr/wiki/Dataflow-Graph) as well as [call graphs](https://github.com/flowr-analysis/flowr/wiki/Dataflow-Graph#perspectives-cg).
|
|
424
424
|
( [▶ Explore in Browser](https://flowr-analysis.github.io/flowr/wiki/playground/#c=zDYSwRgTghhCeAUATADsWECUAoLBnAxlMAKYD6ALgPakC2UAHgAQA8AtIwGYCuAdvuSEo949DIyYB6RnXojsWaAHdGKlW0aIo5KADoO0GsXghEjALyMAjAC4AbABpGANyJdi5xvngBmRwA5HAHZHACZHAE5HABYMbHwSKB5VdQ4QYHJiCHglRxdgN0YAPkYQuISeABICImJTdWqSCmoZeHjiRIq8t3lcLho6OFJcbXJcFnZe-pgQXCM2xMdDRI8l4Qba2KxeLlnEJu1gNQm%2B7KhFTtdieUUIEAydfFwneEmB2CGR3EcAIleYWAeT2%2B2FQlHIrXKVUIJEQIMoIB4owh7UqJgwQA&p=13:1 "run this script in flowR's playground, no setup") )
|
|
@@ -456,7 +456,7 @@ It offers a wide variety of features, for example:
|
|
|
456
456
|
|
|
457
457
|
```shell
|
|
458
458
|
$ docker run -it --rm eagleoutice/flowr # or npm run flowr
|
|
459
|
-
flowR repl v2.15.
|
|
459
|
+
flowR repl v2.15.2, R grammar v14 (tree-sitter engine)
|
|
460
460
|
R> :dataflow* test/testfiles/example.R
|
|
461
461
|
```
|
|
462
462
|
|
|
@@ -765,7 +765,7 @@ It offers a wide variety of features, for example:
|
|
|
765
765
|
```
|
|
766
766
|
|
|
767
767
|
|
|
768
|
-
(The analysis required
|
|
768
|
+
(The analysis required _2.8 ms_ (including parse and normalize, using the [tree-sitter](https://github.com/flowr-analysis/flowr/wiki/Engines) engine) within the generation environment. No [signature database](https://github.com/flowr-analysis/flowr/wiki/Signature-Database) is mounted for these generated graphs, so `library()` calls attach no package exports; base-R names are still qualified via the generated base-package store (e.g. `acf` as `stats::acf`).)
|
|
769
769
|
|
|
770
770
|
|
|
771
771
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { BuiltInMemory } from './built-in';
|
|
2
|
-
import type { IdentifierDefinition } from './identifier';
|
|
2
|
+
import type { BrandedIdentifier, IdentifierDefinition } from './identifier';
|
|
3
3
|
import { Identifier } from './identifier';
|
|
4
4
|
import type { ControlDependency } from '../info';
|
|
5
|
+
import { Frame, MemoryView, WritableMemory } from './frame-memory';
|
|
5
6
|
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
6
7
|
/** A single entry/scope within an {@link REnvironmentInformation} */
|
|
7
8
|
export interface IEnvironment {
|
|
@@ -10,7 +11,7 @@ export interface IEnvironment {
|
|
|
10
11
|
/** Lexical parent of the environment, if any (can be manipulated by R code) */
|
|
11
12
|
parent: IEnvironment;
|
|
12
13
|
/** Maps to exactly one definition of an identifier if the source is known, otherwise to a list of all possible definitions */
|
|
13
|
-
memory:
|
|
14
|
+
memory: MemoryView;
|
|
14
15
|
/** Built-in environment that must not change; only for the top-most envs. */
|
|
15
16
|
builtInEnv?: true | undefined;
|
|
16
17
|
}
|
|
@@ -26,7 +27,7 @@ interface Jsonified {
|
|
|
26
27
|
id: NodeId;
|
|
27
28
|
parent: Jsonified | undefined;
|
|
28
29
|
builtInEnv?: true;
|
|
29
|
-
memory:
|
|
30
|
+
memory: ReadonlyMap<BrandedIdentifier, IdentifierDefinition[]>;
|
|
30
31
|
n?: string;
|
|
31
32
|
t?: EnvType;
|
|
32
33
|
globalEnv?: true;
|
|
@@ -43,26 +44,33 @@ export declare class Environment implements IEnvironment {
|
|
|
43
44
|
/** if created by a closure, the node id of that closure */
|
|
44
45
|
private c?;
|
|
45
46
|
parent: Environment;
|
|
46
|
-
|
|
47
|
+
/** the frame this environment's names live in, shared with every other snapshot of it */
|
|
48
|
+
private frame;
|
|
49
|
+
/** the version of {@link frame} this environment sees */
|
|
50
|
+
private fv;
|
|
51
|
+
private view?;
|
|
52
|
+
private writable?;
|
|
47
53
|
cache?: Map<Identifier, IdentifierDefinition[]>;
|
|
54
|
+
/** what a resolution found below this frame, by target and name; only frames nothing writes keep one */
|
|
55
|
+
tailCache?: Map<string, readonly IdentifierDefinition[] | undefined>;
|
|
48
56
|
builtInEnv?: true;
|
|
49
|
-
/** {@link memory}
|
|
57
|
+
/** {@link memory} may be seen by another snapshot, so a write has to take a version of its own first */
|
|
50
58
|
private sharedMemory?;
|
|
51
59
|
/** {@link parent} is shared with the environment this was cloned from; writing through it needs {@link writableParent} */
|
|
52
60
|
private sharedParent?;
|
|
53
61
|
/** marks the global environment (`.GlobalEnv`); attached packages (see {@link EnvType}) live below it */
|
|
54
62
|
globalEnv?: true;
|
|
55
63
|
/** What the lexical frame this stands in for held when its closure was created; `<<-` binds lexically, so defining super needs this. */
|
|
56
|
-
superMemory?:
|
|
64
|
+
superMemory?: MemoryView;
|
|
57
65
|
/** What the configuration states about packages R does not attach on startup, by package; only the built-in env carries it (see {@link statedIn}). */
|
|
58
66
|
namespaces?: ReadonlyMap<string, BuiltInMemory>;
|
|
59
|
-
constructor(parent: Environment, isBuiltInDefault?: true | undefined,
|
|
67
|
+
constructor(parent: Environment, isBuiltInDefault?: true | undefined, frame?: Frame, version?: number);
|
|
60
68
|
/** Marks this as an attached-package layer (see {@link EnvType}) for package `name`. */
|
|
61
69
|
asLibrary(name: string, type: EnvType): this;
|
|
62
70
|
/** Marks this as the global environment (`.GlobalEnv`); see {@link globalEnv}. */
|
|
63
71
|
asGlobal(): this;
|
|
64
72
|
/** Records the lexical frame this one stands in for; see {@link superMemory}. */
|
|
65
|
-
standsInFor(memory:
|
|
73
|
+
standsInFor(memory: MemoryView): this;
|
|
66
74
|
/** please only use if you know what you are doing */
|
|
67
75
|
setClosureNodeId(nodeId: NodeId): void;
|
|
68
76
|
/** Provides the closure linked to this environment. */
|
|
@@ -72,11 +80,18 @@ export declare class Environment implements IEnvironment {
|
|
|
72
80
|
* and lets it materialize one frame at a time here, since a removal usually reaches only a frame or two.
|
|
73
81
|
*/
|
|
74
82
|
get writableParent(): Environment;
|
|
75
|
-
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
/** What the frame binds at the version this sees; a snapshot, not a copy. */
|
|
84
|
+
get memory(): MemoryView;
|
|
85
|
+
/** Whether `other` holds the very bindings this does. */
|
|
86
|
+
sameMemoryAs(other: Environment): boolean;
|
|
87
|
+
/** What `name` holds here. {@link memory}'s answer without the view, for the chain walks of name resolution. */
|
|
88
|
+
lookup(name: BrandedIdentifier): IdentifierDefinition[] | undefined;
|
|
89
|
+
/** the bindings as a plain map where one is at hand, so a merge copies map from map */
|
|
90
|
+
private get copyableMemory();
|
|
91
|
+
/** Takes `map` as the bindings, sharing it until something writes. */
|
|
92
|
+
adoptMap(map: ReadonlyMap<BrandedIdentifier, IdentifierDefinition[]>): void;
|
|
93
|
+
/** {@link memory} ready to be written to; every write goes through this, so the first takes a version of its own. */
|
|
94
|
+
get writableMemory(): WritableMemory;
|
|
80
95
|
/**
|
|
81
96
|
* Clones this environment, sharing {@link memory} until either side writes to it (see {@link writableMemory}); cloning
|
|
82
97
|
* is therefore independent of how many definitions a frame holds, which matters for packages with thousands of them.
|
|
@@ -12,6 +12,7 @@ const identifier_1 = require("./identifier");
|
|
|
12
12
|
const assert_1 = require("../../util/assert");
|
|
13
13
|
const info_1 = require("../info");
|
|
14
14
|
const append_1 = require("./append");
|
|
15
|
+
const frame_memory_1 = require("./frame-memory");
|
|
15
16
|
const log_1 = require("../../util/log");
|
|
16
17
|
var EnvType;
|
|
17
18
|
(function (EnvType) {
|
|
@@ -37,10 +38,17 @@ class Environment {
|
|
|
37
38
|
/** if created by a closure, the node id of that closure */
|
|
38
39
|
c;
|
|
39
40
|
parent;
|
|
40
|
-
|
|
41
|
+
/** the frame this environment's names live in, shared with every other snapshot of it */
|
|
42
|
+
frame;
|
|
43
|
+
/** the version of {@link frame} this environment sees */
|
|
44
|
+
fv;
|
|
45
|
+
view;
|
|
46
|
+
writable;
|
|
41
47
|
cache;
|
|
48
|
+
/** what a resolution found below this frame, by target and name; only frames nothing writes keep one */
|
|
49
|
+
tailCache;
|
|
42
50
|
builtInEnv;
|
|
43
|
-
/** {@link memory}
|
|
51
|
+
/** {@link memory} may be seen by another snapshot, so a write has to take a version of its own first */
|
|
44
52
|
sharedMemory;
|
|
45
53
|
/** {@link parent} is shared with the environment this was cloned from; writing through it needs {@link writableParent} */
|
|
46
54
|
sharedParent;
|
|
@@ -50,11 +58,15 @@ class Environment {
|
|
|
50
58
|
superMemory;
|
|
51
59
|
/** What the configuration states about packages R does not attach on startup, by package; only the built-in env carries it (see {@link statedIn}). */
|
|
52
60
|
namespaces;
|
|
53
|
-
constructor(parent, isBuiltInDefault = undefined,
|
|
61
|
+
constructor(parent, isBuiltInDefault = undefined, frame, version) {
|
|
54
62
|
this.id = isBuiltInDefault ? 0 : environmentIdCounter++;
|
|
55
63
|
this.parent = parent;
|
|
56
|
-
|
|
57
|
-
this.
|
|
64
|
+
this.frame = frame ?? frame_memory_1.Frame.empty();
|
|
65
|
+
this.fv = version ?? this.frame.version;
|
|
66
|
+
if (frame === undefined) {
|
|
67
|
+
/* the shared empty frame, so the first write forks it */
|
|
68
|
+
this.sharedMemory = true;
|
|
69
|
+
}
|
|
58
70
|
// do not store if not needed!
|
|
59
71
|
if (isBuiltInDefault) {
|
|
60
72
|
this.builtInEnv = isBuiltInDefault;
|
|
@@ -97,16 +109,43 @@ class Environment {
|
|
|
97
109
|
}
|
|
98
110
|
return this.parent;
|
|
99
111
|
}
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
/** What the frame binds at the version this sees; a snapshot, not a copy. */
|
|
113
|
+
get memory() {
|
|
114
|
+
return this.view ??= new frame_memory_1.MemoryView(this.frame, this.fv);
|
|
115
|
+
}
|
|
116
|
+
/** Whether `other` holds the very bindings this does. */
|
|
117
|
+
sameMemoryAs(other) {
|
|
118
|
+
return this === other || (this.frame === other.frame && this.fv === other.fv);
|
|
119
|
+
}
|
|
120
|
+
/** What `name` holds here. {@link memory}'s answer without the view, for the chain walks of name resolution. */
|
|
121
|
+
lookup(name) {
|
|
122
|
+
const frame = this.frame;
|
|
123
|
+
return this.fv === frame.version ? frame.live.get(name) : frame.get(name, this.fv);
|
|
124
|
+
}
|
|
125
|
+
/** the bindings as a plain map where one is at hand, so a merge copies map from map */
|
|
126
|
+
get copyableMemory() {
|
|
127
|
+
return this.frame.settledAt(this.fv) ?? this.memory;
|
|
128
|
+
}
|
|
129
|
+
/** Takes `map` as the bindings, sharing it until something writes. */
|
|
130
|
+
adoptMap(map) {
|
|
131
|
+
this.frame = frame_memory_1.Frame.of(map);
|
|
132
|
+
this.fv = this.frame.version;
|
|
133
|
+
this.view = undefined;
|
|
134
|
+
this.writable = undefined;
|
|
135
|
+
/* the map belongs to whoever handed it over, so the first write forks */
|
|
136
|
+
this.sharedMemory = true;
|
|
137
|
+
}
|
|
138
|
+
/** {@link memory} ready to be written to; every write goes through this, so the first takes a version of its own. */
|
|
104
139
|
get writableMemory() {
|
|
140
|
+
this.tailCache = undefined;
|
|
105
141
|
if (this.sharedMemory) {
|
|
106
|
-
this.
|
|
142
|
+
this.frame = this.frame.forWrite(this.fv);
|
|
143
|
+
this.fv = this.frame.nextVersion();
|
|
107
144
|
this.sharedMemory = undefined;
|
|
145
|
+
this.view = undefined;
|
|
146
|
+
this.writable = undefined;
|
|
108
147
|
}
|
|
109
|
-
return this.
|
|
148
|
+
return this.writable ??= new frame_memory_1.WritableMemory(this.frame, this.fv);
|
|
110
149
|
}
|
|
111
150
|
/**
|
|
112
151
|
* Clones this environment, sharing {@link memory} until either side writes to it (see {@link writableMemory}); cloning
|
|
@@ -116,7 +155,7 @@ class Environment {
|
|
|
116
155
|
if (this.builtInEnv) {
|
|
117
156
|
return this; // do not clone the built-in environment
|
|
118
157
|
}
|
|
119
|
-
const clone = new Environment(this.parent, this.builtInEnv, this.
|
|
158
|
+
const clone = new Environment(this.parent, this.builtInEnv, this.frame, this.fv);
|
|
120
159
|
clone.c = this.c;
|
|
121
160
|
clone.n = this.n;
|
|
122
161
|
clone.t = this.t;
|
|
@@ -163,7 +202,7 @@ class Environment {
|
|
|
163
202
|
this.writableMemory.set(name, [definition]);
|
|
164
203
|
}
|
|
165
204
|
else {
|
|
166
|
-
const existing = this.
|
|
205
|
+
const existing = this.lookup(name);
|
|
167
206
|
const inGraphDefinition = definition;
|
|
168
207
|
if (existing !== undefined &&
|
|
169
208
|
inGraphDefinition.cds === undefined) {
|
|
@@ -227,7 +266,7 @@ class Environment {
|
|
|
227
266
|
do {
|
|
228
267
|
/* `<<-` binds in the closest enclosing frame that holds the name, which for an emptied frame is what
|
|
229
268
|
* it stood in for when the closure was created (see {@link superMemory}) */
|
|
230
|
-
if (current.
|
|
269
|
+
if (current.lookup(name) !== undefined || current.superMemory?.has(name)) {
|
|
231
270
|
current.writableMemory.set(name, [definition]);
|
|
232
271
|
found = true;
|
|
233
272
|
break;
|
|
@@ -257,7 +296,7 @@ class Environment {
|
|
|
257
296
|
if (shortcut !== undefined) {
|
|
258
297
|
return shortcut;
|
|
259
298
|
}
|
|
260
|
-
const map = new Map(this.
|
|
299
|
+
const map = new Map(this.copyableMemory);
|
|
261
300
|
for (const [key, values] of other.memory) {
|
|
262
301
|
const hasMaybe = applyCds === undefined ? values.length === 0 || values.some(v => v.cds !== undefined) : true;
|
|
263
302
|
if (hasMaybe) {
|
|
@@ -295,7 +334,7 @@ class Environment {
|
|
|
295
334
|
out.t = this.t;
|
|
296
335
|
out.globalEnv = this.globalEnv;
|
|
297
336
|
out.superMemory = this.superMemory ?? other.superMemory;
|
|
298
|
-
out.
|
|
337
|
+
out.adoptMap(map);
|
|
299
338
|
return out;
|
|
300
339
|
}
|
|
301
340
|
/** Adds all writes of `other` to this environment (`other`'s operations *might* happen). Always recurses parents. */
|
|
@@ -307,7 +346,7 @@ class Environment {
|
|
|
307
346
|
if (shortcut !== undefined) {
|
|
308
347
|
return shortcut;
|
|
309
348
|
}
|
|
310
|
-
const map = new Map(this.
|
|
349
|
+
const map = new Map(this.copyableMemory);
|
|
311
350
|
for (const [key, value] of other.memory) {
|
|
312
351
|
const old = map.get(key);
|
|
313
352
|
if (old) {
|
|
@@ -323,7 +362,7 @@ class Environment {
|
|
|
323
362
|
out.t = this.t;
|
|
324
363
|
out.globalEnv = this.globalEnv;
|
|
325
364
|
out.superMemory = this.superMemory ?? other.superMemory;
|
|
326
|
-
out.
|
|
365
|
+
out.adoptMap(map);
|
|
327
366
|
return out;
|
|
328
367
|
}
|
|
329
368
|
/**
|
|
@@ -376,7 +415,7 @@ class Environment {
|
|
|
376
415
|
byName.set(layer.n, cloned);
|
|
377
416
|
order.push(cloned);
|
|
378
417
|
}
|
|
379
|
-
else if (existing.
|
|
418
|
+
else if (!existing.sameMemoryAs(layer)) {
|
|
380
419
|
for (const [name, value] of layer.memory) {
|
|
381
420
|
const old = existing.memory.get(name);
|
|
382
421
|
if (old !== value) {
|
|
@@ -397,7 +436,7 @@ class Environment {
|
|
|
397
436
|
this.writableParent.remove(id);
|
|
398
437
|
return this;
|
|
399
438
|
}
|
|
400
|
-
const definition = this.
|
|
439
|
+
const definition = this.lookup(name);
|
|
401
440
|
let cont = true;
|
|
402
441
|
if (definition !== undefined) {
|
|
403
442
|
this.writableMemory.delete(name);
|
|
@@ -425,11 +464,11 @@ class Environment {
|
|
|
425
464
|
id: this.id,
|
|
426
465
|
parent: this.parent,
|
|
427
466
|
builtInEnv: this.builtInEnv,
|
|
428
|
-
memory: this.memory,
|
|
467
|
+
memory: new Map(this.memory),
|
|
429
468
|
} : {
|
|
430
469
|
id: this.id,
|
|
431
470
|
parent: this.parent,
|
|
432
|
-
memory: this.memory,
|
|
471
|
+
memory: new Map(this.memory),
|
|
433
472
|
// markers needed to rebuild the search path after a round-trip (undefined values are dropped by JSON.stringify)
|
|
434
473
|
n: this.n,
|
|
435
474
|
t: this.t,
|
|
@@ -543,7 +582,7 @@ function layersEndWith(layers, tail) {
|
|
|
543
582
|
}
|
|
544
583
|
for (let i = 0; i < tail.length; i++) {
|
|
545
584
|
const l = layers[offset + i], t = tail[i];
|
|
546
|
-
if (l !== t && (l.t !== t.t || l.n !== t.n || l.
|
|
585
|
+
if (l !== t && (l.t !== t.t || l.n !== t.n || !l.sameMemoryAs(t))) {
|
|
547
586
|
return false;
|
|
548
587
|
}
|
|
549
588
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One environment frame's bindings, shared by every snapshot of it: a snapshot is the frame plus a version, not a
|
|
3
|
+
* copy. Copying instead cost a whole map per snapshot, and a call vertex keeps one, so a scope with thousands of
|
|
4
|
+
* definitions retained memory in the square of them. The newest version is answered from a plain map, an older one
|
|
5
|
+
* from what the writes recorded.
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { BrandedIdentifier, IdentifierDefinition } from './identifier';
|
|
9
|
+
/**
|
|
10
|
+
* One frame's bindings across its versions. A frame {@link Frame.of|taken from a map} is frozen: one state, never
|
|
11
|
+
* written, versioned only once {@link forWrite} forks it -- the built-in environment and the package layers.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Frame {
|
|
14
|
+
/** the bindings at {@link version} and no other, so read it only after checking the version, as {@link get} does */
|
|
15
|
+
readonly live: Map<BrandedIdentifier, IdentifierDefinition[]>;
|
|
16
|
+
/** whether {@link live} is this frame's own to write, see {@link Frame.of} */
|
|
17
|
+
private readonly frozen;
|
|
18
|
+
/** what each *rewritten* name held per version, for older snapshots; built on the first rewrite, as most see none */
|
|
19
|
+
private history;
|
|
20
|
+
/** when each name still on its first binding came in; a write-once name needs no more, and most are */
|
|
21
|
+
private bornAt;
|
|
22
|
+
/** the last past version walked out into a map, so re-reading that snapshot skips the walk; one slot only */
|
|
23
|
+
private walked;
|
|
24
|
+
/** the newest version written here, counting this frame's writes alone; only a snapshot at it may extend the frame */
|
|
25
|
+
version: number;
|
|
26
|
+
private constructor();
|
|
27
|
+
/** A frame holding what `map` holds, frozen: only read through here, a write forks rather than reaching back. */
|
|
28
|
+
static of(map: ReadonlyMap<BrandedIdentifier, IdentifierDefinition[]>): Frame;
|
|
29
|
+
/** A frame holding nothing, the same one every time, so an environment that defines nothing allocates nothing. */
|
|
30
|
+
static empty(): Frame;
|
|
31
|
+
/** What `name` held at `version`. One lookup for the newest version, small enough for V8 to inline. */
|
|
32
|
+
get(name: BrandedIdentifier, version: number): IdentifierDefinition[] | undefined;
|
|
33
|
+
/** What `name` held at a version written past since. */
|
|
34
|
+
private bound;
|
|
35
|
+
/** Whether `name` was bound at `version`. */
|
|
36
|
+
has(name: BrandedIdentifier, version: number): boolean;
|
|
37
|
+
/** The names `version` binds. */
|
|
38
|
+
keys(version: number): MapIterator<BrandedIdentifier>;
|
|
39
|
+
/** What `version` binds, without the names. */
|
|
40
|
+
values(version: number): MapIterator<IdentifierDefinition[]>;
|
|
41
|
+
/** How many names `version` binds. */
|
|
42
|
+
size(version: number): number;
|
|
43
|
+
/** What `version` binds, name by name. */
|
|
44
|
+
entries(version: number): MapIterator<[BrandedIdentifier, IdentifierDefinition[]]>;
|
|
45
|
+
/**
|
|
46
|
+
* `version` as a map, `undefined` when it has to be walked out. A frame that never rewrote or took on a name has
|
|
47
|
+
* held the same bindings throughout, so {@link live} answers for any version of it.
|
|
48
|
+
*/
|
|
49
|
+
settledAt(version: number): ReadonlyMap<BrandedIdentifier, IdentifierDefinition[]> | undefined;
|
|
50
|
+
/** `version` walked out into a map, kept in the {@link walked} slot. */
|
|
51
|
+
private materialize;
|
|
52
|
+
/** What `version` bound; the rewritten names come first, since one dropped since is no longer in {@link live}. */
|
|
53
|
+
private recorded;
|
|
54
|
+
/** The frame a snapshot at `version` writes to: this one if it holds the newest version, a fork otherwise. */
|
|
55
|
+
forWrite(version: number): Frame;
|
|
56
|
+
/** The version the next write goes to; only a frame {@link forWrite} just returned may hand one out. */
|
|
57
|
+
nextVersion(): number;
|
|
58
|
+
/** Binds `name` at `version`, `undefined` removing it. Only the newest version may be written; snapshots hold the rest. */
|
|
59
|
+
set(name: BrandedIdentifier, defs: IdentifierDefinition[] | undefined, version: number): void;
|
|
60
|
+
}
|
|
61
|
+
/** One environment's view of its {@link Frame}, as a {@link ReadonlyMap} so the old readers of the map still work. */
|
|
62
|
+
export declare class MemoryView implements ReadonlyMap<BrandedIdentifier, IdentifierDefinition[]> {
|
|
63
|
+
readonly frame: Frame;
|
|
64
|
+
readonly version: number;
|
|
65
|
+
constructor(frame: Frame, version: number);
|
|
66
|
+
get(name: BrandedIdentifier): IdentifierDefinition[] | undefined;
|
|
67
|
+
has(name: BrandedIdentifier): boolean;
|
|
68
|
+
get size(): number;
|
|
69
|
+
entries(): MapIterator<[BrandedIdentifier, IdentifierDefinition[]]>;
|
|
70
|
+
[Symbol.iterator](): MapIterator<[BrandedIdentifier, IdentifierDefinition[]]>;
|
|
71
|
+
keys(): MapIterator<BrandedIdentifier>;
|
|
72
|
+
values(): MapIterator<IdentifierDefinition[]>;
|
|
73
|
+
forEach(fn: (defs: IdentifierDefinition[], name: BrandedIdentifier, map: ReadonlyMap<BrandedIdentifier, IdentifierDefinition[]>) => void, thisArg?: unknown): void;
|
|
74
|
+
}
|
|
75
|
+
/** The write end of a {@link Frame} at one version, standing in for the map writers used to get. */
|
|
76
|
+
export declare class WritableMemory {
|
|
77
|
+
private readonly frame;
|
|
78
|
+
private readonly version;
|
|
79
|
+
constructor(frame: Frame, version: number);
|
|
80
|
+
set(name: BrandedIdentifier, defs: IdentifierDefinition[]): void;
|
|
81
|
+
delete(name: BrandedIdentifier): void;
|
|
82
|
+
get(name: BrandedIdentifier): IdentifierDefinition[] | undefined;
|
|
83
|
+
has(name: BrandedIdentifier): boolean;
|
|
84
|
+
}
|