@eagleoutice/flowr 2.13.3 → 2.13.4

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.
Files changed (67) hide show
  1. package/README.md +11 -11
  2. package/abstract-interpretation/absint-visitor.js +2 -2
  3. package/abstract-interpretation/data-frame/mappers/arguments.js +2 -2
  4. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +1 -1
  5. package/abstract-interpretation/unsupported-functions.js +1 -1
  6. package/control-flow/cfg-dead-code.js +72 -11
  7. package/control-flow/extract-cfg.js +85 -8
  8. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  9. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  10. package/dataflow/environments/built-in-proc-name.js +4 -0
  11. package/dataflow/environments/built-in.d.ts +5 -1
  12. package/dataflow/environments/built-in.js +5 -1
  13. package/dataflow/environments/default-builtin-config.d.ts +59 -4
  14. package/dataflow/environments/default-builtin-config.js +23 -11
  15. package/dataflow/environments/identifier.d.ts +1 -0
  16. package/dataflow/eval/resolve/alias-tracking.d.ts +2 -0
  17. package/dataflow/eval/resolve/alias-tracking.js +8 -1
  18. package/dataflow/eval/resolve/resolve.d.ts +14 -0
  19. package/dataflow/eval/resolve/resolve.js +47 -0
  20. package/dataflow/fn/higher-order-function.js +3 -3
  21. package/dataflow/fn/recursive-function.js +1 -1
  22. package/dataflow/graph/df-helper.js +1 -1
  23. package/dataflow/graph/vertex.d.ts +32 -25
  24. package/dataflow/graph/vertex.js +40 -36
  25. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -0
  26. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -4
  27. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +14 -0
  28. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +28 -29
  29. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +41 -48
  30. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +14 -0
  31. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +45 -0
  32. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +7 -1
  33. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +29 -0
  34. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +62 -2
  35. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +63 -16
  36. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +29 -9
  37. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +5 -1
  38. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +35 -0
  39. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -2
  40. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +1 -1
  41. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +2 -0
  42. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +46 -0
  43. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -1
  44. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +24 -0
  45. package/dataflow/internal/process/functions/process-parameter.js +2 -1
  46. package/linter/rules/absolute-path.js +1 -1
  47. package/linter/rules/function-finder-util.js +1 -1
  48. package/linter/rules/no-leaked-credentials.js +1 -1
  49. package/linter/rules/undefined-symbol.js +1 -1
  50. package/linter/rules/unused-definition.js +15 -10
  51. package/linter/rules/useless-loop.js +1 -1
  52. package/package.json +1 -1
  53. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
  54. package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -1
  55. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  56. package/queries/catalog/dependencies-query/function-info/write-functions.js +23 -24
  57. package/queries/catalog/input-sources-query/input-source-functions.d.ts +2 -1
  58. package/queries/catalog/input-sources-query/input-source-functions.js +14 -20
  59. package/queries/catalog/input-sources-query/input-sources-query-executor.js +11 -6
  60. package/queries/catalog/input-sources-query/input-sources-query-format.js +2 -1
  61. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +14 -1
  62. package/queries/catalog/input-sources-query/simple-input-classifier.js +24 -0
  63. package/r-bridge/data/data.d.ts +2 -2
  64. package/r-bridge/data/data.js +2 -2
  65. package/reconstruct/inline/source-inline-map.js +1 -1
  66. package/util/mermaid/dfg.js +1 -1
  67. package/util/version.js +1 -1
@@ -12,6 +12,7 @@ const edge_1 = require("../../../../../graph/edge");
12
12
  const identifier_1 = require("../../../../../environments/identifier");
13
13
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
14
14
  const built_in_envir_utils_1 = require("./built-in-envir-utils");
15
+ const range_1 = require("../../../../../../util/range");
15
16
  /**
16
17
  * Processes a built-in 'get' function call.
17
18
  *
@@ -28,17 +29,36 @@ function processGet(name, args, rootId, data) {
28
29
  const retrieve = firstArg !== undefined && firstArg !== r_function_call_1.EmptyArgument
29
30
  ? (0, unpack_argument_1.unpackNonameArg)(firstArg)
30
31
  : undefined;
31
- if (retrieve === undefined || retrieve.type !== type_1.RType.String) {
32
+ let treatTargetAsSymbol = undefined;
33
+ if (retrieve !== undefined && retrieve.type === type_1.RType.String) {
34
+ treatTargetAsSymbol = {
35
+ type: type_1.RType.Symbol,
36
+ info: retrieve.info,
37
+ content: (0, retriever_1.removeRQuotes)(retrieve.lexeme),
38
+ lexeme: retrieve.lexeme,
39
+ location: retrieve.location
40
+ };
41
+ }
42
+ else if (retrieve !== undefined) {
43
+ const resolvedName = (0, built_in_envir_utils_1.resolveConstantString)(retrieve, data);
44
+ if (resolvedName !== undefined) {
45
+ const synthId = rootId + '-get-name';
46
+ const synthSymbol = {
47
+ type: type_1.RType.Symbol,
48
+ info: { ...retrieve.info, id: synthId },
49
+ content: resolvedName,
50
+ lexeme: resolvedName,
51
+ location: retrieve.location ?? name.location ?? range_1.SourceRange.invalid()
52
+ };
53
+ data.completeAst.idMap.set(synthId, synthSymbol);
54
+ treatTargetAsSymbol = synthSymbol;
55
+ }
56
+ }
57
+ if (treatTargetAsSymbol === undefined) {
32
58
  logger_1.dataflowLogger.warn(`symbol access with ${identifier_1.Identifier.toString(name.content)} has not 1 string argument, skipping`);
33
- return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
59
+ // dynamic, unresolvable name: reached-but-unknown rather than dropped
60
+ return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default', hasUnknownSideEffect: true }).information;
34
61
  }
35
- const treatTargetAsSymbol = {
36
- type: type_1.RType.Symbol,
37
- info: retrieve.info,
38
- content: (0, retriever_1.removeRQuotes)(retrieve.lexeme),
39
- lexeme: retrieve.lexeme,
40
- location: retrieve.location
41
- };
42
62
  /* resolve in the custom environment if one was found, else the global one.
43
63
  * Pass remaining original args (e.g. envir=e) so they appear as Use vertices in the graph. */
44
64
  const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({
@@ -1,9 +1,11 @@
1
- import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
1
+ import { type PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
2
2
  import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
3
+ import type { RNode } from '../../../../../../r-bridge/lang-4.x/ast/model/model';
3
4
  import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
5
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
5
6
  import type { DataflowInformation } from '../../../../../info';
6
7
  import type { DataflowProcessorInformation } from '../../../../../processor';
8
+ import type { REnvironmentInformation } from '../../../../../environments/environment';
7
9
  /**
8
10
  * Process a list call.
9
11
  *
@@ -13,3 +15,5 @@ import type { DataflowProcessorInformation } from '../../../../../processor';
13
15
  * ```
14
16
  */
15
17
  export declare function processList<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
18
+ /** Records a `list(...)`'s named function entries as a resolvable pseudo-env, so `d$foo(...)`/`d[["foo"]](...)` link to them; `undefined` if none. */
19
+ export declare function resolveListToEnvState<OtherInfo>(source: RNode<OtherInfo & ParentInformation>, data: Pick<DataflowProcessorInformation<never>, 'environment'>): REnvironmentInformation | undefined;
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processList = processList;
4
+ exports.resolveListToEnvState = resolveListToEnvState;
5
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
6
+ const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
4
7
  const known_call_handling_1 = require("../known-call-handling");
5
8
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
9
+ const identifier_1 = require("../../../../../environments/identifier");
10
+ const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
11
+ const define_1 = require("../../../../../environments/define");
12
+ const scoping_1 = require("../../../../../environments/scoping");
6
13
  /**
7
14
  * Process a list call.
8
15
  *
@@ -14,4 +21,32 @@ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-
14
21
  function processList(name, args, rootId, data) {
15
22
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.List }).information;
16
23
  }
24
+ /** Records a `list(...)`'s named function entries as a resolvable pseudo-env, so `d$foo(...)`/`d[["foo"]](...)` link to them; `undefined` if none. */
25
+ function resolveListToEnvState(source, data) {
26
+ if (!r_function_call_1.RFunctionCall.isNamed(source)) {
27
+ return undefined;
28
+ }
29
+ let envState = (0, scoping_1.pushLocalEnvironment)(data.environment);
30
+ let found = false;
31
+ for (const arg of source.arguments) {
32
+ if (arg === r_function_call_1.EmptyArgument || arg.name === undefined || arg.value === undefined) {
33
+ continue;
34
+ }
35
+ const value = arg.value;
36
+ const isFn = value.type === type_1.RType.FunctionDefinition
37
+ || (value.type === type_1.RType.Symbol && ((0, resolve_by_name_1.resolveByName)(value.content, data.environment, identifier_1.ReferenceType.Function)?.length ?? 0) > 0);
38
+ if (!isFn) {
39
+ continue;
40
+ }
41
+ envState = (0, define_1.define)({
42
+ type: identifier_1.ReferenceType.Function,
43
+ name: arg.name.content,
44
+ nodeId: value.info.id,
45
+ definedAt: value.info.id,
46
+ cds: undefined
47
+ }, false, envState);
48
+ found = true;
49
+ }
50
+ return found ? envState : undefined;
51
+ }
17
52
  //# sourceMappingURL=built-in-list.js.map
@@ -28,7 +28,7 @@ function processNewEnv(name, args, rootId, data) {
28
28
  if (data.ctx.config.solver.trackEnvironments) {
29
29
  const parentState = resolveNewEnvParentArg(args, data);
30
30
  const vertex = result.graph.getVertex(rootId);
31
- if (parentState !== undefined && (0, vertex_1.isFunctionCallVertex)(vertex)) {
31
+ if (parentState !== undefined && vertex_1.FunctionCallVertex.is(vertex)) {
32
32
  vertex.newEnvParent = parentState;
33
33
  }
34
34
  }
@@ -85,7 +85,7 @@ function createIsolatedEnvState(data) {
85
85
  function createFreshEnvState(data, sourceInfo) {
86
86
  if (sourceInfo !== undefined) {
87
87
  const vertex = sourceInfo.graph.getVertex(sourceInfo.entryPoint);
88
- if ((0, vertex_1.isFunctionCallVertex)(vertex) && vertex.newEnvParent !== undefined) {
88
+ if (vertex_1.FunctionCallVertex.is(vertex) && vertex.newEnvParent !== undefined) {
89
89
  return {
90
90
  current: new environment_1.Environment(vertex.newEnvParent.current),
91
91
  level: vertex.newEnvParent.level + 1
@@ -47,7 +47,7 @@ function processRecall(name, args, rootId, data, config) {
47
47
  information.graph.addEdge(rootId, closure, edge_1.EdgeType.Calls);
48
48
  // also kill the name of the recall function
49
49
  const r = information.graph.getVertex(rootId);
50
- if ((0, vertex_1.isFunctionCallVertex)(r)) {
50
+ if (vertex_1.FunctionCallVertex.is(r)) {
51
51
  r.name = unnamed_call_handling_1.UnnamedFunctionCallPrefix + rootId + '-' + identifier_1.Identifier.toString(r.name);
52
52
  r.environment = information.environment;
53
53
  }
@@ -24,6 +24,8 @@ export declare function processS7NewGeneric<OtherInfo>(name: RSymbol<OtherInfo &
24
24
  */
25
25
  export declare function processMakeConstructor<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config?: {
26
26
  readonly mode?: readonly ('s7' | 's3' | 's4')[];
27
+ readonly wrapIndex?: number;
28
+ readonly wrapName?: string;
27
29
  }): DataflowInformation;
28
30
  /**
29
31
  * Node-id suffix of the `fun = function(...) S7_dispatch()` argument flowR synthesizes for S7 calls that do not
@@ -4,6 +4,8 @@ exports.S7SyntheticFunArgSuffix = void 0;
4
4
  exports.processS7NewGeneric = processS7NewGeneric;
5
5
  exports.processMakeConstructor = processMakeConstructor;
6
6
  const known_call_handling_1 = require("../known-call-handling");
7
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
8
+ const built_in_apply_1 = require("./built-in-apply");
7
9
  const logger_1 = require("../../../../../logger");
8
10
  const linker_1 = require("../../../../linker");
9
11
  const common_1 = require("../common");
@@ -87,8 +89,52 @@ function processMakeConstructor(name, args, rootId, data, config) {
87
89
  if (fArg?.tag === vertex_1.VertexType.FunctionDefinition && config?.mode) {
88
90
  fArg.mode ??= config.mode.slice(); // copy: mode is mutated in place later, config.mode is shared
89
91
  }
92
+ if (config?.wrapIndex !== undefined) {
93
+ linkWrappedFunction(info, args, config.wrapIndex, config.wrapName, data);
94
+ }
90
95
  return info;
91
96
  }
97
+ /** Mark the wrapped function of an eager higher-order wrapper (`Negate`/`Vectorize`/`partial`) as called. */
98
+ function linkWrappedFunction(info, args, wrapIndex, wrapName, data) {
99
+ let wrapped = undefined;
100
+ if (wrapName !== undefined) {
101
+ wrapped = args.find(a => a !== r_function_call_1.EmptyArgument && a.name?.content === wrapName);
102
+ }
103
+ if (wrapped === undefined) {
104
+ let pos = 0;
105
+ for (const a of args) {
106
+ if (a === r_function_call_1.EmptyArgument || a.name) {
107
+ continue;
108
+ }
109
+ if (pos === wrapIndex) {
110
+ wrapped = a;
111
+ break;
112
+ }
113
+ pos++;
114
+ }
115
+ }
116
+ if (wrapped === undefined || wrapped === r_function_call_1.EmptyArgument || !wrapped.value) {
117
+ return;
118
+ }
119
+ const resolved = (0, built_in_apply_1.resolveFunctionArgument)(wrapped.value, data, {});
120
+ if (resolved === undefined || resolved.anonymous) {
121
+ return;
122
+ }
123
+ const vertex = info.graph.getVertex(resolved.functionId);
124
+ if (vertex?.tag !== vertex_1.VertexType.Use) {
125
+ return;
126
+ }
127
+ info.graph.updateToFunctionCall({
128
+ tag: vertex_1.VertexType.FunctionCall,
129
+ id: resolved.functionId,
130
+ name: resolved.functionName,
131
+ args: [],
132
+ environment: data.environment,
133
+ onlyBuiltin: false,
134
+ cds: data.cds,
135
+ origin: [built_in_proc_name_1.BuiltInProcName.Function]
136
+ });
137
+ }
92
138
  /**
93
139
  * Node-id suffix of the `fun = function(...) S7_dispatch()` argument flowR synthesizes for S7 calls that do not
94
140
  * carry one (`new_class`, `new_generic`, ...). It stands for no argument in the source, so consumers that reason
@@ -57,6 +57,8 @@ function resolveNodeToStackEnv(node, data) {
57
57
  case default_builtin_config_1.StackEnvKind.Base:
58
58
  case default_builtin_config_1.StackEnvKind.Empty:
59
59
  return fixedStackEnv(kind, data);
60
+ case default_builtin_config_1.StackEnvKind.CallerFrame: // parent.frame(): the caller's frame, over-approximated to global (exact at a top-level call)
61
+ return fixedStackEnv(default_builtin_config_1.StackEnvKind.Global, data);
60
62
  case default_builtin_config_1.StackEnvKind.Current: // environment() with no argument is the current environment
61
63
  return firstArg === undefined ? { current: data.environment.current, level: data.environment.level } : undefined;
62
64
  case default_builtin_config_1.StackEnvKind.Parent: {
@@ -86,7 +88,7 @@ function asSearchPathEnv(name, data) {
86
88
  /** If `sourceInfo`'s entry is a {@link BuiltInProcName.StackEnv} call, the stack environment it refers to; else `undefined`. */
87
89
  function stackEnvStateFromSource(sourceInfo, data) {
88
90
  const vertex = sourceInfo.graph.getVertex(sourceInfo.entryPoint);
89
- if (!(0, vertex_1.isFunctionCallVertex)(vertex) || vertex.name === undefined || !vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.StackEnv)) {
91
+ if (!vertex_1.FunctionCallVertex.is(vertex) || vertex.name === undefined || !vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.StackEnv)) {
90
92
  return undefined;
91
93
  }
92
94
  return fixedStackEnv(stackEnvKind(String(vertex.name)), data);
@@ -7,12 +7,32 @@ const common_1 = require("./common");
7
7
  const linker_1 = require("../../../linker");
8
8
  const edge_1 = require("../../../../graph/edge");
9
9
  const graph_1 = require("../../../../graph/graph");
10
+ const unknown_side_effect_1 = require("../../../../graph/unknown-side-effect");
10
11
  const vertex_1 = require("../../../../graph/vertex");
11
12
  const type_1 = require("../../../../../r-bridge/lang-4.x/ast/model/type");
12
13
  const logger_1 = require("../../../../logger");
13
14
  const identifier_1 = require("../../../../environments/identifier");
14
15
  const built_in_proc_name_1 = require("../../../../environments/built-in-proc-name");
16
+ const node_id_1 = require("../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
15
17
  exports.UnnamedFunctionCallPrefix = 'unnamed-fc-';
18
+ /**
19
+ * Whether a `$`/`[[` access callee resolved a field to a stored function: a resolved dispatch (`dispatch$foo()`)
20
+ * carries a `Returns` edge from the access node to the field target (in addition to the base `Returns` to `accessedId`),
21
+ * while an opaque object (`g$greet()` on an untracked `g`) only carries the base `Returns`.
22
+ */
23
+ function accessResolvesToField(graph, accessId, accessedId) {
24
+ const outgoing = graph.outgoingEdges(accessId);
25
+ if (outgoing === undefined) {
26
+ return false;
27
+ }
28
+ const base = node_id_1.NodeId.normalize(accessedId);
29
+ for (const [target, edge] of outgoing) {
30
+ if (node_id_1.NodeId.normalize(target) !== base && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns)) {
31
+ return true;
32
+ }
33
+ }
34
+ return false;
35
+ }
16
36
  /**
17
37
  * Processes an unnamed function call.
18
38
  * For example `(function(x) { x + 1 })(5)`
@@ -53,6 +73,10 @@ function processUnnamedFunctionCall(functionCall, data) {
53
73
  if (functionCall.calledFunction.type === type_1.RType.FunctionDefinition) {
54
74
  (0, linker_1.linkArgumentsOnCall)(callArgs, functionCall.calledFunction.parameters, finalGraph);
55
75
  }
76
+ else if (functionCall.calledFunction.type === type_1.RType.Access && !accessResolvesToField(finalGraph, calledRootId, functionCall.calledFunction.accessed.info.id)) {
77
+ // `obj$method()` whose callee did not resolve to a stored function: reached-but-unknown rather than dropped
78
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(finalGraph, data.environment, functionRootId);
79
+ }
56
80
  // push the called function to the ids:
57
81
  inIds = inIds.concat(calledFunction.in, calledFunction.unknownReferences);
58
82
  return {
@@ -19,7 +19,8 @@ function processFunctionParameter(parameter, data) {
19
19
  type: identifier_1.ReferenceType.Parameter,
20
20
  definedAt: parameter.info.id
21
21
  }));
22
- let environment = name.environment;
22
+ // keep the default's environment so its escaping (`<<-`) writes are carried on
23
+ let environment = defaultValue?.environment ?? name.environment;
23
24
  for (const writtenNode of writtenNodes) {
24
25
  const wid = writtenNode.nodeId;
25
26
  (0, log_1.expensiveTrace)(log_1.log, () => `parameter ${writtenNode.name} (${wid}) is defined at id ${writtenNode.definedAt} with ${defaultValue === undefined ? 'no default value' : ' a default value'}`);
@@ -162,7 +162,7 @@ exports.ABSOLUTE_PATH = {
162
162
  }
163
163
  else {
164
164
  const dfNode = dataflow.graph.getVertex(node.info.id);
165
- if ((0, vertex_1.isFunctionCallVertex)(dfNode)) {
165
+ if (vertex_1.FunctionCallVertex.is(dfNode)) {
166
166
  const handler = dfNode.name ? PathFunctions.get(dfNode.name) : undefined;
167
167
  const strings = handler ? handler(dataflow.graph, dfNode, data.inspectContext()) : [];
168
168
  if (strings) {
@@ -70,7 +70,7 @@ exports.functionFinderUtil = {
70
70
  }
71
71
  const dataflow = await analyzer.dataflow();
72
72
  const vert = dataflow.graph.getVertex(element.node.info.id);
73
- if ((0, vertex_1.isFunctionCallVertex)(vert)) {
73
+ if (vertex_1.FunctionCallVertex.is(vert)) {
74
74
  const args = (0, resolve_argument_1.getArgumentStringValue)(analyzer.flowrConfig.solver.variables, dataflow.graph, vert, info.argIdx, info.argName, info.resolveValue, analyzer.inspectContext());
75
75
  // we obtain all values, at least one of them has to trigger for the request
76
76
  const argValues = args ? args.values().flatMap(s => Array.from(s)).filter(assert_1.isNotUndefined).toArray() : [];
@@ -34,7 +34,7 @@ exports.NO_LEAKED_CREDENTIALS = {
34
34
  totalChecked++;
35
35
  const name = element.node.lexeme ?? '';
36
36
  const vertex = dfg.getVertex(element.node.info.id);
37
- if (!(0, vertex_1.isVariableDefinitionVertex)(vertex)) {
37
+ if (!vertex_1.VariableDefinitionVertex.is(vertex)) {
38
38
  return [];
39
39
  }
40
40
  const nameMatches = namePattern.test(name);
@@ -85,7 +85,7 @@ exports.UNDEFINED_SYMBOL = {
85
85
  return undefined;
86
86
  }
87
87
  const inInstalledFile = isInstalledFile(element.node.info.file);
88
- if ((0, vertex_1.isFunctionCallVertex)(vtx)) {
88
+ if (vertex_1.FunctionCallVertex.is(vtx)) {
89
89
  if (vtx.origin === 'unnamed' || !config.checkFunctions) {
90
90
  return undefined;
91
91
  }
@@ -64,29 +64,30 @@ function collectCalledNames(dfg) {
64
64
  }
65
65
  return names;
66
66
  }
67
- /** Checks if a function body is a single call to UseMethod. */
68
- function isUseMethodOnlyBody(node) {
69
- // Direct call to UseMethod
70
- if (r_function_call_1.RFunctionCall.isNamed(node) && identifier_1.Identifier.getName(node.functionName.content) === 'UseMethod') {
67
+ /** S3 (`UseMethod`) and S4/S7 (`standardGeneric`) generic dispatchers, invoked indirectly by R's dispatch. */
68
+ const GenericDispatchers = new Set(['UseMethod', 'standardGeneric']);
69
+ /** Whether a function body is a single call to a generic dispatcher. */
70
+ function isGenericDispatcherOnlyBody(node) {
71
+ if (r_function_call_1.RFunctionCall.isNamed(node) && GenericDispatchers.has(identifier_1.Identifier.getName(node.functionName.content))) {
71
72
  return true;
72
73
  }
73
74
  const nodeWithChildren = node;
74
75
  if (Array.isArray(nodeWithChildren.children) && nodeWithChildren.children.length === 1) {
75
76
  const child = nodeWithChildren.children[0];
76
- if (child && r_function_call_1.RFunctionCall.isNamed(child) && identifier_1.Identifier.getName(child.functionName.content) === 'UseMethod') {
77
+ if (child && r_function_call_1.RFunctionCall.isNamed(child) && GenericDispatchers.has(identifier_1.Identifier.getName(child.functionName.content))) {
77
78
  return true;
78
79
  }
79
80
  }
80
81
  return false;
81
82
  }
82
- /** Collects the parameter IDs of S3 generic functions (functions whose body is just UseMethod). */
83
+ /** Collects the parameter IDs of generic dispatcher functions. */
83
84
  function collectS3GenericParameterIds(ast) {
84
85
  const paramIds = new Set();
85
86
  for (const [, node] of ast.idMap) {
86
87
  if (!r_function_definition_1.RFunctionDefinition.is(node)) {
87
88
  continue;
88
89
  }
89
- if (isUseMethodOnlyBody(node.body)) {
90
+ if (isGenericDispatcherOnlyBody(node.body)) {
90
91
  for (const param of node.parameters) {
91
92
  paramIds.add(param.name.info.id);
92
93
  }
@@ -211,18 +212,22 @@ exports.UNUSED_DEFINITION = {
211
212
  return [];
212
213
  }
213
214
  const dfgVertex = dataflow.graph.getVertex(element.node.info.id);
214
- if (!dfgVertex || (!(0, vertex_1.isVariableDefinitionVertex)(dfgVertex)
215
- && (0, vertex_1.isFunctionDefinitionVertex)(dfgVertex) && !config.includeFunctionDefinitions)) {
215
+ if (!dfgVertex || (!vertex_1.VariableDefinitionVertex.is(dfgVertex)
216
+ && vertex_1.FunctionDefinitionVertex.is(dfgVertex) && !config.includeFunctionDefinitions)) {
216
217
  return undefined;
217
218
  }
218
219
  if (s3GenericParams.has(element.node.info.id)) {
219
220
  return undefined;
220
221
  }
222
+ // an anonymous dispatcher passed to setGeneric()/new_generic() runs on every dispatch, so it is used
223
+ if (vertex_1.FunctionDefinitionVertex.is(dfgVertex) && r_function_definition_1.RFunctionDefinition.is(element.node) && isGenericDispatcherOnlyBody(element.node.body)) {
224
+ return undefined;
225
+ }
221
226
  if (isConsideredUsed(element.node.lexeme, config, packageInfo, calledNames)) {
222
227
  return undefined;
223
228
  }
224
229
  const ingoingEdges = dataflow.graph.ingoingEdges(dfgVertex.id);
225
- const interestedIn = (0, vertex_1.isVariableDefinitionVertex)(dfgVertex) ? InterestingEdgesVariable : InterestingEdgesFunction;
230
+ const interestedIn = vertex_1.VariableDefinitionVertex.is(dfgVertex) ? InterestingEdgesVariable : InterestingEdgesFunction;
226
231
  const ingoingInteresting = ingoingEdges?.values().some(e => edge_1.DfEdge.includesType(e, interestedIn));
227
232
  if (ingoingInteresting) {
228
233
  return undefined;
@@ -16,7 +16,7 @@ exports.USELESS_LOOP = {
16
16
  const results = elements.getElements().filter(e => {
17
17
  const vertex = dataflow.graph.getVertex(e.node.info.id);
18
18
  return vertex
19
- && (0, vertex_1.isFunctionCallVertex)(vertex)
19
+ && vertex_1.FunctionCallVertex.is(vertex)
20
20
  && vertex.origin !== 'unnamed'
21
21
  && useLessLoopConfig.loopyFunctions.has(vertex.origin[0]);
22
22
  }).filter(loop => (0, useless_loop_1.onlyLoopsOnce)(loop.node.info.id, dataflow.graph, cfg, normalize, data.inspectContext())).map(res => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eagleoutice/flowr",
3
- "version": "2.13.3",
3
+ "version": "2.13.4",
4
4
  "description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {
@@ -147,7 +147,7 @@ function identifyLinkToLastCallRelationSync(from, cfg, graph, { callName, cascad
147
147
  (node) => knownCalls.get(node) :
148
148
  (node) => {
149
149
  const v = graph.getVertex(node);
150
- return (0, vertex_1.isFunctionCallVertex)(v) ? v : undefined;
150
+ return vertex_1.FunctionCallVertex.is(v) ? v : undefined;
151
151
  };
152
152
  (0, simple_visitor_1.visitCfgInReverseOrder)(cfg, [from], node => {
153
153
  /* we ignore the start id as it cannot be the last call */
@@ -21,7 +21,7 @@ async function identifyLinkToNestedRelation(from, analyzer, { callName, ignoreIf
21
21
  const cg = await analyzer.callGraph();
22
22
  const subCg = call_graph_1.CallGraph.computeSubCallGraph(cg, new Set([from]));
23
23
  for (const [, t] of subCg.vertices(true)) {
24
- if (!(0, vertex_1.isFunctionCallVertex)(t)) {
24
+ if (!vertex_1.FunctionCallVertex.is(t)) {
25
25
  continue;
26
26
  }
27
27
  if (test(identifier_1.Identifier.toString(t.name))) {
@@ -78,7 +78,7 @@ exports.ReadFunctions = [
78
78
  { package: 'readxl', name: 'read_excel', argIdx: 0, argName: 'path', resolveValue: true },
79
79
  { package: 'readxl', name: 'read_xls', argIdx: 0, argName: 'path', resolveValue: true },
80
80
  { package: 'readxl', name: 'read_xlsx', argIdx: 0, argName: 'path', resolveValue: true },
81
- { package: 'sf', name: 'read.sf', argIdx: 0, argName: 'dsn', resolveValue: true },
81
+ { package: 'sf', name: 'read_sf', argIdx: 0, argName: 'dsn', resolveValue: true },
82
82
  { package: 'sf', name: 'st_read', argIdx: 0, argName: 'dsn', resolveValue: true },
83
83
  { package: 'rgdal', name: 'readOGR', argIdx: 0, argName: 'dsn', resolveValue: true },
84
84
  { package: 'rgdal', name: 'ogrInfo', argIdx: 0, argName: 'dsn', resolveValue: true },
@@ -33,7 +33,7 @@ exports.WriteFunctions = [
33
33
  { package: 'base', name: 'message', linkTo: OutputRedirects, resolveValue: false },
34
34
  { package: 'base', name: 'warning', linkTo: OutputRedirects, resolveValue: false },
35
35
  { package: 'rlang', name: 'warn', linkTo: OutputRedirects, resolveValue: false },
36
- { package: 'rlang', name: 'info', linkTo: OutputRedirects, resolveValue: false },
36
+ { package: 'rlang', name: 'inform', linkTo: OutputRedirects, resolveValue: false },
37
37
  { package: 'cli', name: 'cli_warn', linkTo: OutputRedirects, resolveValue: false },
38
38
  { package: 'cli', name: 'cli_abort', linkTo: OutputRedirects, resolveValue: false },
39
39
  { package: 'base', name: 'writeLines', argIdx: 1, argName: 'con', resolveValue: true },
@@ -51,11 +51,10 @@ exports.WriteFunctions = [
51
51
  { package: 'readr', name: 'write_log', argIdx: 1, argName: 'file', resolveValue: true },
52
52
  { package: 'readr', name: 'write_lines', argIdx: 1, argName: 'file', resolveValue: true },
53
53
  { package: 'readr', name: 'write_rds', argIdx: 1, argName: 'file', resolveValue: true },
54
- { package: 'heaven', name: 'write_sas', argIdx: 1, argName: 'file', resolveValue: true },
55
- { package: 'heaven', name: 'write_sav', argIdx: 1, argName: 'file', resolveValue: true },
56
- { package: 'heaven', name: 'write_por', argIdx: 1, argName: 'file', resolveValue: true },
57
- { package: 'heaven', name: 'write_dta', argIdx: 1, argName: 'file', resolveValue: true },
58
- { package: 'heaven', name: 'write_xpt', argIdx: 1, argName: 'file', resolveValue: true },
54
+ { package: 'haven', name: 'write_sas', argIdx: 1, argName: 'file', resolveValue: true },
55
+ { package: 'haven', name: 'write_sav', argIdx: 1, argName: 'file', resolveValue: true },
56
+ { package: 'haven', name: 'write_dta', argIdx: 1, argName: 'file', resolveValue: true },
57
+ { package: 'haven', name: 'write_xpt', argIdx: 1, argName: 'file', resolveValue: true },
59
58
  { package: 'feather', name: 'write_feather', argIdx: 1, argName: 'file', resolveValue: true },
60
59
  { package: 'foreign', name: 'write.arff', argIdx: 1, argName: 'file', resolveValue: true },
61
60
  { package: 'foreign', name: 'write.dbf', argIdx: 1, argName: 'file', resolveValue: true },
@@ -63,25 +62,25 @@ exports.WriteFunctions = [
63
62
  { package: 'foreign', name: 'write.foreign', argIdx: 1, argName: 'file', resolveValue: true },
64
63
  { package: 'xlsx', name: 'write.xlsx', argIdx: 1, argName: 'file', resolveValue: true },
65
64
  { package: 'xlsx', name: 'write.xlsx2', argIdx: 1, argName: 'file', resolveValue: true },
66
- { package: 'graphics', name: 'pdf', argIdx: 0, argName: 'file', resolveValue: true },
67
- { package: 'graphics', name: 'jpeg', argIdx: 0, argName: 'file', resolveValue: true },
68
- { package: 'graphics', name: 'png', argIdx: 0, argName: 'file', resolveValue: true },
69
- { package: 'graphics', name: 'windows', argIdx: 0, argName: 'file', resolveValue: true },
70
- { package: 'graphics', name: 'postscript', argIdx: 0, argName: 'file', resolveValue: true },
71
- { package: 'graphics', name: 'xfix', argIdx: 0, argName: 'file', resolveValue: true },
72
- { package: 'graphics', name: 'bitmap', argIdx: 0, argName: 'file', resolveValue: true },
73
- { package: 'graphics', name: 'pictex', argIdx: 0, argName: 'file', resolveValue: true },
74
- { package: 'graphics', name: 'cairo_pdf', argIdx: 0, argName: 'file', resolveValue: true },
75
- { package: 'graphics', name: 'svg', argIdx: 0, argName: 'file', resolveValue: true },
76
- { package: 'graphics', name: 'bmp', argIdx: 0, argName: 'file', resolveValue: true },
77
- { package: 'graphics', name: 'tiff', argIdx: 0, argName: 'file', resolveValue: true },
78
- { package: 'graphics', name: 'X11', argIdx: 0, argName: 'file', resolveValue: true },
79
- { package: 'graphics', name: 'quartz', argIdx: 0, argName: 'file', resolveValue: true },
65
+ { package: 'grDevices', name: 'pdf', argIdx: 0, argName: 'file', resolveValue: true },
66
+ { package: 'grDevices', name: 'jpeg', argIdx: 0, argName: 'file', resolveValue: true },
67
+ { package: 'grDevices', name: 'png', argIdx: 0, argName: 'file', resolveValue: true },
68
+ { package: 'grDevices', name: 'windows', argIdx: 0, argName: 'file', resolveValue: true },
69
+ { package: 'grDevices', name: 'postscript', argIdx: 0, argName: 'file', resolveValue: true },
70
+ { package: 'grDevices', name: 'xfig', argIdx: 0, argName: 'file', resolveValue: true },
71
+ { package: 'grDevices', name: 'bitmap', argIdx: 0, argName: 'file', resolveValue: true },
72
+ { package: 'grDevices', name: 'pictex', argIdx: 0, argName: 'file', resolveValue: true },
73
+ { package: 'grDevices', name: 'cairo_pdf', argIdx: 0, argName: 'file', resolveValue: true },
74
+ { package: 'grDevices', name: 'svg', argIdx: 0, argName: 'file', resolveValue: true },
75
+ { package: 'grDevices', name: 'bmp', argIdx: 0, argName: 'file', resolveValue: true },
76
+ { package: 'grDevices', name: 'tiff', argIdx: 0, argName: 'file', resolveValue: true },
77
+ { package: 'grDevices', name: 'X11', argIdx: 0, argName: 'file', resolveValue: true },
78
+ { package: 'grDevices', name: 'quartz', argIdx: 0, argName: 'file', resolveValue: true },
80
79
  { package: 'car', name: 'Export', argIdx: 0, argName: 'file', resolveValue: true },
81
80
  { package: 'LIM', name: 'PrintMat', linkTo: OutputRedirects, resolveValue: true },
82
- { package: 'sjmisc', name: 'write_spss', argIdx: 1, argName: 'path', resolveValue: true },
83
- { package: 'sjmisc', name: 'write_stata', argIdx: 1, argName: 'path', resolveValue: true },
84
- { package: 'sjmisc', name: 'write_sas', argIdx: 1, argName: 'path', resolveValue: true },
81
+ // write_spss/write_stata moved sjmisc -> sjlabelled, so do not pin a namespace (match either); write_sas also lives in haven
82
+ { name: 'write_spss', argIdx: 1, argName: 'path', resolveValue: true },
83
+ { name: 'write_stata', argIdx: 1, argName: 'path', resolveValue: true },
85
84
  { package: 'ape', name: 'write.tree', argIdx: 1, argName: 'file', resolveValue: true },
86
85
  { package: 'ape', name: 'write.nexus', argIdx: 1, argName: 'file', resolveValue: true },
87
86
  { package: 'ape', name: 'write.phyloXML', argIdx: 1, argName: 'file', resolveValue: true },
@@ -98,7 +97,7 @@ exports.WriteFunctions = [
98
97
  { package: 'visNetwork', name: 'visSave', argIdx: 1, argName: 'file', resolveValue: true },
99
98
  { package: 'DiagrammeR', name: 'save_graph', argIdx: 1, argName: 'file', resolveValue: true },
100
99
  { package: 'DiagrammeR', name: 'export_graph', argName: 'file_name', resolveValue: true },
101
- { package: 'ggplot', name: 'ggsave', argIdx: 0, argName: 'filename', resolveValue: true },
100
+ { package: 'ggplot2', name: 'ggsave', argIdx: 0, argName: 'filename', resolveValue: true },
102
101
  { package: 'cowplot', name: 'ggsave2', argIdx: 0, argName: 'filename', resolveValue: true },
103
102
  { package: 'tinyplot', name: 'tinyplot', argName: 'file', resolveValue: true, ignoreIf: 'arg-missing' },
104
103
  { package: 'tinyplot', name: 'plt', argName: 'file', resolveValue: true, ignoreIf: 'arg-missing' },
@@ -1,5 +1,5 @@
1
1
  import { Identifier } from '../../../dataflow/environments/identifier';
2
- import type { LinkedInputEntryPoint, LinkedInputObject } from './simple-input-classifier';
2
+ import type { LinkedInputEntryPoint, LinkedInputObject, NarrowingFunction } from './simple-input-classifier';
3
3
  /**
4
4
  * Objects that a framework binds for its users, without a definition visible in the code.
5
5
  * The `withParams` and `requires` guards keep ordinary functions that happen to have a parameter of the same
@@ -7,6 +7,7 @@ import type { LinkedInputEntryPoint, LinkedInputObject } from './simple-input-cl
7
7
  * @see {@link LinkedInputObject}
8
8
  */
9
9
  export declare const LinkedInputObjects: readonly LinkedInputObject[];
10
+ export declare const NarrowingFunctions: readonly NarrowingFunction[];
10
11
  /**
11
12
  * Calls that hand a function to a framework which binds its parameters by position.
12
13
  * @see {@link LinkedInputEntryPoint}