Skip to content

Commit 6fa08d0

Browse files
authored
feat: compile-time deduction, resolve #200 (#202)
* feat: compile-time deduction, resolve #200 * chore: tidy * chore: tidy * style: pass prettier * chore: fallback esnext feature
1 parent 21d24b8 commit 6fa08d0

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

packages/compile/src/validations.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('bundle', () => {
9595
])
9696
})
9797

98-
it.skip('checks for counterexamples', () => {
98+
it('checks for counterexamples', () => {
9999
const { errors } = bundle({
100100
properties: [F.property({ uid: 'P1' }), F.property({ uid: 'P2' })],
101101
spaces: [F.space({ uid: 'S1' })],

packages/compile/src/validations.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { z } from 'zod'
22
import yaml from 'yaml-front-matter'
33

44
import {
5-
Bundle,
6-
Property,
7-
Trait,
5+
type Bundle,
6+
ImplicationIndex,
7+
type Property,
8+
type Space,
9+
deduceTraits,
810
formula as Formula,
911
schemas,
1012
} from '@pi-base/core'
1113

12-
import { File } from './fs.js'
14+
import type { File } from './fs.js'
1315

1416
// FIXME
1517
type CheckResult =
@@ -18,7 +20,24 @@ type CheckResult =
1820
kind: 'contradiction'
1921
contradiction: { theorems: unknown[]; properties: unknown[] }
2022
}
21-
function check(bundle: Bundle, _: unknown): CheckResult {
23+
function check(bundle: Bundle, space: Space): CheckResult {
24+
const implications = new ImplicationIndex(
25+
Array.from(bundle.theorems.values()).map(({ uid, when, then }) => ({
26+
id: uid,
27+
when,
28+
then,
29+
})),
30+
)
31+
const traits = new Map(
32+
Array.from(bundle.traits.values())
33+
.filter(trait => trait.space === space.uid)
34+
.map(trait => [trait.property, trait.value]),
35+
)
36+
37+
const result = deduceTraits(implications, traits)
38+
if (result.kind === 'contradiction') {
39+
return result
40+
}
2241
return { kind: 'bundle', bundle }
2342
}
2443

0 commit comments

Comments
 (0)