Skip to content

Commit 781ddfc

Browse files
Gabriella439locallycompact
authored andcommitted
dhall lint no longer sorts let bindings (dhall-lang#2503)
Fixes dhall-lang#2480 This lint transformation was unsound and it seems tricky to fix, so the safe thing to do is to remove the transformation for now.
1 parent 79e539e commit 781ddfc

File tree

3 files changed

+0
-75
lines changed

3 files changed

+0
-75
lines changed

dhall/src/Dhall/Lint.hs

-53
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module Dhall.Lint
1919
) where
2020

2121
import Control.Applicative ((<|>))
22-
import Data.List.NonEmpty (NonEmpty (..))
2322

2423
import Dhall.Syntax
2524
( Binding (..)
@@ -38,7 +37,6 @@ import Dhall.Syntax
3837

3938
import qualified Data.Foldable as Foldable
4039
import qualified Data.List.NonEmpty as NonEmpty
41-
import qualified Data.Map as Map
4240
import qualified Data.Text as Text
4341
import qualified Dhall.Core as Core
4442
import 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.
6966
removeUnusedBindings :: Eq a => Expr s a -> Maybe (Expr s a)
@@ -212,53 +209,3 @@ useToMap (ListLit _ keyValues)
212209
Nothing
213210
useToMap _ =
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

dhall/tests/lint/success/sortLetsA.dhall

-11
This file was deleted.

dhall/tests/lint/success/sortLetsB.dhall

-11
This file was deleted.

0 commit comments

Comments
 (0)