lawspec 0.25.0 → 0.26.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/CHANGELOG.md +43 -1
- package/README.md +5 -4
- package/api.mjs +0 -8
- package/bin/lawspec.mjs +14 -52
- package/build.json +77 -105
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/examples/native-payments/clojure/lawspec.json +1 -1
- package/examples/native-payments/csharp/lawspec.json +1 -1
- package/examples/native-payments/elixir/lawspec.json +1 -1
- package/examples/native-payments/erlang/lawspec.json +1 -1
- package/examples/native-payments/fsharp/lawspec.json +1 -1
- package/examples/native-payments/gleam/lawspec.json +1 -1
- package/examples/native-payments/go/lawspec.json +1 -1
- package/examples/native-payments/groovy/lawspec.json +1 -1
- package/examples/native-payments/haskell/lawspec.json +1 -1
- package/examples/native-payments/java/lawspec.json +1 -1
- package/examples/native-payments/javascript/lawspec.json +1 -1
- package/examples/native-payments/kotlin/lawspec.json +1 -1
- package/examples/native-payments/python/lawspec.json +1 -1
- package/examples/native-payments/rust/lawspec.json +1 -1
- package/examples/native-payments/scala/lawspec.json +1 -1
- package/examples/native-payments/swift/lawspec.json +1 -1
- package/examples/native-payments/typescript/lawspec.json +1 -1
- package/examples/packages/orders/lawspec.json +1 -1
- package/examples/packages/orders/orders.lawspec +27 -25
- package/examples/packages/shop-domain/src/domain.lawspec +15 -14
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +1 -0
- package/examples/rc1/authorization-snapshots.lawspec +24 -23
- package/examples/rc1/banner-filenames.lawspec +7 -6
- package/examples/rc1/bit-codec.lawspec +12 -11
- package/examples/rc1/bounded-witness-search.lawspec +52 -45
- package/examples/rc1/conflicting-requirements.lawspec +8 -7
- package/examples/rc1/constructive-witnesses.lawspec +40 -33
- package/examples/rc1/documentary-review.lawspec +9 -8
- package/examples/rc1/empty-domains.lawspec +16 -15
- package/examples/rc1/finite-integer-domains.lawspec +24 -23
- package/examples/rc1/law-metadata.lawspec +6 -5
- package/examples/rc1/native-payments.lawspec +17 -16
- package/examples/rc1/nesting/rrr.lawspec +4 -3
- package/examples/rc1/nesting/rru.lawspec +7 -6
- package/examples/rc1/nesting/rur.lawspec +7 -6
- package/examples/rc1/nesting/ruu.lawspec +10 -9
- package/examples/rc1/nesting/urr.lawspec +7 -6
- package/examples/rc1/nesting/uru.lawspec +10 -9
- package/examples/rc1/nesting/uur.lawspec +10 -9
- package/examples/rc1/nesting/uuu.lawspec +13 -12
- package/examples/rc1/order-workflow.lawspec +18 -17
- package/examples/rc1/parcel-measurements.lawspec +14 -13
- package/examples/rc1/picture-records.lawspec +6 -5
- package/examples/rc1/picture-tuples.lawspec +6 -5
- package/examples/rc1/record-payloads.lawspec +12 -11
- package/examples/rc1/recursive-records.lawspec +11 -10
- package/examples/rc1/refund-conformance.lawspec +7 -6
- package/examples/rc1/refund-policy.lawspec +15 -14
- package/examples/rc1/requirement-composition.lawspec +26 -25
- package/examples/rc1/structural-records.lawspec +13 -12
- package/examples/rc1-authoring.lawspec +6 -5
- package/examples/specs/abilities.lawspec +67 -65
- package/examples/specs/ability_imports.lawspec +58 -57
- package/examples/specs/actors.lawspec +23 -22
- package/examples/specs/algebra.lawspec +142 -141
- package/examples/specs/approvals.lawspec +16 -15
- package/examples/specs/async_bindings.lawspec +10 -9
- package/examples/specs/async_fetch.lawspec +12 -11
- package/examples/specs/atoi_codec.lawspec +16 -15
- package/examples/specs/boolean_flags.lawspec +10 -9
- package/examples/specs/builtins.lawspec +73 -72
- package/examples/specs/canonical_url.lawspec +14 -13
- package/examples/specs/collections.lawspec +153 -154
- package/examples/specs/composition.lawspec +70 -66
- package/examples/specs/concurrent_collections.lawspec +8 -7
- package/examples/specs/consistency.lawspec +4 -3
- package/examples/specs/contracts.lawspec +80 -79
- package/examples/specs/crypto.lawspec +26 -25
- package/examples/specs/ctc.lawspec +148 -0
- package/examples/specs/currying.lawspec +32 -31
- package/examples/specs/data_types.lawspec +50 -49
- package/examples/specs/distribution.lawspec +57 -56
- package/examples/specs/domain_modeling.lawspec +48 -47
- package/examples/specs/durations.lawspec +39 -38
- package/examples/specs/equivalent.lawspec +25 -24
- package/examples/specs/failures.lawspec +64 -63
- package/examples/specs/finite_data.lawspec +32 -31
- package/examples/specs/flow_stack.lawspec +64 -63
- package/examples/specs/gadt_expressions.lawspec +50 -49
- package/examples/specs/generation.lawspec +115 -114
- package/examples/specs/handler_bindings.lawspec +42 -40
- package/examples/specs/handles.lawspec +2 -1
- package/examples/specs/harness.lawspec +45 -43
- package/examples/specs/harness_testing.lawspec +18 -13
- package/examples/specs/indexed_arithmetic.lawspec +401 -126
- package/examples/specs/indexed_families.lawspec +182 -66
- package/examples/specs/keywords.lawspec +22 -21
- package/examples/specs/limits.lawspec +6 -5
- package/examples/specs/list_contracts.lawspec +121 -120
- package/examples/specs/list_refinements.lawspec +43 -42
- package/examples/specs/lists.lawspec +45 -44
- package/examples/specs/matchers.lawspec +79 -78
- package/examples/specs/matching.lawspec +43 -42
- package/examples/specs/mixed_inputs.lawspec +25 -24
- package/examples/specs/models.lawspec +44 -43
- package/examples/specs/parse_port.lawspec +28 -27
- package/examples/specs/payments.lawspec +55 -54
- package/examples/specs/railway.lawspec +59 -58
- package/examples/specs/records.lawspec +149 -148
- package/examples/specs/records_inner.lawspec +5 -4
- package/examples/specs/recursive_refinements.lawspec +30 -29
- package/examples/specs/refined_definitions.lawspec +24 -23
- package/examples/specs/refinements.lawspec +58 -57
- package/examples/specs/resilience.lawspec +159 -158
- package/examples/specs/resources.lawspec +61 -60
- package/examples/specs/scalar_adapters.lawspec +60 -59
- package/examples/specs/scalar_catalog.lawspec +165 -164
- package/examples/specs/scalars.lawspec +78 -77
- package/examples/specs/scheduling_order.lawspec +8 -7
- package/examples/specs/scheduling_overlap.lawspec +5 -4
- package/examples/specs/sequences.lawspec +66 -65
- package/examples/specs/sessions.lawspec +13 -12
- package/examples/specs/slug.lawspec +16 -15
- package/examples/specs/sum_refinements.lawspec +42 -41
- package/examples/specs/tables.lawspec +29 -28
- package/examples/specs/total_functions.lawspec +71 -70
- package/examples/specs/workflows.lawspec +101 -100
- package/examples-command.mjs +4 -6
- package/explain.mjs +6 -4
- package/expression-presentation.mjs +8 -8
- package/files.mjs +1 -1
- package/index.d.ts +4 -527
- package/launcher.mjs +9 -2
- package/lsp.mjs +10 -6
- package/native-examples.mjs +2 -2
- package/package.json +1 -1
- package/starter-rc1.lawspec +6 -5
- package/starter.lawspec +16 -15
- package/templates.mjs +4 -2
- package/migrate.mjs +0 -135
- package/migration-bindings.mjs +0 -86
- package/migration-cases.mjs +0 -45
- package/migration-collections.mjs +0 -54
- package/migration-correspondence.mjs +0 -275
- package/migration-generation.mjs +0 -99
- package/migration-laws.mjs +0 -102
- package/migration-records.mjs +0 -166
- package/migration-source.mjs +0 -247
- package/migration-write.mjs +0 -156
package/starter.lawspec
CHANGED
|
@@ -3,33 +3,34 @@ unit example.atoi_codec
|
|
|
3
3
|
itoa :: Int32 -> Text
|
|
4
4
|
atoi :: Text -> Int32
|
|
5
5
|
|
|
6
|
-
law
|
|
7
|
-
definition
|
|
8
|
-
|
|
9
|
-
end
|
|
6
|
+
law "|itoa and then atoi yields a| is
|
|
7
|
+
definition :
|
|
8
|
+
apply law "|round trip identity is preserved| itoa atoi
|
|
9
|
+
end definition
|
|
10
10
|
|
|
11
|
-
description
|
|
11
|
+
description :
|
|
12
12
|
"converting an Int32 to Text with {itoa} and then back with {atoi} yields the original Int32"
|
|
13
|
-
end
|
|
13
|
+
end description
|
|
14
14
|
|
|
15
|
-
rationale
|
|
15
|
+
rationale :
|
|
16
16
|
"representing an Int32 as Text must not change its value"
|
|
17
|
-
end
|
|
17
|
+
end rationale
|
|
18
18
|
|
|
19
|
-
example
|
|
19
|
+
example "|negative integers use a minus sign and round-trip unchanged| :
|
|
20
20
|
x = -42
|
|
21
21
|
expect itoa x = "-42"
|
|
22
22
|
expect atoi (itoa x) = -42
|
|
23
|
-
end
|
|
23
|
+
end example
|
|
24
24
|
|
|
25
|
-
example
|
|
25
|
+
example "|zero renders as 0 and round-trips unchanged| :
|
|
26
26
|
x = 0
|
|
27
27
|
expect itoa x = "0"
|
|
28
28
|
expect atoi (itoa x) = 0
|
|
29
|
-
end
|
|
29
|
+
end example
|
|
30
30
|
|
|
31
|
-
references
|
|
31
|
+
references :
|
|
32
32
|
"left inverse"
|
|
33
33
|
"round-trip property"
|
|
34
|
-
end
|
|
35
|
-
end
|
|
34
|
+
end references
|
|
35
|
+
end law
|
|
36
|
+
end unit
|
package/templates.mjs
CHANGED
|
@@ -178,22 +178,24 @@ const scaffolds = {
|
|
|
178
178
|
"haskell": {
|
|
179
179
|
"readable": {
|
|
180
180
|
"stack.yaml": "snapshot: lts-24.58\npackages: [.]\n",
|
|
181
|
-
"package.yaml": "name: lawspec-example\nversion: 0.1.0\ndependencies: [base, text, bytestring, containers, network, directory, time]\nlibrary:\n source-dirs: src\ntests:\n laws:\n main: Spec.hs\n source-dirs: test\n dependencies: [lawspec-example, hspec, hedgehog, hspec-hedgehog, containers, mtl]\n ghc-options: [-threaded, -rtsopts, \"-with-rtsopts=-N\"]\n build-tools: [hspec-discover]\n",
|
|
181
|
+
"package.yaml": "name: lawspec-example\nversion: 0.1.0\ndependencies: [base, text, bytestring, containers, network, directory, time]\nlibrary:\n source-dirs: src\ntests:\n laws:\n main: Spec.hs\n source-dirs: test\n dependencies: [lawspec-example, hspec, hedgehog, hspec-hedgehog, containers, mtl]\n ghc-options: [-O0, -threaded, -rtsopts, \"-with-rtsopts=-N\"]\n build-tools: [hspec-discover]\n",
|
|
182
182
|
"test/Spec.hs": "{-# OPTIONS_GHC -F -pgmF hspec-discover #-}\n"
|
|
183
183
|
},
|
|
184
184
|
"compact": {
|
|
185
185
|
"stack.yaml": "snapshot: lts-24.58\npackages: [.]\n",
|
|
186
|
-
"package.yaml": "name: lawspec-example\nversion: 0.1.0\ndependencies: [base, text, bytestring, containers, network, directory, time]\nlibrary:\n source-dirs: src\ntests:\n laws:\n main: Spec.hs\n source-dirs: test\n dependencies: [lawspec-example, hspec, hedgehog, hspec-hedgehog, containers, mtl]\n ghc-options: [-threaded, -rtsopts, \"-with-rtsopts=-N\"]\n build-tools: [hspec-discover]\n",
|
|
186
|
+
"package.yaml": "name: lawspec-example\nversion: 0.1.0\ndependencies: [base, text, bytestring, containers, network, directory, time]\nlibrary:\n source-dirs: src\ntests:\n laws:\n main: Spec.hs\n source-dirs: test\n dependencies: [lawspec-example, hspec, hedgehog, hspec-hedgehog, containers, mtl]\n ghc-options: [-O0, -threaded, -rtsopts, \"-with-rtsopts=-N\"]\n build-tools: [hspec-discover]\n",
|
|
187
187
|
"test/Spec.hs": "{-# OPTIONS_GHC -F -pgmF hspec-discover #-}\n"
|
|
188
188
|
}
|
|
189
189
|
},
|
|
190
190
|
"kotlin": {
|
|
191
191
|
"readable": {
|
|
192
192
|
"settings.gradle.kts": "rootProject.name = \"lawspec-example\"\n",
|
|
193
|
+
"gradle.properties": "kotlin.daemon.jvmargs=-Xmx2g\n",
|
|
193
194
|
"build.gradle.kts": "plugins {\n kotlin(\"jvm\") version \"2.3.21\"\n}\n\nrepositories {\n mavenCentral()\n}\n\nkotlin {\n jvmToolchain(25)\n}\n\ndependencies {\n implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0\")\n testImplementation(\"io.kotest:kotest-runner-junit5:5.9.1\")\n testImplementation(\"io.kotest:kotest-assertions-core:5.9.1\")\n testImplementation(\"io.kotest:kotest-property:5.9.1\")\n}\n\ntasks.test {\n useJUnitPlatform()\n}\n"
|
|
194
195
|
},
|
|
195
196
|
"compact": {
|
|
196
197
|
"settings.gradle.kts": "rootProject.name = \"lawspec-example\"\n",
|
|
198
|
+
"gradle.properties": "kotlin.daemon.jvmargs=-Xmx2g\n",
|
|
197
199
|
"build.gradle.kts": "plugins { kotlin(\"jvm\") version \"2.3.21\" }\nrepositories { mavenCentral() }\nkotlin { jvmToolchain(25) }\ndependencies { implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0\"); testImplementation(\"io.kotest:kotest-runner-junit5:5.9.1\"); testImplementation(\"io.kotest:kotest-assertions-core:5.9.1\"); testImplementation(\"io.kotest:kotest-property:5.9.1\") }\ntasks.test { useJUnitPlatform() }\n"
|
|
198
200
|
}
|
|
199
201
|
},
|
package/migrate.mjs
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// Generated from templates/npm/migrate.mjs by lawspec-dev generate. Do not edit.
|
|
2
|
-
// Migration starts from the typed legacy baseline. A report is not permission
|
|
3
|
-
// to write an unvalidated transformation or silently alter native payload APIs.
|
|
4
|
-
import {planLegacySourceEdits} from './migration-laws.mjs';
|
|
5
|
-
import {compareMigrationSnapshots} from './migration-correspondence.mjs';
|
|
6
|
-
import {planNativeBindings} from './migration-bindings.mjs';
|
|
7
|
-
import {planMigrationGeneration} from './migration-generation.mjs';
|
|
8
|
-
|
|
9
|
-
export const legacyLawLayers = ['proof', 'exhaustive', 'property', 'examples', 'runtime', 'model'];
|
|
10
|
-
export async function migrationReport(compiler, config, input) {
|
|
11
|
-
if(config?.version!==1||!Array.isArray(config.targets))return {from:'0.24',to:'1.0-rc.1',validated:false,
|
|
12
|
-
diagnostics:[{code:'migration-configuration',message:'Migration requires a version 1 configuration with a targets array.',at:null}]};
|
|
13
|
-
const {nativeBindings:inputBindings,...sourceInput}=input;
|
|
14
|
-
const legacyInput={...sourceInput,schemaVersion:5,languageProfile:'1.0-rc.1',from:'0.24'};
|
|
15
|
-
const baseline = await compiler.migrationBaseline({...legacyInput,verification:{layers:[...legacyLawLayers]}});
|
|
16
|
-
if (baseline.diagnostics?.length) return { from: '0.24', to: '1.0-rc.1', validated: false, diagnostics: baseline.diagnostics };
|
|
17
|
-
if (!Array.isArray(baseline.sourceSyntax)) throw new Error('The compiler did not return the checked source syntax inventory');
|
|
18
|
-
const packageInputs = input.packages ?? [];
|
|
19
|
-
const allSources = [...input.sources, ...packageInputs.flatMap(pkg => pkg.sources)];
|
|
20
|
-
const files = new Set(allSources.map(source => source.path));
|
|
21
|
-
const owned = origin => origin?.kind === 'source' && files.has(origin.span.start.file);
|
|
22
|
-
const declarations = baseline.units.flatMap(unit => unit.declarations.filter(d => owned(d.origin)).map(d => ({ unit: unit.id, ...d })));
|
|
23
|
-
const definitions = baseline.definitions.filter(d => declarations.some(declaration => declaration.id === d.id));
|
|
24
|
-
const laws = baseline.laws.filter(law => files.has(law.location.file));
|
|
25
|
-
const types = baseline.dataTypes.filter(d => owned(d.origin));
|
|
26
|
-
const payloads = types.flatMap(type => type.constructors.filter(c => c.fields.length).map(constructor => ({
|
|
27
|
-
type: type.id, constructor: constructor.id, fields: constructor.fields,
|
|
28
|
-
change: type.constructors.length===1 && constructor.name===type.name
|
|
29
|
-
? 'declare explicit nominal record syntax and preserve its constructor field binding'
|
|
30
|
-
: constructor.fields.length > 1 ? 'group fields into one explicit record payload and reconcile its native field binding' : 'declare an explicit typed payload and reconcile its native field binding',
|
|
31
|
-
})));
|
|
32
|
-
let sourcePreview;
|
|
33
|
-
try {
|
|
34
|
-
if(files.size !== allSources.length) throw new Error('Project and package source paths must be unique.');
|
|
35
|
-
const edited = planLegacySourceEdits(allSources,baseline,baseline.sourceSyntax,baseline.sourceFields);
|
|
36
|
-
const edits = new Map(edited.map(source => [source.path,source]));
|
|
37
|
-
sourcePreview = {scope:'checked computations, nominal records and alternative payloads, ordered collection names, unsigned integers, cases, laws, explicit universal scopes and expectation-first tables',
|
|
38
|
-
sources:input.sources.map(source => edits.get(source.path)),
|
|
39
|
-
packages:packageInputs.map(pkg => ({...pkg,sources:pkg.sources.map(source => edits.get(source.path))})),diagnostics:[]};
|
|
40
|
-
} catch (error) {
|
|
41
|
-
sourcePreview = {scope:'checked computations, nominal records and alternative payloads, ordered collection names, unsigned integers, cases, laws, explicit universal scopes and expectation-first tables',sources:[],
|
|
42
|
-
diagnostics:[{code:'migration-source',message:error.message,at:null}]};
|
|
43
|
-
}
|
|
44
|
-
const migratedSources=sourcePreview.sources.map(({path,content})=>({path,content}));
|
|
45
|
-
const migratedPackages=(sourcePreview.packages??[]).map(pkg=>({...pkg,
|
|
46
|
-
sources:pkg.sources.map(({path,content})=>({path,content}))}));
|
|
47
|
-
const migratedContext=packageInputs.length?{packages:migratedPackages}:{};
|
|
48
|
-
if (!sourcePreview.diagnostics.length) {
|
|
49
|
-
const checked = await compiler.check({...sourceInput,...migratedContext,schemaVersion:5,languageProfile:'1.0-rc.1',verification:{layers:[]},migrationSnapshot:true,
|
|
50
|
-
sources:migratedSources});
|
|
51
|
-
sourcePreview.canonicalCheck = {status:checked.diagnostics.length?'rejected':'accepted',diagnostics:checked.diagnostics,
|
|
52
|
-
intrinsicDefinitionChecks:checked.verification?.intrinsicDefinitionChecks===true,
|
|
53
|
-
lawVerification:'no-selected-checks',coreSnapshot:checked.migrationSemantics??{status:'unavailable',reason:'The compiler did not return a Core migration snapshot.'}};
|
|
54
|
-
} else sourcePreview.canonicalCheck = {status:'unavailable',diagnostics:sourcePreview.diagnostics};
|
|
55
|
-
let payloadComparison={status:'unavailable',reason:'The canonical preview or compiler-side payload comparison is unavailable.'};
|
|
56
|
-
if(sourcePreview.canonicalCheck.status==='accepted'&&typeof compiler.migrationComparison==='function') {
|
|
57
|
-
const compared=await compiler.migrationComparison({...sourceInput,schemaVersion:5,languageProfile:'1.0-rc.1',from:'0.24',verification:{layers:[]},
|
|
58
|
-
migrated:{...sourceInput,...migratedContext,schemaVersion:5,languageProfile:'1.0-rc.1',verification:{layers:[]},
|
|
59
|
-
sources:migratedSources}});
|
|
60
|
-
payloadComparison=compared.migrationComparison??{status:'unavailable',
|
|
61
|
-
reason:'The compiler did not admit both inputs for payload comparison.',diagnostics:compared.diagnostics};
|
|
62
|
-
}
|
|
63
|
-
const correspondence={...compareMigrationSnapshots(baseline.migrationSemantics,sourcePreview.canonicalCheck?.coreSnapshot,
|
|
64
|
-
payloadComparison.executableTransport,payloadComparison.definitionTemplates,payloadComparison.lawTemplates,payloadComparison.sourceUnits),
|
|
65
|
-
payloads:payloadComparison};
|
|
66
|
-
const bindingPreview=sourcePreview.canonicalCheck.status==='accepted' ?
|
|
67
|
-
await planNativeBindings(compiler,config,input,migratedSources,
|
|
68
|
-
baseline.migrationSemantics,sourcePreview.canonicalCheck.coreSnapshot,migratedContext) :
|
|
69
|
-
{status:'not-established',scope:'explicit native binding configuration',
|
|
70
|
-
configurationCount:config.targets.length+(input.nativeBindings!==undefined?1:0),targets:[],
|
|
71
|
-
proposedTargets:config.targets,reason:'Native binding planning requires an admitted canonical source preview.'};
|
|
72
|
-
correspondence.nativeBindings={status:bindingPreview.status,scope:bindingPreview.scope,
|
|
73
|
-
configurationCount:bindingPreview.configurationCount};
|
|
74
|
-
const generationPreview=await planMigrationGeneration(compiler,config,{...input,generation:baseline.generation},
|
|
75
|
-
migratedSources,baseline.migrationSemantics,
|
|
76
|
-
sourcePreview.canonicalCheck.coreSnapshot,bindingPreview,migratedContext);
|
|
77
|
-
correspondence.targetGeneration={status:generationPreview.status,scope:generationPreview.scope,
|
|
78
|
-
configurationCount:generationPreview.configurationCount};
|
|
79
|
-
correspondence.nativeBoundary=generationPreview.nativeBoundary;
|
|
80
|
-
const pending=[
|
|
81
|
-
['program','Complete checked Core correspondence has not been established.'],
|
|
82
|
-
['definitionPlane','Checked definition and contract correspondence has not been established.'],
|
|
83
|
-
['lawBodies','Complete policy-erased Core correspondence has not been established.'],
|
|
84
|
-
['sourceTemplates','Complete checked source-template correspondence has not been established.'],
|
|
85
|
-
['nativeBindings','Native constructor, field and representation bindings require project-wide correspondence.'],
|
|
86
|
-
];
|
|
87
|
-
const domainPending=correspondence.domainPolicies.status!=='matched'||
|
|
88
|
-
correspondence.sourceTemplates.domainPolicies?.status!=='matched';
|
|
89
|
-
const sourceMatched=sourcePreview.canonicalCheck.status==='accepted'&&
|
|
90
|
-
sourcePreview.canonicalCheck.intrinsicDefinitionChecks===true&&sourcePreview.diagnostics.length===0&&
|
|
91
|
-
!domainPending&&pending.every(([name])=>correspondence[name].status==='matched');
|
|
92
|
-
const count=generationPreview.configurationCount;
|
|
93
|
-
const targetsMatched=count===0 ? generationPreview.status==='not-requested'&&
|
|
94
|
-
generationPreview.nativeBoundary.status==='not-requested'&&generationPreview.targets.length===0 :
|
|
95
|
-
generationPreview.status==='accepted'&&generationPreview.nativeBoundary.status==='matched'&&
|
|
96
|
-
generationPreview.targets.length===count&&generationPreview.targets.every(row=>row.status==='accepted'&&
|
|
97
|
-
row.nativeBoundary.status==='matched');
|
|
98
|
-
const validated=sourceMatched&&targetsMatched&&bindingPreview.configurationCount===count;
|
|
99
|
-
const assumptions=['existing compiler validation, transport and target emitters',
|
|
100
|
-
'unchanged native implementations under their original binding assumptions'];
|
|
101
|
-
correspondence.generatedBehavior={status:count===0?'not-requested':validated?
|
|
102
|
-
'matched-under-existing-assumptions':'not-established',
|
|
103
|
-
scope:'preservation of checked source semantics and configured native interfaces; no native execution',
|
|
104
|
-
assumptions,nativeExecution:'not-performed',nativeConformance:'not-established',
|
|
105
|
-
lawVerification:'not-established-by-migration'};
|
|
106
|
-
correspondence.status=validated?'matched-under-existing-assumptions':'not-established';
|
|
107
|
-
correspondence.scope='complete checked source migration and configured target interfaces';
|
|
108
|
-
return {
|
|
109
|
-
from: '0.24', to: '1.0-rc.1', validated, diagnostics: [],
|
|
110
|
-
validation:{status:validated?'validated-under-existing-assumptions':'not-established',
|
|
111
|
-
scope:'all supplied project sources, configuration and configured targets',assumptions,
|
|
112
|
-
nativeConformance:'not-established',lawVerification:'not-established-by-migration'},
|
|
113
|
-
proposedConfiguration: { ...config, targets:bindingPreview.proposedTargets, version: 2, languageProfile: '1.0-rc.1', verification: { layers: [...legacyLawLayers] } },
|
|
114
|
-
baseline: { declarations, definitions, laws, types, obligations: baseline.evidence, sourceSyntax:baseline.sourceSyntax,sourceFields:baseline.sourceFields,
|
|
115
|
-
coreSnapshot:baseline.migrationSemantics??{status:'unavailable',reason:'The compiler did not return a Core migration snapshot.'} },
|
|
116
|
-
sourcePreview,
|
|
117
|
-
correspondence,
|
|
118
|
-
domainPolicyChanges: laws.map(law => ({law:law.id,from:law.inputDomain,to:'universal',
|
|
119
|
-
requirement:'Preserve domain correspondence, including empty and dependent domains, when validating this migration.'})),
|
|
120
|
-
constructorChanges: payloads,
|
|
121
|
-
nativeBindings: config.targets.map(target => ({ target: target.language, bindings: target.nativeBindings ?? null })),
|
|
122
|
-
bindingPreview,
|
|
123
|
-
generationPreview,
|
|
124
|
-
blockers: [...pending.filter(([name])=>correspondence[name].status!=='matched').map(([,reason])=>reason),
|
|
125
|
-
...bindingPreview.targets.filter(target=>target.status!=='matched').map(target=>'Native bindings for '+(target.target||'input')+': '+target.reason),
|
|
126
|
-
...generationPreview.targets.filter(target=>target.status!=='accepted').map(target=>'Target generation for '+(target.target||'input')+': '+target.reason),
|
|
127
|
-
...generationPreview.targets.filter(target=>target.status==='accepted'&&target.nativeBoundary.status!=='matched')
|
|
128
|
-
.map(target=>'Native boundary for '+(target.target||'input')+': '+target.nativeBoundary.reason),
|
|
129
|
-
...(domainPending ? ['Legacy nonempty input-domain handling and canonical universal quantification require explicit correspondence checks; no empty-domain equivalence is assumed.'] : []),
|
|
130
|
-
...(sourcePreview.canonicalCheck.status==='rejected' ? ['The partial preview does not yet pass canonical compilation; inspect sourcePreview.canonicalCheck.diagnostics.'] : []),
|
|
131
|
-
...sourcePreview.diagnostics.map(diagnostic => 'Source preview unavailable: ' + diagnostic.message),
|
|
132
|
-
...(!sourcePreview.canonicalCheck.intrinsicDefinitionChecks?['Mandatory definition validation was not established.']:[])],
|
|
133
|
-
filesWritten: [],
|
|
134
|
-
};
|
|
135
|
-
}
|
package/migration-bindings.mjs
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// Generated from templates/npm/migration-bindings.mjs by lawspec-dev generate. Do not edit.
|
|
2
|
-
// Native configuration correspondence is independent of external execution.
|
|
3
|
-
// The compiler owns payload adaptation and native binding resolution.
|
|
4
|
-
import {targets} from './templates.mjs';
|
|
5
|
-
import {createHash} from 'node:crypto';
|
|
6
|
-
|
|
7
|
-
const fingerprints=['programDigest','definitionPlaneDigest','lawBodiesDigest'];
|
|
8
|
-
const templates=['declarationsDigest','definitionTemplatesDigest','lawTemplatesDigest','lawBodiesDigest'];
|
|
9
|
-
const canonical=value=>Array.isArray(value)?value.map(canonical):value&&typeof value==='object'
|
|
10
|
-
?Object.fromEntries(Object.keys(value).sort().map(key=>[key,canonical(value[key])])):value;
|
|
11
|
-
export const bindingDigest=value=>createHash('sha256').update(JSON.stringify(canonical(value))).digest('hex');
|
|
12
|
-
const digest=value=>typeof value==='string'&&/^[0-9a-f]{64}$/.test(value);
|
|
13
|
-
const equal=(a,b)=>{
|
|
14
|
-
if(a===b)return true;
|
|
15
|
-
if(!a||!b||typeof a!=='object'||typeof b!=='object'||Array.isArray(a)!==Array.isArray(b))return false;
|
|
16
|
-
const left=Object.keys(a).sort(),right=Object.keys(b).sort();
|
|
17
|
-
return left.length===right.length&&left.every((key,i)=>key===right[i]&&equal(a[key],b[key]));
|
|
18
|
-
};
|
|
19
|
-
const pending=reason=>({status:'not-established',reason});
|
|
20
|
-
const bindingObligations=rows=>Array.isArray(rows)&&rows.every(row=>row&&typeof row.owner==='string'&&
|
|
21
|
-
typeof row.declaration==='string'&&row.claim===null&&
|
|
22
|
-
(row.stage==='binding' ? row.status==='runtime-checked' :
|
|
23
|
-
['codec','generator','native-function'].includes(row.stage)&&row.status==='assumed'));
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export function checkBindingProposal(before,after,requested,target,evidence) {
|
|
27
|
-
if(evidence?.status==='unavailable'&&typeof evidence.reason==='string')return pending(evidence.reason);
|
|
28
|
-
const unavailable='The compiler did not return a complete binding proposal for these sources, bindings, target and machine width.';
|
|
29
|
-
if(before?.status!=='available'||after?.status!=='available'||before.machineBits!==after.machineBits||
|
|
30
|
-
evidence?.version!==1||evidence.algorithm!=='sha256'||evidence.target!==target||
|
|
31
|
-
evidence.machineBits!==before.machineBits||evidence.originalsUnchanged!==true||
|
|
32
|
-
!equal(evidence.inputBindings,requested??{})||
|
|
33
|
-
!fingerprints.every(field=>digest(before[field])&&digest(after[field])&&
|
|
34
|
-
evidence.before?.[field]===before[field]&&evidence.after?.[field]===after[field])||
|
|
35
|
-
!templates.every(field=>digest(before.sourceTemplates?.[field])&&digest(after.sourceTemplates?.[field])&&
|
|
36
|
-
evidence.sourceTemplates?.before?.[field]===before.sourceTemplates[field]&&
|
|
37
|
-
evidence.sourceTemplates?.after?.[field]===after.sourceTemplates[field])) return pending(unavailable);
|
|
38
|
-
if(evidence.obligations?.status!=='matched'||!bindingObligations(evidence.obligations.before)||
|
|
39
|
-
!equal(evidence.obligations.before,evidence.obligations.after)||
|
|
40
|
-
evidence.status!=='matched'||evidence.beforeValidated!==true||evidence.afterValidated!==true||
|
|
41
|
-
evidence.proposalComplete!==true||evidence.bindings?.status!=='matched'||
|
|
42
|
-
!digest(evidence.originalBindingsDigest)||!digest(evidence.bindings.before)||evidence.bindings.before!==evidence.bindings.after||
|
|
43
|
-
!evidence.proposedNativeBindings||typeof evidence.proposedNativeBindings!=='object'||
|
|
44
|
-
Array.isArray(evidence.proposedNativeBindings)||!Array.isArray(evidence.requirements)||evidence.requirements.length||
|
|
45
|
-
evidence.nativeConformance!=='not-established'||evidence.targetGeneration!=='not-established'||
|
|
46
|
-
evidence.lawVerification!=='not-established-by-binding-correspondence'||
|
|
47
|
-
bindingDigest(evidence.proposedNativeBindings)!==evidence.bindings.after)
|
|
48
|
-
return pending(evidence.requirements?.join(' ')||evidence.reason||'Native binding adaptation remains incomplete.');
|
|
49
|
-
return {status:'matched',basis:'compiler-checked-native-binding-proposal',
|
|
50
|
-
scope:'explicit binding configuration; external behavior and generated APIs remain separate'};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function planNativeBindings(compiler,config,input,sources,before,after,migratedContext={}) {
|
|
54
|
-
const scopes=config.targets.map((target,index)=>({target,index,language:target.language,
|
|
55
|
-
bindings:target.nativeBindings}));
|
|
56
|
-
if(input.nativeBindings!==undefined)
|
|
57
|
-
scopes.push({index:null,language:input.target??'',bindings:input.nativeBindings});
|
|
58
|
-
const rows=[];
|
|
59
|
-
for(const scope of scopes) {
|
|
60
|
-
const {language,bindings,index}=scope;
|
|
61
|
-
if(language&&!targets.includes(language)) {
|
|
62
|
-
rows.push({target:language,index,...pending('Unknown migration target: '+language)});continue;
|
|
63
|
-
}
|
|
64
|
-
if(typeof compiler.migrationBindings!=='function') {
|
|
65
|
-
rows.push({target:language,index,...pending('This compiler does not expose checked native binding migration.')});continue;
|
|
66
|
-
}
|
|
67
|
-
const options={...input,schemaVersion:5,languageProfile:'1.0-rc.1',verification:{layers:[]}};
|
|
68
|
-
const {nativeBindings:ignored,...canonical}=options;
|
|
69
|
-
const result=await compiler.migrationBindings({...options,from:'0.24',target:language,
|
|
70
|
-
nativeBindings:bindings??{},migrated:{...canonical,...migratedContext,sources}});
|
|
71
|
-
const evidence=result.migrationBindings;
|
|
72
|
-
const checked=result.diagnostics?.length ? pending(result.diagnostics.map(item=>item.message).join(' ')) :
|
|
73
|
-
checkBindingProposal(before,after,bindings,language,evidence);
|
|
74
|
-
rows.push({target:language,index,...checked,evidence,
|
|
75
|
-
diagnostics:result.diagnostics??[],...(checked.status==='matched'?{proposedNativeBindings:evidence.proposedNativeBindings}:{})});
|
|
76
|
-
}
|
|
77
|
-
const matched=rows.every(row=>row.status==='matched');
|
|
78
|
-
return {status:matched?'matched':'not-established',
|
|
79
|
-
scope:'every configured explicit native binding request; native execution and generated APIs remain separate',
|
|
80
|
-
configurationCount:rows.length,targets:rows,
|
|
81
|
-
proposedTargets:config.targets.map((target,index)=>{
|
|
82
|
-
const row=rows.find(row=>row.index===index);
|
|
83
|
-
return row?.status==='matched'&&target.nativeBindings!==undefined
|
|
84
|
-
? {...target,nativeBindings:row.proposedNativeBindings}:{...target};
|
|
85
|
-
})};
|
|
86
|
-
}
|
package/migration-cases.mjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// Generated from templates/npm/migration-cases.mjs by lawspec-dev generate. Do not edit.
|
|
2
|
-
// Selection edits use actual case/branch ranges, including nested selections
|
|
3
|
-
// in the selected expression. No contextual identifier is treated as a block.
|
|
4
|
-
export function planLegacyCases(document,nodes) {
|
|
5
|
-
const contains = (outer,inner) => outer.start <= inner.start && inner.end <= outer.end;
|
|
6
|
-
const replace = (token,content,reason) => {
|
|
7
|
-
if (!token) throw new Error('Checked case has no token for '+reason);
|
|
8
|
-
document.edit(token.start,token.end,content,reason);
|
|
9
|
-
};
|
|
10
|
-
const cases = nodes.filter(node=>node.kind==='case');
|
|
11
|
-
for (const selected of cases) {
|
|
12
|
-
const branches = nodes.filter(node=>node.kind==='case-branch' && contains(selected,node) &&
|
|
13
|
-
!cases.some(inner=>inner!==selected && contains(selected,inner) && contains(inner,node)));
|
|
14
|
-
if (!branches.length) throw new Error('Checked case has no source branches');
|
|
15
|
-
const tokens = document.code(selected.start,selected.end);
|
|
16
|
-
const prefix = document.code(selected.start,Math.min(...branches.map(branch=>branch.start)));
|
|
17
|
-
if (tokens[0]?.text!=='match' || prefix.at(-1)?.text!=='with' || tokens.at(-1)?.text!=='end')
|
|
18
|
-
throw new Error('Checked case has no legacy delimiters');
|
|
19
|
-
replace(tokens[0],'first matching case of','case opener');
|
|
20
|
-
replace(prefix.at(-1),':','case delimiter');
|
|
21
|
-
replace(tokens.at(-1),'end case','case closer');
|
|
22
|
-
for (const branch of branches) {
|
|
23
|
-
const tokens = document.code(branch.start,branch.end);
|
|
24
|
-
const arrow = tokens.find(token=>token.text==='->');
|
|
25
|
-
if (tokens[0]?.text!=='|' || !arrow) throw new Error('Checked case branch has no legacy delimiters');
|
|
26
|
-
if (nodes.some(node=>node.kind==='expression.name' && node.name==='it' &&
|
|
27
|
-
node.start>=arrow.end && contains(branch,node)))
|
|
28
|
-
throw new Error('A legacy case branch referring to it needs an explicit rename before introducing scoped it');
|
|
29
|
-
replace(tokens[0],'when','case branch');
|
|
30
|
-
replace(arrow,'then','case branch delimiter');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// Payload-free alternatives keep their parameters and index equations.
|
|
34
|
-
// Their header/closer edits do not establish semantic or native correspondence;
|
|
35
|
-
// the compiler still has to admit and compare both complete inputs.
|
|
36
|
-
for (const type of nodes.filter(node=>node.kind==='declaration.type')) {
|
|
37
|
-
if (nodes.some(node=>node.kind==='constructor-field' && contains(type,node))) continue;
|
|
38
|
-
const tokens = document.code(type.start,type.end);
|
|
39
|
-
const delimiter = tokens.find(token=>token.text==='is');
|
|
40
|
-
if (tokens[0]?.text!=='type' || !delimiter || tokens.at(-1)?.text!=='end')
|
|
41
|
-
throw new Error('Checked alternative type has no legacy delimiters');
|
|
42
|
-
replace(delimiter,'is one of','alternative type delimiter');
|
|
43
|
-
replace(tokens.at(-1),'end type','type closer');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Generated from templates/npm/migration-collections.mjs by lawspec-dev generate. Do not edit.
|
|
2
|
-
// Names are changed only after the existing compiler has resolved their
|
|
3
|
-
// namespace or free-reference identity. Lexical bindings are never guessed.
|
|
4
|
-
const orderedSet='lawspec.collections::type::Set';
|
|
5
|
-
const operations=new Map(['Of','Member','Insert','Remove','Union','Intersection','Difference']
|
|
6
|
-
.map(suffix=>['lawspec.collections::set'+suffix,'sortedSet'+suffix]));
|
|
7
|
-
const numericNames=new Map([['BigUInt','Whole'],['Natural','Whole'],['BigInt','Integer']]);
|
|
8
|
-
|
|
9
|
-
export function planLegacyCollectionNames(document,source) {
|
|
10
|
-
const {nodes,bindings,references}=source;
|
|
11
|
-
if (!Array.isArray(bindings)||!Array.isArray(references))
|
|
12
|
-
throw new Error('Collection migration requires checked namespaces and free references');
|
|
13
|
-
const contains=(outer,inner)=>outer.start<=inner.start&&inner.end<=outer.end;
|
|
14
|
-
const lookup=(namespace,name)=>bindings.find(binding=>binding.namespace===namespace&&binding.name===name);
|
|
15
|
-
const rename=(range,name,replacement,reason)=>{
|
|
16
|
-
const tokens=document.code(range.start,range.end);
|
|
17
|
-
if (tokens.map(token=>token.text).join('')!==name)
|
|
18
|
-
throw new Error('Checked name does not match its original source tokens: '+name);
|
|
19
|
-
const last=tokens.at(-1);
|
|
20
|
-
document.edit(last.start,last.end,replacement,reason);
|
|
21
|
-
};
|
|
22
|
-
for (const node of nodes.filter(node=>node.kind==='type-name')) {
|
|
23
|
-
const refinement=lookup('refinement',node.name);
|
|
24
|
-
const builtinNatural=node.name==='Natural'&&source.builtinNatural&&refinement?.target==='Natural';
|
|
25
|
-
if (numericNames.has(node.name) && !lookup('type',node.name) && (!refinement||builtinNatural))
|
|
26
|
-
rename(node,node.name,numericNames.get(node.name),'exact numeric type name');
|
|
27
|
-
if (lookup('type',node.name)?.target===orderedSet) {
|
|
28
|
-
if (lookup('refinement',node.name)) throw new Error('A collection type and refinement share a source spelling: '+node.name);
|
|
29
|
-
rename(node,node.name,'SortedSet','ordered set type name');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
for (const node of nodes.filter(node=>node.kind==='type-parameter-kind'&&node.name==='Natural'))
|
|
33
|
-
rename(node,node.name,'Whole','zero-inclusive index kind');
|
|
34
|
-
for (const reference of references) {
|
|
35
|
-
const replacement=operations.get(reference.declaration);
|
|
36
|
-
if (!replacement) continue;
|
|
37
|
-
const range=document.range({kind:'source',span:reference.span});
|
|
38
|
-
if (!range) throw new Error('Checked collection reference belongs to another source');
|
|
39
|
-
rename(range,reference.name,replacement,'ordered set operation');
|
|
40
|
-
}
|
|
41
|
-
for (const item of nodes.filter(node=>['import-item','export-item'].includes(node.kind))) {
|
|
42
|
-
if (item.name.startsWith('`')) continue;
|
|
43
|
-
let name=item.name;
|
|
44
|
-
if (item.kind==='import-item') {
|
|
45
|
-
const parent=nodes.find(node=>node.kind==='import'&&contains(node,item));
|
|
46
|
-
const alias=parent&&nodes.find(node=>node.kind==='import-alias'&&node.start===parent.start&&node.end===parent.end);
|
|
47
|
-
if (!alias) throw new Error('Checked import item has no parsed alias');
|
|
48
|
-
name=alias.name+'.'+name;
|
|
49
|
-
}
|
|
50
|
-
const type=lookup('type',name),value=lookup('value',name);
|
|
51
|
-
const replacement=type?.target===orderedSet?'SortedSet':operations.get(value?.declaration);
|
|
52
|
-
if (replacement) rename(item,item.name,replacement,'ordered set import or export');
|
|
53
|
-
}
|
|
54
|
-
}
|