@@ -12,17 +12,18 @@ import type {
12
12
import { VertexType } from './vertex' ;
13
13
import { arrayEqual } from '../../util/arrays' ;
14
14
import { EmptyArgument } from '../../r-bridge/lang-4.x/ast/model/nodes/r-function-call' ;
15
- import type { IdentifierDefinition , IdentifierReference } from '../environments/identifier' ;
15
+ import type { Identifier , IdentifierDefinition , IdentifierReference } from '../environments/identifier' ;
16
16
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id' ;
17
17
import { normalizeIdToNumberIfPossible } from '../../r-bridge/lang-4.x/ast/model/processing/node-id' ;
18
- import type { REnvironmentInformation } from '../environments/environment' ;
18
+ import type { EnvironmentMemory , IEnvironment , REnvironmentInformation } from '../environments/environment' ;
19
19
import { initializeCleanEnvironments } from '../environments/environment' ;
20
20
import type { AstIdMap } from '../../r-bridge/lang-4.x/ast/model/processing/decorate' ;
21
21
import { cloneEnvironmentInformation } from '../environments/clone' ;
22
22
import { jsonReplacer } from '../../util/json' ;
23
23
import { BuiltIn } from '../environments/built-in' ;
24
24
import { dataflowLogger } from '../logger' ;
25
25
import type { LinkTo } from '../../queries/catalog/call-context-query/call-context-query-format' ;
26
+ import type { Writable } from 'ts-essentials' ;
26
27
27
28
/**
28
29
* Describes the information we store per function body.
@@ -461,6 +462,11 @@ export class DataflowGraph<
461
462
const graph = new DataflowGraph ( undefined ) ;
462
463
graph . rootVertices = new Set < NodeId > ( data . rootVertices ) ;
463
464
graph . vertexInformation = new Map < NodeId , DataflowGraphVertexInfo > ( data . vertexInformation ) ;
465
+ for ( const [ , vertex ] of graph . vertexInformation ) {
466
+ if ( vertex . environment ) {
467
+ ( vertex . environment as Writable < REnvironmentInformation > ) = renvFromJson ( vertex . environment as unknown as REnvironmentInformationJson ) ;
468
+ }
469
+ }
464
470
graph . edgeInformation = new Map < NodeId , OutgoingEdges > ( data . edgeInformation . map ( ( [ id , edges ] ) => [ id , new Map < NodeId , DataflowGraphEdge > ( edges ) ] ) ) ;
465
471
if ( data . sourced ) {
466
472
graph . _sourced = data . sourced ;
@@ -495,3 +501,35 @@ function extractEdgeIds(from: NodeId | ReferenceForEdge, to: NodeId | ReferenceF
495
501
const toId = typeof to === 'object' ? to . nodeId : to ;
496
502
return [ fromId , toId ] ;
497
503
}
504
+
505
+ export interface IEnvironmentJson {
506
+ readonly id : number ;
507
+ parent : IEnvironmentJson ;
508
+ memory : Record < Identifier , IdentifierDefinition [ ] > ;
509
+ }
510
+
511
+ interface REnvironmentInformationJson {
512
+ readonly current : IEnvironmentJson ;
513
+ readonly level : number ;
514
+ }
515
+
516
+ function envFromJson ( json : IEnvironmentJson ) : IEnvironment {
517
+ const parent = json . parent ? envFromJson ( json . parent ) : undefined ;
518
+ const memory : EnvironmentMemory = new Map ( ) ;
519
+ for ( const [ key , value ] of Object . entries ( json . memory ) ) {
520
+ memory . set ( key as Identifier , value ) ;
521
+ }
522
+ return {
523
+ id : json . id ,
524
+ parent : parent as IEnvironment ,
525
+ memory
526
+ } ;
527
+ }
528
+
529
+ function renvFromJson ( json : REnvironmentInformationJson ) : REnvironmentInformation {
530
+ const current = envFromJson ( json . current ) ;
531
+ return {
532
+ current,
533
+ level : json . level
534
+ } ;
535
+ }
0 commit comments