Skip to content

Commit 6bbb814

Browse files
committed
[ refactor ] Move determination info out of typeapp info
1 parent e8fe347 commit 6bbb814

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

  • src/Deriving/DepTyCheck/Gen/ForOneTypeConRhs

src/Deriving/DepTyCheck/Gen/ForOneTypeConRhs/Impl.idr

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ record TypeApp (0 con : Con) where
4848
argHeadType : TypeInfo
4949
{auto 0 argHeadTypeGood : AllTyArgsNamed argHeadType}
5050
argApps : Vect argHeadType.args.length .| Either (Fin con.args.length) TTImp
51-
determ : Determination con
5251

53-
getTypeApps : Elaboration m => NamesInfoInTypes => (con : Con) -> m $ Vect con.args.length $ TypeApp con
52+
getTypeApps : Elaboration m => NamesInfoInTypes => (con : Con) -> m $ Vect con.args.length (TypeApp con, Determination con)
5453
getTypeApps con = do
5554
let conArgIdxs = SortedMap.fromList $ mapI con.args $ \idx, arg => (argName' arg, idx)
5655

5756
-- Analyse that we can do subgeneration for each constructor argument
5857
-- Fails using `Elaboration` if the given expression is not an application to a type constructor
59-
let analyseTypeApp : TTImp -> m $ TypeApp con
58+
let analyseTypeApp : TTImp -> m (TypeApp con, Determination con)
6059
analyseTypeApp expr = do
6160
let (lhs, args) = unAppAny expr
6261
ty <- case lhs of
@@ -80,7 +79,7 @@ getTypeApps con = do
8079
let strongDeterminationWeight = concatMap @{Additive} (max 1 . length) strongDetermination -- we add 1 for constant givens
8180
let stronglyDeterminedBy = fromList $ join strongDetermination
8281
let argsDependsOn = fromList (lefts as.asList) `difference` stronglyDeterminedBy
83-
pure $ MkTypeApp ty as $ MkDetermination stronglyDeterminedBy argsDependsOn $ argsDependsOn.size + strongDeterminationWeight
82+
pure (MkTypeApp ty as, MkDetermination stronglyDeterminedBy argsDependsOn $ argsDependsOn.size + strongDeterminationWeight)
8483

8584
for con.args.asVect $ analyseTypeApp . type
8685

@@ -229,7 +228,7 @@ export
229228
-------------------------------------------------------------
230229

231230
-- Compute left-to-right need of generation when there are non-trivial types at the left
232-
argsTypeApps <- getTypeApps con
231+
(argsTypeApps, argsDeterms) <- unzip <$> getTypeApps con
233232

234233
-- Decide how constructor arguments would be named during generation
235234
let bindNames = argName' <$> fromList con.args
@@ -252,7 +251,7 @@ export
252251
genForOrder order = map (foldr apply callCons) $ evalStateT givs $ for order $ \genedArg => do
253252

254253
-- Get info for the `genedArg`
255-
let MkTypeApp typeOfGened argsOfTypeOfGened _ = index genedArg $ the (Vect _ $ TypeApp con) argsTypeApps
254+
let MkTypeApp typeOfGened argsOfTypeOfGened = index genedArg $ the (Vect _ $ TypeApp con) argsTypeApps
256255

257256
-- Acquire the set of arguments that are already present
258257
presentArguments <- get
@@ -308,7 +307,7 @@ export
308307
--------------------------------------------
309308
310309
-- Compute determination map without weak determination information
311-
let determ = insertFrom' empty $ mapI (\i, ta => (i, ta.determ)) argsTypeApps
310+
let determ = insertFrom' empty $ withIndex argsDeterms
312311

313312
logPoint Debug "deptycheck.derive.least-effort" [sig, con] "- determ: \{determ}"
314313
logPoint Debug "deptycheck.derive.least-effort" [sig, con] "- givs: \{givs}"

0 commit comments

Comments
 (0)