@eagleoutice/flowr 2.14.0 → 2.14.1

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 (96) hide show
  1. package/README.md +39 -28
  2. package/benchmark/calibration.d.ts +13 -11
  3. package/benchmark/calibration.js +25 -26
  4. package/benchmark/slicer.d.ts +2 -1
  5. package/benchmark/slicer.js +6 -3
  6. package/cli/benchmark-app.js +4 -1
  7. package/cli/benchmark-helper-app.d.ts +1 -0
  8. package/cli/benchmark-helper-app.js +2 -2
  9. package/cli/common/options.d.ts +5 -0
  10. package/cli/common/options.js +1 -0
  11. package/cli/common/scripts-info.d.ts +5 -0
  12. package/cli/repl/execute.d.ts +2 -2
  13. package/cli/repl/execute.js +2 -2
  14. package/config.js +5 -6
  15. package/dataflow/environments/apply-kill.js +1 -1
  16. package/dataflow/environments/built-in-props.d.ts +6 -2
  17. package/dataflow/environments/built-in-props.js +5 -1
  18. package/dataflow/environments/default-builtin-config.d.ts +76 -1
  19. package/dataflow/environments/default-builtin-config.js +30 -5
  20. package/dataflow/environments/environment.d.ts +9 -1
  21. package/dataflow/environments/environment.js +25 -7
  22. package/dataflow/environments/identifier.d.ts +1 -0
  23. package/dataflow/environments/query-fn-props.d.ts +6 -0
  24. package/dataflow/environments/query-fn-props.js +20 -0
  25. package/dataflow/environments/resolve-by-name.js +14 -2
  26. package/dataflow/eval/resolve/resolve-operators.js +1 -1
  27. package/dataflow/eval/resolve/resolve-working-directory.d.ts +1 -1
  28. package/dataflow/eval/resolve/resolve-working-directory.js +1 -2
  29. package/dataflow/fn/exceptions-of-function.d.ts +3 -1
  30. package/dataflow/fn/exceptions-of-function.js +85 -38
  31. package/dataflow/fn/strict-function.d.ts +40 -0
  32. package/dataflow/fn/strict-function.js +337 -0
  33. package/dataflow/graph/df-helper.d.ts +9 -1
  34. package/dataflow/graph/df-helper.js +19 -3
  35. package/dataflow/graph/graph.d.ts +28 -2
  36. package/dataflow/graph/graph.js +59 -2
  37. package/dataflow/info.d.ts +26 -0
  38. package/dataflow/info.js +28 -1
  39. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -0
  40. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +27 -1
  41. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +1 -1
  42. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +29 -8
  43. package/documentation/wiki-core.js +1 -1
  44. package/documentation/wiki-dataflow-graph.js +1 -0
  45. package/documentation/wiki-linter.js +1 -0
  46. package/documentation/wiki-query.js +53 -0
  47. package/linter/linter-output.js +1 -1
  48. package/linter/linter-rules.d.ts +24 -0
  49. package/linter/linter-rules.js +3 -1
  50. package/linter/rules/network-functions.d.ts +1 -1
  51. package/linter/rules/unclosed-connection.d.ts +44 -0
  52. package/linter/rules/unclosed-connection.js +200 -0
  53. package/package.json +4 -7
  54. package/project/dependency-version-space.d.ts +3 -3
  55. package/project/dependency-version-space.js +2 -2
  56. package/project/plugins/file-plugins/files/flowr-description-file.d.ts +1 -1
  57. package/project/plugins/file-plugins/files/flowr-description-file.js +1 -1
  58. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +1 -1
  59. package/project/plugins/file-plugins/files/flowr-namespace-file.js +1 -1
  60. package/project/plugins/file-plugins/files/flowr-news-file.d.ts +1 -1
  61. package/project/plugins/file-plugins/files/flowr-news-file.js +1 -1
  62. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +1 -1
  63. package/project/plugins/file-plugins/files/flowr-rda-file.js +1 -1
  64. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +5 -5
  65. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +33 -6
  66. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
  67. package/project/sigdb/manifest.d.ts +3 -1
  68. package/project/sigdb/manifest.js +50 -9
  69. package/project/sigdb/reader.js +1 -1
  70. package/project/sigdb/schema.d.ts +2 -2
  71. package/project/sigdb/schema.js +2 -2
  72. package/queries/catalog/dependencies-query/link-devices.js +2 -8
  73. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -1
  74. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +1 -0
  75. package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.d.ts +6 -0
  76. package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.js +25 -0
  77. package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.d.ts +31 -0
  78. package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.js +56 -0
  79. package/queries/catalog/slice-query-options.d.ts +1 -1
  80. package/queries/catalog/slice-query-options.js +1 -1
  81. package/queries/query-function-filter.d.ts +8 -2
  82. package/queries/query-function-filter.js +11 -1
  83. package/queries/query.d.ts +11 -1
  84. package/queries/query.js +2 -0
  85. package/r-bridge/lang-4.x/ast/model/model.d.ts +4 -4
  86. package/r-bridge/lang-4.x/ast/model/model.js +4 -4
  87. package/search/flowr-search-filters.js +1 -13
  88. package/slicing/criterion/parse.d.ts +2 -2
  89. package/slicing/criterion/parse.js +2 -2
  90. package/slicing/static/fingerprint.js +1 -1
  91. package/util/objects.d.ts +12 -0
  92. package/util/objects.js +48 -0
  93. package/util/simple-df/dfg-ascii.js +14 -3
  94. package/util/text/name-rank.d.ts +1 -1
  95. package/util/text/name-rank.js +1 -1
  96. package/util/version.js +1 -1
@@ -621,13 +621,78 @@ export declare const WrittenBuiltinDefinitions: [{
621
621
  readonly assumePrimitive: false;
622
622
  }, {
623
623
  readonly type: "function";
624
- readonly names: [Identifier];
624
+ readonly names: Identifier[];
625
625
  readonly processor: BuiltInProcName.DefaultReadAllArgs;
626
626
  readonly config: {
627
627
  readonly props: number;
628
628
  readonly sig: [["host", ArgProp.Resource]];
629
629
  };
630
630
  readonly assumePrimitive: false;
631
+ }, {
632
+ readonly type: "function";
633
+ readonly names: Identifier[];
634
+ readonly processor: BuiltInProcName.DefaultReadAllArgs;
635
+ readonly config: {
636
+ readonly props: CallProp.Opens;
637
+ readonly sig: [["object", ArgProp.Value]];
638
+ };
639
+ readonly assumePrimitive: false;
640
+ }, {
641
+ readonly type: "function";
642
+ readonly names: [Identifier];
643
+ readonly processor: BuiltInProcName.DefaultReadAllArgs;
644
+ readonly config: {
645
+ readonly libFn: true;
646
+ readonly props: number;
647
+ };
648
+ readonly assumePrimitive: false;
649
+ }, {
650
+ readonly type: "function";
651
+ readonly names: [Identifier];
652
+ readonly processor: BuiltInProcName.DefaultReadAllArgs;
653
+ readonly config: {
654
+ readonly props: number;
655
+ readonly sig: [["con", ArgProp.Handle], ["...", ArgProp.Value]];
656
+ };
657
+ readonly assumePrimitive: false;
658
+ }, {
659
+ readonly type: "function";
660
+ readonly names: [Identifier];
661
+ readonly processor: BuiltInProcName.DefaultReadAllArgs;
662
+ readonly config: {
663
+ readonly props: number;
664
+ };
665
+ readonly assumePrimitive: false;
666
+ }, {
667
+ readonly type: "function";
668
+ readonly names: [Identifier];
669
+ readonly processor: BuiltInProcName.DefaultReadAllArgs;
670
+ readonly config: {
671
+ readonly libFn: true;
672
+ readonly props: number;
673
+ readonly sig: [["conn", ArgProp.Handle], ["...", ArgProp.Value]];
674
+ };
675
+ readonly assumePrimitive: false;
676
+ }, {
677
+ readonly type: "function";
678
+ readonly names: [Identifier];
679
+ readonly processor: BuiltInProcName.DefaultReadAllArgs;
680
+ readonly config: {
681
+ readonly libFn: true;
682
+ readonly props: CallProp.Closes;
683
+ readonly sig: [["con", ArgProp.Handle], [".local_envir", ArgProp.Written]];
684
+ };
685
+ readonly assumePrimitive: false;
686
+ }, {
687
+ readonly type: "function";
688
+ readonly names: [Identifier];
689
+ readonly processor: BuiltInProcName.DefaultReadAllArgs;
690
+ readonly config: {
691
+ readonly libFn: true;
692
+ readonly props: number;
693
+ readonly sig: [["con", ArgProp.Handle], ["code", number]];
694
+ };
695
+ readonly assumePrimitive: false;
631
696
  }, {
632
697
  readonly type: "function";
633
698
  readonly names: Identifier[];
@@ -2544,6 +2609,16 @@ export declare const WrittenBuiltinDefinitions: [{
2544
2609
  readonly props: CallProp.Process;
2545
2610
  };
2546
2611
  readonly assumePrimitive: false;
2612
+ }, {
2613
+ readonly type: "function";
2614
+ readonly names: [Identifier];
2615
+ readonly processor: BuiltInProcName.Default;
2616
+ readonly config: {
2617
+ readonly forceArgs: "all";
2618
+ readonly props: number;
2619
+ readonly sig: [["description", ArgProp.Resource]];
2620
+ };
2621
+ readonly assumePrimitive: false;
2547
2622
  }, {
2548
2623
  readonly type: "function";
2549
2624
  readonly names: [Identifier];
@@ -492,13 +492,36 @@ exports.WrittenBuiltinDefinitions = [
492
492
  /* the connections and the calls that move data through them, so anything reaching them inherits it */
493
493
  { type: 'function', names: identifier_1.Identifier.fromAll("base" /* PkgName.Base */, ['file', 'gzfile', 'bzfile', 'xzfile', 'unz', 'fifo']),
494
494
  processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
495
- config: { props: built_in_props_1.CallProp.File | built_in_props_1.CallProp.Reads | built_in_props_1.CallProp.Writes, sig: [['description', built_in_props_1.ArgProp.Resource]] }, assumePrimitive: false },
495
+ config: { props: built_in_props_1.CallProp.Opens | built_in_props_1.CallProp.File | built_in_props_1.CallProp.Reads | built_in_props_1.CallProp.Writes, sig: [['description', built_in_props_1.ArgProp.Resource]] }, assumePrimitive: false },
496
496
  { type: 'function', names: [identifier_1.Identifier.from(['url', "base" /* PkgName.Base */])],
497
497
  processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
498
- config: { props: built_in_props_1.CallProp.Network | built_in_props_1.CallProp.Reads, sig: [['description', built_in_props_1.ArgProp.Resource]] }, assumePrimitive: false },
499
- { type: 'function', names: [identifier_1.Identifier.from(['socketConnection', "base" /* PkgName.Base */])],
498
+ config: { props: built_in_props_1.CallProp.Opens | built_in_props_1.CallProp.Network | built_in_props_1.CallProp.Reads, sig: [['description', built_in_props_1.ArgProp.Resource]] }, assumePrimitive: false },
499
+ { type: 'function', names: identifier_1.Identifier.fromAll("base" /* PkgName.Base */, ['socketConnection', 'serverSocket']),
500
500
  processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
501
- config: { props: built_in_props_1.CallProp.Network | built_in_props_1.CallProp.Reads, sig: [['host', built_in_props_1.ArgProp.Resource]] }, assumePrimitive: false },
501
+ config: { props: built_in_props_1.CallProp.Opens | built_in_props_1.CallProp.Network | built_in_props_1.CallProp.Reads, sig: [['host', built_in_props_1.ArgProp.Resource]] }, assumePrimitive: false },
502
+ { type: 'function', names: identifier_1.Identifier.fromAll("base" /* PkgName.Base */, ['textConnection', 'rawConnection']),
503
+ processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
504
+ config: { props: built_in_props_1.CallProp.Opens, sig: [['object', built_in_props_1.ArgProp.Value]] }, assumePrimitive: false },
505
+ { type: 'function', names: [identifier_1.Identifier.from(['dbConnect', "DBI" /* PkgName.Dbi */])],
506
+ processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
507
+ config: { libFn: true, props: built_in_props_1.CallProp.Opens | built_in_props_1.CallProp.Database }, assumePrimitive: false },
508
+ /* the calls ending what an opener started, each stating the argument holding the handle */
509
+ { type: 'function', names: [identifier_1.Identifier.from(['close', "base" /* PkgName.Base */])],
510
+ processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
511
+ config: { props: built_in_props_1.CallProp.Closes | built_in_props_1.CallProp.Invisible | built_in_props_1.CallProp.Generic, sig: [['con', built_in_props_1.ArgProp.Handle], ['...', built_in_props_1.ArgProp.Value]] }, assumePrimitive: false },
512
+ { type: 'function', names: [identifier_1.Identifier.from(['closeAllConnections', "base" /* PkgName.Base */])],
513
+ processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
514
+ config: { props: built_in_props_1.CallProp.Closes | built_in_props_1.CallProp.Invisible }, assumePrimitive: false },
515
+ { type: 'function', names: [identifier_1.Identifier.from(['dbDisconnect', "DBI" /* PkgName.Dbi */])],
516
+ processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
517
+ config: { libFn: true, props: built_in_props_1.CallProp.Closes | built_in_props_1.CallProp.Invisible | built_in_props_1.CallProp.Database, sig: [['conn', built_in_props_1.ArgProp.Handle], ['...', built_in_props_1.ArgProp.Value]] }, assumePrimitive: false },
518
+ /* withr closes the connection it is handed when the scope it is called in ends */
519
+ { type: 'function', names: [identifier_1.Identifier.from(['local_connection', "withr" /* PkgName.Withr */])],
520
+ processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
521
+ config: { libFn: true, props: built_in_props_1.CallProp.Closes, sig: [['con', built_in_props_1.ArgProp.Handle], ['.local_envir', built_in_props_1.ArgProp.Written]] }, assumePrimitive: false },
522
+ { type: 'function', names: [identifier_1.Identifier.from(['with_connection', "withr" /* PkgName.Withr */])],
523
+ processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
524
+ config: { libFn: true, props: built_in_props_1.CallProp.Closes | built_in_props_1.CallProp.MayPure, sig: [['con', built_in_props_1.ArgProp.Handle], ['code', built_in_props_1.ArgProp.Value | built_in_props_1.ArgProp.Forced]] }, assumePrimitive: false },
502
525
  { type: 'function', names: identifier_1.Identifier.fromAll("base" /* PkgName.Base */, ['readLines', 'readBin', 'readChar']),
503
526
  processor: built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs,
504
527
  config: { props: built_in_props_1.CallProp.File | built_in_props_1.CallProp.Reads, sig: [['con', built_in_props_1.ArgProp.Resource]] }, assumePrimitive: false },
@@ -1178,8 +1201,10 @@ exports.WrittenBuiltinDefinitions = [
1178
1201
  { type: 'function', names: [identifier_1.Identifier.from(['commandArgs', "base" /* PkgName.Base */])],
1179
1202
  processor: built_in_proc_name_1.BuiltInProcName.Default, config: { forceArgs: 'all', props: built_in_props_1.CallProp.Ambient | built_in_props_1.CallProp.CommandLine }, assumePrimitive: false },
1180
1203
  /* system commands */
1181
- { type: 'function', names: identifier_1.Identifier.fromAll("base" /* PkgName.Base */, ['system', 'system2', 'pipe', 'shell', 'shell.exec']),
1204
+ { type: 'function', names: identifier_1.Identifier.fromAll("base" /* PkgName.Base */, ['system', 'system2', 'shell', 'shell.exec']),
1182
1205
  processor: built_in_proc_name_1.BuiltInProcName.Default, config: { forceArgs: 'all', props: built_in_props_1.CallProp.Process }, assumePrimitive: false },
1206
+ { type: 'function', names: [identifier_1.Identifier.from(['pipe', "base" /* PkgName.Base */])],
1207
+ processor: built_in_proc_name_1.BuiltInProcName.Default, config: { forceArgs: 'all', props: built_in_props_1.CallProp.Opens | built_in_props_1.CallProp.Process, sig: [['description', built_in_props_1.ArgProp.Resource]] }, assumePrimitive: false },
1183
1208
  { type: 'function', names: [identifier_1.Identifier.from(['runjs', "shinyjs" /* PkgName.ShinyJs */])],
1184
1209
  processor: built_in_proc_name_1.BuiltInProcName.Default, config: { forceArgs: 'all', libFn: true, props: built_in_props_1.CallProp.Process }, assumePrimitive: false },
1185
1210
  /* whatever the user types, picks, or sends along with a request */
@@ -48,9 +48,11 @@ export declare class Environment implements IEnvironment {
48
48
  builtInEnv?: true;
49
49
  /** {@link memory} is shared with a clone; writing needs {@link writableMemory} to unshare it first */
50
50
  private sharedMemory?;
51
+ /** {@link parent} is shared with the environment this was cloned from; writing through it needs {@link writableParent} */
52
+ private sharedParent?;
51
53
  /** marks the global environment (`.GlobalEnv`); attached packages (see {@link EnvType}) live below it */
52
54
  globalEnv?: true;
53
- constructor(parent: Environment, isBuiltInDefault?: true | undefined);
55
+ constructor(parent: Environment, isBuiltInDefault?: true | undefined, memory?: BuiltInMemory);
54
56
  /** Marks this as an attached-package layer (see {@link EnvType}) for package `name`. */
55
57
  asLibrary(name: string, type: EnvType): this;
56
58
  /** Marks this as the global environment (`.GlobalEnv`); see {@link globalEnv}. */
@@ -64,6 +66,12 @@ export declare class Environment implements IEnvironment {
64
66
  * rather than through {@link memory} directly, as {@link clone} hands the map itself to the clone and only
65
67
  * the first writer of either side copies it (copy-on-write).
66
68
  */
69
+ /**
70
+ * The parent, unshared first when a write is about to go through it. A `clone(true)` hands out the original
71
+ * chain and lets it materialize one frame at a time here, because a removal usually reaches a frame or two,
72
+ * not the ~20 an attached-package search path is deep.
73
+ */
74
+ get writableParent(): Environment;
67
75
  get writableMemory(): BuiltInMemory;
68
76
  /**
69
77
  * Create a clone of this environment.
@@ -42,12 +42,15 @@ class Environment {
42
42
  builtInEnv;
43
43
  /** {@link memory} is shared with a clone; writing needs {@link writableMemory} to unshare it first */
44
44
  sharedMemory;
45
+ /** {@link parent} is shared with the environment this was cloned from; writing through it needs {@link writableParent} */
46
+ sharedParent;
45
47
  /** marks the global environment (`.GlobalEnv`); attached packages (see {@link EnvType}) live below it */
46
48
  globalEnv;
47
- constructor(parent, isBuiltInDefault = undefined) {
49
+ constructor(parent, isBuiltInDefault = undefined, memory) {
48
50
  this.id = isBuiltInDefault ? 0 : environmentIdCounter++;
49
51
  this.parent = parent;
50
- this.memory = new Map();
52
+ /* a clone hands its own (then shared) memory in, so the fresh map a new frame needs is not allocated to be dropped */
53
+ this.memory = memory ?? new Map();
51
54
  // do not store if not needed!
52
55
  if (isBuiltInDefault) {
53
56
  this.builtInEnv = isBuiltInDefault;
@@ -77,6 +80,20 @@ class Environment {
77
80
  * rather than through {@link memory} directly, as {@link clone} hands the map itself to the clone and only
78
81
  * the first writer of either side copies it (copy-on-write).
79
82
  */
83
+ /**
84
+ * The parent, unshared first when a write is about to go through it. A `clone(true)` hands out the original
85
+ * chain and lets it materialize one frame at a time here, because a removal usually reaches a frame or two,
86
+ * not the ~20 an attached-package search path is deep.
87
+ */
88
+ get writableParent() {
89
+ if (this.sharedParent) {
90
+ const parent = this.parent.clone(false);
91
+ parent.sharedParent = true;
92
+ this.parent = parent;
93
+ this.sharedParent = undefined;
94
+ }
95
+ return this.parent;
96
+ }
80
97
  get writableMemory() {
81
98
  if (this.sharedMemory) {
82
99
  this.memory = new Map(this.memory);
@@ -96,14 +113,15 @@ class Environment {
96
113
  if (this.builtInEnv) {
97
114
  return this; // do not clone the built-in environment
98
115
  }
99
- const parent = recurseParents ? this.parent.clone(recurseParents) : this.parent;
100
- const clone = new Environment(parent, this.builtInEnv);
116
+ const clone = new Environment(this.parent, this.builtInEnv, this.memory);
101
117
  clone.c = this.c;
102
118
  clone.n = this.n;
103
119
  clone.t = this.t;
104
120
  clone.globalEnv = this.globalEnv;
105
- clone.memory = this.memory;
106
121
  clone.sharedMemory = this.sharedMemory = true;
122
+ if (recurseParents && !this.parent.builtInEnv) {
123
+ clone.sharedParent = true;
124
+ }
107
125
  return clone;
108
126
  }
109
127
  /**
@@ -380,7 +398,7 @@ class Environment {
380
398
  }
381
399
  const [name, ns] = identifier_1.Identifier.toArray(id);
382
400
  if (ns !== undefined && this.n !== ns) {
383
- this.parent.remove(id);
401
+ this.writableParent.remove(id);
384
402
  return this;
385
403
  }
386
404
  const definition = this.memory.get(name);
@@ -391,7 +409,7 @@ class Environment {
391
409
  cont = !definition.every(d => (0, info_1.happensInEveryBranch)(d.cds));
392
410
  }
393
411
  if (cont) {
394
- this.parent.remove(name);
412
+ this.writableParent.remove(name);
395
413
  }
396
414
  return this;
397
415
  }
@@ -155,6 +155,7 @@ export declare const enum PkgName {
155
155
  Cli = "cli",
156
156
  CohortBuilder = "cohortBuilder",
157
157
  DataTable = "data.table",
158
+ Dbi = "DBI",
158
159
  Devtools = "devtools",
159
160
  Dplyr = "dplyr",
160
161
  Fs = "fs",
@@ -3,7 +3,9 @@ import type { BuiltIns } from './built-in';
3
3
  import type { BuiltInDefinition, BuiltInDefinitions } from './built-in-config';
4
4
  import type { REnvironmentInformation } from './environment';
5
5
  import { Identifier } from './identifier';
6
+ import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
6
7
  import type { PackageSignatureSource } from '../../project/sigdb/reader';
8
+ import type { DataflowInformation } from '../info';
7
9
  /**
8
10
  * Where to look up what flowR knows about a function, in that order:
9
11
  * the name as it resolves here, the built-in definitions, and the signature database for the rest.
@@ -25,6 +27,10 @@ export interface FnPropsSource {
25
27
  * in the analyzed code, which shadows any built-in.
26
28
  */
27
29
  export declare function queryFnProps(name: Identifier, { environment, builtIns, signatures, version }: FnPropsSource): BuiltInFnInfo | undefined;
30
+ /** What flowR states about the call `id` makes, together with the name the call resolved to. */
31
+ export declare function callFnProps(id: NodeId, { graph, environment }: Pick<DataflowInformation, 'graph' | 'environment'>): (BuiltInFnInfo & {
32
+ name: Identifier;
33
+ }) | undefined;
28
34
  /**
29
35
  * What the signature database implies for a package function: what its own entry states
30
36
  * (see {@link fnInfoFromSignature}) plus the {@link PropagatedProps} of everything it calls, transitively.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BuiltInIndex = void 0;
4
4
  exports.queryFnProps = queryFnProps;
5
+ exports.callFnProps = callFnProps;
5
6
  exports.inferFnProps = inferFnProps;
6
7
  exports.builtInNames = builtInNames;
7
8
  const built_in_props_1 = require("./built-in-props");
@@ -10,6 +11,8 @@ const environment_1 = require("./environment");
10
11
  const identifier_1 = require("./identifier");
11
12
  const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
12
13
  const resolve_helper_1 = require("./resolve-helper");
14
+ const vertex_1 = require("../graph/vertex");
15
+ const df_helper_1 = require("../graph/df-helper");
13
16
  /**
14
17
  * What flowR states about the package export `definition` binds, `undefined` if it binds none or if flowR
15
18
  * states nothing about it. `library(pkg)` binds every export itself, and that binding hides the built-in layer.
@@ -80,6 +83,23 @@ function queryFnProps(name, { environment, builtIns, signatures, version }) {
80
83
  }
81
84
  return { sig: info?.sig ?? known.sig, props: (info?.props ?? 0) | (known.props ?? 0) };
82
85
  }
86
+ /** What flowR states about the call `id` makes, together with the name the call resolved to. */
87
+ function callFnProps(id, { graph, environment }) {
88
+ const vertex = graph.getVertex(id);
89
+ if (!vertex_1.FunctionCallVertex.is(vertex)) {
90
+ return undefined;
91
+ }
92
+ /* what the call resolved to decides, as a definition in the analyzed code shadows the built-in; a call
93
+ * flowR settled on the built-ins keeps no environment, and a later redefinition must not speak for it */
94
+ const known = vertex.environment ?? environment;
95
+ const name = df_helper_1.Dataflow.qualify(id, graph, false) ?? vertex.name;
96
+ return {
97
+ name,
98
+ ...queryFnProps(name, {
99
+ environment: vertex.onlyBuiltin ? { level: 0, current: environment_1.REnvironment.findBuiltIn(known.current) } : known
100
+ })
101
+ };
102
+ }
83
103
  /**
84
104
  * What the signature database implies for a package function: what its own entry states
85
105
  * (see {@link fnInfoFromSignature}) plus the {@link PropagatedProps} of everything it calls, transitively.
@@ -103,8 +103,20 @@ function resolveByTargetType(id, environment, target) {
103
103
  }
104
104
  if (definition !== undefined && definition.length > 0) {
105
105
  /* ask before filtering: the common case wants all of them and needs no copy */
106
- const allWanted = definition.every(wantedType);
107
- if (allWanted && (target !== identifier_1.ReferenceType.Function || definition.every(notAParameter)) && definition.every(inEveryBranch)) {
106
+ let allWanted = true;
107
+ let allOk = true;
108
+ const checkParameters = target === identifier_1.ReferenceType.Function;
109
+ for (const def of definition) {
110
+ if (!wantedType(def)) {
111
+ allWanted = false;
112
+ allOk = false;
113
+ break;
114
+ }
115
+ if (allOk && ((checkParameters && !notAParameter(def)) || !inEveryBranch(def))) {
116
+ allOk = false;
117
+ }
118
+ }
119
+ if (allOk) {
108
120
  return definition;
109
121
  }
110
122
  /* never alias the environment's own array, it is appended to below */
@@ -24,7 +24,7 @@ function operand(node, args) {
24
24
  }
25
25
  return typeof value === 'object' && value !== null && 'str' in value ? value.str : undefined;
26
26
  }
27
- /** as a condition, R takes any non-zero number for `TRUE`; `NA`, strings and everything else do not fold */
27
+ /** as a condition, R takes any non-zero number for `TRUE`; `NA`, strings, and everything else do not fold */
28
28
  function asLogical(node, args) {
29
29
  const value = operand(node, args);
30
30
  return typeof value === 'number' && !Number.isNaN(value) ? value !== 0 : undefined;
@@ -2,7 +2,7 @@ import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/nod
2
2
  import type { DataflowGraph } from '../../graph/graph';
3
3
  import type { ControlFlowGraph } from '../../../control-flow/control-flow-graph';
4
4
  import type { ReadOnlyFlowrAnalyzerContext } from '../../../project/context/flowr-analyzer-context';
5
- import { type ControlDependency } from '../../info';
5
+ import { ControlDependency } from '../../info';
6
6
  /** a resolved `setwd`-style call: its `dir` is `undefined` when it cannot be determined statically */
7
7
  export interface WorkingDirectoryChange {
8
8
  readonly id: NodeId;
@@ -23,7 +23,6 @@ const graph_1 = require("../../graph/graph");
23
23
  const ChangeFunctions = [
24
24
  { name: 'setwd', namespace: 'base', argIdx: 0, argName: 'dir' }
25
25
  ];
26
- const LoopTypes = new Set([type_1.RType.ForLoop, type_1.RType.WhileLoop, type_1.RType.RepeatLoop]);
27
26
  const CandidateCap = 64;
28
27
  function matchSpec(name) {
29
28
  if (name === undefined) {
@@ -81,7 +80,7 @@ function enclosingFunction(idMap, id) {
81
80
  return undefined;
82
81
  }
83
82
  function isIterated(cds, idMap) {
84
- return cds.some(cd => cd.byIteration || LoopTypes.has(idMap?.get(cd.id)?.type));
83
+ return cds.some(cd => info_1.ControlDependency.isIterated(cd, idMap));
85
84
  }
86
85
  function resolveAt(target, targetCds, baseWd, changes, cfg) {
87
86
  const relevant = changes.filter(c => (0, happens_before_1.happensBefore)(cfg, c.id, target) !== logic_1.Ternary.Never);
@@ -9,7 +9,9 @@ export interface ExceptionPoint {
9
9
  * Collect exception sources of a function in the call graph.
10
10
  * This returns the `NodeId`s of functions that may throw exceptions when called by the given function.
11
11
  * Please be aware, that these are restricted to functions known by flowR.
12
- * With `knownThrower` you can provide additional functions that are known to throw exceptions.
12
+ * With `knownThrower` you can provide additional functions that are known to throw exceptions; the result of
13
+ * an earlier call serves as one, as every definition it passes gets an answer counting its callees.
14
+ * A `try` and its relatives end the search.
13
15
  * @returns A record mapping all `NodeId`s of functions that may throw exceptions to their exception points.
14
16
  */
15
17
  export declare function calculateExceptionsOfFunction(id: NodeId, graph: CallGraph, knownThrower?: Record<NodeId, ExceptionPoint[]>): Record<NodeId, ExceptionPoint[]>;
@@ -6,61 +6,108 @@ const built_in_proc_name_1 = require("../environments/built-in-proc-name");
6
6
  const vertex_1 = require("../graph/vertex");
7
7
  const graph_1 = require("../graph/graph");
8
8
  const CatchHandlers = new Set([built_in_proc_name_1.BuiltInProcName.Try]);
9
- /**
10
- * Collect exception sources of a function in the call graph.
11
- * This returns the `NodeId`s of functions that may throw exceptions when called by the given function.
12
- * Please be aware, that these are restricted to functions known by flowR.
13
- * With `knownThrower` you can provide additional functions that are known to throw exceptions.
14
- * @returns A record mapping all `NodeId`s of functions that may throw exceptions to their exception points.
15
- */
16
- function calculateExceptionsOfFunction(id, graph, knownThrower = {}) {
17
- const collectedExceptions = {};
18
- const mine = [];
19
- const visited = new Set();
9
+ /** Whether the vertex catches what is raised below it, which ends the walk. */
10
+ function catches(vertex) {
11
+ return vertex_1.FunctionCallVertex.is(vertex) && vertex.origin !== 'unnamed' && vertex.origin.some(c => CatchHandlers.has(c));
12
+ }
13
+ function reach(id, graph, knownThrower) {
14
+ const calls = new Map();
15
+ const own = new Map();
16
+ const defs = new Set();
20
17
  const toVisit = [id];
21
18
  while (toVisit.length > 0) {
22
- const currentId = toVisit.pop();
23
- if (visited.has(currentId)) {
19
+ const current = toVisit.pop();
20
+ if (calls.has(current)) {
24
21
  continue;
25
22
  }
26
- visited.add(currentId);
27
- const kt = knownThrower[currentId];
28
- if (kt) {
29
- for (const e of kt) {
30
- if (!mine.includes(e)) {
31
- mine.push(e);
32
- }
33
- }
23
+ const known = knownThrower[current];
24
+ if (known !== undefined) {
25
+ own.set(current, known);
26
+ calls.set(current, []);
34
27
  continue;
35
28
  }
36
- const vtx = graph.getVertex(currentId);
37
- if (!vtx) {
29
+ const vertex = graph.getVertex(current);
30
+ if (vertex === undefined || node_id_1.NodeId.isBuiltIn(current)) {
31
+ calls.set(current, []);
38
32
  continue;
39
33
  }
40
- if (node_id_1.NodeId.isBuiltIn(currentId)) {
34
+ if (vertex_1.FunctionDefinitionVertex.is(vertex)) {
35
+ defs.add(current);
36
+ own.set(current, vertex.exitPoints.filter(e => e.type === 4 /* ExitPointType.Error */).map(e => ({ id: e.nodeId, cds: e.cds })));
37
+ }
38
+ else if (catches(vertex)) {
39
+ calls.set(current, []);
41
40
  continue;
42
41
  }
43
- if (vertex_1.FunctionDefinitionVertex.is(vtx)) {
44
- const es = vtx.exitPoints.filter(e => e.type === 4 /* ExitPointType.Error */).map(e => ({ id: e.nodeId, cds: e.cds }));
45
- for (const e of es) {
46
- if (!mine.includes(e)) {
47
- mine.push(e);
42
+ const next = [...(graph.outgoingEdges(current) ?? graph_1.NoEdges).keys()];
43
+ calls.set(current, next);
44
+ for (const n of next) {
45
+ if (!calls.has(n)) {
46
+ toVisit.push(n);
47
+ }
48
+ }
49
+ }
50
+ return { calls, own, defs };
51
+ }
52
+ /**
53
+ * Collect exception sources of a function in the call graph.
54
+ * This returns the `NodeId`s of functions that may throw exceptions when called by the given function.
55
+ * Please be aware, that these are restricted to functions known by flowR.
56
+ * With `knownThrower` you can provide additional functions that are known to throw exceptions; the result of
57
+ * an earlier call serves as one, as every definition it passes gets an answer counting its callees.
58
+ * A `try` and its relatives end the search.
59
+ * @returns A record mapping all `NodeId`s of functions that may throw exceptions to their exception points.
60
+ */
61
+ function calculateExceptionsOfFunction(id, graph, knownThrower = {}) {
62
+ const { calls, own, defs } = reach(id, graph, knownThrower);
63
+ const raised = new Map();
64
+ for (const node of calls.keys()) {
65
+ raised.set(node, new Map((own.get(node) ?? []).map(e => [e.id, e])));
66
+ }
67
+ const callers = new Map();
68
+ for (const [node, next] of calls) {
69
+ for (const call of next) {
70
+ const known = callers.get(call);
71
+ if (known === undefined) {
72
+ callers.set(call, [node]);
73
+ }
74
+ else {
75
+ known.push(node);
76
+ }
77
+ }
78
+ }
79
+ const pending = [...calls.keys()];
80
+ const queued = new Set(pending);
81
+ while (pending.length > 0) {
82
+ const node = pending.pop();
83
+ queued.delete(node);
84
+ const into = raised.get(node);
85
+ let grew = false;
86
+ for (const call of calls.get(node) ?? []) {
87
+ for (const [at, point] of raised.get(call) ?? NoPoints) {
88
+ if (!into.has(at)) {
89
+ into.set(at, point);
90
+ grew = true;
48
91
  }
49
92
  }
50
- collectedExceptions[vtx.id] = es;
51
93
  }
52
- else if (vertex_1.FunctionCallVertex.is(vtx) && vtx.origin !== 'unnamed' && vtx.origin.some(c => CatchHandlers.has(c))) {
53
- // skip the try-catch handlers as they catch all exceptions within their body
94
+ if (!grew) {
54
95
  continue;
55
96
  }
56
- const outEdges = graph.outgoingEdges(currentId) ?? graph_1.NoEdges;
57
- for (const [out] of outEdges) {
58
- if (!visited.has(out)) {
59
- toVisit.push(out);
97
+ for (const caller of callers.get(node) ?? []) {
98
+ if (!queued.has(caller)) {
99
+ queued.add(caller);
100
+ pending.push(caller);
60
101
  }
61
102
  }
62
103
  }
63
- collectedExceptions[id] = mine;
64
- return collectedExceptions;
104
+ const result = {};
105
+ for (const [node, points] of raised) {
106
+ if (defs.has(node) || node === id) {
107
+ result[node] = [...points.values()];
108
+ }
109
+ }
110
+ return result;
65
111
  }
112
+ const NoPoints = new Map();
66
113
  //# sourceMappingURL=exceptions-of-function.js.map
@@ -0,0 +1,40 @@
1
+ import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
2
+ import type { DataflowGraph } from '../graph/graph';
3
+ import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
4
+ import { Ternary } from '../../util/logic';
5
+ /**
6
+ * How a function treats its parameters: R hands arguments over as promises, so a parameter is strict when
7
+ * calling the function is enough to force it.
8
+ */
9
+ export interface FunctionStrictness {
10
+ /** whether every parameter is forced */
11
+ readonly strict: Ternary;
12
+ /** the same per parameter, keyed by the id of the parameter's name */
13
+ readonly parameters: Record<NodeId, Ternary>;
14
+ }
15
+ /**
16
+ * Determines whether the function with the given id is strict, i.e., whether calling it forces its arguments.
17
+ * {@link Ternary#Always} says every call forces every parameter, {@link Ternary#Never} that no call forces
18
+ * all of them, and {@link Ternary#Maybe} that it depends on the path taken, on the caller, or on a function
19
+ * flowR could not resolve. A definition without parameters has nothing to leave unforced and is strict.
20
+ *
21
+ * The analysis follows an argument that is handed on into the function receiving it, and treats a read in a
22
+ * default, in a loop, in a branch, or in a nested definition as one that may not happen. What a built-in
23
+ * does with an argument is not guessed from its name: an argument stated {@link ArgProp.Nse} or
24
+ * {@link ArgProp.Presence} is never evaluated, one stated {@link ArgProp.Forced} always is, and the calls
25
+ * reaching an argument only on the way the run takes are the ones flowR hands to the processor that says so
26
+ * (`switch` picking a branch, `try` reaching a handler, a hook running at exit).
27
+ * For a generic, the methods reached by S3 dispatch decide: they agree on a parameter or it is left open,
28
+ * while the object the dispatch is on is forced by the dispatch itself. A `NextMethod` carries the same
29
+ * question on to the methods it reaches, matched by the position the parameter is written in.
30
+ * An argument in `...` is followed to the parameter it binds to, whereas the method of an object flowR
31
+ * cannot resolve (`obj$m(x)`) is one more thing it cannot claim anything about.
32
+ * Cyclic dependencies between functions and calls flowR cannot resolve answer {@link Ternary#Maybe}, so this
33
+ * only claims certainty where the code gives it.
34
+ * What a built-in does with an argument comes from the {@link ArgProp} bits its signature states, so a
35
+ * configured or overwritten built-in is the one that answers when the analyzer context is handed along.
36
+ * @see {@link strictnessOfFunctions} - to ask about several definitions at once, sharing the work
37
+ */
38
+ export declare function strictnessOfFunction(id: NodeId, graph: DataflowGraph, ctx?: ReadOnlyFlowrAnalyzerContext): FunctionStrictness;
39
+ /** The {@link strictnessOfFunction|strictness} of several definitions, sharing the work between them. */
40
+ export declare function strictnessOfFunctions(ids: Iterable<NodeId>, graph: DataflowGraph, ctx?: ReadOnlyFlowrAnalyzerContext): Record<NodeId, FunctionStrictness>;