Skip to content

Commit

Permalink
[ fixup ] Concentrate on particular highest-priority arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
buzden committed Oct 22, 2024
1 parent d83acdf commit 61b9d79
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Deriving/DepTyCheck/Gen/Core/ConsDerive.idr
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ removeDeeply : Foldable f =>
FinMap con.args.length $ Determination con
removeDeeply toRemove fromWhat = foldl delete' fromWhat toRemove <&> mapDetermination (\s => foldl delete' s toRemove)

record ArgPriority (0 con : Con) where
constructor Pri
givenTyArguments : Nat
targetConArgument : Fin con.args.length

Eq (ArgPriority con) where
Pri gta tca == Pri gta' tca' = gta == gta' && tca == tca'

Ord (ArgPriority con) where
compare (Pri gta tca) (Pri gta' tca') = compare gta gta' <+> compare @{Reverse} tca tca'

propagatePriOnce : Ord p => FinMap con.args.length (Determination con, p) -> FinMap con.args.length (Determination con, p)
propagatePriOnce =
-- propagate back along dependencies
Expand Down Expand Up @@ -125,10 +136,11 @@ Ord PriorityOrigin where

-- compute the priority
-- priority is a count of given arguments, and it propagates back using `max` on strongly determining arguments and on arguments that depend on this
propagatePri' : FinMap con.args.length (Determination con) -> FinMap con.args.length (Determination con, Nat, PriorityOrigin)
propagatePri' : {con : _} -> FinMap con.args.length (Determination con) -> FinMap con.args.length (Determination con, ArgPriority con, PriorityOrigin)
propagatePri' dets = do
let origPri = dets <&> \det => (det,) $ det.typeArgs `minus` det.argsDependsOn.size
map snd origPri `zip` propagatePri origPri <&> \(origPri, det, newPri) => (det, newPri, if origPri == newPri then Original else Propagated)
let origPri = fromList $ kvList dets <&> \(idx, det) => (idx, det,) $ Pri (det.typeArgs `minus` det.argsDependsOn.size) idx
map snd origPri `zip` propagatePri origPri <&>
\(origPri, det, newPri) => (det, newPri, if ((==) `on` givenTyArguments) origPri newPri then Original else Propagated)

searchOrder : {con : _} ->
(determinable : SortedSet $ Fin con.args.length) ->
Expand Down

0 comments on commit 61b9d79

Please sign in to comment.