Skip to content

Commit 27f708e

Browse files
authored
feat-fix: vapply arg location (#2136)
* feat-fix: vapply arg location * feat-fix: wrong cyclic edge account
1 parent a664336 commit 27f708e

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

src/dataflow/internal/linker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { RParameter } from '../../r-bridge/lang-4.x/ast/model/nodes/r-param
88
import type { AstIdMap, ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
99
import { dataflowLogger } from '../logger';
1010
import { EmptyArgument } from '../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
11-
import { edgeIncludesType, EdgeType } from '../graph/edge';
11+
import { edgeDoesNotIncludeType, edgeIncludesType, EdgeType } from '../graph/edge';
1212
import { RType } from '../../r-bridge/lang-4.x/ast/model/type';
1313
import {
1414
type DataflowGraphVertexFunctionCall,
@@ -214,7 +214,7 @@ function linkFunctionCall(
214214

215215
const functionDefinitionReadIds = new Set<NodeId>();
216216
for(const [t, { types }] of edges.entries()) {
217-
if(!isBuiltIn(t) && edgeIncludesType(types, FCallLinkReadBits)) {
217+
if(!isBuiltIn(t) && edgeDoesNotIncludeType(types, EdgeType.Argument) && edgeIncludesType(types, FCallLinkReadBits)) {
218218
functionDefinitionReadIds.add(t);
219219
}
220220
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,19 @@ export function processApply<OtherInfo>(
6464
index = mayFn;
6565
}
6666
}
67-
67+
// shift the index to point to the index'd unnamed argument
68+
let posArgsFound = 0;
69+
for(let i = 0; i < args.length; i++) {
70+
const arg = args[i];
71+
if(arg !== EmptyArgument && arg.name) {
72+
// do nothing
73+
} else if(posArgsFound === index) {
74+
index = i;
75+
break;
76+
} else {
77+
posArgsFound++;
78+
}
79+
}
6880

6981
/* validate, that we indeed have so many arguments to fill this one :D */
7082
if(index >= args.length) {
@@ -96,7 +108,8 @@ export function processApply<OtherInfo>(
96108
if(resolveValue) {
97109
const resolved = valueSetGuard(resolveIdToValue(val.info.id, { environment: data.environment, idMap: data.completeAst.idMap , resolve: data.ctx.config.solver.variables, ctx: data.ctx }));
98110
if(resolved?.elements.length === 1 && resolved.elements[0].type === 'string') {
99-
functionName = isValue(resolved.elements[0].value) ? resolved.elements[0].value.str : undefined;
111+
const r = resolved.elements[0];
112+
functionName = isValue(r.value) ? r.value.str : undefined;
100113
}
101114
} else {
102115
functionName = val.content;

test/functionality/_helper/shell.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ export function assertSliced(
625625
const decodedExpected = expected.map(e => slicingCriterionToId(e, result.normalize.idMap))
626626
.sort((a, b) => String(a).localeCompare(String(b)))
627627
.map(n => normalizeIdToNumberIfPossible(n));
628-
const inSlice = [...result.slice.result]
628+
const inSlice = Array.from(result.slice.result)
629629
.sort((a, b) => String(a).localeCompare(String(b)))
630630
.map(n => normalizeIdToNumberIfPossible(n));
631631
assert.deepStrictEqual(inSlice, decodedExpected, `expected ids ${JSON.stringify(decodedExpected)} are not in the slice result ${JSON.stringify(inSlice)}, for input ${input} (slice for ${printIdMapping(result.slice.decodedCriteria.map(({ id }) => id), result.normalize.idMap)}), url: ${graphToMermaidUrl(result.dataflow.graph, true, result.slice.result)}`);
@@ -635,6 +635,7 @@ export function assertSliced(
635635
`got: ${result.reconstruct.code as string}, vs. expected: ${JSON.stringify(expected)}, for input ${input} (slice for ${JSON.stringify(criteria)}: ${printIdMapping(result.slice.decodedCriteria.map(({ id }) => id), result.normalize.idMap)}), url: ${graphToMermaidUrl(result.dataflow.graph, true, result.slice.result)}`
636636
);
637637
}
638+
assert.strictEqual(result.slice.timesHitThreshold, 0, 'the slice shall not hit the threshold');
638639
} /* v8 ignore start */ catch(e) {
639640
if(printError) {
640641
console.error(`got:\n${result.reconstruct.code as string}\nvs. expected:\n${JSON.stringify(expected)}`);

test/functionality/slicing/backward/static-backward-program-slices/calls.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,18 @@ x`);
753753
'foo <- bar()\nres <- lapply(1:3, function(x) foo * 2)'
754754
);
755755
});
756+
describe('With FUN.VALUE', () => {
757+
assertSliced(label('Force-Including Call Reference', [
758+
'name-normal', ...OperatorDatabase['<-'].capabilities, 'numbers', 'normal-definition', 'newlines', 'unnamed-arguments', 'call-normal', 'implicit-return', 'closures'
759+
]), shell,
760+
`themed <- vapply(defaults, FUN.VALUE = logical(1), function(x) {
761+
is_quosure(x) && quo_is_call(x, name = "from_theme")
762+
})`, ['1@themed'],
763+
`themed <- vapply(defaults, FUN.VALUE = logical(1), function(x) {
764+
is_quosure(x) && quo_is_call(x, name = "from_theme")
765+
})`
766+
);
767+
});
756768
describe('nested ddply', () => {
757769
assertSliced(label('Force-Including Call Reference', [
758770
'name-normal', ...OperatorDatabase['<-'].capabilities, 'numbers', 'normal-definition', 'newlines', 'unnamed-arguments', 'call-normal', 'implicit-return', 'closures'

test/functionality/slicing/backward/static-backward-program-slices/magic-comments.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { label } from '../../../_helper/label';
2-
import { type TestConfigurationWithOutput , assertSliced, withShell } from '../../../_helper/shell';
2+
import { type TestConfigurationWithOutput, assertSliced, withShell } from '../../../_helper/shell';
33
import { makeMagicCommentHandler } from '../../../../../src/reconstruct/auto-select/magic-comments';
44
import { describe } from 'vitest';
55

0 commit comments

Comments
 (0)