Skip to content

Commit 47eb62c

Browse files
authored
feat: no cds for known eval (#2377)
1 parent c14938a commit 47eb62c

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/dataflow/graph/graph.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,16 @@ export class DataflowGraph<
519519
to = NodeId.normalize(to);
520520
const vertex = this.getVertex(from);
521521
guard(vertex !== undefined, () => `node must be defined for ${from} to add control dependency`);
522-
vertex.cds ??= [];
523-
let hasControlDependency = false;
524-
for(const { id, when: cond } of vertex.cds) {
525-
if(id === to && when !== cond) {
526-
hasControlDependency = true;
527-
break;
522+
if(vertex.cds) {
523+
for(const { id, when: cond } of vertex.cds) {
524+
if(id === to && when !== cond) {
525+
return this;
526+
}
528527
}
528+
} else {
529+
vertex.cds = [];
529530
}
530-
if(!hasControlDependency) {
531-
vertex.cds.push({ id: to, when });
532-
}
531+
vertex.cds.push({ id: to, when });
533532
return this;
534533
}
535534

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ export function processEvalCall<OtherInfo>(
7878

7979
data = {
8080
...data,
81-
cds: [...(data.cds ?? []), { id: rootId, when: true }]
81+
cds: code.length > 1 ? [...(data.cds ?? []), { id: rootId, when: true }] : data.cds
8282
};
8383
const originalInfo = { ...information };
8484

8585
const result: DataflowInformation[] = [];
8686
for(const c of code) {
8787
const codeRequest = requestFromInput(c);
88-
const r = sourceRequest(rootId, codeRequest, data, originalInfo, idGenerator);
88+
const r = sourceRequest(rootId, codeRequest, data, originalInfo, code.length > 1, idGenerator);
8989
result.push(r);
9090
// add a returns edge from the eval to the result
9191
for(const e of r.exitPoints) {

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { resolveIdToValue } from '../../../../../eval/resolve/alias-tracking';
3131
import type { ReadOnlyFlowrAnalyzerContext } from '../../../../../../project/context/flowr-analyzer-context';
3232
import type { RProjectFile } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-project';
3333
import { BuiltInProcName } from '../../../../../environments/built-in';
34+
import { EdgeType } from '../../../../../graph/edge';
3435

3536
/**
3637
* Infers working directories based on the given option and reference chain
@@ -210,7 +211,7 @@ export function processSourceCall<OtherInfo>(
210211
result = sourceRequest(rootId, {
211212
request: 'file',
212213
content: f
213-
}, data, result, sourcedDeterministicCountingIdGenerator((findCount > 0 ? findCount + '::' : '') + f, name.location));
214+
}, data, result, true, sourcedDeterministicCountingIdGenerator((findCount > 0 ? findCount + '::' : '') + f, name.location));
214215
}
215216
return result;
216217
}
@@ -225,7 +226,7 @@ export function processSourceCall<OtherInfo>(
225226
* Processes a source request with the given dataflow processor information and existing dataflow information
226227
* Otherwise, this can be an {@link RProjectFile} representing a standalone source file
227228
*/
228-
export function sourceRequest<OtherInfo>(rootId: NodeId, request: RParseRequest | RProjectFile<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, information: DataflowInformation, getId?: IdGenerator<NoInfo>): DataflowInformation {
229+
export function sourceRequest<OtherInfo>(rootId: NodeId, request: RParseRequest | RProjectFile<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, information: DataflowInformation, makeMaybe: boolean, getId?: IdGenerator<NoInfo>): DataflowInformation {
229230
// parse, normalize and dataflow the sourced file
230231
let dataflow: DataflowInformation;
231232
let fst: RProjectFile<OtherInfo & ParentInformation>;
@@ -276,11 +277,20 @@ export function sourceRequest<OtherInfo>(rootId: NodeId, request: RParseRequest
276277

277278
// take the entry point as well as all the written references, and give them a control dependency to the source call to show that they are conditional
278279
if(!String(rootId).startsWith('file-')) {
279-
if(dataflow.graph.hasVertex(dataflow.entryPoint)) {
280-
dataflow.graph.addControlDependency(dataflow.entryPoint, rootId, true);
281-
}
282-
for(const out of dataflow.out) {
283-
dataflow.graph.addControlDependency(out.nodeId, rootId, true);
280+
if(makeMaybe) {
281+
if(dataflow.graph.hasVertex(dataflow.entryPoint)) {
282+
dataflow.graph.addControlDependency(dataflow.entryPoint, rootId, true);
283+
}
284+
for(const out of dataflow.out) {
285+
dataflow.graph.addControlDependency(out.nodeId, rootId, true);
286+
}
287+
} else {
288+
if(dataflow.graph.hasVertex(dataflow.entryPoint)) {
289+
dataflow.graph.addEdge(dataflow.entryPoint, rootId, EdgeType.Reads);
290+
}
291+
for(const out of dataflow.out) {
292+
dataflow.graph.addEdge(out.nodeId, rootId, EdgeType.Reads);
293+
}
284294
}
285295
}
286296

@@ -319,5 +329,5 @@ export function standaloneSourceFile<OtherInfo>(
319329
...data,
320330
environment: information.environment,
321331
referenceChain: [...data.referenceChain, file.filePath]
322-
}, information);
332+
}, information, false);
323333
}

0 commit comments

Comments
 (0)