lawspec 0.13.2 → 0.15.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/API-MIGRATION.md CHANGED
@@ -294,3 +294,46 @@ changes. Generated definition code no longer re-checks proved postconditions.
294
294
  including a `wrapper` constraint, checked whenever a value is constructed or
295
295
  decoded. Its `declaration` is the constructor identity and its `status` is
296
296
  `runtime-checked`. The TypeScript API names these records `ObligationEvidence`.
297
+
298
+ ## Imports and packages (0.14)
299
+
300
+ Requests on schema 3 or 4 may add three optional fields:
301
+
302
+ - `dependencies`: `Record<string, string>`, package names and version ranges the
303
+ request's own sources require;
304
+ - `packages`: `Package[]`, each `{name, version, dependencies?, sources}`, the
305
+ complete set of packages those sources require directly or indirectly;
306
+ - `package`: `{name, version}` when the request's own sources are themselves a
307
+ package, whose units must then be named after it.
308
+
309
+ Package sources are compiled with the request's sources. When any of these fields
310
+ is present, results add `packages: PackageView[]`, each with `name`, `version`,
311
+ `dependencies` and the package's `units`, and `project: {package?,
312
+ dependencies}`. Package errors use the diagnostic code `package`; import errors
313
+ use `import`. Requests without these fields produce the same results as before.
314
+ A compiler older than 0.14 ignores the fields and reports the imports it cannot
315
+ resolve.
316
+
317
+ Imported declarations need no new wire forms. Data declarations keep the ID of
318
+ the unit that declares them. An imported checked definition appears among the
319
+ importing unit's definitions with a name derived from its unit
320
+ (`shop.orders::shopDomainCentsOf`).
321
+
322
+ ## Evidence and discharge (0.15)
323
+
324
+ `evidence` items now cover every obligation, and `status` is one of `proved`,
325
+ `exhaustively-checked`, `property-tested`, `runtime-checked` or `assumed`
326
+ (`DischargeStatus`). New stages:
327
+
328
+ - `law`: `declaration` is the law's identity (`unit::law::name`) and `claim` the
329
+ law as a Boolean expression over its inputs;
330
+ - `adapter`: an adapter declaration, `assumed`, with `claim: null`;
331
+ - with native bindings: `binding` (`runtime-checked`), `codec`, `generator` and
332
+ `native-function` (`assumed`), each with `claim: null`.
333
+
334
+ Clients that compared `status` against `proved` and `runtime-checked` only must
335
+ handle the new values. Law obligations come first, then contracts,
336
+ adapters, constructions and bindings.
337
+
338
+ A false law over checked definitions with a finite domain is now reported as a
339
+ diagnostic with code `refuted` instead of compiling.
package/LANGUAGE.md CHANGED
@@ -1,4 +1,4 @@
1
- # LawSpec language and compiler boundary (0.13)
1
+ # LawSpec language and compiler boundary (0.15)
2
2
 
3
3
  LawSpec describes portable laws, concrete examples, and adapter contracts. The
4
4
  compiler is written in Haskell. Rust is an output backend alongside Java, Python,
@@ -204,15 +204,57 @@ recursive call contributes its own signature as the induction hypothesis, and
204
204
  natural measures are non-negative. A definition whose result index does not
205
205
  follow fails with `definition result refinement could not be proved`.
206
206
 
207
- Every contract obligation is recorded with how it is discharged. Definition
208
- postconditions are `proved`, and generated code omits their runtime checks.
209
- Definition preconditions guard native callers, and adapter contracts cover
210
- native code that LawSpec cannot inspect, so both are `runtime-checked`.
211
- `lawspec check` summarizes the evidence, and the API reports each obligation in
212
- the `evidence` field. A proved definition is a natural reference model for a
207
+ Definition postconditions are `proved`, and generated code omits their runtime
208
+ checks; see [evidence and discharge](#evidence-and-discharge) for every other
209
+ obligation. A proved definition is a natural reference model for a
213
210
  native adapter, as in `append xs ys = concatV xs ys` in the
214
211
  [indexed example](examples/specs/indexed_families.lawspec).
215
212
 
213
+ ## Evidence and discharge
214
+
215
+ Every obligation of a program reports how it is discharged, strongest first:
216
+
217
+ | Status | Obligations | How |
218
+ | --- | --- | --- |
219
+ | `PROVED` | laws over checked definitions; definition postconditions and indices | statically, by the prover |
220
+ | `EXHAUSTIVELY CHECKED` | laws whose inputs form a finite domain | every input, by the compiler or the generated tests |
221
+ | `PROPERTY TESTED` | other laws | generated cases, boundary cases and examples |
222
+ | `RUNTIME CHECKED` | adapter contracts, definition preconditions, constructor constraints, native type bindings | at every native boundary |
223
+ | `ASSUMED / EXTERNAL` | adapters, native functions, custom generators and codec hooks | taken on trust |
224
+
225
+ A law that calls only checked definitions is attempted as a proof: its claim
226
+ must follow from its input refinements by the same exact linear arithmetic that
227
+ proves definition results. Definitions without preconditions are unfolded
228
+ into the claim; a definition with preconditions stays a call, and its arguments
229
+ must be shown to satisfy them. For example, with
230
+ `definition twice (x :: Int32) :: BigInt is x + x end`, the law
231
+ `` `for all` (x :: Int32) . twice x = x * 2 `` is proved.
232
+
233
+ A law over checked definitions that is not proved but has a finite domain (at
234
+ most `exhaustiveLimit` inputs) is evaluated by the compiler for every input. A
235
+ counterexample is a compile error with code `refuted`:
236
+
237
+ ```text
238
+ law always positive is false for x = -128
239
+ ```
240
+
241
+ A law that calls an adapter is checked by the generated tests: for every input
242
+ of a finite domain, or else by property testing, with the adapters it relies on
243
+ listed. A law with no inputs has a single case and is exhaustively checked.
244
+ Proved and compiler-checked laws are still emitted as tests, which check the
245
+ generated native definitions.
246
+
247
+ An adapter is native code that LawSpec cannot inspect: its only evidence is the
248
+ laws that call it, and one that no law calls is reported as such. Native type
249
+ bindings decode values through checked codecs, so they are runtime-checked,
250
+ while native functions, custom generators and codec hooks are taken on trust
251
+ (their values are still validated).
252
+
253
+ `lawspec check` summarizes the evidence by status. `lawspec evidence` lists each
254
+ obligation with its claim and reason, grouped by status, and accepts a unit or a
255
+ `unit::declaration` filter; with `--json` it prints the API records. The API
256
+ reports the obligations in the `evidence` field.
257
+
216
258
  ## Domain modeling
217
259
 
218
260
  ### Wrappers and constrained primitives
@@ -261,6 +303,107 @@ Because each state is its own type, a `ValidatedOrder` can only hold checked
261
303
  values, and a step that needs one cannot be given raw input. See the
262
304
  [domain modeling example](examples/specs/domain_modeling.lawspec).
263
305
 
306
+ ## Imports and packages
307
+
308
+ ### Importing units
309
+
310
+ A unit may import other units after its `unit` line:
311
+
312
+ ```lawspec
313
+ unit shop.orders
314
+ import shop.domain as domain (Money, Cents, `commutative`)
315
+
316
+ type Currency is | Usd | Gbp end
317
+ settlement :: Currency -> domain.Currency
318
+
319
+ law `dollars settle in dollars` is
320
+ definition is
321
+ settlement Usd = domain.Usd
322
+ end
323
+ end
324
+ ```
325
+
326
+ `import U` makes every declaration of `U` available qualified by an alias, which
327
+ defaults to the unit's last name segment (`import shop.domain` gives `domain`);
328
+ `as` names another alias. A parenthesized list also makes the listed names
329
+ available unqualified. Listing a data type or wrapper brings its constructors and
330
+ its generated functions (`valueOf<Name>`, indexed-family measures) with it; list
331
+ a law by its quoted name. Qualified names are written without spaces around the
332
+ dot (`domain.Usd`); write `f . g` with spaces to compose a function whose name is
333
+ also an alias.
334
+
335
+ What can be imported:
336
+
337
+ - data types, wrappers and indexed families, with their constructors;
338
+ - refinements;
339
+ - checked definitions;
340
+ - generic laws, that is laws with parameters, which the importer applies to its
341
+ own adapters (`` `commutative` total ``).
342
+
343
+ Adapter signatures and laws without parameters belong to their unit: they are the
344
+ unit's own contract with its native code and are tested there. Referring to
345
+ another unit's adapter is an error, as is importing a declaration that uses one.
346
+
347
+ Names are scoped to their unit. Two units may both declare `Currency`, `Usd` or a
348
+ definition `size`; `domain.Usd` and the local `Usd` are different constructors.
349
+ Targets with a single data namespace qualify the colliding native names by unit
350
+ (`ShopDomainCurrency`, `ShopOrdersCurrency`). An unqualified name that is both
351
+ listed in an import and declared locally is an error, as is one listed from two
352
+ units. Imports are not re-exported: a unit uses what it imports itself.
353
+
354
+ Imports are resolved before type checking. A data type stays with the unit that
355
+ declares it, so values of `domain.Money` are the same values in every importing
356
+ unit. Imported refinements, checked definitions and generic laws are copied into
357
+ the importing unit, together with everything they use, under names derived from
358
+ their unit (`domain.centsOf` is emitted as `shopDomainCentsOf`). Core and all
359
+ eight targets therefore need nothing new. Import cycles, unknown units and
360
+ missing names are reported at the import.
361
+
362
+ ### Packages
363
+
364
+ A package is a named, versioned directory of units, described by
365
+ `lawspec-package.json`:
366
+
367
+ ```json
368
+ {
369
+ "name": "shop.domain",
370
+ "version": "1.2.0",
371
+ "sources": ["src"],
372
+ "dependencies": {}
373
+ }
374
+ ```
375
+
376
+ Every unit of a package is named after it: `shop.domain` or `shop.domain.<name>`.
377
+ A project, or another package, declares the packages it depends on with version
378
+ ranges, and lists the package directories to load:
379
+
380
+ ```json
381
+ {
382
+ "version": 1,
383
+ "sources": ["orders.lawspec"],
384
+ "dependencies": {"shop.domain": "^1.0.0"},
385
+ "packages": ["../shop-domain"],
386
+ "targets": [{"language": "java", "root": "java"}]
387
+ }
388
+ ```
389
+
390
+ A unit may import the units of its own package (or project) and of the packages
391
+ it depends on directly. Versions are `MAJOR.MINOR.PATCH` with an optional
392
+ prerelease. Ranges combine `1.2.3` (exactly), `^1.2.3`, `~1.2.3`, `>=`, `>`,
393
+ `<=`, `<` and `*`, with npm's meaning. Resolution is exact: one version of each
394
+ package is supplied, every range must accept it, a package that nothing requires
395
+ is rejected, and package dependency cycles are rejected. Project units may not
396
+ use a dependency's namespace.
397
+
398
+ A package publishes a behavioral contract. Its types, refinements, definitions
399
+ and generic laws are a library, and its adapter signatures and concrete laws are
400
+ obligations: a project that depends on the package implements those adapters in
401
+ its own native code and is tested against the package's laws, with the same
402
+ user-owned adapter files as for its own units. `lawspec package` checks a
403
+ package on its own and summarizes its units, laws and data types. A package
404
+ directory can be distributed any way that delivers the directory, for example
405
+ as an npm package. See the [package example](examples/packages).
406
+
264
407
  ## Total definitions
265
408
 
266
409
  A unit can supply an implementation as a checked total definition:
@@ -333,8 +476,8 @@ entry points enforce the same contracts. See [refined definitions](REFINEMENTS.m
333
476
 
334
477
  ## Source and declarations
335
478
 
336
- A source has one named `unit`, function signatures, data declarations, checked
337
- definitions, reusable refinements, and laws. Qualified unit names determine target module/package paths. Function
479
+ A source has one named `unit`, its imports, function signatures, data
480
+ declarations, checked definitions, reusable refinements, and laws. Qualified unit names determine target module/package paths. Function
338
481
  signatures are curried: `a -> b -> c` takes two inputs and returns `c`. Parentheses
339
482
  group types and expressions. Comments start with `--` and run to the line end.
340
483
 
@@ -342,7 +485,9 @@ The following grammar summarizes the main forms; the parser and executable
342
485
  compiler tests specify lexical details:
343
486
 
344
487
  ```text
345
- source = "unit" qualified-name declaration*
488
+ source = "unit" qualified-name import* declaration*
489
+ import = "import" qualified-name ["as" name]
490
+ ["(" (name | quoted-name) ("," (name | quoted-name))* ")"]
346
491
  declaration = name "::" type | law | refinement | data-type | function
347
492
  data-type = "type" name ("(" name "::" "Type" ")")*
348
493
  "is" constructor* "end"
@@ -500,14 +645,20 @@ GADTs that refine type arguments.
500
645
  checked step types and a generated railway composition law.
501
646
  - See [domain modeling](#domain-modeling).
502
647
 
503
- ### 0.14 Cross-unit imports and packages
648
+ ### 0.14 Cross-unit imports and packages (released)
649
+
650
+ - Reusable law, type and refinement libraries: `import` brings another unit's
651
+ types, refinements, checked definitions and generic laws into scope.
652
+ - Versioning and namespacing: packages have names, semantic versions and
653
+ dependency ranges, units live in their package's namespace, and constructor
654
+ names are scoped to their unit.
655
+ - Publishable behavioral contracts: a package's adapter signatures and laws are
656
+ implemented and tested by every project that depends on it.
657
+ - See [imports and packages](#imports-and-packages).
504
658
 
505
- - Reusable law, type and refinement libraries.
506
- - Versioning and namespacing, including constructor names scoped to their unit.
507
- Today every unit compiled together needs distinct constructor names.
508
- - Publishable behavioral contracts.
659
+ Still open: re-exports, and several versions of one package in one build.
509
660
 
510
- ### 0.15 Evidence/discharge model
661
+ ### 0.15 Evidence/discharge model (released)
511
662
 
512
663
  Each obligation reports how it was discharged:
513
664
 
@@ -517,6 +668,10 @@ Each obligation reports how it was discharged:
517
668
  - `RUNTIME CHECKED`: adapter contracts and checked codecs at native boundaries.
518
669
  - `ASSUMED / EXTERNAL`: native adapters and bindings taken on trust.
519
670
 
671
+ Laws over checked definitions are proved or exhaustively evaluated by the
672
+ compiler, and false ones on finite domains are rejected. See
673
+ [evidence and discharge](#evidence-and-discharge).
674
+
520
675
  ## Generated project formatting
521
676
 
522
677
  `lawspec init --target java` creates a readable Maven scaffold; Kotlin init
package/PRIMITIVES.md CHANGED
@@ -1,4 +1,4 @@
1
- # LawSpec scalar reference (0.13.2)
1
+ # LawSpec scalar reference (0.15.0)
2
2
 
3
3
  A scalar has a declared domain, checked literals, equality, property inputs, and
4
4
  boundary fixtures. General collections, objects, pointers, and type-only constructs
package/README.md CHANGED
@@ -79,8 +79,29 @@ railway composition of its steps. See
79
79
  [example](examples/specs/domain_modeling.lawspec) and the
80
80
  [release notes](RELEASE-0.13.md).
81
81
 
82
- Planned: 0.14 cross-unit packages and 0.15 evidence reporting. See the
83
- [roadmap](LANGUAGE.md#roadmap).
82
+ ## Imports and packages in 0.14
83
+
84
+ LawSpec 0.14 lets units import each other and groups units into versioned
85
+ packages. ``import shop.domain as domain (Money, `commutative`)`` brings in
86
+ another unit's types, refinements, checked definitions and generic laws, qualified
87
+ or by name. Names are scoped to their unit, so two units may both declare a
88
+ `Currency`. A package is a directory with a `lawspec-package.json`; a project
89
+ names the packages it depends on with semantic-version ranges, and implements
90
+ and tests the adapters of the contracts they publish. See
91
+ [imports and packages](LANGUAGE.md#imports-and-packages), the
92
+ [package example](examples/packages) and the [release notes](RELEASE-0.14.md).
93
+
94
+ ## Evidence and discharge in 0.15
95
+
96
+ Every obligation now reports how it is discharged: `PROVED`, `EXHAUSTIVELY
97
+ CHECKED`, `PROPERTY TESTED`, `RUNTIME CHECKED` or `ASSUMED / EXTERNAL`. Laws over
98
+ checked definitions are proved by the compiler's linear-arithmetic prover or,
99
+ on finite domains, evaluated for every input, and a false one is a compile
100
+ error. Laws over adapters are exhaustively or property tested by the generated
101
+ tests, and adapters, native functions and custom generators are listed as taken
102
+ on trust. `lawspec evidence` shows each obligation and why. See
103
+ [evidence and discharge](LANGUAGE.md#evidence-and-discharge) and the
104
+ [release notes](RELEASE-0.15.md).
84
105
 
85
106
  ## Install and try it
86
107
 
@@ -91,7 +112,7 @@ support to use it; GitHub currently uses the Haskell fallback.
91
112
  Install [LawSpec from npm](https://www.npmjs.com/package/lawspec):
92
113
 
93
114
  ```sh
94
- npm install --save-dev lawspec@0.13.2
115
+ npm install --save-dev lawspec@0.15.0
95
116
  npx lawspec --version
96
117
  ```
97
118
 
@@ -105,8 +126,8 @@ local dependencies so LawSpec can create its `package.json` and test script:
105
126
  ```sh
106
127
  mkdir lawspec-example
107
128
  cd lawspec-example
108
- npm exec --package=lawspec@0.13.2 -- lawspec init --target javascript
109
- npm install --save-dev lawspec@0.13.2
129
+ npm exec --package=lawspec@0.15.0 -- lawspec init --target javascript
130
+ npm install --save-dev lawspec@0.15.0
110
131
  npx lawspec check
111
132
  npx lawspec explain 'example.atoi_codec::itoa and then atoi yields a'
112
133
  npx lawspec doctor
@@ -173,6 +194,9 @@ preserved, and setup instructions describe the changes you need to make yourself
173
194
  ```
174
195
 
175
196
  Source entries are files or directories, relative to the configuration file.
197
+ `dependencies` maps package names to version ranges, and `packages` lists the
198
+ package directories to load (each with a `lawspec-package.json`); see
199
+ [packages](LANGUAGE.md#packages).
176
200
  Directories are scanned for `.lawspec` files. Every target has its own project
177
201
  root. Use `init --target python --project python` to add a target; `--config`
178
202
  selects a different configuration file. Targets can override `sourceDir` and
@@ -193,12 +217,17 @@ uses `test/Spec.hs` with `hspec-discover`.
193
217
 
194
218
  Commands:
195
219
 
196
- - `check`: parse, resolve, type-check and expand laws without target dependencies.
220
+ - `check`: parse, resolve, type-check and expand laws without target dependencies,
221
+ and summarize how the obligations are discharged.
222
+ - `evidence [unit | unit::declaration]`: list each obligation, its claim and how
223
+ it is discharged, grouped by status.
197
224
  - `explain [unit::law]`: display expansions, example inputs, and expected results.
198
225
  - `doctor`: inspect selected native environments and print corrective instructions.
199
226
  - `generate`: check environments, validate every output, then write artifacts.
200
227
  - `generate --dry-run`: show proposed file operations without applying them.
201
228
  - `generate --check`: fail when generated files need updating, without writing.
229
+ - `package [--project <directory>]`: check a package directory on its own and
230
+ summarize its units, laws and data types.
202
231
 
203
232
  Use `--target <language>` to select a configured language, and `--json` for
204
233
  machine-readable check, explanation, doctor and generation output. Generation
@@ -316,7 +345,7 @@ reusable laws accept these curried functions, their partial applications, and
316
345
  scalar parameters. Quantified test inputs remain scalar.
317
346
 
318
347
  The prelude defines the following laws. Every row has an executable example in
319
- [algebra.lawspec](https://github.com/brain-fuel/lawspec/blob/v0.13.2/examples/specs/algebra.lawspec), including both sides of every
348
+ [algebra.lawspec](https://github.com/brain-fuel/lawspec/blob/v0.15.0/examples/specs/algebra.lawspec), including both sides of every
320
349
  combined law. `f` and `g` are binary operations, `inverse` is unary, and `e` and
321
350
  `zero` are scalar parameters. All these laws require equality of the element type.
322
351
 
@@ -384,7 +413,7 @@ their entire consequence. Every conjunct is type-checked and emitted. As with
384
413
  existing assertions, the first failure stops that individual test. `and` is now
385
414
  a reserved word.
386
415
 
387
- [Currying examples](https://github.com/brain-fuel/lawspec/blob/v0.13.2/examples/specs/currying.lawspec) demonstrate a four-argument
416
+ [Currying examples](https://github.com/brain-fuel/lawspec/blob/v0.15.0/examples/specs/currying.lawspec) demonstrate a four-argument
388
417
  function partially applied twice, a formatter with four heterogeneous arguments,
389
418
  and composition after partial application. Each example states its exact outputs.
390
419
  Run `node npm/bin/lawspec.mjs examples` after rebuilding to inspect all nine units
@@ -436,7 +465,7 @@ law `valid ports round trip` is
436
465
  end
437
466
  ```
438
467
 
439
- The [complete port example](https://github.com/brain-fuel/lawspec/blob/v0.13.2/examples/specs/parse_port.lawspec)
468
+ The [complete port example](https://github.com/brain-fuel/lawspec/blob/v0.15.0/examples/specs/parse_port.lawspec)
440
469
  defines valid ports as 1–65535, and covers both endpoints, ordinary ports, zero,
441
470
  negative values, and 65536. All explicit `expect` assertions run regardless of
442
471
  the law's condition. A false condition skips only the consequence: invalid ports
@@ -454,7 +483,7 @@ The prelude includes `satisfies predicate` (the predicate holds for every input)
454
483
  and `left inverse when predicate parse render` (the guarded round trip above).
455
484
  These reusable laws preserve the condition and its lexical bindings when expanded.
456
485
  `equivalent` can also compare two predicates, since `Bool` supports equality.
457
- The [Boolean flags example](https://github.com/brain-fuel/lawspec/blob/v0.13.2/examples/specs/boolean_flags.lawspec)
486
+ The [Boolean flags example](https://github.com/brain-fuel/lawspec/blob/v0.15.0/examples/specs/boolean_flags.lawspec)
458
487
  checks that flipping twice restores both `false` and `true`; all targets generate
459
488
  Boolean property inputs and explicit tests for both Boolean boundary values. Java caps Boolean-only JetCheck runs at the number of
460
489
  possible input combinations (up to 100), avoiding generator exhaustion.
@@ -533,7 +562,7 @@ This expands to `for all (x :: Int32) . render (x) = referenceRender (x)`.
533
562
  The example inherits the input name `x` from the prelude. Both functions are
534
563
  user-owned adapter functions; either may delegate to your existing code.
535
564
 
536
- [The complete example](https://github.com/brain-fuel/lawspec/blob/v0.13.2/examples/specs/equivalent.lawspec) compares decimal
565
+ [The complete example](https://github.com/brain-fuel/lawspec/blob/v0.15.0/examples/specs/equivalent.lawspec) compares decimal
537
566
  renderers and two implementations that clamp negative integers to zero. For
538
567
  JavaScript, their adapters can be:
539
568
 
@@ -570,7 +599,7 @@ law `normalizers agree` is
570
599
  end
571
600
  ```
572
601
 
573
- The [slug example](https://github.com/brain-fuel/lawspec/blob/v0.13.2/examples/specs/slug.lawspec)
602
+ The [slug example](https://github.com/brain-fuel/lawspec/blob/v0.15.0/examples/specs/slug.lawspec)
574
603
  compares two implementations of ASCII-space replacement. It includes empty,
575
604
  Unicode and escaped text. Each target uses its native string generator:
576
605
  JetCheck `Generator.stringsOf(Generator.asciiPrintableChars())`, Hypothesis `st.text()`, fast-check `fc.string()`,
@@ -597,7 +626,7 @@ law `canonicalization reaches a fixed point` is
597
626
  end
598
627
  ```
599
628
 
600
- The [canonical URL example](https://github.com/brain-fuel/lawspec/blob/v0.13.2/examples/specs/canonical_url.lawspec)
629
+ The [canonical URL example](https://github.com/brain-fuel/lawspec/blob/v0.15.0/examples/specs/canonical_url.lawspec)
601
630
  uses removal of **all trailing slashes** as a small fixed-point demonstration,
602
631
  not a complete URL canonicalization algorithm. For JavaScript:
603
632
 
@@ -606,7 +635,7 @@ export const canonicalize = value => value.replace(/\/+$/, "");
606
635
  ```
607
636
 
608
637
  Removing just one trailing slash fails the supplied repeated-slash example.
609
- The [mixed-input example](https://github.com/brain-fuel/lawspec/blob/v0.13.2/examples/specs/mixed_inputs.lawspec)
638
+ The [mixed-input example](https://github.com/brain-fuel/lawspec/blob/v0.15.0/examples/specs/mixed_inputs.lawspec)
610
639
  shows `Text` and `Int32` in the same quantified property and executable example.
611
640
  The JavaScript API represents example bindings as typed records whose values use
612
641
  `DataValue`: lossless tagged scalar payloads or structural constructors. Expected results are
@@ -689,7 +718,7 @@ by the JS shim.
689
718
  ## Build and verify
690
719
 
691
720
  For contributors working from a repository checkout, build a local archive with
692
- `npm pack ./npm` and install it with `npm install --save-dev ./lawspec-0.13.2.tgz`.
721
+ `npm pack ./npm` and install it with `npm install --save-dev ./lawspec-0.15.0.tgz`.
693
722
  The package payload lives in `npm/`.
694
723
 
695
724
  ```sh
package/REFINEMENTS.md CHANGED
@@ -1,4 +1,4 @@
1
- # Refinements and abstract integers (0.13.2)
1
+ # Refinements and abstract integers (0.15.0)
2
2
 
3
3
  A refinement restricts a scalar domain with a pure Boolean expression. LawSpec
4
4
  checks concrete examples, generates satisfying input tuples, and checks adapter
@@ -0,0 +1,52 @@
1
+ # LawSpec 0.14
2
+
3
+ ## 0.14.0
4
+
5
+ ### Imports
6
+
7
+ ```lawspec
8
+ unit shop.orders
9
+ import shop.domain as domain (Money, Cents, `commutative`)
10
+ ```
11
+
12
+ A unit imports other units by name. Every declaration of an imported unit is
13
+ available through the alias (`domain.Usd`, `domain.centsOf`), and listed names
14
+ also unqualified. Types, wrappers, indexed families, refinements, checked
15
+ definitions and generic laws can be imported. Adapters and concrete laws stay
16
+ with their unit. Import cycles, unknown units and missing or ambiguous names are
17
+ reported at the import, with the reason: an adapter, a constructor listed
18
+ without its type, or a law without parameters.
19
+
20
+ Names are scoped to their unit, so units compiled together no longer need
21
+ distinct constructor names. Targets with one data namespace (Python,
22
+ JavaScript, TypeScript, Go and Haskell) name colliding types after their unit,
23
+ `ShopDomainCurrency` and `ShopOrdersCurrency`, and their constructors
24
+ `ShopDomainCurrencyUsd`. Java, Kotlin and Rust qualify only the type. Earlier
25
+ versions qualified only the colliding names, for example
26
+ `ShopDomainTypeCurrencyUsd` next to `CurrencyEur`.
27
+
28
+ Imports are resolved before type checking, like indexed families and domain
29
+ models, so Core and the eight backends are unchanged.
30
+
31
+ ### Packages
32
+
33
+ A `lawspec-package.json` names a package, its version, its source directories
34
+ and the version ranges of its dependencies. Package units are named after the
35
+ package, a unit imports only from its own package and direct dependencies, and
36
+ every range must accept the supplied version. A project lists `dependencies` and
37
+ the `packages` directories in `lawspec.json`. A package's adapters and laws are a
38
+ published contract: dependent projects implement and test them as their own.
39
+ `lawspec package` checks a package and summarizes it.
40
+
41
+ The compiler API accepts `dependencies`, `packages` and `package`, and reports
42
+ the resolved packages (see [API migration](API-MIGRATION.md#imports-and-packages-014)).
43
+
44
+ ### Other changes
45
+
46
+ - Rust: a law without quantified inputs no longer emits an untyped empty case
47
+ vector, which did not compile.
48
+ - The VS Code grammar highlights `import` and `as`.
49
+ - A new acceptance suite, `packages`, runs the
50
+ [package example](examples/packages) on all eight targets in both machine
51
+ profiles and rejects five adapter mutants plus the bare stubs. `lawspec-dev ci`
52
+ includes it.
@@ -0,0 +1,44 @@
1
+ # LawSpec 0.15
2
+
3
+ ## 0.15.0
4
+
5
+ ### Evidence and discharge
6
+
7
+ Every obligation of a program reports how it is discharged, strongest first:
8
+
9
+ - `proved`: statically. Definition postconditions and indices, as since 0.12,
10
+ and now laws that call only checked definitions.
11
+ - `exhaustively-checked`: every input of a finite domain, by the compiler for
12
+ laws over checked definitions and otherwise by the generated tests. A law with
13
+ no inputs is a single case.
14
+ - `property-tested`: generated cases, boundary cases and examples.
15
+ - `runtime-checked`: adapter contracts, definition preconditions, constructor
16
+ constraints and native type bindings, at every native boundary.
17
+ - `assumed`: adapters, native functions, custom generators and codec hooks,
18
+ taken on trust. Each adapter reports how many laws call it, or that none does.
19
+
20
+ `lawspec check` summarizes the obligations by status, and the new
21
+ `lawspec evidence` lists each with its claim and reason (`--json` for the API
22
+ records, and a unit or `unit::declaration` filter).
23
+
24
+ ### Laws proved and refuted by the compiler
25
+
26
+ A law over checked definitions is attempted as a proof by the same exact linear
27
+ arithmetic that proves definition results, from its input refinements, with
28
+ definitions that have no preconditions unfolded into the claim. When it is not
29
+ proved and its domain is finite, the compiler evaluates every input; a
30
+ counterexample is a compile error with code `refuted`, such as
31
+ `law always positive is false for x = -128`. Specifications that compiled
32
+ before may therefore be rejected if a law over definitions is false.
33
+
34
+ The prover also handles constant factors on integer expressions (`x * 2`),
35
+ which it previously treated as non-linear, so more definition results are
36
+ proved.
37
+
38
+ ### API
39
+
40
+ `evidence` items have the five statuses above and new stages: `law`,
41
+ `adapter`, and, with native bindings, `binding`, `codec`, `generator` and
42
+ `native-function`. `claim` is `null` for obligations without one. The
43
+ TypeScript API declares `ObligationEvidence` and `DischargeStatus`. See
44
+ [API migration](API-MIGRATION.md#evidence-and-discharge-015).
package/bin/lawspec.mjs CHANGED
@@ -67,6 +67,9 @@ function diagnostics(result) {
67
67
  return result;
68
68
  }
69
69
  async function sources(config) {
70
+ return lawspecFiles(configRoot, config.sources);
71
+ }
72
+ async function lawspecFiles(root, entries) {
70
73
  const files = [];
71
74
  async function visit(file) {
72
75
  const info = await stat(file);
@@ -75,8 +78,7 @@ async function sources(config) {
75
78
  await visit(path.join(file, entry));
76
79
  else if (file.endsWith(".lawspec")) files.push(file);
77
80
  }
78
- for (const source of config.sources)
79
- await visit(path.resolve(configRoot, source));
81
+ for (const source of entries) await visit(path.resolve(root, source));
80
82
  if (!files.length) throw new Error("No .lawspec source files found");
81
83
  return Promise.all(
82
84
  [...new Set(files)].sort().map(async (file) => ({
@@ -85,6 +87,73 @@ async function sources(config) {
85
87
  })),
86
88
  );
87
89
  }
90
+ // A package directory holds lawspec-package.json: its name, version, source
91
+ // directories and dependency ranges. The compiler checks names, versions,
92
+ // namespaces and which units may import which.
93
+ async function loadPackage(directory) {
94
+ const file = path.join(directory, "lawspec-package.json");
95
+ const manifest = JSON.parse(await readFile(file, "utf8"));
96
+ if (
97
+ typeof manifest.name !== "string" ||
98
+ typeof manifest.version !== "string" ||
99
+ !Array.isArray(manifest.sources)
100
+ )
101
+ throw new Error(`${file}: expected name, version and a sources array`);
102
+ return {
103
+ manifest,
104
+ package: {
105
+ name: manifest.name,
106
+ version: manifest.version,
107
+ dependencies: manifest.dependencies ?? {},
108
+ sources: await lawspecFiles(directory, manifest.sources),
109
+ },
110
+ };
111
+ }
112
+ async function packageInput(owner, root) {
113
+ if (owner.packages !== undefined && !Array.isArray(owner.packages))
114
+ throw new Error("packages must be an array of package directories");
115
+ const packages = await Promise.all(
116
+ (owner.packages ?? []).map(async (p) => (await loadPackage(path.resolve(root, p))).package),
117
+ );
118
+ return {
119
+ ...(packages.length ? { packages } : {}),
120
+ ...(owner.dependencies !== undefined ? { dependencies: owner.dependencies } : {}),
121
+ };
122
+ }
123
+ async function packageCommand() {
124
+ const directory = path.resolve(options.project || ".");
125
+ const { manifest, package: own } = await loadPackage(directory);
126
+ const compiler = await createCompiler();
127
+ const result = diagnostics(
128
+ await compiler.check({
129
+ sources: own.sources,
130
+ package: { name: own.name, version: own.version },
131
+ ...(await packageInput(manifest, directory)),
132
+ machineBits: options.machineBits ?? 64,
133
+ }),
134
+ );
135
+ const units = result.units.map((u) => u.id).filter((u) => u !== "prelude");
136
+ const laws = result.laws.filter((l) => units.includes(l.owner));
137
+ const summary = {
138
+ name: own.name,
139
+ version: own.version,
140
+ dependencies: own.dependencies,
141
+ units,
142
+ laws: laws.map((l) => `${l.owner}::${l.name}`),
143
+ dataTypes: result.dataTypes
144
+ .filter((d) => units.some((u) => d.id.startsWith(u + "::")))
145
+ .map((d) => d.id),
146
+ };
147
+ output(
148
+ options.json
149
+ ? summary
150
+ : `${summary.name} ${summary.version}: ${units.length} unit(s), ${summary.laws.length} law(s), ${summary.dataTypes.length} data type(s).
151
+ ` +
152
+ `Units: ${units.join(", ")}
153
+ ` +
154
+ `Dependencies: ${Object.entries(summary.dependencies).map(([n, r]) => `${n} ${r}`).join(", ") || "none"}`,
155
+ );
156
+ }
88
157
  async function init() {
89
158
  const language = options.target;
90
159
  if (!targets.includes(language))
@@ -173,16 +242,16 @@ async function main() {
173
242
  }
174
243
  if (!verb || ["help", "--help", "-h"].includes(verb)) {
175
244
  output(
176
- "LawSpec 0.13.2\nUsage: lawspec init --target <language> [--project <directory>] [--minify]\n lawspec check | doctor | explain <unit>::<law> | generate\n lawspec examples [--example payments] [--target <language>] [--output <directory>]\nOptions: --config <path>, --target <language>, --machine-bits <32|64>, --json\nGeneration: --dry-run, --check, --minify\nTargets: " +
245
+ "LawSpec 0.15.0\nUsage: lawspec init --target <language> [--project <directory>] [--minify]\n lawspec check | doctor | explain <unit>::<law> | generate\n lawspec evidence [<unit> | <unit>::<declaration>]\n lawspec package [--project <package directory>]\n lawspec examples [--example payments] [--target <language>] [--output <directory>]\nOptions: --config <path>, --target <language>, --machine-bits <32|64>, --json\nGeneration: --dry-run, --check, --minify\nTargets: " +
177
246
  targets.join(", "),
178
247
  );
179
248
  return;
180
249
  }
181
250
  if (verb === "--version") {
182
- output("0.13.2");
251
+ output("0.15.0");
183
252
  return;
184
253
  }
185
- if (positional.length > (verb === "explain" ? 1 : 0))
254
+ if (positional.length > (["explain", "evidence"].includes(verb) ? 1 : 0))
186
255
  throw new Error(`Unexpected argument: ${positional.join(" ")}`);
187
256
  if (verb === "examples") {
188
257
  if (
@@ -218,7 +287,8 @@ async function main() {
218
287
  if (options.minify && !["init", "generate", "examples"].includes(verb))
219
288
  throw new Error("--minify applies to init, generate and examples");
220
289
  if (verb === "init") return init();
221
- if (!["check", "doctor", "explain", "generate"].includes(verb))
290
+ if (verb === "package") return packageCommand();
291
+ if (!["check", "doctor", "evidence", "explain", "generate"].includes(verb))
222
292
  throw new Error(`Unknown command: ${verb}`);
223
293
  const config = JSON.parse(await readFile(configFile, "utf8"));
224
294
  if (
@@ -255,14 +325,27 @@ async function main() {
255
325
  return;
256
326
  }
257
327
  if (config.machineBits !== undefined && ![32, 64].includes(config.machineBits)) throw new Error("machineBits must be 32 or 64");
258
- const input = { sources: await sources(config), generation: config.generation, machineBits: options.machineBits ?? config.machineBits ?? 64 };
328
+ const input = {
329
+ sources: await sources(config),
330
+ ...(await packageInput(config, configRoot)),
331
+ generation: config.generation,
332
+ machineBits: options.machineBits ?? config.machineBits ?? 64,
333
+ };
259
334
  const compiler = await createCompiler();
260
- // Proved obligations need no runtime check; the rest are enforced at runtime.
335
+ // Each obligation reports how it is discharged, strongest first.
336
+ const statuses = [
337
+ ["proved", "PROVED"],
338
+ ["exhaustively-checked", "EXHAUSTIVELY CHECKED"],
339
+ ["property-tested", "PROPERTY TESTED"],
340
+ ["runtime-checked", "RUNTIME CHECKED"],
341
+ ["assumed", "ASSUMED / EXTERNAL"],
342
+ ];
261
343
  const evidenceSummary = (evidence) => {
262
344
  if (!evidence.length) return "";
263
345
  const count = (status) => evidence.filter((item) => item.status === status).length;
264
- return ` Evidence: ${count("proved")} proved, ${count("runtime-checked")} runtime-checked obligation(s).`;
346
+ return ` Evidence: ${statuses.map(([status, label]) => `${count(status)} ${label.toLowerCase()}`).join(", ")}.`;
265
347
  };
348
+ const obligationName = (item) => item.declaration.replace("::law::", "::");
266
349
  if (verb === "check") {
267
350
  const result = diagnostics(await compiler.check(input));
268
351
  for (const target of selected) {
@@ -276,6 +359,36 @@ async function main() {
276
359
  );
277
360
  return;
278
361
  }
362
+ if (verb === "evidence") {
363
+ const result = diagnostics(await compiler.check(input));
364
+ let evidence = result.evidence;
365
+ // Native bindings are configured per target; their obligations are added.
366
+ for (const target of selected) {
367
+ if (target.nativeBindings === undefined) continue;
368
+ const bound = diagnostics(await compiler.check({...input, nativeBindings: target.nativeBindings}));
369
+ evidence = evidence.concat(bound.evidence
370
+ .filter((item) => ["binding", "codec", "generator", "native-function"].includes(item.stage))
371
+ .map((item) => ({...item, target: target.language})));
372
+ }
373
+ evidence = evidence.filter((item) => !positional[0] ||
374
+ obligationName(item) === positional[0] || item.owner === positional[0]);
375
+ if (positional[0] && !evidence.length) throw new Error("No matching obligation");
376
+ output(
377
+ options.json
378
+ ? evidence
379
+ : statuses
380
+ .map(([status, label]) => {
381
+ const items = evidence.filter((item) => item.status === status);
382
+ if (!items.length) return null;
383
+ return `${label} (${items.length})\n` + items.map((item) =>
384
+ ` ${item.stage} ${obligationName(item)}${item.target ? ` [${item.target}]` : ""}` +
385
+ (item.claim ? `: ${item.claim.text}` : "") + `\n ${item.reason}`).join("\n");
386
+ })
387
+ .filter((section) => section !== null)
388
+ .join("\n\n"),
389
+ );
390
+ return;
391
+ }
279
392
  if (verb === "explain") {
280
393
  const result = diagnostics(await compiler.expand(input));
281
394
  const indices = result.laws
package/build.json CHANGED
@@ -55,7 +55,9 @@
55
55
  "src/LawSpec/CoreNativeScalarEmit.hs",
56
56
  "src/LawSpec/CoreScalarEmit.hs",
57
57
  "src/LawSpec/Data.hs",
58
+ "src/LawSpec/DataNames.hs",
58
59
  "src/LawSpec/DefinitionTotality.hs",
60
+ "src/LawSpec/Discharge.hs",
59
61
  "src/LawSpec/Domain.hs",
60
62
  "src/LawSpec/DomainModel.hs",
61
63
  "src/LawSpec/Elaboration.hs",
@@ -77,6 +79,7 @@
77
79
  "src/LawSpec/HaskellProperties.hs",
78
80
  "src/LawSpec/HaskellTestHelpers.hs",
79
81
  "src/LawSpec/HaskellTypeRefs.hs",
82
+ "src/LawSpec/Imports.hs",
80
83
  "src/LawSpec/Indexed.hs",
81
84
  "src/LawSpec/Inference.hs",
82
85
  "src/LawSpec/JavaData.hs",
@@ -94,6 +97,7 @@
94
97
  "src/LawSpec/Model.hs",
95
98
  "src/LawSpec/NativeBinding.hs",
96
99
  "src/LawSpec/NativeRequest.hs",
100
+ "src/LawSpec/Packages.hs",
97
101
  "src/LawSpec/Parser.hs",
98
102
  "src/LawSpec/PortableGenerator.hs",
99
103
  "src/LawSpec/PortableTestHelpers.hs",
@@ -130,8 +134,8 @@
130
134
  "wasm/lawspec-wasm.cabal"
131
135
  ],
132
136
  "digests": {
133
- "lawspec.cabal": "88e838807acd277e0e8935016e1fef69a833077f4d71f124c90dc82595a38ff1",
134
- "package.yaml": "63da3402b545fee063873916cbf7a1a21043a7c2a66424d0be715b28e4e2d590",
137
+ "lawspec.cabal": "b929e618142528937531dfa7f524facd2dfb26d12724c3b09a7dc655e4c7c425",
138
+ "package.yaml": "cc4b0ee63fbca1f1bcb7a12adf4fc52d013875a20bbd3f051b542a2f5bfc0f05",
135
139
  "runtime/LawSpecCodecs.hs": "90cb1ed15d7ab664a17a054580c849408d77cfd2b2adcb4a3228b05132caeaca",
136
140
  "runtime/LawSpecDataStrategies.hs": "cbe9f1946228db1076c19cd3158e8798fe32766cfdbea3f66b63d22d3d217508",
137
141
  "runtime/LawSpecDataStrategies.java": "e3416efe8a0d7b1276cb4d1a8105fd01b1f5f3f02a803bf55d955d9e3ec39095",
@@ -155,20 +159,20 @@
155
159
  "runtime/lawspec_schema.mjs": "60eb4204461eaa2c207fc7c3394014e2a814e4383b7045c065b4dae7c7a202c2",
156
160
  "runtime/lawspec_schema.py": "b6967ef1a33fe6a1a180d5573ec37cd8bb2079c06e961ac2eeb05f23cffcdd07",
157
161
  "runtime/lawspec_strategies.rs": "cac9ca301d4614fff9acfe61e7cc5678fabc044edadfa89ec11599b6780dc5f3",
158
- "runtime/rust/Cargo.lock": "17f3a870021e47b128578e6a4e2467ac02376584b89b851daa6280fbeda23abf",
159
- "runtime/rust/Cargo.toml": "f3737514e8a696bdfcf496c483d03aab9dda0c9fc6cf07b8a6ec300d9b0d8e15",
160
- "src/LawSpec/Api.hs": "392f6e8c1a9ae81a95e219ac071e5b4bea03ee330d63b829036f8f54b2eda8a7",
162
+ "runtime/rust/Cargo.lock": "4cf7b8d8d86a8f4d9609675d34e2e5da3efc45bd86a338bec67377c4276df5b2",
163
+ "runtime/rust/Cargo.toml": "519ee452ecc764d512120209a33d32a66e51af62fb608638711db15e88a58652",
164
+ "src/LawSpec/Api.hs": "766d9d2f0c4c43c12524b51e17c42e634b87ba52c78743bd5a2cd6b8dca78983",
161
165
  "src/LawSpec/Backend.hs": "03c3b0cd62467ca677c88d29d7b12b2ab505cc0076d93d1f48fbddb0e9bcf133",
162
166
  "src/LawSpec/Capabilities.hs": "e43d4fc3a4481fbb8aa3ff1c3f41f7e7fca5db01bfe256a30162a45d75a00c1c",
163
167
  "src/LawSpec/Code/Doc.hs": "9e3b70f85deb1dcbce385af1d0cd4bea2dfa8a2d806d54745d4bb437406673e5",
164
168
  "src/LawSpec/Code/JavaScript.hs": "77bf27dcc210216e4739f68c4709f556f80130ab83b3b9387ac4a2421e790910",
165
169
  "src/LawSpec/Common.hs": "107612a8aaa787488413acf9c1a56622004d3bff251db89b99928343e6070883",
166
- "src/LawSpec/Compile.hs": "0260f0f1dc3d18d2f2e172ab47d603b6e3029ce2948cc0a237ad8277fc64707f",
170
+ "src/LawSpec/Compile.hs": "ac7c9d81b7c205b1d56a30f94bd8474c6910db8ecab4802f451ab39a10fe073b",
167
171
  "src/LawSpec/Core.hs": "ec081c49e5ccce95f84ded6073f1d8f30298f061dd8b94437d4b00410c57f27c",
168
172
  "src/LawSpec/Core/DefinitionContracts.hs": "b7f60f038b231187ecf898e585ae1a8fb1fc113bb55bad6d1bb2660350fd969e",
169
173
  "src/LawSpec/Core/Definitions.hs": "52f024fca59661142f70f9aa7dd2cbdb4892e5d3b1ca8079c878c5a1ba667112",
170
174
  "src/LawSpec/Core/Eval.hs": "e1ad8af5b240dd99c3b1126408d2be5f9b42b86ca6189ecd3868680a5119d931",
171
- "src/LawSpec/Core/Evidence.hs": "460af282299258c87ddba58b55ad09290d7d89e6e7d43a02f5470fbd5b7974a3",
175
+ "src/LawSpec/Core/Evidence.hs": "84976ccfc84f8f31c8391008cd767b75753488f9e7872045ab0c997f6f1d8613",
172
176
  "src/LawSpec/Core/Expression.hs": "84985f4f685126253d3af7b6b605d80d28fc9aa115bd5e2946f989eeb1355224",
173
177
  "src/LawSpec/Core/Payload.hs": "df6a2b250c27c12bb6ac16b84847c52546081d066a3dca7575ed0d743cc13d50",
174
178
  "src/LawSpec/Core/PayloadPlan.hs": "f2a7d2dc58c6a0f79707bdc24773bd3aad3a3b8eea2735a8284b2a9f3a4af4a8",
@@ -176,7 +180,7 @@
176
180
  "src/LawSpec/Core/Schema.hs": "9a4ec3967803913e6ff43d33e00a1b4b3b8ec0c79dbdbd80ae98101c85bf430f",
177
181
  "src/LawSpec/Core/Semantics.hs": "a9d019433e3b9731f8cd0f65ec0ccc53179824bea58247b72df26760b878c2b6",
178
182
  "src/LawSpec/Core/Total.hs": "95d2b19ba7fbfd033295504d31f786815384003b3b4d370776860b423cf079dd",
179
- "src/LawSpec/Core/Totality.hs": "a96fc3b9e8be5d18997065b9d09c0f8a2ede4d6ed2974b3bf355967986b0e459",
183
+ "src/LawSpec/Core/Totality.hs": "3bd81ebdd2020d8b17809904a42a2d5f0a12075d8b8b3fa3b1907bdc7024bd46",
180
184
  "src/LawSpec/Core/Types.hs": "48ed1d197ce7089737895b7279f93437301fcfacff8b3a8dd98ecd7f1cb32b37",
181
185
  "src/LawSpec/Core/Validate.hs": "0f045241215e068081d6cd7cf451f0166671bae5fffafda71a2e2320e8014c27",
182
186
  "src/LawSpec/Core/Value.hs": "f2b2e4d82491e184d60b1217922b25c57a06cbbaecb2cb6f31174af50268fbc9",
@@ -184,82 +188,86 @@
184
188
  "src/LawSpec/CoreNativeScalarEmit.hs": "4082661ba5f8b1b09b4811f62ba767fa1ea401a38dd10011aea442c5a27892af",
185
189
  "src/LawSpec/CoreScalarEmit.hs": "d1a51f7fe9b23817eeac7b50dac70ec02219df66d4b0218c5c9ae5237da244fd",
186
190
  "src/LawSpec/Data.hs": "9dbeafa120276b114dad790ec69e617f7ad0c632e3c718962f2f7faf8ca327f4",
191
+ "src/LawSpec/DataNames.hs": "f10da6137dade8ac369fabb9231d87bf0d801655eb6756e816369102d147b4c0",
187
192
  "src/LawSpec/DefinitionTotality.hs": "7671b7efb0cac5d796b074d48b2c10940e5bd0b5df082b926aee694903285efa",
193
+ "src/LawSpec/Discharge.hs": "9b41c93980ae8bc44a11e4ad27efa702d1e6776c9c8584f691464de072c0c2d7",
188
194
  "src/LawSpec/Domain.hs": "222d15f0012ae630802238a6d7e1ee78d1e718b599f5ebb5a1ddc4e8d29d68c3",
189
195
  "src/LawSpec/DomainModel.hs": "3be67117c44e66a39d42d7ce094c2940c48ea1541017b64027afa6ea4b77092f",
190
196
  "src/LawSpec/Elaboration.hs": "86e3ef77a977cb1b55985e2939648135acd0c2c015afe76e34e09615d555f53e",
191
197
  "src/LawSpec/Emit.hs": "9f34f5765915a2a12a66a6dca647ddaef9289372956802c6d99cf0cfec447c7a",
192
198
  "src/LawSpec/Eval.hs": "b0872ba8a6974463b32776653c2939826a6be87318c15641401f913f6b139de2",
193
199
  "src/LawSpec/Frontend.hs": "fbf091b9c96f5b5361dbf4f65819634c0f8526ff98550d97c434c0d47af7839e",
194
- "src/LawSpec/Gen.hs": "c76d00fb1f7e9ed2eed7d387f1cd86cf4d12cc57f007abb0e479043b0ed377e6",
195
- "src/LawSpec/GoData.hs": "35efbfdc1079e777d4760069fa2405a9700bbabab7dc7e3c2c5e0757312ea201",
200
+ "src/LawSpec/Gen.hs": "534c994a500c8af40b5750a6a25505d346b928afa771453466f1980925bae9d8",
201
+ "src/LawSpec/GoData.hs": "1b1882906ba676cdd37c744b91d271c7d25279b137f0c5ba5863f4423729bc86",
196
202
  "src/LawSpec/GoDefinitions.hs": "3cb55c22f28443fff73e73c59780bf1977ab9260b8d66c7f19d1b94b40d1397e",
197
203
  "src/LawSpec/GoExpr.hs": "da3a7cc0e3d2906886dc44f6b990e72098bb351558bbb31ee335da7382fac58a",
198
204
  "src/LawSpec/GoNativeBinding.hs": "1ad8ea4cec6187c7e6005651c0edeec69e196eb329fb958c833da7751225aa1b",
199
205
  "src/LawSpec/GoProperties.hs": "1eee75d852b0a1f8b6fe2cfb1cd3ed7dc57f44ca0ee137697729e8e1583d85fe",
200
206
  "src/LawSpec/GoTestHelpers.hs": "dee55ee8505370e932773b8c685f4a1f380129e6f43f8806bf1e82efb99451b1",
201
207
  "src/LawSpec/GoTypeRefs.hs": "7f239f5ac3ac8bd21c8f76c328049f7715d8562ee1382befa0a58abd4f15f726",
202
- "src/LawSpec/HaskellData.hs": "51374f35de2b1d6c78d15597e41e6f0695fe5fdb040cbb35a7d03d23fa3a3179",
208
+ "src/LawSpec/HaskellData.hs": "0925cf589c8ff1e821ff1f0fa023deed562e2b71bffb97aef5befad69890e010",
203
209
  "src/LawSpec/HaskellDefinitions.hs": "bc3664771247547900fc65f62147048238c3aa477154ac69d7a6e7568b05b2dd",
204
210
  "src/LawSpec/HaskellExpr.hs": "f4144cf2022ef0a3bec6d796ebe7d2f42563e9d25758b9f362cd5545b47e802b",
205
211
  "src/LawSpec/HaskellNativeBinding.hs": "9f98aa0c8659b572bd6486a0e29c4692bc6432db8639fa74a09bbf1b771bbfa6",
206
212
  "src/LawSpec/HaskellProperties.hs": "5d64d5f45b86b5bb148383588d69ad717b0e158926b76938cc5cef54ed3adecc",
207
213
  "src/LawSpec/HaskellTestHelpers.hs": "51e59b2abc9e85455e3c8e2c6baadb27e5d319081cb730d2ce56be5dc8053897",
208
214
  "src/LawSpec/HaskellTypeRefs.hs": "2225b2a5e2ab3662e7202d23b24f4d6db48353b35ae28df8acd2b92fd2b97574",
209
- "src/LawSpec/Indexed.hs": "bfb24a4023517acf9f34e6f3327c5623f0e18b1576e5453a43d7a6cd9e691e00",
215
+ "src/LawSpec/Imports.hs": "4e146ae1c2ee54f038b83430f322f8aadaede252a0857345471eb02a91d39ed6",
216
+ "src/LawSpec/Indexed.hs": "77d0198459ac5b8aad51d7043ed9759035ba5b819ae0664d3e9dcd51d36cac03",
210
217
  "src/LawSpec/Inference.hs": "78285145897f03c3c4adc37acf0f490ea779bab3975fb2830628dae3a152fe38",
211
- "src/LawSpec/JavaData.hs": "177713377f7a38d69fbfd7891899357fc55782cf1d361f2e9dd5baf8725d4067",
218
+ "src/LawSpec/JavaData.hs": "4645edcab4524c6979450a1d92fb88baf39586b2aa56bcc603bd58dabaebe017",
212
219
  "src/LawSpec/JavaDefinitions.hs": "fc2666e4f9f68b747aa596c0caf0483b9f0a47ec4957bbcd399234e77909588d",
213
220
  "src/LawSpec/JavaExpr.hs": "6f237b0fc1eabe2d53c160f4cb781f8b77b478383f1a77ca4ccc8f08ac0dbcd0",
214
221
  "src/LawSpec/JavaNativeBinding.hs": "8abbae78959a5cb61b7c6ae1c9071e43d10e26c2f421766d431fa18031f87173",
215
222
  "src/LawSpec/JavaProperties.hs": "d953771df667aa193b110dbc898b0936b9ff5a32f6ebc9d2ff25d44a6cd4dfec",
216
223
  "src/LawSpec/JavaTestHelpers.hs": "e6f4b9bbb7e5f07ece6ab1845e12aa661e62e8b926680b11454223fc3ec1523d",
217
- "src/LawSpec/KotlinData.hs": "7785fc0c091e50010bce3002355f01c1d237fce05bca6a7ce6de6d207737e228",
224
+ "src/LawSpec/KotlinData.hs": "99ea660416ccc2156584a767e5cc200c0f5ccbf47c47f7b256c00d374ddc65dc",
218
225
  "src/LawSpec/KotlinDefinitions.hs": "97d7d407d4bbdb4ce16035d607dbbcb8e3d6f5db513f2123a2c269e3dc6d2b38",
219
226
  "src/LawSpec/KotlinExpr.hs": "20312f0774f1d0832a21a19b93c8103e2791ecd32a827d8e9c4f2b4830a996a0",
220
227
  "src/LawSpec/KotlinNativeBinding.hs": "1aec7854758f07a4d2288de13931fbb88ef32220f85d3c84fe8233ad67b6d095",
221
228
  "src/LawSpec/KotlinProperties.hs": "ee8c68bc5ee10a601a643356edb1e0a0c50d6e72a4520feaccb716c6f02ac99c",
222
229
  "src/LawSpec/KotlinTestHelpers.hs": "74810d65faafc6ed4d64b1fb0596cda4186e586b7144a7441641b798795bc324",
223
- "src/LawSpec/Model.hs": "1d7ceb7bd66e3d496eef89eaa86403e6896472317ca9a4be86e0c933a7cce403",
230
+ "src/LawSpec/Model.hs": "8d01d937b9ced2047018fa12dc8b06b0d71389c1dd9bd9f4dc5f71613d778b0f",
224
231
  "src/LawSpec/NativeBinding.hs": "33959b0fd432ad4150f3b685f6438e284b801c2a59d9ef3132486a1cc7c8925a",
225
232
  "src/LawSpec/NativeRequest.hs": "fb2dc88f42424ca520533700eab68c407a5de83807d1b0d8c976e6c4f3d65212",
226
- "src/LawSpec/Parser.hs": "94a5603f6831d1dad5634a766bbc02cc58d884d23b5d6606ed4a1537cfe4c813",
233
+ "src/LawSpec/Packages.hs": "161fc68a9959a80762ca4ece405240351e3180ea4dbb2bf148eaca6562fb7c30",
234
+ "src/LawSpec/Parser.hs": "b99b122a5505667906e05c61da74f1c00dea830dd6936bc35b1d715f797723a2",
227
235
  "src/LawSpec/PortableGenerator.hs": "69d457e39f539c77fc7a4c08205e75352bbecd9dfdff031a283a39bf44b22d49",
228
236
  "src/LawSpec/PortableTestHelpers.hs": "8ba4d87183c8c11f6ef1ce21c170127335797154f29fb97ad3429f032a167fd3",
229
237
  "src/LawSpec/Prelude.hs": "b1e155c12f58e7c346551a0c65c5d5af76d045b3f1625977ca2a5d1c97cb8c46",
230
- "src/LawSpec/Public.hs": "ca7f3edd3e5d623ecb1aecb2386fdcf4b1e334cf7bd7770b6a14f5690d8f5ed5",
238
+ "src/LawSpec/Public.hs": "ac46d7b8c5130faf922f10b402e035901d851bb8a229ea823ce0afaaf3011028",
231
239
  "src/LawSpec/PythonData.hs": "07e9bb54a1515f3f4744b7b9bb43633cbdbf07b3f9e35efef511753f97e216d5",
232
240
  "src/LawSpec/PythonDefinitions.hs": "30f3d2d71a378e194d62261e0fd1baade5a49ac8b5eaac97578ca015a48ce8e4",
233
241
  "src/LawSpec/PythonExpr.hs": "23d7d24b5fb4efff9cb63d38c02a93d95744ec79b4565daf1412088fc7c4ba59",
234
242
  "src/LawSpec/PythonNativeBinding.hs": "4e35ff8781062d0f614e45ea45f98038c8d609ab78bd671cb0a239eaa9db1690",
235
- "src/LawSpec/PythonTypes.hs": "ef928bfeb4324eb6e53c99cae247cc2fa84816075d81de4589d14abaa326656a",
236
- "src/LawSpec/Refinement.hs": "8058a9f7e433b4b00ef0966a9ea2be3c91ae93b591ed58a1ffcb792d316193d3",
243
+ "src/LawSpec/PythonTypes.hs": "61c7271279e33b59f5b70cdee6363e0c0efb53a2f58c3256950dbec522ad7f10",
244
+ "src/LawSpec/Refinement.hs": "3bbdc090f9ebce60d99254dbe93dec6e11bd838df8537df828fd9c768c79d126",
237
245
  "src/LawSpec/RuntimeSources.hs": "22c9f7e4f977b4f548363f494c9d66edeb4d3247c7a1e7e7cad470b1059019be",
238
- "src/LawSpec/RustData.hs": "8fda864335ccb5478c39f56cb714d5275edf36fcbdc2d152bbe94960b644ad98",
246
+ "src/LawSpec/RustData.hs": "0d28ff5b35c5085c55604ef1eea366dec737b29d3352ef1576bb82c7421b615c",
239
247
  "src/LawSpec/RustDefinitions.hs": "8c289e2779d7ed623f3578f20974dd9e2016c67734ee1447ed7f4b7c22caedf9",
240
- "src/LawSpec/RustEmit.hs": "0687d8589940e7b39daa953c439009d1416eba7da54e9936d2f5595316744d21",
248
+ "src/LawSpec/RustEmit.hs": "d08797ca26180b6ed2884c0576ec7b0265cadc2236a95d8754cfea89bb2940e0",
241
249
  "src/LawSpec/RustExpr.hs": "04b2ef81417b811c7b98a98acdadab4e588ca8757964a63ba8dc5936c36479e6",
242
250
  "src/LawSpec/RustNativeBinding.hs": "9d08348da571ac335e335e48c1ad4a67108f7bca54119f5960480e97a6d1da84",
243
251
  "src/LawSpec/RustNativeGenerators.hs": "a3b1484d9ff0008e4f961aa81d0aa51da57ec0cd7909124e80c98d56aacc8ce9",
244
252
  "src/LawSpec/Scaffold.hs": "2cdaeaa0708803e6abf3b8e9062dfc2fe31e2d3a6df3b252a17b1ad91eb5d8f2",
245
253
  "src/LawSpec/Scalar.hs": "52e61fec81a337bb5b35e9e6f501446cf0b18bffa6c6af2ddc5aeac2d6e07131",
246
254
  "src/LawSpec/SpecializeDefinitions.hs": "08f2fe674a5e00d1be396d9edab0dd2c948b7beb12fa99f2a6aba00cbdf01e33",
247
- "src/LawSpec/Testing.hs": "7b0a2e58bcef24365883b479b6a5af720cc2ac4c217ae23bb771c2621d82aec3",
255
+ "src/LawSpec/Testing.hs": "9626e43e4c02a0c88435ffe2d629110a99b1b91e8d0bcaa98b468509da69d438",
248
256
  "src/LawSpec/WebData.hs": "919af27be12f63f17762e0c052341ab82dcee5d45951a4fd9c66abead98d1ee0",
249
257
  "src/LawSpec/WebDefinitions.hs": "d654df765e4bafcb1acdd35058f8a510c2cd81920153c0a75ff1e7e1137c96e5",
250
258
  "src/LawSpec/WebExpr.hs": "0389dcd5cf7479dd23ef034b1012de6ebd70bf1dc9e3d90981dfb0ba2702596f",
251
259
  "src/LawSpec/WebNativeBinding.hs": "465251be1a93d24a775aa57955bb9ec612af7364c53c83017da051f44943eda9",
252
- "src/LawSpec/WebTypes.hs": "f77ffee1e0c7929964a889fb252c1c5d0977afed94664ffcb0f8770c37b98c70",
260
+ "src/LawSpec/WebTypes.hs": "f74c6e346e3e3922223f8738a8f85e2b036e8f0469d9d7f027400e2f60f6957e",
253
261
  "stack.yaml": "20ccf4d599e355e60b7aa4f814a7cd4299fe2048616cc2e6dbdc22a7bd8cec73",
254
262
  "stack.yaml.lock": "ae222b9c81af920c56e50fa4596fa57786e7fa5a7b461390362b2b2ff63818c7",
255
263
  "tools/embed-runtimes.py": "91a05197fc542a65387f3ccf4614a4817c850031eb4b84196c621b8baf344865",
256
264
  "wasm/app/Exports.hs": "4ecbdac8faa2449e6fc61b93c82e6278fa14374154f29b4dacf0eef433f06a47",
257
265
  "wasm/cabal.project": "021e560afdc5eb4cb7169e7119ecb8f92c9ee170245af909c94b612941bff5cc",
258
266
  "wasm/cabal.project.freeze": "733dbed3d2ecccb26e874fd58f136296dad772184deb1658c196b5d54a0814dc",
259
- "wasm/lawspec-wasm.cabal": "5ca5b6f2ed98be3095c0f1f2233efbe13f61f2a13dd111936c5c956df0fd1725",
260
- "npm/core.wasm": "16f17510da392bc8fff7d4cbcb34abab2fa0e45abd4a9d4f4d62bf0ffb19cff5",
267
+ "wasm/lawspec-wasm.cabal": "ccc2458717fa37d0bf5d96dfd9a517804d1850553a3a571729886a31618b00ec",
268
+ "npm/core.wasm": "1cb825c73738eb0e05329e24fc7d7a3c905761ff2be7ebf1b8ea8614a8f40319",
261
269
  "npm/core_jsffi.js": "88d136efe92f7cff5758c8fec8d9b6bbc9707fe37741cebeeb415fe34ce3d72b",
262
270
  "npm/api.mjs": "e93251db289ff0609abaff78ad67f0a9af82508c1141c6a999604f67c56b6e7d",
263
- "npm/index.d.ts": "2674f8830bd20a2b9ef7dfa99e183598125b6bcc17e8d454e8f7cca1bbd2c9fe"
271
+ "npm/index.d.ts": "470cff02e89c1f2ec458075c63eff60382b9dc4a7f961691eb4f0ed9afc71e73"
264
272
  }
265
273
  }
package/core.wasm CHANGED
Binary file
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 1,
3
+ "sources": ["orders.lawspec"],
4
+ "dependencies": { "shop.domain": "^1.0.0" },
5
+ "packages": ["../shop-domain"],
6
+ "targets": []
7
+ }
@@ -0,0 +1,57 @@
1
+ unit shop.orders
2
+ import shop.domain as domain (Money, Cents, `commutative`, `idempotent`)
3
+
4
+ -- Constructor names are scoped to their unit: this Usd is not domain.Usd.
5
+ type Currency is | Usd | Gbp end
6
+
7
+ type Line is Line price :: Money quantity :: domain.Quantity end
8
+
9
+ settlement :: Currency -> domain.Currency
10
+ lineTotal :: Line -> Money
11
+ -- Generic laws quantify over the argument's base type, so these adapters take
12
+ -- any Int64; the last law restricts its inputs to Cents.
13
+ cheaper :: Int64 -> Int64 -> Int64
14
+ roundDown :: Int64 -> Int64
15
+
16
+ law `dollars settle in dollars` is
17
+ definition is
18
+ settlement Usd = domain.Usd
19
+ end
20
+ end
21
+
22
+ law `pounds settle in euros` is
23
+ definition is
24
+ settlement Gbp = domain.Eur
25
+ end
26
+ end
27
+
28
+ law `a line total keeps the price currency` is
29
+ definition is
30
+ `for all` (l :: Line) .
31
+ domain.currencyOf (lineTotal l) = (match l with
32
+ | Line p q -> domain.currencyOf p
33
+ end)
34
+ end
35
+ example `two items` is
36
+ l = Line (Money domain.Usd 250) (domain.Quantity 2)
37
+ expect domain.centsOf (lineTotal l) = 500
38
+ end
39
+ end
40
+
41
+ law `the cheaper price does not depend on order` is
42
+ definition is
43
+ `commutative` cheaper
44
+ end
45
+ end
46
+
47
+ law `rounding down to whole dollars is stable` is
48
+ definition is
49
+ `idempotent` roundDown
50
+ end
51
+ end
52
+
53
+ law `rounding down never raises a price` is
54
+ definition is
55
+ `for all` (c :: Cents) . roundDown c <= c
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "shop.domain",
3
+ "version": "1.2.0",
4
+ "sources": ["src"]
5
+ }
@@ -0,0 +1,49 @@
1
+ unit shop.domain
2
+
3
+ -- A package of reusable types, refinements, definitions and laws. Other units
4
+ -- import it by name; its declarations keep their own names, so an importer may
5
+ -- declare a Currency or a Usd of its own.
6
+ type Currency is | Usd | Eur end
7
+
8
+ refinement Cents is (c :: Int64 where c >= 0 && c <= 100000000) end
9
+
10
+ type Money is Money currency :: Currency cents :: Cents end
11
+
12
+ wrapper Quantity is Int32 where value >= 1 && value <= 1000 end
13
+
14
+ definition currencyOf (m :: Money) :: Currency is
15
+ match m with | Money c n -> c end
16
+ end
17
+
18
+ definition centsOf (m :: Money) :: Int64 is
19
+ match m with | Money c n -> n end
20
+ end
21
+
22
+ -- Generic laws are templates: an importer applies them to its own adapters.
23
+ law `commutative` (f :: a -> a -> a) requires Eq a is
24
+ definition is
25
+ `for all` (x :: a) (y :: a) . f x y = f y x
26
+ end
27
+ end
28
+
29
+ law `idempotent` (f :: a -> a) requires Eq a is
30
+ definition is
31
+ `for all` (x :: a) . f (f x) = f x
32
+ end
33
+ end
34
+
35
+ -- A published contract: every project that depends on this package implements
36
+ -- convert and is tested against these laws.
37
+ convert :: Currency -> Money -> Money
38
+
39
+ law `conversion targets the requested currency` is
40
+ definition is
41
+ `for all` (c :: Currency) (m :: Money) . currencyOf (convert c m) = c
42
+ end
43
+ end
44
+
45
+ law `converting to the same currency changes nothing` is
46
+ definition is
47
+ `for all` (m :: Money) . convert (currencyOf m) m = m
48
+ end
49
+ end
package/index.d.ts CHANGED
@@ -212,12 +212,50 @@ export interface NativeBindings {
212
212
  goImports?: NativeGoImport[];
213
213
  }
214
214
 
215
+ export type DischargeStatus =
216
+ 'proved' |
217
+ 'exhaustively-checked' |
218
+ 'property-tested' |
219
+ 'runtime-checked' |
220
+ 'assumed';
221
+
222
+ export interface ObligationEvidence {
223
+ owner: string;
224
+ declaration: string;
225
+ stage: string;
226
+ status: DischargeStatus;
227
+ reason: string;
228
+ claim: Expr | null;
229
+ }
230
+
231
+ export interface PackageVersion {
232
+ name: string;
233
+ version: string;
234
+ }
235
+
236
+ export interface Package {
237
+ name: string;
238
+ version: string;
239
+ dependencies?: Record<string, string>;
240
+ sources: Source[];
241
+ }
242
+
243
+ export interface PackageView {
244
+ name: string;
245
+ version: string;
246
+ dependencies: Record<string, string>;
247
+ units: string[];
248
+ }
249
+
215
250
  export interface CheckRequest {
216
251
  sources: Source[];
217
252
  schemaVersion?: 3 | 4;
218
253
  machineBits?: 32 | 64;
219
254
  generation?: Partial<Generation>;
220
255
  nativeBindings?: NativeBindings;
256
+ package?: PackageVersion;
257
+ dependencies?: Record<string, string>;
258
+ packages?: Package[];
221
259
  }
222
260
 
223
261
  export interface GenerationRequest extends CheckRequest {
@@ -240,6 +278,9 @@ export interface Result {
240
278
  diagnostics: Diagnostic[];
241
279
  expansions?: string[];
242
280
  files?: Artifact[];
281
+ evidence?: ObligationEvidence[];
282
+ packages?: PackageView[];
283
+ project?: {package?: PackageVersion; dependencies: Record<string, string>;};
243
284
  }
244
285
 
245
286
  export interface PayloadPredicate {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lawspec",
3
- "version": "0.13.2",
3
+ "version": "0.15.0",
4
4
  "description": "State the law once. Check it everywhere.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -8,6 +8,6 @@
8
8
  "bin": { "lawspec": "bin/lawspec.mjs" },
9
9
  "exports": { ".": { "types": "./index.d.ts", "import": "./api.mjs" } },
10
10
  "types": "index.d.ts",
11
- "files": ["*.mjs", "*.json", "index.d.ts", "bin", "core.wasm", "core_jsffi.js", "README.md", "NATIVE-BINDINGS.md", "PRIMITIVES.md", "REFINEMENTS.md", "RUST.md", "JAVA.md", "PYTHON.md", "GO.md", "HASKELL.md", "KOTLIN.md", "WEB.md", "LANGUAGE.md", "API-MIGRATION.md", "RELEASE-0.9.md", "RELEASE-0.10.md", "RELEASE-0.11.md", "RELEASE-0.12.md", "RELEASE-0.13.md", "LICENSE", "starter.lawspec", "examples"],
11
+ "files": ["*.mjs", "*.json", "index.d.ts", "bin", "core.wasm", "core_jsffi.js", "README.md", "NATIVE-BINDINGS.md", "PRIMITIVES.md", "REFINEMENTS.md", "RUST.md", "JAVA.md", "PYTHON.md", "GO.md", "HASKELL.md", "KOTLIN.md", "WEB.md", "LANGUAGE.md", "API-MIGRATION.md", "RELEASE-0.9.md", "RELEASE-0.10.md", "RELEASE-0.11.md", "RELEASE-0.12.md", "RELEASE-0.13.md", "RELEASE-0.14.md", "RELEASE-0.15.md", "LICENSE", "starter.lawspec", "examples"],
12
12
  "scripts": { "test": "node --test test/*.test.mjs" }
13
13
  }