hinmil 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +2306 -2
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +338 -0
- package/dist/cli.js.map +1 -0
- package/dist/commentParser.d.ts +384 -0
- package/dist/commentParser.d.ts.map +1 -0
- package/dist/commentParser.js +2487 -0
- package/dist/commentParser.js.map +1 -0
- package/dist/config.d.ts +203 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +375 -0
- package/dist/config.js.map +1 -0
- package/dist/debugLog.d.ts +13 -0
- package/dist/debugLog.d.ts.map +1 -0
- package/dist/debugLog.js +44 -0
- package/dist/debugLog.js.map +1 -0
- package/dist/estree.d.ts +100 -0
- package/dist/estree.d.ts.map +1 -0
- package/dist/estree.js +34 -0
- package/dist/estree.js.map +1 -0
- package/dist/hm/env.d.ts +134 -0
- package/dist/hm/env.d.ts.map +1 -0
- package/dist/hm/env.js +939 -0
- package/dist/hm/env.js.map +1 -0
- package/dist/hm/index.d.ts +7 -0
- package/dist/hm/index.d.ts.map +1 -0
- package/dist/hm/index.js +26 -0
- package/dist/hm/index.js.map +1 -0
- package/dist/hm/substitution.d.ts +57 -0
- package/dist/hm/substitution.d.ts.map +1 -0
- package/dist/hm/substitution.js +546 -0
- package/dist/hm/substitution.js.map +1 -0
- package/dist/hm/typeParser.d.ts +39 -0
- package/dist/hm/typeParser.d.ts.map +1 -0
- package/dist/hm/typeParser.js +1285 -0
- package/dist/hm/typeParser.js.map +1 -0
- package/dist/hm/typeUtils.d.ts +248 -0
- package/dist/hm/typeUtils.d.ts.map +1 -0
- package/dist/hm/typeUtils.js +905 -0
- package/dist/hm/typeUtils.js.map +1 -0
- package/dist/hm/types.d.ts +738 -0
- package/dist/hm/types.d.ts.map +1 -0
- package/dist/hm/types.js +1853 -0
- package/dist/hm/types.js.map +1 -0
- package/dist/hm/unify.d.ts +59 -0
- package/dist/hm/unify.d.ts.map +1 -0
- package/dist/hm/unify.js +1700 -0
- package/dist/hm/unify.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +196 -0
- package/dist/index.js.map +1 -0
- package/dist/infer/annotation-rigid.d.ts +76 -0
- package/dist/infer/annotation-rigid.d.ts.map +1 -0
- package/dist/infer/annotation-rigid.js +542 -0
- package/dist/infer/annotation-rigid.js.map +1 -0
- package/dist/infer/annotation-validation.d.ts +109 -0
- package/dist/infer/annotation-validation.d.ts.map +1 -0
- package/dist/infer/annotation-validation.js +1078 -0
- package/dist/infer/annotation-validation.js.map +1 -0
- package/dist/infer/annotations.d.ts +277 -0
- package/dist/infer/annotations.d.ts.map +1 -0
- package/dist/infer/annotations.js +1343 -0
- package/dist/infer/annotations.js.map +1 -0
- package/dist/infer/call-overloads.d.ts +24 -0
- package/dist/infer/call-overloads.d.ts.map +1 -0
- package/dist/infer/call-overloads.js +900 -0
- package/dist/infer/call-overloads.js.map +1 -0
- package/dist/infer/call-rows.d.ts +154 -0
- package/dist/infer/call-rows.d.ts.map +1 -0
- package/dist/infer/call-rows.js +2162 -0
- package/dist/infer/call-rows.js.map +1 -0
- package/dist/infer/calls.d.ts +20 -0
- package/dist/infer/calls.d.ts.map +1 -0
- package/dist/infer/calls.js +1468 -0
- package/dist/infer/calls.js.map +1 -0
- package/dist/infer/constraints.d.ts +99 -0
- package/dist/infer/constraints.d.ts.map +1 -0
- package/dist/infer/constraints.js +1208 -0
- package/dist/infer/constraints.js.map +1 -0
- package/dist/infer/expr-assignment.d.ts +20 -0
- package/dist/infer/expr-assignment.d.ts.map +1 -0
- package/dist/infer/expr-assignment.js +620 -0
- package/dist/infer/expr-assignment.js.map +1 -0
- package/dist/infer/expr-constraint-lookup.d.ts +44 -0
- package/dist/infer/expr-constraint-lookup.d.ts.map +1 -0
- package/dist/infer/expr-constraint-lookup.js +207 -0
- package/dist/infer/expr-constraint-lookup.js.map +1 -0
- package/dist/infer/expr-functions.d.ts +20 -0
- package/dist/infer/expr-functions.d.ts.map +1 -0
- package/dist/infer/expr-functions.js +1359 -0
- package/dist/infer/expr-functions.js.map +1 -0
- package/dist/infer/expr-jsx.d.ts +19 -0
- package/dist/infer/expr-jsx.d.ts.map +1 -0
- package/dist/infer/expr-jsx.js +310 -0
- package/dist/infer/expr-jsx.js.map +1 -0
- package/dist/infer/expr-member.d.ts +40 -0
- package/dist/infer/expr-member.d.ts.map +1 -0
- package/dist/infer/expr-member.js +1154 -0
- package/dist/infer/expr-member.js.map +1 -0
- package/dist/infer/expr-prototype.d.ts +11 -0
- package/dist/infer/expr-prototype.d.ts.map +1 -0
- package/dist/infer/expr-prototype.js +202 -0
- package/dist/infer/expr-prototype.js.map +1 -0
- package/dist/infer/expressions.d.ts +40 -0
- package/dist/infer/expressions.d.ts.map +1 -0
- package/dist/infer/expressions.js +1497 -0
- package/dist/infer/expressions.js.map +1 -0
- package/dist/infer/functionPatterns.d.ts +229 -0
- package/dist/infer/functionPatterns.d.ts.map +1 -0
- package/dist/infer/functionPatterns.js +1035 -0
- package/dist/infer/functionPatterns.js.map +1 -0
- package/dist/infer/helpers.d.ts +73 -0
- package/dist/infer/helpers.d.ts.map +1 -0
- package/dist/infer/helpers.js +187 -0
- package/dist/infer/helpers.js.map +1 -0
- package/dist/infer/index.d.ts +551 -0
- package/dist/infer/index.d.ts.map +1 -0
- package/dist/infer/index.js +1127 -0
- package/dist/infer/index.js.map +1 -0
- package/dist/infer/jsx-dom.d.ts +26 -0
- package/dist/infer/jsx-dom.d.ts.map +1 -0
- package/dist/infer/jsx-dom.js +303 -0
- package/dist/infer/jsx-dom.js.map +1 -0
- package/dist/infer/moduleReps.d.ts +7 -0
- package/dist/infer/moduleReps.d.ts.map +1 -0
- package/dist/infer/moduleReps.js +48 -0
- package/dist/infer/moduleReps.js.map +1 -0
- package/dist/infer/modules.d.ts +10 -0
- package/dist/infer/modules.d.ts.map +1 -0
- package/dist/infer/modules.js +775 -0
- package/dist/infer/modules.js.map +1 -0
- package/dist/infer/narrowing.d.ts +199 -0
- package/dist/infer/narrowing.d.ts.map +1 -0
- package/dist/infer/narrowing.js +1428 -0
- package/dist/infer/narrowing.js.map +1 -0
- package/dist/infer/results.d.ts +24 -0
- package/dist/infer/results.d.ts.map +1 -0
- package/dist/infer/results.js +611 -0
- package/dist/infer/results.js.map +1 -0
- package/dist/infer/setupPass.d.ts +11 -0
- package/dist/infer/setupPass.d.ts.map +1 -0
- package/dist/infer/setupPass.js +524 -0
- package/dist/infer/setupPass.js.map +1 -0
- package/dist/infer/statements.d.ts +26 -0
- package/dist/infer/statements.d.ts.map +1 -0
- package/dist/infer/statements.js +750 -0
- package/dist/infer/statements.js.map +1 -0
- package/dist/infer/stmt-bindings.d.ts +22 -0
- package/dist/infer/stmt-bindings.d.ts.map +1 -0
- package/dist/infer/stmt-bindings.js +1482 -0
- package/dist/infer/stmt-bindings.js.map +1 -0
- package/dist/infer/stmt-destructure.d.ts +29 -0
- package/dist/infer/stmt-destructure.d.ts.map +1 -0
- package/dist/infer/stmt-destructure.js +490 -0
- package/dist/infer/stmt-destructure.js.map +1 -0
- package/dist/infer/types.d.ts +220 -0
- package/dist/infer/types.d.ts.map +1 -0
- package/dist/infer/types.js +46 -0
- package/dist/infer/types.js.map +1 -0
- package/dist/infer/unifyDiag.d.ts +46 -0
- package/dist/infer/unifyDiag.d.ts.map +1 -0
- package/dist/infer/unifyDiag.js +642 -0
- package/dist/infer/unifyDiag.js.map +1 -0
- package/dist/parsing-babel.d.ts +3 -0
- package/dist/parsing-babel.d.ts.map +1 -0
- package/dist/parsing-babel.js +353 -0
- package/dist/parsing-babel.js.map +1 -0
- package/dist/parsing.d.ts +69 -0
- package/dist/parsing.d.ts.map +1 -0
- package/dist/parsing.js +288 -0
- package/dist/parsing.js.map +1 -0
- package/dist/registries/constraintRegistry.d.ts +233 -0
- package/dist/registries/constraintRegistry.d.ts.map +1 -0
- package/dist/registries/constraintRegistry.js +803 -0
- package/dist/registries/constraintRegistry.js.map +1 -0
- package/dist/registries/dataTypeRegistry.d.ts +63 -0
- package/dist/registries/dataTypeRegistry.d.ts.map +1 -0
- package/dist/registries/dataTypeRegistry.js +180 -0
- package/dist/registries/dataTypeRegistry.js.map +1 -0
- package/dist/registries/domGlobals.d.ts +33 -0
- package/dist/registries/domGlobals.d.ts.map +1 -0
- package/dist/registries/domGlobals.js +309 -0
- package/dist/registries/domGlobals.js.map +1 -0
- package/dist/registries/methodRegistry.d.ts +277 -0
- package/dist/registries/methodRegistry.d.ts.map +1 -0
- package/dist/registries/methodRegistry.js +2074 -0
- package/dist/registries/methodRegistry.js.map +1 -0
- package/dist/registries/session.d.ts +38 -0
- package/dist/registries/session.d.ts.map +1 -0
- package/dist/registries/session.js +75 -0
- package/dist/registries/session.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +1896 -0
- package/dist/server.js.map +1 -0
- package/dist/services/codeActions.d.ts +22 -0
- package/dist/services/codeActions.d.ts.map +1 -0
- package/dist/services/codeActions.js +465 -0
- package/dist/services/codeActions.js.map +1 -0
- package/dist/services/completion.d.ts +259 -0
- package/dist/services/completion.d.ts.map +1 -0
- package/dist/services/completion.js +2794 -0
- package/dist/services/completion.js.map +1 -0
- package/dist/services/definitions.d.ts +37 -0
- package/dist/services/definitions.d.ts.map +1 -0
- package/dist/services/definitions.js +605 -0
- package/dist/services/definitions.js.map +1 -0
- package/dist/services/diagnosticCodes.d.ts +70 -0
- package/dist/services/diagnosticCodes.d.ts.map +1 -0
- package/dist/services/diagnosticCodes.js +239 -0
- package/dist/services/diagnosticCodes.js.map +1 -0
- package/dist/services/diagnostics.d.ts +86 -0
- package/dist/services/diagnostics.d.ts.map +1 -0
- package/dist/services/diagnostics.js +665 -0
- package/dist/services/diagnostics.js.map +1 -0
- package/dist/services/documentCache.d.ts +88 -0
- package/dist/services/documentCache.d.ts.map +1 -0
- package/dist/services/documentCache.js +108 -0
- package/dist/services/documentCache.js.map +1 -0
- package/dist/services/documentSymbols.d.ts +20 -0
- package/dist/services/documentSymbols.d.ts.map +1 -0
- package/dist/services/documentSymbols.js +381 -0
- package/dist/services/documentSymbols.js.map +1 -0
- package/dist/services/fileSelection.d.ts +24 -0
- package/dist/services/fileSelection.d.ts.map +1 -0
- package/dist/services/fileSelection.js +154 -0
- package/dist/services/fileSelection.js.map +1 -0
- package/dist/services/fileSelectionRefresh.d.ts +26 -0
- package/dist/services/fileSelectionRefresh.d.ts.map +1 -0
- package/dist/services/fileSelectionRefresh.js +77 -0
- package/dist/services/fileSelectionRefresh.js.map +1 -0
- package/dist/services/files.d.ts +342 -0
- package/dist/services/files.d.ts.map +1 -0
- package/dist/services/files.js +1712 -0
- package/dist/services/files.js.map +1 -0
- package/dist/services/fsProbe.d.ts +14 -0
- package/dist/services/fsProbe.d.ts.map +1 -0
- package/dist/services/fsProbe.js +112 -0
- package/dist/services/fsProbe.js.map +1 -0
- package/dist/services/globalsLoader.d.ts +20 -0
- package/dist/services/globalsLoader.d.ts.map +1 -0
- package/dist/services/globalsLoader.js +122 -0
- package/dist/services/globalsLoader.js.map +1 -0
- package/dist/services/hmFileServices.d.ts +113 -0
- package/dist/services/hmFileServices.d.ts.map +1 -0
- package/dist/services/hmFileServices.js +686 -0
- package/dist/services/hmFileServices.js.map +1 -0
- package/dist/services/hover.d.ts +280 -0
- package/dist/services/hover.d.ts.map +1 -0
- package/dist/services/hover.js +1687 -0
- package/dist/services/hover.js.map +1 -0
- package/dist/services/importContext.d.ts +396 -0
- package/dist/services/importContext.d.ts.map +1 -0
- package/dist/services/importContext.js +1999 -0
- package/dist/services/importContext.js.map +1 -0
- package/dist/services/projectChecker.d.ts +50 -0
- package/dist/services/projectChecker.d.ts.map +1 -0
- package/dist/services/projectChecker.js +228 -0
- package/dist/services/projectChecker.js.map +1 -0
- package/dist/services/references.d.ts +41 -0
- package/dist/services/references.d.ts.map +1 -0
- package/dist/services/references.js +757 -0
- package/dist/services/references.js.map +1 -0
- package/dist/services/rename.d.ts +22 -0
- package/dist/services/rename.d.ts.map +1 -0
- package/dist/services/rename.js +101 -0
- package/dist/services/rename.js.map +1 -0
- package/dist/services/shortCircuit.d.ts +27 -0
- package/dist/services/shortCircuit.d.ts.map +1 -0
- package/dist/services/shortCircuit.js +28 -0
- package/dist/services/shortCircuit.js.map +1 -0
- package/dist/services/sidecarPerf.d.ts +19 -0
- package/dist/services/sidecarPerf.d.ts.map +1 -0
- package/dist/services/sidecarPerf.js +59 -0
- package/dist/services/sidecarPerf.js.map +1 -0
- package/dist/services/signatureHelp.d.ts +27 -0
- package/dist/services/signatureHelp.d.ts.map +1 -0
- package/dist/services/signatureHelp.js +984 -0
- package/dist/services/signatureHelp.js.map +1 -0
- package/dist/walking.d.ts +25 -0
- package/dist/walking.d.ts.map +1 -0
- package/dist/walking.js +107 -0
- package/dist/walking.js.map +1 -0
- package/hm-types-builtin/assert.hm +20 -0
- package/hm-types-builtin/buffer.hm +8 -0
- package/hm-types-builtin/child_process.hm +16 -0
- package/hm-types-builtin/crypto.hm +17 -0
- package/hm-types-builtin/fs.hm +15 -0
- package/hm-types-builtin/http.hm +14 -0
- package/hm-types-builtin/os.hm +19 -0
- package/hm-types-builtin/path.hm +18 -0
- package/hm-types-builtin/react-dom.hm +27 -0
- package/hm-types-builtin/react.hm +113 -0
- package/hm-types-builtin/url.hm +7 -0
- package/hm-types-builtin/zlib.hm +12 -0
- package/package.json +53 -4
- package/schemas/hinmil.config.schema.json +261 -0
- package/schemas/package-hinmil.schema.json +59 -0
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `TypeVarAllocator` owns a monotonically-increasing counter that is used to
|
|
3
|
+
* generate unique type-variable IDs via {@link tVar}. Wrapping the counter in
|
|
4
|
+
* an instance makes it possible to run multiple inference sessions without
|
|
5
|
+
* sharing (and accidentally corrupting) a single global counter.
|
|
6
|
+
*
|
|
7
|
+
* For backward compatibility a module-level *active* allocator is maintained
|
|
8
|
+
* and all legacy free-functions (`resetTypeVarCounter`, `saveTypeVarCounter`,
|
|
9
|
+
* `restoreTypeVarCounter`, `freshTypeVarId`) delegate to it.
|
|
10
|
+
*/
|
|
11
|
+
export declare class TypeVarAllocator {
|
|
12
|
+
private nextId;
|
|
13
|
+
constructor(start?: number);
|
|
14
|
+
/** Reset the counter to 0 (or to a specific value). */
|
|
15
|
+
reset(value?: number): void;
|
|
16
|
+
/** Return the current counter value (for later {@link restore}). */
|
|
17
|
+
save(): number;
|
|
18
|
+
/** Set the counter to a previously saved value. */
|
|
19
|
+
restore(value: number): void;
|
|
20
|
+
/** Allocate and return the next unique type-variable ID. */
|
|
21
|
+
fresh(): number;
|
|
22
|
+
}
|
|
23
|
+
/** Return the currently active allocator. */
|
|
24
|
+
export declare function getActiveAllocator(): TypeVarAllocator;
|
|
25
|
+
/**
|
|
26
|
+
* Replace the active allocator. Returns the previous one so callers can
|
|
27
|
+
* restore it later (e.g. when an import inference finishes).
|
|
28
|
+
*/
|
|
29
|
+
export declare function setActiveAllocator(a: TypeVarAllocator): TypeVarAllocator;
|
|
30
|
+
export declare function resetTypeVarCounter(): void;
|
|
31
|
+
export declare function saveTypeVarCounter(): number;
|
|
32
|
+
export declare function restoreTypeVarCounter(value: number): void;
|
|
33
|
+
export declare function freshTypeVarId(): number;
|
|
34
|
+
/**
|
|
35
|
+
* Union of all ESTree node types (see `src/estree.ts`).
|
|
36
|
+
*
|
|
37
|
+
* Using `AnyNode` (instead of the base `Node`) gives TypeScript
|
|
38
|
+
* discriminated-union narrowing on `node.type` inside switch statements.
|
|
39
|
+
*/
|
|
40
|
+
export type AstNode = import('../estree').AnyNode;
|
|
41
|
+
/** A type variable — a placeholder for a type we don't know yet, e.g. `a`.
|
|
42
|
+
* Comparable to the `x` in school algebra: "some type, to be determined".
|
|
43
|
+
* Each one carries a unique `id` so two placeholders never collide. */
|
|
44
|
+
export interface TVar {
|
|
45
|
+
tag: 'TVar';
|
|
46
|
+
id: number;
|
|
47
|
+
name: string;
|
|
48
|
+
/** Marks the fresh element variable of an EMPTY array literal `[]` that had
|
|
49
|
+
* no expected element type. Such a variable carries no information ("the
|
|
50
|
+
* array is empty, element type unknown"), so two UNBOUND empty-array element
|
|
51
|
+
* vars compare EQUAL during union dedup (`unionMemberEquivalent`) — collapsing
|
|
52
|
+
* e.g. `[{ cars::[a] } | { cars::[b] }]` (from `concat([{cars:[]}],[{cars:[]}])`)
|
|
53
|
+
* into `[{ cars::[a] }]`. Also lets a strict-empty-array type accept an empty
|
|
54
|
+
* array literal. Pure inference metadata; ignored by `structuralEquals`. */
|
|
55
|
+
emptyArray?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/** A concrete, *named* type, possibly with sub-parts ("arguments"), e.g.
|
|
58
|
+
* `Number` (no args), `Array String` (one arg: the element type), or the
|
|
59
|
+
* internal `Union` / `Tuple` markers. "Con" is short for *constructor*:
|
|
60
|
+
* the name constructs a full type out of the argument types you give it. */
|
|
61
|
+
export interface TCon {
|
|
62
|
+
tag: 'TCon';
|
|
63
|
+
name: string;
|
|
64
|
+
args: Type[];
|
|
65
|
+
/** Marks an array type written as a literal `[]` in a type *annotation* — a
|
|
66
|
+
* strict, exactly-empty array (analogous to a strict-empty record `{}`).
|
|
67
|
+
* Such an array must not absorb a concrete element type during unification;
|
|
68
|
+
* it unifies only with another strict-empty array or with an empty array
|
|
69
|
+
* literal (whose element var carries {@link TVar.emptyArray}). The element
|
|
70
|
+
* arg is retained (`args.length === 1`) so the `Array` 1-arg invariant
|
|
71
|
+
* holds everywhere; this flag is the discriminator. Set only by the
|
|
72
|
+
* type-annotation parser; pure unification metadata. */
|
|
73
|
+
strictEmpty?: boolean;
|
|
74
|
+
/** Parameter tuple of a BUILTIN callback whose positions from this index
|
|
75
|
+
* on are optional for the callee (`Array#map` passes `(x, i, xs)`, most
|
|
76
|
+
* callbacks use only `x`). An as-yet-unknown function passed there is
|
|
77
|
+
* bound to the short form. Preserved by `Substitution.apply`. */
|
|
78
|
+
optionalFrom?: number;
|
|
79
|
+
/** Rigid skolem (`§N`) only: the annotation letter it stands for, so code
|
|
80
|
+
* without access to the engine's skolem map can still display it. */
|
|
81
|
+
skolemName?: string;
|
|
82
|
+
/** Marks a `Union` that is an overload set (from repeated annotations):
|
|
83
|
+
* its members keep declaration order (see `tUnion`). */
|
|
84
|
+
overloadSet?: boolean;
|
|
85
|
+
/** `String` only: the value of a `const` bound to a string literal
|
|
86
|
+
* (`const k = "id"`). Unification ignores it; the directional argument
|
|
87
|
+
* check accepts the value where that literal is expected. */
|
|
88
|
+
stringLiteral?: string;
|
|
89
|
+
/** Optional display-only hint carrying a parameter record inferred at
|
|
90
|
+
* call-site post-processing (see `applyPickedProjection` in
|
|
91
|
+
* `src/infer/calls.ts`). Used by hover and signature help to
|
|
92
|
+
* substitute the parameter slot of an instance-callable overload
|
|
93
|
+
* (e.g. `QueryTag() :: p -> Promise [o]`) when the host TCon's
|
|
94
|
+
* declared arity does not include a parameter arg. Carries no
|
|
95
|
+
* semantic meaning during unification or type printing of the
|
|
96
|
+
* TCon itself; consumers must opt in to reading it. */
|
|
97
|
+
paramHint?: Type;
|
|
98
|
+
}
|
|
99
|
+
/** A function type `a -> b`: "takes an `a`, gives back a `b`". Functions
|
|
100
|
+
* with several parameters are stored either as a chain of these
|
|
101
|
+
* (`a -> b -> c`, i.e. curried) or with a Tuple parameter (`(a, b) -> c`). */
|
|
102
|
+
export interface TFun {
|
|
103
|
+
tag: 'TFun';
|
|
104
|
+
param: Type;
|
|
105
|
+
result: Type;
|
|
106
|
+
}
|
|
107
|
+
/** A record/object type `{ field1 :: Type1, field2 :: Type2 }`.
|
|
108
|
+
*
|
|
109
|
+
* When `rest` is set, the record is **open** (row-polymorphic): the row
|
|
110
|
+
* variable absorbs additional fields during unification, modelling the
|
|
111
|
+
* `{ x, ...rest }` JavaScript spread/rest pattern. When undefined, the
|
|
112
|
+
* record is closed (the historical default — preserved for back-compat).
|
|
113
|
+
*/
|
|
114
|
+
export interface TRecord {
|
|
115
|
+
tag: 'TRecord';
|
|
116
|
+
fields: Record<string, Type>;
|
|
117
|
+
/** Row variable for open records. Unifies with a TRecord of leftover
|
|
118
|
+
* fields when this record is unified against another with extra keys.
|
|
119
|
+
*
|
|
120
|
+
* Historically this was a plain {@link TVar}; W2 introduced the
|
|
121
|
+
* disjoint {@link TRow} sort and TRecord.rest now accepts either —
|
|
122
|
+
* the migration to row-only happens incrementally as call-sites are
|
|
123
|
+
* audited. Mixed shapes are valid: a TVar in rest position behaves
|
|
124
|
+
* as a row by virtue of its position (i.e. it can never resolve to a
|
|
125
|
+
* non-record without unification failing). */
|
|
126
|
+
rest?: TVar | TRow;
|
|
127
|
+
/** Optional alias name for display (e.g. 'Person' instead of the expanded fields). */
|
|
128
|
+
alias?: string;
|
|
129
|
+
/** Marks a record written as a literal `{}` in a type *annotation* — a
|
|
130
|
+
* strict, closed, exactly-empty object. Such a record must not absorb
|
|
131
|
+
* surplus fields during unification (unlike inferred empty object literals,
|
|
132
|
+
* which stay open/lenient so growing objects still type-check). Set only
|
|
133
|
+
* by the type-annotation parser; pure unification metadata. */
|
|
134
|
+
strictEmpty?: boolean;
|
|
135
|
+
/** Rigid skolem (`§N`) only: the annotation letter it stands for, so code
|
|
136
|
+
* without access to the engine's skolem map can still display it. */
|
|
137
|
+
skolemName?: string;
|
|
138
|
+
/** When this record was produced by a `Picked R sel` projection, holds
|
|
139
|
+
* the source row name `R`. Survives the `alias`-stripping that
|
|
140
|
+
* inlines the projection in hover output, so unification can still
|
|
141
|
+
* match the record against `Picked R _` slot expectations in selector
|
|
142
|
+
* unions (e.g. a `…Selector` branch like `QueryTag p (Picked LocationRow a)`).
|
|
143
|
+
* Generic mechanism — any library that uses `Picked` benefits, not
|
|
144
|
+
* just query-builder. */
|
|
145
|
+
pickedFrom?: string;
|
|
146
|
+
/** Set on a `Picked` projection whose selection named no columns: the
|
|
147
|
+
* "all columns" result is a fallback for running the query by itself,
|
|
148
|
+
* not a selection — in a `Merge` (e.g. `QueryTag#concat`) such a record
|
|
149
|
+
* is the identity and the other operands decide the fields. */
|
|
150
|
+
defaultProjection?: boolean;
|
|
151
|
+
/** Polymorphic-label fields, e.g. `{ [k] :: a }` where `k` is a label
|
|
152
|
+
* variable. Once `k` resolves to a literal label, the entry migrates
|
|
153
|
+
* to {@link fields} during substitution. Keeping these separate from
|
|
154
|
+
* string-keyed `fields` avoids ambiguous encoding while the label is
|
|
155
|
+
* still a variable. */
|
|
156
|
+
labelFields?: Array<{
|
|
157
|
+
label: TLabel;
|
|
158
|
+
type: Type;
|
|
159
|
+
}>;
|
|
160
|
+
/** Per-field type schemes captured at annotated member assignment time.
|
|
161
|
+
* When a member is assigned via `Obj.X = func` and an HM annotation
|
|
162
|
+
* `// X :: Obj.X :: ...` (or `// Obj.X :: ...`) is in scope, the
|
|
163
|
+
* scheme is recorded here in addition to the instantiated type going
|
|
164
|
+
* into {@link fields}. Member-access reads (e.g. `Obj.X(args)` or
|
|
165
|
+
* `aliased.X(args)` after `const aliased = Obj`) re-instantiate the
|
|
166
|
+
* scheme freshly per use site so argument unification AND constraint
|
|
167
|
+
* validation happen at the call site, not at the assignment site.
|
|
168
|
+
* Pure inference metadata: ignored by `unify`/`structuralEquals`. */
|
|
169
|
+
fieldSchemes?: Record<string, Scheme>;
|
|
170
|
+
/** Optional per-field display strings used by `typeToString` to render
|
|
171
|
+
* fields whose declared form cannot be reconstructed from the stored
|
|
172
|
+
* field type alone — e.g. a method annotation
|
|
173
|
+
* `// Array#chain :: builtIn.Array :: Array a ~> (a -> Array b) -> Array b`
|
|
174
|
+
* stores the method-type (right of `~>`) as the field type, but hover
|
|
175
|
+
* on the host record should still show the full `Array a ~> …` form.
|
|
176
|
+
* Pure display metadata: ignored by `unify`/`structuralEquals`. */
|
|
177
|
+
fieldDisplays?: Record<string, string>;
|
|
178
|
+
/** Field names that were marked with a `// ::hidden` (or `// ::private`)
|
|
179
|
+
* directive directly above the property in an object literal. Kept on
|
|
180
|
+
* the type so completion/hover can filter them while structural
|
|
181
|
+
* unification still sees the underlying field. Pure metadata:
|
|
182
|
+
* ignored by `unify`. */
|
|
183
|
+
hiddenFields?: Set<string>;
|
|
184
|
+
/** Set by `tryExpandRowMap` on a label-group result row that also carries
|
|
185
|
+
* an open `...b` tail (e.g. the annotation `({ [k]::a }, {...b}) -> { [k]::a, ...b }`).
|
|
186
|
+
* Signals that when the row variable resolves to a concrete record during
|
|
187
|
+
* `Substitution.apply`, overlapping keys must be DEEP-merged
|
|
188
|
+
* (`deepMergeTypes`) rather than first-wins kept — so a spread-merge
|
|
189
|
+
* combines `likedTypes::[String]` and `likedTypes::[Number]` into
|
|
190
|
+
* `[String | Number]`. Pure inference metadata: ignored by `unify`. */
|
|
191
|
+
mergeRow?: boolean;
|
|
192
|
+
}
|
|
193
|
+
/** A field-label type, used by row polymorphism's presence/absence constraints.
|
|
194
|
+
* A label is either a concrete literal (e.g. `'x'`) — `kind: 'lit'` —
|
|
195
|
+
* or a label variable that ranges over labels — `kind: 'var'`.
|
|
196
|
+
* Label vars participate in unification just like ordinary type vars
|
|
197
|
+
* but live in a separate sort: they unify only with other labels. */
|
|
198
|
+
export interface TLabelLit {
|
|
199
|
+
tag: 'TLabel';
|
|
200
|
+
kind: 'lit';
|
|
201
|
+
value: string;
|
|
202
|
+
}
|
|
203
|
+
export interface TLabelVar {
|
|
204
|
+
tag: 'TLabel';
|
|
205
|
+
kind: 'var';
|
|
206
|
+
id: number;
|
|
207
|
+
name: string;
|
|
208
|
+
}
|
|
209
|
+
export type TLabel = TLabelLit | TLabelVar;
|
|
210
|
+
/** A row variable — a separate sort from {@link TVar}. Row variables
|
|
211
|
+
* inhabit only the rest-position of records, where they absorb the
|
|
212
|
+
* set of remaining fields during row-unification. Distinguishing them
|
|
213
|
+
* from ordinary type variables eliminates the historical conflation of
|
|
214
|
+
* "type-of-type" vs. "row-of-fields" in `TRecord.rest` and lets the
|
|
215
|
+
* pretty-printer render them with the distinctive `...r` syntax.
|
|
216
|
+
*
|
|
217
|
+
* TRow ids live in the SAME counter as TVar ids — they are still
|
|
218
|
+
* produced via {@link freshTypeVarId} so that all-vars set tracking
|
|
219
|
+
* (e.g. occurs-check) does not need a second id space; the disjointness
|
|
220
|
+
* is enforced by `tag` only. */
|
|
221
|
+
export interface TRow {
|
|
222
|
+
tag: 'TRow';
|
|
223
|
+
id: number;
|
|
224
|
+
name: string;
|
|
225
|
+
}
|
|
226
|
+
/** A nested universal quantifier — the rank-N building block.
|
|
227
|
+
*
|
|
228
|
+
* Plain language: `forall a. a -> a` as a *type* (not a scheme). A
|
|
229
|
+
* `TForall` appears only in NESTED positions — e.g. as a function
|
|
230
|
+
* parameter (`(forall a. a -> a) -> b`, rank-2) or a record field value.
|
|
231
|
+
* Top-level / result-position quantifiers are hoisted into the enclosing
|
|
232
|
+
* {@link Scheme} by the parser (prenex normalization), so a `TForall`
|
|
233
|
+
* node always marks a place where the CALLEE chooses the instantiation
|
|
234
|
+
* (the caller must supply a genuinely polymorphic value).
|
|
235
|
+
*
|
|
236
|
+
* Invariants:
|
|
237
|
+
* - `vars` ids are globally fresh and occur ONLY inside `body` — they are
|
|
238
|
+
* never bound in the engine substitution and never quantified by any
|
|
239
|
+
* enclosing Scheme.
|
|
240
|
+
* - `constraints` (optional) scope over `vars`, e.g.
|
|
241
|
+
* `forall f. Functor f => (a -> f a)`. */
|
|
242
|
+
export interface TForall {
|
|
243
|
+
tag: 'TForall';
|
|
244
|
+
/** Bound type-variable ids (fresh, scoped to `body`). */
|
|
245
|
+
vars: number[];
|
|
246
|
+
/** Source names of the bound variables, parallel to `vars`. */
|
|
247
|
+
varNames: string[];
|
|
248
|
+
/** Constraints scoped to the bound variables (`forall f. Functor f => …`). */
|
|
249
|
+
constraints?: Constraint[];
|
|
250
|
+
/** The quantified body type. */
|
|
251
|
+
body: Type;
|
|
252
|
+
}
|
|
253
|
+
export type Type = TVar | TCon | TFun | TRecord | TLabel | TRow | TForall;
|
|
254
|
+
/** A type class constraint, e.g. `Functor f` or `Monoid (f a)`,
|
|
255
|
+
* or a structural-union constraint like `((a -> Number) | Number) run`. */
|
|
256
|
+
export interface Constraint {
|
|
257
|
+
className: string;
|
|
258
|
+
typeVarName: string;
|
|
259
|
+
/** Branch-specific bound var id this constraint targets. Set by
|
|
260
|
+
* {@link mergeOverloadSchemes} when combining overload branches so a
|
|
261
|
+
* constraint from one branch (e.g. `Semigroupoid c`) attaches to ITS OWN
|
|
262
|
+
* branch's `c` var rather than colliding by name with a same-named var in
|
|
263
|
+
* another branch. When present, instantiation resolves the fresh var id
|
|
264
|
+
* through the id map instead of the (ambiguous) name map. */
|
|
265
|
+
varId?: number;
|
|
266
|
+
/** True when the constraint uses applied syntax, e.g. `Monoid (f a)`.
|
|
267
|
+
* Applied constraints target the constructor of the applied type. */
|
|
268
|
+
isApplied?: boolean;
|
|
269
|
+
/** Inner type-variable names from applied constraints, e.g. `['a']` for `Monoid (f a)`.
|
|
270
|
+
* A nested application renders as one compound entry, e.g. `['(t a)']` for
|
|
271
|
+
* `Setoid (f (t a))`. */
|
|
272
|
+
appliedArgNames?: string[];
|
|
273
|
+
/** Parsed inner argument TYPES from applied constraints — parallel to
|
|
274
|
+
* `appliedArgNames`. Plain vars are TVars; a nested application
|
|
275
|
+
* (`Setoid (f (t a))`) is the same kv-encoded TCon the signature body
|
|
276
|
+
* would produce for `t a`. */
|
|
277
|
+
appliedArgs?: Type[];
|
|
278
|
+
/** When set, this is an inline anonymous structural-union constraint
|
|
279
|
+
* written as `(T1 | T2 | …) v =>`. The constrained type variable must
|
|
280
|
+
* unify with one of the listed alternative types (left-to-right).
|
|
281
|
+
* `className` then holds a synthetic display string. */
|
|
282
|
+
unionAlternatives?: Type[];
|
|
283
|
+
/** Positional type arguments supplied at the use site for a structural
|
|
284
|
+
* constraint defined as `::constraint Name p1 p2 … pN = …`. Each entry
|
|
285
|
+
* may be a TVar (use-site bound) or a concrete type. Matches the def's
|
|
286
|
+
* `headerParams` positionally. `typeVarName` mirrors the LAST positional
|
|
287
|
+
* arg when it is a bare TVar (so existing nominal-style consumers keep
|
|
288
|
+
* reading it); when the last positional arg is concrete, `typeVarName`
|
|
289
|
+
* is set to the synthetic placeholder '_concrete'. */
|
|
290
|
+
positionalArgs?: Type[];
|
|
291
|
+
}
|
|
292
|
+
/** A type predicate for narrowing, attached via `::narrow` on a Boolean-returning function annotation */
|
|
293
|
+
export interface TypePredicate {
|
|
294
|
+
/** The type-variable name of the parameter that gets narrowed (e.g. 'a').
|
|
295
|
+
* May be empty when the narrowed parameter is not a bare type variable
|
|
296
|
+
* (e.g. a record parameter like `{ [k] :: a }`). */
|
|
297
|
+
paramName: string;
|
|
298
|
+
/** The (0-based) curried-parameter index that gets narrowed. For a simple
|
|
299
|
+
* `a -> Boolean` predicate this is 0; for a multi-parameter predicate such
|
|
300
|
+
* as `k -> { [k] :: a } -> Boolean` it is the index of the LAST parameter
|
|
301
|
+
* (the value being tested), here 1. */
|
|
302
|
+
paramIndex: number;
|
|
303
|
+
/** The type to narrow to when the predicate returns true (e.g. String) */
|
|
304
|
+
narrowedType: Type;
|
|
305
|
+
/** The label-variable name referenced in {@link narrowedType} (e.g. 'k' in
|
|
306
|
+
* `{ [k] :: a }`). When set, the call-site narrowing substitutes this
|
|
307
|
+
* label var with the concrete key argument supplied at {@link keyParamIndex}
|
|
308
|
+
* (when that argument is a string literal). */
|
|
309
|
+
keyVarName?: string;
|
|
310
|
+
/** The (0-based) curried-parameter index supplying the value for
|
|
311
|
+
* {@link keyVarName} — the index of the signature parameter whose type
|
|
312
|
+
* variable name matches the label var (e.g. 0 for the `k` in
|
|
313
|
+
* `k -> { [k] :: a } -> Boolean`). */
|
|
314
|
+
keyParamIndex?: number;
|
|
315
|
+
}
|
|
316
|
+
/** Conditional return type info for literal equality or truthiness guards in function bodies.
|
|
317
|
+
* When a function has `if (param === literal) { return T; }` or `if (param) { return T; }`,
|
|
318
|
+
* this records the param position and the matching return type string
|
|
319
|
+
* so the return type union can be narrowed at call sites. */
|
|
320
|
+
export interface ConditionalReturn {
|
|
321
|
+
paramIndex: number;
|
|
322
|
+
matchReturnTypeStr: string;
|
|
323
|
+
literalValue?: string | number | boolean | bigint | RegExp | null;
|
|
324
|
+
isTruthiness?: boolean;
|
|
325
|
+
}
|
|
326
|
+
export interface Scheme {
|
|
327
|
+
vars: number[];
|
|
328
|
+
type: Type;
|
|
329
|
+
constraints?: Constraint[];
|
|
330
|
+
typePredicate?: TypePredicate;
|
|
331
|
+
isCurriedResult?: boolean;
|
|
332
|
+
isCurryWrapper?: boolean;
|
|
333
|
+
/** curryN-style wrapper: number of leading arguments before the function
|
|
334
|
+
* to curry (`curryN :: Number -> ((a, b, ...) -> z) -> a -> b -> ... -> z`). */
|
|
335
|
+
curryLeadingArgs?: number;
|
|
336
|
+
conditionalReturn?: ConditionalReturn;
|
|
337
|
+
optionalParamSlots?: number[];
|
|
338
|
+
/** `::rep` representatives attached to a constrained function. Each entry
|
|
339
|
+
* lets a container type discharge a constraint method (constraint, typeName,
|
|
340
|
+
* methodName) via the local representing `signature` — but ONLY while
|
|
341
|
+
* discharging THIS function's constraints (call-scoped, not global). See
|
|
342
|
+
* RepEntry. Travels with the scheme across the import boundary. */
|
|
343
|
+
reps?: RepEntry[];
|
|
344
|
+
/** Display-only override: the **annotation** type to show for this binding,
|
|
345
|
+
* regardless of how body inference later substitutes its vars. Set on
|
|
346
|
+
* annotated function parameters so hover/usages always render the signature
|
|
347
|
+
* form (`{ a }`, `{ x :: Number }`, …) instead of a body-poisoned type.
|
|
348
|
+
* Dropped by control-flow narrowing (which rebinds via plain `mono`), so an
|
|
349
|
+
* accepted narrow inside e.g. `if (!b) { … }` still shows the narrowed type. */
|
|
350
|
+
frozenDisplay?: Type;
|
|
351
|
+
/** True when the scheme's type contains a nested {@link TForall} (rank-N
|
|
352
|
+
* annotation). Cached at parse time so hot paths can gate all rank-N
|
|
353
|
+
* handling behind a single boolean check. */
|
|
354
|
+
hasForall?: boolean;
|
|
355
|
+
}
|
|
356
|
+
/** A `::rep <Constraint> <Type#method>` representative. Declares that the
|
|
357
|
+
* named container method (already annotated locally in the declaring file)
|
|
358
|
+
* stands in for the constraint's like-named method when satisfying that
|
|
359
|
+
* constraint — scoped to the function that carries it. `signature` is the
|
|
360
|
+
* resolved local annotation signature (form-exact, see Fase 2). */
|
|
361
|
+
export interface RepEntry {
|
|
362
|
+
constraint: string;
|
|
363
|
+
typeName: string;
|
|
364
|
+
methodName: string;
|
|
365
|
+
signature: string;
|
|
366
|
+
/** True when the rep was declared with `Type.method` (a static constraint
|
|
367
|
+
* method, no `~>` receiver); false/undefined for instance reps. */
|
|
368
|
+
isStatic?: boolean;
|
|
369
|
+
}
|
|
370
|
+
/** Create a fresh type variable (a brand-new "unknown type" placeholder)
|
|
371
|
+
* with a unique id. Without an explicit name it gets an auto name like
|
|
372
|
+
* `t42` — the pretty-printer later renames those to `a`, `b`, `c`, … */
|
|
373
|
+
export declare function tVar(name?: string): TVar;
|
|
374
|
+
/** Smart constructor for a fresh row-variable. Used by the parser when
|
|
375
|
+
* it sees `{ ...r }` with a lowercase identifier, and by destructure
|
|
376
|
+
* inference (`{ a, ...rest }` patterns) to allocate the row-tail. */
|
|
377
|
+
export declare function tRow(name?: string): TRow;
|
|
378
|
+
/** Create a named type, e.g. `tCon('Number')` or `tCon('Array', [elem])`. */
|
|
379
|
+
export declare function tCon(name: string, args?: Type[]): TCon;
|
|
380
|
+
/** Create a function type `param -> result`. */
|
|
381
|
+
export declare function tFun(param: Type, result: Type): TFun;
|
|
382
|
+
/** Create a nested universal quantifier (rank-N position), e.g.
|
|
383
|
+
* `forall a. a -> a` as used inside `(forall a. a -> a) -> b`. */
|
|
384
|
+
export declare function tForall(vars: number[], varNames: string[], body: Type, constraints?: Constraint[]): TForall;
|
|
385
|
+
/** Does the type contain a nested {@link TForall} anywhere? */
|
|
386
|
+
export declare function containsForall(t: Type): boolean;
|
|
387
|
+
/** Create a type scheme: `type` with the variable ids in `vars` sealed in
|
|
388
|
+
* (universally quantified — "works for any choice of these variables"). */
|
|
389
|
+
export declare function scheme(vars: number[], type: Type): Scheme;
|
|
390
|
+
/** Create a monomorphic scheme (no quantified variables) */
|
|
391
|
+
export declare function mono(type: Type): Scheme;
|
|
392
|
+
/** Monomorphic scheme carrying a display-only `frozenDisplay` override. Used
|
|
393
|
+
* for annotated function parameters: `type` participates in body inference as
|
|
394
|
+
* usual, while `frozenDisplay` (the annotation) is what hover renders for the
|
|
395
|
+
* parameter and every reference to it. Defaults `frozenDisplay` to `type`. */
|
|
396
|
+
export declare function monoFrozen(type: Type, frozen?: Type): Scheme;
|
|
397
|
+
export declare const T_ARRAY = "Array";
|
|
398
|
+
export declare const T_TUPLE = "$Tuple";
|
|
399
|
+
export declare const T_UNION = "Union";
|
|
400
|
+
export declare const T_SPREAD_ARRAY = "SpreadArray";
|
|
401
|
+
export declare const T_ERROR = "$error";
|
|
402
|
+
export declare const T_NUMBER = "Number";
|
|
403
|
+
export declare const T_STRING = "String";
|
|
404
|
+
export declare const T_BOOLEAN = "Boolean";
|
|
405
|
+
export declare const T_TYPEREP = "TypeRep";
|
|
406
|
+
/** The two built-ins with mandatory children: `Function [params] result`
|
|
407
|
+
* and `Object k a`. Both are kept in applied `TCon` form for display but
|
|
408
|
+
* are pure sugar over `TFun` / `TRecord` (see `desugarFunctionType` /
|
|
409
|
+
* `desugarObjectType`). */
|
|
410
|
+
export declare const T_FUNCTION = "Function";
|
|
411
|
+
export declare const T_OBJECT = "Object";
|
|
412
|
+
/** Reserved TCon name for inline call-site record projection. A signature
|
|
413
|
+
* such as `[a] -> QueryTag (Picked R a)` tells the call-expression
|
|
414
|
+
* post-processor in `src/infer/calls.ts` to inspect the call's literal
|
|
415
|
+
* array argument and replace `Picked R a` with a record built from the
|
|
416
|
+
* array's elements (string-literal columns become row-field types,
|
|
417
|
+
* identifiers of `Prop T` type contribute named fields, nested calls of
|
|
418
|
+
* type `QueryTag YRow` resolve via the parent row's method-shadows).
|
|
419
|
+
* Generic — not coupled to any one library. */
|
|
420
|
+
export declare const T_PICKED = "Picked";
|
|
421
|
+
/** Reserved TCon name for structural record-union reduction. An
|
|
422
|
+
* annotation such as `QueryTag#concat :: QueryTag p1 r1 ~> QueryTag p2 r2 ->
|
|
423
|
+
* QueryTag (Merge p1 p2) (Merge r1 r2)` tells the call-expression
|
|
424
|
+
* post-processor in `src/infer/calls.ts` to collapse each `Merge a b`
|
|
425
|
+
* whose args resolve to two TRecords into a single structural-union
|
|
426
|
+
* record (alias-stripped). Conflicting field types are unified.
|
|
427
|
+
* Generic — usable by any combinator that merges row + param shapes. */
|
|
428
|
+
export declare const T_MERGE = "Merge";
|
|
429
|
+
/** Is `t` a TCon with the given name? */
|
|
430
|
+
export declare function isTCon(t: Type, name: string): t is TCon;
|
|
431
|
+
/** Is `t` a Union type? (`TCon('Union', [...])`) */
|
|
432
|
+
export declare function isUnion(t: Type): t is TCon;
|
|
433
|
+
/** Is `t` a Tuple type? (`TCon('Tuple', [...])`) */
|
|
434
|
+
export declare function isTuple(t: Type): t is TCon;
|
|
435
|
+
/** Is `t` the `$error` sentinel produced by failed property accesses? */
|
|
436
|
+
export declare function isErrorType(t: Type): boolean;
|
|
437
|
+
/** Does any subtree of `t` contain the `$error` sentinel? Used by hover
|
|
438
|
+
* to suppress display lines that have been polluted by error recovery
|
|
439
|
+
* poisoning (where free type variables in a failed unification are bound
|
|
440
|
+
* to `$error` to stop diagnostic cascades). */
|
|
441
|
+
export declare function containsErrorType(t: Type): boolean;
|
|
442
|
+
export declare const tNumber: TCon;
|
|
443
|
+
export declare const tString: TCon;
|
|
444
|
+
export declare const tBool: TCon;
|
|
445
|
+
export declare const tBigInt: TCon;
|
|
446
|
+
export declare const tSymbol: TCon;
|
|
447
|
+
export declare const tNull: TCon;
|
|
448
|
+
export declare const tUndefined: TCon;
|
|
449
|
+
export declare const tVoid: TCon;
|
|
450
|
+
export declare const T_ANY_TYPE = "Any";
|
|
451
|
+
export declare const tAnyType: TCon;
|
|
452
|
+
export declare const tObject: TCon;
|
|
453
|
+
export declare const tBuffer: TCon;
|
|
454
|
+
export declare const tInteger: TCon;
|
|
455
|
+
export declare const tFloat: TCon;
|
|
456
|
+
export declare const tDouble: TCon;
|
|
457
|
+
export declare const tNonNegativeInteger: TCon;
|
|
458
|
+
export declare const tNegativeInteger: TCon;
|
|
459
|
+
export declare const tPositiveNumber: TCon;
|
|
460
|
+
export declare const tNegativeNumber: TCon;
|
|
461
|
+
export declare const tValidNumber: TCon;
|
|
462
|
+
export declare const tNonZeroValidNumber: TCon;
|
|
463
|
+
export declare const tFiniteNumber: TCon;
|
|
464
|
+
export declare const tNonZeroFiniteNumber: TCon;
|
|
465
|
+
export declare const tPositiveFiniteNumber: TCon;
|
|
466
|
+
export declare const tNegativeFiniteNumber: TCon;
|
|
467
|
+
export declare const tNonZeroInteger: TCon;
|
|
468
|
+
export declare const tPositiveInteger: TCon;
|
|
469
|
+
export declare function tStrMap(val: Type): TCon;
|
|
470
|
+
/** Check if a type is the `Any` top type (unifies with everything, but is a real named type). */
|
|
471
|
+
export declare function isAnyType(t: Type): boolean;
|
|
472
|
+
/** Numeric subtypes of Number. These are Sanctuary refinement types that
|
|
473
|
+
* should unify with `Number` (and with each other) because JS only has a
|
|
474
|
+
* single `number` runtime type. */
|
|
475
|
+
export declare const NUMERIC_SUBTYPES: ReadonlySet<string>;
|
|
476
|
+
/** Is this type `Number` or one of its Sanctuary subtypes? */
|
|
477
|
+
export declare function isNumericType(t: Type): boolean;
|
|
478
|
+
/** May the numeric type named `sub` be safely treated as `sup`?
|
|
479
|
+
* E.g. `isNumericSubtypeOf('Integer', 'Number')` → true. */
|
|
480
|
+
export declare function isNumericSubtypeOf(sub: string, sup: string): boolean;
|
|
481
|
+
/** Create an array type `[elem]` — "a list whose elements are all `elem`". */
|
|
482
|
+
export declare function tArray(elem: Type): TCon;
|
|
483
|
+
/** A spread/variadic marker in tuple types: (a, ..., z) */
|
|
484
|
+
export declare const tSpread: TCon;
|
|
485
|
+
/** Check if a type is a spread marker. */
|
|
486
|
+
export declare function isSpread(t: Type): boolean;
|
|
487
|
+
/** A wildcard type that unifies with anything (no substitution produced). */
|
|
488
|
+
export declare const tAny: TCon;
|
|
489
|
+
/** Check if a type is a wildcard (either bare '*' or named '*:name'). */
|
|
490
|
+
export declare function isWildcard(t: Type): boolean;
|
|
491
|
+
/** Create a named wildcard for a particular annotation var name. */
|
|
492
|
+
export declare function tNamedWildcard(varName: string): TCon;
|
|
493
|
+
/** Extract the display name from a wildcard type. Returns the var name
|
|
494
|
+
* for named wildcards, or '*' for the bare wildcard. */
|
|
495
|
+
export declare function wildcardDisplayName(t: Type): string;
|
|
496
|
+
/** Structural equality check: are `a` and `b` the exact same type, compared
|
|
497
|
+
* piece by piece? ("Structural" = we compare the tree contents, not object
|
|
498
|
+
* identity.) O(tree size) but avoids allocating a string representation. */
|
|
499
|
+
export declare function structuralEquals(a: Type, b: Type): boolean;
|
|
500
|
+
/** Like {@link structuralEquals}, but two UNBOUND empty-array element variables
|
|
501
|
+
* (see {@link TVar.emptyArray}) compare EQUAL regardless of their id. Used
|
|
502
|
+
* ONLY by {@link tUnion} dedup so union members that differ solely in a fresh
|
|
503
|
+
* empty-array element var collapse to a single member. Kept separate from
|
|
504
|
+
* `structuralEquals` to avoid relaxing equality anywhere else (occurs-checks,
|
|
505
|
+
* general inference comparisons). */
|
|
506
|
+
export declare function unionMemberEquivalent(a: Type, b: Type): boolean;
|
|
507
|
+
/**
|
|
508
|
+
* Build a union type (`Number | String | …`) from a list of members.
|
|
509
|
+
*
|
|
510
|
+
* Plain language: a union means "the value is ONE of these types". This
|
|
511
|
+
* builder does three jobs so unions stay small and predictable:
|
|
512
|
+
* 1. flattens unions nested inside unions,
|
|
513
|
+
* 2. removes duplicate members,
|
|
514
|
+
* 3. sorts the members into a canonical order so the same set of types
|
|
515
|
+
* always prints identically.
|
|
516
|
+
* A single-member union collapses to just that member.
|
|
517
|
+
*/
|
|
518
|
+
export declare function tUnion(types: Type[], opts?: {
|
|
519
|
+
overloadSet?: boolean;
|
|
520
|
+
}): Type;
|
|
521
|
+
/** A tuple type for multi-parameter functions: (A, B) -> C */
|
|
522
|
+
export declare function tTuple(types: Type[]): TCon;
|
|
523
|
+
/**
|
|
524
|
+
* Build a function type from parameter types and a return type.
|
|
525
|
+
* Single param: A -> R
|
|
526
|
+
* Multi param: (A, B) -> R (uses Tuple internally)
|
|
527
|
+
*/
|
|
528
|
+
export declare function tMultiFun(params: Type[], result: Type): Type;
|
|
529
|
+
/** Is `t` an applied `Function [params] result` (exactly two children)? */
|
|
530
|
+
export declare function isAppliedFunction(t: Type): t is TCon;
|
|
531
|
+
/** Is `t` an applied `Object k a` (exactly two children)? */
|
|
532
|
+
export declare function isAppliedObject(t: Type): t is TCon;
|
|
533
|
+
/** Extract the positional parameter list from a `Function` first child,
|
|
534
|
+
* which must be array-like (`[x]` → Array, `[x, y]` → SpreadArray, `[]` →
|
|
535
|
+
* strict-empty Array). Returns `null` when the child is not array-like — a
|
|
536
|
+
* malformed annotation that the validator reports separately. */
|
|
537
|
+
export declare function functionParamList(params: Type): Type[] | null;
|
|
538
|
+
/** Desugar `Function [params] result` to the equivalent `TFun`. */
|
|
539
|
+
export declare function desugarFunctionType(params: Type, result: Type): Type;
|
|
540
|
+
/** Desugar `Object k a` to the equivalent `{ [k] :: a }` record. */
|
|
541
|
+
export declare function desugarObjectType(key: Type, val: Type): TRecord;
|
|
542
|
+
/** Canonical opaque "any function" — `Function [a] b` with fresh vars. */
|
|
543
|
+
export declare function tAnyFunction(): TCon;
|
|
544
|
+
/** Canonical opaque "any object" — `Object k a` with a fresh label + value. */
|
|
545
|
+
export declare function tAnyObject(): TCon;
|
|
546
|
+
/** A record type, e.g. `{ name :: String, age :: Number }` */
|
|
547
|
+
export declare function tRecord(fields: Record<string, Type>, alias?: string): TRecord;
|
|
548
|
+
/** An open (row-polymorphic) record `{ field1 :: T1 | r }`. The optional
|
|
549
|
+
* `rest` argument lets callers reuse an existing row variable (for
|
|
550
|
+
* destructuring patterns where the same row is shared between the
|
|
551
|
+
* parameter and the `rest` binding); when omitted, a fresh TVar is
|
|
552
|
+
* allocated. */
|
|
553
|
+
export declare function tOpenRecord(fields: Record<string, Type>, rest?: TVar | TRow): TRecord;
|
|
554
|
+
/**
|
|
555
|
+
* Deep-merge two record types the way `{ ...a, ...b }` spreads them: fields
|
|
556
|
+
* present in only one side are carried over; fields present in BOTH are
|
|
557
|
+
* combined — recursively merged when both are records, otherwise unioned
|
|
558
|
+
* (`Number | String`). Overlapping keys therefore appear exactly once.
|
|
559
|
+
*
|
|
560
|
+
* `labelFields` (index signatures) are concatenated, and the result stays
|
|
561
|
+
* open when either input is open (its row variable is preserved). Inputs
|
|
562
|
+
* are assumed to be already substitution-applied by the caller.
|
|
563
|
+
*/
|
|
564
|
+
export declare function mergeRecordTypes(a: TRecord, b: TRecord): TRecord;
|
|
565
|
+
/**
|
|
566
|
+
* Deep-merge two arbitrary types for `{ ...a, ...b }`-style spreads / `Merge`
|
|
567
|
+
* marker reduction. This is the single shared primitive every merge site
|
|
568
|
+
* routes through so overlapping keys are combined consistently:
|
|
569
|
+
*
|
|
570
|
+
* • both records → field-wise `mergeRecordTypes` (recurses here)
|
|
571
|
+
* • same real container TCon → merge arg-wise, so `[String]` + `[Number]`
|
|
572
|
+
* becomes `[String | Number]` and `[{x::A}]` + `[{x::B}]` becomes
|
|
573
|
+
* `[{x :: A | B}]`. Structural markers (Union / Merge / Tuple / TypeRep /
|
|
574
|
+
* Picked / SpreadArray) are NOT treated as containers — merging their
|
|
575
|
+
* positional args would be meaningless — so they fall through to a union.
|
|
576
|
+
* • structurally identical → either side
|
|
577
|
+
* • anything else → `A | B`
|
|
578
|
+
*/
|
|
579
|
+
export declare function deepMergeTypes(a: Type, b: Type): Type;
|
|
580
|
+
/** A concrete field-label literal, e.g. `tLabelLit('x')`. */
|
|
581
|
+
export declare function tLabelLit(value: string): TLabelLit;
|
|
582
|
+
/** A fresh label variable, optionally with a display name. */
|
|
583
|
+
export declare function tLabelVar(name?: string): TLabelVar;
|
|
584
|
+
/** True when `t` is a label type. */
|
|
585
|
+
export declare function isLabel(t: Type): t is TLabel;
|
|
586
|
+
/** Check whether a TCon name represents a kind variable. */
|
|
587
|
+
export declare function isKindVariable(name: string): boolean;
|
|
588
|
+
/** Create a kind-variable TCon name from the var name and id. */
|
|
589
|
+
export declare function kvName(varName: string, varId: number): string;
|
|
590
|
+
/**
|
|
591
|
+
* Flatten a curried function type into its individual parameter types and final result.
|
|
592
|
+
* e.g. A -> B -> C -> R → { params: [A, B, C], result: R }
|
|
593
|
+
* e.g. (Tuple [A, B]) -> R → { params: [A, B], result: R } (from multi-param)
|
|
594
|
+
*/
|
|
595
|
+
export declare function flattenCurriedType(t: Type): {
|
|
596
|
+
params: Type[];
|
|
597
|
+
result: Type;
|
|
598
|
+
};
|
|
599
|
+
/**
|
|
600
|
+
* Generate all curried overload types for a set of parameters and a result type.
|
|
601
|
+
* For params [A, B, C] and result R, generates all ordered partitions:
|
|
602
|
+
* - A -> B -> C -> R (fully curried)
|
|
603
|
+
* - (A, B) -> C -> R
|
|
604
|
+
* - A -> (B, C) -> R
|
|
605
|
+
* - (A, B, C) -> R (original uncurried)
|
|
606
|
+
*
|
|
607
|
+
* The number of overloads is 2^(n-1) where n = params.length.
|
|
608
|
+
*/
|
|
609
|
+
export declare function generateCurriedOverloads(params: Type[], result: Type): Type[];
|
|
610
|
+
export declare function parseKvName(name: string): Readonly<{
|
|
611
|
+
varName: string;
|
|
612
|
+
varId: number;
|
|
613
|
+
}> | null;
|
|
614
|
+
/**
|
|
615
|
+
* Extract the base constraint name from a possibly-applied constraint string.
|
|
616
|
+
* "Monoid (f a)" → "Monoid", "Semigroup" → "Semigroup".
|
|
617
|
+
*/
|
|
618
|
+
export declare function constraintBaseName(name: string): string;
|
|
619
|
+
/** Matches single lowercase annotation var names (a, b, c, ... z). */
|
|
620
|
+
export declare const ANNOTATION_NAME_RE: RegExp;
|
|
621
|
+
/** Matches auto-generated type var names (t0, t1, ...). */
|
|
622
|
+
export declare const AUTO_TVAR_NAME_RE: RegExp;
|
|
623
|
+
/** Prefix used for rigid skolem TCon names (e.g. `§0`, `§1`). A skolem is a
|
|
624
|
+
* rigid type constant standing in for a universally-quantified annotation
|
|
625
|
+
* variable while a function body is checked against its signature. */
|
|
626
|
+
export declare const SKOLEM_PREFIX = "\u00A7";
|
|
627
|
+
/** True when a type is a rigid skolem constant (a `§N` TCon). */
|
|
628
|
+
export declare function isSkolem(t: Type): boolean;
|
|
629
|
+
/** Render a type as text using each variable's own stored name (no
|
|
630
|
+
* re-lettering). For user-facing output prefer {@link prettyTypeToString},
|
|
631
|
+
* which renames variables to friendly sequential letters. */
|
|
632
|
+
export declare function typeToString(t: Type): string;
|
|
633
|
+
/**
|
|
634
|
+
* Produce an alpha-canonical key string for a scheme: every distinct type /
|
|
635
|
+
* row / label / kind variable is renamed to a positional canonical name
|
|
636
|
+
* (`a`, `b`, `c`, …) in order of first appearance, and the (sorted) constraint
|
|
637
|
+
* list is appended. Two schemes that are identical up to consistent variable
|
|
638
|
+
* renaming therefore produce the SAME key. Used to detect duplicate overload
|
|
639
|
+
* signatures regardless of which variable letters the author happened to use.
|
|
640
|
+
*
|
|
641
|
+
* Plain language: a "fingerprint" for a signature that ignores the author's
|
|
642
|
+
* choice of letter names — `a -> a` and `x -> x` get the same fingerprint.
|
|
643
|
+
*/
|
|
644
|
+
export declare function canonicalSchemeKey(scheme: Scheme): string;
|
|
645
|
+
/** Render a scheme as annotation text, constraints included —
|
|
646
|
+
* e.g. `Functor f => f a -> f b`. */
|
|
647
|
+
export declare function schemeToString(s: Scheme): string;
|
|
648
|
+
/**
|
|
649
|
+
* Pretty-print a type, renaming type variables to a, b, c, ... in order of
|
|
650
|
+
* first appearance. Produces human-friendly output for hover display.
|
|
651
|
+
*/
|
|
652
|
+
export declare function prettyTypeToString(t: Type): string;
|
|
653
|
+
/**
|
|
654
|
+
* Pretty-print `t` using a letter assignment SEEDED from `context` so that a
|
|
655
|
+
* type variable shared between the two renders with the SAME letter in both.
|
|
656
|
+
*
|
|
657
|
+
* Used for hover: when the cursor is on a sub-expression inside a function,
|
|
658
|
+
* `context` is the enclosing function's type. Without this, each hover
|
|
659
|
+
* canonicalizes letters from scratch, so a variable shared by `f :: a -> b`
|
|
660
|
+
* and its result `result` would render as `b` when hovering `f` but `a` when
|
|
661
|
+
* hovering `result` in isolation. Seeding from `context` first pins the
|
|
662
|
+
* shared variable to the letter it has in the enclosing scope.
|
|
663
|
+
*/
|
|
664
|
+
export declare function prettyTypeToStringWithContext(t: Type, context: Type): string;
|
|
665
|
+
/**
|
|
666
|
+
* Build the type-variable → display-letter map that {@link prettyTypeToString}
|
|
667
|
+
* (or {@link prettyTypeToStringWithContext} when `context` is given) uses to
|
|
668
|
+
* render `t`. Exposed so callers that render a constraint prefix separately
|
|
669
|
+
* from the type body (e.g. hover) can label the constrained variable with the
|
|
670
|
+
* SAME letter the body shows for it, instead of the variable's raw internal
|
|
671
|
+
* name.
|
|
672
|
+
*/
|
|
673
|
+
export declare function buildVarDisplayNameMap(t: Type, context?: Type): Map<number, string>;
|
|
674
|
+
/**
|
|
675
|
+
* Pretty-print two types using a shared name map so that the same TVar id
|
|
676
|
+
* gets the same letter in both. Used for error messages like
|
|
677
|
+
* "Cannot unify X with Y" to keep variable names readable and consistent.
|
|
678
|
+
*
|
|
679
|
+
* Distinct TVar ids that originated from the same source name (e.g. both
|
|
680
|
+
* sides of a comparison reference an annotation's `a`) collapse to the same
|
|
681
|
+
* displayed letter so the two type strings line up visually. This matters
|
|
682
|
+
* for the "X has type ... but annotation expects ..." family of messages,
|
|
683
|
+
* where instantiation produces fresh TVar ids on each side.
|
|
684
|
+
*/
|
|
685
|
+
export declare function prettyTypeToStringPair(t1: Type, t2: Type): [string, string];
|
|
686
|
+
/**
|
|
687
|
+
* Rewrite a type so that distinct variables (TVar / TRow / TLabel-var)
|
|
688
|
+
* carrying the SAME user-chosen source name collapse onto a single
|
|
689
|
+
* representative id — a DISPLAY-ONLY normalization. Used when combining
|
|
690
|
+
* independently-instantiated overload branches into one union for hover: each
|
|
691
|
+
* branch wrote e.g. `a`, but `mergeOverloadSchemes` refreshed them to distinct
|
|
692
|
+
* ids, so the pretty-printer would otherwise rename the second `a` to `b`
|
|
693
|
+
* (e.g. `[a] | { b }`). Sharing the id per source name makes it render as the
|
|
694
|
+
* source name in every branch (`[a] | { a }`).
|
|
695
|
+
*
|
|
696
|
+
* Auto-generated names (`t0`, `t1`, …) are left untouched so genuinely
|
|
697
|
+
* distinct inference vars keep distinct letters. The result must be used for
|
|
698
|
+
* display only — it deliberately conflates ids that are NOT semantically equal.
|
|
699
|
+
*/
|
|
700
|
+
export declare function canonicalizeDisplayVarsByName(t: Type): Type;
|
|
701
|
+
/**
|
|
702
|
+
* Collect every display-relevant variable id in `t` (ordinary TVars, row-tail
|
|
703
|
+
* TRow vars, TLabel vars, and higher-kinded `$kv:name:id` ids baked into TCon
|
|
704
|
+
* names). Used by hover scope-seeding to decide whether a piece of enclosing
|
|
705
|
+
* context genuinely SHARES a variable with the hovered type — only then may it
|
|
706
|
+
* influence letter assignment.
|
|
707
|
+
*/
|
|
708
|
+
export declare function collectAllVarIds(t: Type): Set<number>;
|
|
709
|
+
/** Get the final return type of a (possibly curried) function type:
|
|
710
|
+
* for `a -> b -> c` that is `c`. */
|
|
711
|
+
export declare function getReturnType(t: Type): Type;
|
|
712
|
+
/**
|
|
713
|
+
* Merge a list of return types into a unified type.
|
|
714
|
+
* When all types share the same outer TCon, merges inner type args
|
|
715
|
+
* position-by-position. Otherwise produces a flat Union.
|
|
716
|
+
*/
|
|
717
|
+
export declare function mergeReturnTypes(types: Type[]): Type;
|
|
718
|
+
/**
|
|
719
|
+
* Decompose a function type into its parameter slot types for N params.
|
|
720
|
+
* Handles Tuple-encoded multi-param functions, spread/variadic tuples, and
|
|
721
|
+
* JS's "fewer params than expected" convention.
|
|
722
|
+
*
|
|
723
|
+
* For curried: a -> b -> c with N=1 → params=[a], rest=(b -> c)
|
|
724
|
+
* For tuple: (a, b) -> c with N=2 → params=[a, b], rest=c
|
|
725
|
+
*/
|
|
726
|
+
export declare function decomposeFunParams(t: Type, numParams: number): {
|
|
727
|
+
paramTypes: Type[];
|
|
728
|
+
restType: Type;
|
|
729
|
+
extraParamTypes?: Type[];
|
|
730
|
+
} | null;
|
|
731
|
+
/** Count how many parameters a function type expects (returns a display string). */
|
|
732
|
+
export declare function countFunParams(t: Type): string;
|
|
733
|
+
export declare function isNumLitName(name: string): boolean;
|
|
734
|
+
export declare function tNumLit(value: number): TCon;
|
|
735
|
+
export declare function findUnknownTCons(t: Type, known: Set<string>, out?: string[]): string[];
|
|
736
|
+
/** Collect all TVar id→name mappings from a type (for preserving var names across instantiation). */
|
|
737
|
+
export declare function collectVarNames(t: Type, names: Map<number, string>): void;
|
|
738
|
+
//# sourceMappingURL=types.d.ts.map
|