@eagleoutice/flowr 2.16.1 → 2.16.2
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/built-in-props.d.ts +5 -2
- package/dataflow/environments/built-in-props.js +6 -3
- package/dataflow/environments/default-builtin-config.d.ts +197 -11
- package/dataflow/environments/default-builtin-config.js +62 -42
- package/dataflow/environments/identifier.d.ts +1 -0
- package/dataflow/environments/query-fn-props.d.ts +3 -0
- package/dataflow/environments/query-fn-props.js +8 -0
- package/dataflow/environments/resolve-by-name.js +11 -4
- package/dataflow/eval/resolve/resolve-argument.js +5 -1
- package/dataflow/graph/graph.js +12 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +9 -0
- package/dataflow/internal/process/functions/call/named-call-handling.js +60 -8
- package/linter/linter-rules.d.ts +8 -3
- package/linter/rules/function-finder-util.d.ts +1 -1
- package/linter/rules/function-finder-util.js +1 -3
- package/linter/rules/network-functions.d.ts +4 -3
- package/linter/rules/network-functions.js +14 -12
- package/linter/rules/no-leaked-credentials.d.ts +8 -3
- package/linter/rules/no-leaked-credentials.js +133 -35
- package/linter/rules/problematic-inputs.d.ts +1 -1
- package/linter/rules/problematic-inputs.js +20 -14
- package/linter/rules/unescaped-arguments.d.ts +13 -2
- package/linter/rules/unescaped-arguments.js +100 -12
- package/package.json +1 -1
- package/queries/catalog/call-context-query/call-context-query-executor.js +2 -1
- package/queries/catalog/input-sources-query/input-source-functions.d.ts +6 -4
- package/queries/catalog/input-sources-query/input-source-functions.js +11 -6
- package/queries/catalog/input-sources-query/input-sources-query-executor.js +1 -1
- package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +1 -1
- package/queries/catalog/input-sources-query/input-sources-query-format.js +9 -2
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +12 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.js +227 -29
- package/search/search-executor/search-enrichers.js +5 -3
- package/util/version.js +2 -2
|
@@ -13,6 +13,8 @@ const vertex_1 = require("../../../dataflow/graph/vertex");
|
|
|
13
13
|
const df_helper_1 = require("../../../dataflow/graph/df-helper");
|
|
14
14
|
const edge_1 = require("../../../dataflow/graph/edge");
|
|
15
15
|
const identifier_1 = require("../../../dataflow/environments/identifier");
|
|
16
|
+
const r_parameter_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
|
|
17
|
+
const r_comment_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-comment");
|
|
16
18
|
const assert_1 = require("../../../util/assert");
|
|
17
19
|
const arrays_1 = require("../../../util/collections/arrays");
|
|
18
20
|
const built_in_proc_name_1 = require("../../../dataflow/environments/built-in-proc-name");
|
|
@@ -24,7 +26,11 @@ const r_symbol_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol"
|
|
|
24
26
|
const convert_values_1 = require("../../../r-bridge/lang-4.x/convert-values");
|
|
25
27
|
const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
|
|
26
28
|
const r_function_definition_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
29
|
+
const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
30
|
+
const r_argument_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
27
31
|
const frame_reflection_1 = require("../../../dataflow/fn/frame-reflection");
|
|
32
|
+
const range_1 = require("../../../util/range");
|
|
33
|
+
const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
|
|
28
34
|
/** how far a function handed to an entry point may be passed along before we give up resolving it */
|
|
29
35
|
const MaxFunctionResolveDepth = 4;
|
|
30
36
|
function isConstantLike(type) {
|
|
@@ -77,8 +83,10 @@ class InputClassifier {
|
|
|
77
83
|
packages;
|
|
78
84
|
cache = new Map();
|
|
79
85
|
fullClassifier;
|
|
86
|
+
unsanitized;
|
|
80
87
|
declarationIndex;
|
|
81
88
|
entryPointIndex;
|
|
89
|
+
rebinding;
|
|
82
90
|
/** `packages` are the packages attached in the analyzed program, `undefined` if that is not known (then everything may match) */
|
|
83
91
|
constructor(dfg, config, fullDfg, packages) {
|
|
84
92
|
this.dfg = dfg;
|
|
@@ -90,7 +98,12 @@ class InputClassifier {
|
|
|
90
98
|
return this.fullDfg ?? this.dfg;
|
|
91
99
|
}
|
|
92
100
|
matches(call, list) {
|
|
93
|
-
|
|
101
|
+
/* a call of a definition in the code does not mean the built-in of the same name */
|
|
102
|
+
return list?.some(id => call.id === id || (identifier_1.Identifier.is(id) && callMeans(call.name, id, this.packages) && !this.callsDefinition(call))) ?? false;
|
|
103
|
+
}
|
|
104
|
+
/** whether the callee is a definition of the code rather than one handed in as an argument */
|
|
105
|
+
callsDefinition(call) {
|
|
106
|
+
return (0, frame_reflection_1.calledDefinitions)(this.whole, call.id).some(d => !(0, frame_reflection_1.hasEdgeOfType)(this.whole, call.id, d, edge_1.EdgeType.Argument));
|
|
94
107
|
}
|
|
95
108
|
/** whether the package the given entry needs is attached (unknown package information lets everything through) */
|
|
96
109
|
hasPackage(name) {
|
|
@@ -98,7 +111,26 @@ class InputClassifier {
|
|
|
98
111
|
}
|
|
99
112
|
classifyAt(ref, graph = this.dfg) {
|
|
100
113
|
const vtx = ref === undefined ? undefined : graph.getVertex(ref);
|
|
101
|
-
|
|
114
|
+
/* what the criterion's function reads through a template (`glue("{x}")`) is no node of its code */
|
|
115
|
+
return vtx ? this.classifyEntry(vtx) : ref !== undefined && graph === this.dfg ? this.classifyInFullGraph(ref) : undefined;
|
|
116
|
+
}
|
|
117
|
+
/** classifies an argument as written: the name a `get` looks up, the function `do.call` is handed */
|
|
118
|
+
classifyArgument(call, ref) {
|
|
119
|
+
const node = ref === undefined ? undefined : this.dfg.idMap?.get(ref);
|
|
120
|
+
const parent = node?.info.parent === undefined ? undefined : this.dfg.idMap?.get(node.info.parent);
|
|
121
|
+
const vtx = ref === undefined ? undefined : this.dfg.getVertex(ref);
|
|
122
|
+
if (ref === undefined || !r_symbol_1.RSymbol.is(node)) {
|
|
123
|
+
return this.classifyAt(ref);
|
|
124
|
+
}
|
|
125
|
+
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Get) && parent !== undefined && !r_argument_1.RArgument.is(parent)) {
|
|
126
|
+
const written = r_string_1.RString.is(parent) ? (0, objects_1.compactRecord)({ ...sourceOf(ref, input_types_1.InputType.Constant), value: parent.content.str }) : this.classifyAt(parent.info.id);
|
|
127
|
+
return written && { ...written, id: ref };
|
|
128
|
+
}
|
|
129
|
+
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Apply) && vertex_1.DfgVertex.isFunctionCall(vtx) && (0, frame_reflection_1.edgeTargets)(this.dfg, ref, edge_1.EdgeType.Reads).every(t => node_id_1.NodeId.isBuiltIn(t) || !this.functionDefinitionsAt(t).next().done)) {
|
|
130
|
+
/* a name of a function the code defines or flowR knows */
|
|
131
|
+
return sourceOf(ref, input_types_1.InputType.Constant);
|
|
132
|
+
}
|
|
133
|
+
return this.classifyAt(ref);
|
|
102
134
|
}
|
|
103
135
|
/**
|
|
104
136
|
* Returns the specification of the {@link LinkedInputObject|linked input object} the given id refers to
|
|
@@ -276,6 +308,13 @@ class InputClassifier {
|
|
|
276
308
|
const parameters = new Set(enclosing.flatMap(fn => fn.parameters.map(p => identifier_1.Identifier.getName(p.name.content))));
|
|
277
309
|
for (const arg of call.args) {
|
|
278
310
|
const ref = graph_1.FunctionArgument.getReference(arg);
|
|
311
|
+
/* an evaluated argument (`parse_expr(text)`) is code only as far as its value is */
|
|
312
|
+
if (ref !== undefined && (0, frame_reflection_1.hasEdgeOfType)(this.whole, call.id, ref, edge_1.EdgeType.Reads)) {
|
|
313
|
+
if (!this.classifyAt(ref)?.types.every(isConstantLike)) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
279
318
|
const within = model_1.RNode.collectAllIds(ref === undefined ? undefined : idMap.get(ref));
|
|
280
319
|
for (const id of within) {
|
|
281
320
|
const node = idMap.get(id);
|
|
@@ -323,49 +362,95 @@ class InputClassifier {
|
|
|
323
362
|
}
|
|
324
363
|
return undefined;
|
|
325
364
|
}
|
|
326
|
-
/** the argument a built-in hands on: the value of a block or `get` (then `renamed`), the condition of a
|
|
365
|
+
/** the argument a built-in hands on: the value of a block or `get` (then `renamed`), the condition of a loop */
|
|
327
366
|
passedOn(call) {
|
|
328
367
|
if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.ExpressionList)) {
|
|
329
368
|
// `{ a; b }` evaluates to its last expression, just like in R
|
|
330
369
|
return { via: call.args.findLast(a => !graph_1.FunctionArgument.isEmpty(a)), renamed: true };
|
|
331
370
|
}
|
|
332
|
-
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.
|
|
371
|
+
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop)) {
|
|
333
372
|
return { via: call.args[0], renamed: false };
|
|
334
373
|
}
|
|
335
374
|
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.ForLoop)) {
|
|
336
375
|
return { via: call.args[1], renamed: false };
|
|
337
376
|
}
|
|
338
|
-
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Get) && !this.whole.unknownSideEffects.has(node_id_1.NodeId.normalize(call.id))
|
|
377
|
+
else if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Get) && !this.whole.unknownSideEffects.has(node_id_1.NodeId.normalize(call.id))
|
|
378
|
+
&& (0, frame_reflection_1.edgeTargets)(this.whole, call.id, edge_1.EdgeType.Returns).length > 0) {
|
|
339
379
|
// a statically resolved `get("x")` yields the value of the retrieved variable, read via its first argument
|
|
340
380
|
return { via: call.args[0], renamed: true };
|
|
341
381
|
}
|
|
342
382
|
return undefined;
|
|
343
383
|
}
|
|
384
|
+
/** an `if` or `switch` yields one of its branches (`NULL` without a matching one), its condition only picks which */
|
|
385
|
+
classifyBranches(call) {
|
|
386
|
+
const acc = new ClassificationAccumulator();
|
|
387
|
+
const isSwitch = call.origin.includes(built_in_proc_name_1.BuiltInProcName.Switch);
|
|
388
|
+
const condition = conditionArgument(call);
|
|
389
|
+
const branches = call.args.filter(a => a !== condition);
|
|
390
|
+
for (const ref of branches.map(graph_1.FunctionArgument.getReference)) {
|
|
391
|
+
/* a branch flowR found dead is in no graph */
|
|
392
|
+
const vtx = ref === undefined ? undefined : this.dfg.getVertex(ref) ?? this.whole.getVertex(ref);
|
|
393
|
+
if (vtx !== undefined) {
|
|
394
|
+
acc.merge(this.classifyEntry(vtx));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (isSwitch || branches.length < 2 || branches.some(graph_1.FunctionArgument.isEmpty)) {
|
|
398
|
+
acc.push(input_types_1.InputType.Constant, null);
|
|
399
|
+
}
|
|
400
|
+
acc.cds.push(...condition === undefined ? [] : this.dependencies(graph_1.FunctionArgument.getReference(condition), []));
|
|
401
|
+
return acc.build(call.id);
|
|
402
|
+
}
|
|
403
|
+
/** the arguments of a sanitizer it takes as code rather than escaping, see {@link InputClassifierConfig.templates} */
|
|
404
|
+
templateArguments(call) {
|
|
405
|
+
return (this.config.templates ?? []).filter(t => this.matches(call, [t.call])).flatMap(t => t.argName === '...'
|
|
406
|
+
? call.args.filter(a => !graph_1.FunctionArgument.isNamed(a)).map(graph_1.FunctionArgument.getReference)
|
|
407
|
+
: [this.argumentReference(call, t.argIdx, t.argName)]);
|
|
408
|
+
}
|
|
409
|
+
/** the types and control dependencies of what `ref` yields, `unknown` when it cannot be classified */
|
|
410
|
+
dependencies(ref, unknown = [input_types_1.InputType.Unknown]) {
|
|
411
|
+
const c = this.classifyAt(ref);
|
|
412
|
+
return c ? [...c.types, ...c.cds ?? []] : unknown;
|
|
413
|
+
}
|
|
414
|
+
/** what a control dependency on the given id depends on: the condition of an `if` or `switch`, else the id itself */
|
|
415
|
+
conditionOf(id) {
|
|
416
|
+
const vtx = this.dfg.getVertex(id);
|
|
417
|
+
const condition = vertex_1.DfgVertex.isFunctionCall(vtx) ? conditionArgument(vtx) : undefined;
|
|
418
|
+
return condition === undefined ? id : graph_1.FunctionArgument.getReference(condition);
|
|
419
|
+
}
|
|
344
420
|
classifyFunctionCall(call) {
|
|
345
421
|
const linkedAccess = this.classifyLinkedObjectAccess(call);
|
|
346
422
|
if (linkedAccess) {
|
|
347
423
|
return this.classifyCdsAndReturn(call, linkedAccess);
|
|
348
424
|
}
|
|
425
|
+
if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) || call.origin.includes(built_in_proc_name_1.BuiltInProcName.Switch)) {
|
|
426
|
+
return this.classifyCdsAndReturn(call, this.classifyBranches(call));
|
|
427
|
+
}
|
|
349
428
|
const handed = this.passedOn(call);
|
|
350
429
|
const passed = this.classifyAt(handed?.via === undefined ? undefined : graph_1.FunctionArgument.getReference(handed.via));
|
|
351
430
|
if (passed) {
|
|
352
431
|
return this.classifyCdsAndReturn(call, handed?.renamed ? { ...passed, id: call.id } : passed);
|
|
353
432
|
}
|
|
354
|
-
|
|
355
|
-
|
|
433
|
+
if (this.matches(call, this.config.sanitizers)) {
|
|
434
|
+
const acc = new ClassificationAccumulator();
|
|
435
|
+
acc.push(input_types_1.InputType.DerivedConstant);
|
|
436
|
+
this.templateArguments(call).forEach(t => acc.merge(this.classifyAt(t)));
|
|
437
|
+
return this.classifyCdsAndReturn(call, acc.build(call.id));
|
|
438
|
+
}
|
|
439
|
+
// a narrowing function returns one of a specific argument's values (e.g. `match.arg` -> its `choices`)
|
|
356
440
|
for (const narrow of this.config.narrowing ?? []) {
|
|
357
441
|
if (!this.matches(call, [narrow.call])) {
|
|
358
442
|
continue;
|
|
359
443
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
const narrowed = this.classifyAt(this.argumentReference(call, narrow.argIdx, narrow.argName ?? ''));
|
|
444
|
+
const bound = this.argumentReference(call, narrow.argIdx, narrow.argName);
|
|
445
|
+
const narrowed = this.classifyAt(bound);
|
|
364
446
|
if (narrowed) {
|
|
365
|
-
|
|
447
|
+
/* which of the values it is depends on the other arguments */
|
|
448
|
+
const cds = call.args.map(graph_1.FunctionArgument.getReference).filter(a => a !== bound).flatMap(a => this.dependencies(a));
|
|
449
|
+
return this.classifyCdsAndReturn(call, { ...narrowed, id: call.id, cds: (0, arrays_1.uniqueArray)([...narrowed.cds ?? [], ...cds]) });
|
|
366
450
|
}
|
|
367
451
|
}
|
|
368
|
-
|
|
452
|
+
const evaluates = this.matches(call, this.config.evaluating);
|
|
453
|
+
if (!evaluates && !this.matches(call, this.config.pure)) {
|
|
369
454
|
const types = record_1.Record.values(input_types_1.InputType).filter(type => this.matches(call, this.config[type]));
|
|
370
455
|
// if a File-typed call reads from a temp path, replace File with TempFile
|
|
371
456
|
const readsFile = types.includes(input_types_1.InputType.File) && !types.includes(input_types_1.InputType.TempFile);
|
|
@@ -380,7 +465,20 @@ class InputClassifier {
|
|
|
380
465
|
if (types.length === 0) {
|
|
381
466
|
/* a call of something the code produced (a shiny `reactive()`) or defines yields what that produced or returns */
|
|
382
467
|
const produced = this.classifyCallee(call) ?? this.classifyDefinitionResult(call);
|
|
383
|
-
if (produced !== undefined) {
|
|
468
|
+
if (produced !== undefined && call.origin.includes(built_in_proc_name_1.BuiltInProcName.Try)) {
|
|
469
|
+
/* the handlers only answer for a failing block, which may just as well succeed */
|
|
470
|
+
const acc = new ClassificationAccumulator();
|
|
471
|
+
const block = this.argumentReference(call, 0, 'expr');
|
|
472
|
+
acc.merge(produced);
|
|
473
|
+
acc.merge(this.classifyAt(block));
|
|
474
|
+
/* and whether they answer depends on everything the block does */
|
|
475
|
+
const statements = block === undefined ? undefined : this.whole.getVertex(block);
|
|
476
|
+
for (const arg of vertex_1.DfgVertex.isFunctionCall(statements) && vertex_1.DfgVertex.hasOrigin(statements, built_in_proc_name_1.BuiltInProcName.ExpressionList) ? statements.args : []) {
|
|
477
|
+
acc.cds.push(...this.dependencies(graph_1.FunctionArgument.getReference(arg)));
|
|
478
|
+
}
|
|
479
|
+
return this.classifyCdsAndReturn(call, acc.build(call.id));
|
|
480
|
+
}
|
|
481
|
+
else if (produced !== undefined) {
|
|
384
482
|
return this.classifyCdsAndReturn(call, { ...produced, id: call.id });
|
|
385
483
|
}
|
|
386
484
|
// if it is not pure, we cannot classify based on the inputs, in that case we do not know!
|
|
@@ -388,10 +486,18 @@ class InputClassifier {
|
|
|
388
486
|
}
|
|
389
487
|
return this.classifyCdsAndReturn(call, { id: call.id, types, trace: input_types_1.InputTraceType.Unknown });
|
|
390
488
|
}
|
|
391
|
-
const argTypes = [];
|
|
489
|
+
const argTypes = evaluates ? [input_types_1.InputType.Unknown] : [];
|
|
392
490
|
const cdTypes = [];
|
|
393
|
-
|
|
394
|
-
|
|
491
|
+
const interpolated = this.templateReads(call);
|
|
492
|
+
/* cutting into what a sanitizer escaped undoes the escape */
|
|
493
|
+
const edits = this.matches(call, this.config.editing);
|
|
494
|
+
const of = edits && this.config.sanitizers !== undefined ? this.unsanitized ??= new InputClassifier(this.dfg, { ...this.config, sanitizers: undefined }, this.fullDfg, this.packages) : this;
|
|
495
|
+
for (const ref of (0, arrays_1.uniqueArray)([...call.args.filter(graph_1.FunctionArgument.isNotEmpty).map(graph_1.FunctionArgument.getReference), ...interpolated])) {
|
|
496
|
+
/* a function handed in (`sapply(x, function(i) runif(1))`) contributes what it returns */
|
|
497
|
+
const vtx = ref === undefined ? undefined : this.whole.getVertex(ref);
|
|
498
|
+
const fns = vtx === undefined || vertex_1.DfgVertex.isFunctionCall(vtx) ? [] : [...this.functionDefinitionsAt(ref)];
|
|
499
|
+
const classified = fns.length > 0 ? this.classifyExits(fns, ref)
|
|
500
|
+
: vertex_1.DfgVertex.isFunctionCall(vtx) && identifier_1.Identifier.getName(vtx.name) === '~' && (0, frame_reflection_1.hasEdgeOfType)(this.whole, call.id, vtx.id, edge_1.EdgeType.Calls) ? this.classifyFormula(vtx) : of.classifyAt(ref);
|
|
395
501
|
argTypes.push(...classified?.types ?? [input_types_1.InputType.Unknown]);
|
|
396
502
|
cdTypes.push(...classified?.cds ?? []);
|
|
397
503
|
}
|
|
@@ -400,7 +506,7 @@ class InputClassifier {
|
|
|
400
506
|
return this.classifyCdsAndReturn(call, (0, objects_1.compactRecord)({
|
|
401
507
|
id: call.id,
|
|
402
508
|
types: constLike ? [input_types_1.InputType.DerivedConstant] : (0, arrays_1.uniqueArray)([...argTypes, input_types_1.InputType.DerivedConstant]),
|
|
403
|
-
trace: constLike ? input_types_1.InputTraceType.Pure : input_types_1.InputTraceType.Known,
|
|
509
|
+
trace: constLike ? input_types_1.InputTraceType.Pure : evaluates || edits || interpolated.length > 0 ? input_types_1.InputTraceType.Unknown : input_types_1.InputTraceType.Known,
|
|
404
510
|
cds: cdTypes.length > 0 ? (0, arrays_1.uniqueArray)(cdTypes) : undefined
|
|
405
511
|
}));
|
|
406
512
|
}
|
|
@@ -410,8 +516,22 @@ class InputClassifier {
|
|
|
410
516
|
* when the call names no definition here or when none of them says anything about what it returns.
|
|
411
517
|
*/
|
|
412
518
|
classifyDefinitionResult(call) {
|
|
519
|
+
return this.classifyExits(this.functionDefinitionsAt(call.id), call.id);
|
|
520
|
+
}
|
|
521
|
+
/** what a string template like `glue("{x}")` evaluates and reads, which is no argument, but flows in all the same */
|
|
522
|
+
templateReads(call) {
|
|
523
|
+
return call.origin.includes(built_in_proc_name_1.BuiltInProcName.StringTemplate) ? (0, frame_reflection_1.edgeTargets)(this.whole, call.id, edge_1.EdgeType.Reads).filter(t => this.whole.hasVertex(t) && !vertex_1.DfgVertex.hasOrigin(this.whole.getVertex(t), built_in_proc_name_1.BuiltInProcName.Library)) : [];
|
|
524
|
+
}
|
|
525
|
+
/** a formula called as a function (`purrr::map(x, ~ runif(1))`) yields what its body does */
|
|
526
|
+
classifyFormula(formula) {
|
|
413
527
|
const acc = new ClassificationAccumulator();
|
|
414
|
-
|
|
528
|
+
formula.args.forEach(a => acc.merge(this.classifyAt(graph_1.FunctionArgument.getReference(a))));
|
|
529
|
+
return acc.build(formula.id);
|
|
530
|
+
}
|
|
531
|
+
/** what the exit points of the given function definitions yield, see {@link classifyDefinitionResult} */
|
|
532
|
+
classifyExits(fns, id) {
|
|
533
|
+
const acc = new ClassificationAccumulator();
|
|
534
|
+
for (const fn of fns) {
|
|
415
535
|
const definition = this.whole.getVertex(fn);
|
|
416
536
|
for (const { nodeId } of vertex_1.DfgVertex.isFunctionDefinition(definition) ? definition.exitPoints : []) {
|
|
417
537
|
for (const value of this.exitValues(nodeId)) {
|
|
@@ -428,7 +548,7 @@ class InputClassifier {
|
|
|
428
548
|
if (acc.values.length === 0) {
|
|
429
549
|
return undefined;
|
|
430
550
|
}
|
|
431
|
-
const built = acc.build(
|
|
551
|
+
const built = acc.build(id);
|
|
432
552
|
return built.types.includes(input_types_1.InputType.Unknown) ? undefined : built;
|
|
433
553
|
}
|
|
434
554
|
/**
|
|
@@ -469,7 +589,11 @@ class InputClassifier {
|
|
|
469
589
|
continue;
|
|
470
590
|
}
|
|
471
591
|
const classified = this.classifyAt(o.id) ?? this.classifyInFullGraph(o.id);
|
|
472
|
-
if (classified
|
|
592
|
+
if (classified?.types.every(isConstantLike)) {
|
|
593
|
+
/* a constant held as a function (`get("readLines")`, a body set to quoted code) says nothing about what calling it yields */
|
|
594
|
+
return sourceOf(call.id, input_types_1.InputType.Unknown);
|
|
595
|
+
}
|
|
596
|
+
else if (classified !== undefined && !classified.types.includes(input_types_1.InputType.Unknown)) {
|
|
473
597
|
return classified;
|
|
474
598
|
}
|
|
475
599
|
}
|
|
@@ -504,13 +628,35 @@ class InputClassifier {
|
|
|
504
628
|
acc.merge(undefined);
|
|
505
629
|
}
|
|
506
630
|
}
|
|
631
|
+
if (this.mayBeRebound(vtx.id, origins.map(o => o.id))) {
|
|
632
|
+
acc.merge(undefined);
|
|
633
|
+
}
|
|
507
634
|
return this.classifyCdsAndReturn(vtx, acc.build(vtx.id));
|
|
508
635
|
}
|
|
636
|
+
/** what the default of a parameter yields when a call leaves the parameter out */
|
|
637
|
+
defaultTypes(id) {
|
|
638
|
+
const idMap = this.whole.idMap;
|
|
639
|
+
const param = idMap?.get(idMap.get(id)?.info.parent);
|
|
640
|
+
return r_parameter_1.RParameter.is(param) && param.defaultValue !== undefined ? this.classifyInFullGraph(param.defaultValue.info.id)?.types ?? [input_types_1.InputType.Unknown] : [];
|
|
641
|
+
}
|
|
509
642
|
parameterType(id) {
|
|
510
643
|
if (this.dfg.idMap?.get(id)?.info.role !== "param-n" /* RoleInParent.ParameterName */) {
|
|
511
644
|
return undefined;
|
|
512
645
|
}
|
|
513
|
-
return this.matchWholeLinkedObject(id)?.type ?? input_types_1.InputType.Parameter;
|
|
646
|
+
return this.matchWholeLinkedObject(id)?.type ?? (this.isPlumberEndpointParameter(id) ? input_types_1.InputType.User : input_types_1.InputType.Parameter);
|
|
647
|
+
}
|
|
648
|
+
/** plumber hands each parameter of a function with a `#*` route annotation what a request sends */
|
|
649
|
+
isPlumberEndpointParameter(id) {
|
|
650
|
+
const idMap = this.whole.idMap;
|
|
651
|
+
for (const node of model_1.RNode.iterateParents(idMap.get(id), idMap)) {
|
|
652
|
+
if (node.info.adToks?.some(t => r_comment_1.RComment.is(t) && PlumberEndpoint.test(t.lexeme ?? ''))) {
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
else if (node.info.parent === undefined || (r_function_definition_1.RFunctionDefinition.is(node) && node.info.adToks?.length)) {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return false;
|
|
514
660
|
}
|
|
515
661
|
/**
|
|
516
662
|
* Resolves a variable definition or use origin, handling the special cases of
|
|
@@ -529,7 +675,7 @@ class InputClassifier {
|
|
|
529
675
|
const callers = onCall.map(t => this.classifyInFullGraph(t)).filter(assert_1.isNotUndefined);
|
|
530
676
|
const known = callers.filter(c => !c.types.includes(input_types_1.InputType.Unknown));
|
|
531
677
|
known.forEach(c => acc.merge(c));
|
|
532
|
-
if (known.length > 0 && known.length === callers.length) {
|
|
678
|
+
if (known.length > 0 && known.length === callers.length && !this.escapes(v.id)) {
|
|
533
679
|
return;
|
|
534
680
|
}
|
|
535
681
|
acc.push(input_types_1.InputType.Scope);
|
|
@@ -538,15 +684,50 @@ class InputClassifier {
|
|
|
538
684
|
const parameter = vertex_1.DfgVertex.isVariableDefinition(v) ? this.parameterType(v.id) : undefined;
|
|
539
685
|
if (parameter !== undefined) {
|
|
540
686
|
acc.push(parameter);
|
|
687
|
+
acc.types.push(...this.defaultTypes(v.id));
|
|
541
688
|
}
|
|
542
689
|
else {
|
|
543
690
|
acc.merge(this.classifyEntry(v));
|
|
544
691
|
}
|
|
545
692
|
}
|
|
693
|
+
/** whether the function binding the parameter is used as a value, so it may be called with anything the visible callers do not pass */
|
|
694
|
+
escapes(parameter) {
|
|
695
|
+
const idMap = this.whole.idMap;
|
|
696
|
+
const fn = idMap === undefined ? undefined : model_1.RNode.iterateParents(idMap.get(parameter), idMap).find(r_function_definition_1.RFunctionDefinition.is);
|
|
697
|
+
const holders = fn === undefined ? [] : (0, frame_reflection_1.edgeSources)(this.whole, fn.info.id, edge_1.EdgeType.DefinedBy);
|
|
698
|
+
return holders.length === 0 || holders.some(h => (0, frame_reflection_1.edgeSources)(this.whole, h, edge_1.EdgeType.Reads)
|
|
699
|
+
.some(r => !r_function_call_1.RFunctionCall.is(idMap?.get(r)) || !(0, frame_reflection_1.hasEdgeOfType)(this.whole, r, fn?.info.id, edge_1.EdgeType.Calls)));
|
|
700
|
+
}
|
|
701
|
+
/** whether code flowR cannot follow (`load`, `eval`, `e$x <-`) may rebind the variable before the use */
|
|
702
|
+
mayBeRebound(use, definitions) {
|
|
703
|
+
const idMap = this.whole.idMap;
|
|
704
|
+
const node = idMap.get(use);
|
|
705
|
+
const fn = model_1.RNode.iterateParents(node, idMap).find(r_function_definition_1.RFunctionDefinition.is);
|
|
706
|
+
const within = (id) => fn !== undefined && model_1.RNode.iterateParents(idMap.get(id), idMap).some(p => p === fn);
|
|
707
|
+
const local = definitions.length > 0 && definitions.every(within);
|
|
708
|
+
/* an unconditional definition after the effect binds anew */
|
|
709
|
+
const overwritten = (e) => definitions.length > 0 && definitions.every(d => !this.whole.getVertex(d)?.cds?.length
|
|
710
|
+
&& runsAfter(idMap.get(idMap.get(d)?.info.parent), idMap.get(e), idMap));
|
|
711
|
+
return this.rebinders().some(([e, fields]) => (fields === undefined || fields.some(f => f === undefined || f === model_1.RNode.lexeme(node)))
|
|
712
|
+
&& (!local || within(e)) && !overwritten(e) && !((fn === undefined || local) && runsAfter(idMap.get(e), node, idMap)));
|
|
713
|
+
}
|
|
714
|
+
/** the unknown side effects, and the replacements `e$x <- v` with the names they may bind (`undefined` for any) */
|
|
715
|
+
rebinders() {
|
|
716
|
+
const name = (a) => {
|
|
717
|
+
const ref = graph_1.FunctionArgument.getReference(a);
|
|
718
|
+
return ref === undefined ? undefined : this.extractConstantValue(ref) ?? model_1.RNode.lexeme(this.whole.idMap?.get(ref));
|
|
719
|
+
};
|
|
720
|
+
return this.rebinding ??= [
|
|
721
|
+
...[...this.whole.unknownSideEffects].filter(e => !graph_1.UnknownSideEffect.isLinked(e)).map(e => [graph_1.UnknownSideEffect.id(e), undefined]),
|
|
722
|
+
...this.whole.verticesOfType(vertex_1.VertexType.FunctionCall)
|
|
723
|
+
.filter(([, c]) => c.origin.includes(built_in_proc_name_1.BuiltInProcName.Replacement) && FieldReplacements.has(identifier_1.Identifier.getName(c.name)))
|
|
724
|
+
.map(([id, c]) => [id, c.args.slice(1, -1).map(name)])
|
|
725
|
+
];
|
|
726
|
+
}
|
|
546
727
|
classifyVariableDefinition(vtx) {
|
|
547
728
|
const parameter = this.parameterType(vtx.id);
|
|
548
729
|
if (parameter !== undefined) {
|
|
549
|
-
return this.classifyCdsAndReturn(vtx, sourceOf(vtx.id, parameter));
|
|
730
|
+
return this.classifyCdsAndReturn(vtx, { ...sourceOf(vtx.id, parameter), types: (0, arrays_1.uniqueArray)([parameter, ...this.defaultTypes(vtx.id)]) });
|
|
550
731
|
}
|
|
551
732
|
else if (!vtx.source?.length) {
|
|
552
733
|
// fallback to unknown if we cannot find the value
|
|
@@ -559,10 +740,7 @@ class InputClassifier {
|
|
|
559
740
|
classifyCdsAndReturn(vtx, src) {
|
|
560
741
|
if (vtx.cds) {
|
|
561
742
|
/* running only once a call forces it is no condition on the data */
|
|
562
|
-
const cds = (0, arrays_1.uniqueArray)(vtx.cds.filter(c => c.byPromise !== true).flatMap(c =>
|
|
563
|
-
const e = this.classifyAt(c.id);
|
|
564
|
-
return e ? [...e.types, ...e.cds ?? []] : [];
|
|
565
|
-
}).concat(src.cds ?? []));
|
|
743
|
+
const cds = (0, arrays_1.uniqueArray)(vtx.cds.filter(c => c.byPromise !== true).flatMap(c => this.dependencies(this.conditionOf(c.id), [])).concat(src.cds ?? []));
|
|
566
744
|
if (cds.length > 0) {
|
|
567
745
|
src.cds = cds;
|
|
568
746
|
}
|
|
@@ -574,6 +752,13 @@ class InputClassifier {
|
|
|
574
752
|
return src;
|
|
575
753
|
}
|
|
576
754
|
}
|
|
755
|
+
/** the condition of an `if` or `switch`; with named arguments to an `if`, we do not know which it is */
|
|
756
|
+
function conditionArgument(call) {
|
|
757
|
+
if (call.origin.includes(built_in_proc_name_1.BuiltInProcName.Switch)) {
|
|
758
|
+
return call.args.find(a => graph_1.FunctionArgument.hasName(a, 'EXPR')) ?? call.args.find(a => !graph_1.FunctionArgument.isNamed(a));
|
|
759
|
+
}
|
|
760
|
+
return call.origin.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse) && !call.args.some(graph_1.FunctionArgument.isNamed) ? call.args[0] : undefined;
|
|
761
|
+
}
|
|
577
762
|
/** the function definitions the given node is nested in, innermost first */
|
|
578
763
|
function* enclosingFunctions(node, idMap) {
|
|
579
764
|
for (const parent of model_1.RNode.iterateParents(node, idMap)) {
|
|
@@ -595,6 +780,19 @@ function isBoundAsLinkedObject(node, obj, idMap) {
|
|
|
595
780
|
}
|
|
596
781
|
return false;
|
|
597
782
|
}
|
|
783
|
+
const PlumberEndpoint = /^#\*\s*@(?:get|post|put|delete|patch|head|options|any|use)\b/i;
|
|
784
|
+
/** the replacements that may write a binding of an environment, as `e$x <- v` does */
|
|
785
|
+
const FieldReplacements = new Set(['$<-', '[[<-']);
|
|
786
|
+
const LoopTypes = new Set([type_1.RType.ForLoop, type_1.RType.WhileLoop, type_1.RType.RepeatLoop]);
|
|
787
|
+
/** whether `later` surely runs after `node`: later in the same file, in no shared loop, not deferred into a function apart from it */
|
|
788
|
+
function runsAfter(later, node, idMap) {
|
|
789
|
+
const [first, second] = [model_1.RNode.span(node), model_1.RNode.span(later)];
|
|
790
|
+
if (first === undefined || second === undefined || node?.info.file !== later?.info.file || !(range_1.SourceRange.startsCompletelyBefore(first, second) || range_1.SourceRange.isSubsetOf(first, second))) {
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
793
|
+
const around = new Set(model_1.RNode.iterateParents(later, idMap));
|
|
794
|
+
return model_1.RNode.iterateParents(node, idMap).every(p => r_function_definition_1.RFunctionDefinition.is(p) ? around.has(p) : !LoopTypes.has(p.type) || !around.has(p));
|
|
795
|
+
}
|
|
598
796
|
function declarationKey(object, field) {
|
|
599
797
|
return `${object}\u0000${field}`;
|
|
600
798
|
}
|
|
@@ -632,7 +830,7 @@ function classifyInput(id, dfg, config, fullDfg, packages) {
|
|
|
632
830
|
}
|
|
633
831
|
const ret = [];
|
|
634
832
|
for (const arg of vtx.args) {
|
|
635
|
-
const entry = c.
|
|
833
|
+
const entry = c.classifyArgument(vtx, graph_1.FunctionArgument.getReference(arg));
|
|
636
834
|
if (entry === undefined) {
|
|
637
835
|
continue;
|
|
638
836
|
}
|
|
@@ -95,7 +95,6 @@ exports.Enrichments = {
|
|
|
95
95
|
ast: await data.normalize()
|
|
96
96
|
},
|
|
97
97
|
enrichElement: async (e, s, analyzer, args, prev) => {
|
|
98
|
-
// we don't resolve aliases here yet!
|
|
99
98
|
const content = { targets: [] };
|
|
100
99
|
const shared = s.enrichmentContent(Enrichment.CallTargets);
|
|
101
100
|
const df = shared?.dfg ?? await analyzer.dataflow();
|
|
@@ -134,8 +133,11 @@ exports.Enrichments = {
|
|
|
134
133
|
return qualifyIdentifier([o], node_id_1.NodeId.recoverName(o.id, n.idMap)) ?? String(o.id);
|
|
135
134
|
}
|
|
136
135
|
return { node: n.idMap.get(o.id) };
|
|
137
|
-
case 3 /* OriginType.BuiltInFunctionOrigin */:
|
|
138
|
-
|
|
136
|
+
case 3 /* OriginType.BuiltInFunctionOrigin */: {
|
|
137
|
+
/* an alias (`s <- system; s()`) calls the built-in it is linked to rather than its own name */
|
|
138
|
+
const linked = node_id_1.NodeId.isBuiltIn(o.proc) ? node_id_1.NodeId.toPkgFn(o.proc)?.[1] ?? node_id_1.NodeId.fromBuiltIn(o.proc) : undefined;
|
|
139
|
+
return qualifyIdentifier([o], linked === undefined || linked === identifier_1.Identifier.getName(o.fn.name) ? o.fn.name : linked);
|
|
140
|
+
}
|
|
139
141
|
default:
|
|
140
142
|
return undefined;
|
|
141
143
|
}
|
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.16.
|
|
45
|
+
const version = '2.16.2';
|
|
46
46
|
// this is automatically replaced with the release date by release-it (scripts/bump-version.ts)
|
|
47
|
-
const versionDate = '2026-10-
|
|
47
|
+
const versionDate = '2026-10-16T18:03:09Z';
|
|
48
48
|
/**
|
|
49
49
|
* Retrieves the current flowR version as a new {@link SemVer} object.
|
|
50
50
|
*/
|