Skip to content

Commit cce7a90

Browse files
committed
wip: start to work but wait on #2034
1 parent b70768f commit cce7a90

File tree

8 files changed

+33
-49
lines changed

8 files changed

+33
-49
lines changed

src/dataflow/environments/append.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { guard } from '../../util/assert';
2-
import { type IEnvironment, type REnvironmentInformation , Environment } from './environment';
2+
import { type REnvironmentInformation , Environment } from './environment';
33
import type { IdentifierDefinition } from './identifier';
44

55
function uniqueMergeValues(old: IdentifierDefinition[], value: readonly IdentifierDefinition[]): IdentifierDefinition[] {
@@ -13,7 +13,7 @@ function uniqueMergeValues(old: IdentifierDefinition[], value: readonly Identifi
1313
return result;
1414
}
1515

16-
function appendIEnvironmentWith(base: IEnvironment | undefined, next: IEnvironment | undefined): IEnvironment {
16+
function appendIEnvironmentWith(base: Environment | undefined, next: Environment | undefined): Environment {
1717
guard(base !== undefined && next !== undefined, 'can not append environments with undefined');
1818
const map = new Map(base.memory);
1919
for(const [key, value] of next.memory) {

src/dataflow/environments/clone.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { type IEnvironment, type REnvironmentInformation , Environment } from './environment';
1+
import { type REnvironmentInformation, Environment } from './environment';
22
import type { Identifier, IdentifierDefinition } from './identifier';
33

4-
function cloneEnvironment(environment: IEnvironment, recurseParents: boolean): IEnvironment
5-
function cloneEnvironment(environment: IEnvironment | undefined, recurseParents: boolean): IEnvironment | undefined {
4+
function cloneEnvironment(environment: Environment, recurseParents: boolean): Environment
5+
function cloneEnvironment(environment: Environment | undefined, recurseParents: boolean): Environment | undefined {
66
if(environment === undefined) {
77
return undefined;
88
} else if(environment.builtInEnv) {
@@ -16,9 +16,8 @@ function cloneEnvironment(environment: IEnvironment | undefined, recurseParents:
1616

1717
/**
1818
* Produce a clone of the given environment information.
19-
* @param environment - The environment information to clone.
20-
* @param builtInEnvironment - The built-in environment
21-
* @param recurseParents - Whether to clone the parent environments as well.
19+
* @param environment - The environment information to clone.
20+
* @param recurseParents - Whether to clone the parent environments as well.
2221
*/
2322
export function cloneEnvironmentInformation(environment: REnvironmentInformation, recurseParents = true): REnvironmentInformation {
2423
return {

src/dataflow/environments/define.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { guard, isNotUndefined } from '../../util/assert';
2-
import type { IEnvironment, REnvironmentInformation } from './environment';
2+
import type { Environment, REnvironmentInformation } from './environment';
33
import { cloneEnvironmentInformation } from './clone';
44
import type { IdentifierDefinition, InGraphIdentifierDefinition } from './identifier';
55
import { type ContainerIndex, type ContainerIndices , isParentContainerIndex, isSameIndex } from '../graph/vertex';
66
import type { FlowrConfigOptions } from '../../config';
77

8-
function defInEnv(newEnvironments: IEnvironment, name: string, definition: IdentifierDefinition, config: FlowrConfigOptions) {
8+
function defInEnv(newEnvironments: Environment, name: string, definition: IdentifierDefinition, config: FlowrConfigOptions) {
99
const existing = newEnvironments.memory.get(name);
1010

1111
// When there are defined indices, merge the definitions

src/dataflow/environments/environment.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,6 @@ export function makeAllMaybe(references: readonly IdentifierReference[] | undefi
5858
return references?.map(ref => makeReferenceMaybe(ref, graph, environments, includeDefs, defaultCd)) ?? [];
5959
}
6060

61-
/** A single entry/scope within an {@link REnvironmentInformation} */
62-
export interface IEnvironment {
63-
/** Unique and internally generated identifier -- will not be used for comparison but helps with debugging for tracking identities */
64-
readonly id: number
65-
/** Lexical parent of the environment, if any (can be manipulated by R code) */
66-
parent: IEnvironment
67-
/** Maps to exactly one definition of an identifier if the source is known, otherwise to a list of all possible definitions */
68-
memory: BuiltInMemory
69-
/**
70-
* Is this a built-in environment that is not allowed to change? Please use this carefully and only for the top-most envs!
71-
*/
72-
builtInEnv?: true | undefined
73-
}
74-
7561
/**
7662
* Please use this function only if you do not know the object type.
7763
* Otherwise, rely on {@link IEnvironment#builtInEnv}
@@ -82,14 +68,18 @@ export function isDefaultBuiltInEnvironment(obj: unknown) {
8268

8369
let environmentIdCounter = 1; // Zero is reserved for built-in environment
8470

85-
/** @see REnvironmentInformation */
86-
export class Environment implements IEnvironment {
87-
readonly id;
88-
parent: IEnvironment;
71+
/** A single entry/scope within an {@link REnvironmentInformation} */
72+
export class Environment {
73+
/** Unique and internally generated identifier -- will not be used for comparison but helps with debugging for tracking identities */
74+
readonly id: number;
75+
/** Lexical parent of the environment, if any (can be manipulated by R code) */
76+
parent: Environment;
77+
/** Maps to exactly one definition of an identifier if the source is known, otherwise to a list of all possible definitions */
8978
memory: BuiltInMemory;
79+
/** Is this a built-in environment that is not allowed to change? Please use this carefully and only for the top-most envs! */
9080
builtInEnv?: true;
9181

92-
constructor(parent: IEnvironment, isBuiltInDefault: true | undefined = undefined) {
82+
constructor(parent: Environment, isBuiltInDefault: true | undefined = undefined) {
9383
this.id = isBuiltInDefault ? 0 : environmentIdCounter++;
9484
this.parent = parent;
9585
this.memory = new Map();
@@ -126,8 +116,8 @@ export interface WorkingDirectoryReference {
126116
* @see {@link overwriteEnvironment} - to overwrite the definitions in the current environment with those of another one
127117
*/
128118
export interface REnvironmentInformation {
129-
/** The currently active environment (the stack is represented by the currently active {@link IEnvironment#parent}). Environments are maintained within the dataflow graph. */
130-
readonly current: IEnvironment
119+
/** The currently active environment (the stack is represented by the currently active {@link Environment#parent}). Environments are maintained within the dataflow graph. */
120+
readonly current: Environment
131121
/** nesting level of the environment, will be `0` for the global/root environment */
132122
readonly level: number
133123
}
@@ -136,7 +126,7 @@ export interface REnvironmentInformation {
136126
* Initialize a new {@link REnvironmentInformation|environment} with the built-ins.
137127
*/
138128
export function initializeCleanEnvironments(memory?: BuiltInMemory, fullBuiltIns = true): REnvironmentInformation {
139-
const builtInEnv = new Environment(undefined as unknown as IEnvironment, true);
129+
const builtInEnv = new Environment(undefined as unknown as Environment, true);
140130
builtInEnv.memory = memory ?? (fullBuiltIns ? getDefaultBuiltInDefinitions().builtInMemory : getDefaultBuiltInDefinitions().emptyBuiltInMemory);
141131

142132
return {

src/dataflow/environments/overwrite.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ function anyIsMaybeOrEmpty(values: readonly IdentifierDefinition[]): boolean {
1616
return false;
1717
}
1818

19-
20-
/**
21-
*
22-
*/
23-
export function overwriteIEnvironmentWith(base: IEnvironment | undefined, next: IEnvironment | undefined, includeParent = true, applyCds?: readonly ControlDependency[]): IEnvironment {
19+
function overwriteIEnvironmentWith(base: IEnvironment | undefined, next: IEnvironment | undefined, includeParent = true, applyCds?: readonly ControlDependency[]): IEnvironment {
2420
guard(base !== undefined && next !== undefined, 'can not overwrite environments with undefined');
2521
const map = new Map(base.memory);
2622
for(const [key, values] of next.memory) {

src/dataflow/eval/resolve/alias-tracking.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { envFingerprint } from '../../../slicing/static/fingerprint';
77
import { VisitingQueue } from '../../../slicing/static/visiting-queue';
88
import { guard } from '../../../util/assert';
99
import type { BuiltInIdentifierConstant } from '../../environments/built-in';
10-
import { type IEnvironment, type REnvironmentInformation , initializeCleanEnvironments } from '../../environments/environment';
11-
import { type Identifier , ReferenceType } from '../../environments/identifier';
10+
import { type Environment, type REnvironmentInformation, initializeCleanEnvironments } from '../../environments/environment';
11+
import { type Identifier, ReferenceType } from '../../environments/identifier';
1212
import { resolveByName } from '../../environments/resolve-by-name';
1313
import { EdgeType } from '../../graph/edge';
1414
import type { DataflowGraph } from '../../graph/graph';
@@ -22,7 +22,7 @@ import { resolveNode } from './resolve';
2222

2323
export type ResolveResult = Lift<ValueSet<Value[]>>;
2424

25-
type AliasHandler = (s: NodeId, d: DataflowGraph, e: REnvironmentInformation, def: IEnvironment) => NodeId[] | undefined;
25+
type AliasHandler = (s: NodeId, d: DataflowGraph, e: REnvironmentInformation, def: Environment) => NodeId[] | undefined;
2626
const AliasHandler = {
2727
[VertexType.Value]: (sourceId: NodeId) => [sourceId],
2828
[VertexType.Use]: getUseAlias,

src/dataflow/graph/dataflowgraph-builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { deepMergeObject } from '../../util/objects';
22
import { type NodeId , normalizeIdToNumberIfPossible } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
33
import type { AstIdMap } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
44
import { type DataflowFunctionFlowInformation, type FunctionArgument , DataflowGraph, isPositionalArgument } from './graph';
5-
import { type IEnvironment, type REnvironmentInformation , initializeCleanEnvironments } from '../environments/environment';
5+
import type { Environment , type REnvironmentInformation , initializeCleanEnvironments } from '../environments/environment';
66
import { type DataflowGraphVertexAstLink, type DataflowGraphVertexUse, type FunctionOriginInformation , VertexType } from './vertex';
77
import { EmptyArgument } from '../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
88
import { isBuiltIn } from '../environments/built-in';
@@ -42,7 +42,7 @@ export class DataflowGraphBuilder extends DataflowGraph {
4242
*/
4343
public defineFunction(id: NodeId,
4444
exitPoints: readonly NodeId[], subflow: DataflowFunctionFlowInformation,
45-
info?: { environment?: REnvironmentInformation, builtInEnvironment?: IEnvironment, controlDependencies?: ControlDependency[] },
45+
info?: { environment?: REnvironmentInformation, builtInEnvironment?: Environment, controlDependencies?: ControlDependency[] },
4646
asRoot: boolean = true) {
4747
return this.addVertex({
4848
tag: VertexType.FunctionDefinition,
@@ -76,7 +76,7 @@ export class DataflowGraphBuilder extends DataflowGraph {
7676
reads?: readonly NodeId[],
7777
onlyBuiltIn?: boolean,
7878
environment?: REnvironmentInformation,
79-
builtInEnvironment?: IEnvironment,
79+
builtInEnvironment?: Environment,
8080
controlDependencies?: ControlDependency[],
8181
origin?: FunctionOriginInformation[]
8282
link?: DataflowGraphVertexAstLink

src/dataflow/internal/process/functions/call/built-in/built-in-expression-list.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import { linkFunctionCalls } from '../../../../linker';
99
import { guard, isNotUndefined } from '../../../../../../util/assert';
1010
import { unpackArgument } from '../argument/unpack-argument';
1111
import { patchFunctionCall } from '../common';
12-
import {
13-
type IEnvironment,
14-
type REnvironmentInformation
15-
,
16-
makeAllMaybe } from '../../../../../environments/environment';
12+
import { type Environment,
13+
type REnvironmentInformation,
14+
makeAllMaybe
15+
} from '../../../../../environments/environment';
1716
import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
1817
import { DataflowGraph } from '../../../../../graph/graph';
1918
import { type IdentifierReference , ReferenceType } from '../../../../../environments/identifier';
@@ -94,7 +93,7 @@ function updateSideEffectsForCalledFunctions(calledEnvs: {
9493
environment = popLocalEnvironment(environment);
9594
}
9695
// update alle definitions to be defined at this function call
97-
let current: IEnvironment | undefined = environment.current;
96+
let current: Environment | undefined = environment.current;
9897

9998
let hasUpdate = false;
10099
while(!current?.builtInEnv) {

0 commit comments

Comments
 (0)