@@ -19,7 +19,6 @@ module Dhall.Lint
1919 ) where
2020
2121import Control.Applicative ((<|>) )
22- import Data.List.NonEmpty (NonEmpty (.. ))
2322
2423import Dhall.Syntax
2524 ( Binding (.. )
@@ -38,7 +37,6 @@ import Dhall.Syntax
3837
3938import qualified Data.Foldable as Foldable
4039import qualified Data.List.NonEmpty as NonEmpty
41- import qualified Data.Map as Map
4240import qualified Data.Text as Text
4341import qualified Dhall.Core as Core
4442import qualified Dhall.Map
@@ -63,7 +61,6 @@ lint = Dhall.Optics.rewriteOf subExpressions rewrite
6361 <|> fixParentPath e
6462 <|> removeLetInLet e
6563 <|> addPreludeExtensions e
66- <|> sortImports e
6764
6865-- | Remove unused `Let` bindings.
6966removeUnusedBindings :: Eq a => Expr s a -> Maybe (Expr s a )
@@ -212,53 +209,3 @@ useToMap (ListLit _ keyValues)
212209 Nothing
213210useToMap _ =
214211 Nothing
215-
216- -- | This sorts `let` bindings to move imports to the front if doing so does not
217- -- change the behavior of the code.
218- sortImports :: Eq s => Expr s Import -> Maybe (Expr s Import )
219- sortImports oldExpression@ (Let binding0 oldBody0)
220- | oldExpression == newExpression = Nothing
221- | otherwise = Just newExpression
222- where
223- toBool (Embed _ ) = False
224- toBool (Note _ e) = toBool e
225- toBool _ = True
226-
227- process (seen, index) Binding {.. } oldBody function = (pair, pairs, newBody)
228- where
229- order =
230- if b then index else Map. findWithDefault (0 :: Int ) variable seen
231-
232- b = toBool value
233-
234- pair = (order, function)
235-
236- ~ (pairs, newBody) =
237- label (Map. insert variable order seen, index + 1 ) oldBody
238-
239- label state (Let binding oldBody) = (pair : pairs, newBody)
240- where
241- function = Let binding
242-
243- ~ (pair, pairs, newBody) = process state binding oldBody function
244-
245- label state (Note src (Let binding oldBody)) = (pair : pairs, newBody)
246- where
247- function e = Note src (Let binding e)
248-
249- ~ (pair, pairs, newBody) = process state binding oldBody function
250-
251- label _ body =
252- ([] , body)
253-
254- ~ (pairs0, newBody0) = (pair :| pairs, newBody)
255- where
256- function = Let binding0
257-
258- ~ (pair, pairs, newBody) =
259- process (Map. empty, 1 ) binding0 oldBody0 function
260-
261- sortedFunctions = fmap snd (NonEmpty. sortWith fst pairs0)
262-
263- newExpression = foldr id newBody0 sortedFunctions
264- sortImports _ = Nothing
0 commit comments