@magnusopera/fscript 0.75.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.
- package/README.md +5 -0
- package/dist/FScript.Language/Ast.js +234 -0
- package/dist/FScript.Language/BuiltinFunctions.js +2039 -0
- package/dist/FScript.Language/BuiltinSignatures.js +24 -0
- package/dist/FScript.Language/BuiltinTypes.js +13 -0
- package/dist/FScript.Language/Error.js +74 -0
- package/dist/FScript.Language/Eval.js +2404 -0
- package/dist/FScript.Language/IncludeResolver.js +806 -0
- package/dist/FScript.Language/Lexer.js +1067 -0
- package/dist/FScript.Language/Library.js +28 -0
- package/dist/FScript.Language/Parser.js +2368 -0
- package/dist/FScript.Language/Pretty.js +115 -0
- package/dist/FScript.Language/Span.js +33 -0
- package/dist/FScript.Language/Token.js +32 -0
- package/dist/FScript.Language/TypeInfer.js +2561 -0
- package/dist/FScript.Language/Types.js +205 -0
- package/dist/FScript.Language/Value.js +91 -0
- package/dist/Library.js +732 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Array.js +1347 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Async.js +134 -0
- package/dist/fable_modules/fable-library-js.5.2.0/AsyncBuilder.js +183 -0
- package/dist/fable_modules/fable-library-js.5.2.0/BigInt.js +306 -0
- package/dist/fable_modules/fable-library-js.5.2.0/BitConverter.js +138 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Boolean.js +22 -0
- package/dist/fable_modules/fable-library-js.5.2.0/CHANGELOG.md +234 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Char.js +202 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Choice.js +184 -0
- package/dist/fable_modules/fable-library-js.5.2.0/CollectionUtil.js +182 -0
- package/dist/fable_modules/fable-library-js.5.2.0/ConditionalWeakTable.js +21 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Date.js +841 -0
- package/dist/fable_modules/fable-library-js.5.2.0/DateOffset.js +261 -0
- package/dist/fable_modules/fable-library-js.5.2.0/DateOnly.js +124 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Decimal.js +238 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Double.js +47 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Encoding.js +185 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Event.js +93 -0
- package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Collections.js +45 -0
- package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Core.CompilerServices.js +27 -0
- package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Core.js +156 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Global.js +29 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Guid.js +161 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Int32.js +135 -0
- package/dist/fable_modules/fable-library-js.5.2.0/List.js +1323 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Long.js +47 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MailboxProcessor.js +94 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Map.js +1396 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MapUtil.js +130 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MutableMap.js +339 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MutableSet.js +233 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Native.js +14 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Numeric.js +75 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Observable.js +113 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Option.js +104 -0
- package/dist/fable_modules/fable-library-js.5.2.0/README.md +3 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Random.js +172 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Range.js +45 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Reflection.js +479 -0
- package/dist/fable_modules/fable-library-js.5.2.0/RegExp.js +141 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Result.js +165 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Seq.js +1417 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Seq2.js +111 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Set.js +1816 -0
- package/dist/fable_modules/fable-library-js.5.2.0/String.js +674 -0
- package/dist/fable_modules/fable-library-js.5.2.0/System.Collections.Generic.js +333 -0
- package/dist/fable_modules/fable-library-js.5.2.0/System.Text.js +200 -0
- package/dist/fable_modules/fable-library-js.5.2.0/System.js +283 -0
- package/dist/fable_modules/fable-library-js.5.2.0/TimeOnly.js +122 -0
- package/dist/fable_modules/fable-library-js.5.2.0/TimeSpan.js +180 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Timer.js +67 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Types.js +198 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Unicode.13.0.0.js +4 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Uri.js +165 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Util.js +795 -0
- package/dist/fable_modules/fable-library-js.5.2.0/big.d.ts +338 -0
- package/dist/fable_modules/fable-library-js.5.2.0/lib/big.js +825 -0
- package/dist/fable_modules/fable-library-js.5.2.0/package.json +24 -0
- package/dist/fable_modules/fable-library-js.5.2.0/quotation.js +618 -0
- package/dist/fable_modules/project_cracked.json +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,2561 @@
|
|
|
1
|
+
|
|
2
|
+
import { Span_$reflection, Span, Position } from "./Span.js";
|
|
3
|
+
import { iterate as iterate_2, FSharpMap__Add, FSharpMap__ContainsKey, values, keys, FSharpMap__TryFind, ofList, toList, FSharpMap__get_Item, FSharpMap__get_Keys, add, fold as fold_1, remove, map as map_1, tryFind, empty } from "../fable_modules/fable-library-js.5.2.0/Map.js";
|
|
4
|
+
import { disposeSafe, getEnumerator, stringHash, compareArrays, equals, comparePrimitives } from "../fable_modules/fable-library-js.5.2.0/Util.js";
|
|
5
|
+
import { Types_generalize, Type_$reflection, Types_freshVar, Types_typeToString, Types_ftvType, Scheme, Type } from "./Types.js";
|
|
6
|
+
import { tryFind as tryFind_1, indexed, ofArray, collect, append, iterate, reverse, tryFindIndex, choose, tail as tail_2, cons, head as head_1, isEmpty, empty as empty_2, singleton, zip, length, fold, map } from "../fable_modules/fable-library-js.5.2.0/List.js";
|
|
7
|
+
import { toList as toList_2, add as add_1, empty as empty_1, isSubset, ofSeq, FSharpSet__Add, FSharpSet__Contains, contains } from "../fable_modules/fable-library-js.5.2.0/Set.js";
|
|
8
|
+
import { TypeException, TypeError$ } from "./Error.js";
|
|
9
|
+
import { endsWith, split, join, concat, isNullOrWhiteSpace, printf, toText } from "../fable_modules/fable-library-js.5.2.0/String.js";
|
|
10
|
+
import { toArray, map as map_3, defaultArg } from "../fable_modules/fable-library-js.5.2.0/Option.js";
|
|
11
|
+
import { Union, Record } from "../fable_modules/fable-library-js.5.2.0/Types.js";
|
|
12
|
+
import { Expr, Ast_spanOfPattern, Ast_spanOfExpr, Pattern_$reflection, TypeDef_$reflection, Expr_$reflection } from "./Ast.js";
|
|
13
|
+
import { option_type, array_type, union_type, list_type, tuple_type, class_type, bool_type, string_type, record_type } from "../fable_modules/fable-library-js.5.2.0/Reflection.js";
|
|
14
|
+
import { foldBack, iterate as iterate_1, filter, map as map_2, toList as toList_1 } from "../fable_modules/fable-library-js.5.2.0/Seq.js";
|
|
15
|
+
import { last, item as item_2 } from "../fable_modules/fable-library-js.5.2.0/Array.js";
|
|
16
|
+
import { distinct } from "../fable_modules/fable-library-js.5.2.0/Seq2.js";
|
|
17
|
+
import { builtinReservedNames, builtinSchemes } from "./BuiltinSignatures.js";
|
|
18
|
+
import { typeDefs as typeDefs_1 } from "./BuiltinTypes.js";
|
|
19
|
+
|
|
20
|
+
const unknownSpan = new Span(new Position(undefined, 0, 0), new Position(undefined, 0, 0));
|
|
21
|
+
|
|
22
|
+
const emptySubst = empty({
|
|
23
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
function applyType(s_mut, t_mut) {
|
|
27
|
+
applyType:
|
|
28
|
+
while (true) {
|
|
29
|
+
const s = s_mut, t = t_mut;
|
|
30
|
+
switch (t.tag) {
|
|
31
|
+
case 15: {
|
|
32
|
+
const matchValue = tryFind(t.fields[0], s);
|
|
33
|
+
if (matchValue == null) {
|
|
34
|
+
return t;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
s_mut = s;
|
|
38
|
+
t_mut = matchValue;
|
|
39
|
+
continue applyType;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
case 5:
|
|
43
|
+
return new Type(5, [applyType(s, t.fields[0])]);
|
|
44
|
+
case 6:
|
|
45
|
+
return new Type(6, [applyType(s, t.fields[0])]);
|
|
46
|
+
case 7:
|
|
47
|
+
return new Type(7, [map((t_1) => applyType(s, t_1), t.fields[0])]);
|
|
48
|
+
case 8:
|
|
49
|
+
return new Type(8, [map_1((_arg, t1_2) => applyType(s, t1_2), t.fields[0])]);
|
|
50
|
+
case 9:
|
|
51
|
+
return new Type(9, [applyType(s, t.fields[0]), applyType(s, t.fields[1])]);
|
|
52
|
+
case 10:
|
|
53
|
+
return new Type(10, [applyType(s, t.fields[0])]);
|
|
54
|
+
case 11:
|
|
55
|
+
return new Type(11, [applyType(s, t.fields[0]), applyType(s, t.fields[1])]);
|
|
56
|
+
default:
|
|
57
|
+
return t;
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function applyScheme(s, _arg) {
|
|
64
|
+
const vars = _arg.fields[0];
|
|
65
|
+
return new Scheme(vars, applyType(fold((acc, v) => remove(v, acc), s, vars), _arg.fields[1]));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function applyEnv(s, env) {
|
|
69
|
+
return map_1((_arg, sc) => applyScheme(s, sc), env);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function compose(s1, s2) {
|
|
73
|
+
return fold_1((acc, k, v) => add(k, v, acc), s1, map_1((_arg, t) => applyType(s1, t), s2));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function occurs(v, t) {
|
|
77
|
+
return contains(v, Types_ftvType(t));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function unify(typeDefs, t1, t2, span) {
|
|
81
|
+
const uni = (seen_mut, a_mut, b_mut) => {
|
|
82
|
+
uni:
|
|
83
|
+
while (true) {
|
|
84
|
+
const seen = seen_mut, a = a_mut, b = b_mut;
|
|
85
|
+
let arg, arg_1, arg_2, arg_3, arg_4, arg_5;
|
|
86
|
+
if (FSharpSet__Contains(seen, [a, b]) ? true : FSharpSet__Contains(seen, [b, a])) {
|
|
87
|
+
return emptySubst;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const seen$0027 = FSharpSet__Add(seen, [a, b]);
|
|
91
|
+
let matchResult, x_1, y_1, x_2, y_2, x_3, y_3, xs, ys, xf, yf, kx, ky, vx, vy, x_7, y_7, a1, a2, b1, b2, t, v, name_1, t_1, name_2, t_2;
|
|
92
|
+
switch (a.tag) {
|
|
93
|
+
case 0: {
|
|
94
|
+
switch (b.tag) {
|
|
95
|
+
case 0: {
|
|
96
|
+
matchResult = 0;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case 15: {
|
|
100
|
+
matchResult = 9;
|
|
101
|
+
t = a;
|
|
102
|
+
v = b.fields[0];
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case 12: {
|
|
106
|
+
matchResult = 11;
|
|
107
|
+
name_2 = b.fields[0];
|
|
108
|
+
t_2 = a;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
default:
|
|
112
|
+
matchResult = 12;
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case 1: {
|
|
117
|
+
switch (b.tag) {
|
|
118
|
+
case 1: {
|
|
119
|
+
matchResult = 0;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 15: {
|
|
123
|
+
matchResult = 9;
|
|
124
|
+
t = a;
|
|
125
|
+
v = b.fields[0];
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case 12: {
|
|
129
|
+
matchResult = 11;
|
|
130
|
+
name_2 = b.fields[0];
|
|
131
|
+
t_2 = a;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
default:
|
|
135
|
+
matchResult = 12;
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case 2: {
|
|
140
|
+
switch (b.tag) {
|
|
141
|
+
case 2: {
|
|
142
|
+
matchResult = 0;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case 15: {
|
|
146
|
+
matchResult = 9;
|
|
147
|
+
t = a;
|
|
148
|
+
v = b.fields[0];
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case 12: {
|
|
152
|
+
matchResult = 11;
|
|
153
|
+
name_2 = b.fields[0];
|
|
154
|
+
t_2 = a;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
default:
|
|
158
|
+
matchResult = 12;
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case 3: {
|
|
163
|
+
switch (b.tag) {
|
|
164
|
+
case 3: {
|
|
165
|
+
matchResult = 0;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
case 15: {
|
|
169
|
+
matchResult = 9;
|
|
170
|
+
t = a;
|
|
171
|
+
v = b.fields[0];
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 12: {
|
|
175
|
+
matchResult = 11;
|
|
176
|
+
name_2 = b.fields[0];
|
|
177
|
+
t_2 = a;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
default:
|
|
181
|
+
matchResult = 12;
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case 4: {
|
|
186
|
+
switch (b.tag) {
|
|
187
|
+
case 4: {
|
|
188
|
+
matchResult = 0;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case 15: {
|
|
192
|
+
matchResult = 9;
|
|
193
|
+
t = a;
|
|
194
|
+
v = b.fields[0];
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case 12: {
|
|
198
|
+
matchResult = 11;
|
|
199
|
+
name_2 = b.fields[0];
|
|
200
|
+
t_2 = a;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
default:
|
|
204
|
+
matchResult = 12;
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case 14: {
|
|
209
|
+
switch (b.tag) {
|
|
210
|
+
case 14: {
|
|
211
|
+
matchResult = 0;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case 15: {
|
|
215
|
+
matchResult = 9;
|
|
216
|
+
t = a;
|
|
217
|
+
v = b.fields[0];
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case 12: {
|
|
221
|
+
matchResult = 11;
|
|
222
|
+
name_2 = b.fields[0];
|
|
223
|
+
t_2 = a;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
default:
|
|
227
|
+
matchResult = 12;
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
case 12: {
|
|
232
|
+
switch (b.tag) {
|
|
233
|
+
case 12: {
|
|
234
|
+
if (a.fields[0] === b.fields[0]) {
|
|
235
|
+
matchResult = 1;
|
|
236
|
+
x_1 = a.fields[0];
|
|
237
|
+
y_1 = b.fields[0];
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
matchResult = 10;
|
|
241
|
+
name_1 = a.fields[0];
|
|
242
|
+
t_1 = b;
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
case 15: {
|
|
247
|
+
matchResult = 9;
|
|
248
|
+
t = a;
|
|
249
|
+
v = b.fields[0];
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
default: {
|
|
253
|
+
matchResult = 10;
|
|
254
|
+
name_1 = a.fields[0];
|
|
255
|
+
t_1 = b;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
case 5: {
|
|
261
|
+
switch (b.tag) {
|
|
262
|
+
case 5: {
|
|
263
|
+
matchResult = 2;
|
|
264
|
+
x_2 = a.fields[0];
|
|
265
|
+
y_2 = b.fields[0];
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
case 15: {
|
|
269
|
+
matchResult = 9;
|
|
270
|
+
t = a;
|
|
271
|
+
v = b.fields[0];
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
case 12: {
|
|
275
|
+
matchResult = 11;
|
|
276
|
+
name_2 = b.fields[0];
|
|
277
|
+
t_2 = a;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
default:
|
|
281
|
+
matchResult = 12;
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
case 6: {
|
|
286
|
+
switch (b.tag) {
|
|
287
|
+
case 6: {
|
|
288
|
+
matchResult = 3;
|
|
289
|
+
x_3 = a.fields[0];
|
|
290
|
+
y_3 = b.fields[0];
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
case 15: {
|
|
294
|
+
matchResult = 9;
|
|
295
|
+
t = a;
|
|
296
|
+
v = b.fields[0];
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
case 12: {
|
|
300
|
+
matchResult = 11;
|
|
301
|
+
name_2 = b.fields[0];
|
|
302
|
+
t_2 = a;
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
default:
|
|
306
|
+
matchResult = 12;
|
|
307
|
+
}
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
case 7: {
|
|
311
|
+
switch (b.tag) {
|
|
312
|
+
case 7: {
|
|
313
|
+
matchResult = 4;
|
|
314
|
+
xs = a.fields[0];
|
|
315
|
+
ys = b.fields[0];
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
case 15: {
|
|
319
|
+
matchResult = 9;
|
|
320
|
+
t = a;
|
|
321
|
+
v = b.fields[0];
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
case 12: {
|
|
325
|
+
matchResult = 11;
|
|
326
|
+
name_2 = b.fields[0];
|
|
327
|
+
t_2 = a;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
default:
|
|
331
|
+
matchResult = 12;
|
|
332
|
+
}
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
case 8: {
|
|
336
|
+
switch (b.tag) {
|
|
337
|
+
case 8: {
|
|
338
|
+
matchResult = 5;
|
|
339
|
+
xf = a.fields[0];
|
|
340
|
+
yf = b.fields[0];
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
case 15: {
|
|
344
|
+
matchResult = 9;
|
|
345
|
+
t = a;
|
|
346
|
+
v = b.fields[0];
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
case 12: {
|
|
350
|
+
matchResult = 11;
|
|
351
|
+
name_2 = b.fields[0];
|
|
352
|
+
t_2 = a;
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
default:
|
|
356
|
+
matchResult = 12;
|
|
357
|
+
}
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
case 9: {
|
|
361
|
+
switch (b.tag) {
|
|
362
|
+
case 9: {
|
|
363
|
+
matchResult = 6;
|
|
364
|
+
kx = a.fields[0];
|
|
365
|
+
ky = b.fields[0];
|
|
366
|
+
vx = a.fields[1];
|
|
367
|
+
vy = b.fields[1];
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
case 15: {
|
|
371
|
+
matchResult = 9;
|
|
372
|
+
t = a;
|
|
373
|
+
v = b.fields[0];
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
case 12: {
|
|
377
|
+
matchResult = 11;
|
|
378
|
+
name_2 = b.fields[0];
|
|
379
|
+
t_2 = a;
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
default:
|
|
383
|
+
matchResult = 12;
|
|
384
|
+
}
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
case 10: {
|
|
388
|
+
switch (b.tag) {
|
|
389
|
+
case 10: {
|
|
390
|
+
matchResult = 7;
|
|
391
|
+
x_7 = a.fields[0];
|
|
392
|
+
y_7 = b.fields[0];
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
case 15: {
|
|
396
|
+
matchResult = 9;
|
|
397
|
+
t = a;
|
|
398
|
+
v = b.fields[0];
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
case 12: {
|
|
402
|
+
matchResult = 11;
|
|
403
|
+
name_2 = b.fields[0];
|
|
404
|
+
t_2 = a;
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
default:
|
|
408
|
+
matchResult = 12;
|
|
409
|
+
}
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
case 11: {
|
|
413
|
+
switch (b.tag) {
|
|
414
|
+
case 11: {
|
|
415
|
+
matchResult = 8;
|
|
416
|
+
a1 = a.fields[0];
|
|
417
|
+
a2 = b.fields[0];
|
|
418
|
+
b1 = a.fields[1];
|
|
419
|
+
b2 = b.fields[1];
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
case 15: {
|
|
423
|
+
matchResult = 9;
|
|
424
|
+
t = a;
|
|
425
|
+
v = b.fields[0];
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
case 12: {
|
|
429
|
+
matchResult = 11;
|
|
430
|
+
name_2 = b.fields[0];
|
|
431
|
+
t_2 = a;
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
default:
|
|
435
|
+
matchResult = 12;
|
|
436
|
+
}
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
case 15: {
|
|
440
|
+
matchResult = 9;
|
|
441
|
+
t = b;
|
|
442
|
+
v = a.fields[0];
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
default:
|
|
446
|
+
switch (b.tag) {
|
|
447
|
+
case 15: {
|
|
448
|
+
matchResult = 9;
|
|
449
|
+
t = a;
|
|
450
|
+
v = b.fields[0];
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
case 12: {
|
|
454
|
+
matchResult = 11;
|
|
455
|
+
name_2 = b.fields[0];
|
|
456
|
+
t_2 = a;
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
default:
|
|
460
|
+
matchResult = 12;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
switch (matchResult) {
|
|
464
|
+
case 0:
|
|
465
|
+
return emptySubst;
|
|
466
|
+
case 1:
|
|
467
|
+
return emptySubst;
|
|
468
|
+
case 2: {
|
|
469
|
+
seen_mut = seen$0027;
|
|
470
|
+
a_mut = x_2;
|
|
471
|
+
b_mut = y_2;
|
|
472
|
+
continue uni;
|
|
473
|
+
}
|
|
474
|
+
case 3: {
|
|
475
|
+
seen_mut = seen$0027;
|
|
476
|
+
a_mut = x_3;
|
|
477
|
+
b_mut = y_3;
|
|
478
|
+
continue uni;
|
|
479
|
+
}
|
|
480
|
+
case 4: {
|
|
481
|
+
if (length(xs) !== length(ys)) {
|
|
482
|
+
throw new TypeException(new TypeError$("Tuple arity mismatch", span));
|
|
483
|
+
}
|
|
484
|
+
return fold((sAcc, tupledArg) => compose(uni(seen$0027, applyType(sAcc, tupledArg[0]), applyType(sAcc, tupledArg[1])), sAcc), emptySubst, zip(xs, ys));
|
|
485
|
+
}
|
|
486
|
+
case 5: {
|
|
487
|
+
const xKeys = ofSeq(FSharpMap__get_Keys(xf), {
|
|
488
|
+
Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
|
|
489
|
+
});
|
|
490
|
+
const yKeys = ofSeq(FSharpMap__get_Keys(yf), {
|
|
491
|
+
Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
|
|
492
|
+
});
|
|
493
|
+
let patternInput;
|
|
494
|
+
if (isSubset(xKeys, yKeys)) {
|
|
495
|
+
patternInput = [xf, yf];
|
|
496
|
+
}
|
|
497
|
+
else if (isSubset(yKeys, xKeys)) {
|
|
498
|
+
patternInput = [yf, xf];
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
throw new TypeException(new TypeError$("Record field set mismatch", span));
|
|
502
|
+
}
|
|
503
|
+
return fold((sAcc_1, tupledArg_1) => {
|
|
504
|
+
const yt = FSharpMap__get_Item(patternInput[1], tupledArg_1[0]);
|
|
505
|
+
return compose(uni(seen$0027, applyType(sAcc_1, tupledArg_1[1]), applyType(sAcc_1, yt)), sAcc_1);
|
|
506
|
+
}, emptySubst, toList(patternInput[0]));
|
|
507
|
+
}
|
|
508
|
+
case 6: {
|
|
509
|
+
const s1_2 = uni(seen$0027, kx, ky);
|
|
510
|
+
return compose(uni(seen$0027, applyType(s1_2, vx), applyType(s1_2, vy)), s1_2);
|
|
511
|
+
}
|
|
512
|
+
case 7: {
|
|
513
|
+
seen_mut = seen$0027;
|
|
514
|
+
a_mut = x_7;
|
|
515
|
+
b_mut = y_7;
|
|
516
|
+
continue uni;
|
|
517
|
+
}
|
|
518
|
+
case 8: {
|
|
519
|
+
const s1_3 = uni(seen$0027, a1, a2);
|
|
520
|
+
return compose(uni(seen$0027, applyType(s1_3, b1), applyType(s1_3, b2)), s1_3);
|
|
521
|
+
}
|
|
522
|
+
case 9:
|
|
523
|
+
if (equals(t, new Type(15, [v]))) {
|
|
524
|
+
return emptySubst;
|
|
525
|
+
}
|
|
526
|
+
else if (occurs(v, t)) {
|
|
527
|
+
throw new TypeException(new TypeError$("Occurs check failed", span));
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
return ofList(singleton([v, t]), {
|
|
531
|
+
Compare: (x_8, y_8) => (comparePrimitives(x_8, y_8) | 0),
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
case 10: {
|
|
535
|
+
const matchValue_1 = FSharpMap__TryFind(typeDefs, name_1);
|
|
536
|
+
let matchResult_1, expanded_1;
|
|
537
|
+
if (matchValue_1 != null) {
|
|
538
|
+
if (!equals(matchValue_1, new Type(12, [name_1]))) {
|
|
539
|
+
matchResult_1 = 0;
|
|
540
|
+
expanded_1 = matchValue_1;
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
matchResult_1 = 1;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
matchResult_1 = 1;
|
|
548
|
+
}
|
|
549
|
+
switch (matchResult_1) {
|
|
550
|
+
case 0: {
|
|
551
|
+
seen_mut = seen$0027;
|
|
552
|
+
a_mut = expanded_1;
|
|
553
|
+
b_mut = t_1;
|
|
554
|
+
continue uni;
|
|
555
|
+
}
|
|
556
|
+
default: {
|
|
557
|
+
let matchResult_2, other_1;
|
|
558
|
+
if (t_1.tag === 12) {
|
|
559
|
+
if (t_1.fields[0] === name_1) {
|
|
560
|
+
matchResult_2 = 0;
|
|
561
|
+
other_1 = t_1.fields[0];
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
matchResult_2 = 1;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
matchResult_2 = 1;
|
|
569
|
+
}
|
|
570
|
+
switch (matchResult_2) {
|
|
571
|
+
case 0:
|
|
572
|
+
return emptySubst;
|
|
573
|
+
default:
|
|
574
|
+
throw new TypeException(new TypeError$((arg = Types_typeToString(a), (arg_1 = Types_typeToString(b), toText(printf("Type mismatch: %s vs %s"))(arg)(arg_1))), span));
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
case 11: {
|
|
580
|
+
const matchValue_2 = FSharpMap__TryFind(typeDefs, name_2);
|
|
581
|
+
let matchResult_3, expanded_3;
|
|
582
|
+
if (matchValue_2 != null) {
|
|
583
|
+
if (!equals(matchValue_2, new Type(12, [name_2]))) {
|
|
584
|
+
matchResult_3 = 0;
|
|
585
|
+
expanded_3 = matchValue_2;
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
matchResult_3 = 1;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
matchResult_3 = 1;
|
|
593
|
+
}
|
|
594
|
+
switch (matchResult_3) {
|
|
595
|
+
case 0: {
|
|
596
|
+
seen_mut = seen$0027;
|
|
597
|
+
a_mut = t_2;
|
|
598
|
+
b_mut = expanded_3;
|
|
599
|
+
continue uni;
|
|
600
|
+
}
|
|
601
|
+
default: {
|
|
602
|
+
let matchResult_4, other_3;
|
|
603
|
+
if (t_2.tag === 12) {
|
|
604
|
+
if (t_2.fields[0] === name_2) {
|
|
605
|
+
matchResult_4 = 0;
|
|
606
|
+
other_3 = t_2.fields[0];
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
matchResult_4 = 1;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
matchResult_4 = 1;
|
|
614
|
+
}
|
|
615
|
+
switch (matchResult_4) {
|
|
616
|
+
case 0:
|
|
617
|
+
return emptySubst;
|
|
618
|
+
default:
|
|
619
|
+
throw new TypeException(new TypeError$((arg_2 = Types_typeToString(a), (arg_3 = Types_typeToString(b), toText(printf("Type mismatch: %s vs %s"))(arg_2)(arg_3))), span));
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
default:
|
|
625
|
+
throw new TypeException(new TypeError$((arg_4 = Types_typeToString(a), (arg_5 = Types_typeToString(b), toText(printf("Type mismatch: %s vs %s"))(arg_4)(arg_5))), span));
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
break;
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
return uni(empty_1({
|
|
632
|
+
Compare: (x_9, y_9) => (compareArrays(x_9, y_9) | 0),
|
|
633
|
+
}), t1, t2);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function instantiate(_arg) {
|
|
637
|
+
const freshMap = ofList(map((v) => [v, Types_freshVar()], _arg.fields[0]), {
|
|
638
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
639
|
+
});
|
|
640
|
+
const subst = (t_1) => {
|
|
641
|
+
switch (t_1.tag) {
|
|
642
|
+
case 15:
|
|
643
|
+
return defaultArg(tryFind(t_1.fields[0], freshMap), t_1);
|
|
644
|
+
case 5:
|
|
645
|
+
return new Type(5, [subst(t_1.fields[0])]);
|
|
646
|
+
case 6:
|
|
647
|
+
return new Type(6, [subst(t_1.fields[0])]);
|
|
648
|
+
case 7:
|
|
649
|
+
return new Type(7, [map(subst, t_1.fields[0])]);
|
|
650
|
+
case 8:
|
|
651
|
+
return new Type(8, [map_1((_arg_1, t1) => subst(t1), t_1.fields[0])]);
|
|
652
|
+
case 9:
|
|
653
|
+
return new Type(9, [subst(t_1.fields[0]), subst(t_1.fields[1])]);
|
|
654
|
+
case 10:
|
|
655
|
+
return new Type(10, [subst(t_1.fields[0])]);
|
|
656
|
+
case 11:
|
|
657
|
+
return new Type(11, [subst(t_1.fields[0]), subst(t_1.fields[1])]);
|
|
658
|
+
default:
|
|
659
|
+
return t_1;
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
return subst(_arg.fields[1]);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
export class TypedExpr extends Record {
|
|
666
|
+
constructor(Expr, Type, Span) {
|
|
667
|
+
super();
|
|
668
|
+
this.Expr = Expr;
|
|
669
|
+
this.Type = Type;
|
|
670
|
+
this.Span = Span;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
export function TypedExpr_$reflection() {
|
|
675
|
+
return record_type("FScript.Language.TypeInfer.TypedExpr", [], TypedExpr, () => [["Expr", Expr_$reflection()], ["Type", Type_$reflection()], ["Span", Span_$reflection()]]);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
export class LocalVariableTypeInfo extends Record {
|
|
679
|
+
constructor(Name, Span, Type) {
|
|
680
|
+
super();
|
|
681
|
+
this.Name = Name;
|
|
682
|
+
this.Span = Span;
|
|
683
|
+
this.Type = Type;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
export function LocalVariableTypeInfo_$reflection() {
|
|
688
|
+
return record_type("FScript.Language.TypeInfer.LocalVariableTypeInfo", [], LocalVariableTypeInfo, () => [["Name", string_type], ["Span", Span_$reflection()], ["Type", Type_$reflection()]]);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
class LocalVariableTypeCapture extends Record {
|
|
692
|
+
constructor(Name, Span, Type) {
|
|
693
|
+
super();
|
|
694
|
+
this.Name = Name;
|
|
695
|
+
this.Span = Span;
|
|
696
|
+
this.Type = Type;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function LocalVariableTypeCapture_$reflection() {
|
|
701
|
+
return record_type("FScript.Language.TypeInfer.LocalVariableTypeCapture", [], LocalVariableTypeCapture, () => [["Name", string_type], ["Span", Span_$reflection()], ["Type", Type_$reflection()]]);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
export class TypedStmt extends Union {
|
|
705
|
+
constructor(tag, fields) {
|
|
706
|
+
super();
|
|
707
|
+
this.tag = tag;
|
|
708
|
+
this.fields = fields;
|
|
709
|
+
}
|
|
710
|
+
cases() {
|
|
711
|
+
return ["TSType", "TSLet", "TSLetPattern", "TSLetRecGroup", "TSExpr"];
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
export function TypedStmt_$reflection() {
|
|
716
|
+
return union_type("FScript.Language.TypeInfer.TypedStmt", [], TypedStmt, () => [[["Item", TypeDef_$reflection()]], [["Item1", string_type], ["Item2", Expr_$reflection()], ["Item3", Type_$reflection()], ["Item4", bool_type], ["Item5", bool_type], ["Item6", Span_$reflection()]], [["Item1", Pattern_$reflection()], ["Item2", Expr_$reflection()], ["Item3", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, Type_$reflection()])], ["Item4", bool_type], ["Item5", Span_$reflection()]], [["Item1", list_type(tuple_type(string_type, Expr_$reflection(), Type_$reflection(), Span_$reflection()))], ["Item2", bool_type], ["Item3", Span_$reflection()]], [["Item", TypedExpr_$reflection()]]]);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
class InferenceTelemetry extends Record {
|
|
720
|
+
constructor(ScopeStack, LocalVariableTypes) {
|
|
721
|
+
super();
|
|
722
|
+
this.ScopeStack = ScopeStack;
|
|
723
|
+
this.LocalVariableTypes = LocalVariableTypes;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function InferenceTelemetry_$reflection() {
|
|
728
|
+
return record_type("FScript.Language.TypeInfer.InferenceTelemetry", [], InferenceTelemetry, () => [["ScopeStack", list_type(class_type("Microsoft.FSharp.Collections.FSharpSet`1", [string_type]))], ["LocalVariableTypes", array_type(LocalVariableTypeCapture_$reflection())]]);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
let telemetry = undefined;
|
|
732
|
+
|
|
733
|
+
function beginTelemetry() {
|
|
734
|
+
telemetry = (new InferenceTelemetry(singleton(empty_1({
|
|
735
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
736
|
+
})), []));
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function endTelemetry() {
|
|
740
|
+
const captured = (telemetry == null) ? empty_2() : toList_1(map_2((item) => (new LocalVariableTypeInfo(item.Name, item.Span, item.Type)), telemetry.LocalVariableTypes));
|
|
741
|
+
telemetry = undefined;
|
|
742
|
+
return captured;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
function withLocalBindings(names, work) {
|
|
746
|
+
let matchValue;
|
|
747
|
+
if (telemetry != null) {
|
|
748
|
+
const t = telemetry;
|
|
749
|
+
const pushed = fold((acc, name) => {
|
|
750
|
+
if (isNullOrWhiteSpace(name) ? true : (name === "_")) {
|
|
751
|
+
return acc;
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
return add_1(name, acc);
|
|
755
|
+
}
|
|
756
|
+
}, (matchValue = t.ScopeStack, isEmpty(matchValue) ? empty_1({
|
|
757
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
758
|
+
}) : head_1(matchValue)), names);
|
|
759
|
+
t.ScopeStack = cons(pushed, t.ScopeStack);
|
|
760
|
+
try {
|
|
761
|
+
return work();
|
|
762
|
+
}
|
|
763
|
+
finally {
|
|
764
|
+
const matchValue_1 = t.ScopeStack;
|
|
765
|
+
if (isEmpty(matchValue_1)) {
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
t.ScopeStack = tail_2(matchValue_1);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
else {
|
|
773
|
+
return work();
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function recordLocalVariableUse(name, span, varType) {
|
|
778
|
+
let matchValue;
|
|
779
|
+
if (telemetry != null) {
|
|
780
|
+
const t = telemetry;
|
|
781
|
+
if (contains(name, (matchValue = t.ScopeStack, isEmpty(matchValue) ? empty_1({
|
|
782
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
783
|
+
}) : head_1(matchValue)))) {
|
|
784
|
+
void (t.LocalVariableTypes.push(new LocalVariableTypeCapture(name, span, varType)));
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function recordLocalVariableDeclaration(name, span, varType) {
|
|
790
|
+
if (isNullOrWhiteSpace(name) ? true : (name === "_")) {
|
|
791
|
+
}
|
|
792
|
+
else if (telemetry != null) {
|
|
793
|
+
const t = telemetry;
|
|
794
|
+
void (t.LocalVariableTypes.push(new LocalVariableTypeCapture(name, span, varType)));
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function applySubstToCapturedLocals(startIndex, subst) {
|
|
799
|
+
if (telemetry != null) {
|
|
800
|
+
const t = telemetry;
|
|
801
|
+
for (let i = startIndex; i <= (t.LocalVariableTypes.length - 1); i++) {
|
|
802
|
+
const entry = item_2(i, t.LocalVariableTypes);
|
|
803
|
+
entry.Type = applyType(subst, entry.Type);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function currentTelemetryCaptureCount() {
|
|
809
|
+
if (telemetry == null) {
|
|
810
|
+
return 0;
|
|
811
|
+
}
|
|
812
|
+
else {
|
|
813
|
+
const t = telemetry;
|
|
814
|
+
return t.LocalVariableTypes.length | 0;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
class ConstructorSig extends Record {
|
|
819
|
+
constructor(UnionName, Payload) {
|
|
820
|
+
super();
|
|
821
|
+
this.UnionName = UnionName;
|
|
822
|
+
this.Payload = Payload;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function ConstructorSig_$reflection() {
|
|
827
|
+
return record_type("FScript.Language.TypeInfer.ConstructorSig", [], ConstructorSig, () => [["UnionName", string_type], ["Payload", option_type(Type_$reflection())]]);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
function asTyped(expr, t) {
|
|
831
|
+
return new TypedExpr(expr, t, Ast_spanOfExpr(expr));
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
function builtinType(name) {
|
|
835
|
+
switch (name) {
|
|
836
|
+
case "unit":
|
|
837
|
+
return new Type(0, []);
|
|
838
|
+
case "int":
|
|
839
|
+
return new Type(1, []);
|
|
840
|
+
case "float":
|
|
841
|
+
return new Type(2, []);
|
|
842
|
+
case "bool":
|
|
843
|
+
return new Type(3, []);
|
|
844
|
+
case "string":
|
|
845
|
+
return new Type(4, []);
|
|
846
|
+
default:
|
|
847
|
+
return undefined;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
function resolveNamedRecordByShape(typeDefs, shape, span) {
|
|
852
|
+
const matches = choose((tupledArg) => {
|
|
853
|
+
const t = tupledArg[1];
|
|
854
|
+
let matchResult, fields_1;
|
|
855
|
+
if (t.tag === 8) {
|
|
856
|
+
if (t.fields[0].Equals(shape)) {
|
|
857
|
+
matchResult = 0;
|
|
858
|
+
fields_1 = t.fields[0];
|
|
859
|
+
}
|
|
860
|
+
else {
|
|
861
|
+
matchResult = 1;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
else {
|
|
865
|
+
matchResult = 1;
|
|
866
|
+
}
|
|
867
|
+
switch (matchResult) {
|
|
868
|
+
case 0:
|
|
869
|
+
return tupledArg[0];
|
|
870
|
+
default:
|
|
871
|
+
return undefined;
|
|
872
|
+
}
|
|
873
|
+
}, toList(typeDefs));
|
|
874
|
+
if (isEmpty(matches)) {
|
|
875
|
+
throw new TypeException(new TypeError$(concat("No declared record type matches shape ", Types_typeToString(new Type(8, [shape]))), span));
|
|
876
|
+
}
|
|
877
|
+
else if (isEmpty(tail_2(matches))) {
|
|
878
|
+
return new Type(12, [head_1(matches)]);
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
throw new TypeException(new TypeError$(concat("Ambiguous declared record type for shape ", Types_typeToString(new Type(8, [shape])), ": ", join(", ", matches)), span));
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
function resolveNamedRecordByFieldSet(typeDefs, fields, span) {
|
|
886
|
+
const matches = choose((tupledArg) => {
|
|
887
|
+
const t = tupledArg[1];
|
|
888
|
+
let matchResult, recordFields_1;
|
|
889
|
+
if (t.tag === 8) {
|
|
890
|
+
if (ofSeq(keys(t.fields[0]), {
|
|
891
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
892
|
+
}).Equals(fields)) {
|
|
893
|
+
matchResult = 0;
|
|
894
|
+
recordFields_1 = t.fields[0];
|
|
895
|
+
}
|
|
896
|
+
else {
|
|
897
|
+
matchResult = 1;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
else {
|
|
901
|
+
matchResult = 1;
|
|
902
|
+
}
|
|
903
|
+
switch (matchResult) {
|
|
904
|
+
case 0:
|
|
905
|
+
return tupledArg[0];
|
|
906
|
+
default:
|
|
907
|
+
return undefined;
|
|
908
|
+
}
|
|
909
|
+
}, toList(typeDefs));
|
|
910
|
+
if (isEmpty(matches)) {
|
|
911
|
+
throw new TypeException(new TypeError$(concat("No declared record type matches fields ", concat("{ ", join("; ", toList_2(fields)), " }")), span));
|
|
912
|
+
}
|
|
913
|
+
else if (isEmpty(tail_2(matches))) {
|
|
914
|
+
return head_1(matches);
|
|
915
|
+
}
|
|
916
|
+
else {
|
|
917
|
+
throw new TypeException(new TypeError$(concat("Ambiguous declared record type for fields ", concat("{ ", join("; ", toList_2(fields)), " }"), ": ", join(", ", matches)), span));
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function resolveReferencedTypeName(knownNames, name, span) {
|
|
922
|
+
if (FSharpSet__Contains(ofSeq(knownNames, {
|
|
923
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
924
|
+
}), name)) {
|
|
925
|
+
return name;
|
|
926
|
+
}
|
|
927
|
+
else if (name.indexOf(".") >= 0) {
|
|
928
|
+
const shortName = last(split(name, ["."], undefined, 0));
|
|
929
|
+
const matches = toList_1(distinct(filter((candidate) => {
|
|
930
|
+
if (candidate === shortName) {
|
|
931
|
+
return true;
|
|
932
|
+
}
|
|
933
|
+
else {
|
|
934
|
+
return endsWith(candidate, "." + shortName, 4);
|
|
935
|
+
}
|
|
936
|
+
}, knownNames), {
|
|
937
|
+
Equals: (x_1, y_1) => (x_1 === y_1),
|
|
938
|
+
GetHashCode: (x_1) => (stringHash(x_1) | 0),
|
|
939
|
+
}));
|
|
940
|
+
if (isEmpty(matches)) {
|
|
941
|
+
return name;
|
|
942
|
+
}
|
|
943
|
+
else if (isEmpty(tail_2(matches))) {
|
|
944
|
+
return head_1(matches);
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
throw new TypeException(new TypeError$(concat("Ambiguous type reference \'", name, "\'. Candidates: ", join(", ", matches)), span));
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
else {
|
|
951
|
+
return name;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
function annotationTypeFromRef(typeDefs, span, tref) {
|
|
956
|
+
switch (tref.tag) {
|
|
957
|
+
case 1:
|
|
958
|
+
return new Type(7, [map((tref_1) => annotationTypeFromRef(typeDefs, span, tref_1), tref.fields[0])]);
|
|
959
|
+
case 2:
|
|
960
|
+
return new Type(11, [annotationTypeFromRef(typeDefs, span, tref.fields[0]), annotationTypeFromRef(typeDefs, span, tref.fields[1])]);
|
|
961
|
+
case 3:
|
|
962
|
+
switch (tref.fields[1]) {
|
|
963
|
+
case "list":
|
|
964
|
+
return new Type(5, [annotationTypeFromRef(typeDefs, span, tref.fields[0])]);
|
|
965
|
+
case "task":
|
|
966
|
+
return new Type(6, [annotationTypeFromRef(typeDefs, span, tref.fields[0])]);
|
|
967
|
+
case "option":
|
|
968
|
+
return new Type(10, [annotationTypeFromRef(typeDefs, span, tref.fields[0])]);
|
|
969
|
+
case "map":
|
|
970
|
+
return new Type(9, [new Type(4, []), annotationTypeFromRef(typeDefs, span, tref.fields[0])]);
|
|
971
|
+
default:
|
|
972
|
+
throw new TypeException(new TypeError$(concat("Unknown type suffix \'", tref.fields[1], "\'"), span));
|
|
973
|
+
}
|
|
974
|
+
case 4:
|
|
975
|
+
return resolveNamedRecordByShape(typeDefs, ofList(map((tupledArg) => [tupledArg[0], annotationTypeFromRef(typeDefs, span, tupledArg[1])], tref.fields[0]), {
|
|
976
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
977
|
+
}), span);
|
|
978
|
+
case 5:
|
|
979
|
+
return new Type(8, [ofList(map((tupledArg_1) => [tupledArg_1[0], annotationTypeFromRef(typeDefs, span, tupledArg_1[1])], tref.fields[0]), {
|
|
980
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
981
|
+
})]);
|
|
982
|
+
default:
|
|
983
|
+
switch (tref.fields[0]) {
|
|
984
|
+
case "unit":
|
|
985
|
+
return new Type(0, []);
|
|
986
|
+
case "int":
|
|
987
|
+
return new Type(1, []);
|
|
988
|
+
case "float":
|
|
989
|
+
return new Type(2, []);
|
|
990
|
+
case "bool":
|
|
991
|
+
return new Type(3, []);
|
|
992
|
+
case "string":
|
|
993
|
+
return new Type(4, []);
|
|
994
|
+
default:
|
|
995
|
+
return new Type(12, [resolveReferencedTypeName(FSharpMap__get_Keys(typeDefs), tref.fields[0], span)]);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function functionReturnType(t_mut) {
|
|
1001
|
+
functionReturnType:
|
|
1002
|
+
while (true) {
|
|
1003
|
+
const t = t_mut;
|
|
1004
|
+
if (t.tag === 11) {
|
|
1005
|
+
t_mut = t.fields[1];
|
|
1006
|
+
continue functionReturnType;
|
|
1007
|
+
}
|
|
1008
|
+
else {
|
|
1009
|
+
return t;
|
|
1010
|
+
}
|
|
1011
|
+
break;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
function typeFromRef(decls, stack, tref) {
|
|
1016
|
+
switch (tref.tag) {
|
|
1017
|
+
case 1:
|
|
1018
|
+
return new Type(7, [map((tref_1) => typeFromRef(decls, stack, tref_1), tref.fields[0])]);
|
|
1019
|
+
case 2:
|
|
1020
|
+
return new Type(11, [typeFromRef(decls, stack, tref.fields[0]), typeFromRef(decls, stack, tref.fields[1])]);
|
|
1021
|
+
case 3: {
|
|
1022
|
+
const suffix = tref.fields[1];
|
|
1023
|
+
const resolved = typeFromRef(decls, stack, tref.fields[0]);
|
|
1024
|
+
switch (suffix) {
|
|
1025
|
+
case "list":
|
|
1026
|
+
return new Type(5, [resolved]);
|
|
1027
|
+
case "task":
|
|
1028
|
+
return new Type(6, [resolved]);
|
|
1029
|
+
case "option":
|
|
1030
|
+
return new Type(10, [resolved]);
|
|
1031
|
+
case "map":
|
|
1032
|
+
return new Type(9, [new Type(4, []), resolved]);
|
|
1033
|
+
default:
|
|
1034
|
+
throw new TypeException(new TypeError$(concat("Unknown type suffix \'", suffix, "\'"), unknownSpan));
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
case 4:
|
|
1038
|
+
return new Type(8, [ofList(map((tupledArg_1) => [tupledArg_1[0], typeFromRef(decls, stack, tupledArg_1[1])], tref.fields[0]), {
|
|
1039
|
+
Compare: (x_1, y_2) => (comparePrimitives(x_1, y_2) | 0),
|
|
1040
|
+
})]);
|
|
1041
|
+
case 5:
|
|
1042
|
+
return new Type(8, [ofList(map((tupledArg_2) => [tupledArg_2[0], typeFromRef(decls, stack, tupledArg_2[1])], tref.fields[0]), {
|
|
1043
|
+
Compare: (x_2, y_3) => (comparePrimitives(x_2, y_3) | 0),
|
|
1044
|
+
})]);
|
|
1045
|
+
default: {
|
|
1046
|
+
const name = tref.fields[0];
|
|
1047
|
+
const matchValue = builtinType(name);
|
|
1048
|
+
if (matchValue == null) {
|
|
1049
|
+
const resolvedName = resolveReferencedTypeName(FSharpMap__get_Keys(decls), name, unknownSpan);
|
|
1050
|
+
const matchValue_1 = FSharpMap__TryFind(decls, resolvedName);
|
|
1051
|
+
if (matchValue_1 == null) {
|
|
1052
|
+
return new Type(12, [resolvedName]);
|
|
1053
|
+
}
|
|
1054
|
+
else {
|
|
1055
|
+
const def = matchValue_1;
|
|
1056
|
+
const matchValue_2 = tryFindIndex((y) => (resolvedName === y), stack);
|
|
1057
|
+
if (matchValue_2 == null) {
|
|
1058
|
+
if (!isEmpty(def.Cases)) {
|
|
1059
|
+
return new Type(12, [resolvedName]);
|
|
1060
|
+
}
|
|
1061
|
+
else {
|
|
1062
|
+
return new Type(8, [ofList(map((tupledArg) => [tupledArg[0], typeFromRef(decls, cons(resolvedName, stack), tupledArg[1])], def.Fields), {
|
|
1063
|
+
Compare: (x, y_1) => (comparePrimitives(x, y_1) | 0),
|
|
1064
|
+
})]);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
else if (matchValue_2 === 0) {
|
|
1068
|
+
if (def.IsRecursive) {
|
|
1069
|
+
return new Type(12, [resolvedName]);
|
|
1070
|
+
}
|
|
1071
|
+
else {
|
|
1072
|
+
throw new TypeException(new TypeError$(concat("Recursive type \'", resolvedName, "\' requires \'type rec\'"), unknownSpan));
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
else {
|
|
1076
|
+
throw new TypeException(new TypeError$("Mutual recursive types are not supported", unknownSpan));
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
else {
|
|
1081
|
+
return matchValue;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
function inferPattern(typeDefs, constructors, pat) {
|
|
1088
|
+
let table_5;
|
|
1089
|
+
switch (pat.tag) {
|
|
1090
|
+
case 1: {
|
|
1091
|
+
const name = pat.fields[0];
|
|
1092
|
+
const tv = Types_freshVar();
|
|
1093
|
+
recordLocalVariableDeclaration(name, Ast_spanOfPattern(pat), tv);
|
|
1094
|
+
return [ofList(singleton([name, tv]), {
|
|
1095
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
1096
|
+
}), tv];
|
|
1097
|
+
}
|
|
1098
|
+
case 2: {
|
|
1099
|
+
const lit = pat.fields[0];
|
|
1100
|
+
const t = (lit.tag === 1) ? (new Type(2, [])) : ((lit.tag === 2) ? (new Type(3, [])) : ((lit.tag === 3) ? (new Type(4, [])) : (new Type(1, []))));
|
|
1101
|
+
return [empty({
|
|
1102
|
+
Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
|
|
1103
|
+
}), t];
|
|
1104
|
+
}
|
|
1105
|
+
case 3: {
|
|
1106
|
+
const tv_1 = Types_freshVar();
|
|
1107
|
+
return [empty({
|
|
1108
|
+
Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
|
|
1109
|
+
}), new Type(5, [tv_1])];
|
|
1110
|
+
}
|
|
1111
|
+
case 4: {
|
|
1112
|
+
const startIndex = currentTelemetryCaptureCount() | 0;
|
|
1113
|
+
const patternInput = inferPattern(typeDefs, constructors, pat.fields[0]);
|
|
1114
|
+
const t1 = patternInput[1];
|
|
1115
|
+
const patternInput_1 = inferPattern(typeDefs, constructors, pat.fields[1]);
|
|
1116
|
+
const s = unify(empty({
|
|
1117
|
+
Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
|
|
1118
|
+
}), patternInput_1[1], new Type(5, [t1]), pat.fields[2]);
|
|
1119
|
+
applySubstToCapturedLocals(startIndex, s);
|
|
1120
|
+
return [map_1((_arg, ty) => applyType(s, ty), fold_1((acc, k, v) => add(k, v, acc), patternInput[0], patternInput_1[0])), applyType(s, new Type(5, [t1]))];
|
|
1121
|
+
}
|
|
1122
|
+
case 5: {
|
|
1123
|
+
const patternInput_3 = fold((tupledArg, p) => {
|
|
1124
|
+
const patternInput_2 = inferPattern(typeDefs, constructors, p);
|
|
1125
|
+
return [fold_1((acc_1, k_1, v_1) => add(k_1, v_1, acc_1), tupledArg[0], patternInput_2[0]), cons(patternInput_2[1], tupledArg[1])];
|
|
1126
|
+
}, [empty({
|
|
1127
|
+
Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
|
|
1128
|
+
}), empty_2()], pat.fields[0]);
|
|
1129
|
+
return [patternInput_3[0], new Type(7, [reverse(patternInput_3[1])])];
|
|
1130
|
+
}
|
|
1131
|
+
case 6: {
|
|
1132
|
+
const patternInput_5 = fold((tupledArg_1, tupledArg_2) => {
|
|
1133
|
+
const patternInput_4 = inferPattern(typeDefs, constructors, tupledArg_2[1]);
|
|
1134
|
+
return [fold_1((acc_2, k_2, v_2) => add(k_2, v_2, acc_2), tupledArg_1[0], patternInput_4[0]), add(tupledArg_2[0], patternInput_4[1], tupledArg_1[1])];
|
|
1135
|
+
}, [empty({
|
|
1136
|
+
Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
|
|
1137
|
+
}), empty({
|
|
1138
|
+
Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
|
|
1139
|
+
})], pat.fields[0]);
|
|
1140
|
+
return [patternInput_5[0], new Type(8, [patternInput_5[1]])];
|
|
1141
|
+
}
|
|
1142
|
+
case 7: {
|
|
1143
|
+
const tailPattern = pat.fields[1];
|
|
1144
|
+
const span_1 = pat.fields[2];
|
|
1145
|
+
const startIndex_1 = currentTelemetryCaptureCount() | 0;
|
|
1146
|
+
const ensureSupportedMapKeyType = (t_1) => {
|
|
1147
|
+
switch (t_1.tag) {
|
|
1148
|
+
case 4:
|
|
1149
|
+
case 15: {
|
|
1150
|
+
break;
|
|
1151
|
+
}
|
|
1152
|
+
default:
|
|
1153
|
+
throw new TypeException(new TypeError$(concat("Map key type must be string, got ", Types_typeToString(t_1)), span_1));
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1156
|
+
const mapKeyType = Types_freshVar();
|
|
1157
|
+
const valueType = Types_freshVar();
|
|
1158
|
+
let sAcc = emptySubst;
|
|
1159
|
+
let envAcc_2 = empty({
|
|
1160
|
+
Compare: (x_8, y_8) => (comparePrimitives(x_8, y_8) | 0),
|
|
1161
|
+
});
|
|
1162
|
+
const enumerator = getEnumerator(pat.fields[0]);
|
|
1163
|
+
try {
|
|
1164
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1165
|
+
const forLoopVar = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1166
|
+
const patternInput_6 = inferPattern(typeDefs, constructors, forLoopVar[0]);
|
|
1167
|
+
const patternInput_7 = inferPattern(typeDefs, constructors, forLoopVar[1]);
|
|
1168
|
+
const sKey = unify(typeDefs, applyType(sAcc, patternInput_6[1]), applyType(sAcc, mapKeyType), span_1);
|
|
1169
|
+
sAcc = compose(sKey, sAcc);
|
|
1170
|
+
ensureSupportedMapKeyType(applyType(sAcc, mapKeyType));
|
|
1171
|
+
const sValue = unify(typeDefs, applyType(sAcc, patternInput_7[1]), applyType(sAcc, valueType), span_1);
|
|
1172
|
+
sAcc = compose(sValue, sAcc);
|
|
1173
|
+
const mergedClauseEnv = map_1((_arg_1, t_2) => applyType(sAcc, t_2), fold_1((acc_3, k_3, v_3) => add(k_3, v_3, acc_3), patternInput_7[0], patternInput_6[0]));
|
|
1174
|
+
envAcc_2 = fold_1((acc_4, k_4, v_4) => add(k_4, v_4, acc_4), envAcc_2, mergedClauseEnv);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
finally {
|
|
1178
|
+
disposeSafe(enumerator);
|
|
1179
|
+
}
|
|
1180
|
+
if (tailPattern == null) {
|
|
1181
|
+
}
|
|
1182
|
+
else {
|
|
1183
|
+
const patternInput_8 = inferPattern(typeDefs, constructors, tailPattern);
|
|
1184
|
+
const expectedTailType = new Type(9, [applyType(sAcc, mapKeyType), applyType(sAcc, valueType)]);
|
|
1185
|
+
const sTail = unify(typeDefs, applyType(sAcc, patternInput_8[1]), expectedTailType, span_1);
|
|
1186
|
+
sAcc = compose(sTail, sAcc);
|
|
1187
|
+
envAcc_2 = ((table_5 = map_1((_arg_2, t_3) => applyType(sAcc, t_3), patternInput_8[0]), fold_1((acc_5, k_5, v_5) => add(k_5, v_5, acc_5), envAcc_2, table_5)));
|
|
1188
|
+
}
|
|
1189
|
+
ensureSupportedMapKeyType(applyType(sAcc, mapKeyType));
|
|
1190
|
+
applySubstToCapturedLocals(startIndex_1, sAcc);
|
|
1191
|
+
return [map_1((_arg_3, t_4) => applyType(sAcc, t_4), envAcc_2), new Type(9, [applyType(sAcc, mapKeyType), applyType(sAcc, valueType)])];
|
|
1192
|
+
}
|
|
1193
|
+
case 8: {
|
|
1194
|
+
const patternInput_9 = inferPattern(typeDefs, constructors, pat.fields[0]);
|
|
1195
|
+
return [patternInput_9[0], new Type(10, [patternInput_9[1]])];
|
|
1196
|
+
}
|
|
1197
|
+
case 9: {
|
|
1198
|
+
const tv_2 = Types_freshVar();
|
|
1199
|
+
return [empty({
|
|
1200
|
+
Compare: (x_9, y_9) => (comparePrimitives(x_9, y_9) | 0),
|
|
1201
|
+
}), new Type(10, [tv_2])];
|
|
1202
|
+
}
|
|
1203
|
+
case 10: {
|
|
1204
|
+
const span_2 = pat.fields[3];
|
|
1205
|
+
const qualifier = pat.fields[0];
|
|
1206
|
+
const payload = pat.fields[2];
|
|
1207
|
+
const caseName = pat.fields[1];
|
|
1208
|
+
const constructorName = (qualifier == null) ? caseName : concat(qualifier, ".", caseName);
|
|
1209
|
+
const matchValue = FSharpMap__TryFind(constructors, constructorName);
|
|
1210
|
+
if (matchValue != null) {
|
|
1211
|
+
const sigInfo = matchValue;
|
|
1212
|
+
const unionType = new Type(12, [sigInfo.UnionName]);
|
|
1213
|
+
const matchValue_1 = sigInfo.Payload;
|
|
1214
|
+
if (matchValue_1 != null) {
|
|
1215
|
+
if (payload == null) {
|
|
1216
|
+
throw new TypeException(new TypeError$(toText(printf("Union case \'%s\' requires a payload"))(constructorName), span_2));
|
|
1217
|
+
}
|
|
1218
|
+
else {
|
|
1219
|
+
const expectedPayload = matchValue_1;
|
|
1220
|
+
const payloadPattern = payload;
|
|
1221
|
+
const startIndex_2 = currentTelemetryCaptureCount() | 0;
|
|
1222
|
+
const patternInput_10 = inferPattern(typeDefs, constructors, payloadPattern);
|
|
1223
|
+
const s_1 = unify(typeDefs, patternInput_10[1], expectedPayload, span_2);
|
|
1224
|
+
applySubstToCapturedLocals(startIndex_2, s_1);
|
|
1225
|
+
return [map_1((_arg_4, t_6) => applyType(s_1, t_6), patternInput_10[0]), unionType];
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
else if (payload != null) {
|
|
1229
|
+
throw new TypeException(new TypeError$(toText(printf("Union case \'%s\' does not take a payload"))(constructorName), span_2));
|
|
1230
|
+
}
|
|
1231
|
+
else {
|
|
1232
|
+
return [empty({
|
|
1233
|
+
Compare: (x_10, y_10) => (comparePrimitives(x_10, y_10) | 0),
|
|
1234
|
+
}), unionType];
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
else {
|
|
1238
|
+
throw new TypeException(new TypeError$(toText(printf("Unknown union case \'%s\'"))(constructorName), span_2));
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
case 11:
|
|
1242
|
+
return [empty({
|
|
1243
|
+
Compare: (x_11, y_11) => (comparePrimitives(x_11, y_11) | 0),
|
|
1244
|
+
}), annotationTypeFromRef(typeDefs, pat.fields[1], pat.fields[0])];
|
|
1245
|
+
default:
|
|
1246
|
+
return [empty({
|
|
1247
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
1248
|
+
}), Types_freshVar()];
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
function numericResult(t, span) {
|
|
1253
|
+
switch (t.tag) {
|
|
1254
|
+
case 1:
|
|
1255
|
+
case 2:
|
|
1256
|
+
return t;
|
|
1257
|
+
case 15:
|
|
1258
|
+
return new Type(1, []);
|
|
1259
|
+
default:
|
|
1260
|
+
throw new TypeException(new TypeError$("Expected numeric type", span));
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
function validateMapKeyTypes(span, t) {
|
|
1265
|
+
const loop = (t_1_mut) => {
|
|
1266
|
+
loop:
|
|
1267
|
+
while (true) {
|
|
1268
|
+
const t_1 = t_1_mut;
|
|
1269
|
+
switch (t_1.tag) {
|
|
1270
|
+
case 9: {
|
|
1271
|
+
const keyType = t_1.fields[0];
|
|
1272
|
+
loop(keyType);
|
|
1273
|
+
loop(t_1.fields[1]);
|
|
1274
|
+
switch (keyType.tag) {
|
|
1275
|
+
case 4:
|
|
1276
|
+
case 15: {
|
|
1277
|
+
break;
|
|
1278
|
+
}
|
|
1279
|
+
default:
|
|
1280
|
+
throw new TypeException(new TypeError$(concat("Map key type must be string, got ", Types_typeToString(keyType)), span));
|
|
1281
|
+
}
|
|
1282
|
+
break;
|
|
1283
|
+
}
|
|
1284
|
+
case 5: {
|
|
1285
|
+
t_1_mut = t_1.fields[0];
|
|
1286
|
+
continue loop;
|
|
1287
|
+
break;
|
|
1288
|
+
}
|
|
1289
|
+
case 6: {
|
|
1290
|
+
t_1_mut = t_1.fields[0];
|
|
1291
|
+
continue loop;
|
|
1292
|
+
break;
|
|
1293
|
+
}
|
|
1294
|
+
case 7: {
|
|
1295
|
+
iterate(loop, t_1.fields[0]);
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
case 8: {
|
|
1299
|
+
iterate_1(loop, values(t_1.fields[0]));
|
|
1300
|
+
break;
|
|
1301
|
+
}
|
|
1302
|
+
case 10: {
|
|
1303
|
+
t_1_mut = t_1.fields[0];
|
|
1304
|
+
continue loop;
|
|
1305
|
+
break;
|
|
1306
|
+
}
|
|
1307
|
+
case 11: {
|
|
1308
|
+
loop(t_1.fields[0]);
|
|
1309
|
+
t_1_mut = t_1.fields[1];
|
|
1310
|
+
continue loop;
|
|
1311
|
+
break;
|
|
1312
|
+
}
|
|
1313
|
+
default:
|
|
1314
|
+
undefined;
|
|
1315
|
+
}
|
|
1316
|
+
break;
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
loop(t);
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
function inferExpr(typeDefs, constructors, env, expr) {
|
|
1323
|
+
let expectedReturn, expectedReturn_1;
|
|
1324
|
+
switch (expr.tag) {
|
|
1325
|
+
case 1: {
|
|
1326
|
+
const lit = expr.fields[0];
|
|
1327
|
+
const t = (lit.tag === 1) ? (new Type(2, [])) : ((lit.tag === 2) ? (new Type(3, [])) : ((lit.tag === 3) ? (new Type(4, [])) : (new Type(1, []))));
|
|
1328
|
+
return [emptySubst, t, asTyped(expr, t)];
|
|
1329
|
+
}
|
|
1330
|
+
case 2: {
|
|
1331
|
+
const span = expr.fields[1];
|
|
1332
|
+
const name = expr.fields[0];
|
|
1333
|
+
const matchValue = tryFind(name, env);
|
|
1334
|
+
if (matchValue == null) {
|
|
1335
|
+
throw new TypeException(new TypeError$(toText(printf("Unbound variable \'%s\'"))(name), span));
|
|
1336
|
+
}
|
|
1337
|
+
else {
|
|
1338
|
+
const t_1 = instantiate(matchValue);
|
|
1339
|
+
recordLocalVariableUse(name, span, t_1);
|
|
1340
|
+
return [emptySubst, t_1, asTyped(expr, t_1)];
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
case 3: {
|
|
1344
|
+
const patternInput = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
1345
|
+
const t_2 = patternInput[1];
|
|
1346
|
+
return [patternInput[0], t_2, asTyped(expr, t_2)];
|
|
1347
|
+
}
|
|
1348
|
+
case 28: {
|
|
1349
|
+
const name_1 = expr.fields[0];
|
|
1350
|
+
if (FSharpMap__ContainsKey(typeDefs, name_1)) {
|
|
1351
|
+
return [emptySubst, new Type(14, []), asTyped(expr, new Type(14, []))];
|
|
1352
|
+
}
|
|
1353
|
+
else {
|
|
1354
|
+
throw new TypeException(new TypeError$(toText(printf("Unknown type \'%s\'"))(name_1), expr.fields[1]));
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
case 29: {
|
|
1358
|
+
const name_2 = expr.fields[0];
|
|
1359
|
+
if (FSharpMap__ContainsKey(env, name_2)) {
|
|
1360
|
+
return [emptySubst, new Type(4, []), asTyped(expr, new Type(4, []))];
|
|
1361
|
+
}
|
|
1362
|
+
else {
|
|
1363
|
+
throw new TypeException(new TypeError$(toText(printf("Unbound variable \'%s\'"))(name_2), expr.fields[1]));
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
case 30: {
|
|
1367
|
+
let sAcc = emptySubst;
|
|
1368
|
+
const enumerator = getEnumerator(expr.fields[0]);
|
|
1369
|
+
try {
|
|
1370
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1371
|
+
const part = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1372
|
+
if (part.tag === 1) {
|
|
1373
|
+
const patternInput_1 = inferExpr(typeDefs, constructors, applyEnv(sAcc, env), part.fields[0]);
|
|
1374
|
+
sAcc = compose(patternInput_1[0], sAcc);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
finally {
|
|
1379
|
+
disposeSafe(enumerator);
|
|
1380
|
+
}
|
|
1381
|
+
return [sAcc, new Type(4, []), asTyped(expr, new Type(4, []))];
|
|
1382
|
+
}
|
|
1383
|
+
case 4: {
|
|
1384
|
+
const param = expr.fields[0];
|
|
1385
|
+
let tv;
|
|
1386
|
+
const matchValue_1 = param.Annotation;
|
|
1387
|
+
tv = ((matchValue_1 == null) ? Types_freshVar() : annotationTypeFromRef(typeDefs, param.Span, matchValue_1));
|
|
1388
|
+
recordLocalVariableDeclaration(param.Name, param.Span, tv);
|
|
1389
|
+
const env$0027 = add(param.Name, new Scheme(empty_2(), tv), env);
|
|
1390
|
+
const patternInput_2 = withLocalBindings(singleton(param.Name), () => inferExpr(typeDefs, constructors, env$0027, expr.fields[1]));
|
|
1391
|
+
const s1_1 = patternInput_2[0];
|
|
1392
|
+
const tFun = new Type(11, [applyType(s1_1, tv), patternInput_2[1]]);
|
|
1393
|
+
return [s1_1, tFun, asTyped(expr, tFun)];
|
|
1394
|
+
}
|
|
1395
|
+
case 5: {
|
|
1396
|
+
const patternInput_3 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
1397
|
+
const s1_2 = patternInput_3[0];
|
|
1398
|
+
const patternInput_4 = inferExpr(typeDefs, constructors, applyEnv(s1_2, env), expr.fields[1]);
|
|
1399
|
+
const s2 = patternInput_4[0];
|
|
1400
|
+
const tv_1 = Types_freshVar();
|
|
1401
|
+
const s_1 = compose(unify(typeDefs, applyType(s2, patternInput_3[1]), new Type(11, [patternInput_4[1], tv_1]), expr.fields[2]), compose(s2, s1_2));
|
|
1402
|
+
const tRes = applyType(s_1, tv_1);
|
|
1403
|
+
return [s_1, tRes, asTyped(expr, tRes)];
|
|
1404
|
+
}
|
|
1405
|
+
case 6: {
|
|
1406
|
+
const span_5 = expr.fields[3];
|
|
1407
|
+
const patternInput_5 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
1408
|
+
const s1_3 = patternInput_5[0];
|
|
1409
|
+
const sBool = unify(typeDefs, patternInput_5[1], new Type(3, []), span_5);
|
|
1410
|
+
const patternInput_6 = inferExpr(typeDefs, constructors, applyEnv(compose(sBool, s1_3), env), expr.fields[1]);
|
|
1411
|
+
const s2_1 = patternInput_6[0];
|
|
1412
|
+
const patternInput_7 = inferExpr(typeDefs, constructors, applyEnv(compose(s2_1, compose(sBool, s1_3)), env), expr.fields[2]);
|
|
1413
|
+
const tElse = patternInput_7[1];
|
|
1414
|
+
const s3_1 = patternInput_7[0];
|
|
1415
|
+
const s_2 = compose(unify(typeDefs, applyType(s3_1, patternInput_6[1]), tElse, span_5), compose(s3_1, compose(s2_1, compose(sBool, s1_3))));
|
|
1416
|
+
const tRes_1 = applyType(s_2, tElse);
|
|
1417
|
+
return [s_2, tRes_1, asTyped(expr, tRes_1)];
|
|
1418
|
+
}
|
|
1419
|
+
case 7: {
|
|
1420
|
+
const patternInput_8 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
1421
|
+
const s1_4 = patternInput_8[0];
|
|
1422
|
+
const s_3 = compose(unify(typeDefs, applyType(s1_4, patternInput_8[1]), new Type(4, []), expr.fields[1]), s1_4);
|
|
1423
|
+
const tRes_2 = Types_freshVar();
|
|
1424
|
+
return [s_3, tRes_2, asTyped(expr, tRes_2)];
|
|
1425
|
+
}
|
|
1426
|
+
case 8: {
|
|
1427
|
+
const name_3 = expr.fields[0];
|
|
1428
|
+
const body_1 = expr.fields[2];
|
|
1429
|
+
const patternInput_9 = inferExpr(typeDefs, constructors, env, expr.fields[1]);
|
|
1430
|
+
const s1_5 = patternInput_9[0];
|
|
1431
|
+
const tv_2 = Types_freshVar();
|
|
1432
|
+
const sSource = compose(unify(typeDefs, applyType(s1_5, patternInput_9[1]), new Type(5, [tv_2]), expr.fields[3]), s1_5);
|
|
1433
|
+
const envBody = add(name_3, new Scheme(empty_2(), applyType(sSource, tv_2)), applyEnv(sSource, env));
|
|
1434
|
+
const patternInput_10 = withLocalBindings(singleton(name_3), () => inferExpr(typeDefs, constructors, envBody, body_1));
|
|
1435
|
+
const s2_3 = patternInput_10[0];
|
|
1436
|
+
return [compose(unify(typeDefs, applyType(s2_3, patternInput_10[1]), new Type(0, []), Ast_spanOfExpr(body_1)), compose(s2_3, sSource)), new Type(0, []), asTyped(expr, new Type(0, []))];
|
|
1437
|
+
}
|
|
1438
|
+
case 10: {
|
|
1439
|
+
const value_3 = expr.fields[1];
|
|
1440
|
+
const span_8 = expr.fields[5];
|
|
1441
|
+
const returnAnnotation = expr.fields[4];
|
|
1442
|
+
const name_4 = expr.fields[0];
|
|
1443
|
+
const body_2 = expr.fields[2];
|
|
1444
|
+
if (expr.fields[3]) {
|
|
1445
|
+
const tv_3 = Types_freshVar();
|
|
1446
|
+
const envRec = add(name_4, new Scheme(empty_2(), tv_3), env);
|
|
1447
|
+
const patternInput_11 = withLocalBindings(singleton(name_4), () => inferExpr(typeDefs, constructors, envRec, value_3));
|
|
1448
|
+
const t1_2 = patternInput_11[1];
|
|
1449
|
+
const s1_6 = patternInput_11[0];
|
|
1450
|
+
const s2_4 = unify(typeDefs, applyType(s1_6, tv_3), t1_2, span_8);
|
|
1451
|
+
const sValue = compose((returnAnnotation == null) ? emptySubst : ((expectedReturn = annotationTypeFromRef(typeDefs, span_8, returnAnnotation), unify(typeDefs, functionReturnType(applyType(s2_4, t1_2)), expectedReturn, span_8))), compose(s2_4, s1_6));
|
|
1452
|
+
const env1 = applyEnv(sValue, env);
|
|
1453
|
+
const env2_2 = add(name_4, Types_generalize(env1, applyType(sValue, t1_2)), env1);
|
|
1454
|
+
const patternInput_12 = withLocalBindings(singleton(name_4), () => inferExpr(typeDefs, constructors, env2_2, body_2));
|
|
1455
|
+
const tBody_2 = patternInput_12[1];
|
|
1456
|
+
return [compose(patternInput_12[0], sValue), tBody_2, asTyped(expr, tBody_2)];
|
|
1457
|
+
}
|
|
1458
|
+
else {
|
|
1459
|
+
const patternInput_13 = inferExpr(typeDefs, constructors, env, value_3);
|
|
1460
|
+
const t1_3 = patternInput_13[1];
|
|
1461
|
+
const s1_7 = patternInput_13[0];
|
|
1462
|
+
const sDiscard = (name_4 === "_") ? unify(typeDefs, applyType(s1_7, t1_3), new Type(0, []), Ast_spanOfExpr(value_3)) : emptySubst;
|
|
1463
|
+
const sValue_1 = compose((returnAnnotation == null) ? emptySubst : ((expectedReturn_1 = annotationTypeFromRef(typeDefs, span_8, returnAnnotation), unify(typeDefs, functionReturnType(applyType(sDiscard, t1_3)), expectedReturn_1, span_8))), compose(sDiscard, s1_7));
|
|
1464
|
+
const env1_1 = applyEnv(sValue_1, env);
|
|
1465
|
+
const env2_3 = add(name_4, Types_generalize(env1_1, applyType(sValue_1, t1_3)), env1_1);
|
|
1466
|
+
const patternInput_14 = withLocalBindings(singleton(name_4), () => inferExpr(typeDefs, constructors, env2_3, body_2));
|
|
1467
|
+
const t2_1 = patternInput_14[1];
|
|
1468
|
+
return [compose(patternInput_14[0], sValue_1), t2_1, asTyped(expr, t2_1)];
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
case 11: {
|
|
1472
|
+
const startIndex = currentTelemetryCaptureCount() | 0;
|
|
1473
|
+
const patternInput_15 = inferExpr(typeDefs, constructors, env, expr.fields[1]);
|
|
1474
|
+
const s1_8 = patternInput_15[0];
|
|
1475
|
+
const patternInput_16 = inferPattern(typeDefs, constructors, expr.fields[0]);
|
|
1476
|
+
const sValue_2 = compose(unify(typeDefs, applyType(s1_8, patternInput_15[1]), patternInput_16[1], expr.fields[3]), s1_8);
|
|
1477
|
+
applySubstToCapturedLocals(startIndex, sValue_2);
|
|
1478
|
+
const env1_2 = applyEnv(sValue_2, env);
|
|
1479
|
+
const envPatTyped = map_1((_arg, ty) => applyType(sValue_2, ty), patternInput_16[0]);
|
|
1480
|
+
const env2_4 = fold_1((state, name_5, bindingType) => add(name_5, Types_generalize(env1_2, bindingType), state), env1_2, envPatTyped);
|
|
1481
|
+
const patternInput_17 = withLocalBindings(map((tuple) => tuple[0], toList(envPatTyped)), () => inferExpr(typeDefs, constructors, env2_4, expr.fields[2]));
|
|
1482
|
+
const tBody_3 = patternInput_17[1];
|
|
1483
|
+
return [compose(patternInput_17[0], sValue_2), tBody_3, asTyped(expr, tBody_3)];
|
|
1484
|
+
}
|
|
1485
|
+
case 12: {
|
|
1486
|
+
const foldedBindings = map((tupledArg) => {
|
|
1487
|
+
const args = tupledArg[1];
|
|
1488
|
+
const bindingSpan = tupledArg[4];
|
|
1489
|
+
if (isEmpty(args)) {
|
|
1490
|
+
throw new TypeException(new TypeError$("\'let rec ... and ...\' requires function arguments for each binding", bindingSpan));
|
|
1491
|
+
}
|
|
1492
|
+
return [tupledArg[0], tupledArg[2], foldBack((arg_4, acc) => (new Expr(4, [arg_4, acc, bindingSpan])), args, tupledArg[3]), bindingSpan];
|
|
1493
|
+
}, expr.fields[0]);
|
|
1494
|
+
const freshByName = ofList(map((tupledArg_1) => [tupledArg_1[0], Types_freshVar()], foldedBindings), {
|
|
1495
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
1496
|
+
});
|
|
1497
|
+
const envRec_1 = fold_1((acc_1, name_8, tv_4) => add(name_8, new Scheme(empty_2(), tv_4), acc_1), env, freshByName);
|
|
1498
|
+
let sRec = emptySubst;
|
|
1499
|
+
const recursiveNames = map((tuple_1) => tuple_1[0], toList(freshByName));
|
|
1500
|
+
withLocalBindings(recursiveNames, () => {
|
|
1501
|
+
const enumerator_1 = getEnumerator(foldedBindings);
|
|
1502
|
+
try {
|
|
1503
|
+
while (enumerator_1["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1504
|
+
const forLoopVar = enumerator_1["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1505
|
+
const patternInput_18 = inferExpr(typeDefs, constructors, applyEnv(sRec, envRec_1), forLoopVar[2]);
|
|
1506
|
+
const s1_9 = patternInput_18[0];
|
|
1507
|
+
const s2_7 = unify(typeDefs, applyType(s1_9, applyType(sRec, FSharpMap__get_Item(freshByName, forLoopVar[0]))), patternInput_18[1], forLoopVar[3]);
|
|
1508
|
+
sRec = compose(s2_7, compose(s1_9, sRec));
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
finally {
|
|
1512
|
+
disposeSafe(enumerator_1);
|
|
1513
|
+
}
|
|
1514
|
+
});
|
|
1515
|
+
const enumerator_2 = getEnumerator(foldedBindings);
|
|
1516
|
+
try {
|
|
1517
|
+
while (enumerator_2["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1518
|
+
const forLoopVar_1 = enumerator_2["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1519
|
+
const returnAnnotation_2 = forLoopVar_1[1];
|
|
1520
|
+
const bindingSpan_2 = forLoopVar_1[3];
|
|
1521
|
+
if (returnAnnotation_2 == null) {
|
|
1522
|
+
}
|
|
1523
|
+
else {
|
|
1524
|
+
const expectedReturn_2 = annotationTypeFromRef(typeDefs, bindingSpan_2, returnAnnotation_2);
|
|
1525
|
+
const sRet_2 = unify(typeDefs, functionReturnType(applyType(sRec, FSharpMap__get_Item(freshByName, forLoopVar_1[0]))), expectedReturn_2, bindingSpan_2);
|
|
1526
|
+
sRec = compose(sRet_2, sRec);
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
finally {
|
|
1531
|
+
disposeSafe(enumerator_2);
|
|
1532
|
+
}
|
|
1533
|
+
const envGeneralize = applyEnv(sRec, env);
|
|
1534
|
+
const envBody_1 = fold((acc_2, tupledArg_3) => add(tupledArg_3[0], tupledArg_3[1], acc_2), envGeneralize, map((tupledArg_2) => {
|
|
1535
|
+
const name_11 = tupledArg_2[0];
|
|
1536
|
+
return [name_11, Types_generalize(envGeneralize, applyType(sRec, FSharpMap__get_Item(freshByName, name_11)))];
|
|
1537
|
+
}, foldedBindings));
|
|
1538
|
+
const patternInput_19 = withLocalBindings(recursiveNames, () => inferExpr(typeDefs, constructors, envBody_1, expr.fields[1]));
|
|
1539
|
+
const tBody_4 = patternInput_19[1];
|
|
1540
|
+
return [compose(patternInput_19[0], sRec), tBody_4, asTyped(expr, tBody_4)];
|
|
1541
|
+
}
|
|
1542
|
+
case 9: {
|
|
1543
|
+
const patternInput_20 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
1544
|
+
const tScrut = patternInput_20[1];
|
|
1545
|
+
let sAcc_1 = patternInput_20[0];
|
|
1546
|
+
let resultTypeOpt = undefined;
|
|
1547
|
+
const enumerator_3 = getEnumerator(expr.fields[1]);
|
|
1548
|
+
try {
|
|
1549
|
+
while (enumerator_3["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1550
|
+
let tPrev, sEq;
|
|
1551
|
+
const forLoopVar_2 = enumerator_3["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1552
|
+
const pat_1 = forLoopVar_2[0];
|
|
1553
|
+
const guard = forLoopVar_2[1];
|
|
1554
|
+
const caseSpan = forLoopVar_2[3];
|
|
1555
|
+
const patternInput_21 = inferPattern(typeDefs, constructors, pat_1);
|
|
1556
|
+
const tPat_1 = patternInput_21[1];
|
|
1557
|
+
const envPat_1 = patternInput_21[0];
|
|
1558
|
+
let sPat;
|
|
1559
|
+
const matchValue_2 = applyType(sAcc_1, tScrut);
|
|
1560
|
+
let matchResult, patFields, scrutFields, patFields_1, typeName;
|
|
1561
|
+
if (pat_1.tag === 6) {
|
|
1562
|
+
switch (matchValue_2.tag) {
|
|
1563
|
+
case 8: {
|
|
1564
|
+
if (tPat_1.tag === 8) {
|
|
1565
|
+
matchResult = 0;
|
|
1566
|
+
patFields = tPat_1.fields[0];
|
|
1567
|
+
scrutFields = matchValue_2.fields[0];
|
|
1568
|
+
}
|
|
1569
|
+
else {
|
|
1570
|
+
matchResult = 2;
|
|
1571
|
+
}
|
|
1572
|
+
break;
|
|
1573
|
+
}
|
|
1574
|
+
case 12: {
|
|
1575
|
+
if (tPat_1.tag === 8) {
|
|
1576
|
+
matchResult = 1;
|
|
1577
|
+
patFields_1 = tPat_1.fields[0];
|
|
1578
|
+
typeName = matchValue_2.fields[0];
|
|
1579
|
+
}
|
|
1580
|
+
else {
|
|
1581
|
+
matchResult = 2;
|
|
1582
|
+
}
|
|
1583
|
+
break;
|
|
1584
|
+
}
|
|
1585
|
+
default:
|
|
1586
|
+
matchResult = 2;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
else {
|
|
1590
|
+
matchResult = 3;
|
|
1591
|
+
}
|
|
1592
|
+
switch (matchResult) {
|
|
1593
|
+
case 0: {
|
|
1594
|
+
sPat = fold_1((sLocal, field, patTy) => {
|
|
1595
|
+
const matchValue_4 = FSharpMap__TryFind(scrutFields, field);
|
|
1596
|
+
if (matchValue_4 == null) {
|
|
1597
|
+
throw new TypeException(new TypeError$(toText(printf("Record field \'%s\' not found"))(field), caseSpan));
|
|
1598
|
+
}
|
|
1599
|
+
else {
|
|
1600
|
+
return compose(unify(typeDefs, applyType(sLocal, matchValue_4), applyType(sLocal, patTy), caseSpan), sLocal);
|
|
1601
|
+
}
|
|
1602
|
+
}, emptySubst, patFields);
|
|
1603
|
+
break;
|
|
1604
|
+
}
|
|
1605
|
+
case 1: {
|
|
1606
|
+
const matchValue_5 = FSharpMap__TryFind(typeDefs, typeName);
|
|
1607
|
+
let matchResult_1, scrutFields_1;
|
|
1608
|
+
if (matchValue_5 != null) {
|
|
1609
|
+
if (matchValue_5.tag === 8) {
|
|
1610
|
+
matchResult_1 = 0;
|
|
1611
|
+
scrutFields_1 = matchValue_5.fields[0];
|
|
1612
|
+
}
|
|
1613
|
+
else {
|
|
1614
|
+
matchResult_1 = 1;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
else {
|
|
1618
|
+
matchResult_1 = 1;
|
|
1619
|
+
}
|
|
1620
|
+
switch (matchResult_1) {
|
|
1621
|
+
case 0: {
|
|
1622
|
+
sPat = fold_1((sLocal_1, field_1, patTy_1) => {
|
|
1623
|
+
const matchValue_6 = FSharpMap__TryFind(scrutFields_1, field_1);
|
|
1624
|
+
if (matchValue_6 == null) {
|
|
1625
|
+
throw new TypeException(new TypeError$(toText(printf("Record field \'%s\' not found"))(field_1), caseSpan));
|
|
1626
|
+
}
|
|
1627
|
+
else {
|
|
1628
|
+
return compose(unify(typeDefs, applyType(sLocal_1, matchValue_6), applyType(sLocal_1, patTy_1), caseSpan), sLocal_1);
|
|
1629
|
+
}
|
|
1630
|
+
}, emptySubst, patFields_1);
|
|
1631
|
+
break;
|
|
1632
|
+
}
|
|
1633
|
+
default:
|
|
1634
|
+
throw new TypeException(new TypeError$("Record pattern requires a concrete record scrutinee type", caseSpan));
|
|
1635
|
+
}
|
|
1636
|
+
break;
|
|
1637
|
+
}
|
|
1638
|
+
case 2: {
|
|
1639
|
+
throw new TypeException(new TypeError$("Record pattern requires a concrete record scrutinee type", caseSpan));
|
|
1640
|
+
break;
|
|
1641
|
+
}
|
|
1642
|
+
default:
|
|
1643
|
+
sPat = unify(typeDefs, applyType(sAcc_1, tScrut), tPat_1, caseSpan);
|
|
1644
|
+
}
|
|
1645
|
+
const envCase$0027 = fold_1((acc_3, k, v) => add(k, new Scheme(empty_2(), applyType(sPat, v)), acc_3), applyEnv(compose(sPat, sAcc_1), env), envPat_1);
|
|
1646
|
+
const patternInput_23 = withLocalBindings(map((tuple_2) => tuple_2[0], toList(envPat_1)), () => {
|
|
1647
|
+
let envBodyCase = envCase$0027;
|
|
1648
|
+
if (guard == null) {
|
|
1649
|
+
}
|
|
1650
|
+
else {
|
|
1651
|
+
const guardExpr = guard;
|
|
1652
|
+
const patternInput_22 = inferExpr(typeDefs, constructors, envBodyCase, guardExpr);
|
|
1653
|
+
const sGuard = patternInput_22[0];
|
|
1654
|
+
const sGuardBool = unify(typeDefs, applyType(sGuard, patternInput_22[1]), new Type(3, []), caseSpan);
|
|
1655
|
+
sAcc_1 = compose(sGuardBool, compose(sGuard, sAcc_1));
|
|
1656
|
+
envBodyCase = applyEnv(compose(sGuardBool, sGuard), envBodyCase);
|
|
1657
|
+
}
|
|
1658
|
+
return inferExpr(typeDefs, constructors, envBodyCase, forLoopVar_2[2]);
|
|
1659
|
+
});
|
|
1660
|
+
const sBody_2 = patternInput_23[0];
|
|
1661
|
+
const tBody$0027 = applyType(sBody_2, patternInput_23[1]);
|
|
1662
|
+
resultTypeOpt = ((resultTypeOpt != null) ? ((tPrev = resultTypeOpt, (sEq = unify(typeDefs, tPrev, tBody$0027, caseSpan), (sAcc_1 = compose(sEq, sAcc_1), applyType(sEq, tPrev))))) : tBody$0027);
|
|
1663
|
+
sAcc_1 = compose(sBody_2, compose(sPat, sAcc_1));
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
finally {
|
|
1667
|
+
disposeSafe(enumerator_3);
|
|
1668
|
+
}
|
|
1669
|
+
const tRes_3 = defaultArg(resultTypeOpt, Types_freshVar());
|
|
1670
|
+
return [sAcc_1, tRes_3, asTyped(expr, tRes_3)];
|
|
1671
|
+
}
|
|
1672
|
+
case 13: {
|
|
1673
|
+
const tv_5 = Types_freshVar();
|
|
1674
|
+
let sAcc_2 = emptySubst;
|
|
1675
|
+
const enumerator_4 = getEnumerator(expr.fields[0]);
|
|
1676
|
+
try {
|
|
1677
|
+
while (enumerator_4["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1678
|
+
const item = enumerator_4["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1679
|
+
const patternInput_24 = inferExpr(typeDefs, constructors, applyEnv(sAcc_2, env), item);
|
|
1680
|
+
const s1_11 = patternInput_24[0];
|
|
1681
|
+
const s2_8 = unify(typeDefs, applyType(s1_11, tv_5), patternInput_24[1], expr.fields[1]);
|
|
1682
|
+
sAcc_2 = compose(s2_8, compose(s1_11, sAcc_2));
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
finally {
|
|
1686
|
+
disposeSafe(enumerator_4);
|
|
1687
|
+
}
|
|
1688
|
+
const tRes_4 = new Type(5, [applyType(sAcc_2, tv_5)]);
|
|
1689
|
+
return [sAcc_2, tRes_4, asTyped(expr, tRes_4)];
|
|
1690
|
+
}
|
|
1691
|
+
case 14: {
|
|
1692
|
+
const span_13 = expr.fields[2];
|
|
1693
|
+
const patternInput_25 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
1694
|
+
const s1_12 = patternInput_25[0];
|
|
1695
|
+
const patternInput_26 = inferExpr(typeDefs, constructors, applyEnv(s1_12, env), expr.fields[1]);
|
|
1696
|
+
const s2_9 = patternInput_26[0];
|
|
1697
|
+
const s3_3 = unify(typeDefs, applyType(s2_9, patternInput_25[1]), new Type(1, []), span_13);
|
|
1698
|
+
const tRes_5 = new Type(5, [new Type(1, [])]);
|
|
1699
|
+
return [compose(unify(typeDefs, applyType(s3_3, applyType(s2_9, patternInput_26[1])), new Type(1, []), span_13), compose(s3_3, compose(s2_9, s1_12))), tRes_5, asTyped(expr, tRes_5)];
|
|
1700
|
+
}
|
|
1701
|
+
case 15: {
|
|
1702
|
+
let sAcc_3 = emptySubst;
|
|
1703
|
+
let inferred_1 = empty_2();
|
|
1704
|
+
const enumerator_5 = getEnumerator(expr.fields[0]);
|
|
1705
|
+
try {
|
|
1706
|
+
while (enumerator_5["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1707
|
+
const item_1 = enumerator_5["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1708
|
+
const patternInput_27 = inferExpr(typeDefs, constructors, applyEnv(sAcc_3, env), item_1);
|
|
1709
|
+
sAcc_3 = compose(patternInput_27[0], sAcc_3);
|
|
1710
|
+
inferred_1 = append(inferred_1, singleton(applyType(sAcc_3, patternInput_27[1])));
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
finally {
|
|
1714
|
+
disposeSafe(enumerator_5);
|
|
1715
|
+
}
|
|
1716
|
+
const tRes_6 = new Type(7, [inferred_1]);
|
|
1717
|
+
return [sAcc_3, tRes_6, asTyped(expr, tRes_6)];
|
|
1718
|
+
}
|
|
1719
|
+
case 16: {
|
|
1720
|
+
const span_14 = expr.fields[1];
|
|
1721
|
+
let sAcc_4 = emptySubst;
|
|
1722
|
+
let inferred_2 = empty({
|
|
1723
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
1724
|
+
});
|
|
1725
|
+
const enumerator_6 = getEnumerator(expr.fields[0]);
|
|
1726
|
+
try {
|
|
1727
|
+
while (enumerator_6["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1728
|
+
const forLoopVar_3 = enumerator_6["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1729
|
+
const patternInput_28 = inferExpr(typeDefs, constructors, applyEnv(sAcc_4, env), forLoopVar_3[1]);
|
|
1730
|
+
sAcc_4 = compose(patternInput_28[0], sAcc_4);
|
|
1731
|
+
inferred_2 = FSharpMap__Add(inferred_2, forLoopVar_3[0], applyType(sAcc_4, patternInput_28[1]));
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
finally {
|
|
1735
|
+
disposeSafe(enumerator_6);
|
|
1736
|
+
}
|
|
1737
|
+
const expected_1 = new Type(12, [resolveNamedRecordByFieldSet(typeDefs, ofSeq(keys(inferred_2), {
|
|
1738
|
+
Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
|
|
1739
|
+
}), span_14)]);
|
|
1740
|
+
const s_10 = compose(unify(typeDefs, applyType(sAcc_4, new Type(8, [inferred_2])), expected_1, span_14), sAcc_4);
|
|
1741
|
+
const tRes_7 = applyType(s_10, expected_1);
|
|
1742
|
+
return [s_10, tRes_7, asTyped(expr, tRes_7)];
|
|
1743
|
+
}
|
|
1744
|
+
case 17: {
|
|
1745
|
+
let sAcc_5 = emptySubst;
|
|
1746
|
+
let inferred_3 = empty({
|
|
1747
|
+
Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
|
|
1748
|
+
});
|
|
1749
|
+
const enumerator_7 = getEnumerator(expr.fields[0]);
|
|
1750
|
+
try {
|
|
1751
|
+
while (enumerator_7["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1752
|
+
const forLoopVar_4 = enumerator_7["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1753
|
+
const patternInput_29 = inferExpr(typeDefs, constructors, applyEnv(sAcc_5, env), forLoopVar_4[1]);
|
|
1754
|
+
sAcc_5 = compose(patternInput_29[0], sAcc_5);
|
|
1755
|
+
inferred_3 = FSharpMap__Add(inferred_3, forLoopVar_4[0], applyType(sAcc_5, patternInput_29[1]));
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
finally {
|
|
1759
|
+
disposeSafe(enumerator_7);
|
|
1760
|
+
}
|
|
1761
|
+
const tRes_8 = new Type(8, [inferred_3]);
|
|
1762
|
+
return [sAcc_5, tRes_8, asTyped(expr, tRes_8)];
|
|
1763
|
+
}
|
|
1764
|
+
case 18: {
|
|
1765
|
+
const ensureSupportedMapKeyType = (t_3) => {
|
|
1766
|
+
switch (t_3.tag) {
|
|
1767
|
+
case 4:
|
|
1768
|
+
case 15: {
|
|
1769
|
+
break;
|
|
1770
|
+
}
|
|
1771
|
+
default:
|
|
1772
|
+
throw new TypeException(new TypeError$(concat("Map key type must be string, got ", Types_typeToString(t_3)), expr.fields[1]));
|
|
1773
|
+
}
|
|
1774
|
+
};
|
|
1775
|
+
const keyType = Types_freshVar();
|
|
1776
|
+
const valueType = Types_freshVar();
|
|
1777
|
+
let sAcc_6 = emptySubst;
|
|
1778
|
+
const enumerator_8 = getEnumerator(expr.fields[0]);
|
|
1779
|
+
try {
|
|
1780
|
+
while (enumerator_8["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1781
|
+
const entry = enumerator_8["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1782
|
+
if (entry.tag === 1) {
|
|
1783
|
+
const spreadExpr = entry.fields[0];
|
|
1784
|
+
const patternInput_32 = inferExpr(typeDefs, constructors, applyEnv(sAcc_6, env), spreadExpr);
|
|
1785
|
+
const sSpread = patternInput_32[0];
|
|
1786
|
+
const expectedSpreadType = new Type(9, [applyType(sSpread, applyType(sAcc_6, keyType)), applyType(sSpread, applyType(sAcc_6, valueType))]);
|
|
1787
|
+
const sSpreadMap = unify(typeDefs, applyType(sSpread, patternInput_32[1]), expectedSpreadType, Ast_spanOfExpr(spreadExpr));
|
|
1788
|
+
sAcc_6 = compose(sSpreadMap, compose(sSpread, sAcc_6));
|
|
1789
|
+
}
|
|
1790
|
+
else {
|
|
1791
|
+
const valueExpr_3 = entry.fields[1];
|
|
1792
|
+
const keyExpr = entry.fields[0];
|
|
1793
|
+
const patternInput_30 = inferExpr(typeDefs, constructors, applyEnv(sAcc_6, env), keyExpr);
|
|
1794
|
+
const sKey = patternInput_30[0];
|
|
1795
|
+
const sAfterKey = compose(unify(typeDefs, applyType(sKey, patternInput_30[1]), applyType(sKey, applyType(sAcc_6, keyType)), Ast_spanOfExpr(keyExpr)), compose(sKey, sAcc_6));
|
|
1796
|
+
ensureSupportedMapKeyType(applyType(sAfterKey, keyType));
|
|
1797
|
+
const patternInput_31 = inferExpr(typeDefs, constructors, applyEnv(sAfterKey, env), valueExpr_3);
|
|
1798
|
+
const sValue_3 = patternInput_31[0];
|
|
1799
|
+
const sValueType = unify(typeDefs, applyType(sValue_3, applyType(sAfterKey, valueType)), patternInput_31[1], Ast_spanOfExpr(valueExpr_3));
|
|
1800
|
+
sAcc_6 = compose(sValueType, compose(sValue_3, sAfterKey));
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
finally {
|
|
1805
|
+
disposeSafe(enumerator_8);
|
|
1806
|
+
}
|
|
1807
|
+
ensureSupportedMapKeyType(applyType(sAcc_6, keyType));
|
|
1808
|
+
const tRes_9 = new Type(9, [applyType(sAcc_6, keyType), applyType(sAcc_6, valueType)]);
|
|
1809
|
+
return [sAcc_6, tRes_9, asTyped(expr, tRes_9)];
|
|
1810
|
+
}
|
|
1811
|
+
case 19: {
|
|
1812
|
+
const span_16 = expr.fields[2];
|
|
1813
|
+
const patternInput_33 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
1814
|
+
const sBase = patternInput_33[0];
|
|
1815
|
+
let baseFields;
|
|
1816
|
+
const matchValue_7 = applyType(sBase, patternInput_33[1]);
|
|
1817
|
+
switch (matchValue_7.tag) {
|
|
1818
|
+
case 8: {
|
|
1819
|
+
baseFields = matchValue_7.fields[0];
|
|
1820
|
+
break;
|
|
1821
|
+
}
|
|
1822
|
+
case 12: {
|
|
1823
|
+
const matchValue_8 = FSharpMap__TryFind(typeDefs, matchValue_7.fields[0]);
|
|
1824
|
+
let matchResult_2, fields_3;
|
|
1825
|
+
if (matchValue_8 != null) {
|
|
1826
|
+
if (matchValue_8.tag === 8) {
|
|
1827
|
+
matchResult_2 = 0;
|
|
1828
|
+
fields_3 = matchValue_8.fields[0];
|
|
1829
|
+
}
|
|
1830
|
+
else {
|
|
1831
|
+
matchResult_2 = 1;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
else {
|
|
1835
|
+
matchResult_2 = 1;
|
|
1836
|
+
}
|
|
1837
|
+
switch (matchResult_2) {
|
|
1838
|
+
case 0: {
|
|
1839
|
+
baseFields = fields_3;
|
|
1840
|
+
break;
|
|
1841
|
+
}
|
|
1842
|
+
default:
|
|
1843
|
+
throw new TypeException(new TypeError$("Record update requires a record value", span_16));
|
|
1844
|
+
}
|
|
1845
|
+
break;
|
|
1846
|
+
}
|
|
1847
|
+
default:
|
|
1848
|
+
throw new TypeException(new TypeError$("Record update requires a record value", span_16));
|
|
1849
|
+
}
|
|
1850
|
+
let sAcc_7 = sBase;
|
|
1851
|
+
const enumerator_9 = getEnumerator(expr.fields[1]);
|
|
1852
|
+
try {
|
|
1853
|
+
while (enumerator_9["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1854
|
+
const forLoopVar_5 = enumerator_9["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1855
|
+
const valueExpr_4 = forLoopVar_5[1];
|
|
1856
|
+
const name_16 = forLoopVar_5[0];
|
|
1857
|
+
let expectedFieldType;
|
|
1858
|
+
const matchValue_9 = FSharpMap__TryFind(baseFields, name_16);
|
|
1859
|
+
if (matchValue_9 == null) {
|
|
1860
|
+
throw new TypeException(new TypeError$(toText(printf("Record field \'%s\' not found"))(name_16), Ast_spanOfExpr(valueExpr_4)));
|
|
1861
|
+
}
|
|
1862
|
+
else {
|
|
1863
|
+
expectedFieldType = matchValue_9;
|
|
1864
|
+
}
|
|
1865
|
+
const patternInput_34 = inferExpr(typeDefs, constructors, applyEnv(sAcc_7, env), valueExpr_4);
|
|
1866
|
+
const sField_2 = patternInput_34[0];
|
|
1867
|
+
const sEq_1 = unify(typeDefs, applyType(sField_2, applyType(sAcc_7, expectedFieldType)), patternInput_34[1], Ast_spanOfExpr(valueExpr_4));
|
|
1868
|
+
sAcc_7 = compose(sEq_1, compose(sField_2, sAcc_7));
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
finally {
|
|
1872
|
+
disposeSafe(enumerator_9);
|
|
1873
|
+
}
|
|
1874
|
+
const tRes_10 = new Type(8, [map_1((_arg_7, t_5) => applyType(sAcc_7, t_5), baseFields)]);
|
|
1875
|
+
return [sAcc_7, tRes_10, asTyped(expr, tRes_10)];
|
|
1876
|
+
}
|
|
1877
|
+
case 20: {
|
|
1878
|
+
const span_17 = expr.fields[2];
|
|
1879
|
+
const patternInput_35 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
1880
|
+
const sBase_1 = patternInput_35[0];
|
|
1881
|
+
let sAcc_8 = sBase_1;
|
|
1882
|
+
let resultFields_1;
|
|
1883
|
+
const matchValue_10 = applyType(sBase_1, patternInput_35[1]);
|
|
1884
|
+
switch (matchValue_10.tag) {
|
|
1885
|
+
case 8: {
|
|
1886
|
+
resultFields_1 = matchValue_10.fields[0];
|
|
1887
|
+
break;
|
|
1888
|
+
}
|
|
1889
|
+
case 12: {
|
|
1890
|
+
const matchValue_11 = FSharpMap__TryFind(typeDefs, matchValue_10.fields[0]);
|
|
1891
|
+
let matchResult_3, fields_5;
|
|
1892
|
+
if (matchValue_11 != null) {
|
|
1893
|
+
if (matchValue_11.tag === 8) {
|
|
1894
|
+
matchResult_3 = 0;
|
|
1895
|
+
fields_5 = matchValue_11.fields[0];
|
|
1896
|
+
}
|
|
1897
|
+
else {
|
|
1898
|
+
matchResult_3 = 1;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
else {
|
|
1902
|
+
matchResult_3 = 1;
|
|
1903
|
+
}
|
|
1904
|
+
switch (matchResult_3) {
|
|
1905
|
+
case 0: {
|
|
1906
|
+
resultFields_1 = fields_5;
|
|
1907
|
+
break;
|
|
1908
|
+
}
|
|
1909
|
+
default:
|
|
1910
|
+
throw new TypeException(new TypeError$("Structural record update requires a record value", span_17));
|
|
1911
|
+
}
|
|
1912
|
+
break;
|
|
1913
|
+
}
|
|
1914
|
+
default:
|
|
1915
|
+
throw new TypeException(new TypeError$("Structural record update requires a record value", span_17));
|
|
1916
|
+
}
|
|
1917
|
+
const enumerator_10 = getEnumerator(expr.fields[1]);
|
|
1918
|
+
try {
|
|
1919
|
+
while (enumerator_10["System.Collections.IEnumerator.MoveNext"]()) {
|
|
1920
|
+
let matchValue_12, existingFieldType, table_17;
|
|
1921
|
+
const forLoopVar_6 = enumerator_10["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
1922
|
+
const valueExpr_5 = forLoopVar_6[1];
|
|
1923
|
+
const name_18 = forLoopVar_6[0];
|
|
1924
|
+
const patternInput_36 = inferExpr(typeDefs, constructors, applyEnv(sAcc_8, env), valueExpr_5);
|
|
1925
|
+
const sField_3 = patternInput_36[0];
|
|
1926
|
+
const tFieldApplied = applyType(sField_3, patternInput_36[1]);
|
|
1927
|
+
const sEq_2 = unify(typeDefs, (matchValue_12 = FSharpMap__TryFind(resultFields_1, name_18), (matchValue_12 == null) ? tFieldApplied : ((existingFieldType = matchValue_12, applyType(sField_3, applyType(sAcc_8, existingFieldType))))), tFieldApplied, Ast_spanOfExpr(valueExpr_5));
|
|
1928
|
+
sAcc_8 = compose(sEq_2, compose(sField_3, sAcc_8));
|
|
1929
|
+
resultFields_1 = ((table_17 = resultFields_1, add(name_18, applyType(sAcc_8, tFieldApplied), table_17)));
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
finally {
|
|
1933
|
+
disposeSafe(enumerator_10);
|
|
1934
|
+
}
|
|
1935
|
+
const tRes_11 = new Type(8, [map_1((_arg_8, t_6) => applyType(sAcc_8, t_6), resultFields_1)]);
|
|
1936
|
+
return [sAcc_8, tRes_11, asTyped(expr, tRes_11)];
|
|
1937
|
+
}
|
|
1938
|
+
case 21: {
|
|
1939
|
+
const target = expr.fields[0];
|
|
1940
|
+
const span_18 = expr.fields[2];
|
|
1941
|
+
const fieldName = expr.fields[1];
|
|
1942
|
+
const inferRecordField = (s1_16, tTarget) => {
|
|
1943
|
+
const matchValue_13 = applyType(s1_16, tTarget);
|
|
1944
|
+
switch (matchValue_13.tag) {
|
|
1945
|
+
case 8: {
|
|
1946
|
+
const matchValue_14 = FSharpMap__TryFind(matchValue_13.fields[0], fieldName);
|
|
1947
|
+
if (matchValue_14 == null) {
|
|
1948
|
+
throw new TypeException(new TypeError$(toText(printf("Record field \'%s\' not found"))(fieldName), span_18));
|
|
1949
|
+
}
|
|
1950
|
+
else {
|
|
1951
|
+
return [s1_16, matchValue_14];
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
case 12: {
|
|
1955
|
+
const matchValue_15 = FSharpMap__TryFind(typeDefs, matchValue_13.fields[0]);
|
|
1956
|
+
let matchResult_4, fields_7;
|
|
1957
|
+
if (matchValue_15 != null) {
|
|
1958
|
+
if (matchValue_15.tag === 8) {
|
|
1959
|
+
matchResult_4 = 0;
|
|
1960
|
+
fields_7 = matchValue_15.fields[0];
|
|
1961
|
+
}
|
|
1962
|
+
else {
|
|
1963
|
+
matchResult_4 = 1;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
else {
|
|
1967
|
+
matchResult_4 = 1;
|
|
1968
|
+
}
|
|
1969
|
+
switch (matchResult_4) {
|
|
1970
|
+
case 0: {
|
|
1971
|
+
const matchValue_16 = FSharpMap__TryFind(fields_7, fieldName);
|
|
1972
|
+
if (matchValue_16 == null) {
|
|
1973
|
+
throw new TypeException(new TypeError$(toText(printf("Record field \'%s\' not found"))(fieldName), span_18));
|
|
1974
|
+
}
|
|
1975
|
+
else {
|
|
1976
|
+
return [s1_16, matchValue_16];
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
default:
|
|
1980
|
+
throw new TypeException(new TypeError$("Field access requires a record value", span_18));
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
case 15: {
|
|
1984
|
+
const tField_4 = Types_freshVar();
|
|
1985
|
+
const s_11 = compose(unify(typeDefs, matchValue_13, new Type(8, [ofList(singleton([fieldName, tField_4]), {
|
|
1986
|
+
Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
|
|
1987
|
+
})]), span_18), s1_16);
|
|
1988
|
+
return [s_11, applyType(s_11, tField_4)];
|
|
1989
|
+
}
|
|
1990
|
+
default:
|
|
1991
|
+
throw new TypeException(new TypeError$("Field access requires a record value", span_18));
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1994
|
+
let matchResult_5, moduleName_1;
|
|
1995
|
+
if (target.tag === 2) {
|
|
1996
|
+
if (!FSharpMap__ContainsKey(env, target.fields[0])) {
|
|
1997
|
+
matchResult_5 = 0;
|
|
1998
|
+
moduleName_1 = target.fields[0];
|
|
1999
|
+
}
|
|
2000
|
+
else {
|
|
2001
|
+
matchResult_5 = 1;
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
else {
|
|
2005
|
+
matchResult_5 = 1;
|
|
2006
|
+
}
|
|
2007
|
+
switch (matchResult_5) {
|
|
2008
|
+
case 0: {
|
|
2009
|
+
const matchValue_17 = FSharpMap__TryFind(env, concat(moduleName_1, ".", fieldName));
|
|
2010
|
+
if (matchValue_17 == null) {
|
|
2011
|
+
const patternInput_37 = inferExpr(typeDefs, constructors, env, target);
|
|
2012
|
+
const patternInput_38 = inferRecordField(patternInput_37[0], patternInput_37[1]);
|
|
2013
|
+
const tField_5 = patternInput_38[1];
|
|
2014
|
+
return [patternInput_38[0], tField_5, asTyped(expr, tField_5)];
|
|
2015
|
+
}
|
|
2016
|
+
else {
|
|
2017
|
+
const t_7 = instantiate(matchValue_17);
|
|
2018
|
+
return [emptySubst, t_7, asTyped(expr, t_7)];
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
default: {
|
|
2022
|
+
const patternInput_39 = inferExpr(typeDefs, constructors, env, target);
|
|
2023
|
+
const patternInput_40 = inferRecordField(patternInput_39[0], patternInput_39[1]);
|
|
2024
|
+
const tField_6 = patternInput_40[1];
|
|
2025
|
+
return [patternInput_40[0], tField_6, asTyped(expr, tField_6)];
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
case 22: {
|
|
2030
|
+
const span_19 = expr.fields[2];
|
|
2031
|
+
const patternInput_41 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
2032
|
+
const s1_19 = patternInput_41[0];
|
|
2033
|
+
const patternInput_42 = inferExpr(typeDefs, constructors, applyEnv(s1_19, env), expr.fields[1]);
|
|
2034
|
+
const s2_10 = patternInput_42[0];
|
|
2035
|
+
const targetType = applyType(s2_10, patternInput_41[1]);
|
|
2036
|
+
const keyType_1 = applyType(s2_10, patternInput_42[1]);
|
|
2037
|
+
let matchResult_6, itemType_1, mapKeyType, valueType_1;
|
|
2038
|
+
switch (targetType.tag) {
|
|
2039
|
+
case 5: {
|
|
2040
|
+
matchResult_6 = 0;
|
|
2041
|
+
itemType_1 = targetType.fields[0];
|
|
2042
|
+
break;
|
|
2043
|
+
}
|
|
2044
|
+
case 9: {
|
|
2045
|
+
matchResult_6 = 1;
|
|
2046
|
+
mapKeyType = targetType.fields[0];
|
|
2047
|
+
valueType_1 = targetType.fields[1];
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
case 15: {
|
|
2051
|
+
switch (keyType_1.tag) {
|
|
2052
|
+
case 1: {
|
|
2053
|
+
matchResult_6 = 2;
|
|
2054
|
+
break;
|
|
2055
|
+
}
|
|
2056
|
+
case 4: {
|
|
2057
|
+
matchResult_6 = 3;
|
|
2058
|
+
break;
|
|
2059
|
+
}
|
|
2060
|
+
case 15: {
|
|
2061
|
+
matchResult_6 = 4;
|
|
2062
|
+
break;
|
|
2063
|
+
}
|
|
2064
|
+
default:
|
|
2065
|
+
matchResult_6 = 5;
|
|
2066
|
+
}
|
|
2067
|
+
break;
|
|
2068
|
+
}
|
|
2069
|
+
default:
|
|
2070
|
+
matchResult_6 = 5;
|
|
2071
|
+
}
|
|
2072
|
+
switch (matchResult_6) {
|
|
2073
|
+
case 0: {
|
|
2074
|
+
const s_12 = compose(unify(typeDefs, keyType_1, new Type(1, []), span_19), compose(s2_10, s1_19));
|
|
2075
|
+
const tRes_12 = new Type(10, [applyType(s_12, itemType_1)]);
|
|
2076
|
+
return [s_12, tRes_12, asTyped(expr, tRes_12)];
|
|
2077
|
+
}
|
|
2078
|
+
case 1: {
|
|
2079
|
+
const s_13 = compose(unify(typeDefs, keyType_1, mapKeyType, span_19), compose(s2_10, s1_19));
|
|
2080
|
+
const matchValue_19 = applyType(s_13, mapKeyType);
|
|
2081
|
+
switch (matchValue_19.tag) {
|
|
2082
|
+
case 4:
|
|
2083
|
+
case 15: {
|
|
2084
|
+
break;
|
|
2085
|
+
}
|
|
2086
|
+
default:
|
|
2087
|
+
throw new TypeException(new TypeError$(concat("Map key type must be string, got ", Types_typeToString(matchValue_19)), span_19));
|
|
2088
|
+
}
|
|
2089
|
+
const tRes_13 = new Type(10, [applyType(s_13, valueType_1)]);
|
|
2090
|
+
return [s_13, tRes_13, asTyped(expr, tRes_13)];
|
|
2091
|
+
}
|
|
2092
|
+
case 2: {
|
|
2093
|
+
const itemType_2 = Types_freshVar();
|
|
2094
|
+
const s_14 = compose(unify(typeDefs, targetType, new Type(5, [itemType_2]), span_19), compose(s2_10, s1_19));
|
|
2095
|
+
const tRes_14 = new Type(10, [applyType(s_14, itemType_2)]);
|
|
2096
|
+
return [s_14, tRes_14, asTyped(expr, tRes_14)];
|
|
2097
|
+
}
|
|
2098
|
+
case 3: {
|
|
2099
|
+
const valueType_2 = Types_freshVar();
|
|
2100
|
+
const s_15 = compose(unify(typeDefs, targetType, new Type(9, [new Type(4, []), valueType_2]), span_19), compose(s2_10, s1_19));
|
|
2101
|
+
const tRes_15 = new Type(10, [applyType(s_15, valueType_2)]);
|
|
2102
|
+
return [s_15, tRes_15, asTyped(expr, tRes_15)];
|
|
2103
|
+
}
|
|
2104
|
+
case 4:
|
|
2105
|
+
throw new TypeException(new TypeError$("Ambiguous index access: use a list with int index or a map with string key", span_19));
|
|
2106
|
+
default:
|
|
2107
|
+
throw new TypeException(new TypeError$(concat("Index access requires a ", (keyType_1.tag === 1) ? "list" : ((keyType_1.tag === 4) ? "map" : "list or map"), " target with a compatible index type"), span_19));
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
case 25: {
|
|
2111
|
+
const span_20 = expr.fields[3];
|
|
2112
|
+
const op = expr.fields[0];
|
|
2113
|
+
const b = expr.fields[2];
|
|
2114
|
+
const a = expr.fields[1];
|
|
2115
|
+
switch (op) {
|
|
2116
|
+
case "|>": {
|
|
2117
|
+
const patternInput_43 = inferExpr(typeDefs, constructors, env, a);
|
|
2118
|
+
const s1_20 = patternInput_43[0];
|
|
2119
|
+
const patternInput_44 = inferExpr(typeDefs, constructors, applyEnv(s1_20, env), b);
|
|
2120
|
+
const s2_11 = patternInput_44[0];
|
|
2121
|
+
const tv_7 = Types_freshVar();
|
|
2122
|
+
const s_16 = compose(unify(typeDefs, applyType(s2_11, patternInput_44[1]), new Type(11, [applyType(s2_11, patternInput_43[1]), tv_7]), span_20), compose(s2_11, s1_20));
|
|
2123
|
+
const tRes_16 = applyType(s_16, tv_7);
|
|
2124
|
+
return [s_16, tRes_16, asTyped(expr, tRes_16)];
|
|
2125
|
+
}
|
|
2126
|
+
case "::": {
|
|
2127
|
+
const patternInput_45 = inferExpr(typeDefs, constructors, env, a);
|
|
2128
|
+
const tHead = patternInput_45[1];
|
|
2129
|
+
const s1_21 = patternInput_45[0];
|
|
2130
|
+
const patternInput_46 = inferExpr(typeDefs, constructors, applyEnv(s1_21, env), b);
|
|
2131
|
+
const s2_12 = patternInput_46[0];
|
|
2132
|
+
const s_17 = compose(unify(typeDefs, applyType(s2_12, patternInput_46[1]), new Type(5, [tHead]), span_20), compose(s2_12, s1_21));
|
|
2133
|
+
const tRes_17 = applyType(s_17, new Type(5, [tHead]));
|
|
2134
|
+
return [s_17, tRes_17, asTyped(expr, tRes_17)];
|
|
2135
|
+
}
|
|
2136
|
+
case "@": {
|
|
2137
|
+
const patternInput_47 = inferExpr(typeDefs, constructors, env, a);
|
|
2138
|
+
const s1_22 = patternInput_47[0];
|
|
2139
|
+
const patternInput_48 = inferExpr(typeDefs, constructors, applyEnv(s1_22, env), b);
|
|
2140
|
+
const s2_13 = patternInput_48[0];
|
|
2141
|
+
const tv_8 = Types_freshVar();
|
|
2142
|
+
const s3_10 = unify(typeDefs, applyType(s2_13, patternInput_47[1]), new Type(5, [tv_8]), span_20);
|
|
2143
|
+
const s_18 = compose(unify(typeDefs, applyType(s3_10, applyType(s2_13, patternInput_48[1])), new Type(5, [applyType(s3_10, tv_8)]), span_20), compose(s3_10, compose(s2_13, s1_22)));
|
|
2144
|
+
const tRes_18 = new Type(5, [applyType(s_18, tv_8)]);
|
|
2145
|
+
return [s_18, tRes_18, asTyped(expr, tRes_18)];
|
|
2146
|
+
}
|
|
2147
|
+
default: {
|
|
2148
|
+
const patternInput_49 = inferExpr(typeDefs, constructors, env, a);
|
|
2149
|
+
const s1_23 = patternInput_49[0];
|
|
2150
|
+
const patternInput_50 = inferExpr(typeDefs, constructors, applyEnv(s1_23, env), b);
|
|
2151
|
+
const t2_3 = patternInput_50[1];
|
|
2152
|
+
const s2_14 = patternInput_50[0];
|
|
2153
|
+
const s3_11 = unify(typeDefs, applyType(s2_14, patternInput_49[1]), t2_3, span_20);
|
|
2154
|
+
const t_9 = applyType(s3_11, t2_3);
|
|
2155
|
+
let resultType;
|
|
2156
|
+
switch (op) {
|
|
2157
|
+
case "+":
|
|
2158
|
+
case "-":
|
|
2159
|
+
case "*":
|
|
2160
|
+
case "/":
|
|
2161
|
+
case "%": {
|
|
2162
|
+
resultType = numericResult(t_9, span_20);
|
|
2163
|
+
break;
|
|
2164
|
+
}
|
|
2165
|
+
case "=": {
|
|
2166
|
+
resultType = (new Type(3, []));
|
|
2167
|
+
break;
|
|
2168
|
+
}
|
|
2169
|
+
case "<":
|
|
2170
|
+
case ">":
|
|
2171
|
+
case "<=":
|
|
2172
|
+
case ">=": {
|
|
2173
|
+
numericResult(t_9, span_20);
|
|
2174
|
+
resultType = (new Type(3, []));
|
|
2175
|
+
break;
|
|
2176
|
+
}
|
|
2177
|
+
case "&&":
|
|
2178
|
+
case "||": {
|
|
2179
|
+
unify(typeDefs, t_9, new Type(3, []), span_20);
|
|
2180
|
+
resultType = (new Type(3, []));
|
|
2181
|
+
break;
|
|
2182
|
+
}
|
|
2183
|
+
default:
|
|
2184
|
+
throw new TypeException(new TypeError$(toText(printf("Unknown operator %s"))(op), span_20));
|
|
2185
|
+
}
|
|
2186
|
+
return [compose(s3_11, compose(s2_14, s1_23)), resultType, asTyped(expr, resultType)];
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
case 26: {
|
|
2191
|
+
const patternInput_51 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
2192
|
+
const t1_11 = patternInput_51[1];
|
|
2193
|
+
return [patternInput_51[0], new Type(10, [t1_11]), asTyped(expr, new Type(10, [t1_11]))];
|
|
2194
|
+
}
|
|
2195
|
+
case 27: {
|
|
2196
|
+
const tv_9 = Types_freshVar();
|
|
2197
|
+
return [emptySubst, new Type(10, [tv_9]), asTyped(expr, new Type(10, [tv_9]))];
|
|
2198
|
+
}
|
|
2199
|
+
case 23: {
|
|
2200
|
+
const patternInput_52 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
2201
|
+
const t1_12 = patternInput_52[1];
|
|
2202
|
+
const s1_25 = patternInput_52[0];
|
|
2203
|
+
const patternInput_53 = inferExpr(typeDefs, constructors, applyEnv(s1_25, env), expr.fields[1]);
|
|
2204
|
+
const s2_15 = patternInput_53[0];
|
|
2205
|
+
const s_20 = compose(unify(typeDefs, applyType(s2_15, patternInput_53[1]), new Type(5, [t1_12]), expr.fields[2]), compose(s2_15, s1_25));
|
|
2206
|
+
const tRes_19 = applyType(s_20, new Type(5, [t1_12]));
|
|
2207
|
+
return [s_20, tRes_19, asTyped(expr, tRes_19)];
|
|
2208
|
+
}
|
|
2209
|
+
case 24: {
|
|
2210
|
+
const span_22 = expr.fields[2];
|
|
2211
|
+
const patternInput_54 = inferExpr(typeDefs, constructors, env, expr.fields[0]);
|
|
2212
|
+
const s1_26 = patternInput_54[0];
|
|
2213
|
+
const patternInput_55 = inferExpr(typeDefs, constructors, applyEnv(s1_26, env), expr.fields[1]);
|
|
2214
|
+
const s2_16 = patternInput_55[0];
|
|
2215
|
+
const tv_10 = Types_freshVar();
|
|
2216
|
+
const s3_13 = unify(typeDefs, applyType(s2_16, patternInput_54[1]), new Type(5, [tv_10]), span_22);
|
|
2217
|
+
const s_21 = compose(unify(typeDefs, applyType(s3_13, applyType(s2_16, patternInput_55[1])), new Type(5, [applyType(s3_13, tv_10)]), span_22), compose(s3_13, compose(s2_16, s1_26)));
|
|
2218
|
+
const tRes_20 = new Type(5, [applyType(s_21, tv_10)]);
|
|
2219
|
+
return [s_21, tRes_20, asTyped(expr, tRes_20)];
|
|
2220
|
+
}
|
|
2221
|
+
default:
|
|
2222
|
+
return [emptySubst, new Type(0, []), asTyped(expr, new Type(0, []))];
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
function envFromExterns(externs) {
|
|
2227
|
+
return fold((acc, ext) => FSharpMap__Add(acc, ext.Name, ext.Scheme), builtinSchemes, externs);
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
function patternBindingNames(pat) {
|
|
2231
|
+
const loop = (acc_mut, pattern_mut) => {
|
|
2232
|
+
loop:
|
|
2233
|
+
while (true) {
|
|
2234
|
+
const acc = acc_mut, pattern = pattern_mut;
|
|
2235
|
+
switch (pattern.tag) {
|
|
2236
|
+
case 1:
|
|
2237
|
+
return cons(pattern.fields[0], acc);
|
|
2238
|
+
case 4: {
|
|
2239
|
+
acc_mut = loop(acc, pattern.fields[0]);
|
|
2240
|
+
pattern_mut = pattern.fields[1];
|
|
2241
|
+
continue loop;
|
|
2242
|
+
}
|
|
2243
|
+
case 5:
|
|
2244
|
+
return fold(loop, acc, pattern.fields[0]);
|
|
2245
|
+
case 6:
|
|
2246
|
+
return fold((state, tupledArg) => loop(state, tupledArg[1]), acc, pattern.fields[0]);
|
|
2247
|
+
case 7: {
|
|
2248
|
+
const tailPattern = pattern.fields[1];
|
|
2249
|
+
const withClauses = fold((state_1, tupledArg_1) => loop(loop(state_1, tupledArg_1[0]), tupledArg_1[1]), acc, pattern.fields[0]);
|
|
2250
|
+
if (tailPattern == null) {
|
|
2251
|
+
return withClauses;
|
|
2252
|
+
}
|
|
2253
|
+
else {
|
|
2254
|
+
acc_mut = withClauses;
|
|
2255
|
+
pattern_mut = tailPattern;
|
|
2256
|
+
continue loop;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
case 8: {
|
|
2260
|
+
acc_mut = acc;
|
|
2261
|
+
pattern_mut = pattern.fields[0];
|
|
2262
|
+
continue loop;
|
|
2263
|
+
}
|
|
2264
|
+
case 10: {
|
|
2265
|
+
const payload = pattern.fields[2];
|
|
2266
|
+
if (payload == null) {
|
|
2267
|
+
return acc;
|
|
2268
|
+
}
|
|
2269
|
+
else {
|
|
2270
|
+
acc_mut = acc;
|
|
2271
|
+
pattern_mut = payload;
|
|
2272
|
+
continue loop;
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
default:
|
|
2276
|
+
return acc;
|
|
2277
|
+
}
|
|
2278
|
+
break;
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
return loop(empty_2(), pat);
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
function topLevelBindingNames(program) {
|
|
2285
|
+
return collect((_arg) => {
|
|
2286
|
+
switch (_arg.tag) {
|
|
2287
|
+
case 2:
|
|
2288
|
+
return singleton(_arg.fields[0]);
|
|
2289
|
+
case 3:
|
|
2290
|
+
return patternBindingNames(_arg.fields[0]);
|
|
2291
|
+
case 4:
|
|
2292
|
+
return map((tupledArg) => tupledArg[0], _arg.fields[0]);
|
|
2293
|
+
default:
|
|
2294
|
+
return empty_2();
|
|
2295
|
+
}
|
|
2296
|
+
}, program);
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
function inferProgramWithExternsRawAndLocals(externs, program) {
|
|
2300
|
+
const decls = ofList(append(map((d) => [d.Name, d], typeDefs_1), choose((_arg) => {
|
|
2301
|
+
if (_arg.tag === 0) {
|
|
2302
|
+
const d_1 = _arg.fields[0];
|
|
2303
|
+
return [d_1.Name, d_1];
|
|
2304
|
+
}
|
|
2305
|
+
else {
|
|
2306
|
+
return undefined;
|
|
2307
|
+
}
|
|
2308
|
+
}, program)), {
|
|
2309
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
2310
|
+
});
|
|
2311
|
+
const typeDefs = map_1((name, d_2) => {
|
|
2312
|
+
if (!isEmpty(d_2.Cases)) {
|
|
2313
|
+
return new Type(13, [name, ofList(map((tupledArg) => [tupledArg[0], map_3((tref) => typeFromRef(decls, singleton(name), tref), tupledArg[1])], d_2.Cases), {
|
|
2314
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
2315
|
+
})]);
|
|
2316
|
+
}
|
|
2317
|
+
else {
|
|
2318
|
+
return new Type(8, [ofList(map((tupledArg_1) => [tupledArg_1[0], typeFromRef(decls, singleton(d_2.Name), tupledArg_1[1])], d_2.Fields), {
|
|
2319
|
+
Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
|
|
2320
|
+
})]);
|
|
2321
|
+
}
|
|
2322
|
+
}, decls);
|
|
2323
|
+
const constructors = ofList(collect((tupledArg_2) => {
|
|
2324
|
+
const typeName = tupledArg_2[0];
|
|
2325
|
+
return collect((tupledArg_3) => {
|
|
2326
|
+
const caseName_1 = tupledArg_3[0];
|
|
2327
|
+
const sigInfo = new ConstructorSig(typeName, map_3((tref_1) => typeFromRef(decls, singleton(typeName), tref_1), tupledArg_3[1]));
|
|
2328
|
+
return ofArray([[caseName_1, sigInfo], [concat(typeName, ".", caseName_1), sigInfo]]);
|
|
2329
|
+
}, tupledArg_2[1].Cases);
|
|
2330
|
+
}, toList(decls)), {
|
|
2331
|
+
Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
|
|
2332
|
+
});
|
|
2333
|
+
const constructorSchemes = map((tupledArg_4) => {
|
|
2334
|
+
let matchValue;
|
|
2335
|
+
const sigInfo_1 = tupledArg_4[1];
|
|
2336
|
+
const unionType = new Type(12, [sigInfo_1.UnionName]);
|
|
2337
|
+
return [tupledArg_4[0], new Scheme(empty_2(), (matchValue = sigInfo_1.Payload, (matchValue != null) ? (new Type(11, [matchValue, unionType])) : unionType))];
|
|
2338
|
+
}, toList(constructors));
|
|
2339
|
+
let env = fold((acc, tupledArg_5) => FSharpMap__Add(acc, tupledArg_5[0], tupledArg_5[1]), envFromExterns(externs), constructorSchemes);
|
|
2340
|
+
beginTelemetry();
|
|
2341
|
+
try {
|
|
2342
|
+
const typed = [];
|
|
2343
|
+
const enumerator = getEnumerator(indexed(program));
|
|
2344
|
+
try {
|
|
2345
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
2346
|
+
let expectedReturn, expectedReturn_1;
|
|
2347
|
+
const forLoopVar = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
2348
|
+
const stmt = forLoopVar[1];
|
|
2349
|
+
switch (stmt.tag) {
|
|
2350
|
+
case 1: {
|
|
2351
|
+
throw new TypeException(new TypeError$("\'import\' must be resolved before type inference", stmt.fields[2]));
|
|
2352
|
+
break;
|
|
2353
|
+
}
|
|
2354
|
+
case 2: {
|
|
2355
|
+
const span_1 = stmt.fields[6];
|
|
2356
|
+
const returnAnnotation = stmt.fields[2];
|
|
2357
|
+
const name_2 = stmt.fields[0];
|
|
2358
|
+
const isExported = stmt.fields[5];
|
|
2359
|
+
const exprVal = foldBack((arg, acc_1) => (new Expr(4, [arg, acc_1, span_1])), stmt.fields[1], stmt.fields[3]);
|
|
2360
|
+
let startIndex;
|
|
2361
|
+
if (telemetry == null) {
|
|
2362
|
+
startIndex = 0;
|
|
2363
|
+
}
|
|
2364
|
+
else {
|
|
2365
|
+
const t_1 = telemetry;
|
|
2366
|
+
startIndex = t_1.LocalVariableTypes.length;
|
|
2367
|
+
}
|
|
2368
|
+
if (stmt.fields[4]) {
|
|
2369
|
+
const tv = Types_freshVar();
|
|
2370
|
+
const patternInput = inferExpr(typeDefs, constructors, add(name_2, new Scheme(empty_2(), tv), env), exprVal);
|
|
2371
|
+
const t1 = patternInput[1];
|
|
2372
|
+
const s1 = patternInput[0];
|
|
2373
|
+
const s2 = unify(typeDefs, applyType(s1, tv), t1, span_1);
|
|
2374
|
+
const s = compose((returnAnnotation == null) ? emptySubst : ((expectedReturn = annotationTypeFromRef(typeDefs, span_1, returnAnnotation), unify(typeDefs, functionReturnType(applyType(s2, t1)), expectedReturn, span_1))), compose(s2, s1));
|
|
2375
|
+
applySubstToCapturedLocals(startIndex, s);
|
|
2376
|
+
const env$0027 = applyEnv(s, env);
|
|
2377
|
+
const inferred = applyType(s, t1);
|
|
2378
|
+
validateMapKeyTypes(span_1, inferred);
|
|
2379
|
+
const scheme_1 = Types_generalize(env$0027, inferred);
|
|
2380
|
+
env = add(name_2, scheme_1, env$0027);
|
|
2381
|
+
void (typed.push(new TypedStmt(1, [name_2, exprVal, inferred, true, isExported, span_1])));
|
|
2382
|
+
}
|
|
2383
|
+
else {
|
|
2384
|
+
const patternInput_1 = inferExpr(typeDefs, constructors, env, exprVal);
|
|
2385
|
+
const t1_1 = patternInput_1[1];
|
|
2386
|
+
const s1_1 = patternInput_1[0];
|
|
2387
|
+
const s_1 = compose((returnAnnotation == null) ? emptySubst : ((expectedReturn_1 = annotationTypeFromRef(typeDefs, span_1, returnAnnotation), unify(typeDefs, functionReturnType(applyType(s1_1, t1_1)), expectedReturn_1, span_1))), s1_1);
|
|
2388
|
+
applySubstToCapturedLocals(startIndex, s_1);
|
|
2389
|
+
const env$0027_1 = applyEnv(s_1, env);
|
|
2390
|
+
const inferred_1 = applyType(s_1, t1_1);
|
|
2391
|
+
validateMapKeyTypes(span_1, inferred_1);
|
|
2392
|
+
const scheme_2 = Types_generalize(env$0027_1, inferred_1);
|
|
2393
|
+
env = add(name_2, scheme_2, env$0027_1);
|
|
2394
|
+
void (typed.push(new TypedStmt(1, [name_2, exprVal, inferred_1, false, isExported, span_1])));
|
|
2395
|
+
}
|
|
2396
|
+
break;
|
|
2397
|
+
}
|
|
2398
|
+
case 3: {
|
|
2399
|
+
const span_2 = stmt.fields[3];
|
|
2400
|
+
const pattern = stmt.fields[0];
|
|
2401
|
+
const expr_1 = stmt.fields[1];
|
|
2402
|
+
let startIndex_1;
|
|
2403
|
+
if (telemetry == null) {
|
|
2404
|
+
startIndex_1 = 0;
|
|
2405
|
+
}
|
|
2406
|
+
else {
|
|
2407
|
+
const t_2 = telemetry;
|
|
2408
|
+
startIndex_1 = t_2.LocalVariableTypes.length;
|
|
2409
|
+
}
|
|
2410
|
+
const patternInput_2 = inferExpr(typeDefs, constructors, env, expr_1);
|
|
2411
|
+
const s1_2 = patternInput_2[0];
|
|
2412
|
+
const patternInput_3 = inferPattern(typeDefs, constructors, pattern);
|
|
2413
|
+
const s_2 = compose(unify(typeDefs, applyType(s1_2, patternInput_2[1]), patternInput_3[1], span_2), s1_2);
|
|
2414
|
+
applySubstToCapturedLocals(startIndex_1, s_2);
|
|
2415
|
+
const envBase = applyEnv(s_2, env);
|
|
2416
|
+
const typedBindings = map_1((_arg_1, ty) => applyType(s_2, ty), patternInput_3[0]);
|
|
2417
|
+
iterate_2((_arg_2, ty_1) => {
|
|
2418
|
+
validateMapKeyTypes(span_2, ty_1);
|
|
2419
|
+
}, typedBindings);
|
|
2420
|
+
env = fold_1((state_1, name_3, bindingType) => add(name_3, Types_generalize(envBase, bindingType), state_1), envBase, typedBindings);
|
|
2421
|
+
void (typed.push(new TypedStmt(2, [pattern, expr_1, typedBindings, stmt.fields[2], span_2])));
|
|
2422
|
+
break;
|
|
2423
|
+
}
|
|
2424
|
+
case 4: {
|
|
2425
|
+
const span_3 = stmt.fields[2];
|
|
2426
|
+
let startIndex_2;
|
|
2427
|
+
if (telemetry == null) {
|
|
2428
|
+
startIndex_2 = 0;
|
|
2429
|
+
}
|
|
2430
|
+
else {
|
|
2431
|
+
const t_3 = telemetry;
|
|
2432
|
+
startIndex_2 = t_3.LocalVariableTypes.length;
|
|
2433
|
+
}
|
|
2434
|
+
const foldedBindings = map((tupledArg_6) => {
|
|
2435
|
+
const args_1 = tupledArg_6[1];
|
|
2436
|
+
const bindingSpan = tupledArg_6[4];
|
|
2437
|
+
if (isEmpty(args_1)) {
|
|
2438
|
+
throw new TypeException(new TypeError$("\'let rec ... and ...\' requires function arguments for each binding", bindingSpan));
|
|
2439
|
+
}
|
|
2440
|
+
return [tupledArg_6[0], tupledArg_6[2], foldBack((arg_1, acc_2) => (new Expr(4, [arg_1, acc_2, bindingSpan])), args_1, tupledArg_6[3]), bindingSpan];
|
|
2441
|
+
}, stmt.fields[0]);
|
|
2442
|
+
const freshByName = ofList(map((tupledArg_7) => [tupledArg_7[0], Types_freshVar()], foldedBindings), {
|
|
2443
|
+
Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
|
|
2444
|
+
});
|
|
2445
|
+
const envRec_1 = fold_1((acc_3, name_6, tv_1) => add(name_6, new Scheme(empty_2(), tv_1), acc_3), env, freshByName);
|
|
2446
|
+
let sRec = emptySubst;
|
|
2447
|
+
const enumerator_1 = getEnumerator(foldedBindings);
|
|
2448
|
+
try {
|
|
2449
|
+
while (enumerator_1["System.Collections.IEnumerator.MoveNext"]()) {
|
|
2450
|
+
const forLoopVar_1 = enumerator_1["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
2451
|
+
const patternInput_4 = inferExpr(typeDefs, constructors, applyEnv(sRec, envRec_1), forLoopVar_1[2]);
|
|
2452
|
+
const s1_3 = patternInput_4[0];
|
|
2453
|
+
const s2_2 = unify(typeDefs, applyType(s1_3, applyType(sRec, FSharpMap__get_Item(freshByName, forLoopVar_1[0]))), patternInput_4[1], forLoopVar_1[3]);
|
|
2454
|
+
sRec = compose(s2_2, compose(s1_3, sRec));
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
finally {
|
|
2458
|
+
disposeSafe(enumerator_1);
|
|
2459
|
+
}
|
|
2460
|
+
const enumerator_2 = getEnumerator(foldedBindings);
|
|
2461
|
+
try {
|
|
2462
|
+
while (enumerator_2["System.Collections.IEnumerator.MoveNext"]()) {
|
|
2463
|
+
const forLoopVar_2 = enumerator_2["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
2464
|
+
const returnAnnotation_2 = forLoopVar_2[1];
|
|
2465
|
+
const bindingSpan_2 = forLoopVar_2[3];
|
|
2466
|
+
if (returnAnnotation_2 == null) {
|
|
2467
|
+
}
|
|
2468
|
+
else {
|
|
2469
|
+
const expectedReturn_2 = annotationTypeFromRef(typeDefs, bindingSpan_2, returnAnnotation_2);
|
|
2470
|
+
const sRet_2 = unify(typeDefs, functionReturnType(applyType(sRec, FSharpMap__get_Item(freshByName, forLoopVar_2[0]))), expectedReturn_2, bindingSpan_2);
|
|
2471
|
+
sRec = compose(sRet_2, sRec);
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
finally {
|
|
2476
|
+
disposeSafe(enumerator_2);
|
|
2477
|
+
}
|
|
2478
|
+
applySubstToCapturedLocals(startIndex_2, sRec);
|
|
2479
|
+
const envGeneralize = applyEnv(sRec, env);
|
|
2480
|
+
const schemes = map((tupledArg_8) => {
|
|
2481
|
+
const name_9 = tupledArg_8[0];
|
|
2482
|
+
const inferred_2 = applyType(sRec, FSharpMap__get_Item(freshByName, name_9));
|
|
2483
|
+
validateMapKeyTypes(span_3, inferred_2);
|
|
2484
|
+
return [name_9, Types_generalize(envGeneralize, inferred_2)];
|
|
2485
|
+
}, foldedBindings);
|
|
2486
|
+
const typedBindings_1 = map((tupledArg_9) => {
|
|
2487
|
+
const name_10 = tupledArg_9[0];
|
|
2488
|
+
return [name_10, tupledArg_9[2], applyType(sRec, FSharpMap__get_Item(freshByName, name_10)), tupledArg_9[3]];
|
|
2489
|
+
}, foldedBindings);
|
|
2490
|
+
env = fold((acc_4, tupledArg_10) => add(tupledArg_10[0], tupledArg_10[1], acc_4), envGeneralize, schemes);
|
|
2491
|
+
void (typed.push(new TypedStmt(3, [typedBindings_1, stmt.fields[1], span_3])));
|
|
2492
|
+
break;
|
|
2493
|
+
}
|
|
2494
|
+
case 5: {
|
|
2495
|
+
const expr_2 = stmt.fields[0];
|
|
2496
|
+
let startIndex_3;
|
|
2497
|
+
if (telemetry == null) {
|
|
2498
|
+
startIndex_3 = 0;
|
|
2499
|
+
}
|
|
2500
|
+
else {
|
|
2501
|
+
const t_4 = telemetry;
|
|
2502
|
+
startIndex_3 = t_4.LocalVariableTypes.length;
|
|
2503
|
+
}
|
|
2504
|
+
const patternInput_5 = inferExpr(typeDefs, constructors, env, expr_2);
|
|
2505
|
+
const t1_3 = patternInput_5[1];
|
|
2506
|
+
const s1_4 = patternInput_5[0];
|
|
2507
|
+
const s_3 = compose((forLoopVar[0] < (length(program) - 1)) ? unify(typeDefs, applyType(s1_4, t1_3), new Type(0, []), Ast_spanOfExpr(expr_2)) : emptySubst, s1_4);
|
|
2508
|
+
applySubstToCapturedLocals(startIndex_3, s_3);
|
|
2509
|
+
validateMapKeyTypes(Ast_spanOfExpr(expr_2), applyType(s_3, t1_3));
|
|
2510
|
+
env = applyEnv(s_3, env);
|
|
2511
|
+
void (typed.push(new TypedStmt(4, [patternInput_5[2]])));
|
|
2512
|
+
break;
|
|
2513
|
+
}
|
|
2514
|
+
default:
|
|
2515
|
+
void (typed.push(new TypedStmt(0, [stmt.fields[0]])));
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
finally {
|
|
2520
|
+
disposeSafe(enumerator);
|
|
2521
|
+
}
|
|
2522
|
+
return [toList_1(typed), endTelemetry()];
|
|
2523
|
+
}
|
|
2524
|
+
catch (matchValue_1) {
|
|
2525
|
+
endTelemetry();
|
|
2526
|
+
throw matchValue_1;
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
export function inferProgramWithExternsRaw(externs, program) {
|
|
2531
|
+
return inferProgramWithExternsRawAndLocals(externs, program)[0];
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
export function inferProgramWithExterns(externs, program) {
|
|
2535
|
+
iterate_1((ext_1) => {
|
|
2536
|
+
throw new TypeException(new TypeError$(concat("Host extern \'", ext_1.Name, "\' collides with reserved stdlib symbol"), unknownSpan));
|
|
2537
|
+
}, toArray(tryFind_1((ext) => contains(ext.Name, builtinReservedNames), externs)));
|
|
2538
|
+
iterate_1((name_1) => {
|
|
2539
|
+
throw new TypeException(new TypeError$(concat("Top-level binding \'", name_1, "\' collides with reserved stdlib symbol"), unknownSpan));
|
|
2540
|
+
}, toArray(tryFind_1((name) => contains(name, builtinReservedNames), topLevelBindingNames(program))));
|
|
2541
|
+
return inferProgramWithExternsRaw(externs, program);
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
export function inferProgramWithExternsAndLocalVariableTypes(externs, program) {
|
|
2545
|
+
iterate_1((ext_1) => {
|
|
2546
|
+
throw new TypeException(new TypeError$(concat("Host extern \'", ext_1.Name, "\' collides with reserved stdlib symbol"), unknownSpan));
|
|
2547
|
+
}, toArray(tryFind_1((ext) => contains(ext.Name, builtinReservedNames), externs)));
|
|
2548
|
+
iterate_1((name_1) => {
|
|
2549
|
+
throw new TypeException(new TypeError$(concat("Top-level binding \'", name_1, "\' collides with reserved stdlib symbol"), unknownSpan));
|
|
2550
|
+
}, toArray(tryFind_1((name) => contains(name, builtinReservedNames), topLevelBindingNames(program))));
|
|
2551
|
+
return inferProgramWithExternsRawAndLocals(externs, program);
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
export function inferProgramWithLocalVariableTypes(program) {
|
|
2555
|
+
return inferProgramWithExternsAndLocalVariableTypes(empty_2(), program);
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
export function inferProgram(program) {
|
|
2559
|
+
return inferProgramWithExterns(empty_2(), program);
|
|
2560
|
+
}
|
|
2561
|
+
|