pud.dev 0.0.0-stage → 0.0.2
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 +143 -2
- package/THIRD-PARTY-NOTICES +112 -0
- package/chunk-224av1ab.js +10 -0
- package/chunk-fstxscck.js +3 -0
- package/chunk-h90k6v7w.js +3 -0
- package/chunk-k7a83qqm.js +3 -0
- package/cli.js +37 -0
- package/index.js +2 -0
- package/lean/index.js +880 -0
- package/package.json +32 -3
- package/project-runner.js +2 -0
- package/types/assistant.d.ts +200 -0
- package/types/check.d.ts +55 -0
- package/types/expressions.d.ts +47 -0
- package/types/index.d.ts +4 -0
- package/types/input-scope.d.ts +4 -0
- package/types/lean/command.d.ts +14 -0
- package/types/lean/index.d.ts +5 -0
- package/types/lean/number.d.ts +4 -0
- package/types/lean/program.d.ts +26 -0
- package/types/lean/replay-predicate.d.ts +5 -0
- package/types/lean/replay.d.ts +6 -0
- package/types/lean/scalar.d.ts +23 -0
- package/types/lean/subject.d.ts +25 -0
- package/types/lean/syntax.d.ts +42 -0
- package/types/module.d.ts +9 -0
- package/types/prover-process.d.ts +7 -0
- package/types/run.d.ts +30 -0
- package/types/source.d.ts +5 -0
- package/types/suite-authoring.d.ts +117 -0
- package/types/suite-check.d.ts +10 -0
- package/types/suite.d.ts +44 -0
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pud.dev",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Write proofs for TypeScript functions and check them with Lean.",
|
|
5
|
+
"homepage": "https://pud.dev",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/PudHQ/pud.git",
|
|
9
|
+
"directory": "packages/pud"
|
|
10
|
+
},
|
|
11
|
+
"bugs": "https://github.com/PudHQ/pud/issues",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"typescript",
|
|
14
|
+
"formal-verification",
|
|
15
|
+
"proof-assistant",
|
|
16
|
+
"lean4",
|
|
17
|
+
"bun"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./types/index.d.ts",
|
|
24
|
+
"default": "./index.js"
|
|
25
|
+
},
|
|
26
|
+
"./lean": {
|
|
27
|
+
"types": "./types/lean/index.d.ts",
|
|
28
|
+
"default": "./lean/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"types": "./types/index.d.ts",
|
|
32
|
+
"bin": {
|
|
33
|
+
"pud": "./cli.js"
|
|
34
|
+
}
|
|
6
35
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{Unsupported2}from"./chunk-224av1ab.js";import{checkFiles3,emit3}from"./chunk-fstxscck.js";import{once}from"events";var send=(reply)=>process.send(reply);function progress(event){const acknowledged=event.kind==="validating"?once(process,"message"):undefined;send({kind:"progress",event});return acknowledged}process.once("disconnect",()=>process.exit());process.once("message",async(request)=>{try{const value=request.kind==="check"?await checkFiles3(request.files,{onProgress:request.progress?progress:undefined}):await emit3(request.file,{property:request.property});send({kind:"result",value})}catch(cause){const error=cause instanceof Error?cause:new Error(String(cause));const code="code"in error&&typeof error.code==="string"?error.code:undefined;send({kind:"error",error,unsupported:error instanceof Unsupported2,code})}});
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/** A construct for which the selected frontend or adapter has no semantics. */
|
|
2
|
+
export declare class Unsupported extends Error {
|
|
3
|
+
}
|
|
4
|
+
export declare function failure(error: unknown): {
|
|
5
|
+
status: "unsupported" | "error";
|
|
6
|
+
detail: string;
|
|
7
|
+
};
|
|
8
|
+
export interface SubjectSource {
|
|
9
|
+
name: string;
|
|
10
|
+
file: string;
|
|
11
|
+
source: string;
|
|
12
|
+
/** Read and track a UTF-8 input relative to the subject's directory or by absolute path. */
|
|
13
|
+
readDependency?(path: string): string;
|
|
14
|
+
/** Read a linked source and track any import resolution that selected it. */
|
|
15
|
+
readModule?(path: string, resolveAgain?: () => string): {
|
|
16
|
+
canonical: string;
|
|
17
|
+
source: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface Counterexample {
|
|
21
|
+
summary: string;
|
|
22
|
+
input: Record<string, string>;
|
|
23
|
+
result: string;
|
|
24
|
+
/** A distinct value accepted by an exact result rule for the same input. */
|
|
25
|
+
alternative?: string;
|
|
26
|
+
difference?: {
|
|
27
|
+
subject: string;
|
|
28
|
+
expected: string;
|
|
29
|
+
received: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export type ProofType = {
|
|
33
|
+
kind: "integer" | "number" | "boolean";
|
|
34
|
+
} | {
|
|
35
|
+
kind: "opaque";
|
|
36
|
+
name: string;
|
|
37
|
+
} | {
|
|
38
|
+
kind: "array" | "textOrArray";
|
|
39
|
+
item: ProofType;
|
|
40
|
+
};
|
|
41
|
+
/** A TypeScript expression and its mapping from callback bindings to subject parameters. */
|
|
42
|
+
export interface ProofExpression {
|
|
43
|
+
file: string;
|
|
44
|
+
source: string;
|
|
45
|
+
line: number;
|
|
46
|
+
column: number;
|
|
47
|
+
offset: number;
|
|
48
|
+
bindings: ReadonlyMap<string, string>;
|
|
49
|
+
/** In-scope references to Pud's specification helpers. */
|
|
50
|
+
schemaBindings?: ReadonlySet<string>;
|
|
51
|
+
/** The JavaScript Number constructor is in scope in this expression. */
|
|
52
|
+
numberGlobal?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export type NativeProofTerm = {
|
|
55
|
+
assistant: string;
|
|
56
|
+
args: readonly ProofExpression[];
|
|
57
|
+
} & ({
|
|
58
|
+
kind: "reference";
|
|
59
|
+
name: string;
|
|
60
|
+
} | {
|
|
61
|
+
kind: "template";
|
|
62
|
+
parts: readonly string[];
|
|
63
|
+
});
|
|
64
|
+
export type ProofTarget = {
|
|
65
|
+
kind: "parameter";
|
|
66
|
+
name: string;
|
|
67
|
+
} | {
|
|
68
|
+
kind: "result";
|
|
69
|
+
} | {
|
|
70
|
+
kind: "quantified";
|
|
71
|
+
};
|
|
72
|
+
export type ProofComparison = "eq" | "gt" | "gte" | "lt" | "lte";
|
|
73
|
+
export type ProofPredicate = {
|
|
74
|
+
kind: "boolean";
|
|
75
|
+
expression: ProofExpression;
|
|
76
|
+
} | {
|
|
77
|
+
kind: "not";
|
|
78
|
+
operand: ProofPredicate;
|
|
79
|
+
} | {
|
|
80
|
+
kind: "binary";
|
|
81
|
+
operator: "and" | "or" | "implies" | "iff";
|
|
82
|
+
left: ProofPredicate;
|
|
83
|
+
right: ProofPredicate;
|
|
84
|
+
} | {
|
|
85
|
+
kind: "quantifier";
|
|
86
|
+
quantifier: "forall" | "exists";
|
|
87
|
+
variable: string;
|
|
88
|
+
domain: {
|
|
89
|
+
kind: "array";
|
|
90
|
+
expression: ProofExpression;
|
|
91
|
+
} | {
|
|
92
|
+
kind: "schema";
|
|
93
|
+
type: "integer" | "number" | "boolean";
|
|
94
|
+
constraints: readonly ProofConstraint[];
|
|
95
|
+
};
|
|
96
|
+
predicate: ProofPredicate;
|
|
97
|
+
};
|
|
98
|
+
export type ProofConstraint = {
|
|
99
|
+
kind: "condition";
|
|
100
|
+
expression: ProofExpression;
|
|
101
|
+
} | {
|
|
102
|
+
kind: "proposition";
|
|
103
|
+
predicate: ProofPredicate;
|
|
104
|
+
} | {
|
|
105
|
+
kind: "comparison";
|
|
106
|
+
target: ProofTarget;
|
|
107
|
+
operator: ProofComparison;
|
|
108
|
+
value: ProofExpression;
|
|
109
|
+
} | {
|
|
110
|
+
kind: "nearestInteger";
|
|
111
|
+
target: ProofTarget;
|
|
112
|
+
value: ProofExpression;
|
|
113
|
+
ties: "up" | "down";
|
|
114
|
+
} | {
|
|
115
|
+
kind: "sameValue";
|
|
116
|
+
target: ProofTarget;
|
|
117
|
+
value: ProofExpression;
|
|
118
|
+
} | {
|
|
119
|
+
kind: "refinement";
|
|
120
|
+
target: ProofTarget;
|
|
121
|
+
variable: string;
|
|
122
|
+
predicate: ProofPredicate;
|
|
123
|
+
} | {
|
|
124
|
+
kind: "native";
|
|
125
|
+
target: ProofTarget;
|
|
126
|
+
term: NativeProofTerm;
|
|
127
|
+
};
|
|
128
|
+
export type ProofClaim = {
|
|
129
|
+
premises: readonly ProofConstraint[];
|
|
130
|
+
proof?: NativeProofTerm;
|
|
131
|
+
observation?: ProofCall;
|
|
132
|
+
} & ({
|
|
133
|
+
kind: "return";
|
|
134
|
+
assertions: readonly ProofConstraint[];
|
|
135
|
+
/** The assertions must characterize the observed result uniquely. */
|
|
136
|
+
exactResult?: true;
|
|
137
|
+
reference?: never;
|
|
138
|
+
expectedError?: never;
|
|
139
|
+
} | {
|
|
140
|
+
kind: "equal";
|
|
141
|
+
assertions: readonly [];
|
|
142
|
+
reference: ProofCall;
|
|
143
|
+
expectedError?: never;
|
|
144
|
+
exactResult?: never;
|
|
145
|
+
} | {
|
|
146
|
+
kind: "throw";
|
|
147
|
+
assertions: readonly [];
|
|
148
|
+
expectedError: ProofErrorKind;
|
|
149
|
+
reference?: never;
|
|
150
|
+
exactResult?: never;
|
|
151
|
+
});
|
|
152
|
+
export type ProofErrorKind = "Error" | "RangeError" | "TypeError";
|
|
153
|
+
export interface ProofCall {
|
|
154
|
+
kind: "call";
|
|
155
|
+
callee: "subject" | {
|
|
156
|
+
file: string;
|
|
157
|
+
name: string;
|
|
158
|
+
};
|
|
159
|
+
args: readonly (ProofCall | {
|
|
160
|
+
kind: "parameter";
|
|
161
|
+
name: string;
|
|
162
|
+
})[];
|
|
163
|
+
}
|
|
164
|
+
export interface ProofModule {
|
|
165
|
+
file: string;
|
|
166
|
+
source: string;
|
|
167
|
+
}
|
|
168
|
+
export type ProofOutcome = {
|
|
169
|
+
status: "proved";
|
|
170
|
+
}
|
|
171
|
+
/** A concrete input witnesses a violated assertion or an ambiguous exact result. */
|
|
172
|
+
| {
|
|
173
|
+
status: "disproved";
|
|
174
|
+
counterexample: Counterexample;
|
|
175
|
+
} | {
|
|
176
|
+
status: "unproved" | "unsupported" | "error";
|
|
177
|
+
detail: string;
|
|
178
|
+
diagnostic?: string;
|
|
179
|
+
};
|
|
180
|
+
export type ClaimProgress = (index: number, state: "running" | "finished", status?: ProofOutcome["status"]) => void;
|
|
181
|
+
/** The adapter has parsed the exact implementation snapshot and can certify claims about it. */
|
|
182
|
+
export interface PreparedProofAssistant {
|
|
183
|
+
parameters: readonly {
|
|
184
|
+
name: string;
|
|
185
|
+
type: ProofType;
|
|
186
|
+
}[];
|
|
187
|
+
result: ProofType;
|
|
188
|
+
inspectCall?(call: ProofCall): ProofType;
|
|
189
|
+
/** The assistant can compare the observation with a reference call. */
|
|
190
|
+
callEquality?: true;
|
|
191
|
+
/** The assistant proves both satisfaction and uniqueness for scalar return schemas. */
|
|
192
|
+
exactResults?: true;
|
|
193
|
+
errors?: readonly ProofErrorKind[];
|
|
194
|
+
emit(claim: ProofClaim, modules: readonly ProofModule[]): string | Promise<string>;
|
|
195
|
+
verify(claims: readonly ProofClaim[], modules: readonly ProofModule[], onClaim?: ClaimProgress): Promise<readonly ProofOutcome[]>;
|
|
196
|
+
}
|
|
197
|
+
export interface ProofAssistant<Id extends string = string> {
|
|
198
|
+
readonly id: Id;
|
|
199
|
+
prepare(subject: SubjectSource): PreparedProofAssistant | Promise<PreparedProofAssistant>;
|
|
200
|
+
}
|
package/types/check.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type Counterexample, type ProofAssistant, type ProofOutcome } from "./assistant.ts";
|
|
2
|
+
import type { ConcreteScope } from "./input-scope.ts";
|
|
3
|
+
export interface CheckResult {
|
|
4
|
+
status: ProofOutcome["status"] | "todo";
|
|
5
|
+
name?: string;
|
|
6
|
+
subject?: string;
|
|
7
|
+
line?: number;
|
|
8
|
+
detail?: string;
|
|
9
|
+
diagnostic?: string;
|
|
10
|
+
counterexample?: Counterexample;
|
|
11
|
+
concreteScope?: ConcreteScope;
|
|
12
|
+
exactResult?: true;
|
|
13
|
+
assistant?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface CheckReport {
|
|
16
|
+
file: string;
|
|
17
|
+
results: CheckResult[];
|
|
18
|
+
}
|
|
19
|
+
type ItemEvent = {
|
|
20
|
+
kind: "running";
|
|
21
|
+
indices: readonly number[];
|
|
22
|
+
statuses?: never;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "finished";
|
|
25
|
+
indices: readonly number[];
|
|
26
|
+
statuses: readonly CheckResult["status"][];
|
|
27
|
+
};
|
|
28
|
+
/** Each active index finishes once. Its status is provisional until the final report. */
|
|
29
|
+
export type CheckProgress = {
|
|
30
|
+
kind: "suite";
|
|
31
|
+
file: string;
|
|
32
|
+
index: number;
|
|
33
|
+
total: number;
|
|
34
|
+
totalItems: number;
|
|
35
|
+
items: readonly {
|
|
36
|
+
name: string;
|
|
37
|
+
todo?: boolean;
|
|
38
|
+
}[];
|
|
39
|
+
} | (ItemEvent & {
|
|
40
|
+
file: string;
|
|
41
|
+
}) | {
|
|
42
|
+
kind: "validating";
|
|
43
|
+
};
|
|
44
|
+
export type ItemProgress = (event: ItemEvent) => void;
|
|
45
|
+
export interface CheckOptions {
|
|
46
|
+
adapter?: ProofAssistant;
|
|
47
|
+
onProgress?: (event: CheckProgress) => void;
|
|
48
|
+
}
|
|
49
|
+
export interface EmitOptions extends Pick<CheckOptions, "adapter"> {
|
|
50
|
+
property?: string;
|
|
51
|
+
}
|
|
52
|
+
/** Check a batch against shared snapshots of the sidecars and their proof inputs. */
|
|
53
|
+
export declare function checkFiles(files: readonly string[], options?: CheckOptions): Promise<CheckReport[]>;
|
|
54
|
+
export declare function emit(file: string, options: EmitOptions): Promise<string>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Node } from "@babel/types";
|
|
2
|
+
/** Typed expressions shared by TypeScript frontends. */
|
|
3
|
+
export type Sort = "integer" | "boolean" | "string";
|
|
4
|
+
export type BinaryOp = "+" | "-" | "*" | "<" | "<=" | ">" | ">=" | "===" | "!==" | "&&" | "||";
|
|
5
|
+
export type Expr = {
|
|
6
|
+
kind: "integer";
|
|
7
|
+
sort: "integer";
|
|
8
|
+
value: string;
|
|
9
|
+
} | {
|
|
10
|
+
kind: "boolean";
|
|
11
|
+
sort: "boolean";
|
|
12
|
+
value: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "string";
|
|
15
|
+
sort: "string";
|
|
16
|
+
value: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "reference";
|
|
19
|
+
sort: Sort;
|
|
20
|
+
path: string[];
|
|
21
|
+
} | {
|
|
22
|
+
kind: "unary";
|
|
23
|
+
sort: Sort;
|
|
24
|
+
op: "!" | "-";
|
|
25
|
+
arg: Expr;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "binary";
|
|
28
|
+
sort: Sort;
|
|
29
|
+
op: BinaryOp;
|
|
30
|
+
left: Expr;
|
|
31
|
+
right: Expr;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "choose";
|
|
34
|
+
sort: Sort;
|
|
35
|
+
test: Expr;
|
|
36
|
+
yes: Expr;
|
|
37
|
+
no: Expr;
|
|
38
|
+
};
|
|
39
|
+
export declare const integer: (value: bigint) => Expr;
|
|
40
|
+
export declare const bool: (value: boolean) => Expr;
|
|
41
|
+
export declare const string: (value: string) => Expr;
|
|
42
|
+
export declare const ref: (sort: Sort, ...path: string[]) => Expr;
|
|
43
|
+
export declare function unary(op: "!" | "-", arg: Expr): Expr;
|
|
44
|
+
export declare function binary(op: BinaryOp, left: Expr, right: Expr): Expr;
|
|
45
|
+
export declare function choose(test: Expr, yes: Expr, no: Expr): Expr;
|
|
46
|
+
/** The caller supplies the meanings of names and domain-specific observations. */
|
|
47
|
+
export declare function readExpression(file: string, node: Node, resolve: (node: Node) => Expr | undefined): Expr;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { check, checkFiles, emit } from "./run.ts";
|
|
2
|
+
export type { CheckOptions, CheckProgress, CheckReport, CheckResult, EmitOptions } from "./check.ts";
|
|
3
|
+
export { defineConfig, describe, expect, given, it, native, pud, type PudConfig, type NativeModule, type NativeSyntax, type NativeTerm, type Proposition, type Schema } from "./suite-authoring.ts";
|
|
4
|
+
export { Unsupported, type ClaimProgress, type Counterexample, type NativeProofTerm, type PreparedProofAssistant, type ProofAssistant, type ProofCall, type ProofClaim, type ProofComparison, type ProofConstraint, type ProofErrorKind, type ProofExpression, type ProofModule, type ProofOutcome, type ProofPredicate, type ProofTarget, type ProofType, type SubjectSource } from "./assistant.ts";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PreparedProofAssistant, ProofClaim } from "./assistant.ts";
|
|
2
|
+
export type ConcreteScope = "literal-inputs" | "no-inputs";
|
|
3
|
+
/** Recognize explicit literal constraints. An unclassified domain can still be empty or have one member. */
|
|
4
|
+
export declare function concreteScope(parameters: PreparedProofAssistant["parameters"], claim: ProofClaim): ConcreteScope | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SubjectSource } from "../assistant.ts";
|
|
2
|
+
export interface LeanOptions {
|
|
3
|
+
executable?: string;
|
|
4
|
+
toolchain?: string;
|
|
5
|
+
replay?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function leanCommand(subject: SubjectSource, options: LeanOptions): {
|
|
8
|
+
binary: string;
|
|
9
|
+
env: {
|
|
10
|
+
[key: string]: string | undefined;
|
|
11
|
+
NODE_ENV?: string;
|
|
12
|
+
TZ?: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ProofAssistant } from "../assistant.ts";
|
|
2
|
+
import { type LeanOptions } from "./command.ts";
|
|
3
|
+
export type { LeanOptions } from "./command.ts";
|
|
4
|
+
export declare const lean: import("../suite-authoring.ts").NativeSyntax<"lean">;
|
|
5
|
+
export declare function leanAdapter(options?: LeanOptions): ProofAssistant<"lean">;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Program } from "@babel/types";
|
|
2
|
+
import type { SubjectSource } from "../assistant.ts";
|
|
3
|
+
import { type Subject } from "./subject.ts";
|
|
4
|
+
interface Module {
|
|
5
|
+
file: string;
|
|
6
|
+
source: string;
|
|
7
|
+
program: Program;
|
|
8
|
+
declarations: Program;
|
|
9
|
+
imports: Map<string, {
|
|
10
|
+
owner: Module;
|
|
11
|
+
name: string;
|
|
12
|
+
}>;
|
|
13
|
+
resolvedImports: {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
file: string;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
/** Link source functions only after validating module initialization and binding identities. */
|
|
20
|
+
export declare function lowerProgram(source: SubjectSource): {
|
|
21
|
+
root: Subject;
|
|
22
|
+
modules: Map<string, Module>;
|
|
23
|
+
resolve(file: string, name: string): Subject;
|
|
24
|
+
};
|
|
25
|
+
export declare function definitions(roots: readonly Subject[]): Subject[];
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ProofConstraint } from "../assistant.ts";
|
|
2
|
+
type Scope = ReadonlyMap<string, string>;
|
|
3
|
+
/** An unavailable premise or assertion disables this replay, so every reported witness is in-domain. */
|
|
4
|
+
export declare function replayConstraints(constraints: readonly ProofConstraint[], parameters: Scope): string | undefined;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Counterexample, ProofClaim } from "../assistant.ts";
|
|
2
|
+
import type { lowerProgram } from "./program.ts";
|
|
3
|
+
type Program = ReturnType<typeof lowerProgram>;
|
|
4
|
+
/** Execute the observation against the same frozen files and resolved imports used by the proof. */
|
|
5
|
+
export declare function replayClaim(program: Program, claim: ProofClaim, directory: string): Promise<Counterexample | undefined>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Node } from "@babel/types";
|
|
2
|
+
import { type Sort } from "./syntax.ts";
|
|
3
|
+
export declare const scalarSemantics: string;
|
|
4
|
+
export declare const iterationSemantics: string;
|
|
5
|
+
type Kind = "integer" | "boolean";
|
|
6
|
+
type Scalar = {
|
|
7
|
+
sort: Kind;
|
|
8
|
+
code: string;
|
|
9
|
+
};
|
|
10
|
+
interface ScalarFunction {
|
|
11
|
+
code: string;
|
|
12
|
+
result: Sort;
|
|
13
|
+
sourceExpression?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function scalarValue(sort: Sort, value: string): Scalar | undefined;
|
|
16
|
+
export declare function scalarCall(subject: ScalarFunction, args: readonly (Scalar | undefined)[], fresh: () => string): Scalar | undefined;
|
|
17
|
+
/** Reify the frozen AST independently of the ordinary Lean expression printer. */
|
|
18
|
+
export declare function scalarSource(fn: Node, parameters: readonly {
|
|
19
|
+
name: string;
|
|
20
|
+
sort: Sort;
|
|
21
|
+
code: string;
|
|
22
|
+
}[], result: Sort, callees: ReadonlyMap<string, ScalarFunction>): string | undefined;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ArrowFunctionExpression, type FunctionDeclaration, type Node, type Program } from "@babel/types";
|
|
2
|
+
import { type Sort, type Value } from "./syntax.ts";
|
|
3
|
+
export type Parameter = Value & {
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
export interface Subject {
|
|
7
|
+
file: string;
|
|
8
|
+
name: string;
|
|
9
|
+
code: string;
|
|
10
|
+
params: Parameter[];
|
|
11
|
+
result: Sort;
|
|
12
|
+
itemType?: string;
|
|
13
|
+
definition: string;
|
|
14
|
+
fallible: boolean;
|
|
15
|
+
countdown: boolean;
|
|
16
|
+
fold: boolean;
|
|
17
|
+
loopConformance: readonly {
|
|
18
|
+
name: string;
|
|
19
|
+
definition: string;
|
|
20
|
+
}[];
|
|
21
|
+
recursive: boolean;
|
|
22
|
+
callees: ReadonlySet<Subject>;
|
|
23
|
+
sourceExpression?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function lowerFunction(file: string, program: Program, fn: FunctionDeclaration | ArrowFunctionExpression, symbol: string, code: string, resolveCall: (name: string, at: Node) => Subject): Subject;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CallExpression, Node } from "@babel/types";
|
|
2
|
+
export declare const leanTypes: {
|
|
3
|
+
integer: string;
|
|
4
|
+
number: string;
|
|
5
|
+
boolean: string;
|
|
6
|
+
integers: string;
|
|
7
|
+
items: string;
|
|
8
|
+
textOrItems: string;
|
|
9
|
+
};
|
|
10
|
+
export type Sort = keyof typeof leanTypes;
|
|
11
|
+
export type Value = {
|
|
12
|
+
sort: Sort;
|
|
13
|
+
code: string;
|
|
14
|
+
fallible?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const errorKinds: {
|
|
17
|
+
readonly Error: "error";
|
|
18
|
+
readonly RangeError: "rangeError";
|
|
19
|
+
readonly TypeError: "typeError";
|
|
20
|
+
};
|
|
21
|
+
export declare function isScalar(sort: Sort): sort is "integer" | "number" | "boolean";
|
|
22
|
+
export declare function truthy(value: Value, code: string): string;
|
|
23
|
+
export declare function nameOf(file: string, node: Node | null | undefined): string;
|
|
24
|
+
export declare function tsSort(file: string, annotation: Node | null | undefined, at: Node, registerItem?: (name: string, node: Node) => void): Sort;
|
|
25
|
+
export declare function asOutcome(value: Value): string;
|
|
26
|
+
/** Sequence exactly the potentially throwing operands in JavaScript evaluation order. */
|
|
27
|
+
export declare function sequence(values: readonly Value[], fresh: () => string, finish: (codes: string[]) => Value): Value;
|
|
28
|
+
export declare function invoke(callee: {
|
|
29
|
+
code: string;
|
|
30
|
+
result: Sort;
|
|
31
|
+
fallible: boolean;
|
|
32
|
+
}, args: readonly Value[], fresh: () => string): Value;
|
|
33
|
+
export interface ExecutableExpressions {
|
|
34
|
+
fresh(): string;
|
|
35
|
+
call(node: CallExpression, read: (value: Node) => Value): Value;
|
|
36
|
+
recursive: boolean;
|
|
37
|
+
numberGlobal: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare function bigintLiteral(node: Node): bigint | undefined;
|
|
40
|
+
export declare function readValue(file: string, node: Node, scope: ReadonlyMap<string, Value>, helpers?: ReadonlySet<string>, executable?: ExecutableExpressions, numberGlobal?: boolean | undefined): Value;
|
|
41
|
+
export declare function ofSort<T extends Sort>(file: string, at: Node, value: Value, expected: T): string;
|
|
42
|
+
export declare function readProposition(file: string, node: Node, scope: ReadonlyMap<string, Value>, helpers?: ReadonlySet<string>, numberGlobal?: boolean): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ArrowFunctionExpression, type FunctionDeclaration, type Program } from "@babel/types";
|
|
2
|
+
type SubjectFunction = FunctionDeclaration | ArrowFunctionExpression;
|
|
3
|
+
type FunctionOptions = {
|
|
4
|
+
allowArrowFunctions: true;
|
|
5
|
+
allowLocalFunctions?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function selectSubject(program: Program, file: string, name: string): FunctionDeclaration;
|
|
8
|
+
export declare function selectSubject(program: Program, file: string, name: string, options: FunctionOptions): SubjectFunction;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ExecFileOptions } from "node:child_process";
|
|
2
|
+
/** A normal prover rejection is evidence. Startup, timeout and signal failures are tool errors. */
|
|
3
|
+
export declare function runProver(binary: string, args: string[], options: ExecFileOptions): Promise<{
|
|
4
|
+
status: number;
|
|
5
|
+
stdout: string;
|
|
6
|
+
stderr: string;
|
|
7
|
+
}>;
|
package/types/run.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type CheckOptions, type CheckProgress, type CheckReport, type EmitOptions } from "./check.ts";
|
|
2
|
+
type CheckRequest = {
|
|
3
|
+
kind: "check";
|
|
4
|
+
files: readonly string[];
|
|
5
|
+
progress: boolean;
|
|
6
|
+
};
|
|
7
|
+
type EmitRequest = {
|
|
8
|
+
kind: "emit";
|
|
9
|
+
file: string;
|
|
10
|
+
property?: string;
|
|
11
|
+
};
|
|
12
|
+
export type ProjectRequest = CheckRequest | EmitRequest;
|
|
13
|
+
export type ProjectReply = {
|
|
14
|
+
kind: "progress";
|
|
15
|
+
event: CheckProgress;
|
|
16
|
+
} | {
|
|
17
|
+
kind: "result";
|
|
18
|
+
value: CheckReport[] | string;
|
|
19
|
+
} | {
|
|
20
|
+
kind: "error";
|
|
21
|
+
error: Error;
|
|
22
|
+
unsupported: boolean;
|
|
23
|
+
code?: string;
|
|
24
|
+
};
|
|
25
|
+
/** Check a batch against shared snapshots, loading project config once per run. */
|
|
26
|
+
export declare function checkFiles(files: readonly string[], options?: CheckOptions): Promise<CheckReport[]>;
|
|
27
|
+
export declare function check(file: string, options?: CheckOptions): Promise<CheckReport>;
|
|
28
|
+
/** Emit the same verification unit as pud --emit, without running a prover. */
|
|
29
|
+
export declare function emit(file: string, selector?: string | EmitOptions): Promise<string>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Node, StringLiteral } from "@babel/types";
|
|
2
|
+
export type { BlockStatement, Node, Statement, TryStatement } from "@babel/types";
|
|
3
|
+
export declare function invalid(file: string, node: Node | undefined, message: string): never;
|
|
4
|
+
export declare function parseSourceModule(file: string, source: string): import("@babel/types").Program;
|
|
5
|
+
export declare function resolveTypeScriptImport(file: string, specifier: StringLiteral, base: string): string;
|