@magnusopera/fscript 0.93.0 → 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
9
  import { Type, Types_expand, Type_$reflection } from "./Types.js";
9
- import { filter as filter_1, toList as toList_1, forAll, fold as fold_1, add, toSeq, map as map_1, 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";
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_2 } 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) {
@@ -187,28 +223,33 @@ export function analyze(registration, options, program) {
187
223
  }, program.Symbols)), {
188
224
  Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
189
225
  }));
190
- 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
+ });
191
231
  if (!FSharpSet__get_IsEmpty(invalid)) {
192
- 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)));
193
233
  }
194
234
  const safeTypes = union(options.ThreadSafeTypes, program.Purity.PureTypes);
195
235
  const safeFunctions = union(options.ThreadSafeFunctions, program.Purity.PureFunctions);
196
236
  const diagnostics = [];
197
237
  const reported = new HashSet([], {
198
238
  Equals: equalArrays,
199
- GetHashCode: (x_8) => (arrayHash(x_8) | 0),
239
+ GetHashCode: (x_10) => (arrayHash(x_10) | 0),
200
240
  });
201
241
  const histories = new Dictionary([], {
202
242
  Equals: equals,
203
- GetHashCode: (x_9) => (safeHash(x_9) | 0),
243
+ GetHashCode: (x_11) => (safeHash(x_11) | 0),
204
244
  });
205
245
  const tasks = new Map([]);
246
+ const consumers = new Map([]);
206
247
  const activeCalls = new Set([]);
207
248
  let callSites = empty_3();
208
249
  let nextTask = 0;
209
250
  let task = 0;
210
251
  let clock = ofList(singleton([0, 0]), {
211
- Compare: (x_10, y_10) => (comparePrimitives(x_10, y_10) | 0),
252
+ Compare: (x_12, y_12) => (comparePrimitives(x_12, y_12) | 0),
212
253
  });
213
254
  const tick = () => {
214
255
  clock = add(task, 1 + defaultArg(tryFind(task, clock), 0), clock);
@@ -264,194 +305,187 @@ export function analyze(registration, options, program) {
264
305
  disposeSafe(enumerator);
265
306
  }
266
307
  };
267
- const fromType = (source_2_mut, visited_mut, typ_mut) => {
268
- fromType:
269
- while (true) {
270
- const source_2 = source_2_mut, visited = visited_mut, typ = typ_mut;
271
- let list_9, f2, mapping_10, f2_1, f2_2, mapping_13;
272
- const nested = (typ_1) => fromType(source_2, visited, typ_1);
273
- let matchResult, name_3, applied_1, name_4, name_5, typ_3, typ_4, typ_5, types, fields_1, cases_2, key_3, value_8;
274
- switch (typ.tag) {
275
- case 19: {
276
- if (!contains(typ.fields[0], safeTypes)) {
277
- matchResult = 0;
278
- name_3 = typ.fields[0];
279
- }
280
- else {
281
- matchResult = 10;
282
- }
283
- break;
284
- }
285
- case 13: {
286
- if (!contains(typ, visited)) {
287
- matchResult = 1;
288
- applied_1 = typ;
289
- name_4 = typ.fields[0];
290
- }
291
- else {
292
- matchResult = 10;
293
- }
294
- break;
295
- }
296
- case 12: {
297
- if (!contains(typ, visited)) {
298
- matchResult = 2;
299
- name_5 = typ.fields[0];
300
- }
301
- else {
302
- matchResult = 10;
303
- }
304
- break;
305
- }
306
- case 5: {
307
- matchResult = 3;
308
- typ_3 = typ.fields[0];
309
- break;
310
- }
311
- case 10: {
312
- matchResult = 4;
313
- typ_4 = typ.fields[0];
314
- break;
315
- }
316
- case 6: {
317
- matchResult = 5;
318
- typ_5 = typ.fields[0];
319
- break;
320
- }
321
- case 7: {
322
- matchResult = 6;
323
- types = typ.fields[0];
324
- break;
308
+ const fromType = (source_2, visited, typ) => {
309
+ let list_9, f2, mapping_10, f2_1, f2_2, mapping_13;
310
+ const nested = (typ_1) => fromType(source_2, visited, typ_1);
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;
312
+ switch (typ.tag) {
313
+ case 19: {
314
+ if (!contains(typ.fields[0], safeTypes)) {
315
+ matchResult = 0;
316
+ name_2 = typ.fields[0];
325
317
  }
326
- case 8: {
327
- matchResult = 7;
328
- fields_1 = typ.fields[0];
329
- break;
318
+ else {
319
+ matchResult = 10;
330
320
  }
331
- case 20: {
332
- matchResult = 7;
333
- fields_1 = typ.fields[1];
334
- break;
321
+ break;
322
+ }
323
+ case 13: {
324
+ if (!contains(typ, visited)) {
325
+ matchResult = 1;
326
+ applied_1 = typ;
327
+ arguments$_1 = typ.fields[1];
335
328
  }
336
- case 15: {
337
- matchResult = 8;
338
- cases_2 = typ.fields[1];
339
- break;
329
+ else {
330
+ matchResult = 10;
340
331
  }
341
- case 9: {
342
- matchResult = 9;
343
- key_3 = typ.fields[0];
344
- value_8 = typ.fields[1];
345
- break;
332
+ break;
333
+ }
334
+ case 12: {
335
+ if (!contains(typ, visited)) {
336
+ matchResult = 2;
337
+ name_3 = typ.fields[0];
346
338
  }
347
- default:
339
+ else {
348
340
  matchResult = 10;
349
- }
350
- switch (matchResult) {
351
- case 0:
352
- return new AbstractValue(singleton_1(new Resource((source_2 + ":") + name_3, name_3, false), {
353
- Compare: (x_11, y_11) => (compare(x_11, y_11) | 0),
354
- }), empty.Fields, empty.Callables, empty.Tasks, empty.Count);
355
- case 1: {
356
- source_2_mut = source_2;
357
- visited_mut = add_1(typ, visited);
358
- typ_mut = Types_expand(typeDefinitions, applied_1);
359
- continue fromType;
360
341
  }
361
- case 2: {
362
- const matchValue_2 = tryFind(name_5, hostTypes);
363
- let matchResult_1, descriptor_1;
364
- if (matchValue_2 != null) {
365
- if (!contains(name_5, safeTypes)) {
366
- matchResult_1 = 0;
367
- descriptor_1 = matchValue_2;
368
- }
369
- else if (contains(name_5, safeTypes)) {
370
- matchResult_1 = 1;
371
- }
372
- else {
373
- matchResult_1 = 2;
374
- }
342
+ break;
343
+ }
344
+ case 5: {
345
+ matchResult = 3;
346
+ typ_3 = typ.fields[0];
347
+ break;
348
+ }
349
+ case 10: {
350
+ matchResult = 4;
351
+ typ_4 = typ.fields[0];
352
+ break;
353
+ }
354
+ case 6: {
355
+ matchResult = 5;
356
+ typ_5 = typ.fields[0];
357
+ break;
358
+ }
359
+ case 7: {
360
+ matchResult = 6;
361
+ types = typ.fields[0];
362
+ break;
363
+ }
364
+ case 8: {
365
+ matchResult = 7;
366
+ fields_1 = typ.fields[0];
367
+ break;
368
+ }
369
+ case 20: {
370
+ matchResult = 7;
371
+ fields_1 = typ.fields[1];
372
+ break;
373
+ }
374
+ case 15: {
375
+ matchResult = 8;
376
+ cases_2 = typ.fields[1];
377
+ break;
378
+ }
379
+ case 9: {
380
+ matchResult = 9;
381
+ key_3 = typ.fields[0];
382
+ value_8 = typ.fields[1];
383
+ break;
384
+ }
385
+ default:
386
+ matchResult = 10;
387
+ }
388
+ switch (matchResult) {
389
+ case 0:
390
+ return new AbstractValue(singleton_1(new Resource((source_2 + ":") + name_2, name_2, false), {
391
+ Compare: (x_13, y_13) => (compare(x_13, y_13) | 0),
392
+ }), empty.Fields, empty.Callables, empty.Tasks, empty.Consumers, empty.Count);
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: {
398
+ const matchValue_2 = tryFind(name_3, hostTypes);
399
+ let matchResult_1, descriptor_1;
400
+ if (matchValue_2 != null) {
401
+ if (!contains(name_3, safeTypes)) {
402
+ matchResult_1 = 0;
403
+ descriptor_1 = matchValue_2;
375
404
  }
376
- else if (contains(name_5, safeTypes)) {
405
+ else if (contains(name_3, safeTypes)) {
377
406
  matchResult_1 = 1;
378
407
  }
379
408
  else {
380
409
  matchResult_1 = 2;
381
410
  }
382
- switch (matchResult_1) {
383
- case 0: {
384
- const value_7 = new AbstractValue(singleton_1(new Resource((source_2 + ":") + name_5, name_5, false), {
385
- Compare: (x_12, y_12) => (compare(x_12, y_12) | 0),
386
- }), empty.Fields, empty.Callables, empty.Tasks, empty.Count);
387
- if (descriptor_1.HostManaged) {
388
- return value_7;
389
- }
390
- else {
391
- return combine(cons(value_7, map((tupledArg) => {
392
- const typ_2 = tupledArg[1];
393
- return fromType(source_2, add_1(typ_2, visited), typ_2);
394
- }, toList_1(descriptor_1.Fields))));
395
- }
411
+ }
412
+ else if (contains(name_3, safeTypes)) {
413
+ matchResult_1 = 1;
414
+ }
415
+ else {
416
+ matchResult_1 = 2;
417
+ }
418
+ switch (matchResult_1) {
419
+ case 0: {
420
+ const value_7 = new AbstractValue(singleton_1(new Resource((source_2 + ":") + name_3, name_3, false), {
421
+ Compare: (x_14, y_14) => (compare(x_14, y_14) | 0),
422
+ }), empty.Fields, empty.Callables, empty.Tasks, empty.Consumers, empty.Count);
423
+ if (descriptor_1.HostManaged) {
424
+ return value_7;
396
425
  }
397
- case 1:
398
- return empty;
399
- default: {
400
- const visited_1 = add_1(typ, visited);
401
- const matchValue_3 = tryFind(name_5, hostUnions);
402
- const matchValue_4 = tryFind(name_5, declaredTypes);
403
- if (matchValue_3 != null) {
404
- return combine((list_9 = toList_1(matchValue_3), choose((f2 = ((mapping_10 = curry3(fromType)(source_2)(visited_1), (option_4) => {
405
- const option_5 = option_4;
406
- return (option_5 != null) ? mapping_10(option_5) : undefined;
407
- })), (arg) => f2(arg[1])), list_9)));
408
- }
409
- else if (matchValue_4 != null) {
410
- const declaration_2 = matchValue_4;
411
- return combine(append(map((f2_1 = curry3(fromType)(source_2)(visited_1), (arg_1) => f2_1(arg_1[1])), declaration_2.Fields), choose((f2_2 = ((mapping_13 = curry3(fromType)(source_2)(visited_1), (option_6) => {
412
- const option_7 = option_6;
413
- return (option_7 != null) ? mapping_13(option_7) : undefined;
414
- })), (arg_2) => f2_2(arg_2[1])), declaration_2.Cases)));
415
- }
416
- else {
417
- return empty;
418
- }
426
+ else {
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))));
419
431
  }
420
432
  }
421
- }
422
- case 3:
423
- return container("$items", undefined, nested(typ_3));
424
- case 4:
425
- return container("$value", undefined, nested(typ_4));
426
- case 5:
427
- return nested(typ_5);
428
- case 6:
429
- return combine(map(nested, types));
430
- case 7: {
431
- const values_4 = map_1((_arg_4, typ_6) => nested(typ_6), fields_1);
432
- const bind$0040 = combine(map((tuple_5) => tuple_5[1], toList_1(values_4)));
433
- return new AbstractValue(bind$0040.Resources, values_4, bind$0040.Callables, bind$0040.Tasks, bind$0040.Count);
434
- }
435
- case 8:
436
- return combine(choose((arg_3) => {
437
- const option_9 = arg_3[1];
438
- if (option_9 != null) {
439
- return nested(option_9);
433
+ case 1:
434
+ return empty;
435
+ default: {
436
+ const visited_2 = add_1(typ, visited);
437
+ const matchValue_3 = tryFind(name_3, hostUnions);
438
+ const matchValue_4 = tryFind(name_3, declaredTypes);
439
+ if (matchValue_3 != null) {
440
+ return combine((list_9 = toList_1(matchValue_3), choose((f2 = ((mapping_10 = curry3(fromType)(source_2)(visited_2), (option_4) => {
441
+ const option_5 = option_4;
442
+ return (option_5 != null) ? mapping_10(option_5) : undefined;
443
+ })), (arg) => f2(arg[1])), list_9)));
444
+ }
445
+ else if (matchValue_4 != null) {
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) => {
448
+ const option_7 = option_6;
449
+ return (option_7 != null) ? mapping_13(option_7) : undefined;
450
+ })), (arg_2) => f2_2(arg_2[1])), declaration_2.Cases)));
440
451
  }
441
452
  else {
442
- return undefined;
453
+ return empty;
443
454
  }
444
- }, toList_1(cases_2)));
445
- case 9:
446
- return combine(ofArray([nested(key_3), nested(value_8)]));
447
- default:
448
- return empty;
455
+ }
456
+ }
449
457
  }
450
- break;
458
+ case 3:
459
+ return container("$items", undefined, nested(typ_3));
460
+ case 4:
461
+ return container("$value", undefined, nested(typ_4));
462
+ case 5:
463
+ return nested(typ_5);
464
+ case 6:
465
+ return combine(map(nested, types));
466
+ case 7: {
467
+ const values_4 = map_1((_arg_4, typ_6) => nested(typ_6), fields_1);
468
+ const bind$0040 = combine(map((tuple_5) => tuple_5[1], toList_1(values_4)));
469
+ return new AbstractValue(bind$0040.Resources, values_4, bind$0040.Callables, bind$0040.Tasks, bind$0040.Consumers, bind$0040.Count);
470
+ }
471
+ case 8:
472
+ return combine(choose((arg_3) => {
473
+ const option_9 = arg_3[1];
474
+ if (option_9 != null) {
475
+ return nested(option_9);
476
+ }
477
+ else {
478
+ return undefined;
479
+ }
480
+ }, toList_1(cases_2)));
481
+ case 9:
482
+ return combine(ofArray([nested(key_3), nested(value_8)]));
483
+ default:
484
+ return empty;
451
485
  }
452
486
  };
453
487
  const unknown = (source_3, typ_7) => fromType(source_3, empty_1({
454
- Compare: (x_13, y_13) => (compare(x_13, y_13) | 0),
488
+ Compare: (x_15, y_15) => (compare(x_15, y_15) | 0),
455
489
  }), typ_7);
456
490
  const references = (expression) => delay(() => {
457
491
  let matchValue_6;
@@ -561,7 +595,7 @@ export function analyze(registration, options, program) {
561
595
  }
562
596
  };
563
597
  const count = defaultArg(tryFind(reference_1.Name, functions), arity(reference_1.Type)) | 0;
564
- 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);
565
599
  return (count === 0) ? invokeFunction(expression_1.Span)(expression_1.Type)(reference_1.Name)(equals(reference_1.Kind, ResolvedSymbolKind.ExternSymbol))(empty_3()) : value_13;
566
600
  }
567
601
  else {
@@ -576,7 +610,7 @@ export function analyze(registration, options, program) {
576
610
  const binding = matchValue_9.fields[0];
577
611
  const body = matchValue_9.fields[1];
578
612
  const capturedIds = ofSeq(references(body), {
579
- Compare: (x_14, y_14) => (comparePrimitives(x_14, y_14) | 0),
613
+ Compare: (x_16, y_16) => (comparePrimitives(x_16, y_16) | 0),
580
614
  });
581
615
  const captured = fold_2((state_2, id) => {
582
616
  const matchValue_7 = tryFind(id, env_7);
@@ -587,10 +621,10 @@ export function analyze(registration, options, program) {
587
621
  return add(id, matchValue_7, state_2);
588
622
  }
589
623
  }, empty_2({
590
- Compare: (x_15, y_15) => (comparePrimitives(x_15, y_15) | 0),
624
+ Compare: (x_17, y_17) => (comparePrimitives(x_17, y_17) | 0),
591
625
  }), capturedIds);
592
626
  const captures = combine(map((tuple_7) => tuple_7[1], toList_1(captured)));
593
- 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);
594
628
  }
595
629
  case 3:
596
630
  return apply(expression_1.Span)(expression_1.Type)(eval$(matchValue_9.fields[0]))(eval$(matchValue_9.fields[1]));
@@ -693,27 +727,27 @@ export function analyze(registration, options, program) {
693
727
  }, matchValue_9.fields[0])));
694
728
  case 7: {
695
729
  const fields_3 = ofList(mapIndexed((index_2, value_26) => [int32ToString(index_2), eval$(value_26)], matchValue_9.fields[0]), {
696
- Compare: (x_17, y_17) => (comparePrimitives(x_17, y_17) | 0),
730
+ Compare: (x_19, y_19) => (comparePrimitives(x_19, y_19) | 0),
697
731
  });
698
732
  const bind$0040_1 = combine(map((tuple_9) => tuple_9[1], toList_1(fields_3)));
699
733
  return new AbstractValue(bind$0040_1.Resources, fields_3, empty_3(), empty_1({
700
- Compare: (x_18, y_18) => (comparePrimitives(x_18, y_18) | 0),
701
- }), 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);
702
736
  }
703
737
  case 9: {
704
738
  const fields_4 = ofList(map((tupledArg_5) => [tupledArg_5[0], eval$(tupledArg_5[1])], matchValue_9.fields[0]), {
705
- Compare: (x_19, y_19) => (comparePrimitives(x_19, y_19) | 0),
739
+ Compare: (x_21, y_21) => (comparePrimitives(x_21, y_21) | 0),
706
740
  });
707
741
  const bind$0040_2 = combine(map((tuple_10) => tuple_10[1], toList_1(fields_4)));
708
742
  return new AbstractValue(bind$0040_2.Resources, fields_4, empty_3(), empty_1({
709
- Compare: (x_20, y_20) => (comparePrimitives(x_20, y_20) | 0),
710
- }), 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);
711
745
  }
712
746
  case 10: {
713
- const name_8 = matchValue_9.fields[1];
747
+ const name_6 = matchValue_9.fields[1];
714
748
  const value_28 = eval$(matchValue_9.fields[0]);
715
749
  access(expression_1.Span, value_28.Resources);
716
- const matchValue_19 = tryFind(name_8, value_28.Fields);
750
+ const matchValue_19 = tryFind(name_6, value_28.Fields);
717
751
  if (matchValue_19 == null) {
718
752
  const matchValue_20 = expression_1.Type;
719
753
  switch (matchValue_20.tag) {
@@ -725,7 +759,7 @@ export function analyze(registration, options, program) {
725
759
  case 16:
726
760
  return empty;
727
761
  default:
728
- return combine(ofArray([value_28, unknown("field:" + name_8, expression_1.Type)]));
762
+ return combine(ofArray([value_28, unknown("field:" + name_6, expression_1.Type)]));
729
763
  }
730
764
  }
731
765
  else {
@@ -738,8 +772,8 @@ export function analyze(registration, options, program) {
738
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]);
739
773
  const bind$0040_3 = combine(cons(target_4, map((tuple_11) => tuple_11[1], toList_1(fields_6))));
740
774
  return new AbstractValue(bind$0040_3.Resources, fields_6, empty_3(), empty_1({
741
- Compare: (x_21, y_21) => (comparePrimitives(x_21, y_21) | 0),
742
- }), 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);
743
777
  }
744
778
  case 6: {
745
779
  const arg_9 = combine(map(eval$, matchValue_9.fields[1])).Resources;
@@ -780,6 +814,8 @@ export function analyze(registration, options, program) {
780
814
  });
781
815
  const branches = (alternatives) => {
782
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();
783
819
  const clock_1 = clock;
784
820
  const matchValue_21 = snapshot();
785
821
  const results = map((branch) => {
@@ -795,97 +831,116 @@ export function analyze(registration, options, program) {
795
831
  finally {
796
832
  disposeSafe(enumerator_3);
797
833
  }
798
- 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()];
799
846
  }, alternatives);
800
847
  histories.clear();
801
- const enumerator_4 = getEnumerator(results);
848
+ const enumerator_5 = getEnumerator(results);
802
849
  try {
803
- while (enumerator_4["System.Collections.IEnumerator.MoveNext"]()) {
804
- 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]);
805
852
  try {
806
- while (enumerator_5["System.Collections.IEnumerator.MoveNext"]()) {
807
- const forLoopVar_4 = enumerator_5["System.Collections.Generic.IEnumerator`1.get_Current"]();
808
- const values_14 = forLoopVar_4[1];
809
- 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];
810
857
  let matchValue_22;
811
858
  const cell_1 = new FSharpRef(defaultOf());
812
- matchValue_22 = [tryGetValue(histories, key_9, cell_1), cell_1.contents];
859
+ matchValue_22 = [tryGetValue(histories, key_10, cell_1), cell_1.contents];
813
860
  if (matchValue_22[0]) {
814
- addRangeInPlace(values_14, matchValue_22[1]);
861
+ addRangeInPlace(values_15, matchValue_22[1]);
815
862
  }
816
863
  else {
817
- histories.set(key_9, Array.from(values_14));
864
+ histories.set(key_10, Array.from(values_15));
818
865
  }
819
866
  }
820
867
  }
821
868
  finally {
822
- disposeSafe(enumerator_5);
869
+ disposeSafe(enumerator_6);
823
870
  }
824
871
  }
825
872
  }
826
873
  finally {
827
- disposeSafe(enumerator_4);
874
+ disposeSafe(enumerator_5);
828
875
  }
829
- let enumerator_6 = getEnumerator(histories);
876
+ let enumerator_7 = getEnumerator(histories);
830
877
  try {
831
- while (enumerator_6["System.Collections.IEnumerator.MoveNext"]()) {
832
- const pair_1 = enumerator_6["System.Collections.Generic.IEnumerator`1.get_Current"]();
833
- 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], {
834
881
  Equals: equalArrays,
835
- GetHashCode: (x_22) => (arrayHash(x_22) | 0),
882
+ GetHashCode: (x_24) => (arrayHash(x_24) | 0),
836
883
  }));
837
- clear(pair_1[1]);
838
- addRangeInPlace(distinct, pair_1[1]);
884
+ clear(pair_2[1]);
885
+ addRangeInPlace(distinct, pair_2[1]);
839
886
  }
840
887
  }
841
888
  finally {
842
- disposeSafe(enumerator_6);
889
+ disposeSafe(enumerator_7);
843
890
  }
844
891
  clock = commonClock(map((tupledArg_7) => tupledArg_7[1], results));
845
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;
846
893
  clock = add(task, ownTime, clock);
847
- 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));
848
903
  };
849
- const wireRecursive = (env_8) => ((values_16) => {
850
- const enumerator_7 = getEnumerator(values_16);
904
+ const wireRecursive = (env_8) => ((values_20) => {
905
+ const enumerator_8 = getEnumerator(values_20);
851
906
  try {
852
- while (enumerator_7["System.Collections.IEnumerator.MoveNext"]()) {
853
- 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);
854
909
  try {
855
- while (enumerator_8["System.Collections.IEnumerator.MoveNext"]()) {
856
- 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"]();
857
912
  if (callable.tag === 0) {
858
913
  const ids = ofSeq(references(callable.fields[2]), {
859
- Compare: (x_23, y_23) => (comparePrimitives(x_23, y_23) | 0),
914
+ Compare: (x_26, y_26) => (comparePrimitives(x_26, y_26) | 0),
860
915
  });
861
- callable.fields[3].contents = filter_1((id_2, _arg_13) => contains(id_2, ids), env_8);
916
+ callable.fields[3].contents = filter_1((id_3, _arg_21) => contains(id_3, ids), env_8);
862
917
  }
863
918
  }
864
919
  }
865
920
  finally {
866
- disposeSafe(enumerator_8);
921
+ disposeSafe(enumerator_9);
867
922
  }
868
923
  }
869
924
  }
870
925
  finally {
871
- disposeSafe(enumerator_7);
926
+ disposeSafe(enumerator_8);
872
927
  }
873
928
  });
874
929
  const apply = (span_1) => ((resultType) => ((fn_4) => ((argument_4) => {
875
930
  if (isEmpty(fn_4.Callables)) {
876
- const arg_13 = union(fn_4.Resources, argument_4.Resources);
877
- access(span_1, arg_13);
931
+ const arg_14 = union(fn_4.Resources, argument_4.Resources);
932
+ access(span_1, arg_14);
878
933
  return combine(ofArray([fn_4, argument_4, unknown("unknown-call", resultType)]));
879
934
  }
880
935
  else {
881
- const invoke = (_arg_14) => {
882
- if (_arg_14.tag === 1) {
883
- const signature = _arg_14.fields[3];
884
- const name_10 = _arg_14.fields[0];
885
- const external = _arg_14.fields[2];
886
- const arity_1 = _arg_14.fields[1] | 0;
887
- const arguments$_1 = append(_arg_14.fields[4], singleton(argument_4));
888
- 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) {
889
944
  const returned = (count_2_mut, typ_8_mut) => {
890
945
  returned:
891
946
  while (true) {
@@ -904,33 +959,33 @@ export function analyze(registration, options, program) {
904
959
  break;
905
960
  }
906
961
  };
907
- return invokeFunction(span_1)(returned(arity_1, signature))(name_10)(external)(arguments$_1);
962
+ return invokeFunction(span_1)(returned(arity_1, signature))(name_8)(external)(arguments$_3);
908
963
  }
909
964
  else {
910
- const bind$0040_4 = combine(arguments$_1);
911
- return new AbstractValue(bind$0040_4.Resources, bind$0040_4.Fields, singleton(new Callable(/* Function */ 1, [name_10, 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);
912
967
  }
913
968
  }
914
969
  else {
915
- const id_3 = _arg_14.fields[0] | 0;
916
- if (addToSet(id_3, activeCalls)) {
970
+ const id_4 = _arg_22.fields[0] | 0;
971
+ if (addToSet(id_4, activeCalls)) {
917
972
  const previous_2 = callSites;
918
973
  callSites = cons(span_1, previous_2);
919
974
  try {
920
- return evaluate(add(_arg_14.fields[1].SymbolId, argument_4, _arg_14.fields[3].contents))(_arg_14.fields[2]);
975
+ return evaluate(add(_arg_22.fields[1].SymbolId, argument_4, _arg_22.fields[3].contents))(_arg_22.fields[2]);
921
976
  }
922
977
  finally {
923
978
  callSites = previous_2;
924
- activeCalls.delete(id_3);
979
+ activeCalls.delete(id_4);
925
980
  }
926
981
  }
927
982
  else {
928
- 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)]));
929
984
  }
930
985
  }
931
986
  };
932
987
  const matchValue_24 = fn_4.Callables;
933
- let matchResult_4, only, alternatives_1;
988
+ let matchResult_4, only, alternatives_2;
934
989
  if (!isEmpty(matchValue_24)) {
935
990
  if (isEmpty(tail_2(matchValue_24))) {
936
991
  matchResult_4 = 0;
@@ -938,49 +993,155 @@ export function analyze(registration, options, program) {
938
993
  }
939
994
  else {
940
995
  matchResult_4 = 1;
941
- alternatives_1 = matchValue_24;
996
+ alternatives_2 = matchValue_24;
942
997
  }
943
998
  }
944
999
  else {
945
1000
  matchResult_4 = 1;
946
- alternatives_1 = matchValue_24;
1001
+ alternatives_2 = matchValue_24;
947
1002
  }
948
1003
  switch (matchResult_4) {
949
1004
  case 0:
950
1005
  return invoke(only);
951
1006
  default:
952
- return branches(map((callable_1) => (() => invoke(callable_1)), alternatives_1));
1007
+ return branches(map((callable_1) => (() => invoke(callable_1)), alternatives_2));
953
1008
  }
954
1009
  }
955
1010
  })));
956
- const invokeFunction = (span_2) => ((resultType_1) => ((name_11) => ((external_1) => ((arguments$_2) => {
957
- let option_27;
958
- const completed = (value_40) => choose((id_4) => {
959
- let matchValue_25;
960
- const cell_2 = new FSharpRef(defaultOf());
961
- matchValue_25 = [tryGetValue(tasks, id_4, cell_2), cell_2.contents];
962
- if (matchValue_25[0]) {
963
- 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];
964
1125
  }
965
1126
  else {
966
1127
  return undefined;
967
1128
  }
968
- }, toList(value_40.Tasks));
969
- const join = (completions) => {
970
- let list_41;
971
- if (!isEmpty(completions)) {
972
- clock = mergeClock(clock, (list_41 = map((tuple_12) => tuple_12[0], completions), fold(mergeClock, empty_2({
973
- Compare: (x_24, y_24) => (comparePrimitives(x_24, y_24) | 0),
974
- }), 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)));
975
1136
  }
976
1137
  tick();
977
1138
  };
978
- const ready = (value_41) => {
1139
+ const ready = (value_45) => {
979
1140
  nextTask = ((nextTask + 1) | 0);
980
- tasks.set(nextTask, [clock, value_41]);
1141
+ tasks.set(nextTask, [clock, value_45]);
981
1142
  return new AbstractValue(empty.Resources, empty.Fields, empty.Callables, singleton_1(nextTask, {
982
- Compare: (x_25, y_25) => (comparePrimitives(x_25, y_25) | 0),
983
- }), empty.Count);
1143
+ Compare: (x_32, y_32) => (comparePrimitives(x_32, y_32) | 0),
1144
+ }), empty.Consumers, empty.Count);
984
1145
  };
985
1146
  const fork = (callback, run) => {
986
1147
  const task_1 = task | 0;
@@ -991,25 +1152,25 @@ export function analyze(registration, options, program) {
991
1152
  const child_1 = nextTask | 0;
992
1153
  task = (child_1 | 0);
993
1154
  clock = add(child_1, 0, forkClock);
994
- const result_2 = run((argument_5) => {
995
- access(defaultArg(tryHead(callSites), span_2), callback.Resources);
996
- 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);
997
1158
  });
998
- tasks.set(child_1, [clock, result_2]);
1159
+ tasks.set(child_1, [clock, result_3]);
999
1160
  task = (task_1 | 0);
1000
1161
  clock = mergeClock(clock_3, forkClock);
1001
1162
  tick();
1002
1163
  return new AbstractValue(empty.Resources, empty.Fields, empty.Callables, singleton_1(child_1, {
1003
- Compare: (x_26, y_26) => (comparePrimitives(x_26, y_26) | 0),
1004
- }), empty.Count);
1164
+ Compare: (x_33, y_33) => (comparePrimitives(x_33, y_33) | 0),
1165
+ }), empty.Consumers, empty.Count);
1005
1166
  };
1006
- let matchResult_5, value_42, callback_1, value_43, callback_2, values_18, callback_3, values_20, values_21, thunk, value_45;
1007
- switch (name_11) {
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) {
1008
1169
  case "Task.fromResult": {
1009
- if (!isEmpty(arguments$_2)) {
1010
- if (isEmpty(tail_2(arguments$_2))) {
1170
+ if (!isEmpty(arguments$_5)) {
1171
+ if (isEmpty(tail_2(arguments$_5))) {
1011
1172
  matchResult_5 = 0;
1012
- value_42 = head(arguments$_2);
1173
+ value_46 = head(arguments$_5);
1013
1174
  }
1014
1175
  else {
1015
1176
  matchResult_5 = 8;
@@ -1021,8 +1182,8 @@ export function analyze(registration, options, program) {
1021
1182
  break;
1022
1183
  }
1023
1184
  case "Task.delay": {
1024
- if (!isEmpty(arguments$_2)) {
1025
- if (isEmpty(tail_2(arguments$_2))) {
1185
+ if (!isEmpty(arguments$_5)) {
1186
+ if (isEmpty(tail_2(arguments$_5))) {
1026
1187
  matchResult_5 = 1;
1027
1188
  }
1028
1189
  else {
@@ -1035,12 +1196,12 @@ export function analyze(registration, options, program) {
1035
1196
  break;
1036
1197
  }
1037
1198
  case "Task.continueWith": {
1038
- if (!isEmpty(arguments$_2)) {
1039
- if (!isEmpty(tail_2(arguments$_2))) {
1040
- 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)))) {
1041
1202
  matchResult_5 = 2;
1042
- callback_1 = head(arguments$_2);
1043
- value_43 = head(tail_2(arguments$_2));
1203
+ callback_1 = head(arguments$_5);
1204
+ value_47 = head(tail_2(arguments$_5));
1044
1205
  }
1045
1206
  else {
1046
1207
  matchResult_5 = 8;
@@ -1056,12 +1217,12 @@ export function analyze(registration, options, program) {
1056
1217
  break;
1057
1218
  }
1058
1219
  case "Task.whenAll": {
1059
- if (!isEmpty(arguments$_2)) {
1060
- if (!isEmpty(tail_2(arguments$_2))) {
1061
- 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)))) {
1062
1223
  matchResult_5 = 3;
1063
- callback_2 = head(arguments$_2);
1064
- values_18 = head(tail_2(arguments$_2));
1224
+ callback_2 = head(arguments$_5);
1225
+ values_23 = head(tail_2(arguments$_5));
1065
1226
  }
1066
1227
  else {
1067
1228
  matchResult_5 = 8;
@@ -1077,12 +1238,12 @@ export function analyze(registration, options, program) {
1077
1238
  break;
1078
1239
  }
1079
1240
  case "Task.whenAny": {
1080
- if (!isEmpty(arguments$_2)) {
1081
- if (!isEmpty(tail_2(arguments$_2))) {
1082
- 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)))) {
1083
1244
  matchResult_5 = 4;
1084
- callback_3 = head(arguments$_2);
1085
- values_20 = head(tail_2(arguments$_2));
1245
+ callback_3 = head(arguments$_5);
1246
+ values_25 = head(tail_2(arguments$_5));
1086
1247
  }
1087
1248
  else {
1088
1249
  matchResult_5 = 8;
@@ -1098,10 +1259,10 @@ export function analyze(registration, options, program) {
1098
1259
  break;
1099
1260
  }
1100
1261
  case "Task.awaitAll": {
1101
- if (!isEmpty(arguments$_2)) {
1102
- if (isEmpty(tail_2(arguments$_2))) {
1262
+ if (!isEmpty(arguments$_5)) {
1263
+ if (isEmpty(tail_2(arguments$_5))) {
1103
1264
  matchResult_5 = 5;
1104
- values_21 = head(arguments$_2);
1265
+ values_26 = head(arguments$_5);
1105
1266
  }
1106
1267
  else {
1107
1268
  matchResult_5 = 8;
@@ -1113,10 +1274,10 @@ export function analyze(registration, options, program) {
1113
1274
  break;
1114
1275
  }
1115
1276
  case "Task.spawn": {
1116
- if (!isEmpty(arguments$_2)) {
1117
- if (isEmpty(tail_2(arguments$_2))) {
1277
+ if (!isEmpty(arguments$_5)) {
1278
+ if (isEmpty(tail_2(arguments$_5))) {
1118
1279
  matchResult_5 = 6;
1119
- thunk = head(arguments$_2);
1280
+ thunk = head(arguments$_5);
1120
1281
  }
1121
1282
  else {
1122
1283
  matchResult_5 = 8;
@@ -1128,10 +1289,10 @@ export function analyze(registration, options, program) {
1128
1289
  break;
1129
1290
  }
1130
1291
  case "Task.await": {
1131
- if (!isEmpty(arguments$_2)) {
1132
- if (isEmpty(tail_2(arguments$_2))) {
1292
+ if (!isEmpty(arguments$_5)) {
1293
+ if (isEmpty(tail_2(arguments$_5))) {
1133
1294
  matchResult_5 = 7;
1134
- value_45 = head(arguments$_2);
1295
+ value_49 = head(arguments$_5);
1135
1296
  }
1136
1297
  else {
1137
1298
  matchResult_5 = 8;
@@ -1147,35 +1308,35 @@ export function analyze(registration, options, program) {
1147
1308
  }
1148
1309
  switch (matchResult_5) {
1149
1310
  case 0:
1150
- return ready(value_42);
1311
+ return ready(value_46);
1151
1312
  case 1:
1152
1313
  return ready(empty);
1153
1314
  case 2: {
1154
- const completions_1 = completed(value_43);
1315
+ const completions_2 = completed_1(value_47);
1155
1316
  return fork(callback_1, (invoke_1) => {
1156
- join(completions_1);
1157
- 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)));
1158
1319
  });
1159
1320
  }
1160
1321
  case 3: {
1161
- const completions_2 = completed(contents(values_18));
1322
+ const completions_3 = completed_1(contents(values_23));
1162
1323
  return fork(callback_2, (invoke_2) => {
1163
- join(completions_2);
1164
- 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))));
1165
1326
  });
1166
1327
  }
1167
1328
  case 4: {
1168
- const completions_3 = completed(contents(values_20));
1169
- return fork(callback_3, (invoke_3) => (isEmpty(completions_3) ? invoke_3(contents(values_20)) : branches(map((tupledArg_10) => (() => {
1170
- const value_44 = tupledArg_10[1];
1171
- join(singleton([tupledArg_10[0], value_44]));
1172
- return invoke_3(value_44);
1173
- }), 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))));
1174
1335
  }
1175
1336
  case 5: {
1176
- const completions_4 = completed(contents(values_21));
1177
- join(completions_4);
1178
- 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)));
1179
1340
  }
1180
1341
  case 6: {
1181
1342
  const task_2 = task | 0;
@@ -1186,65 +1347,65 @@ export function analyze(registration, options, program) {
1186
1347
  const child_2 = nextTask | 0;
1187
1348
  task = (child_2 | 0);
1188
1349
  clock = add(child_2, 0, forkClock_1);
1189
- access(defaultArg(tryHead(callSites), span_2), thunk.Resources);
1190
- const result_3 = apply(span_2)((resultType_1.tag === 6) ? resultType_1.fields[0] : Type.TUnit)(thunk)(empty);
1191
- 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]);
1192
1353
  task = (task_2 | 0);
1193
1354
  clock = mergeClock(clock_4, forkClock_1);
1194
1355
  tick();
1195
1356
  return new AbstractValue(empty.Resources, empty.Fields, empty.Callables, singleton_1(child_2, {
1196
- Compare: (x_27, y_27) => (comparePrimitives(x_27, y_27) | 0),
1197
- }), empty.Count);
1357
+ Compare: (x_34, y_34) => (comparePrimitives(x_34, y_34) | 0),
1358
+ }), empty.Consumers, empty.Count);
1198
1359
  }
1199
1360
  case 7: {
1200
- const completed_1 = choose((id_5) => {
1201
- let matchValue_27;
1202
- const cell_3 = new FSharpRef(defaultOf());
1203
- matchValue_27 = [tryGetValue(tasks, id_5, cell_3), cell_3.contents];
1204
- if (matchValue_27[0]) {
1205
- 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];
1206
1367
  }
1207
1368
  else {
1208
1369
  return undefined;
1209
1370
  }
1210
- }, toList(value_45.Tasks));
1211
- if (!isEmpty(completed_1)) {
1212
- 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)));
1213
1374
  }
1214
1375
  tick();
1215
- return combine(map((tuple_17) => tuple_17[1], completed_1));
1376
+ return combine(map((tuple_21) => tuple_21[1], completed_2));
1216
1377
  }
1217
1378
  default: {
1218
- const inputs_1 = combine(arguments$_2);
1219
- if (external_1 && !contains(name_11, safeFunctions)) {
1220
- const arg_19 = add_1(new Resource("function:" + name_11, name_11, true), inputs_1.Resources);
1221
- access(span_2, arg_19);
1222
- }
1223
- const parameterTypes = (_arg_15) => {
1224
- if (_arg_15.tag === 11) {
1225
- return cons(_arg_15.fields[0], parameterTypes(_arg_15.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]));
1226
1387
  }
1227
1388
  else {
1228
1389
  return empty_3();
1229
1390
  }
1230
1391
  };
1231
- const signature_1 = defaultArg((option_27 = tryFind(name_11, builtinSchemes), (option_27 != null) ? parameterTypes(option_27.fields[1]) : undefined), empty_3());
1232
- const items_1 = combine(map(contents, filter((value_47) => isEmpty(value_47.Callables), arguments$_2)));
1233
- const callbackResults = collect((tupledArg_11) => {
1234
- let option_30, option_33;
1235
- const callback_4 = tupledArg_11[1];
1236
- 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());
1237
1398
  if (isEmpty(callback_4.Callables) ? true : isEmpty(callbackParameters)) {
1238
1399
  return empty_3();
1239
1400
  }
1240
1401
  else {
1241
- const iterations = ((name_11.startsWith("List.") ? true : name_11.startsWith("Map.")) ? defaultArg((option_33 = tryPick((_arg_17) => _arg_17.Count, arguments$_2), (option_33 != null) ? min(2, option_33) : undefined), 2) : 1) | 0;
1242
- 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))));
1243
1404
  }
1244
- }, indexed(arguments$_2));
1245
- const result_6 = unknown("result:" + name_11, resultType_1);
1405
+ }, indexed(arguments$_5));
1406
+ const result_7 = unknown("result:" + name_10, resultType_3);
1246
1407
  let matchResult_6;
1247
- switch (resultType_1.tag) {
1408
+ switch (resultType_3.tag) {
1248
1409
  case 0:
1249
1410
  case 1:
1250
1411
  case 2:
@@ -1267,7 +1428,7 @@ export function analyze(registration, options, program) {
1267
1428
  break;
1268
1429
  }
1269
1430
  case 11: {
1270
- if (external_1) {
1431
+ if (external_2) {
1271
1432
  matchResult_6 = 4;
1272
1433
  }
1273
1434
  else {
@@ -1282,113 +1443,113 @@ export function analyze(registration, options, program) {
1282
1443
  case 0:
1283
1444
  return empty;
1284
1445
  case 1:
1285
- return container("$items", tryPick((_arg_18) => _arg_18.Count, arguments$_2), contains_1(name_11, ofArray(["List.map", "List.choose", "List.collect"]), {
1286
- Equals: (x_28, y_28) => (x_28 === y_28),
1287
- GetHashCode: (x_28) => (stringHash(x_28) | 0),
1288
- }) ? 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)])));
1289
1450
  case 2:
1290
- return container("$value", undefined, (name_11 === "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)])));
1291
1452
  case 3:
1292
- 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)));
1293
1454
  case 4: {
1294
- const arity_2 = (_arg_19) => {
1295
- if (_arg_19.tag === 11) {
1296
- return (1 + arity_2(_arg_19.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;
1297
1458
  }
1298
1459
  else {
1299
1460
  return 0;
1300
1461
  }
1301
1462
  };
1302
- const bind$0040_5 = combine(ofArray([result_6, inputs_1]));
1303
- return new AbstractValue(bind$0040_5.Resources, bind$0040_5.Fields, singleton(new Callable(/* Function */ 1, [name_11 + " (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);
1304
1465
  }
1305
1466
  default:
1306
- return combine(ofArrayWithTail([result_6, inputs_1], callbackResults));
1467
+ return combine(ofArrayWithTail([result_7, inputs_1], callbackResults));
1307
1468
  }
1308
1469
  }
1309
1470
  }
1310
1471
  }))));
1311
1472
  let environment = empty_2({
1312
- Compare: (x_29, y_29) => (comparePrimitives(x_29, y_29) | 0),
1473
+ Compare: (x_36, y_36) => (comparePrimitives(x_36, y_36) | 0),
1313
1474
  });
1314
1475
  const entryFunctions = [];
1315
- const remember = (binding_7, value_52) => {
1316
- environment = add(binding_7.SymbolId, value_52, environment);
1317
- if (!isEmpty(value_52.Callables)) {
1318
- 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]));
1319
1480
  }
1320
1481
  };
1321
- const enumerator_9 = getEnumerator(program.ResolvedStatements);
1482
+ const enumerator_11 = getEnumerator(program.ResolvedStatements);
1322
1483
  try {
1323
- while (enumerator_9["System.Collections.IEnumerator.MoveNext"]()) {
1324
- const matchValue_29 = enumerator_9["System.Collections.Generic.IEnumerator`1.get_Current"]().Node;
1325
- 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) {
1326
1487
  case 1: {
1327
- const declaration_3 = matchValue_29.fields[0];
1328
- const value_53 = evaluate(environment)(declaration_3.Value);
1329
- remember(declaration_3.Binding, 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);
1330
1491
  if (declaration_3.IsRecursive) {
1331
- wireRecursive(environment)(singleton(value_53));
1492
+ wireRecursive(environment)(singleton(value_57));
1332
1493
  }
1333
1494
  break;
1334
1495
  }
1335
1496
  case 3: {
1336
- const values_28 = map((declaration_4) => [declaration_4, evaluate(environment)(declaration_4.Value)], matchValue_29.fields[0]);
1337
- 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);
1338
1499
  try {
1339
- while (enumerator_10["System.Collections.IEnumerator.MoveNext"]()) {
1340
- const forLoopVar_5 = enumerator_10["System.Collections.Generic.IEnumerator`1.get_Current"]();
1341
- 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]);
1342
1503
  }
1343
1504
  }
1344
1505
  finally {
1345
- disposeSafe(enumerator_10);
1506
+ disposeSafe(enumerator_12);
1346
1507
  }
1347
- wireRecursive(environment)(map((tuple_18) => tuple_18[1], values_28));
1508
+ wireRecursive(environment)(map((tuple_22) => tuple_22[1], values_33));
1348
1509
  break;
1349
1510
  }
1350
1511
  case 2: {
1351
- const declaration_6 = matchValue_29.fields[0];
1352
- const value_55 = evaluate(environment)(declaration_6.Value);
1353
- const bound = bindPattern(environment, declaration_6.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);
1354
1515
  const bindings_1 = (pattern_6_mut) => {
1355
1516
  bindings_1:
1356
1517
  while (true) {
1357
1518
  const pattern_6 = pattern_6_mut;
1358
- let option_36;
1359
- const matchValue_30 = pattern_6.Node;
1519
+ let option_37;
1520
+ const matchValue_35 = pattern_6.Node;
1360
1521
  let matchResult_7, binding_8, patterns_1, fields_7, a_2, b_2, item_4, entries_2, tail_1;
1361
- switch (matchValue_30.tag) {
1522
+ switch (matchValue_35.tag) {
1362
1523
  case 1: {
1363
1524
  matchResult_7 = 0;
1364
- binding_8 = matchValue_30.fields[0];
1525
+ binding_8 = matchValue_35.fields[0];
1365
1526
  break;
1366
1527
  }
1367
1528
  case 5: {
1368
1529
  matchResult_7 = 1;
1369
- patterns_1 = matchValue_30.fields[0];
1530
+ patterns_1 = matchValue_35.fields[0];
1370
1531
  break;
1371
1532
  }
1372
1533
  case 6: {
1373
1534
  matchResult_7 = 2;
1374
- fields_7 = matchValue_30.fields[0];
1535
+ fields_7 = matchValue_35.fields[0];
1375
1536
  break;
1376
1537
  }
1377
1538
  case 4: {
1378
1539
  matchResult_7 = 3;
1379
- a_2 = matchValue_30.fields[0];
1380
- b_2 = matchValue_30.fields[1];
1540
+ a_2 = matchValue_35.fields[0];
1541
+ b_2 = matchValue_35.fields[1];
1381
1542
  break;
1382
1543
  }
1383
1544
  case 8: {
1384
1545
  matchResult_7 = 4;
1385
- item_4 = matchValue_30.fields[0];
1546
+ item_4 = matchValue_35.fields[0];
1386
1547
  break;
1387
1548
  }
1388
1549
  case 10: {
1389
- if (matchValue_30.fields[2] != null) {
1550
+ if (matchValue_35.fields[2] != null) {
1390
1551
  matchResult_7 = 4;
1391
- item_4 = matchValue_30.fields[2];
1552
+ item_4 = matchValue_35.fields[2];
1392
1553
  }
1393
1554
  else {
1394
1555
  matchResult_7 = 6;
@@ -1397,8 +1558,8 @@ export function analyze(registration, options, program) {
1397
1558
  }
1398
1559
  case 7: {
1399
1560
  matchResult_7 = 5;
1400
- entries_2 = matchValue_30.fields[0];
1401
- tail_1 = matchValue_30.fields[1];
1561
+ entries_2 = matchValue_35.fields[0];
1562
+ tail_1 = matchValue_35.fields[1];
1402
1563
  break;
1403
1564
  }
1404
1565
  default:
@@ -1410,7 +1571,7 @@ export function analyze(registration, options, program) {
1410
1571
  case 1:
1411
1572
  return collect(bindings_1, patterns_1);
1412
1573
  case 2:
1413
- return collect((arg_20) => bindings_1(arg_20[1]), fields_7);
1574
+ return collect((arg_23) => bindings_1(arg_23[1]), fields_7);
1414
1575
  case 3:
1415
1576
  return append(bindings_1(a_2), bindings_1(b_2));
1416
1577
  case 4: {
@@ -1418,7 +1579,7 @@ export function analyze(registration, options, program) {
1418
1579
  continue bindings_1;
1419
1580
  }
1420
1581
  case 5:
1421
- 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()));
1422
1583
  default:
1423
1584
  return empty_3();
1424
1585
  }
@@ -1426,17 +1587,17 @@ export function analyze(registration, options, program) {
1426
1587
  }
1427
1588
  };
1428
1589
  const patternIds = ofList(map((binding_9) => [binding_9.Name, binding_9.SymbolId], bindings_1(declaration_6.Pattern)), {
1429
- Compare: (x_30, y_30) => (comparePrimitives(x_30, y_30) | 0),
1590
+ Compare: (x_37, y_37) => (comparePrimitives(x_37, y_37) | 0),
1430
1591
  });
1431
- environment = fold((env_9, tupledArg_13) => {
1432
- let option_39;
1433
- const binding_10 = tupledArg_13[0];
1434
- 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);
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);
1435
1596
  }, bound, declaration_6.Bindings);
1436
1597
  break;
1437
1598
  }
1438
1599
  case 5: {
1439
- evaluate(environment)(matchValue_29.fields[0]);
1600
+ evaluate(environment)(matchValue_34.fields[0]);
1440
1601
  break;
1441
1602
  }
1442
1603
  default:
@@ -1445,45 +1606,58 @@ export function analyze(registration, options, program) {
1445
1606
  }
1446
1607
  }
1447
1608
  finally {
1448
- disposeSafe(enumerator_9);
1609
+ disposeSafe(enumerator_11);
1449
1610
  }
1450
- 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);
1451
1613
  try {
1452
- while (enumerator_11["System.Collections.IEnumerator.MoveNext"]()) {
1453
- const forLoopVar_6 = enumerator_11["System.Collections.Generic.IEnumerator`1.get_Current"]();
1454
- 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];
1455
1617
  histories.clear();
1456
1618
  tasks.clear();
1457
1619
  activeCalls.clear();
1620
+ consumers.clear();
1458
1621
  task = 0;
1459
1622
  clock = ofList(singleton([0, 0]), {
1460
- Compare: (x_31, y_31) => (comparePrimitives(x_31, y_31) | 0),
1623
+ Compare: (x_38, y_38) => (comparePrimitives(x_38, y_38) | 0),
1461
1624
  });
1462
- 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) => {
1463
1637
  enter:
1464
1638
  while (true) {
1465
- const value_61 = value_61_mut, typ_15 = typ_15_mut, index_4 = index_4_mut;
1466
- if (typ_15.tag === 11) {
1467
- const result_8 = typ_15.fields[1];
1468
- value_61_mut = apply(span_3)(result_8)(value_61)(unknown((("entry:" + int32ToString(index_4)) + ":") + int32ToString(span_3.Start.Line), typ_15.fields[0]));
1469
- 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;
1470
1644
  index_4_mut = (index_4 + 1);
1471
1645
  continue enter;
1472
1646
  }
1473
1647
  break;
1474
1648
  }
1475
1649
  };
1476
- enter(forLoopVar_6[0], forLoopVar_6[1], 0);
1650
+ enter(forLoopVar_7[0], forLoopVar_7[1], 0);
1477
1651
  }
1478
1652
  }
1479
1653
  finally {
1480
- disposeSafe(enumerator_11);
1654
+ disposeSafe(enumerator_13);
1481
1655
  }
1482
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, {
1483
1657
  Equals: equals,
1484
- GetHashCode: (x_32) => (safeHash(x_32) | 0),
1658
+ GetHashCode: (x_39) => (safeHash(x_39) | 0),
1485
1659
  }), {
1486
- Compare: (x_33, y_33) => (compareArrays(x_33, y_33) | 0),
1660
+ Compare: (x_40, y_40) => (compareArrays(x_40, y_40) | 0),
1487
1661
  }));
1488
1662
  }
1489
1663