From f6e3603b476d8317be63b723c90827790031dd6c Mon Sep 17 00:00:00 2001 From: Denis Buzdalov Date: Wed, 25 Sep 2024 20:46:03 +0300 Subject: [PATCH] [ experim ] Lightweight way of computing dependees --- src/Deriving/DepTyCheck/Gen/Core/ConsDerive.idr | 2 +- src/Deriving/DepTyCheck/Util/Reflection.idr | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Deriving/DepTyCheck/Gen/Core/ConsDerive.idr b/src/Deriving/DepTyCheck/Gen/Core/ConsDerive.idr index 2f660050..88e837b8 100644 --- a/src/Deriving/DepTyCheck/Gen/Core/ConsDerive.idr +++ b/src/Deriving/DepTyCheck/Gen/Core/ConsDerive.idr @@ -133,7 +133,7 @@ namespace NonObligatoryExts argsTypeApps <- getTypeApps con -- Get arguments which any other argument depends on - let dependees = concat $ downmap (mapIn weakenToSuper) $ argDeps con.args + let dependees = dependees con.args -- Decide how constructor arguments would be named during generation let bindNames = withIndex (fromList con.args) <&> map (bindNameRenamer . argName) diff --git a/src/Deriving/DepTyCheck/Util/Reflection.idr b/src/Deriving/DepTyCheck/Util/Reflection.idr index e4212aaa..a549a89c 100644 --- a/src/Deriving/DepTyCheck/Util/Reflection.idr +++ b/src/Deriving/DepTyCheck/Util/Reflection.idr @@ -401,6 +401,13 @@ argDeps args = do flip upmapI args $ \i, deps => flip concatMap deps $ \candidates => maybe empty singleton $ last' $ mapMaybe tryToFit $ SortedSet.toList candidates +export +dependees : (args : List Arg) -> SortedSet $ Fin $ args.length +dependees args = do + let nameToIndex = SortedMap.fromList $ mapI args $ \i, arg => (argName arg, i) + let varsInTypes = concatMap (\arg => allVarNames' arg.type) args + fromList $ mapMaybe (lookup' nameToIndex) $ SortedSet.toList varsInTypes + export record NamesInfoInTypes where constructor Names