1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE NoImplicitPrelude #-}
-- | Temporary routing data for the content-addressed migration.
--
-- These values select current physical sources. They are not durable module
-- names and must be deleted with the legacy driver.
module Felix.Migration
( MigrationMountRole(..)
, migrationMountId
, MigrationModuleRef
, migrationModuleRefRole
, migrationModuleRefPath
, MigrationManifestError(..)
, migrationModuleCandidatePath
, ResolvedMigrationSelection
, resolveMigrationSelection
, migrationSelectionContains
, MigrationGraphRoute(..)
, classifyMigrationGraph
, activeMigrationRoots
, protectedMigrationModules
, phase53LibraryMigrationModules
, typedMigrationModules
, PreludeSourceFamily(..)
, finalPreludeSourceFamilies
, PreludePublicRole(..)
, expectedFinalPreludePublicRoles
) where
import Base
import Felix.Parse
import Felix.Source
import Data.List qualified as List
import Data.Set qualified as Set
data MigrationMountRole
= MigrationProject
| MigrationLibrary
| MigrationDebug
deriving stock (Show, Eq, Ord, Enum, Bounded)
migrationMountId :: MigrationMountRole -> SourceMountId
migrationMountId = \case
MigrationProject ->
sourceMountId "project"
MigrationLibrary ->
sourceMountId "library"
MigrationDebug ->
sourceMountId "debug"
data MigrationModuleRef = MigrationModuleRef
!MigrationMountRole
!SafeRelativePath
deriving stock (Show, Eq, Ord)
migrationModuleRefRole
:: MigrationModuleRef
-> MigrationMountRole
migrationModuleRefRole (MigrationModuleRef role _path) =
role
migrationModuleRefPath
:: MigrationModuleRef
-> SafeRelativePath
migrationModuleRefPath (MigrationModuleRef _role path) =
path
data MigrationManifestError
= MissingMigrationMountRole !MigrationMountRole
deriving stock (Show, Eq)
newtype ResolvedMigrationSelection = ResolvedMigrationSelection
(Set (SourceMountId, CanonicalPath, SafeRelativePath))
resolveMigrationSelection
:: Foldable references
=> SourceMounts
-> references MigrationModuleRef
-> Either MigrationManifestError ResolvedMigrationSelection
resolveMigrationSelection mounts references =
ResolvedMigrationSelection . Set.fromList
<$> traverse resolveOne (toList references)
where
resolveOne reference =
case List.find
((== migrationMountId role) . sourceMountIdentifier)
(sourceMountList mounts) of
Nothing ->
Left (MissingMigrationMountRole role)
Just mount ->
Right
( sourceMountIdentifier mount
, sourceMountRoot mount
, migrationModuleRefPath reference
)
where
role = migrationModuleRefRole reference
migrationSelectionContains
:: ResolvedMigrationSelection
-> ResolvedSource
-> Bool
migrationSelectionContains
(ResolvedMigrationSelection selected) source =
( resolvedSourceMount source
, resolvedSourceMountRoot source
, resolvedSourceRelativePath source
) `Set.member` selected
data MigrationGraphRoute
= TypedMigrationGraph
| LegacyMigrationGraph
deriving stock (Show, Eq)
classifyMigrationGraph
:: ResolvedMigrationSelection
-> ParsedSourceWorkspace
-> MigrationGraphRoute
classifyMigrationGraph selected workspace
| all
(migrationSelectionContains selected . parsedModuleResolved)
(parsedWorkspaceModules workspace) =
TypedMigrationGraph
| otherwise =
LegacyMigrationGraph
-- | Resolve one routing reference against the current prepared mount table.
--
-- This deliberately returns a physical candidate path, not a logical owner.
migrationModuleCandidatePath
:: SourceMounts
-> MigrationModuleRef
-> Either MigrationManifestError FilePath
migrationModuleCandidatePath mounts reference =
case List.find matchesRole candidates of
Nothing ->
Left (MissingMigrationMountRole role)
Just candidate ->
Right (sourceCandidatePath candidate)
where
role = migrationModuleRefRole reference
expectedMount = migrationMountId role
candidates =
sourceCandidates
mounts
(migrationModuleRefPath reference)
matchesRole candidate =
sourceCandidateMount candidate == expectedMount
-- | Current supported verification root.
activeMigrationRoots :: NonEmpty MigrationModuleRef
activeMigrationRoots =
migrationLibraryModule "everything.tex" :| []
-- | Dependency-closed set/naturals migration boundary.
protectedMigrationModules :: NonEmpty MigrationModuleRef
protectedMigrationModules =
migrationLibraryModule "set.tex" :|
[ migrationLibraryModule "set/cons.tex"
, migrationLibraryModule "set/regularity.tex"
, migrationLibraryModule "set/suc.tex"
, migrationLibraryModule "nat.tex"
]
-- | Phase 5.3 ordinary library modules admitted by the typed driver.
phase53LibraryMigrationModules :: NonEmpty MigrationModuleRef
phase53LibraryMigrationModules =
migrationLibraryModule "set/symdiff.tex" :|
[ migrationLibraryModule "set/powerset.tex"
, migrationLibraryModule "set/partition.tex"
, migrationLibraryModule "set/bipartition.tex"
, migrationLibraryModule "set/product.tex"
, migrationLibraryModule "set/filter.tex"
, migrationLibraryModule "relation.tex"
, migrationLibraryModule "relation/properties.tex"
, migrationLibraryModule "relation/uniqueness.tex"
, migrationLibraryModule "function.tex"
, migrationLibraryModule "set/cantor.tex"
, migrationLibraryModule "set/fixpoint.tex"
, migrationLibraryModule "set/equinumerosity.tex"
, migrationLibraryModule "order/quasiorder.tex"
, migrationLibraryModule "order/order.tex"
]
-- | Sources whose complete graphs may enter the typed driver.
typedMigrationModules :: NonEmpty MigrationModuleRef
typedMigrationModules =
protectedMigrationModules
<> phase53LibraryMigrationModules
<> (migrationProjectModule "test/phase3/typed-producer.tex" :|
[ migrationProjectModule "test/phase3/typed-unsupported.tex"
, migrationProjectModule "test/phase3/typed-shared-a.tex"
, migrationProjectModule "test/phase3/typed-shared-b.tex"
, migrationProjectModule "test/phase3/typed-shared-root.tex"
, migrationProjectModule "test/phase5/exact-producer.tex"
, migrationProjectModule "test/phase5/exact-importer.tex"
, migrationProjectModule "test/phase5/exact-failure.tex"
, migrationProjectModule "test/phase5/exact-proofs.tex"
, migrationProjectModule "test/phase5/exact-local-definition.tex"
, migrationProjectModule "test/phase5/exact-local-definition-failure.tex"
, migrationProjectModule "test/phase5/exact-local-function.tex"
, migrationProjectModule "test/phase5/exact-local-function-failure.tex"
, migrationProjectModule "test/phase5/exact-contradiction.tex"
, migrationProjectModule "test/phase5/exact-contradiction-goal.tex"
, migrationProjectModule "test/phase5/exact-relation-expression.tex"
, migrationProjectModule "test/phase5/exact-relation-expression-missing-pair.tex"
, migrationProjectModule "test/phase5/exact-application.tex"
, migrationProjectModule "test/phase5/exact-application-missing.tex"
, migrationProjectModule "test/phase5/exact-quantified-subject.tex"
, migrationProjectModule "test/phase5/exact-quantified-subject-nested.tex"
, migrationProjectModule "test/phase5/exact-proof-failure.tex"
, migrationProjectModule "test/phase5/exact-induction-nested.tex"
, migrationProjectModule "test/phase5/exact-runtime-failure.tex"
, migrationProjectModule "test/phase5/exact-source-axiom.tex"
, migrationProjectModule "test/phase5/exact-source-axiom-assumptions.tex"
, migrationProjectModule "test/phase5/exact-omitted.tex"
, migrationProjectModule "test/phase5/exact-escape-producer.tex"
, migrationProjectModule "test/phase5/exact-escape-consumer.tex"
, migrationProjectModule "test/phase5/exact-separation.tex"
, migrationProjectModule "test/phase5/exact-replacement.tex"
, migrationProjectModule "test/phase5/exact-finite-set.tex"
, migrationProjectModule "test/phase5/exact-datatype.tex"
, migrationProjectModule "test/phase5/exact-datatype-nested.tex"
, migrationProjectModule "test/phase5/exact-inductive.tex"
, migrationProjectModule "test/phase5/exact-inductive-recursive.tex"
, migrationProjectModule "test/phase5/exact-inductive-nested.tex"
, migrationProjectModule "test/phase5/unmatched-proof.tex"
])
-- | Source constructs required by the non-authoritative prelude skeleton.
data PreludeSourceFamily
= PreludeDefinition
| PreludeAbbreviation
| PreludeProposition
| PreludeProof
deriving stock (Show, Eq, Ord, Enum, Bounded)
finalPreludeSourceFamilies :: Set PreludeSourceFamily
finalPreludeSourceFamilies =
Set.fromList
[ PreludeDefinition
, PreludeAbbreviation
, PreludeProposition
, PreludeProof
]
-- | Stable public roles required at final-prelude cutover.
--
-- Helper declarations used to derive these roles are intentionally not
-- frozen by Phase 0.
data PreludePublicRole
= PreludeInfinityTheorem
| PreludeOmegaObject
| PreludeOmegaDefiningEquation
| PreludeNaturalsAlias
| PreludeNaturalsInductiveTheorem
| PreludeNaturalsMinimalTheorem
deriving stock (Show, Eq, Ord, Enum, Bounded)
expectedFinalPreludePublicRoles :: Set PreludePublicRole
expectedFinalPreludePublicRoles =
Set.fromList [minBound .. maxBound]
migrationLibraryModule :: FilePath -> MigrationModuleRef
migrationLibraryModule =
MigrationModuleRef MigrationLibrary . checkedRelativePath
migrationProjectModule :: FilePath -> MigrationModuleRef
migrationProjectModule =
MigrationModuleRef MigrationProject . checkedRelativePath
checkedRelativePath :: FilePath -> SafeRelativePath
checkedRelativePath path =
case safeRelativePath path of
Left err ->
impossible
("invalid migration path literal "
<> show path
<> ": "
<> show err)
Right relative ->
relative
|