@magnusopera/fscript 0.92.5 → 0.94.0

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.
@@ -1,43 +1,61 @@
1
1
 
2
- import { FSharpRef, Union, Record } from "../fable_modules/fable-library-js.5.27.0/Types.js";
3
- import { union_type, option_type, int32_type, list_type, bool_type, record_type, class_type, string_type } from "../fable_modules/fable-library-js.5.27.0/Reflection.js";
4
- import { fold as fold_2, contains, add as add_1, singleton as singleton_1, toList, FSharpSet__get_IsEmpty, difference, ofList as ofList_1, ofSeq, union, empty as empty_1 } from "../fable_modules/fable-library-js.5.27.0/Set.js";
5
- import { compareArrays, stringHash, clear, curry2, int32ToString, curry3, defaultOf, disposeSafe, getEnumerator, safeHash, arrayHash, equalArrays, equals, compare, comparePrimitives } from "../fable_modules/fable-library-js.5.27.0/Util.js";
2
+ import { FSharpRef, Record, Union } from "../fable_modules/fable-library-js.5.27.0/Types.js";
3
+ import { option_type, list_type, bool_type, record_type, class_type, string_type, union_type, int32_type } from "../fable_modules/fable-library-js.5.27.0/Reflection.js";
4
+ import { fold as fold_2, contains, add as add_1, singleton as singleton_1, toList, FSharpSet__get_IsEmpty, difference, unionMany, ofList as ofList_1, ofSeq, union, empty as empty_1 } from "../fable_modules/fable-library-js.5.27.0/Set.js";
5
+ import { compareArrays, stringHash, numberHash, clear, curry2, int32ToString, curry3, defaultOf, disposeSafe, getEnumerator, safeHash, arrayHash, equalArrays, equals, compare, comparePrimitives } from "../fable_modules/fable-library-js.5.27.0/Util.js";
6
+ import { filter as filter_1, toList as toList_1, forAll, fold as fold_1, add, keys, toSeq, map as map_1, tryFind, ofList, empty as empty_2 } from "../fable_modules/fable-library-js.5.27.0/Map.js";
6
7
  import { Span_$reflection } from "./Span.js";
7
8
  import { ResolvedSymbolKind, ResolvedExpression_$reflection, ResolvedBinding_$reflection } from "./TypeInfer.js";
8
- import { Type, Type_$reflection } from "./Types.js";
9
- import { filter as filter_1, toList as toList_1, map as map_2, forAll, fold as fold_1, add, toSeq, tryFind, ofList, empty as empty_2 } from "../fable_modules/fable-library-js.5.27.0/Map.js";
10
- import { ofArrayWithTail, contains as contains_1, tryPick, tryItem, tryHead, ofSeq as ofSeq_1, mapIndexed, length, indexed, ofArray, append, cons, filter, choose, singleton, head, tail as tail_2, isEmpty, collect, fold, map, empty as empty_3 } from "../fable_modules/fable-library-js.5.27.0/List.js";
9
+ import { Type, Types_expand, Type_$reflection } from "./Types.js";
10
+ import { ofArrayWithTail, contains as contains_1, tryItem, tryHead, tryPick, item as item_5, FSharpList__get_Head, iterate, ofSeq as ofSeq_1, mapIndexed, length, indexed, ofArray, append, cons, filter, choose, singleton, head, tail as tail_2, isEmpty, collect, fold, map, empty as empty_3 } from "../fable_modules/fable-library-js.5.27.0/List.js";
11
11
  import { defaultArg } from "../fable_modules/fable-library-js.5.27.0/Option.js";
12
- import { sortBy, toArray, toList as toList_2, collect as collect_1, empty as empty_4, singleton as singleton_2, append as append_1, delay, map as map_1 } from "../fable_modules/fable-library-js.5.27.0/Seq.js";
12
+ import { sortBy, choose as choose_1, toArray, toList as toList_2, collect as collect_1, empty as empty_4, singleton as singleton_2, append as append_1, delay, map as map_2 } from "../fable_modules/fable-library-js.5.27.0/Seq.js";
13
13
  import { Operators_InvalidArg } from "../fable_modules/fable-library-js.5.27.0/FSharp.Core.js";
14
- import { concat, join as join_1 } from "../fable_modules/fable-library-js.5.27.0/String.js";
14
+ import { concat, join as join_2 } from "../fable_modules/fable-library-js.5.27.0/String.js";
15
15
  import { HashSet } from "../fable_modules/fable-library-js.5.27.0/MutableSet.js";
16
16
  import { Dictionary } from "../fable_modules/fable-library-js.5.27.0/MutableMap.js";
17
17
  import { min, max } from "../fable_modules/fable-library-js.5.27.0/Double.js";
18
18
  import { addToSet, addToDict, tryGetValue } from "../fable_modules/fable-library-js.5.27.0/MapUtil.js";
19
19
  import { equals as equals_1 } from "../fable_modules/fable-library-js.5.27.0/BigInt.js";
20
20
  import { addRangeInPlace } from "../fable_modules/fable-library-js.5.27.0/Array.js";
21
- import { distinct as distinct_1 } from "../fable_modules/fable-library-js.5.27.0/Seq2.js";
21
+ import { List_groupBy, distinct as distinct_1 } from "../fable_modules/fable-library-js.5.27.0/Seq2.js";
22
22
  import { builtinSchemes } from "./BuiltinSignatures.js";
23
23
  import { rangeDouble } from "../fable_modules/fable-library-js.5.27.0/Range.js";
24
24
 
25
+ export class ConsumerOperation extends Union {
26
+ constructor(tag, fields) {
27
+ super();
28
+ this.tag = tag;
29
+ this.fields = fields;
30
+ }
31
+ cases() {
32
+ return ["CreateConsumer", "SendMessage", "FinishConsumer"];
33
+ }
34
+ }
35
+
36
+ export function ConsumerOperation_$reflection() {
37
+ return union_type("FScript.Language.TaskSharingAnalysis.ConsumerOperation", [], ConsumerOperation, () => [[["handler", int32_type], ["initialState", int32_type]], [["receiver", int32_type], ["message", int32_type]], [["receiver", int32_type]]]);
38
+ }
39
+
25
40
  export class Options extends Record {
26
- constructor(ThreadSafeTypes, ThreadSafeFunctions) {
41
+ constructor(ThreadSafeTypes, ThreadSafeFunctions, ConsumerOperations) {
27
42
  super();
28
43
  this.ThreadSafeTypes = ThreadSafeTypes;
29
44
  this.ThreadSafeFunctions = ThreadSafeFunctions;
45
+ this.ConsumerOperations = ConsumerOperations;
30
46
  }
31
47
  }
32
48
 
33
49
  export function Options_$reflection() {
34
- return record_type("FScript.Language.TaskSharingAnalysis.Options", [], Options, () => [["ThreadSafeTypes", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [string_type])], ["ThreadSafeFunctions", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [string_type])]]);
50
+ return record_type("FScript.Language.TaskSharingAnalysis.Options", [], Options, () => [["ThreadSafeTypes", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [string_type])], ["ThreadSafeFunctions", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [string_type])], ["ConsumerOperations", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, ConsumerOperation_$reflection()])]]);
35
51
  }
36
52
 
37
53
  export const defaults = new Options(empty_1({
38
54
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
39
55
  }), empty_1({
40
56
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
57
+ }), empty_2({
58
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
41
59
  }));
42
60
 
43
61
  export class Diagnostic extends Record {
@@ -68,18 +86,19 @@ function Resource_$reflection() {
68
86
  }
69
87
 
70
88
  class AbstractValue extends Record {
71
- constructor(Resources, Fields, Callables, Tasks, Count) {
89
+ constructor(Resources, Fields, Callables, Tasks, Consumers, Count) {
72
90
  super();
73
91
  this.Resources = Resources;
74
92
  this.Fields = Fields;
75
93
  this.Callables = Callables;
76
94
  this.Tasks = Tasks;
95
+ this.Consumers = Consumers;
77
96
  this.Count = Count;
78
97
  }
79
98
  }
80
99
 
81
100
  function AbstractValue_$reflection() {
82
- return record_type("FScript.Language.TaskSharingAnalysis.AbstractValue", [], AbstractValue, () => [["Resources", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [Resource_$reflection()])], ["Fields", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, AbstractValue_$reflection()])], ["Callables", list_type(Callable_$reflection())], ["Tasks", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [int32_type])], ["Count", option_type(int32_type)]]);
101
+ return record_type("FScript.Language.TaskSharingAnalysis.AbstractValue", [], AbstractValue, () => [["Resources", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [Resource_$reflection()])], ["Fields", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, AbstractValue_$reflection()])], ["Callables", list_type(Callable_$reflection())], ["Tasks", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [int32_type])], ["Consumers", class_type("Microsoft.FSharp.Collections.FSharpSet`1", [int32_type])], ["Count", option_type(int32_type)]]);
83
102
  }
84
103
 
85
104
  class Callable extends Union {
@@ -97,16 +116,31 @@ function Callable_$reflection() {
97
116
  return union_type("FScript.Language.TaskSharingAnalysis.Callable", [], Callable, () => [[["Item1", int32_type], ["Item2", ResolvedBinding_$reflection()], ["Item3", ResolvedExpression_$reflection()], ["Item4", record_type("Microsoft.FSharp.Core.FSharpRef`1", [class_type("Microsoft.FSharp.Collections.FSharpMap`2", [int32_type, AbstractValue_$reflection()])], FSharpRef, () => [["contents", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [int32_type, AbstractValue_$reflection()])]])]], [["Item1", string_type], ["Item2", int32_type], ["Item3", bool_type], ["Item4", Type_$reflection()], ["Item5", list_type(AbstractValue_$reflection())]]]);
98
117
  }
99
118
 
119
+ class Consumer extends Record {
120
+ constructor(Handler, State, Clock) {
121
+ super();
122
+ this.Handler = Handler;
123
+ this.State = State;
124
+ this.Clock = Clock;
125
+ }
126
+ }
127
+
128
+ function Consumer_$reflection() {
129
+ return record_type("FScript.Language.TaskSharingAnalysis.Consumer", [], Consumer, () => [["Handler", AbstractValue_$reflection()], ["State", AbstractValue_$reflection()], ["Clock", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [int32_type, int32_type])]]);
130
+ }
131
+
100
132
  const empty = new AbstractValue(empty_1({
101
133
  Compare: (x, y) => (compare(x, y) | 0),
102
134
  }), empty_2({
103
135
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
104
136
  }), empty_3(), empty_1({
105
137
  Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
138
+ }), empty_1({
139
+ Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
106
140
  }), undefined);
107
141
 
108
142
  function combine(values) {
109
- let list_1, list_4;
143
+ let list_1, list_4, list_6;
110
144
  let matchResult, value;
111
145
  if (!isEmpty(values)) {
112
146
  if (isEmpty(tail_2(values))) {
@@ -128,14 +162,16 @@ function combine(values) {
128
162
  Compare: (x, y) => (compare(x, y) | 0),
129
163
  }), list_1)), empty.Fields, collect((_arg_1) => _arg_1.Callables, values), (list_4 = map((_arg_2) => _arg_2.Tasks, values), fold(union, empty_1({
130
164
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
131
- }), list_4)), empty.Count);
165
+ }), list_4)), (list_6 = map((_arg_3) => _arg_3.Consumers, values), fold(union, empty_1({
166
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
167
+ }), list_6)), empty.Count);
132
168
  }
133
169
  }
134
170
 
135
171
  function container(key, count, value) {
136
172
  return new AbstractValue(value.Resources, ofList(singleton([key, value]), {
137
173
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
138
- }), empty.Callables, empty.Tasks, count);
174
+ }), empty.Callables, empty.Tasks, empty.Consumers, count);
139
175
  }
140
176
 
141
177
  function contents(value) {
@@ -163,20 +199,21 @@ export function analyze(registration, options, program) {
163
199
  }, program.ResolvedStatements), {
164
200
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
165
201
  });
202
+ const typeDefinitions = map_1((_arg, declaration_1) => declaration_1.Definition, declaredTypes);
166
203
  const hostUnions = ofList(map((item_1) => [item_1.Name, item_1.Cases], registration.Unions), {
167
204
  Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
168
205
  });
169
206
  const functions = ofList(map((item_2) => [item_2.Name, item_2.Arity], registration.Functions), {
170
207
  Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
171
208
  });
172
- const knownTypes = union(ofSeq(map_1((tuple) => tuple[0], toSeq(hostTypes)), {
209
+ const knownTypes = union(ofSeq(map_2((tuple) => tuple[0], toSeq(hostTypes)), {
173
210
  Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
174
- }), ofList_1(map((_arg) => _arg.Name, registration.Unions), {
211
+ }), ofList_1(map((_arg_1) => _arg_1.Name, registration.Unions), {
175
212
  Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
176
213
  }));
177
- const knownFunctions = union(ofSeq(map_1((tuple_1) => tuple_1[0], toSeq(functions)), {
214
+ const knownFunctions = union(ofSeq(map_2((tuple_1) => tuple_1[0], toSeq(functions)), {
178
215
  Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
179
- }), ofList_1(map((_arg_1) => _arg_1.Name, filter((symbol) => {
216
+ }), ofList_1(map((_arg_2) => _arg_2.Name, filter((symbol) => {
180
217
  if (equals(symbol.Kind, ResolvedSymbolKind.ExternSymbol)) {
181
218
  return true;
182
219
  }
@@ -186,28 +223,33 @@ export function analyze(registration, options, program) {
186
223
  }, program.Symbols)), {
187
224
  Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
188
225
  }));
189
- const invalid = union(difference(options.ThreadSafeTypes, knownTypes), difference(options.ThreadSafeFunctions, knownFunctions));
226
+ const invalid = unionMany([difference(options.ThreadSafeTypes, knownTypes), difference(options.ThreadSafeFunctions, knownFunctions), difference(ofSeq(keys(options.ConsumerOperations), {
227
+ Compare: (x_8, y_8) => (comparePrimitives(x_8, y_8) | 0),
228
+ }), knownFunctions)], {
229
+ Compare: (x_9, y_9) => (comparePrimitives(x_9, y_9) | 0),
230
+ });
190
231
  if (!FSharpSet__get_IsEmpty(invalid)) {
191
- throw Operators_InvalidArg("options", "Unknown thread-safety contract names: " + join_1(", ", toList(invalid)));
232
+ throw Operators_InvalidArg("options", "Unknown thread-safety contract names: " + join_2(", ", toList(invalid)));
192
233
  }
193
234
  const safeTypes = union(options.ThreadSafeTypes, program.Purity.PureTypes);
194
235
  const safeFunctions = union(options.ThreadSafeFunctions, program.Purity.PureFunctions);
195
236
  const diagnostics = [];
196
237
  const reported = new HashSet([], {
197
238
  Equals: equalArrays,
198
- GetHashCode: (x_8) => (arrayHash(x_8) | 0),
239
+ GetHashCode: (x_10) => (arrayHash(x_10) | 0),
199
240
  });
200
241
  const histories = new Dictionary([], {
201
242
  Equals: equals,
202
- GetHashCode: (x_9) => (safeHash(x_9) | 0),
243
+ GetHashCode: (x_11) => (safeHash(x_11) | 0),
203
244
  });
204
245
  const tasks = new Map([]);
246
+ const consumers = new Map([]);
205
247
  const activeCalls = new Set([]);
206
248
  let callSites = empty_3();
207
249
  let nextTask = 0;
208
250
  let task = 0;
209
251
  let clock = ofList(singleton([0, 0]), {
210
- Compare: (x_10, y_10) => (comparePrimitives(x_10, y_10) | 0),
252
+ Compare: (x_12, y_12) => (comparePrimitives(x_12, y_12) | 0),
211
253
  });
212
254
  const tick = () => {
213
255
  clock = add(task, 1 + defaultArg(tryFind(task, clock), 0), clock);
@@ -216,7 +258,7 @@ export function analyze(registration, options, program) {
216
258
  const before = (left_1, right_1) => forAll((key_1, value_3) => (value_3 <= defaultArg(tryFind(key_1, right_1), 0)), left_1);
217
259
  const commonClock = (clocks) => {
218
260
  if (!isEmpty(clocks)) {
219
- return fold((state_1, other) => map_2((key_2, value_5) => (min(value_5, defaultArg(tryFind(key_2, other), 0)) | 0), state_1), head(clocks), tail_2(clocks));
261
+ return fold((state_1, other) => map_1((key_2, value_5) => (min(value_5, defaultArg(tryFind(key_2, other), 0)) | 0), state_1), head(clocks), tail_2(clocks));
220
262
  }
221
263
  else {
222
264
  return clock;
@@ -264,80 +306,95 @@ export function analyze(registration, options, program) {
264
306
  }
265
307
  };
266
308
  const fromType = (source_2, visited, typ) => {
267
- let list_9, f2, mapping_9, f2_1, f2_2, mapping_12;
309
+ let list_9, f2, mapping_10, f2_1, f2_2, mapping_13;
268
310
  const nested = (typ_1) => fromType(source_2, visited, typ_1);
269
- let matchResult, name_2, name_3, typ_3, typ_4, typ_5, types, fields_1, cases_2, key_3, value_8;
311
+ let matchResult, name_2, applied_1, arguments$_1, name_3, typ_3, typ_4, typ_5, types, fields_1, cases_2, key_3, value_8;
270
312
  switch (typ.tag) {
271
- case 17: {
313
+ case 19: {
272
314
  if (!contains(typ.fields[0], safeTypes)) {
273
315
  matchResult = 0;
274
316
  name_2 = typ.fields[0];
275
317
  }
276
318
  else {
277
- matchResult = 9;
319
+ matchResult = 10;
278
320
  }
279
321
  break;
280
322
  }
281
- case 12: {
282
- if (!contains(typ.fields[0], visited)) {
323
+ case 13: {
324
+ if (!contains(typ, visited)) {
283
325
  matchResult = 1;
326
+ applied_1 = typ;
327
+ arguments$_1 = typ.fields[1];
328
+ }
329
+ else {
330
+ matchResult = 10;
331
+ }
332
+ break;
333
+ }
334
+ case 12: {
335
+ if (!contains(typ, visited)) {
336
+ matchResult = 2;
284
337
  name_3 = typ.fields[0];
285
338
  }
286
339
  else {
287
- matchResult = 9;
340
+ matchResult = 10;
288
341
  }
289
342
  break;
290
343
  }
291
344
  case 5: {
292
- matchResult = 2;
345
+ matchResult = 3;
293
346
  typ_3 = typ.fields[0];
294
347
  break;
295
348
  }
296
349
  case 10: {
297
- matchResult = 3;
350
+ matchResult = 4;
298
351
  typ_4 = typ.fields[0];
299
352
  break;
300
353
  }
301
354
  case 6: {
302
- matchResult = 4;
355
+ matchResult = 5;
303
356
  typ_5 = typ.fields[0];
304
357
  break;
305
358
  }
306
359
  case 7: {
307
- matchResult = 5;
360
+ matchResult = 6;
308
361
  types = typ.fields[0];
309
362
  break;
310
363
  }
311
364
  case 8: {
312
- matchResult = 6;
365
+ matchResult = 7;
313
366
  fields_1 = typ.fields[0];
314
367
  break;
315
368
  }
316
- case 18: {
317
- matchResult = 6;
369
+ case 20: {
370
+ matchResult = 7;
318
371
  fields_1 = typ.fields[1];
319
372
  break;
320
373
  }
321
- case 13: {
322
- matchResult = 7;
374
+ case 15: {
375
+ matchResult = 8;
323
376
  cases_2 = typ.fields[1];
324
377
  break;
325
378
  }
326
379
  case 9: {
327
- matchResult = 8;
380
+ matchResult = 9;
328
381
  key_3 = typ.fields[0];
329
382
  value_8 = typ.fields[1];
330
383
  break;
331
384
  }
332
385
  default:
333
- matchResult = 9;
386
+ matchResult = 10;
334
387
  }
335
388
  switch (matchResult) {
336
389
  case 0:
337
390
  return new AbstractValue(singleton_1(new Resource((source_2 + ":") + name_2, name_2, false), {
338
- Compare: (x_11, y_11) => (compare(x_11, y_11) | 0),
339
- }), empty.Fields, empty.Callables, empty.Tasks, empty.Count);
391
+ Compare: (x_13, y_13) => (compare(x_13, y_13) | 0),
392
+ }), empty.Fields, empty.Callables, empty.Tasks, empty.Consumers, empty.Count);
340
393
  case 1: {
394
+ const visited_1 = add_1(typ, visited);
395
+ return combine(cons(fromType(source_2, visited_1, Types_expand(typeDefinitions, applied_1)), map(curry3(fromType)(source_2)(visited_1), arguments$_1)));
396
+ }
397
+ case 2: {
341
398
  const matchValue_2 = tryFind(name_3, hostTypes);
342
399
  let matchResult_1, descriptor_1;
343
400
  if (matchValue_2 != null) {
@@ -361,33 +418,36 @@ export function analyze(registration, options, program) {
361
418
  switch (matchResult_1) {
362
419
  case 0: {
363
420
  const value_7 = new AbstractValue(singleton_1(new Resource((source_2 + ":") + name_3, name_3, false), {
364
- Compare: (x_12, y_12) => (compare(x_12, y_12) | 0),
365
- }), empty.Fields, empty.Callables, empty.Tasks, empty.Count);
421
+ Compare: (x_14, y_14) => (compare(x_14, y_14) | 0),
422
+ }), empty.Fields, empty.Callables, empty.Tasks, empty.Consumers, empty.Count);
366
423
  if (descriptor_1.HostManaged) {
367
424
  return value_7;
368
425
  }
369
426
  else {
370
- return combine(cons(value_7, map((tupledArg) => fromType(source_2, add_1(name_3, visited), tupledArg[1]), toList_1(descriptor_1.Fields))));
427
+ return combine(cons(value_7, map((tupledArg) => {
428
+ const typ_2 = tupledArg[1];
429
+ return fromType(source_2, add_1(typ_2, visited), typ_2);
430
+ }, toList_1(descriptor_1.Fields))));
371
431
  }
372
432
  }
373
433
  case 1:
374
434
  return empty;
375
435
  default: {
376
- const visited_1 = add_1(name_3, visited);
436
+ const visited_2 = add_1(typ, visited);
377
437
  const matchValue_3 = tryFind(name_3, hostUnions);
378
438
  const matchValue_4 = tryFind(name_3, declaredTypes);
379
439
  if (matchValue_3 != null) {
380
- return combine((list_9 = toList_1(matchValue_3), choose((f2 = ((mapping_9 = curry3(fromType)(source_2)(visited_1), (option_4) => {
440
+ return combine((list_9 = toList_1(matchValue_3), choose((f2 = ((mapping_10 = curry3(fromType)(source_2)(visited_2), (option_4) => {
381
441
  const option_5 = option_4;
382
- return (option_5 != null) ? mapping_9(option_5) : undefined;
442
+ return (option_5 != null) ? mapping_10(option_5) : undefined;
383
443
  })), (arg) => f2(arg[1])), list_9)));
384
444
  }
385
445
  else if (matchValue_4 != null) {
386
- const declaration_1 = matchValue_4;
387
- return combine(append(map((f2_1 = curry3(fromType)(source_2)(visited_1), (arg_1) => f2_1(arg_1[1])), declaration_1.Fields), choose((f2_2 = ((mapping_12 = curry3(fromType)(source_2)(visited_1), (option_6) => {
446
+ const declaration_2 = matchValue_4;
447
+ return combine(append(map((f2_1 = curry3(fromType)(source_2)(visited_2), (arg_1) => f2_1(arg_1[1])), declaration_2.Fields), choose((f2_2 = ((mapping_13 = curry3(fromType)(source_2)(visited_2), (option_6) => {
388
448
  const option_7 = option_6;
389
- return (option_7 != null) ? mapping_12(option_7) : undefined;
390
- })), (arg_2) => f2_2(arg_2[1])), declaration_1.Cases)));
449
+ return (option_7 != null) ? mapping_13(option_7) : undefined;
450
+ })), (arg_2) => f2_2(arg_2[1])), declaration_2.Cases)));
391
451
  }
392
452
  else {
393
453
  return empty;
@@ -395,20 +455,20 @@ export function analyze(registration, options, program) {
395
455
  }
396
456
  }
397
457
  }
398
- case 2:
399
- return container("$items", undefined, nested(typ_3));
400
458
  case 3:
401
- return container("$value", undefined, nested(typ_4));
459
+ return container("$items", undefined, nested(typ_3));
402
460
  case 4:
403
- return nested(typ_5);
461
+ return container("$value", undefined, nested(typ_4));
404
462
  case 5:
463
+ return nested(typ_5);
464
+ case 6:
405
465
  return combine(map(nested, types));
406
- case 6: {
407
- const values_4 = map_2((_arg_3, typ_6) => nested(typ_6), fields_1);
466
+ case 7: {
467
+ const values_4 = map_1((_arg_4, typ_6) => nested(typ_6), fields_1);
408
468
  const bind$0040 = combine(map((tuple_5) => tuple_5[1], toList_1(values_4)));
409
- return new AbstractValue(bind$0040.Resources, values_4, bind$0040.Callables, bind$0040.Tasks, bind$0040.Count);
469
+ return new AbstractValue(bind$0040.Resources, values_4, bind$0040.Callables, bind$0040.Tasks, bind$0040.Consumers, bind$0040.Count);
410
470
  }
411
- case 7:
471
+ case 8:
412
472
  return combine(choose((arg_3) => {
413
473
  const option_9 = arg_3[1];
414
474
  if (option_9 != null) {
@@ -418,14 +478,14 @@ export function analyze(registration, options, program) {
418
478
  return undefined;
419
479
  }
420
480
  }, toList_1(cases_2)));
421
- case 8:
481
+ case 9:
422
482
  return combine(ofArray([nested(key_3), nested(value_8)]));
423
483
  default:
424
484
  return empty;
425
485
  }
426
486
  };
427
487
  const unknown = (source_3, typ_7) => fromType(source_3, empty_1({
428
- Compare: (x_13, y_13) => (comparePrimitives(x_13, y_13) | 0),
488
+ Compare: (x_15, y_15) => (compare(x_15, y_15) | 0),
429
489
  }), typ_7);
430
490
  const references = (expression) => delay(() => {
431
491
  let matchValue_6;
@@ -435,7 +495,7 @@ export function analyze(registration, options, program) {
435
495
  bindPattern:
436
496
  while (true) {
437
497
  const env_1 = env_1_mut, pattern = pattern_mut, value_10 = value_10_mut;
438
- let mapping_18, option_13;
498
+ let mapping_19, option_13;
439
499
  const bind = (env_2, pattern_1) => bindPattern(env_2, pattern_1, value_10);
440
500
  const matchValue_8 = pattern.Node;
441
501
  let matchResult_2, binding_1, patterns, fields_2, a, b, pattern_4, pattern_5, entries, tail;
@@ -508,7 +568,7 @@ export function analyze(registration, options, program) {
508
568
  return bind(env_1, pattern_5);
509
569
  case 6: {
510
570
  const env_6 = fold((env_5, tupledArg_3) => bindPattern(bindPattern(env_5, tupledArg_3[0], contents(value_10)), tupledArg_3[1], contents(value_10)), env_1, entries);
511
- return defaultArg((mapping_18 = curry2(bind)(env_6), (option_13 = tail, (option_13 != null) ? mapping_18(option_13) : undefined)), env_6);
571
+ return defaultArg((mapping_19 = curry2(bind)(env_6), (option_13 = tail, (option_13 != null) ? mapping_19(option_13) : undefined)), env_6);
512
572
  }
513
573
  default:
514
574
  return env_1;
@@ -526,16 +586,16 @@ export function analyze(registration, options, program) {
526
586
  const matchValue_10 = tryFind(reference_1.SymbolId, env_7);
527
587
  if (matchValue_10 == null) {
528
588
  if (equals(reference_1.Kind, ResolvedSymbolKind.ExternSymbol) ? true : equals(reference_1.Kind, ResolvedSymbolKind.BuiltinSymbol)) {
529
- const arity = (_arg_4) => {
530
- if (_arg_4.tag === 11) {
531
- return (1 + arity(_arg_4.fields[1])) | 0;
589
+ const arity = (_arg_5) => {
590
+ if (_arg_5.tag === 11) {
591
+ return (1 + arity(_arg_5.fields[1])) | 0;
532
592
  }
533
593
  else {
534
594
  return 0;
535
595
  }
536
596
  };
537
597
  const count = defaultArg(tryFind(reference_1.Name, functions), arity(reference_1.Type)) | 0;
538
- const value_13 = new AbstractValue(empty.Resources, empty.Fields, singleton(new Callable(/* Function */ 1, [reference_1.Name, count, equals(reference_1.Kind, ResolvedSymbolKind.ExternSymbol), reference_1.Type, empty_3()])), empty.Tasks, empty.Count);
598
+ const value_13 = new AbstractValue(empty.Resources, empty.Fields, singleton(new Callable(/* Function */ 1, [reference_1.Name, count, equals(reference_1.Kind, ResolvedSymbolKind.ExternSymbol), reference_1.Type, empty_3()])), empty.Tasks, empty.Consumers, empty.Count);
539
599
  return (count === 0) ? invokeFunction(expression_1.Span)(expression_1.Type)(reference_1.Name)(equals(reference_1.Kind, ResolvedSymbolKind.ExternSymbol))(empty_3()) : value_13;
540
600
  }
541
601
  else {
@@ -550,7 +610,7 @@ export function analyze(registration, options, program) {
550
610
  const binding = matchValue_9.fields[0];
551
611
  const body = matchValue_9.fields[1];
552
612
  const capturedIds = ofSeq(references(body), {
553
- Compare: (x_14, y_14) => (comparePrimitives(x_14, y_14) | 0),
613
+ Compare: (x_16, y_16) => (comparePrimitives(x_16, y_16) | 0),
554
614
  });
555
615
  const captured = fold_2((state_2, id) => {
556
616
  const matchValue_7 = tryFind(id, env_7);
@@ -561,10 +621,10 @@ export function analyze(registration, options, program) {
561
621
  return add(id, matchValue_7, state_2);
562
622
  }
563
623
  }, empty_2({
564
- Compare: (x_15, y_15) => (comparePrimitives(x_15, y_15) | 0),
624
+ Compare: (x_17, y_17) => (comparePrimitives(x_17, y_17) | 0),
565
625
  }), capturedIds);
566
626
  const captures = combine(map((tuple_7) => tuple_7[1], toList_1(captured)));
567
- return new AbstractValue(captures.Resources, captures.Fields, singleton(new Callable(/* Closure */ 0, [binding.SymbolId, binding, body, new FSharpRef(captured)])), captures.Tasks, captures.Count);
627
+ return new AbstractValue(captures.Resources, captures.Fields, singleton(new Callable(/* Closure */ 0, [binding.SymbolId, binding, body, new FSharpRef(captured)])), captures.Tasks, captures.Consumers, captures.Count);
568
628
  }
569
629
  case 3:
570
630
  return apply(expression_1.Span)(expression_1.Type)(eval$(matchValue_9.fields[0]))(eval$(matchValue_9.fields[1]));
@@ -657,31 +717,31 @@ export function analyze(registration, options, program) {
657
717
  return contents(eval$(matchValue_9.fields[0]));
658
718
  }
659
719
  case 23:
660
- return container("$items", undefined, combine(collect((_arg_5) => {
661
- if (_arg_5.tag === 1) {
662
- return singleton(contents(eval$(_arg_5.fields[0])));
720
+ return container("$items", undefined, combine(collect((_arg_6) => {
721
+ if (_arg_6.tag === 1) {
722
+ return singleton(contents(eval$(_arg_6.fields[0])));
663
723
  }
664
724
  else {
665
- return ofArray([eval$(_arg_5.fields[0]), eval$(_arg_5.fields[1])]);
725
+ return ofArray([eval$(_arg_6.fields[0]), eval$(_arg_6.fields[1])]);
666
726
  }
667
727
  }, matchValue_9.fields[0])));
668
728
  case 7: {
669
729
  const fields_3 = ofList(mapIndexed((index_2, value_26) => [int32ToString(index_2), eval$(value_26)], matchValue_9.fields[0]), {
670
- Compare: (x_17, y_17) => (comparePrimitives(x_17, y_17) | 0),
730
+ Compare: (x_19, y_19) => (comparePrimitives(x_19, y_19) | 0),
671
731
  });
672
732
  const bind$0040_1 = combine(map((tuple_9) => tuple_9[1], toList_1(fields_3)));
673
733
  return new AbstractValue(bind$0040_1.Resources, fields_3, empty_3(), empty_1({
674
- Compare: (x_18, y_18) => (comparePrimitives(x_18, y_18) | 0),
675
- }), bind$0040_1.Count);
734
+ Compare: (x_20, y_20) => (comparePrimitives(x_20, y_20) | 0),
735
+ }), bind$0040_1.Consumers, bind$0040_1.Count);
676
736
  }
677
737
  case 9: {
678
738
  const fields_4 = ofList(map((tupledArg_5) => [tupledArg_5[0], eval$(tupledArg_5[1])], matchValue_9.fields[0]), {
679
- Compare: (x_19, y_19) => (comparePrimitives(x_19, y_19) | 0),
739
+ Compare: (x_21, y_21) => (comparePrimitives(x_21, y_21) | 0),
680
740
  });
681
741
  const bind$0040_2 = combine(map((tuple_10) => tuple_10[1], toList_1(fields_4)));
682
742
  return new AbstractValue(bind$0040_2.Resources, fields_4, empty_3(), empty_1({
683
- Compare: (x_20, y_20) => (comparePrimitives(x_20, y_20) | 0),
684
- }), bind$0040_2.Count);
743
+ Compare: (x_22, y_22) => (comparePrimitives(x_22, y_22) | 0),
744
+ }), bind$0040_2.Consumers, bind$0040_2.Count);
685
745
  }
686
746
  case 10: {
687
747
  const name_6 = matchValue_9.fields[1];
@@ -696,7 +756,7 @@ export function analyze(registration, options, program) {
696
756
  case 2:
697
757
  case 3:
698
758
  case 4:
699
- case 14:
759
+ case 16:
700
760
  return empty;
701
761
  default:
702
762
  return combine(ofArray([value_28, unknown("field:" + name_6, expression_1.Type)]));
@@ -712,8 +772,8 @@ export function analyze(registration, options, program) {
712
772
  const fields_6 = fold((state_5, tupledArg_6) => add(tupledArg_6[0], eval$(tupledArg_6[1]), state_5), target_4.Fields, matchValue_9.fields[2]);
713
773
  const bind$0040_3 = combine(cons(target_4, map((tuple_11) => tuple_11[1], toList_1(fields_6))));
714
774
  return new AbstractValue(bind$0040_3.Resources, fields_6, empty_3(), empty_1({
715
- Compare: (x_21, y_21) => (comparePrimitives(x_21, y_21) | 0),
716
- }), bind$0040_3.Count);
775
+ Compare: (x_23, y_23) => (comparePrimitives(x_23, y_23) | 0),
776
+ }), bind$0040_3.Consumers, bind$0040_3.Count);
717
777
  }
718
778
  case 6: {
719
779
  const arg_9 = combine(map(eval$, matchValue_9.fields[1])).Resources;
@@ -753,7 +813,9 @@ export function analyze(registration, options, program) {
753
813
  }
754
814
  });
755
815
  const branches = (alternatives) => {
756
- const snapshot = () => toList_2(map_1((pair) => [pair[0], ofSeq_1(pair[1])], histories));
816
+ const snapshot = () => toList_2(map_2((pair) => [pair[0], ofSeq_1(pair[1])], histories));
817
+ const consumerSnapshot = () => toList_2(map_2((pair_1) => [pair_1[0], pair_1[1]], consumers));
818
+ const initialConsumers = consumerSnapshot();
757
819
  const clock_1 = clock;
758
820
  const matchValue_21 = snapshot();
759
821
  const results = map((branch) => {
@@ -769,97 +831,116 @@ export function analyze(registration, options, program) {
769
831
  finally {
770
832
  disposeSafe(enumerator_3);
771
833
  }
772
- return [branch(), clock, snapshot()];
834
+ consumers.clear();
835
+ const enumerator_4 = getEnumerator(initialConsumers);
836
+ try {
837
+ while (enumerator_4["System.Collections.IEnumerator.MoveNext"]()) {
838
+ const forLoopVar_3 = enumerator_4["System.Collections.Generic.IEnumerator`1.get_Current"]();
839
+ consumers.set(forLoopVar_3[0], forLoopVar_3[1]);
840
+ }
841
+ }
842
+ finally {
843
+ disposeSafe(enumerator_4);
844
+ }
845
+ return [branch(), clock, snapshot(), consumerSnapshot()];
773
846
  }, alternatives);
774
847
  histories.clear();
775
- const enumerator_4 = getEnumerator(results);
848
+ const enumerator_5 = getEnumerator(results);
776
849
  try {
777
- while (enumerator_4["System.Collections.IEnumerator.MoveNext"]()) {
778
- const enumerator_5 = getEnumerator(enumerator_4["System.Collections.Generic.IEnumerator`1.get_Current"]()[2]);
850
+ while (enumerator_5["System.Collections.IEnumerator.MoveNext"]()) {
851
+ const enumerator_6 = getEnumerator(enumerator_5["System.Collections.Generic.IEnumerator`1.get_Current"]()[2]);
779
852
  try {
780
- while (enumerator_5["System.Collections.IEnumerator.MoveNext"]()) {
781
- const forLoopVar_4 = enumerator_5["System.Collections.Generic.IEnumerator`1.get_Current"]();
782
- const values_14 = forLoopVar_4[1];
783
- const key_9 = forLoopVar_4[0];
853
+ while (enumerator_6["System.Collections.IEnumerator.MoveNext"]()) {
854
+ const forLoopVar_5 = enumerator_6["System.Collections.Generic.IEnumerator`1.get_Current"]();
855
+ const values_15 = forLoopVar_5[1];
856
+ const key_10 = forLoopVar_5[0];
784
857
  let matchValue_22;
785
858
  const cell_1 = new FSharpRef(defaultOf());
786
- matchValue_22 = [tryGetValue(histories, key_9, cell_1), cell_1.contents];
859
+ matchValue_22 = [tryGetValue(histories, key_10, cell_1), cell_1.contents];
787
860
  if (matchValue_22[0]) {
788
- addRangeInPlace(values_14, matchValue_22[1]);
861
+ addRangeInPlace(values_15, matchValue_22[1]);
789
862
  }
790
863
  else {
791
- histories.set(key_9, Array.from(values_14));
864
+ histories.set(key_10, Array.from(values_15));
792
865
  }
793
866
  }
794
867
  }
795
868
  finally {
796
- disposeSafe(enumerator_5);
869
+ disposeSafe(enumerator_6);
797
870
  }
798
871
  }
799
872
  }
800
873
  finally {
801
- disposeSafe(enumerator_4);
874
+ disposeSafe(enumerator_5);
802
875
  }
803
- let enumerator_6 = getEnumerator(histories);
876
+ let enumerator_7 = getEnumerator(histories);
804
877
  try {
805
- while (enumerator_6["System.Collections.IEnumerator.MoveNext"]()) {
806
- const pair_1 = enumerator_6["System.Collections.Generic.IEnumerator`1.get_Current"]();
807
- const distinct = toArray(distinct_1(pair_1[1], {
878
+ while (enumerator_7["System.Collections.IEnumerator.MoveNext"]()) {
879
+ const pair_2 = enumerator_7["System.Collections.Generic.IEnumerator`1.get_Current"]();
880
+ const distinct = toArray(distinct_1(pair_2[1], {
808
881
  Equals: equalArrays,
809
- GetHashCode: (x_22) => (arrayHash(x_22) | 0),
882
+ GetHashCode: (x_24) => (arrayHash(x_24) | 0),
810
883
  }));
811
- clear(pair_1[1]);
812
- addRangeInPlace(distinct, pair_1[1]);
884
+ clear(pair_2[1]);
885
+ addRangeInPlace(distinct, pair_2[1]);
813
886
  }
814
887
  }
815
888
  finally {
816
- disposeSafe(enumerator_6);
889
+ disposeSafe(enumerator_7);
817
890
  }
818
891
  clock = commonClock(map((tupledArg_7) => tupledArg_7[1], results));
819
892
  const ownTime = fold((e_2, e_3) => (max(e_2, e_3) | 0), 0, map((tupledArg_8) => (defaultArg(tryFind(task, tupledArg_8[1]), 0) | 0), results)) | 0;
820
893
  clock = add(task, ownTime, clock);
821
- return combine(map((tupledArg_9) => tupledArg_9[0], results));
894
+ consumers.clear();
895
+ iterate((tupledArg_10) => {
896
+ const alternatives_1 = map((tuple_13) => tuple_13[1], tupledArg_10[1]);
897
+ consumers.set(tupledArg_10[0], new Consumer(FSharpList__get_Head(alternatives_1).Handler, combine(map((_arg_16) => _arg_16.State, alternatives_1)), commonClock(map((_arg_17) => _arg_17.Clock, alternatives_1))));
898
+ }, List_groupBy((tuple_12) => (tuple_12[0] | 0), collect((tupledArg_9) => tupledArg_9[3], results), {
899
+ Equals: (x_25, y_25) => (x_25 === y_25),
900
+ GetHashCode: (x_25) => (numberHash(x_25) | 0),
901
+ }));
902
+ return combine(map((tupledArg_11) => tupledArg_11[0], results));
822
903
  };
823
- const wireRecursive = (env_8) => ((values_16) => {
824
- const enumerator_7 = getEnumerator(values_16);
904
+ const wireRecursive = (env_8) => ((values_20) => {
905
+ const enumerator_8 = getEnumerator(values_20);
825
906
  try {
826
- while (enumerator_7["System.Collections.IEnumerator.MoveNext"]()) {
827
- const enumerator_8 = getEnumerator(enumerator_7["System.Collections.Generic.IEnumerator`1.get_Current"]().Callables);
907
+ while (enumerator_8["System.Collections.IEnumerator.MoveNext"]()) {
908
+ const enumerator_9 = getEnumerator(enumerator_8["System.Collections.Generic.IEnumerator`1.get_Current"]().Callables);
828
909
  try {
829
- while (enumerator_8["System.Collections.IEnumerator.MoveNext"]()) {
830
- const callable = enumerator_8["System.Collections.Generic.IEnumerator`1.get_Current"]();
910
+ while (enumerator_9["System.Collections.IEnumerator.MoveNext"]()) {
911
+ const callable = enumerator_9["System.Collections.Generic.IEnumerator`1.get_Current"]();
831
912
  if (callable.tag === 0) {
832
913
  const ids = ofSeq(references(callable.fields[2]), {
833
- Compare: (x_23, y_23) => (comparePrimitives(x_23, y_23) | 0),
914
+ Compare: (x_26, y_26) => (comparePrimitives(x_26, y_26) | 0),
834
915
  });
835
- callable.fields[3].contents = filter_1((id_2, _arg_12) => contains(id_2, ids), env_8);
916
+ callable.fields[3].contents = filter_1((id_3, _arg_21) => contains(id_3, ids), env_8);
836
917
  }
837
918
  }
838
919
  }
839
920
  finally {
840
- disposeSafe(enumerator_8);
921
+ disposeSafe(enumerator_9);
841
922
  }
842
923
  }
843
924
  }
844
925
  finally {
845
- disposeSafe(enumerator_7);
926
+ disposeSafe(enumerator_8);
846
927
  }
847
928
  });
848
929
  const apply = (span_1) => ((resultType) => ((fn_4) => ((argument_4) => {
849
930
  if (isEmpty(fn_4.Callables)) {
850
- const arg_13 = union(fn_4.Resources, argument_4.Resources);
851
- access(span_1, arg_13);
931
+ const arg_14 = union(fn_4.Resources, argument_4.Resources);
932
+ access(span_1, arg_14);
852
933
  return combine(ofArray([fn_4, argument_4, unknown("unknown-call", resultType)]));
853
934
  }
854
935
  else {
855
- const invoke = (_arg_13) => {
856
- if (_arg_13.tag === 1) {
857
- const signature = _arg_13.fields[3];
858
- const name_8 = _arg_13.fields[0];
859
- const external = _arg_13.fields[2];
860
- const arity_1 = _arg_13.fields[1] | 0;
861
- const arguments$_1 = append(_arg_13.fields[4], singleton(argument_4));
862
- if (length(arguments$_1) >= arity_1) {
936
+ const invoke = (_arg_22) => {
937
+ if (_arg_22.tag === 1) {
938
+ const signature = _arg_22.fields[3];
939
+ const name_8 = _arg_22.fields[0];
940
+ const external = _arg_22.fields[2];
941
+ const arity_1 = _arg_22.fields[1] | 0;
942
+ const arguments$_3 = append(_arg_22.fields[4], singleton(argument_4));
943
+ if (length(arguments$_3) >= arity_1) {
863
944
  const returned = (count_2_mut, typ_8_mut) => {
864
945
  returned:
865
946
  while (true) {
@@ -878,33 +959,33 @@ export function analyze(registration, options, program) {
878
959
  break;
879
960
  }
880
961
  };
881
- return invokeFunction(span_1)(returned(arity_1, signature))(name_8)(external)(arguments$_1);
962
+ return invokeFunction(span_1)(returned(arity_1, signature))(name_8)(external)(arguments$_3);
882
963
  }
883
964
  else {
884
- const bind$0040_4 = combine(arguments$_1);
885
- return new AbstractValue(bind$0040_4.Resources, bind$0040_4.Fields, singleton(new Callable(/* Function */ 1, [name_8, arity_1, external, signature, arguments$_1])), bind$0040_4.Tasks, bind$0040_4.Count);
965
+ const bind$0040_5 = combine(arguments$_3);
966
+ return new AbstractValue(bind$0040_5.Resources, bind$0040_5.Fields, singleton(new Callable(/* Function */ 1, [name_8, arity_1, external, signature, arguments$_3])), bind$0040_5.Tasks, bind$0040_5.Consumers, bind$0040_5.Count);
886
967
  }
887
968
  }
888
969
  else {
889
- const id_3 = _arg_13.fields[0] | 0;
890
- if (addToSet(id_3, activeCalls)) {
970
+ const id_4 = _arg_22.fields[0] | 0;
971
+ if (addToSet(id_4, activeCalls)) {
891
972
  const previous_2 = callSites;
892
973
  callSites = cons(span_1, previous_2);
893
974
  try {
894
- return evaluate(add(_arg_13.fields[1].SymbolId, argument_4, _arg_13.fields[3].contents))(_arg_13.fields[2]);
975
+ return evaluate(add(_arg_22.fields[1].SymbolId, argument_4, _arg_22.fields[3].contents))(_arg_22.fields[2]);
895
976
  }
896
977
  finally {
897
978
  callSites = previous_2;
898
- activeCalls.delete(id_3);
979
+ activeCalls.delete(id_4);
899
980
  }
900
981
  }
901
982
  else {
902
- return combine(ofArray([fn_4, argument_4, unknown("recursive:" + int32ToString(id_3), resultType)]));
983
+ return combine(ofArray([fn_4, argument_4, unknown("recursive:" + int32ToString(id_4), resultType)]));
903
984
  }
904
985
  }
905
986
  };
906
987
  const matchValue_24 = fn_4.Callables;
907
- let matchResult_4, only, alternatives_1;
988
+ let matchResult_4, only, alternatives_2;
908
989
  if (!isEmpty(matchValue_24)) {
909
990
  if (isEmpty(tail_2(matchValue_24))) {
910
991
  matchResult_4 = 0;
@@ -912,49 +993,155 @@ export function analyze(registration, options, program) {
912
993
  }
913
994
  else {
914
995
  matchResult_4 = 1;
915
- alternatives_1 = matchValue_24;
996
+ alternatives_2 = matchValue_24;
916
997
  }
917
998
  }
918
999
  else {
919
1000
  matchResult_4 = 1;
920
- alternatives_1 = matchValue_24;
1001
+ alternatives_2 = matchValue_24;
921
1002
  }
922
1003
  switch (matchResult_4) {
923
1004
  case 0:
924
1005
  return invoke(only);
925
1006
  default:
926
- return branches(map((callable_1) => (() => invoke(callable_1)), alternatives_1));
1007
+ return branches(map((callable_1) => (() => invoke(callable_1)), alternatives_2));
927
1008
  }
928
1009
  }
929
1010
  })));
930
- const invokeFunction = (span_2) => ((resultType_1) => ((name_9) => ((external_1) => ((arguments$_2) => {
931
- let option_27;
932
- const completed = (value_40) => choose((id_4) => {
933
- let matchValue_25;
934
- const cell_2 = new FSharpRef(defaultOf());
935
- matchValue_25 = [tryGetValue(tasks, id_4, cell_2), cell_2.contents];
936
- if (matchValue_25[0]) {
937
- return matchValue_25[1];
1011
+ const invokeFunction = (span_2) => ((resultType_1) => ((name_9) => ((external_1) => ((arguments$_4) => {
1012
+ let list_46;
1013
+ const matchValue_25 = tryFind(name_9, options.ConsumerOperations);
1014
+ if (matchValue_25 != null) {
1015
+ switch (matchValue_25.tag) {
1016
+ case 1: {
1017
+ const messageIndex = matchValue_25.fields[1] | 0;
1018
+ const receiverIndex = matchValue_25.fields[0] | 0;
1019
+ const parent = task | 0;
1020
+ tick();
1021
+ const parentClock = clock;
1022
+ const enumerator_10 = getEnumerator(item_5(receiverIndex, arguments$_4).Consumers);
1023
+ try {
1024
+ while (enumerator_10["System.Collections.IEnumerator.MoveNext"]()) {
1025
+ const id_5 = enumerator_10["System.Collections.Generic.IEnumerator`1.get_Current"]() | 0;
1026
+ let matchValue_27;
1027
+ const cell_2 = new FSharpRef(defaultOf());
1028
+ matchValue_27 = [tryGetValue(consumers, id_5, cell_2), cell_2.contents];
1029
+ if (matchValue_27[0]) {
1030
+ const consumer = matchValue_27[1];
1031
+ task = (id_5 | 0);
1032
+ clock = mergeClock(consumer.Clock, parentClock);
1033
+ const arg_16 = unionMany([consumer.Handler.Resources, consumer.State.Resources, item_5(messageIndex, arguments$_4).Resources], {
1034
+ Compare: (x_29, y_29) => (compare(x_29, y_29) | 0),
1035
+ });
1036
+ access(span_2, arg_16);
1037
+ const returnType = (count_3_mut, typ_10_mut) => {
1038
+ returnType:
1039
+ while (true) {
1040
+ const count_3 = count_3_mut, typ_10 = typ_10_mut;
1041
+ if (count_3 === 0) {
1042
+ return typ_10;
1043
+ }
1044
+ else if (typ_10.tag === 11) {
1045
+ count_3_mut = (count_3 - 1);
1046
+ typ_10_mut = typ_10.fields[1];
1047
+ continue returnType;
1048
+ }
1049
+ else {
1050
+ return typ_10;
1051
+ }
1052
+ break;
1053
+ }
1054
+ };
1055
+ const resultType_2 = (value_41) => defaultArg(tryPick((_arg_23) => {
1056
+ if (_arg_23.tag === 1) {
1057
+ return returnType(length(_arg_23.fields[4]) + 1, _arg_23.fields[3]);
1058
+ }
1059
+ else {
1060
+ return _arg_23.fields[2].Type;
1061
+ }
1062
+ }, value_41.Callables), new Type(/* TRecord */ 8, [empty_2({
1063
+ Compare: (x_30, y_30) => (comparePrimitives(x_30, y_30) | 0),
1064
+ })]));
1065
+ const next_4 = apply(span_2)(resultType_2(consumer.Handler))(consumer.Handler)(consumer.State);
1066
+ const state_9 = apply(span_2)(resultType_2(next_4))(next_4)(item_5(messageIndex, arguments$_4));
1067
+ consumers.set(id_5, new Consumer(consumer.Handler, state_9, clock));
1068
+ }
1069
+ }
1070
+ }
1071
+ finally {
1072
+ disposeSafe(enumerator_10);
1073
+ }
1074
+ task = (parent | 0);
1075
+ clock = parentClock;
1076
+ tick();
1077
+ return empty;
1078
+ }
1079
+ case 2: {
1080
+ const receiverIndex_1 = matchValue_25.fields[0] | 0;
1081
+ const completed = toList_2(choose_1((id_6) => {
1082
+ let matchValue_29;
1083
+ const cell_3 = new FSharpRef(defaultOf());
1084
+ matchValue_29 = [tryGetValue(consumers, id_6, cell_3), cell_3.contents];
1085
+ if (matchValue_29[0]) {
1086
+ const value_43 = matchValue_29[1];
1087
+ return [value_43.Clock, value_43.State];
1088
+ }
1089
+ else {
1090
+ return undefined;
1091
+ }
1092
+ }, item_5(receiverIndex_1, arguments$_4).Consumers));
1093
+ const completions = completed;
1094
+ if (!isEmpty(completions)) {
1095
+ clock = mergeClock(clock, (list_46 = map((tuple_14) => tuple_14[0], completions), fold(mergeClock, empty_2({
1096
+ Compare: (x_27, y_27) => (comparePrimitives(x_27, y_27) | 0),
1097
+ }), list_46)));
1098
+ }
1099
+ tick();
1100
+ return combine(map((tuple_15) => tuple_15[1], completed));
1101
+ }
1102
+ default: {
1103
+ const handlerIndex = matchValue_25.fields[0] | 0;
1104
+ const stateIndex = matchValue_25.fields[1] | 0;
1105
+ nextTask = ((nextTask + 1) | 0);
1106
+ consumers.set(nextTask, new Consumer(item_5(handlerIndex, arguments$_4), item_5(stateIndex, arguments$_4), clock));
1107
+ return new AbstractValue(empty.Resources, empty.Fields, empty.Callables, empty.Tasks, singleton_1(nextTask, {
1108
+ Compare: (x_28, y_28) => (comparePrimitives(x_28, y_28) | 0),
1109
+ }), empty.Count);
1110
+ }
1111
+ }
1112
+ }
1113
+ else {
1114
+ return invokeOrdinary(span_2)(resultType_1)(name_9)(external_1)(arguments$_4);
1115
+ }
1116
+ }))));
1117
+ const invokeOrdinary = (span_3) => ((resultType_3) => ((name_10) => ((external_2) => ((arguments$_5) => {
1118
+ let option_28;
1119
+ const completed_1 = (value_44) => choose((id_7) => {
1120
+ let matchValue_30;
1121
+ const cell_4 = new FSharpRef(defaultOf());
1122
+ matchValue_30 = [tryGetValue(tasks, id_7, cell_4), cell_4.contents];
1123
+ if (matchValue_30[0]) {
1124
+ return matchValue_30[1];
938
1125
  }
939
1126
  else {
940
1127
  return undefined;
941
1128
  }
942
- }, toList(value_40.Tasks));
943
- const join = (completions) => {
944
- let list_41;
945
- if (!isEmpty(completions)) {
946
- clock = mergeClock(clock, (list_41 = map((tuple_12) => tuple_12[0], completions), fold(mergeClock, empty_2({
947
- Compare: (x_24, y_24) => (comparePrimitives(x_24, y_24) | 0),
948
- }), list_41)));
1129
+ }, toList(value_44.Tasks));
1130
+ const join_1 = (completions_1) => {
1131
+ let list_51;
1132
+ if (!isEmpty(completions_1)) {
1133
+ clock = mergeClock(clock, (list_51 = map((tuple_16) => tuple_16[0], completions_1), fold(mergeClock, empty_2({
1134
+ Compare: (x_31, y_31) => (comparePrimitives(x_31, y_31) | 0),
1135
+ }), list_51)));
949
1136
  }
950
1137
  tick();
951
1138
  };
952
- const ready = (value_41) => {
1139
+ const ready = (value_45) => {
953
1140
  nextTask = ((nextTask + 1) | 0);
954
- tasks.set(nextTask, [clock, value_41]);
1141
+ tasks.set(nextTask, [clock, value_45]);
955
1142
  return new AbstractValue(empty.Resources, empty.Fields, empty.Callables, singleton_1(nextTask, {
956
- Compare: (x_25, y_25) => (comparePrimitives(x_25, y_25) | 0),
957
- }), empty.Count);
1143
+ Compare: (x_32, y_32) => (comparePrimitives(x_32, y_32) | 0),
1144
+ }), empty.Consumers, empty.Count);
958
1145
  };
959
1146
  const fork = (callback, run) => {
960
1147
  const task_1 = task | 0;
@@ -965,25 +1152,25 @@ export function analyze(registration, options, program) {
965
1152
  const child_1 = nextTask | 0;
966
1153
  task = (child_1 | 0);
967
1154
  clock = add(child_1, 0, forkClock);
968
- const result_2 = run((argument_5) => {
969
- access(defaultArg(tryHead(callSites), span_2), callback.Resources);
970
- return apply(span_2)((resultType_1.tag === 6) ? resultType_1.fields[0] : Type.TUnit)(callback)(argument_5);
1155
+ const result_3 = run((argument_5) => {
1156
+ access(defaultArg(tryHead(callSites), span_3), callback.Resources);
1157
+ return apply(span_3)((resultType_3.tag === 6) ? resultType_3.fields[0] : Type.TUnit)(callback)(argument_5);
971
1158
  });
972
- tasks.set(child_1, [clock, result_2]);
1159
+ tasks.set(child_1, [clock, result_3]);
973
1160
  task = (task_1 | 0);
974
1161
  clock = mergeClock(clock_3, forkClock);
975
1162
  tick();
976
1163
  return new AbstractValue(empty.Resources, empty.Fields, empty.Callables, singleton_1(child_1, {
977
- Compare: (x_26, y_26) => (comparePrimitives(x_26, y_26) | 0),
978
- }), empty.Count);
1164
+ Compare: (x_33, y_33) => (comparePrimitives(x_33, y_33) | 0),
1165
+ }), empty.Consumers, empty.Count);
979
1166
  };
980
- let matchResult_5, value_42, callback_1, value_43, callback_2, values_18, callback_3, values_20, values_21, thunk, value_45;
981
- switch (name_9) {
1167
+ let matchResult_5, value_46, callback_1, value_47, callback_2, values_23, callback_3, values_25, values_26, thunk, value_49;
1168
+ switch (name_10) {
982
1169
  case "Task.fromResult": {
983
- if (!isEmpty(arguments$_2)) {
984
- if (isEmpty(tail_2(arguments$_2))) {
1170
+ if (!isEmpty(arguments$_5)) {
1171
+ if (isEmpty(tail_2(arguments$_5))) {
985
1172
  matchResult_5 = 0;
986
- value_42 = head(arguments$_2);
1173
+ value_46 = head(arguments$_5);
987
1174
  }
988
1175
  else {
989
1176
  matchResult_5 = 8;
@@ -995,8 +1182,8 @@ export function analyze(registration, options, program) {
995
1182
  break;
996
1183
  }
997
1184
  case "Task.delay": {
998
- if (!isEmpty(arguments$_2)) {
999
- if (isEmpty(tail_2(arguments$_2))) {
1185
+ if (!isEmpty(arguments$_5)) {
1186
+ if (isEmpty(tail_2(arguments$_5))) {
1000
1187
  matchResult_5 = 1;
1001
1188
  }
1002
1189
  else {
@@ -1009,12 +1196,12 @@ export function analyze(registration, options, program) {
1009
1196
  break;
1010
1197
  }
1011
1198
  case "Task.continueWith": {
1012
- if (!isEmpty(arguments$_2)) {
1013
- if (!isEmpty(tail_2(arguments$_2))) {
1014
- if (isEmpty(tail_2(tail_2(arguments$_2)))) {
1199
+ if (!isEmpty(arguments$_5)) {
1200
+ if (!isEmpty(tail_2(arguments$_5))) {
1201
+ if (isEmpty(tail_2(tail_2(arguments$_5)))) {
1015
1202
  matchResult_5 = 2;
1016
- callback_1 = head(arguments$_2);
1017
- value_43 = head(tail_2(arguments$_2));
1203
+ callback_1 = head(arguments$_5);
1204
+ value_47 = head(tail_2(arguments$_5));
1018
1205
  }
1019
1206
  else {
1020
1207
  matchResult_5 = 8;
@@ -1030,12 +1217,12 @@ export function analyze(registration, options, program) {
1030
1217
  break;
1031
1218
  }
1032
1219
  case "Task.whenAll": {
1033
- if (!isEmpty(arguments$_2)) {
1034
- if (!isEmpty(tail_2(arguments$_2))) {
1035
- if (isEmpty(tail_2(tail_2(arguments$_2)))) {
1220
+ if (!isEmpty(arguments$_5)) {
1221
+ if (!isEmpty(tail_2(arguments$_5))) {
1222
+ if (isEmpty(tail_2(tail_2(arguments$_5)))) {
1036
1223
  matchResult_5 = 3;
1037
- callback_2 = head(arguments$_2);
1038
- values_18 = head(tail_2(arguments$_2));
1224
+ callback_2 = head(arguments$_5);
1225
+ values_23 = head(tail_2(arguments$_5));
1039
1226
  }
1040
1227
  else {
1041
1228
  matchResult_5 = 8;
@@ -1051,12 +1238,12 @@ export function analyze(registration, options, program) {
1051
1238
  break;
1052
1239
  }
1053
1240
  case "Task.whenAny": {
1054
- if (!isEmpty(arguments$_2)) {
1055
- if (!isEmpty(tail_2(arguments$_2))) {
1056
- if (isEmpty(tail_2(tail_2(arguments$_2)))) {
1241
+ if (!isEmpty(arguments$_5)) {
1242
+ if (!isEmpty(tail_2(arguments$_5))) {
1243
+ if (isEmpty(tail_2(tail_2(arguments$_5)))) {
1057
1244
  matchResult_5 = 4;
1058
- callback_3 = head(arguments$_2);
1059
- values_20 = head(tail_2(arguments$_2));
1245
+ callback_3 = head(arguments$_5);
1246
+ values_25 = head(tail_2(arguments$_5));
1060
1247
  }
1061
1248
  else {
1062
1249
  matchResult_5 = 8;
@@ -1072,10 +1259,10 @@ export function analyze(registration, options, program) {
1072
1259
  break;
1073
1260
  }
1074
1261
  case "Task.awaitAll": {
1075
- if (!isEmpty(arguments$_2)) {
1076
- if (isEmpty(tail_2(arguments$_2))) {
1262
+ if (!isEmpty(arguments$_5)) {
1263
+ if (isEmpty(tail_2(arguments$_5))) {
1077
1264
  matchResult_5 = 5;
1078
- values_21 = head(arguments$_2);
1265
+ values_26 = head(arguments$_5);
1079
1266
  }
1080
1267
  else {
1081
1268
  matchResult_5 = 8;
@@ -1087,10 +1274,10 @@ export function analyze(registration, options, program) {
1087
1274
  break;
1088
1275
  }
1089
1276
  case "Task.spawn": {
1090
- if (!isEmpty(arguments$_2)) {
1091
- if (isEmpty(tail_2(arguments$_2))) {
1277
+ if (!isEmpty(arguments$_5)) {
1278
+ if (isEmpty(tail_2(arguments$_5))) {
1092
1279
  matchResult_5 = 6;
1093
- thunk = head(arguments$_2);
1280
+ thunk = head(arguments$_5);
1094
1281
  }
1095
1282
  else {
1096
1283
  matchResult_5 = 8;
@@ -1102,10 +1289,10 @@ export function analyze(registration, options, program) {
1102
1289
  break;
1103
1290
  }
1104
1291
  case "Task.await": {
1105
- if (!isEmpty(arguments$_2)) {
1106
- if (isEmpty(tail_2(arguments$_2))) {
1292
+ if (!isEmpty(arguments$_5)) {
1293
+ if (isEmpty(tail_2(arguments$_5))) {
1107
1294
  matchResult_5 = 7;
1108
- value_45 = head(arguments$_2);
1295
+ value_49 = head(arguments$_5);
1109
1296
  }
1110
1297
  else {
1111
1298
  matchResult_5 = 8;
@@ -1121,35 +1308,35 @@ export function analyze(registration, options, program) {
1121
1308
  }
1122
1309
  switch (matchResult_5) {
1123
1310
  case 0:
1124
- return ready(value_42);
1311
+ return ready(value_46);
1125
1312
  case 1:
1126
1313
  return ready(empty);
1127
1314
  case 2: {
1128
- const completions_1 = completed(value_43);
1315
+ const completions_2 = completed_1(value_47);
1129
1316
  return fork(callback_1, (invoke_1) => {
1130
- join(completions_1);
1131
- return invoke_1(combine(map((tuple_13) => tuple_13[1], completions_1)));
1317
+ join_1(completions_2);
1318
+ return invoke_1(combine(map((tuple_17) => tuple_17[1], completions_2)));
1132
1319
  });
1133
1320
  }
1134
1321
  case 3: {
1135
- const completions_2 = completed(contents(values_18));
1322
+ const completions_3 = completed_1(contents(values_23));
1136
1323
  return fork(callback_2, (invoke_2) => {
1137
- join(completions_2);
1138
- return invoke_2(container("$items", values_18.Count, combine(map((tuple_14) => tuple_14[1], completions_2))));
1324
+ join_1(completions_3);
1325
+ return invoke_2(container("$items", values_23.Count, combine(map((tuple_18) => tuple_18[1], completions_3))));
1139
1326
  });
1140
1327
  }
1141
1328
  case 4: {
1142
- const completions_3 = completed(contents(values_20));
1143
- return fork(callback_3, (invoke_3) => (isEmpty(completions_3) ? invoke_3(contents(values_20)) : branches(map((tupledArg_10) => (() => {
1144
- const value_44 = tupledArg_10[1];
1145
- join(singleton([tupledArg_10[0], value_44]));
1146
- return invoke_3(value_44);
1147
- }), completions_3))));
1329
+ const completions_4 = completed_1(contents(values_25));
1330
+ return fork(callback_3, (invoke_3) => (isEmpty(completions_4) ? invoke_3(contents(values_25)) : branches(map((tupledArg_12) => (() => {
1331
+ const value_48 = tupledArg_12[1];
1332
+ join_1(singleton([tupledArg_12[0], value_48]));
1333
+ return invoke_3(value_48);
1334
+ }), completions_4))));
1148
1335
  }
1149
1336
  case 5: {
1150
- const completions_4 = completed(contents(values_21));
1151
- join(completions_4);
1152
- return container("$items", values_21.Count, combine(map((tuple_15) => tuple_15[1], completions_4)));
1337
+ const completions_5 = completed_1(contents(values_26));
1338
+ join_1(completions_5);
1339
+ return container("$items", values_26.Count, combine(map((tuple_19) => tuple_19[1], completions_5)));
1153
1340
  }
1154
1341
  case 6: {
1155
1342
  const task_2 = task | 0;
@@ -1160,71 +1347,71 @@ export function analyze(registration, options, program) {
1160
1347
  const child_2 = nextTask | 0;
1161
1348
  task = (child_2 | 0);
1162
1349
  clock = add(child_2, 0, forkClock_1);
1163
- access(defaultArg(tryHead(callSites), span_2), thunk.Resources);
1164
- const result_3 = apply(span_2)((resultType_1.tag === 6) ? resultType_1.fields[0] : Type.TUnit)(thunk)(empty);
1165
- tasks.set(child_2, [clock, result_3]);
1350
+ access(defaultArg(tryHead(callSites), span_3), thunk.Resources);
1351
+ const result_4 = apply(span_3)((resultType_3.tag === 6) ? resultType_3.fields[0] : Type.TUnit)(thunk)(empty);
1352
+ tasks.set(child_2, [clock, result_4]);
1166
1353
  task = (task_2 | 0);
1167
1354
  clock = mergeClock(clock_4, forkClock_1);
1168
1355
  tick();
1169
1356
  return new AbstractValue(empty.Resources, empty.Fields, empty.Callables, singleton_1(child_2, {
1170
- Compare: (x_27, y_27) => (comparePrimitives(x_27, y_27) | 0),
1171
- }), empty.Count);
1357
+ Compare: (x_34, y_34) => (comparePrimitives(x_34, y_34) | 0),
1358
+ }), empty.Consumers, empty.Count);
1172
1359
  }
1173
1360
  case 7: {
1174
- const completed_1 = choose((id_5) => {
1175
- let matchValue_27;
1176
- const cell_3 = new FSharpRef(defaultOf());
1177
- matchValue_27 = [tryGetValue(tasks, id_5, cell_3), cell_3.contents];
1178
- if (matchValue_27[0]) {
1179
- return matchValue_27[1];
1361
+ const completed_2 = choose((id_8) => {
1362
+ let matchValue_32;
1363
+ const cell_5 = new FSharpRef(defaultOf());
1364
+ matchValue_32 = [tryGetValue(tasks, id_8, cell_5), cell_5.contents];
1365
+ if (matchValue_32[0]) {
1366
+ return matchValue_32[1];
1180
1367
  }
1181
1368
  else {
1182
1369
  return undefined;
1183
1370
  }
1184
- }, toList(value_45.Tasks));
1185
- if (!isEmpty(completed_1)) {
1186
- clock = mergeClock(clock, commonClock(map((tuple_16) => tuple_16[0], completed_1)));
1371
+ }, toList(value_49.Tasks));
1372
+ if (!isEmpty(completed_2)) {
1373
+ clock = mergeClock(clock, commonClock(map((tuple_20) => tuple_20[0], completed_2)));
1187
1374
  }
1188
1375
  tick();
1189
- return combine(map((tuple_17) => tuple_17[1], completed_1));
1376
+ return combine(map((tuple_21) => tuple_21[1], completed_2));
1190
1377
  }
1191
1378
  default: {
1192
- const inputs_1 = combine(arguments$_2);
1193
- if (external_1 && !contains(name_9, safeFunctions)) {
1194
- const arg_19 = add_1(new Resource("function:" + name_9, name_9, true), inputs_1.Resources);
1195
- access(span_2, arg_19);
1196
- }
1197
- const parameterTypes = (_arg_14) => {
1198
- if (_arg_14.tag === 11) {
1199
- return cons(_arg_14.fields[0], parameterTypes(_arg_14.fields[1]));
1379
+ const inputs_1 = combine(arguments$_5);
1380
+ if (external_2) {
1381
+ const arg_22 = contains(name_10, safeFunctions) ? inputs_1.Resources : add_1(new Resource("function:" + name_10, name_10, true), inputs_1.Resources);
1382
+ access(span_3, arg_22);
1383
+ }
1384
+ const parameterTypes = (_arg_24) => {
1385
+ if (_arg_24.tag === 11) {
1386
+ return cons(_arg_24.fields[0], parameterTypes(_arg_24.fields[1]));
1200
1387
  }
1201
1388
  else {
1202
1389
  return empty_3();
1203
1390
  }
1204
1391
  };
1205
- const signature_1 = defaultArg((option_27 = tryFind(name_9, builtinSchemes), (option_27 != null) ? parameterTypes(option_27.fields[1]) : undefined), empty_3());
1206
- const items_1 = combine(map(contents, filter((value_47) => isEmpty(value_47.Callables), arguments$_2)));
1207
- const callbackResults = collect((tupledArg_11) => {
1208
- let option_30, option_33;
1209
- const callback_4 = tupledArg_11[1];
1210
- const callbackParameters = defaultArg((option_30 = tryItem(tupledArg_11[0], signature_1), (option_30 != null) ? parameterTypes(option_30) : undefined), empty_3());
1392
+ const signature_2 = defaultArg((option_28 = tryFind(name_10, builtinSchemes), (option_28 != null) ? parameterTypes(option_28.fields[1]) : undefined), empty_3());
1393
+ const items_1 = combine(map(contents, filter((value_51) => isEmpty(value_51.Callables), arguments$_5)));
1394
+ const callbackResults = collect((tupledArg_13) => {
1395
+ let option_31, option_34;
1396
+ const callback_4 = tupledArg_13[1];
1397
+ const callbackParameters = defaultArg((option_31 = tryItem(tupledArg_13[0], signature_2), (option_31 != null) ? parameterTypes(option_31) : undefined), empty_3());
1211
1398
  if (isEmpty(callback_4.Callables) ? true : isEmpty(callbackParameters)) {
1212
1399
  return empty_3();
1213
1400
  }
1214
1401
  else {
1215
- const iterations = ((name_9.startsWith("List.") ? true : name_9.startsWith("Map.")) ? defaultArg((option_33 = tryPick((_arg_16) => _arg_16.Count, arguments$_2), (option_33 != null) ? min(2, option_33) : undefined), 2) : 1) | 0;
1216
- return toList_2(delay(() => collect_1((matchValue_28) => singleton_2(fold((fn_5, typ_13) => apply(span_2)(typ_13)(fn_5)(items_1), callback_4, callbackParameters)), rangeDouble(1, 1, iterations))));
1402
+ const iterations = ((name_10.startsWith("List.") ? true : name_10.startsWith("Map.")) ? defaultArg((option_34 = tryPick((_arg_26) => _arg_26.Count, arguments$_5), (option_34 != null) ? min(2, option_34) : undefined), 2) : 1) | 0;
1403
+ return toList_2(delay(() => collect_1((matchValue_33) => singleton_2(fold((fn_5, typ_14) => apply(span_3)(typ_14)(fn_5)(items_1), callback_4, callbackParameters)), rangeDouble(1, 1, iterations))));
1217
1404
  }
1218
- }, indexed(arguments$_2));
1219
- const result_6 = unknown("result:" + name_9, resultType_1);
1405
+ }, indexed(arguments$_5));
1406
+ const result_7 = unknown("result:" + name_10, resultType_3);
1220
1407
  let matchResult_6;
1221
- switch (resultType_1.tag) {
1408
+ switch (resultType_3.tag) {
1222
1409
  case 0:
1223
1410
  case 1:
1224
1411
  case 2:
1225
1412
  case 3:
1226
1413
  case 4:
1227
- case 14: {
1414
+ case 16: {
1228
1415
  matchResult_6 = 0;
1229
1416
  break;
1230
1417
  }
@@ -1241,7 +1428,7 @@ export function analyze(registration, options, program) {
1241
1428
  break;
1242
1429
  }
1243
1430
  case 11: {
1244
- if (external_1) {
1431
+ if (external_2) {
1245
1432
  matchResult_6 = 4;
1246
1433
  }
1247
1434
  else {
@@ -1256,113 +1443,113 @@ export function analyze(registration, options, program) {
1256
1443
  case 0:
1257
1444
  return empty;
1258
1445
  case 1:
1259
- return container("$items", tryPick((_arg_17) => _arg_17.Count, arguments$_2), contains_1(name_9, ofArray(["List.map", "List.choose", "List.collect"]), {
1260
- Equals: (x_28, y_28) => (x_28 === y_28),
1261
- GetHashCode: (x_28) => (stringHash(x_28) | 0),
1262
- }) ? combine(map(contents, callbackResults)) : combine(ofArray([items_1, contents(result_6)])));
1446
+ return container("$items", tryPick((_arg_27) => _arg_27.Count, arguments$_5), contains_1(name_10, ofArray(["List.map", "List.choose", "List.collect"]), {
1447
+ Equals: (x_35, y_35) => (x_35 === y_35),
1448
+ GetHashCode: (x_35) => (stringHash(x_35) | 0),
1449
+ }) ? combine(map(contents, callbackResults)) : combine(ofArray([items_1, contents(result_7)])));
1263
1450
  case 2:
1264
- return container("$value", undefined, (name_9 === "Option.map") ? combine(callbackResults) : combine(ofArray([items_1, contents(result_6)])));
1451
+ return container("$value", undefined, (name_10 === "Option.map") ? combine(callbackResults) : combine(ofArray([items_1, contents(result_7)])));
1265
1452
  case 3:
1266
- return container("$items", undefined, combine(ofArrayWithTail([contents(inputs_1), result_6], callbackResults)));
1453
+ return container("$items", undefined, combine(ofArrayWithTail([contents(inputs_1), result_7], callbackResults)));
1267
1454
  case 4: {
1268
- const arity_2 = (_arg_18) => {
1269
- if (_arg_18.tag === 11) {
1270
- return (1 + arity_2(_arg_18.fields[1])) | 0;
1455
+ const arity_2 = (_arg_28) => {
1456
+ if (_arg_28.tag === 11) {
1457
+ return (1 + arity_2(_arg_28.fields[1])) | 0;
1271
1458
  }
1272
1459
  else {
1273
1460
  return 0;
1274
1461
  }
1275
1462
  };
1276
- const bind$0040_5 = combine(ofArray([result_6, inputs_1]));
1277
- return new AbstractValue(bind$0040_5.Resources, bind$0040_5.Fields, singleton(new Callable(/* Function */ 1, [name_9 + " (returned function)", arity_2(resultType_1), true, resultType_1, empty_3()])), bind$0040_5.Tasks, bind$0040_5.Count);
1463
+ const bind$0040_6 = combine(ofArray([result_7, inputs_1]));
1464
+ return new AbstractValue(bind$0040_6.Resources, bind$0040_6.Fields, singleton(new Callable(/* Function */ 1, [name_10 + " (returned function)", arity_2(resultType_3), true, resultType_3, empty_3()])), bind$0040_6.Tasks, bind$0040_6.Consumers, bind$0040_6.Count);
1278
1465
  }
1279
1466
  default:
1280
- return combine(ofArrayWithTail([result_6, inputs_1], callbackResults));
1467
+ return combine(ofArrayWithTail([result_7, inputs_1], callbackResults));
1281
1468
  }
1282
1469
  }
1283
1470
  }
1284
1471
  }))));
1285
1472
  let environment = empty_2({
1286
- Compare: (x_29, y_29) => (comparePrimitives(x_29, y_29) | 0),
1473
+ Compare: (x_36, y_36) => (comparePrimitives(x_36, y_36) | 0),
1287
1474
  });
1288
1475
  const entryFunctions = [];
1289
- const remember = (binding_7, value_52) => {
1290
- environment = add(binding_7.SymbolId, value_52, environment);
1291
- if (!isEmpty(value_52.Callables)) {
1292
- void (entryFunctions.push([value_52, binding_7.Type, binding_7.Span]));
1476
+ const remember = (binding_7, value_56) => {
1477
+ environment = add(binding_7.SymbolId, value_56, environment);
1478
+ if (!isEmpty(value_56.Callables)) {
1479
+ void (entryFunctions.push([value_56, binding_7.Type, binding_7.Span]));
1293
1480
  }
1294
1481
  };
1295
- const enumerator_9 = getEnumerator(program.ResolvedStatements);
1482
+ const enumerator_11 = getEnumerator(program.ResolvedStatements);
1296
1483
  try {
1297
- while (enumerator_9["System.Collections.IEnumerator.MoveNext"]()) {
1298
- const matchValue_29 = enumerator_9["System.Collections.Generic.IEnumerator`1.get_Current"]().Node;
1299
- switch (matchValue_29.tag) {
1484
+ while (enumerator_11["System.Collections.IEnumerator.MoveNext"]()) {
1485
+ const matchValue_34 = enumerator_11["System.Collections.Generic.IEnumerator`1.get_Current"]().Node;
1486
+ switch (matchValue_34.tag) {
1300
1487
  case 1: {
1301
- const declaration_2 = matchValue_29.fields[0];
1302
- const value_53 = evaluate(environment)(declaration_2.Value);
1303
- remember(declaration_2.Binding, value_53);
1304
- if (declaration_2.IsRecursive) {
1305
- wireRecursive(environment)(singleton(value_53));
1488
+ const declaration_3 = matchValue_34.fields[0];
1489
+ const value_57 = evaluate(environment)(declaration_3.Value);
1490
+ remember(declaration_3.Binding, value_57);
1491
+ if (declaration_3.IsRecursive) {
1492
+ wireRecursive(environment)(singleton(value_57));
1306
1493
  }
1307
1494
  break;
1308
1495
  }
1309
1496
  case 3: {
1310
- const values_28 = map((declaration_3) => [declaration_3, evaluate(environment)(declaration_3.Value)], matchValue_29.fields[0]);
1311
- const enumerator_10 = getEnumerator(values_28);
1497
+ const values_33 = map((declaration_4) => [declaration_4, evaluate(environment)(declaration_4.Value)], matchValue_34.fields[0]);
1498
+ const enumerator_12 = getEnumerator(values_33);
1312
1499
  try {
1313
- while (enumerator_10["System.Collections.IEnumerator.MoveNext"]()) {
1314
- const forLoopVar_5 = enumerator_10["System.Collections.Generic.IEnumerator`1.get_Current"]();
1315
- remember(forLoopVar_5[0].Binding, forLoopVar_5[1]);
1500
+ while (enumerator_12["System.Collections.IEnumerator.MoveNext"]()) {
1501
+ const forLoopVar_6 = enumerator_12["System.Collections.Generic.IEnumerator`1.get_Current"]();
1502
+ remember(forLoopVar_6[0].Binding, forLoopVar_6[1]);
1316
1503
  }
1317
1504
  }
1318
1505
  finally {
1319
- disposeSafe(enumerator_10);
1506
+ disposeSafe(enumerator_12);
1320
1507
  }
1321
- wireRecursive(environment)(map((tuple_18) => tuple_18[1], values_28));
1508
+ wireRecursive(environment)(map((tuple_22) => tuple_22[1], values_33));
1322
1509
  break;
1323
1510
  }
1324
1511
  case 2: {
1325
- const declaration_5 = matchValue_29.fields[0];
1326
- const value_55 = evaluate(environment)(declaration_5.Value);
1327
- const bound = bindPattern(environment, declaration_5.Pattern, value_55);
1512
+ const declaration_6 = matchValue_34.fields[0];
1513
+ const value_59 = evaluate(environment)(declaration_6.Value);
1514
+ const bound = bindPattern(environment, declaration_6.Pattern, value_59);
1328
1515
  const bindings_1 = (pattern_6_mut) => {
1329
1516
  bindings_1:
1330
1517
  while (true) {
1331
1518
  const pattern_6 = pattern_6_mut;
1332
- let option_36;
1333
- const matchValue_30 = pattern_6.Node;
1519
+ let option_37;
1520
+ const matchValue_35 = pattern_6.Node;
1334
1521
  let matchResult_7, binding_8, patterns_1, fields_7, a_2, b_2, item_4, entries_2, tail_1;
1335
- switch (matchValue_30.tag) {
1522
+ switch (matchValue_35.tag) {
1336
1523
  case 1: {
1337
1524
  matchResult_7 = 0;
1338
- binding_8 = matchValue_30.fields[0];
1525
+ binding_8 = matchValue_35.fields[0];
1339
1526
  break;
1340
1527
  }
1341
1528
  case 5: {
1342
1529
  matchResult_7 = 1;
1343
- patterns_1 = matchValue_30.fields[0];
1530
+ patterns_1 = matchValue_35.fields[0];
1344
1531
  break;
1345
1532
  }
1346
1533
  case 6: {
1347
1534
  matchResult_7 = 2;
1348
- fields_7 = matchValue_30.fields[0];
1535
+ fields_7 = matchValue_35.fields[0];
1349
1536
  break;
1350
1537
  }
1351
1538
  case 4: {
1352
1539
  matchResult_7 = 3;
1353
- a_2 = matchValue_30.fields[0];
1354
- b_2 = matchValue_30.fields[1];
1540
+ a_2 = matchValue_35.fields[0];
1541
+ b_2 = matchValue_35.fields[1];
1355
1542
  break;
1356
1543
  }
1357
1544
  case 8: {
1358
1545
  matchResult_7 = 4;
1359
- item_4 = matchValue_30.fields[0];
1546
+ item_4 = matchValue_35.fields[0];
1360
1547
  break;
1361
1548
  }
1362
1549
  case 10: {
1363
- if (matchValue_30.fields[2] != null) {
1550
+ if (matchValue_35.fields[2] != null) {
1364
1551
  matchResult_7 = 4;
1365
- item_4 = matchValue_30.fields[2];
1552
+ item_4 = matchValue_35.fields[2];
1366
1553
  }
1367
1554
  else {
1368
1555
  matchResult_7 = 6;
@@ -1371,8 +1558,8 @@ export function analyze(registration, options, program) {
1371
1558
  }
1372
1559
  case 7: {
1373
1560
  matchResult_7 = 5;
1374
- entries_2 = matchValue_30.fields[0];
1375
- tail_1 = matchValue_30.fields[1];
1561
+ entries_2 = matchValue_35.fields[0];
1562
+ tail_1 = matchValue_35.fields[1];
1376
1563
  break;
1377
1564
  }
1378
1565
  default:
@@ -1384,7 +1571,7 @@ export function analyze(registration, options, program) {
1384
1571
  case 1:
1385
1572
  return collect(bindings_1, patterns_1);
1386
1573
  case 2:
1387
- return collect((arg_20) => bindings_1(arg_20[1]), fields_7);
1574
+ return collect((arg_23) => bindings_1(arg_23[1]), fields_7);
1388
1575
  case 3:
1389
1576
  return append(bindings_1(a_2), bindings_1(b_2));
1390
1577
  case 4: {
@@ -1392,25 +1579,25 @@ export function analyze(registration, options, program) {
1392
1579
  continue bindings_1;
1393
1580
  }
1394
1581
  case 5:
1395
- return append(collect((tupledArg_12) => append(bindings_1(tupledArg_12[0]), bindings_1(tupledArg_12[1])), entries_2), defaultArg((option_36 = tail_1, (option_36 != null) ? bindings_1(option_36) : undefined), empty_3()));
1582
+ return append(collect((tupledArg_14) => append(bindings_1(tupledArg_14[0]), bindings_1(tupledArg_14[1])), entries_2), defaultArg((option_37 = tail_1, (option_37 != null) ? bindings_1(option_37) : undefined), empty_3()));
1396
1583
  default:
1397
1584
  return empty_3();
1398
1585
  }
1399
1586
  break;
1400
1587
  }
1401
1588
  };
1402
- const patternIds = ofList(map((binding_9) => [binding_9.Name, binding_9.SymbolId], bindings_1(declaration_5.Pattern)), {
1403
- Compare: (x_30, y_30) => (comparePrimitives(x_30, y_30) | 0),
1589
+ const patternIds = ofList(map((binding_9) => [binding_9.Name, binding_9.SymbolId], bindings_1(declaration_6.Pattern)), {
1590
+ Compare: (x_37, y_37) => (comparePrimitives(x_37, y_37) | 0),
1404
1591
  });
1405
- environment = fold((env_9, tupledArg_13) => {
1406
- let option_39;
1407
- const binding_10 = tupledArg_13[0];
1408
- return add(binding_10.SymbolId, defaultArg((option_39 = tryFind(binding_10.Name, patternIds), (option_39 != null) ? tryFind(option_39, bound) : undefined), value_55), env_9);
1409
- }, bound, declaration_5.Bindings);
1592
+ environment = fold((env_9, tupledArg_15) => {
1593
+ let option_40;
1594
+ const binding_10 = tupledArg_15[0];
1595
+ return add(binding_10.SymbolId, defaultArg((option_40 = tryFind(binding_10.Name, patternIds), (option_40 != null) ? tryFind(option_40, bound) : undefined), value_59), env_9);
1596
+ }, bound, declaration_6.Bindings);
1410
1597
  break;
1411
1598
  }
1412
1599
  case 5: {
1413
- evaluate(environment)(matchValue_29.fields[0]);
1600
+ evaluate(environment)(matchValue_34.fields[0]);
1414
1601
  break;
1415
1602
  }
1416
1603
  default:
@@ -1419,45 +1606,58 @@ export function analyze(registration, options, program) {
1419
1606
  }
1420
1607
  }
1421
1608
  finally {
1422
- disposeSafe(enumerator_9);
1609
+ disposeSafe(enumerator_11);
1423
1610
  }
1424
- let enumerator_11 = getEnumerator(entryFunctions);
1611
+ const entryConsumers = toList_2(map_2((pair_3) => [pair_3[0], pair_3[1]], consumers));
1612
+ let enumerator_13 = getEnumerator(entryFunctions);
1425
1613
  try {
1426
- while (enumerator_11["System.Collections.IEnumerator.MoveNext"]()) {
1427
- const forLoopVar_6 = enumerator_11["System.Collections.Generic.IEnumerator`1.get_Current"]();
1428
- const span_3 = forLoopVar_6[2];
1614
+ while (enumerator_13["System.Collections.IEnumerator.MoveNext"]()) {
1615
+ const forLoopVar_7 = enumerator_13["System.Collections.Generic.IEnumerator`1.get_Current"]();
1616
+ const span_4 = forLoopVar_7[2];
1429
1617
  histories.clear();
1430
1618
  tasks.clear();
1431
1619
  activeCalls.clear();
1620
+ consumers.clear();
1432
1621
  task = 0;
1433
1622
  clock = ofList(singleton([0, 0]), {
1434
- Compare: (x_31, y_31) => (comparePrimitives(x_31, y_31) | 0),
1623
+ Compare: (x_38, y_38) => (comparePrimitives(x_38, y_38) | 0),
1435
1624
  });
1436
- const enter = (value_61_mut, typ_15_mut, index_4_mut) => {
1625
+ const enumerator_14 = getEnumerator(entryConsumers);
1626
+ try {
1627
+ while (enumerator_14["System.Collections.IEnumerator.MoveNext"]()) {
1628
+ const forLoopVar_8 = enumerator_14["System.Collections.Generic.IEnumerator`1.get_Current"]();
1629
+ const consumer_1 = forLoopVar_8[1];
1630
+ consumers.set(forLoopVar_8[0], new Consumer(consumer_1.Handler, consumer_1.State, clock));
1631
+ }
1632
+ }
1633
+ finally {
1634
+ disposeSafe(enumerator_14);
1635
+ }
1636
+ const enter = (value_65_mut, typ_16_mut, index_4_mut) => {
1437
1637
  enter:
1438
1638
  while (true) {
1439
- const value_61 = value_61_mut, typ_15 = typ_15_mut, index_4 = index_4_mut;
1440
- if (typ_15.tag === 11) {
1441
- const result_8 = typ_15.fields[1];
1442
- value_61_mut = apply(span_3)(result_8)(value_61)(unknown((("entry:" + int32ToString(index_4)) + ":") + int32ToString(span_3.Start.Line), typ_15.fields[0]));
1443
- typ_15_mut = result_8;
1639
+ const value_65 = value_65_mut, typ_16 = typ_16_mut, index_4 = index_4_mut;
1640
+ if (typ_16.tag === 11) {
1641
+ const result_9 = typ_16.fields[1];
1642
+ value_65_mut = apply(span_4)(result_9)(value_65)(unknown((("entry:" + int32ToString(index_4)) + ":") + int32ToString(span_4.Start.Line), typ_16.fields[0]));
1643
+ typ_16_mut = result_9;
1444
1644
  index_4_mut = (index_4 + 1);
1445
1645
  continue enter;
1446
1646
  }
1447
1647
  break;
1448
1648
  }
1449
1649
  };
1450
- enter(forLoopVar_6[0], forLoopVar_6[1], 0);
1650
+ enter(forLoopVar_7[0], forLoopVar_7[1], 0);
1451
1651
  }
1452
1652
  }
1453
1653
  finally {
1454
- disposeSafe(enumerator_11);
1654
+ disposeSafe(enumerator_13);
1455
1655
  }
1456
1656
  return toList_2(sortBy((diagnostic) => [diagnostic.Span.Start.File, diagnostic.Span.Start.Line, diagnostic.Span.Start.Column, diagnostic.Code, diagnostic.RelatedSpan.Start.Line], distinct_1(diagnostics, {
1457
1657
  Equals: equals,
1458
- GetHashCode: (x_32) => (safeHash(x_32) | 0),
1658
+ GetHashCode: (x_39) => (safeHash(x_39) | 0),
1459
1659
  }), {
1460
- Compare: (x_33, y_33) => (compareArrays(x_33, y_33) | 0),
1660
+ Compare: (x_40, y_40) => (compareArrays(x_40, y_40) | 0),
1461
1661
  }));
1462
1662
  }
1463
1663