Skip to content

Commit 6dd8cf0

Browse files
authored
Get rid of oeis2 and polysemy-plugin dependencies to allow compiling with WASM (#449)
1 parent 998d6d0 commit 6dd8cf0

29 files changed

Lines changed: 160 additions & 193 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,5 @@ tmp/
8282

8383
*.pygtex
8484
*.pygstyle
85+
86+
*/_minted/*

cabal.project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
packages: *.cabal
2+
3+
source-repository-package
4+
type: git
5+
location: https://github.com/disco-lang/polysemy
6+
tag: db923b90c88374c8de4e597136f0ec3154533677

disco.cabal

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ common common
397397

398398
library
399399
import: common
400-
ghc-options: -flate-specialise -fspecialise-aggressively -fplugin=Polysemy.Plugin
400+
ghc-options: -flate-specialise -fspecialise-aggressively
401401
default-extensions: DataKinds
402402
DeriveGeneric
403403
FlexibleContexts
@@ -487,7 +487,6 @@ library
487487
-- Need the Alpha and Subst instances for
488488
-- NonEmpty from unbound-generics 0.4.4
489489
polysemy >= 1.6.0.0 && < 1.10,
490-
polysemy-plugin >= 0.4 && < 0.5,
491490
reflection >= 2.1.7 && < 2.2,
492491
random >= 1.2.1.1 && < 1.4,
493492
constraints >= 0.13.4 && < 0.15,
@@ -503,7 +502,6 @@ library
503502
splitmix >= 0.1 && < 0.2,
504503
fgl >= 5.5 && < 5.9,
505504
optparse-applicative >= 0.12 && < 0.20,
506-
oeis2 >= 1.0.9 && < 1.1,
507505
algebraic-graphs >= 0.5 && < 0.8,
508506
pretty-show >= 1.10 && < 1.11,
509507
boxes >= 0.1.5 && < 0.2,
@@ -530,7 +528,6 @@ executable disco
530528
unbound-generics >= 0.3 && < 0.5,
531529
lens >= 4.14 && < 5.4,
532530
optparse-applicative >= 0.12 && < 0.20,
533-
oeis2 >= 1.0.9 && < 1.1
534531

535532
default-language: Haskell2010
536533

example/catalan.disco

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import list
2-
import oeis
32

43
-- The type of binary tree shapes: empty tree, or a pair of subtrees.
54
type BT = Unit + BT*BT
@@ -13,7 +12,3 @@ treesOfSize(k+1) =
1312
-- Compute first few Catalan numbers by brute force.
1413
catalan1 : List(N)
1514
catalan1 = each(\k. length(treesOfSize(k)), [0..4])
16-
17-
-- Extend the sequence via the OEIS.
18-
catalan : List(N)
19-
catalan = extendSequence(catalan1)

src/Disco/AST/Core.hs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ data Op
218218
OCrash
219219
| -- | No-op/identity function
220220
OId
221-
| -- | Lookup OEIS sequence
222-
OLookupSeq
223-
| -- | Extend a List via OEIS
224-
OExtendSeq
225221
| -- | Not the Boolean `And`, but instead a propositional BOp
226222
-- | Should only be seen and used with Props.
227223
OAnd
@@ -298,7 +294,7 @@ instance Pretty Core where
298294
toTuple :: [Core] -> Core
299295
toTuple = foldr CPair CUnit
300296

301-
prettyTestVars :: Members '[Reader PA, LFresh] r => [(String, Type, Name Core)] -> Sem r (Doc ann)
297+
prettyTestVars :: Members '[Reader PA, LFresh] r => [(String, Type, Name Core)] -> Sem r Doc
302298
prettyTestVars = brackets . intercalate "," . map prettyTestVar
303299
where
304300
prettyTestVar (s, ty, n) = parens (intercalate "," [text s, pretty ty, pretty n])
@@ -384,8 +380,6 @@ opToStr = \case
384380
OMatchErr -> "matchErr"
385381
OCrash -> "crash"
386382
OId -> "id"
387-
OLookupSeq -> "lookupSeq"
388-
OExtendSeq -> "extendSeq"
389383
OForall {} -> ""
390384
OExists {} -> ""
391385
OAnd -> "and"

src/Disco/AST/Surface.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ instance Pretty (Name a, Bind [Pattern] Term) where
234234
pretty x <> hcat (map prettyPatternP ps) <+> text "=" <+> setPA initPA (pretty t)
235235

236236
-- | Pretty-print a type declaration.
237-
prettyTyDecl :: Members '[Reader PA, LFresh] r => Name t -> Type -> Sem r (Doc ann)
237+
prettyTyDecl :: Members '[Reader PA, LFresh] r => Name t -> Type -> Sem r Doc
238238
prettyTyDecl x ty = hsep [pretty x, text ":", pretty ty]
239239

240240
------------------------------------------------------------
@@ -525,7 +525,7 @@ pattern PNonlinear p x <- PNonlinear_ (unembed -> p) x
525525
-- term (e.g. via the :doc REPL command).
526526

527527
-- | Pretty-print a term with guaranteed parentheses.
528-
prettyTermP :: Members '[LFresh, Reader PA] r => Term -> Sem r (Doc ann)
528+
prettyTermP :: Members '[LFresh, Reader PA] r => Term -> Sem r Doc
529529
prettyTermP t@TTup {} = setPA initPA $ pretty t
530530
-- prettyTermP t@TContainer{} = setPA initPA $ "" <+> prettyTerm t
531531
prettyTermP t = withPA initPA $ pretty t
@@ -629,12 +629,12 @@ instance Pretty Term where
629629
TWild -> text "_"
630630

631631
-- | Print appropriate delimiters for a container literal.
632-
containerDelims :: Member (Reader PA) r => Container -> (Sem r (Doc ann) -> Sem r (Doc ann))
632+
containerDelims :: Member (Reader PA) r => Container -> (Sem r Doc -> Sem r Doc)
633633
containerDelims ListContainer = brackets
634634
containerDelims BagContainer = bag
635635
containerDelims SetContainer = braces
636636

637-
prettyBranches :: Members '[Reader PA, LFresh] r => [Branch] -> Sem r (Doc ann)
637+
prettyBranches :: Members '[Reader PA, LFresh] r => [Branch] -> Sem r Doc
638638
prettyBranches = \case
639639
[] -> text ""
640640
b : bs ->
@@ -680,7 +680,7 @@ instance Pretty Qual where
680680
QGuard (unembed -> t) -> pretty t
681681

682682
-- | Pretty-print a pattern with guaranteed parentheses.
683-
prettyPatternP :: Members '[LFresh, Reader PA] r => Pattern -> Sem r (Doc ann)
683+
prettyPatternP :: Members '[LFresh, Reader PA] r => Pattern -> Sem r Doc
684684
prettyPatternP p@PTup {} = setPA initPA $ pretty p
685685
prettyPatternP p = withPA initPA $ pretty p
686686

src/Disco/Compile.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,6 @@ compilePrim _ PrimFrac = return $ CConst OFrac
359359
compilePrim _ PrimCrash = return $ CConst OCrash
360360
compilePrim _ PrimUntil = return $ CConst OUntil
361361
compilePrim _ PrimHolds = return $ CConst OHolds
362-
compilePrim _ PrimLookupSeq = return $ CConst OLookupSeq
363-
compilePrim _ PrimExtendSeq = return $ CConst OExtendSeq
364362
compilePrim ty PrimMin = desugaredPrimErr PrimMin ty
365363
compilePrim ty PrimMax = desugaredPrimErr PrimMax ty
366364

src/Disco/Effects/Store.hs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{-# LANGUAGE BlockArguments #-}
22
{-# LANGUAGE TemplateHaskell #-}
33

4-
-----------------------------------------------------------------------------
5-
6-
-----------------------------------------------------------------------------
7-
84
-- |
95
-- Module : Disco.Effects.Store
106
-- Copyright : disco team and contributors
@@ -18,19 +14,20 @@ module Disco.Effects.Store where
1814
import qualified Data.IntMap.Lazy as IntMap
1915
import Data.IntSet (IntSet)
2016
import qualified Data.IntSet as IntSet
17+
import Data.Proxy
2118

2219
import Disco.Effects.Counter
2320
import Polysemy
2421
import Polysemy.State
2522

2623
data Store v m a where
27-
ClearStore :: Store v m ()
24+
ClearStore :: Proxy v -> Store v m ()
2825
New :: v -> Store v m Int
2926
LookupStore :: Int -> Store v m (Maybe v)
3027
InsertStore :: Int -> v -> Store v m ()
3128
MapStore :: (v -> v) -> Store v m ()
3229
AssocsStore :: Store v m [(Int, v)]
33-
KeepKeys :: IntSet -> Store v m ()
30+
KeepKeys :: Proxy v -> IntSet -> Store v m ()
3431

3532
makeSem ''Store
3633

@@ -40,7 +37,7 @@ runStore =
4037
runCounter
4138
. evalState @(IntMap.IntMap v) IntMap.empty
4239
. reinterpret2 \case
43-
ClearStore -> put IntMap.empty
40+
ClearStore _ -> put @(IntMap.IntMap v) IntMap.empty
4441
New v -> do
4542
loc <- fromIntegral <$> next
4643
modify $ IntMap.insert loc v
@@ -49,4 +46,6 @@ runStore =
4946
InsertStore k v -> modify (IntMap.insert k v)
5047
MapStore f -> modify (IntMap.map f)
5148
AssocsStore -> gets IntMap.assocs
52-
KeepKeys ks -> modify (\m -> IntMap.withoutKeys m (IntMap.keysSet m `IntSet.difference` ks))
49+
KeepKeys _ ks ->
50+
modify @(IntMap.IntMap v) $ \m ->
51+
IntMap.withoutKeys m (IntMap.keysSet m `IntSet.difference` ks)

src/Disco/Error.hs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ deriving instance Show EvalError
7878
panic :: Member (Error DiscoError) r => String -> Sem r a
7979
panic = throw . Panic
8080

81-
outputDiscoErrors :: Member (Output (Message ann)) r => Sem (Error DiscoError ': r) () -> Sem r ()
81+
outputDiscoErrors :: Member (Output Message) r => Sem (Error DiscoError ': r) () -> Sem r ()
8282
outputDiscoErrors m = do
8383
e <- runError m
8484
either (err . pretty') return e
@@ -102,10 +102,10 @@ instance Pretty DiscoError where
102102
, "Please report this as a bug at https://github.com/disco-lang/disco/issues/ ."
103103
]
104104

105-
rtd :: String -> Sem r (Doc ann)
105+
rtd :: String -> Sem r Doc
106106
rtd page = "https://disco-lang.readthedocs.io/en/latest/reference/" <> text page <> ".html"
107107

108-
-- issue :: Int -> Sem r (Doc ann)
108+
-- issue :: Int -> Sem r Doc
109109
-- issue n = "See https://github.com/disco-lang/disco/issues/" <> text (show n)
110110

111111
squote :: String -> String
@@ -114,15 +114,15 @@ squote x = "'" ++ x ++ "'"
114114
cyclicImportError ::
115115
Members '[Reader PA, LFresh] r =>
116116
[ModuleName] ->
117-
Sem r (Doc ann)
117+
Sem r Doc
118118
cyclicImportError ms =
119119
nest 2 $
120120
vcat
121121
[ "Error: module imports form a cycle:"
122122
, intercalate " ->" (map pretty ms)
123123
]
124124

125-
prettyEvalError :: Members '[Reader PA, LFresh] r => EvalError -> Sem r (Doc ann)
125+
prettyEvalError :: Members '[Reader PA, LFresh] r => EvalError -> Sem r Doc
126126
prettyEvalError = \case
127127
UnboundPanic x ->
128128
("Bug! No variable found named" <+> pretty' x <> ".")
@@ -139,7 +139,7 @@ prettyEvalError = \case
139139
-- [ ] Step 3: improve error messages according to notes below
140140
-- [ ] Step 4: get it to return multiple error messages
141141
-- [ ] Step 5: save parse locations, display with errors
142-
prettyTCError :: Members '[Reader PA, LFresh] r => TCError -> Sem r (Doc ann)
142+
prettyTCError :: Members '[Reader PA, LFresh] r => TCError -> Sem r Doc
143143
prettyTCError = \case
144144
-- XXX include some potential misspellings along with Unbound
145145
-- see https://github.com/disco-lang/disco/issues/180
@@ -261,13 +261,12 @@ prettyTCError = \case
261261
[ "Error: in the definition of " <> text s <> parens (intercalate "," (map text ss)) <> ": recursive occurrences of" <+> text s <+> "may only have type variables as arguments."
262262
, indent
263263
2
264-
( text s <> parens (intercalate "," (map pretty' tys)) <+> "does not follow this rule."
265-
)
264+
(text s <> parens (intercalate "," (map pretty' tys)) <+> "does not follow this rule.")
266265
, rtd "no-poly-rec"
267266
]
268267
NoError -> empty
269268

270-
conWord :: Con -> Sem r (Doc ann)
269+
conWord :: Con -> Sem r Doc
271270
conWord = \case
272271
CArr -> "function"
273272
CProd -> "pair"
@@ -280,7 +279,7 @@ conWord = \case
280279
CGraph -> "graph"
281280
CUser s -> text s
282281

283-
prettySolveError :: Members '[Reader PA, LFresh] r => SolveError -> Sem r (Doc ann)
282+
prettySolveError :: Members '[Reader PA, LFresh] r => SolveError -> Sem r Doc
284283
prettySolveError = \case
285284
-- XXX say which types!
286285
NoWeakUnifier ->
@@ -311,12 +310,12 @@ prettySolveError = \case
311310
, rtd "qual-skolem"
312311
]
313312

314-
qualPhrase :: Bool -> Qualifier -> Sem r (Doc ann)
313+
qualPhrase :: Bool -> Qualifier -> Sem r Doc
315314
qualPhrase b q
316315
| q `elem` [QBool, QBasic, QSimple] = "are" <+> (if b then empty else "not") <+> qualAction q
317316
| otherwise = "can" <> (if b then empty else "not") <+> "be" <+> qualAction q
318317

319-
qualAction :: Qualifier -> Sem r (Doc ann)
318+
qualAction :: Qualifier -> Sem r Doc
320319
qualAction = \case
321320
QNum -> "added and multiplied"
322321
QSub -> "subtracted"

src/Disco/Eval.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ type family AppendEffects (r :: EffectRow) (s :: EffectRow) :: EffectRow where
162162
-- However, just manually implementing it here seems easier.
163163

164164
-- | Effects needed at the top level.
165-
type TopEffects = '[Error DiscoError, State TopInfo, Output (Message ()), Embed IO, Final (H.InputT IO)]
165+
type TopEffects = '[Error DiscoError, State TopInfo, Output Message, Embed IO, Final (H.InputT IO)]
166166

167167
-- | Effects needed for evaluation.
168-
type EvalEffects = [Error EvalError, Random, LFresh, Output (Message ()), State Mem]
168+
type EvalEffects = [Error EvalError, Random, LFresh, Output Message, State Mem]
169169

170170
-- XXX write about order.
171171
-- memory, counter etc. should not be reset by errors.
@@ -191,11 +191,11 @@ runDisco cfg =
191191
void
192192
. H.runInputT inputSettings
193193
. runFinal @(H.InputT IO)
194-
. embedToFinal
194+
. embedToFinal @(H.InputT IO)
195195
. runEmbedded @_ @(H.InputT IO) liftIO
196196
. runOutputSem (handleMsg msgFilter) -- Handle Output Message via printing to console
197197
. stateToIO (initTopInfo cfg) -- Run State TopInfo via an IORef
198-
. inputToState -- Dispatch Input TopInfo effect via State effect
198+
. inputToState @TopInfo -- Dispatch Input TopInfo effect via State effect
199199
. runState emptyMem -- Start with empty memory
200200
. outputDiscoErrors -- Output any top-level errors
201201
. runLFresh -- Generate locally fresh names
@@ -293,7 +293,7 @@ typecheckTop tcm = do
293293
-- The 'Resolver' argument specifies where to look for imported
294294
-- modules.
295295
loadDiscoModule ::
296-
Members '[State TopInfo, Output (Message ann), Random, State Mem, Error DiscoError, Embed IO] r =>
296+
Members '[State TopInfo, Output Message, Random, State Mem, Error DiscoError, Embed IO] r =>
297297
Bool ->
298298
Resolver ->
299299
FilePath ->
@@ -307,7 +307,7 @@ loadDiscoModule quiet resolver =
307307
-- module loaded from disk). Used for e.g. blocks/modules entered
308308
-- at the REPL prompt.
309309
loadParsedDiscoModule ::
310-
Members '[State TopInfo, Output (Message ann), Random, State Mem, Error DiscoError, Embed IO] r =>
310+
Members '[State TopInfo, Output Message, Random, State Mem, Error DiscoError, Embed IO] r =>
311311
Bool ->
312312
Resolver ->
313313
ModuleName ->
@@ -321,7 +321,7 @@ loadParsedDiscoModule quiet resolver =
321321
-- any imported module more than once. Resolve the module, load and
322322
-- parse it, then call 'loadParsedDiscoModule''.
323323
loadDiscoModule' ::
324-
Members '[State TopInfo, Output (Message ann), Random, State Mem, Error DiscoError, Embed IO] r =>
324+
Members '[State TopInfo, Output Message, Random, State Mem, Error DiscoError, Embed IO] r =>
325325
Bool ->
326326
Resolver ->
327327
[ModuleName] ->
@@ -353,7 +353,7 @@ stdLib = ["list", "container"]
353353
-- 'LoadingMode' parameter is 'REPL'. Recursively load all its
354354
-- imports, then typecheck it.
355355
loadParsedDiscoModule' ::
356-
Members '[State TopInfo, Output (Message ann), Random, State Mem, Error DiscoError, Embed IO] r =>
356+
Members '[State TopInfo, Output Message, Random, State Mem, Error DiscoError, Embed IO] r =>
357357
Bool ->
358358
LoadingMode ->
359359
Resolver ->
@@ -399,7 +399,7 @@ loadParsedDiscoModule' quiet mode resolver inProcess name cm@(Module _ mns _ _ _
399399

400400
-- | Try loading the contents of a file from the filesystem, emitting
401401
-- an error if it's not found.
402-
loadFile :: Members '[Output (Message ann), Embed IO] r => FilePath -> Sem r (Maybe String)
402+
loadFile :: Members '[Output Message, Embed IO] r => FilePath -> Sem r (Maybe String)
403403
loadFile file = do
404404
res <- liftIO $ handle @SomeException (return . Left) (Right <$> readFile file)
405405
case res of
@@ -409,7 +409,7 @@ loadFile file = do
409409
-- | Add things from the given module to the set of currently loaded
410410
-- things.
411411
addToREPLModule ::
412-
Members '[Error DiscoError, State TopInfo, Random, State Mem, Output (Message ann)] r =>
412+
Members '[Error DiscoError, State TopInfo, Random, State Mem, Output Message] r =>
413413
ModuleInfo ->
414414
Sem r ()
415415
addToREPLModule mi = modify @TopInfo (replModInfo <>~ mi)
@@ -419,7 +419,7 @@ addToREPLModule mi = modify @TopInfo (replModInfo <>~ mi)
419419
-- term definitions, documentation, types, and type definitions.
420420
-- Replaces any previously loaded module.
421421
setREPLModule ::
422-
Members '[State TopInfo, Random, Error EvalError, State Mem, Output (Message ann)] r =>
422+
Members '[State TopInfo, Random, Error EvalError, State Mem, Output Message] r =>
423423
ModuleInfo ->
424424
Sem r ()
425425
setREPLModule mi = do
@@ -450,7 +450,7 @@ loadDef x body = do
450450
v <- inputToState @TopInfo . inputTopEnv $ eval body
451451
modify @TopInfo $ topEnv %~ Ctx.insert x v
452452

453-
checkExhaustive :: Members '[Fresh, Output (Message ann), Embed IO] r => TyDefCtx -> Defn -> Sem r ()
453+
checkExhaustive :: Members '[Fresh, Output Message, Embed IO] r => TyDefCtx -> Defn -> Sem r ()
454454
checkExhaustive tyDefCtx (Defn name argsType _ boundClauses) = do
455455
clauses <- NonEmpty.map fst <$> mapM unbind boundClauses
456456
runReader @TyDefCtx tyDefCtx $ checkClauses name argsType clauses

0 commit comments

Comments
 (0)