Skip to content

Commit 8001af3

Browse files
Remove use of LinkedHashMap package (#913)
1 parent 88bb116 commit 8001af3

4 files changed

Lines changed: 15 additions & 21 deletions

File tree

cabal.project.config

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
-- different configurations for Vehicle. See `cabal.project` for more
55
-- details.
66

7-
-- 03-11-2022:
8-
-- The package linkedhashmap seems unmaintained. The latest update seems to
9-
-- have been in 2015. Unfortunately, it requires containers <0.6.
10-
-- See: https://github.com/vehicle-lang/vehicle/issues/191
11-
12-
allow-newer: linkedhashmap-0.4.0.0:containers
13-
147
-- 03-04-2023:
158
-- The package terminal-size, which is a dependency of terminal-progress-bar,
169
-- requires Win32>=2.13.2.0 && <2.14 since version 0.3.4. Unfortunately, the

vehicle/src/Vehicle/Compile/FunctionaliseResources.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import Control.Monad (when)
77
import Control.Monad.Reader (MonadReader (..), ReaderT (..))
88
import Control.Monad.Writer (MonadWriter (..), execWriterT)
99
import Data.Bifunctor (Bifunctor (..))
10-
import Data.LinkedHashMap (LinkedHashMap)
11-
import Data.LinkedHashMap qualified as LinkedHashMap (empty, filterWithKey, insert, member, toList)
1210
import Data.Map (Map)
1311
import Data.Map qualified as Map (fromList, insert, lookup)
12+
import Data.Map.Ordered (OMap)
13+
import Data.Map.Ordered qualified as OMap (assocs, empty, filter, member, (>|))
1414
import Data.Maybe (catMaybes)
1515
import Data.Set (Set)
1616
import Data.Set qualified as Set (fromList, member, singleton)
@@ -48,7 +48,7 @@ functionaliseResources ::
4848
m (Prog builtin)
4949
functionaliseResources prog =
5050
logCompilerPass MidDetail currentPass $ do
51-
runReaderT (functionaliseProg prog) (FuncState LinkedHashMap.empty mempty)
51+
runReaderT (functionaliseProg prog) (FuncState OMap.empty mempty)
5252

5353
--------------------------------------------------------------------------------
5454
-- Utilities
@@ -57,14 +57,14 @@ currentPass :: CompilerPass
5757
currentPass = "resource functionalisation"
5858

5959
data FuncState builtin = FuncState
60-
{ resourceDeclarations :: LinkedHashMap Name (Type builtin),
60+
{ resourceDeclarations :: OMap Name (Type builtin),
6161
resourceUsageFreeCtx :: GenericFreeCtx [Name]
6262
}
6363

6464
addResourceDeclaration :: Identifier -> Type builtin -> FuncState builtin -> FuncState builtin
6565
addResourceDeclaration resource typ FuncState {..} =
6666
FuncState
67-
{ resourceDeclarations = LinkedHashMap.insert (nameOf resource) typ resourceDeclarations,
67+
{ resourceDeclarations = resourceDeclarations OMap.>| (nameOf resource, typ),
6868
..
6969
}
7070

@@ -134,7 +134,7 @@ findResourceUses e = do
134134
args' <- traverse (traverse recGo) args
135135
FuncState {..} <- ask
136136
let name = nameOf ident
137-
when (name `LinkedHashMap.member` resourceDeclarations) $ do
137+
when (name `OMap.member` resourceDeclarations) $ do
138138
tell (Set.singleton name)
139139
let resourceArgs = lookupInFreeCtx ident resourceUsageFreeCtx
140140
tell (Set.fromList resourceArgs)
@@ -171,7 +171,7 @@ replaceResourceUses (mkBinder, binders, binderNames) initialExpr = do
171171
return $ BoundVar p resourceIx
172172

173173
newFun <-
174-
if name `LinkedHashMap.member` resourceDeclarations
174+
if name `OMap.member` resourceDeclarations
175175
then mkResourceVar name
176176
else return $ FreeVar p ident
177177

@@ -188,8 +188,8 @@ createBinders ::
188188
m (Binder builtin -> Expr builtin -> Expr builtin, [Binder builtin], [Name])
189189
createBinders isType p idents = do
190190
FuncState {..} <- ask
191-
let identsAndTypes = LinkedHashMap.filterWithKey (\i _ -> Set.member i idents) resourceDeclarations
192-
let identsAndTypesList = LinkedHashMap.toList identsAndTypes
191+
let identsAndTypes = OMap.filter (\i _ -> Set.member i idents) resourceDeclarations
192+
let identsAndTypesList = OMap.assocs identsAndTypes
193193
let mkBindingForm ident
194194
| isType = BinderDisplayForm OnlyType True
195195
| otherwise = BinderDisplayForm (OnlyName (nameOf ident)) True

vehicle/src/Vehicle/Compile/Monomorphisation.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import Control.Monad.State
1717
)
1818
import Control.Monad.Writer (MonadWriter (..), runWriterT)
1919
import Data.Bifunctor (Bifunctor (..))
20-
import Data.Foldable (traverse_)
20+
import Data.Foldable (Foldable (..), traverse_)
2121
import Data.HashMap.Strict (HashMap)
2222
import Data.HashMap.Strict qualified as HashMap
2323
import Data.Hashable (Hashable)
24-
import Data.LinkedHashSet qualified as HashSet (fromList, toList)
24+
import Data.List (nub)
2525
import Data.List.NonEmpty (NonEmpty)
2626
import Data.List.NonEmpty qualified as NonEmpty
2727
import Data.Map (Map)
@@ -190,8 +190,10 @@ calculateMonomorphisations declType allApplications = do
190190
MonoSettings {..} <- ask
191191
let calculateMonomorphisation = obtainArgsToMonomorphise isMonomorphisableBinder declType
192192
let monomorphisations = fmap (fst . calculateMonomorphisation) allApplications
193-
let uniqueMonomorphisations = HashSet.fromList $ NonEmpty.toList monomorphisations
194-
return $ HashSet.toList uniqueMonomorphisations
193+
-- This is inefficient and not strictly semantically correct.
194+
-- Semantic equality is difficult however.
195+
let uniqueMonomorphisations = nub $ NonEmpty.toList monomorphisations
196+
return $ toList uniqueMonomorphisations
195197

196198
performMonomorphisation ::
197199
(MonadCollect builtin m) =>

vehicle/vehicle.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ library
300300
, filepath >=1.4 && <2
301301
, gitrev >=1.3 && <2
302302
, hashable >=1.3 && <2
303-
, linkedhashmap >=0.4 && <1
304303
, mnist-idx >=0.1.3.1 && <0.2
305304
, mtl >=2.2 && <3
306305
, optparse-applicative >=0.16 && <1

0 commit comments

Comments
 (0)