Caller-relative imports; smart deduping in imports
All checks were successful
Test, Build, and Release / test (push) Successful in 1m35s
Test, Build, and Release / build (push) Successful in 1m13s

This commit is contained in:
2025-01-30 17:56:46 -06:00
parent a16a24a808
commit 1a9a4494e0
19 changed files with 183 additions and 205 deletions

View File

@ -141,18 +141,23 @@ reorderDefs env defs
buildDepGraph :: [TricuAST] -> Map.Map String (Set.Set String)
buildDepGraph topDefs
| not (null duplicateNames) =
| not (null conflictingDefs) =
errorWithoutStackTrace $
"Duplicate definitions detected: " ++ show duplicateNames
"Conflicting definitions detected: " ++ show conflictingDefs
| otherwise =
Map.fromList
[ (name, depends topDefs (SDef name [] body))
| SDef name _ body <- topDefs]
where
names = [name | SDef name _ _ <- topDefs]
duplicateNames =
[ name | (name, count) <- Map.toList (countOccurrences names) , count > 1]
countOccurrences = foldr (\x -> Map.insertWith (+) x 1) Map.empty
defsMap = Map.fromListWith (++)
[(name, [(name, body)]) | SDef name _ body <- topDefs]
conflictingDefs =
[ name
| (name, defs) <- Map.toList defsMap
, let bodies = map snd defs
, not $ all (== head bodies) (tail bodies)
]
sortDeps :: Map.Map String (Set.Set String) -> [String]
sortDeps graph = go [] Set.empty (Map.keys graph)