lemmascript 0.5.18 → 0.5.20
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 +1 -1
- package/package.json +1 -1
- package/tools/dist/autohavoc.js +2 -0
- package/tools/dist/builtins.js +125 -0
- package/tools/dist/condition-facts.js +364 -0
- package/tools/dist/dafny-emit.js +228 -37
- package/tools/dist/extract.js +175 -37
- package/tools/dist/info-command.js +68 -0
- package/tools/dist/ir.js +27 -7
- package/tools/dist/lean-emit.js +29 -18
- package/tools/dist/lsc.js +53 -5
- package/tools/dist/names.js +10 -6
- package/tools/dist/narrow.js +296 -677
- package/tools/dist/peephole.js +12 -94
- package/tools/dist/rawir.js +15 -1
- package/tools/dist/resolve.js +268 -249
- package/tools/dist/specparser.js +21 -17
- package/tools/dist/transform.js +411 -131
- package/tools/dist/typedecls.js +59 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeDecls — declaration lookup over a module's type declarations
|
|
3
|
+
* (DESIGN_LS_IN_LS.md §5.2).
|
|
4
|
+
*
|
|
5
|
+
* One home for the lookup idioms formerly re-spelled at each use site.
|
|
6
|
+
* Three name semantics exist, and call sites deliberately differ:
|
|
7
|
+
* - exact: `declOf` — the name as written;
|
|
8
|
+
* - dotted: `declOfDotted` — exact, else the last dotted segment
|
|
9
|
+
* (`Agent.Info` matches `//@ declare-type Info`);
|
|
10
|
+
* - sliced: `declOfTy`/`tyBaseName` — generic arguments stripped
|
|
11
|
+
* (`Foo<Bar>` looks up `Foo`).
|
|
12
|
+
* Preserve a site's semantics when changing its lookup; do not "upgrade"
|
|
13
|
+
* an exact site to dotted or sliced in passing.
|
|
14
|
+
*/
|
|
15
|
+
/** `Foo<Bar>` → `Foo`. The single home of the generic-base slice; §5.1
|
|
16
|
+
* (structured generic args) retires it. */
|
|
17
|
+
export function tyBaseName(name) {
|
|
18
|
+
return name.includes("<") ? name.slice(0, name.indexOf("<")) : name;
|
|
19
|
+
}
|
|
20
|
+
/** Declaration by exact name. */
|
|
21
|
+
export function declOf(decls, name) {
|
|
22
|
+
return decls.find(d => d.name === name);
|
|
23
|
+
}
|
|
24
|
+
/** Declaration by exact name, restricted to the given kinds. */
|
|
25
|
+
export function declOfKind(decls, name, ...kinds) {
|
|
26
|
+
const d = declOf(decls, name);
|
|
27
|
+
return d && kinds.includes(d.kind) ? d : undefined;
|
|
28
|
+
}
|
|
29
|
+
/** Declaration by exact name, falling back to the last dotted segment. */
|
|
30
|
+
export function declOfDotted(decls, name) {
|
|
31
|
+
const direct = declOf(decls, name);
|
|
32
|
+
if (direct)
|
|
33
|
+
return direct;
|
|
34
|
+
const dotIdx = name.lastIndexOf(".");
|
|
35
|
+
if (dotIdx >= 0)
|
|
36
|
+
return declOf(decls, name.slice(dotIdx + 1));
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
/** Declaration for a user-typed value: generic-base sliced, exact match.
|
|
40
|
+
* Undefined for non-user types. */
|
|
41
|
+
export function declOfTy(decls, ty) {
|
|
42
|
+
return ty.kind === "user" ? declOf(decls, tyBaseName(ty.name)) : undefined;
|
|
43
|
+
}
|
|
44
|
+
/** The discriminated-union declaration of a user-typed value, if any. */
|
|
45
|
+
export function unionDeclOfTy(decls, ty) {
|
|
46
|
+
const d = declOfTy(decls, ty);
|
|
47
|
+
return d?.kind === "discriminated-union" ? d : undefined;
|
|
48
|
+
}
|
|
49
|
+
/** The discriminant field name of a user-typed value that is a
|
|
50
|
+
* discriminated union. */
|
|
51
|
+
export function discriminantOf(decls, ty) {
|
|
52
|
+
return unionDeclOfTy(decls, ty)?.discriminant;
|
|
53
|
+
}
|
|
54
|
+
/** Reverse lookup: the union declaration owning a variant (discriminated
|
|
55
|
+
* union) or literal value (string union) of this name. */
|
|
56
|
+
export function declWithVariant(decls, ctorOrValue) {
|
|
57
|
+
return decls.find(d => (d.kind === "discriminated-union" || d.kind === "string-union") &&
|
|
58
|
+
((d.variants?.some(v => v.name === ctorOrValue)) || (d.values?.includes(ctorOrValue) ?? false)));
|
|
59
|
+
}
|