lawspec 0.15.0 → 0.15.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/CHANGELOG.md +532 -0
- package/README.md +60 -741
- package/api.mjs +1 -1
- package/bin/lawspec.mjs +4 -2
- package/build.json +25 -27
- package/core.wasm +0 -0
- package/doctor.mjs +1 -0
- package/examples-command.mjs +1 -0
- package/files.mjs +1 -0
- package/index.d.ts +1 -1
- package/launcher.mjs +26 -16
- package/native-examples.mjs +1 -0
- package/package.json +33 -6
- package/read-only-hpack.mjs +1 -0
- package/scalars.mjs +1 -0
- package/templates.mjs +112 -219
- package/API-MIGRATION.md +0 -339
- package/GO.md +0 -144
- package/HASKELL.md +0 -172
- package/JAVA.md +0 -113
- package/KOTLIN.md +0 -219
- package/LANGUAGE.md +0 -692
- package/NATIVE-BINDINGS.md +0 -1051
- package/PRIMITIVES.md +0 -150
- package/PYTHON.md +0 -152
- package/REFINEMENTS.md +0 -449
- package/RELEASE-0.10.md +0 -60
- package/RELEASE-0.11.md +0 -62
- package/RELEASE-0.12.md +0 -47
- package/RELEASE-0.13.md +0 -97
- package/RELEASE-0.14.md +0 -52
- package/RELEASE-0.15.md +0 -44
- package/RELEASE-0.9.md +0 -61
- package/RUST.md +0 -211
- package/WEB.md +0 -144
package/REFINEMENTS.md
DELETED
|
@@ -1,449 +0,0 @@
|
|
|
1
|
-
# Refinements and abstract integers (0.15.0)
|
|
2
|
-
|
|
3
|
-
A refinement restricts a scalar domain with a pure Boolean expression. LawSpec
|
|
4
|
-
checks concrete examples, generates satisfying input tuples, and checks adapter
|
|
5
|
-
contracts during testing. It does not prove that an adapter is correct.
|
|
6
|
-
|
|
7
|
-
## Exact integers without a storage width
|
|
8
|
-
|
|
9
|
-
`Integer` is the mathematical integer domain. Integer literals default to it;
|
|
10
|
-
integer addition, subtraction, multiplication, negation, quotient, and remainder
|
|
11
|
-
produce it. Calculations use arbitrary precision internally. `BigInt` remains
|
|
12
|
-
available when a concrete arbitrary-precision adapter representation is wanted.
|
|
13
|
-
|
|
14
|
-
```lawspec
|
|
15
|
-
unit example.increment
|
|
16
|
-
successor :: (x :: Int8) -> (result :: Integer where result == x + 1)
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
This signature generates contract tests without a separate law. The maximum
|
|
20
|
-
input, `127`, requires the value `128`. Returning a wrapped `-128` fails.
|
|
21
|
-
`Integer` does not assert which storage width the implementation used.
|
|
22
|
-
|
|
23
|
-
Abstract integer results accept Python `int` (excluding `bool`), JavaScript or
|
|
24
|
-
TypeScript `bigint` and safe integral `number` values, Java/Kotlin standard signed
|
|
25
|
-
integral wrappers and `BigInteger` through `Number`, and Go signed/unsigned integer
|
|
26
|
-
values or `big.Int` values/pointers through `any`. Floating representations are
|
|
27
|
-
rejected even when their current value is integral. Haskell uses `IntegerValue`:
|
|
28
|
-
|
|
29
|
-
```haskell
|
|
30
|
-
successor :: Int8 -> IntegerValue
|
|
31
|
-
successor x = integerValue (toInteger x + 1)
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
`integerValue :: Integral a => a -> IntegerValue` erases the width losslessly.
|
|
35
|
-
Abstract integer arguments use the target's arbitrary-precision integer type.
|
|
36
|
-
Concrete signatures keep their existing checked native mappings.
|
|
37
|
-
|
|
38
|
-
## Inline and named refinements
|
|
39
|
-
|
|
40
|
-
Use `where` on a quantified input, function argument, or function result:
|
|
41
|
-
|
|
42
|
-
```lawspec
|
|
43
|
-
`for all` (x :: Int8) (y :: Int8 where y > Int8.max - x) .
|
|
44
|
-
add x y = x + y
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
A predicate can reference its own value and earlier inputs. A function result
|
|
48
|
-
predicate can also reference the function's named arguments. Forward value
|
|
49
|
-
references are errors. `Int8.min` and `Int8.max` denote representation bounds;
|
|
50
|
-
machine-sized bounds use the requested `machineBits` profile.
|
|
51
|
-
|
|
52
|
-
Named refinements distinguish type parameters from value parameters:
|
|
53
|
-
|
|
54
|
-
```lawspec
|
|
55
|
-
refinement Between
|
|
56
|
-
(T :: Type) (minimum :: T) (maximum :: T)
|
|
57
|
-
requires Ordered T is
|
|
58
|
-
(value :: T where minimum <= value && value <= maximum)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
refinement AdditionOverflows
|
|
62
|
-
(T :: Type) (left :: T)
|
|
63
|
-
requires Integer T Bounded T is
|
|
64
|
-
(right :: T where left + right > T.max)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
add :: (x :: Int8)
|
|
68
|
-
-> (y :: AdditionOverflows Int8 x)
|
|
69
|
-
-> (result :: Integer where result == x + y)
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
`(x :: Between Int8 1 10)` applies a refinement. Parenthesize compound arguments,
|
|
73
|
-
for example `Between Int8 (-10) (5 + 5)`. Later value-parameter types can use
|
|
74
|
-
earlier parameters. Value arguments must satisfy their declared domains,
|
|
75
|
-
including refinements. Substitution avoids capturing names from the call site.
|
|
76
|
-
Declarations can appear in any order within a unit; recursive aliases are errors.
|
|
77
|
-
Fixed refinements are the zero-parameter form:
|
|
78
|
-
|
|
79
|
-
```lawspec
|
|
80
|
-
refinement PositiveInt8 is (value :: Int8 where value > 0) end
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
Aliases preserve their underlying native representation. They can be nested in
|
|
84
|
-
`Nullable` and `Optional`; inner predicates are checked only for present values.
|
|
85
|
-
Type parameters range over supported value types, including structural types.
|
|
86
|
-
Their declared capabilities determine which operations are available.
|
|
87
|
-
|
|
88
|
-
`requires Integer T` describes integer capabilities in a generic declaration.
|
|
89
|
-
`Integer` entails `Eq` and `Ordered`. `Ordered` currently covers exact real numbers
|
|
90
|
-
and floats, with the existing IEEE comparisons (including NaN behavior).
|
|
91
|
-
`Bounded` covers fixed and machine-sized integers. Bounds refer to the underlying
|
|
92
|
-
integer representation, rather than a tighter interval inferred from a predicate.
|
|
93
|
-
Capabilities are checked on generic declarations and their specializations.
|
|
94
|
-
|
|
95
|
-
## Predicate expressions and contracts
|
|
96
|
-
|
|
97
|
-
Predicates support existing pure arithmetic, comparisons, scalar constructors,
|
|
98
|
-
conversions, and built-in helpers. `&&`, `||`, and `!` short-circuit; comparisons
|
|
99
|
-
bind more tightly than `&&`, which binds more tightly than `||`. Assertion `and`
|
|
100
|
-
continues to combine law conclusions. Exact/inexact mixing still needs an explicit
|
|
101
|
-
conversion, and floating expressions retain their declared precision.
|
|
102
|
-
|
|
103
|
-
`prelude.length` counts Unicode scalars for Text, code points for CodePointText,
|
|
104
|
-
UTF-16 units for Utf16Text, and octets for Bytes. `prelude.isPresent` and
|
|
105
|
-
`prelude.presentValue` inspect tagged presence values; guard extraction with
|
|
106
|
-
`isPresent` before accessing a possibly absent value.
|
|
107
|
-
|
|
108
|
-
Adapter calls are forbidden in refinements. Predicate errors such as division by
|
|
109
|
-
zero are reported as failures when evaluated; they are not ordinary rejection of
|
|
110
|
-
an input. Short-circuited branches are not evaluated by generation optimizations.
|
|
111
|
-
|
|
112
|
-
In the 0.9 frontend, predicates can call checked total definitions, including
|
|
113
|
-
generic definitions specialized to the predicate's concrete types:
|
|
114
|
-
|
|
115
|
-
```lawspec
|
|
116
|
-
definition nonempty (xs :: List a) :: Bool is
|
|
117
|
-
match xs with
|
|
118
|
-
| Nil -> false
|
|
119
|
-
| Cons head tail -> true
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
refinement Nonempty (T :: Type) is
|
|
124
|
-
(xs :: List T where nonempty xs)
|
|
125
|
-
end
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
The same closed definitions evaluate example inputs, constant refinement
|
|
129
|
-
arguments, finite domains, and boundaries, and run in generated predicate and
|
|
130
|
-
contract checks on all eight targets. Calls to adapters cannot enter that closed
|
|
131
|
-
environment. Definitions can also refine their own parameters and results.
|
|
132
|
-
Their bodies must be proved total under the ordered input preconditions, and
|
|
133
|
-
every result refinement must follow from the body.
|
|
134
|
-
|
|
135
|
-
Every refined adapter signature creates a standalone property. Calls from other
|
|
136
|
-
laws also check argument preconditions, invoke the adapter once, snapshot its
|
|
137
|
-
result, and check postconditions. Calling a function outside its precondition is
|
|
138
|
-
a test failure, not a discarded example. Ordinary `implies` guards retain their
|
|
139
|
-
existing conditional behavior.
|
|
140
|
-
|
|
141
|
-
## Dependent generation and shrinking
|
|
142
|
-
|
|
143
|
-
A quantified law ranges over satisfying tuples. For `AdditionOverflows Int8 x`,
|
|
144
|
-
`x = 0` has no admissible `y`. The generator backtracks to choose another `x`;
|
|
145
|
-
it does not count that dead end as a passing test. Valid pairs satisfy:
|
|
146
|
-
|
|
147
|
-
```text
|
|
148
|
-
1 <= x <= 127
|
|
149
|
-
128 - x <= y <= 127
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
The generator derives integer bounds from affine comparisons and conjunctions,
|
|
153
|
-
seeds direct comparison values and boundaries, and checks the complete predicate.
|
|
154
|
-
Predicates outside that analysis use bounded sampling. Small finite base-domain
|
|
155
|
-
products are enumerated exhaustively, retaining only satisfying tuples.
|
|
156
|
-
|
|
157
|
-
A refinement `m x == e` over declared data, where `m` is a linear structural
|
|
158
|
-
measure (each branch is a constant plus `m` of that branch's fields), is solved
|
|
159
|
-
rather than sampled: values are constructed with measure exactly `e`. Indexed
|
|
160
|
-
families rely on this; see [natural-indexed families](LANGUAGE.md#natural-indexed-families).
|
|
161
|
-
|
|
162
|
-
Shrinking checks refinements again and repairs dependent later inputs when an
|
|
163
|
-
earlier value changes. An overflowing counterexample can shrink to `(1, 127)`;
|
|
164
|
-
it cannot shrink to `(0, 127)` because that pair is outside the domain.
|
|
165
|
-
|
|
166
|
-
Compiler requests and `lawspec.json` accept:
|
|
167
|
-
|
|
168
|
-
```json
|
|
169
|
-
{
|
|
170
|
-
"generation": {
|
|
171
|
-
"cases": 100,
|
|
172
|
-
"maxAttempts": 10000,
|
|
173
|
-
"maxShrinks": 1000,
|
|
174
|
-
"exhaustiveLimit": 4096
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
All limits are positive integers. These are the defaults for refinement properties.
|
|
180
|
-
`cases` counts accepted property inputs; explicit examples and boundary fixtures
|
|
181
|
-
are additional checks. Exhausted searches report an error with reproduction
|
|
182
|
-
information. Exhaustion does not prove that the mathematical domain is empty.
|
|
183
|
-
Statically established empty executable domains and invalid examples are rejected.
|
|
184
|
-
|
|
185
|
-
See [the bundled examples](examples/specs/refinements.lawspec) for overflow,
|
|
186
|
-
abstract integer arguments/results, dependent bounds, optional refinements,
|
|
187
|
-
floating classification, and raw-byte lengths.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
## Refined definitions
|
|
191
|
-
|
|
192
|
-
```lawspec
|
|
193
|
-
definition increment (x :: Int8 where x < 127)
|
|
194
|
-
:: (result :: Int8 where result > x)
|
|
195
|
-
is
|
|
196
|
-
prelude.Int8 (x + 1)
|
|
197
|
-
end
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
Arithmetic promotes before the explicit Int8 conversion. The compiler proves
|
|
201
|
-
that the precondition makes the conversion safe and that the result exceeds x.
|
|
202
|
-
Later parameters may depend on earlier parameters. Result binders must differ
|
|
203
|
-
from argument names.
|
|
204
|
-
|
|
205
|
-
Generic definitions retain their contracts through specialization. Templates,
|
|
206
|
-
including unused ones, must pass type, capability, termination and definedness
|
|
207
|
-
checks before concrete instances are emitted. Each closed call must satisfy its
|
|
208
|
-
callee's preconditions. Contracts cannot depend cyclically on their definitions
|
|
209
|
-
or call adapters. A claim the proof checker cannot establish is rejected.
|
|
210
|
-
|
|
211
|
-
The reference evaluator and all eight native backends validate arguments, check
|
|
212
|
-
preconditions in order, evaluate the body, validate its result, and check
|
|
213
|
-
postconditions. An invalid native call fails before unsafe body arithmetic.
|
|
214
|
-
Definitions are proved during compilation; adapter contracts instead generate
|
|
215
|
-
standalone properties because their implementations are external.
|
|
216
|
-
|
|
217
|
-
See [refined definitions](examples/specs/refined_definitions.lawspec) for generic
|
|
218
|
-
reciprocals, checked narrowing and dependent bounds. Both the native compiler
|
|
219
|
-
and packaged WASM build support these contracts.
|
|
220
|
-
|
|
221
|
-
The native definition-contract harnesses accept `LAWSPEC_CONTRACT_SOURCE=1`.
|
|
222
|
-
This compiles `test/fixtures/definition_contracts.lawspec` through the public
|
|
223
|
-
frontend before emitting native code. All eight targets pass both machine
|
|
224
|
-
profiles and readable/compact modes, including ordered predicate checks, exact
|
|
225
|
-
division through a specialized generic helper, narrowing, direct logical calls,
|
|
226
|
-
and postcondition rejection of deliberately corrupted results. The default mode
|
|
227
|
-
retains the independently constructed Core fixture.
|
|
228
|
-
|
|
229
|
-
## Sum payload refinements
|
|
230
|
-
|
|
231
|
-
`Maybe (value :: Int8 where value > 0)` admits `Nothing` and positive `Just`
|
|
232
|
-
payloads. `Either (value :: Int8 where value > 0) Bool` checks the positive bound
|
|
233
|
-
only for `Left`; `Right` retains its Bool domain. Nested sums compose these
|
|
234
|
-
checks, and payload predicates may refer to earlier quantified inputs.
|
|
235
|
-
|
|
236
|
-
These refinements elaborate to exhaustive Core matches. Unselected branches are
|
|
237
|
-
not evaluated, and generated binder names preserve outer dependencies. Finite
|
|
238
|
-
domains retain distinct absence and variant states. Named data payload and constructor-field refinements are also supported. The bundled [sum refinement examples](examples/specs/sum_refinements.lawspec)
|
|
239
|
-
pass native framework execution on all eight targets under both machine profiles
|
|
240
|
-
and readable/compact layouts. The data integration harnesses include these laws
|
|
241
|
-
with their existing structural and incorrect-adapter checks.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
## List payload refinements
|
|
245
|
-
|
|
246
|
-
`List (value :: Int8 where value > 0)` constrains every element and admits the
|
|
247
|
-
empty list. Lists compose with other Lists, Maybe, and Either. An element
|
|
248
|
-
predicate can refer to an earlier quantified input, for example:
|
|
249
|
-
|
|
250
|
-
```lawspec
|
|
251
|
-
law `elements exceed the earlier bound` is
|
|
252
|
-
definition is `for all` (floor :: Int8)
|
|
253
|
-
(xs :: List (value :: Int8 where value > floor)) .
|
|
254
|
-
prelude.length xs >= 0
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
These domains elaborate to a typed, scoped Core `AllElements` predicate. It
|
|
260
|
-
checks elements in order, stops at the first false result, and returns true for
|
|
261
|
-
an empty list. Its binder is fresh with respect to outer dependencies. There is
|
|
262
|
-
no new user-facing predicate syntax. Explicit examples outside the domain are
|
|
263
|
-
rejected; nested predicates keep their element scope during specialization.
|
|
264
|
-
See [the List refinement examples](examples/specs/list_refinements.lawspec).
|
|
265
|
-
|
|
266
|
-
Generic definition signatures can contain List payload refinements, including
|
|
267
|
-
calls to generic Boolean helpers. Native entry points check these contracts.
|
|
268
|
-
The totality prover retains universal element facts for each List identity.
|
|
269
|
-
A stronger exact numeric bound can satisfy a weaker callee contract, including
|
|
270
|
-
nested Lists. Matching calls to pure Boolean helpers can also be reused after
|
|
271
|
-
specialization. Returned inputs and explicitly constructed Lists can establish
|
|
272
|
-
universal postconditions; the empty list satisfies every element predicate.
|
|
273
|
-
See [the List contract examples](examples/specs/list_contracts.lawspec).
|
|
274
|
-
|
|
275
|
-
Proof binders are fresh and scoped. An element condition never implies that a
|
|
276
|
-
list is nonempty, and facts about one list do not transfer to another list or to
|
|
277
|
-
an unrelated scalar. In a `Cons first rest` branch, `first` inherits the element
|
|
278
|
-
predicate and `rest` retains the universal predicate with its original outer
|
|
279
|
-
dependencies. Both are strict structural subterms for termination checking. A
|
|
280
|
-
`Nil` branch knows only that its matched list is empty. These facts stay inside
|
|
281
|
-
their branch and can establish branch-specific result contracts.
|
|
282
|
-
|
|
283
|
-
For example, a definition over `List (value :: Int8 where value != 0)` can divide
|
|
284
|
-
by each matched head and recursively process the tail. The bundled List contract
|
|
285
|
-
examples include exact reciprocal sums and nested rows. More complex implications,
|
|
286
|
-
including facts requiring a callee's result contract to be unfolded, remain
|
|
287
|
-
conservative and may be rejected.
|
|
288
|
-
|
|
289
|
-
Verified callee results are available to the total-definition proof checker.
|
|
290
|
-
A helper's postcondition can establish a nonzero divisor, justify checked integer
|
|
291
|
-
narrowing, or satisfy the next helper's input contract. For example:
|
|
292
|
-
|
|
293
|
-
```lawspec
|
|
294
|
-
definition nonzero (value :: Int8 where value != 0)
|
|
295
|
-
:: (result :: Int8 where result != 0)
|
|
296
|
-
is value end
|
|
297
|
-
|
|
298
|
-
definition reciprocal (value :: Int8 where value != 0) :: Rational is
|
|
299
|
-
1 / nonzero value
|
|
300
|
-
end
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
The checker first proves the call's preconditions and, for recursive calls,
|
|
304
|
-
strict structural descent. Only then does it use the result guarantee. Recursive
|
|
305
|
-
List construction can therefore prove element postconditions by induction over
|
|
306
|
-
the tail. A returned List does not itself acquire structural-subterm status.
|
|
307
|
-
Guarantees remain scoped to evaluated branches and short-circuit operands;
|
|
308
|
-
a skipped call cannot justify arithmetic elsewhere. Every helper's own result
|
|
309
|
-
contract is checked, including helpers unused by laws.
|
|
310
|
-
|
|
311
|
-
Constructor-sensitive matching also preserves payload refinements in total
|
|
312
|
-
functions. A `Maybe` payload fact is available in the `Just` branch; an `Either`
|
|
313
|
-
fact belongs to its corresponding `Left` or `Right` branch. Constructed results
|
|
314
|
-
are checked against the matching alternative, including nested sums.
|
|
315
|
-
|
|
316
|
-
Whole-value refinements on named products can relate fields explicitly:
|
|
317
|
-
|
|
318
|
-
```lawspec
|
|
319
|
-
type Range is Range lower :: Int8 upper :: Int8 end
|
|
320
|
-
|
|
321
|
-
definition gap
|
|
322
|
-
(range :: Range where match range with | Range lo hi -> hi > lo end)
|
|
323
|
-
:: Rational
|
|
324
|
-
is
|
|
325
|
-
match range with | Range lo hi -> 1 / (hi - lo) end
|
|
326
|
-
end
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
The field relation justifies the nonzero denominator within that branch. It
|
|
330
|
-
cannot establish a fact about a different value or another constructor's payload.
|
|
331
|
-
This example uses a refinement on the function's whole input value; direct
|
|
332
|
-
constructor-field refinements can express the relation at the data declaration.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
## Named data payloads
|
|
336
|
-
|
|
337
|
-
A product or sum can receive refined type arguments. The predicate
|
|
338
|
-
applies wherever that parameter is stored, including recursive named
|
|
339
|
-
types, List elements, and Maybe/Either payloads. Other alternatives remain
|
|
340
|
-
unconstrained when they do not store that parameter.
|
|
341
|
-
|
|
342
|
-
```lawspec
|
|
343
|
-
unit example.positive_pair
|
|
344
|
-
|
|
345
|
-
type Pair (a :: Type) (b :: Type) is
|
|
346
|
-
Pair first :: a second :: b
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
refinement Positive is (value :: Int8 where value > 0) end
|
|
350
|
-
|
|
351
|
-
definition reciprocal (pair :: Pair Positive Bool) :: Rational is
|
|
352
|
-
match pair with
|
|
353
|
-
| Pair first second -> 1 / first
|
|
354
|
-
end
|
|
355
|
-
end
|
|
356
|
-
|
|
357
|
-
law `half` is
|
|
358
|
-
definition is
|
|
359
|
-
`for all` (pair :: Pair Positive Bool) . reciprocal pair > 0
|
|
360
|
-
end
|
|
361
|
-
example `two` is
|
|
362
|
-
pair = Pair 2 false
|
|
363
|
-
expect reciprocal pair = rational(1, 2)
|
|
364
|
-
end
|
|
365
|
-
end
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
The compiler lowers the payload requirement to a scoped traversal in the shared
|
|
369
|
-
Core. Generators, concrete examples, adapter contracts, and checked definition
|
|
370
|
-
entry points use that predicate. The native representation remains
|
|
371
|
-
`Pair Int8 Bool`; the refinement does not introduce a new wrapper type. Definition proofs
|
|
372
|
-
can use the selected field's predicate to establish that division is defined.
|
|
373
|
-
|
|
374
|
-
Free value names in a type argument retain the scope where the argument was
|
|
375
|
-
written. In `Pair Int8 (n :: Int8 where n > first)`, `first` refers to an earlier
|
|
376
|
-
outer input; a constructor field also named `first` does not capture it.
|
|
377
|
-
|
|
378
|
-
Recursive payloads such as `Tree Positive` use the same operation. Traversal
|
|
379
|
-
follows stored parameter positions, including mutual recursion and growing
|
|
380
|
-
arguments such as `Nest (List a)`. A fixed `Int8` field is not constrained merely
|
|
381
|
-
because another parameter is instantiated as `Int8`. Empty and phantom storage
|
|
382
|
-
satisfies its payload predicate without evaluating a callback. See the bundled
|
|
383
|
-
[recursive refinement example](examples/specs/recursive_refinements.lawspec),
|
|
384
|
-
which proves a positive result for a recursive sum and preserves outer thresholds.
|
|
385
|
-
|
|
386
|
-
The front end checks direct constructor field contracts:
|
|
387
|
-
|
|
388
|
-
```lawspec
|
|
389
|
-
type Gap is
|
|
390
|
-
Gap first :: Int8 second :: (n :: Int8 where n > first)
|
|
391
|
-
end
|
|
392
|
-
|
|
393
|
-
definition inverseGap (gap :: Gap) :: Rational is
|
|
394
|
-
match gap with | Gap x y -> 1 / (y - x) end
|
|
395
|
-
end
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
A field predicate may refer to that field and earlier fields. Construction in a
|
|
399
|
-
total definition must prove the predicates; matching makes them available in the
|
|
400
|
-
selected branch. Concrete example inputs and expected values are checked too.
|
|
401
|
-
The reference interpreter enforces predicates on definition inputs and results.
|
|
402
|
-
All eight backends enforce these
|
|
403
|
-
contracts in generated runtime checks and native Hypothesis/fast-check/proptest/
|
|
404
|
-
JetCheck/Kotest/Rapid/Hedgehog strategies. Each generated case
|
|
405
|
-
shares one Symbol fixture context across witnesses, inputs, adapter checks and
|
|
406
|
-
assertions. Witnesses supplement native strategies; sampled alternatives may
|
|
407
|
-
retain large counterexamples even when native branches can shrink further.
|
|
408
|
-
Web and Rust generation bound whole-value retries with `maxAttempts`; an exhausted search
|
|
409
|
-
reports failure rather than claiming that the domain is empty. Input guards use
|
|
410
|
-
fast-check preconditions, preserving its skip and shrink handling. Rust carries
|
|
411
|
-
predicate evaluation errors into property failures rather than treating them as
|
|
412
|
-
rejected candidates. Java preserves native JetCheck filtering/shrinking, caps each
|
|
413
|
-
filter at the smaller of `maxAttempts` and the framework's 100-attempt limit, and
|
|
414
|
-
reports evaluator errors as contextual generation failures. It uses one native
|
|
415
|
-
session per requested constructor-contract case to avoid session-wide draw
|
|
416
|
-
uniqueness exhaustion for fixture identities. Kotlin bounds candidate sampling
|
|
417
|
-
while retaining native shrink trees; case state carries evaluator errors past
|
|
418
|
-
input guards to the property failure. Go uses Rapid's bounded native filtering
|
|
419
|
-
and replay-based shrinking, with per-sample error state that prevents later fields
|
|
420
|
-
from hiding an evaluator failure. Required conjunctive Symbol equalities bind the
|
|
421
|
-
fixture identity directly; disjunctions retain their alternatives. Go's structural
|
|
422
|
-
properties honor `cases` with scoped Rapid settings, restoring the previous flag
|
|
423
|
-
after each sequential generated test. Rapid's explicit short-test mode may reduce
|
|
424
|
-
that count. Each filter uses at most the smaller of `maxAttempts` and Rapid's
|
|
425
|
-
five-attempt native limit; enclosing native generators and the engine retain
|
|
426
|
-
their own retry limits. For structural Go properties, minimization uses Rapid's
|
|
427
|
-
`-rapid.shrinktime` setting, not the scalar refinement engine's `maxShrinks`
|
|
428
|
-
step budget. Haskell constructor properties use native Hedgehog strategies with
|
|
429
|
-
one Symbol context per case. Each dependent draw is forced before the next draw;
|
|
430
|
-
evaluator failures cannot disappear behind a later discard. Native `filterT`
|
|
431
|
-
prunes rejected shrink branches instead of searching all their descendants.
|
|
432
|
-
Hedgehog receives `cases` as its test limit, `maxAttempts` as its property discard
|
|
433
|
-
limit, and `maxShrinks` as its shrink limit. Internal generator filters retain
|
|
434
|
-
Hedgehog's own retry policy; `maxAttempts` is not a total count of candidate draws.
|
|
435
|
-
Recursively refined named payloads use scoped payload predicates that follow
|
|
436
|
-
declared type-parameter positions through constructor fields.
|
|
437
|
-
|
|
438
|
-
Common domain planning filters finite constructor domains through their field
|
|
439
|
-
predicates. For larger domains, it searches combinations of field boundaries and
|
|
440
|
-
literal values from contracts. This covers dependent fields such as `Gap` and
|
|
441
|
-
sparse Symbol fixture identities. Recursive expansion and candidate combinations
|
|
442
|
-
have finite search budgets; every returned witness satisfies the contracts.
|
|
443
|
-
Exhausting that search reports that no witness was found, rather than declaring
|
|
444
|
-
the domain empty. Bounded samples are never reported as an exhaustive domain.
|
|
445
|
-
|
|
446
|
-
Expression annotations select a representation, such as `(127 :: Int8)`; they
|
|
447
|
-
do not establish a refinement contract. Inline refinement predicates in expression
|
|
448
|
-
annotations are rejected. Put the refinement on a quantified input or function
|
|
449
|
-
signature so that generation, checking, and definition proofs enforce it.
|
package/RELEASE-0.10.md
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# LawSpec 0.10.0
|
|
2
|
-
|
|
3
|
-
## Existing application models
|
|
4
|
-
|
|
5
|
-
Native bindings connect LawSpec products and sums to existing application types
|
|
6
|
-
on Java, Python, JavaScript, TypeScript, Go, Haskell, Kotlin and Rust. Configure
|
|
7
|
-
constructor and field mappings, bind adapter declarations to existing functions,
|
|
8
|
-
or supply paired conversion hooks for representations requiring custom code.
|
|
9
|
-
Bindings resolve against typed declaration identities; they do not change the
|
|
10
|
-
meaning of arithmetic, equality, definitions or refinements.
|
|
11
|
-
|
|
12
|
-
Checked bridges compose through generic and recursive types and the built-in
|
|
13
|
-
containers. They preserve exact numeric values, Symbol identity and distinct
|
|
14
|
-
absence states. Invalid native inputs, results, generator samples and shrink
|
|
15
|
-
candidates fail with context.
|
|
16
|
-
|
|
17
|
-
## Native generators
|
|
18
|
-
|
|
19
|
-
Factories return their framework's generator: JetCheck, Hypothesis, fast-check,
|
|
20
|
-
Rapid, Hedgehog, Kotest or Proptest. Generic factories receive child generators.
|
|
21
|
-
Composition retains native shrinking. Explicit examples, deterministic boundaries
|
|
22
|
-
and finite-domain enumeration still run when the factory's distribution excludes
|
|
23
|
-
those values.
|
|
24
|
-
|
|
25
|
-
A factory can ignore an uninhabited parameter, as in `Phantom Empty`. Requesting a
|
|
26
|
-
value from that parameter fails generation; it cannot turn a property into a
|
|
27
|
-
vacuous success. Finite inhabited containers such as `List Empty` still enumerate.
|
|
28
|
-
|
|
29
|
-
Optional `stub: true` generator bindings create user-owned implementation files.
|
|
30
|
-
Regeneration preserves edits and reports changed factory signatures for review.
|
|
31
|
-
|
|
32
|
-
## API and migration
|
|
33
|
-
|
|
34
|
-
Native binding requests negotiate schema 4. Schema 3 remains supported for
|
|
35
|
-
specifications without bindings. Structured native references and strict
|
|
36
|
-
configuration validation prevent older compilers from silently ignoring mappings.
|
|
37
|
-
Go additionally supports explicit import aliases; Rust binds tests to the
|
|
38
|
-
application library's type identities.
|
|
39
|
-
|
|
40
|
-
Existing adapter files cannot be overwritten by adopting a binding. Move their
|
|
41
|
-
implementations into the application module and save the old adapters before
|
|
42
|
-
generation. Generated source bridges, test helpers and user-owned application
|
|
43
|
-
files retain separate placement and ownership. See the
|
|
44
|
-
[migration guide](API-MIGRATION.md#schema-4-native-bindings) and
|
|
45
|
-
[ownership instructions](NATIVE-BINDINGS.md#ownership-regeneration-and-migration).
|
|
46
|
-
|
|
47
|
-
## Runnable payment projects
|
|
48
|
-
|
|
49
|
-
`lawspec examples --example payments` exports a project for every target; use
|
|
50
|
-
`--target rust` or another language to select one. Each project includes an
|
|
51
|
-
application model, native generator, configuration, build files and instructions.
|
|
52
|
-
The shared specification checks exact fees, currency preservation, sum payloads,
|
|
53
|
-
ordered archives, duplicates and absence. Re-exporting preserves application
|
|
54
|
-
edits and the separate compiler generation manifest.
|
|
55
|
-
|
|
56
|
-
Both 32-bit and 64-bit logical machine profiles and readable/compact output are
|
|
57
|
-
covered by the acceptance matrices. Java 25+, Python 3.13+ and the other published
|
|
58
|
-
toolchain baselines remain unchanged. Python output follows PEP 8.
|
|
59
|
-
|
|
60
|
-
GADTs, dependent indices and cross-unit packages remain subsequent work.
|
package/RELEASE-0.11.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# LawSpec 0.11.0
|
|
2
|
-
|
|
3
|
-
## Natural-indexed families
|
|
4
|
-
|
|
5
|
-
Data declarations may take `Natural` parameters, and each constructor states
|
|
6
|
-
its index equation:
|
|
7
|
-
|
|
8
|
-
```lawspec
|
|
9
|
-
type Vec (n :: Natural) (a :: Type) is
|
|
10
|
-
| VNil where n = 0
|
|
11
|
-
| VCons head :: a tail :: Vec m a where n = m + 1
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
append :: (xs :: Vec n Int8) -> (ys :: Vec m Int8) -> (r :: Vec (n + m) Int8)
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
A family elaborates before inference into ordinary erased data, a checked
|
|
18
|
-
structural measure per index (`nOfVec`), and a refinement relating the measure
|
|
19
|
-
to the index. Core and all eight emitters are unchanged. Native code works with
|
|
20
|
-
the erased type, and every index claim is evidence checked at test time: a
|
|
21
|
-
dependent result such as `Vec (n + m) Int8` is an adapter postcondition.
|
|
22
|
-
|
|
23
|
-
An index variable that is otherwise unbound is implicit. The first binder whose
|
|
24
|
-
family type mentions it determines it, and later occurrences read that binder's
|
|
25
|
-
measure. Index expressions are sums of natural literals and index variables.
|
|
26
|
-
`Natural` is also available as a value type. Diagnostics use the `indexed` code.
|
|
27
|
-
|
|
28
|
-
## Index-directed generation
|
|
29
|
-
|
|
30
|
-
A quantifier constrained by a linear structural measure, including a fixed index
|
|
31
|
-
(`Vec 3 Int8`) or a shared one (`zip`'s second argument), is generated by solving
|
|
32
|
-
the constructor equations backwards instead of filtering. Multi-field equations
|
|
33
|
-
such as `Bin … where n = l + r + 1` split the remaining index across fields.
|
|
34
|
-
Python, JavaScript, TypeScript, Java, Kotlin, Go, Haskell and Rust construct these
|
|
35
|
-
values natively, and framework shrinking stays within the index. The same
|
|
36
|
-
planning applies to user-written linear measures over declared data.
|
|
37
|
-
|
|
38
|
-
`examples/specs/indexed_families.lawspec` runs on all eight targets through
|
|
39
|
-
`tools/indexed-integration.mjs`. Correct adapters pass free, fixed and shared
|
|
40
|
-
index laws; mutants that add, drop or lose elements fail their dependent
|
|
41
|
-
contracts.
|
|
42
|
-
|
|
43
|
-
## Tower-polymorphic Integer results restored
|
|
44
|
-
|
|
45
|
-
0.9 had narrowed Kotlin and Haskell adapters whose result is the abstract
|
|
46
|
-
`Integer` to `BigInteger` and `Integer`. They again return `Number` (Kotlin) and
|
|
47
|
-
`LS.IntegerValue` (Haskell), as in 0.8 and as Java always did. `Integer` is the top
|
|
48
|
-
of the integral tower: an implementation may return any integral native value,
|
|
49
|
-
and the result bridge rejects non-integral values and checks the logical domain.
|
|
50
|
-
Adapters written against 0.9 or 0.10 stubs that return `BigInteger` or `Integer`
|
|
51
|
-
still compile, because both are integral.
|
|
52
|
-
|
|
53
|
-
This regression had kept the Kotlin and Haskell CI target jobs failing since
|
|
54
|
-
0.9. Those jobs, and the scalar mutation fixtures, now pass with the documented
|
|
55
|
-
typed Symbol, Decimal, Utf16Text and Optional representations.
|
|
56
|
-
|
|
57
|
-
## Compatibility
|
|
58
|
-
|
|
59
|
-
Specifications without indexed families generate the same code as 0.10, apart
|
|
60
|
-
from the Integer result signatures above. API schemas 3 and 4 are unchanged.
|
|
61
|
-
GADTs that refine type arguments, non-linear indices and index equalities between
|
|
62
|
-
sibling fields remain future work.
|
package/RELEASE-0.12.md
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# LawSpec 0.12.0
|
|
2
|
-
|
|
3
|
-
## Proved indices
|
|
4
|
-
|
|
5
|
-
Checked definitions may return natural-indexed families, and the compiler
|
|
6
|
-
proves their result indices statically:
|
|
7
|
-
|
|
8
|
-
```lawspec
|
|
9
|
-
definition concatV (xs :: Vec n Int8) (ys :: Vec m Int8) :: Vec (n + m) Int8 is
|
|
10
|
-
match xs with
|
|
11
|
-
| VNil -> ys
|
|
12
|
-
| VCons h t -> VCons h (concatV t ys)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
The totality prover now treats calls of checked definitions as pure linear
|
|
18
|
-
atoms, so equal calls have equal results. A single-argument definition that
|
|
19
|
-
matches on its argument unfolds on a known constructor, so `nOfVec (VCons h t)`
|
|
20
|
-
is `nOfVec t + 1`. Natural measures are non-negative. Together with the existing
|
|
21
|
-
match facts and the induction hypothesis from recursive calls, this proves
|
|
22
|
-
definitions such as `concatV`, and tree flattening through nested calls. It
|
|
23
|
-
rejects definitions whose result indices do not follow, including an unchanged
|
|
24
|
-
length, a dropped element, an extra element and a wrong recursive argument.
|
|
25
|
-
|
|
26
|
-
## Evidence
|
|
27
|
-
|
|
28
|
-
Every contract obligation is recorded as `proved` or `runtime-checked`.
|
|
29
|
-
Definition postconditions are proved, and generated code on all eight targets no
|
|
30
|
-
longer re-checks them at runtime. Definition preconditions, which guard native
|
|
31
|
-
callers, and adapter contracts remain runtime-checked. `lawspec check` prints a
|
|
32
|
-
summary, and API responses include an additive `evidence` array; see
|
|
33
|
-
[API migration](API-MIGRATION.md#evidence-in-check-results-012).
|
|
34
|
-
|
|
35
|
-
The indexed example now includes proved definitions `concatV` and `flattenV`,
|
|
36
|
-
used as reference models for the native `append` and `flatten` adapters. The
|
|
37
|
-
eight-target acceptance runner executes them in both machine profiles and still
|
|
38
|
-
rejects every index-breaking adapter mutant.
|
|
39
|
-
|
|
40
|
-
## Compatibility
|
|
41
|
-
|
|
42
|
-
Specifications that compiled with 0.11 compile unchanged. Generated definition
|
|
43
|
-
code omits postcondition checks that are now proved, which changes generated
|
|
44
|
-
output but not behavior. API schemas 3 and 4 are unchanged apart from the
|
|
45
|
-
additive `evidence` field. Index equalities between sibling fields, non-linear
|
|
46
|
-
indices and type-refining GADTs remain open; see the
|
|
47
|
-
[roadmap](LANGUAGE.md#roadmap).
|