@eagleoutice/flowr 2.15.3 → 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/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/resolve-by-name.js +28 -9
- package/dataflow/graph/graph.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +19 -5
- package/package.json +1 -1
- package/project/context/flowr-analyzer-environment-context.js +2 -2
- package/project/sigdb/reader.js +44 -13
- package/queries/catalog/input-sources-query/simple-input-classifier.js +4 -5
- package/slicing/static/fingerprint.js +7 -2
- package/util/version.js +2 -2
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* One environment frame's bindings, shared by every snapshot of it: a snapshot is the frame plus a version, not a
|
|
4
|
+
* copy. Copying instead cost a whole map per snapshot, and a call vertex keeps one, so a scope with thousands of
|
|
5
|
+
* definitions retained memory in the square of them. The newest version is answered from a plain map, an older one
|
|
6
|
+
* from what the writes recorded.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.WritableMemory = exports.MemoryView = exports.Frame = void 0;
|
|
11
|
+
const assert_1 = require("../../util/assert");
|
|
12
|
+
/** the index in `history` of what the greatest version at most `version` bound, `-1` if unbound then */
|
|
13
|
+
function at(history, version) {
|
|
14
|
+
let low = 0;
|
|
15
|
+
let high = (history.length >> 1) - 1;
|
|
16
|
+
while (low <= high) {
|
|
17
|
+
const mid = (low + high) >> 1;
|
|
18
|
+
if (history[mid << 1] <= version) {
|
|
19
|
+
low = mid + 1;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
high = mid - 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return high < 0 ? -1 : (high << 1) + 1;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One frame's bindings across its versions. A frame {@link Frame.of|taken from a map} is frozen: one state, never
|
|
29
|
+
* written, versioned only once {@link forWrite} forks it -- the built-in environment and the package layers.
|
|
30
|
+
*/
|
|
31
|
+
class Frame {
|
|
32
|
+
/** the bindings at {@link version} and no other, so read it only after checking the version, as {@link get} does */
|
|
33
|
+
live;
|
|
34
|
+
/** whether {@link live} is this frame's own to write, see {@link Frame.of} */
|
|
35
|
+
frozen;
|
|
36
|
+
/** what each *rewritten* name held per version, for older snapshots; built on the first rewrite, as most see none */
|
|
37
|
+
history;
|
|
38
|
+
/** when each name still on its first binding came in; a write-once name needs no more, and most are */
|
|
39
|
+
bornAt;
|
|
40
|
+
/** the last past version walked out into a map, so re-reading that snapshot skips the walk; one slot only */
|
|
41
|
+
walked;
|
|
42
|
+
/** the newest version written here, counting this frame's writes alone; only a snapshot at it may extend the frame */
|
|
43
|
+
version = 0;
|
|
44
|
+
constructor(live, frozen) {
|
|
45
|
+
this.live = live;
|
|
46
|
+
this.frozen = frozen;
|
|
47
|
+
}
|
|
48
|
+
/** A frame holding what `map` holds, frozen: only read through here, a write forks rather than reaching back. */
|
|
49
|
+
static of(map) {
|
|
50
|
+
return new Frame(map, true);
|
|
51
|
+
}
|
|
52
|
+
/** A frame holding nothing, the same one every time, so an environment that defines nothing allocates nothing. */
|
|
53
|
+
static empty() {
|
|
54
|
+
return EmptyFrame;
|
|
55
|
+
}
|
|
56
|
+
/** What `name` held at `version`. One lookup for the newest version, small enough for V8 to inline. */
|
|
57
|
+
get(name, version) {
|
|
58
|
+
return version === this.version ? this.live.get(name) : this.bound(name, version);
|
|
59
|
+
}
|
|
60
|
+
/** What `name` held at a version written past since. */
|
|
61
|
+
bound(name, version) {
|
|
62
|
+
const history = this.history?.get(name);
|
|
63
|
+
if (history !== undefined) {
|
|
64
|
+
const index = at(history, version);
|
|
65
|
+
return index < 0 ? undefined : history[index];
|
|
66
|
+
}
|
|
67
|
+
const born = this.bornAt?.get(name);
|
|
68
|
+
/* never rewritten, so it still holds what it held then -- unless it came in after then */
|
|
69
|
+
return born !== undefined && born > version ? undefined : this.live.get(name);
|
|
70
|
+
}
|
|
71
|
+
/** Whether `name` was bound at `version`. */
|
|
72
|
+
has(name, version) {
|
|
73
|
+
return (version === this.version ? this.live.get(name) : this.bound(name, version)) !== undefined;
|
|
74
|
+
}
|
|
75
|
+
/** The names `version` binds. */
|
|
76
|
+
keys(version) {
|
|
77
|
+
return (this.settledAt(version) ?? this.materialize(version)).keys();
|
|
78
|
+
}
|
|
79
|
+
/** What `version` binds, without the names. */
|
|
80
|
+
values(version) {
|
|
81
|
+
return (this.settledAt(version) ?? this.materialize(version)).values();
|
|
82
|
+
}
|
|
83
|
+
/** How many names `version` binds. */
|
|
84
|
+
size(version) {
|
|
85
|
+
return (this.settledAt(version) ?? this.materialize(version)).size;
|
|
86
|
+
}
|
|
87
|
+
/** What `version` binds, name by name. */
|
|
88
|
+
entries(version) {
|
|
89
|
+
return (this.settledAt(version) ?? this.materialize(version)).entries();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* `version` as a map, `undefined` when it has to be walked out. A frame that never rewrote or took on a name has
|
|
93
|
+
* held the same bindings throughout, so {@link live} answers for any version of it.
|
|
94
|
+
*/
|
|
95
|
+
settledAt(version) {
|
|
96
|
+
if (version === this.version || (this.history === undefined && this.bornAt === undefined)) {
|
|
97
|
+
return this.live;
|
|
98
|
+
}
|
|
99
|
+
const walked = this.walked;
|
|
100
|
+
return walked !== undefined && walked.version === version ? walked.bindings : undefined;
|
|
101
|
+
}
|
|
102
|
+
/** `version` walked out into a map, kept in the {@link walked} slot. */
|
|
103
|
+
materialize(version) {
|
|
104
|
+
const bindings = new Map(this.recorded(version));
|
|
105
|
+
this.walked = { version, bindings };
|
|
106
|
+
return bindings;
|
|
107
|
+
}
|
|
108
|
+
/** What `version` bound; the rewritten names come first, since one dropped since is no longer in {@link live}. */
|
|
109
|
+
*recorded(version) {
|
|
110
|
+
const history = this.history;
|
|
111
|
+
if (history !== undefined) {
|
|
112
|
+
for (const name of history.keys()) {
|
|
113
|
+
const defs = this.bound(name, version);
|
|
114
|
+
if (defs !== undefined) {
|
|
115
|
+
yield [name, defs];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const [name, defs] of this.live) {
|
|
120
|
+
if (history?.has(name)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const born = this.bornAt?.get(name);
|
|
124
|
+
if (born === undefined || born <= version) {
|
|
125
|
+
yield [name, defs];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** The frame a snapshot at `version` writes to: this one if it holds the newest version, a fork otherwise. */
|
|
130
|
+
forWrite(version) {
|
|
131
|
+
if (!this.frozen && version === this.version) {
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
return new Frame(new Map(this.settledAt(version) ?? this.materialize(version)), false);
|
|
135
|
+
}
|
|
136
|
+
/** The version the next write goes to; only a frame {@link forWrite} just returned may hand one out. */
|
|
137
|
+
nextVersion() {
|
|
138
|
+
(0, assert_1.guard)(!this.frozen, 'a frozen frame hands out no version, fork it with forWrite first');
|
|
139
|
+
return ++this.version;
|
|
140
|
+
}
|
|
141
|
+
/** Binds `name` at `version`, `undefined` removing it. Only the newest version may be written; snapshots hold the rest. */
|
|
142
|
+
set(name, defs, version) {
|
|
143
|
+
const live = this.live;
|
|
144
|
+
(0, assert_1.guard)(!this.frozen && version === this.version, () => `cannot write version ${version} of a frame standing at ${this.version}`);
|
|
145
|
+
const history = this.history?.get(name);
|
|
146
|
+
if (history !== undefined) {
|
|
147
|
+
if (history[history.length - 2] === version) {
|
|
148
|
+
history[history.length - 1] = defs;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
history.push(version, defs);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const before = live.get(name);
|
|
156
|
+
const born = this.bornAt?.get(name);
|
|
157
|
+
if (before === undefined && born === undefined) {
|
|
158
|
+
/* never held here, so when it came in is all an older snapshot needs */
|
|
159
|
+
(this.bornAt ??= new Map()).set(name, version);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
/* record what it is replacing before the write buries it */
|
|
163
|
+
this.bornAt?.delete(name);
|
|
164
|
+
(this.history ??= new Map()).set(name, [born ?? 0, before, version, defs]);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (defs === undefined) {
|
|
168
|
+
live.delete(name);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
live.set(name, defs);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.Frame = Frame;
|
|
176
|
+
/** what every environment starts out on, until a write forks it one of its own */
|
|
177
|
+
const EmptyFrame = Frame.of(new Map());
|
|
178
|
+
/** One environment's view of its {@link Frame}, as a {@link ReadonlyMap} so the old readers of the map still work. */
|
|
179
|
+
class MemoryView {
|
|
180
|
+
frame;
|
|
181
|
+
version;
|
|
182
|
+
constructor(frame, version) {
|
|
183
|
+
this.frame = frame;
|
|
184
|
+
this.version = version;
|
|
185
|
+
}
|
|
186
|
+
get(name) {
|
|
187
|
+
return this.frame.get(name, this.version);
|
|
188
|
+
}
|
|
189
|
+
has(name) {
|
|
190
|
+
return this.frame.has(name, this.version);
|
|
191
|
+
}
|
|
192
|
+
get size() {
|
|
193
|
+
return this.frame.size(this.version);
|
|
194
|
+
}
|
|
195
|
+
entries() {
|
|
196
|
+
return this.frame.entries(this.version);
|
|
197
|
+
}
|
|
198
|
+
[Symbol.iterator]() {
|
|
199
|
+
return this.frame.entries(this.version);
|
|
200
|
+
}
|
|
201
|
+
keys() {
|
|
202
|
+
return this.frame.keys(this.version);
|
|
203
|
+
}
|
|
204
|
+
values() {
|
|
205
|
+
return this.frame.values(this.version);
|
|
206
|
+
}
|
|
207
|
+
forEach(fn, thisArg) {
|
|
208
|
+
const settled = this.frame.settledAt(this.version);
|
|
209
|
+
if (settled !== undefined) {
|
|
210
|
+
settled.forEach(fn, thisArg);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
for (const [name, defs] of this.frame.entries(this.version)) {
|
|
214
|
+
fn.call(thisArg, defs, name, this);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.MemoryView = MemoryView;
|
|
219
|
+
/** The write end of a {@link Frame} at one version, standing in for the map writers used to get. */
|
|
220
|
+
class WritableMemory {
|
|
221
|
+
frame;
|
|
222
|
+
version;
|
|
223
|
+
constructor(frame, version) {
|
|
224
|
+
this.frame = frame;
|
|
225
|
+
this.version = version;
|
|
226
|
+
}
|
|
227
|
+
set(name, defs) {
|
|
228
|
+
this.frame.set(name, defs, this.version);
|
|
229
|
+
}
|
|
230
|
+
delete(name) {
|
|
231
|
+
this.frame.set(name, undefined, this.version);
|
|
232
|
+
}
|
|
233
|
+
get(name) {
|
|
234
|
+
return this.frame.get(name, this.version);
|
|
235
|
+
}
|
|
236
|
+
has(name) {
|
|
237
|
+
return this.frame.has(name, this.version);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.WritableMemory = WritableMemory;
|
|
241
|
+
//# sourceMappingURL=frame-memory.js.map
|
|
@@ -85,11 +85,24 @@ function resolveByTargetType(id, environment, target) {
|
|
|
85
85
|
/* `current` can already be the built-in environment itself (e.g. `get(x, envir=baseenv())`);
|
|
86
86
|
* it has no parent to walk to, so resolve directly instead of entering the loop below. */
|
|
87
87
|
if (current.builtInEnv) {
|
|
88
|
-
return current.
|
|
88
|
+
return current.lookup(name);
|
|
89
89
|
}
|
|
90
90
|
let definitions = undefined;
|
|
91
91
|
const wantedType = TargetTypePredicate[target];
|
|
92
|
+
/* the attached packages below the code's own frames are a dozen layers deep and nothing writes them, so the
|
|
93
|
+
* walk through them is done once per name and target instead of once per resolution */
|
|
94
|
+
const flatten = ns === undefined && internal !== false && typeof id === 'string'
|
|
95
|
+
&& target !== identifier_1.ReferenceType.S3MethodPrefix && target !== identifier_1.ReferenceType.S7MethodPrefix;
|
|
96
|
+
const key = flatten ? `${target}\u0000${name}` : '';
|
|
97
|
+
let flattenAt;
|
|
92
98
|
do {
|
|
99
|
+
if (flatten && flattenAt === undefined && definitions === undefined && (current.t !== undefined || current.builtInEnv)) {
|
|
100
|
+
const cached = current.tailCache?.get(key);
|
|
101
|
+
if (cached !== undefined || current.tailCache?.has(key)) {
|
|
102
|
+
return cached;
|
|
103
|
+
}
|
|
104
|
+
flattenAt = current;
|
|
105
|
+
}
|
|
93
106
|
if (layerSkipped(current, ns)) {
|
|
94
107
|
current = current.parent;
|
|
95
108
|
continue;
|
|
@@ -104,7 +117,7 @@ function resolveByTargetType(id, environment, target) {
|
|
|
104
117
|
.toArray();
|
|
105
118
|
}
|
|
106
119
|
else {
|
|
107
|
-
definition = current.
|
|
120
|
+
definition = current.lookup(name);
|
|
108
121
|
if (internal === false) {
|
|
109
122
|
definition = definition?.filter(({ name }) => name === undefined || !identifier_1.Identifier.accessesInternal(name));
|
|
110
123
|
}
|
|
@@ -125,6 +138,9 @@ function resolveByTargetType(id, environment, target) {
|
|
|
125
138
|
}
|
|
126
139
|
}
|
|
127
140
|
if (allOk) {
|
|
141
|
+
if (flattenAt !== undefined) {
|
|
142
|
+
(flattenAt.tailCache ??= new Map()).set(key, definition);
|
|
143
|
+
}
|
|
128
144
|
return definition;
|
|
129
145
|
}
|
|
130
146
|
/* never alias the environment's own array, it is appended to below */
|
|
@@ -142,12 +158,15 @@ function resolveByTargetType(id, environment, target) {
|
|
|
142
158
|
} while (!current.builtInEnv);
|
|
143
159
|
/* the built-in layer is handed over as it is, except to a value position: `filter(df, c > 2)` means the
|
|
144
160
|
column `c`, never `base::c`, and only with nothing left does `ownDefinitions` have its say */
|
|
145
|
-
const known = statedIn(current, name, ns) ?? current.
|
|
161
|
+
const known = statedIn(current, name, ns) ?? current.lookup(name);
|
|
146
162
|
const builtIns = target === identifier_1.ReferenceType.NonFunction ? known?.filter(wantedType) : known;
|
|
147
|
-
|
|
148
|
-
|
|
163
|
+
const result = definitions
|
|
164
|
+
? (builtIns === undefined || builtIns.length === 0 ? definitions : definitions.concat(builtIns))
|
|
165
|
+
: (builtIns === undefined || builtIns.length > 0 ? builtIns : undefined);
|
|
166
|
+
if (flattenAt !== undefined) {
|
|
167
|
+
(flattenAt.tailCache ??= new Map()).set(key, result);
|
|
149
168
|
}
|
|
150
|
-
return
|
|
169
|
+
return result;
|
|
151
170
|
}
|
|
152
171
|
/**
|
|
153
172
|
* The more performant version of {@link resolveByName} when the target type is unknown.
|
|
@@ -168,7 +187,7 @@ function resolveByNameAnyType(id, environment) {
|
|
|
168
187
|
const internal = identifier_1.Identifier.accessesInternal(id);
|
|
169
188
|
/* `current` can already be the built-in environment itself */
|
|
170
189
|
if (current.builtInEnv) {
|
|
171
|
-
const ret = current.
|
|
190
|
+
const ret = current.lookup(name);
|
|
172
191
|
if (ret && cacheable) {
|
|
173
192
|
current.cache ??= new Map();
|
|
174
193
|
current.cache.set(id, ret);
|
|
@@ -181,7 +200,7 @@ function resolveByNameAnyType(id, environment) {
|
|
|
181
200
|
current = current.parent;
|
|
182
201
|
continue;
|
|
183
202
|
}
|
|
184
|
-
let definition = current.
|
|
203
|
+
let definition = current.lookup(name);
|
|
185
204
|
if (definition) {
|
|
186
205
|
if (internal === false) {
|
|
187
206
|
definition = definition.filter(({ name }) => name === undefined || !identifier_1.Identifier.accessesInternal(name));
|
|
@@ -204,7 +223,7 @@ function resolveByNameAnyType(id, environment) {
|
|
|
204
223
|
}
|
|
205
224
|
current = current.parent;
|
|
206
225
|
} while (!current.builtInEnv);
|
|
207
|
-
const builtIns = statedIn(current, name, ns) ?? current.
|
|
226
|
+
const builtIns = statedIn(current, name, ns) ?? current.lookup(name);
|
|
208
227
|
let ret;
|
|
209
228
|
if (definitions) {
|
|
210
229
|
ret = builtIns === undefined ? definitions : definitions.concat(builtIns);
|
package/dataflow/graph/graph.js
CHANGED
|
@@ -567,7 +567,7 @@ function attachStatedDefinitions(pack, envInfo, ctx, spec, as, loadedAt, cds) {
|
|
|
567
567
|
}
|
|
568
568
|
const layer = new environment_1.Environment(envInfo.current)
|
|
569
569
|
.asLibrary(pack, as ?? (spec.namespaceOnly ? environment_1.EnvType.LoadedNamespace : environment_1.EnvType.Namespace));
|
|
570
|
-
layer.memory
|
|
570
|
+
layer.adoptMap(memory);
|
|
571
571
|
return { level: envInfo.level, current: environment_1.REnvironment.attachAt(envInfo.current, layer, layer, spec.pos) };
|
|
572
572
|
}
|
|
573
573
|
/**
|
|
@@ -161,11 +161,18 @@ function* escapeTargetFrames(fdef) {
|
|
|
161
161
|
* dominated by the built-ins it holds, so filtering each frame once per pass saves the bulk of the work.
|
|
162
162
|
*/
|
|
163
163
|
function escapedDefinitions() {
|
|
164
|
+
/* keyed by frame and then by version: one frame answers differently at each, so the version has to be part of it */
|
|
164
165
|
const perFrame = new Map();
|
|
165
166
|
return (_id, fdef) => {
|
|
166
167
|
const defs = [];
|
|
167
168
|
for (const e of escapeTargetFrames(fdef)) {
|
|
168
|
-
|
|
169
|
+
const { frame, version } = e.memory;
|
|
170
|
+
let byVersion = perFrame.get(frame);
|
|
171
|
+
if (byVersion === undefined) {
|
|
172
|
+
byVersion = new Map();
|
|
173
|
+
perFrame.set(frame, byVersion);
|
|
174
|
+
}
|
|
175
|
+
let escaped = byVersion.get(version);
|
|
169
176
|
if (escaped === undefined) {
|
|
170
177
|
/* a package frame holds thousands of entries and keeps none of them, so this walks them in place
|
|
171
178
|
* rather than through a spread/flatMap/filter/map chain that allocates an array per step */
|
|
@@ -178,7 +185,7 @@ function escapedDefinitions() {
|
|
|
178
185
|
}
|
|
179
186
|
}
|
|
180
187
|
escaped = collected;
|
|
181
|
-
|
|
188
|
+
byVersion.set(version, escaped);
|
|
182
189
|
}
|
|
183
190
|
for (const d of escaped) {
|
|
184
191
|
defs.push(d);
|
|
@@ -242,16 +249,23 @@ function propagateTransitivePackages(graph, environment, ctx) {
|
|
|
242
249
|
/** Maps each escaped definition's node id to its full (name-carrying) definition. */
|
|
243
250
|
function escapedDefinitionMap(graph) {
|
|
244
251
|
const map = new Map();
|
|
245
|
-
|
|
252
|
+
/* a frame answers differently at each version, so a visit is only a repeat when both match */
|
|
253
|
+
const seen = new Map();
|
|
246
254
|
for (const [, vertex] of graph.vertices(true)) {
|
|
247
255
|
if (!vertex_1.FunctionDefinitionVertex.is(vertex)) {
|
|
248
256
|
continue;
|
|
249
257
|
}
|
|
250
258
|
for (const e of escapeTargetFrames(vertex)) {
|
|
251
|
-
|
|
259
|
+
const { frame, version } = e.memory;
|
|
260
|
+
let versions = seen.get(frame);
|
|
261
|
+
if (versions === undefined) {
|
|
262
|
+
versions = new Set();
|
|
263
|
+
seen.set(frame, versions);
|
|
264
|
+
}
|
|
265
|
+
else if (versions.has(version)) {
|
|
252
266
|
continue; // a frame shared with an already-visited definition contributes the same entries
|
|
253
267
|
}
|
|
254
|
-
|
|
268
|
+
versions.add(version);
|
|
255
269
|
for (const definitions of e.memory.values()) {
|
|
256
270
|
for (const def of definitions) {
|
|
257
271
|
if (!node_id_1.NodeId.isBuiltIn(def.nodeId) && def.name !== undefined) {
|
package/package.json
CHANGED
|
@@ -23,9 +23,9 @@ class FlowrAnalyzerEnvironmentContext {
|
|
|
23
23
|
const builtInsConfig = ctx.config.semantics.environment.overwriteBuiltIns;
|
|
24
24
|
const builtIns = (0, built_in_config_1.getBuiltInDefinitions)(builtInsConfig.definitions, builtInsConfig.loadDefaults);
|
|
25
25
|
this.builtInEnv = new environment_1.Environment(undefined, true);
|
|
26
|
-
this.builtInEnv.
|
|
26
|
+
this.builtInEnv.adoptMap(builtIns.builtInMemory);
|
|
27
27
|
this.emptyBuiltInEnv = new environment_1.Environment(undefined, true);
|
|
28
|
-
this.emptyBuiltInEnv.
|
|
28
|
+
this.emptyBuiltInEnv.adoptMap(builtIns.emptyBuiltInMemory);
|
|
29
29
|
this.stated = builtIns.packageMemory;
|
|
30
30
|
/* `pkg::fn` resolves whether or not the package is attached, so the built-in env answers for it */
|
|
31
31
|
this.builtInEnv.namespaces = builtIns.packageMemory;
|
package/project/sigdb/reader.js
CHANGED
|
@@ -313,20 +313,48 @@ const NoFile = -1;
|
|
|
313
313
|
* anything: how many shards a query set opens is not something the caller picks, and each would claim the
|
|
314
314
|
* budget again. A count would not bound anything either -- one package's blob outweighs a hundred small ones.
|
|
315
315
|
*/
|
|
316
|
-
const BlobCacheBudget =
|
|
317
|
-
/** what every open bundle holds decoded,
|
|
316
|
+
const BlobCacheBudget = 64 * 1024 * 1024;
|
|
317
|
+
/** what every open bundle holds decoded, so the budget is spent across all of them */
|
|
318
318
|
const cachedBlobs = [];
|
|
319
|
+
/** where {@link keepBlob} resumes looking for something to drop */
|
|
320
|
+
let hand = 0;
|
|
319
321
|
let cachedBlobBytes = 0;
|
|
320
|
-
/**
|
|
322
|
+
/**
|
|
323
|
+
* Keep `blob` decoded for `db`, dropping blobs until all of them fit the budget (age gated).
|
|
324
|
+
*/
|
|
321
325
|
function keepBlob(db, blobIdx, bytes) {
|
|
322
326
|
while (cachedBlobBytes + bytes > BlobCacheBudget && cachedBlobs.length > 0) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
+
if (hand >= cachedBlobs.length) {
|
|
328
|
+
hand = 0;
|
|
329
|
+
}
|
|
330
|
+
const candidate = cachedBlobs[hand];
|
|
331
|
+
if (candidate.used) {
|
|
332
|
+
candidate.used = false;
|
|
333
|
+
hand++;
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
cachedBlobs.splice(hand, 1);
|
|
337
|
+
cachedBlobBytes -= candidate.bytes;
|
|
338
|
+
candidate.db.dropBlob(candidate.blobIdx);
|
|
327
339
|
}
|
|
328
|
-
|
|
340
|
+
const entry = { db, blobIdx, bytes, used: true };
|
|
341
|
+
cachedBlobs.push(entry);
|
|
329
342
|
cachedBlobBytes += bytes;
|
|
343
|
+
return entry;
|
|
344
|
+
}
|
|
345
|
+
/** Mark `entry` read, so the hand passes over it once before dropping it. */
|
|
346
|
+
function touchBlob(entry) {
|
|
347
|
+
entry.used = true;
|
|
348
|
+
}
|
|
349
|
+
/** give back what `db` held, so a closed bundle stops spending the budget of the open ones */
|
|
350
|
+
function releaseBlobs(db) {
|
|
351
|
+
for (let i = cachedBlobs.length - 1; i >= 0; i--) {
|
|
352
|
+
if (cachedBlobs[i].db === db) {
|
|
353
|
+
cachedBlobBytes -= cachedBlobs[i].bytes;
|
|
354
|
+
cachedBlobs.splice(i, 1);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
hand = 0;
|
|
330
358
|
}
|
|
331
359
|
/**
|
|
332
360
|
* Fast, partial reader for a single bundle. `open()`/`openSync()` load the string dictionary + `.idx` once, then every
|
|
@@ -361,7 +389,7 @@ class SigDatabase {
|
|
|
361
389
|
static fromMemory(db) {
|
|
362
390
|
const index = { byteCount: 0, dict: [0, 0], blobs: [], pkgs: db.pkgs, meta: db.meta };
|
|
363
391
|
const source = new SigDatabase(NoFile, db.strings, index, db.content, db.cranBase ?? schema_1.DefaultCranBase);
|
|
364
|
-
db.blobs.forEach((blob, i) => source.blobCache.set(i, blob));
|
|
392
|
+
db.blobs.forEach((blob, i) => source.blobCache.set(i, { blob }));
|
|
365
393
|
return source;
|
|
366
394
|
}
|
|
367
395
|
/**
|
|
@@ -421,7 +449,10 @@ class SigDatabase {
|
|
|
421
449
|
}
|
|
422
450
|
const cached = this.blobCache.get(blobIdx);
|
|
423
451
|
if (cached !== undefined) {
|
|
424
|
-
|
|
452
|
+
if (cached.entry !== undefined) {
|
|
453
|
+
touchBlob(cached.entry);
|
|
454
|
+
}
|
|
455
|
+
return cached.blob;
|
|
425
456
|
}
|
|
426
457
|
if (this.fd === NoFile) {
|
|
427
458
|
return undefined; // an in-memory database starts out with every blob cached
|
|
@@ -431,8 +462,7 @@ class SigDatabase {
|
|
|
431
462
|
if (!this.nameIdsOfBlob.has(blobIdx)) {
|
|
432
463
|
this.nameIdsOfBlob.set(blobIdx, Int32Array.from(new Set(blob.fns.map(fn => fn[0]))).sort());
|
|
433
464
|
}
|
|
434
|
-
keepBlob(this, blobIdx, range[1]);
|
|
435
|
-
this.blobCache.set(blobIdx, blob);
|
|
465
|
+
this.blobCache.set(blobIdx, { blob, entry: keepBlob(this, blobIdx, range[1]) });
|
|
436
466
|
return blob;
|
|
437
467
|
}
|
|
438
468
|
/** the dictionary id of `name`, or `-1` if the dictionary does not hold it, so no package can offer it */
|
|
@@ -498,7 +528,7 @@ class SigDatabase {
|
|
|
498
528
|
allBlobs() {
|
|
499
529
|
// an in-memory database has no byte ranges to re-read: its blobs are the cached ones, in blob-index order
|
|
500
530
|
return this.fd === NoFile
|
|
501
|
-
? [...this.blobCache.entries()].sort(([a], [b]) => a - b).map(([, blob]) => blob)
|
|
531
|
+
? [...this.blobCache.entries()].sort(([a], [b]) => a - b).map(([, { blob }]) => blob)
|
|
502
532
|
: this.index.blobs.map(range => this.readBlobAt(range));
|
|
503
533
|
}
|
|
504
534
|
/** recompute this bundle's self-contained content hash from its re-read data (matches {@link writeSignatureDb}) */
|
|
@@ -677,6 +707,7 @@ class SigDatabase {
|
|
|
677
707
|
close() {
|
|
678
708
|
if (!this.closed) {
|
|
679
709
|
this.closed = true;
|
|
710
|
+
releaseBlobs(this);
|
|
680
711
|
this.blobCache.clear();
|
|
681
712
|
this.versionFnCache.clear();
|
|
682
713
|
this.classIndex = undefined;
|
|
@@ -593,11 +593,10 @@ class InputClassifier {
|
|
|
593
593
|
// caller argument), follow it into the caller; only if that leads nowhere is it an opaque Scope origin
|
|
594
594
|
const onCall = this.definedByOnCallTargets(v.id);
|
|
595
595
|
if (onCall.length > 0) {
|
|
596
|
-
const callers = onCall.map(t => this.classifyInFullGraph(t))
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
if (
|
|
600
|
-
callers.forEach(c => acc.merge(c));
|
|
596
|
+
const callers = onCall.map(t => this.classifyInFullGraph(t)).filter(assert_1.isNotUndefined);
|
|
597
|
+
const known = callers.filter(c => !c.types.includes(input_types_1.InputType.Unknown));
|
|
598
|
+
known.forEach(c => acc.merge(c));
|
|
599
|
+
if (known.length > 0 && known.length === callers.length) {
|
|
601
600
|
return;
|
|
602
601
|
}
|
|
603
602
|
acc.types.push(input_types_1.InputType.Scope);
|
|
@@ -32,7 +32,12 @@ function definitionHash(definition) {
|
|
|
32
32
|
return hash;
|
|
33
33
|
}
|
|
34
34
|
function memoryHash(memory) {
|
|
35
|
-
let
|
|
35
|
+
let byVersion = memoryHashes.get(memory.frame);
|
|
36
|
+
if (byVersion === undefined) {
|
|
37
|
+
byVersion = new Map();
|
|
38
|
+
memoryHashes.set(memory.frame, byVersion);
|
|
39
|
+
}
|
|
40
|
+
let hash = byVersion.get(memory.version);
|
|
36
41
|
if (hash === undefined) {
|
|
37
42
|
const entries = [];
|
|
38
43
|
for (const [name, definitions] of memory) {
|
|
@@ -40,7 +45,7 @@ function memoryHash(memory) {
|
|
|
40
45
|
}
|
|
41
46
|
entries.sort();
|
|
42
47
|
hash = (0, object_hash_1.default)(entries, HashOptions);
|
|
43
|
-
|
|
48
|
+
byVersion.set(memory.version, hash);
|
|
44
49
|
}
|
|
45
50
|
return hash;
|
|
46
51
|
}
|
package/util/version.js
CHANGED
|
@@ -42,9 +42,9 @@ const assert_1 = require("./assert");
|
|
|
42
42
|
const sigdb_download_1 = require("../project/sigdb/sigdb-download");
|
|
43
43
|
const doc_files_1 = require("../documentation/doc-util/doc-files");
|
|
44
44
|
// this is automatically replaced with the current version by release-it
|
|
45
|
-
const version = '2.15.
|
|
45
|
+
const version = '2.15.4';
|
|
46
46
|
// this is automatically replaced with the release date by release-it (regex-bumper, see package.json)
|
|
47
|
-
const versionDate = '2026-08-
|
|
47
|
+
const versionDate = '2026-08-26T17:54:03Z';
|
|
48
48
|
/**
|
|
49
49
|
* Retrieves the current flowR version as a new {@link SemVer} object.
|
|
50
50
|
*/
|