Skip to content

Commit 0f42b70

Browse files
committed
Use BlockArguments
1 parent ad1b9de commit 0f42b70

40 files changed

+286
-248
lines changed

benchmarks/parser/Main.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BlockArguments #-}
12
{-# LANGUAGE OverloadedStrings #-}
23

34
module Main where
@@ -40,8 +41,8 @@ main = do
4041
listDirectoryRecursive :: (FilePath -> Bool) -> FilePath -> IO [FilePath]
4142
listDirectoryRecursive p dir = do
4243
files <- listDirectory dir
43-
fmap concat $
44-
forM files $ \file -> do
44+
concat
45+
<$> forM files \file -> do
4546
let path = dir </> file
4647
isDir <- doesDirectoryExist path
4748
if isDir
@@ -59,9 +60,10 @@ listDirectoriesWithFilesMatching p dir = do
5960
then do
6061
recursiveFiles <- listDirectoryRecursive p dir
6162
pure [(dir, recursiveFiles)]
62-
else fmap concat $
63-
forM paths $ \path -> do
64-
isDir <- doesDirectoryExist path
65-
if isDir
66-
then listDirectoriesWithFilesMatching p path
67-
else pure []
63+
else
64+
concat
65+
<$> forM paths \path -> do
66+
isDir <- doesDirectoryExist path
67+
if isDir
68+
then listDirectoriesWithFilesMatching p path
69+
else pure []

src/AssemblyToLLVM.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ freshName (Assembly.NameSuggestion nameSuggestion) = do
146146
usedNames <- gets (.usedNames)
147147
let bsName = ShortByteString.toShort $ toUtf8 nameSuggestion
148148
i = HashMap.lookupDefault 0 bsName usedNames
149-
modify $ \s ->
149+
modify \s ->
150150
s
151151
{ usedNames = HashMap.insert bsName (i + 1) usedNames
152152
}
@@ -155,7 +155,7 @@ freshName (Assembly.NameSuggestion nameSuggestion) = do
155155
activateLocal :: Assembly.Type -> Assembly.Local -> Assembler Name
156156
activateLocal type_ local@(Assembly.Local _ nameSuggestion) = do
157157
name <- freshName nameSuggestion
158-
modify $ \s ->
158+
modify \s ->
159159
s
160160
{ locals = HashMap.insert local (type_, TypedOperand {type_ = llvmType type_, operand = Local name}) s.locals
161161
}
@@ -477,7 +477,7 @@ assembleInstruction instruction =
477477
_ -> panic "AssemblyToLLVM.assembleInstruction: ExtractValue of non-struct"
478478
Assembly.Switch destination scrutinee branches (Assembly.BasicBlock defaultBranchInstructions defaultBranchResult) -> do
479479
scrutinee' <- assembleOperandAndCastTo Assembly.Word scrutinee
480-
branchLabels <- forM branches $ \(i, _) -> do
480+
branchLabels <- forM branches \(i, _) -> do
481481
branchLabel <- freshName $ Assembly.NameSuggestion $ "branch_" <> show i
482482
pure (i, branchLabel)
483483
defaultBranchLabel <- freshName "default"
@@ -489,7 +489,7 @@ assembleInstruction instruction =
489489
<> localName defaultBranchLabel
490490
<> " "
491491
<> brackets [separate " " [typedOperand TypedOperand {type_ = wordSizedInt, operand = Constant $ Builder.integerDec i} <> ", label " <> localName l | (i, l) <- branchLabels]]
492-
branchResultOperands <- forM (zip branchLabels branches) $ \((_, branchLabel), (_, Assembly.BasicBlock instructions result)) -> do
492+
branchResultOperands <- forM (zip branchLabels branches) \((_, branchLabel), (_, Assembly.BasicBlock instructions result)) -> do
493493
startBlock branchLabel
494494
mapM_ assembleInstruction instructions
495495
resultOperand <- forM ((,) . fst <$> destination <*> result) $ uncurry assembleOperandAndCastTo

src/ClosureConverted/Readback.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BlockArguments #-}
12
{-# LANGUAGE OverloadedStrings #-}
23

34
module ClosureConverted.Readback where
@@ -78,7 +79,7 @@ readbackGroupedElimination env eliminee elimination =
7879
branchValue <- Evaluation.evaluate env' branch
7980
readback env branchValue
8081
)
81-
defaultBranch' <- forM defaultBranch $ \branch -> do
82+
defaultBranch' <- forM defaultBranch \branch -> do
8283
branch' <- Evaluation.evaluate env' branch
8384
readback env branch'
8485
pure $ Syntax.Case eliminee branches' defaultBranch'

src/ClosureConverted/Representation.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BlockArguments #-}
12
{-# LANGUAGE DeriveGeneric #-}
23
{-# LANGUAGE FlexibleContexts #-}
34
{-# LANGUAGE OverloadedStrings #-}
@@ -38,7 +39,7 @@ signature :: Syntax.Definition -> M Representation.Signature
3839
signature def =
3940
case def of
4041
Syntax.TypeDeclaration (Syntax.Function tele) -> do
41-
telescopeSignature context tele mempty $ \context' body parameterRepresentations -> do
42+
telescopeSignature context tele mempty \context' body parameterRepresentations -> do
4243
let env' =
4344
Context.toEnvironment context'
4445
body' <- Evaluation.evaluate env' body
@@ -52,7 +53,7 @@ signature def =
5253
type_ <- TypeOf.typeOf context value
5354
Representation.ConstantSignature <$> typeRepresentation env type_
5455
Syntax.FunctionDefinition tele ->
55-
telescopeSignature context tele mempty $ \context' body parameterRepresentations -> do
56+
telescopeSignature context tele mempty \context' body parameterRepresentations -> do
5657
let env' =
5758
Context.toEnvironment context'
5859
body' <- Evaluation.evaluate env' body
@@ -62,7 +63,7 @@ signature def =
6263
Syntax.DataDefinition {} ->
6364
pure $ Representation.ConstantSignature $ Representation.Direct Representation.Doesn'tContainHeapPointers
6465
Syntax.ParameterisedDataDefinition _boxity tele ->
65-
telescopeSignature context tele mempty $ \_ _ parameterRepresentations -> do
66+
telescopeSignature context tele mempty \_ _ parameterRepresentations -> do
6667
pure $ Representation.FunctionSignature parameterRepresentations $ Representation.Direct Representation.Doesn'tContainHeapPointers
6768
where
6869
context =
@@ -201,7 +202,7 @@ compileData env dataTypeName (Syntax.ConstructorDefinitions constructors) = do
201202
Boxed ->
202203
pure $ Syntax.Global (Name.Lifted Builtin.WordRepresentationName 0)
203204
Unboxed -> do
204-
compiledConstructorFields <- forM (OrderedHashMap.toList constructors) $ \(_, type_) -> do
205+
compiledConstructorFields <- forM (OrderedHashMap.toList constructors) \(_, type_) -> do
205206
type' <- Evaluation.evaluate env type_
206207
compileUnboxedConstructorFields env type'
207208
let maxFieldSize =
@@ -314,7 +315,7 @@ constructorRepresentations name = do
314315
pure $ case definition of
315316
Core.Syntax.DataDefinition boxity tele ->
316317
( boxity
317-
, Telescope.under tele $ \(Core.Syntax.ConstructorDefinitions constructors) ->
318+
, Telescope.under tele \(Core.Syntax.ConstructorDefinitions constructors) ->
318319
case OrderedHashMap.toList constructors of
319320
[] -> Nothing
320321
[_] -> Nothing

src/ClosureConvertedToAssembly.hs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BlockArguments #-}
12
{-# LANGUAGE DuplicateRecordFields #-}
23
{-# LANGUAGE FlexibleContexts #-}
34
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@@ -80,7 +81,7 @@ subBuilder (Builder s) = do
8081

8182
emit :: Assembly.Instruction -> Builder ()
8283
emit instruction =
83-
modify $ \s -> s {instructions = s.instructions Tsil.:> instruction}
84+
modify \s -> s {instructions = s.instructions Tsil.:> instruction}
8485

8586
tagBytes :: Num a => a
8687
tagBytes = wordBytes
@@ -157,14 +158,14 @@ getFreeShadowStackSlot :: Builder (Int, Builder ())
157158
getFreeShadowStackSlot = do
158159
slot <- gets (.nextShadowStackSlot)
159160
let newNextSlot = slot + 1
160-
modify $ \s ->
161+
modify \s ->
161162
s
162163
{ nextShadowStackSlot = newNextSlot
163164
, shadowStackSlotCount = max newNextSlot s.shadowStackSlotCount
164165
}
165166
pure
166167
( slot
167-
, modify $ \s ->
168+
, modify \s ->
168169
s
169170
{ nextShadowStackSlot =
170171
if s.nextShadowStackSlot == newNextSlot
@@ -244,7 +245,7 @@ heapAllocate nameSuggestion constructorTag size = do
244245
result <- extractValue nameSuggestion destinationOperand 0
245246
heapPointer' <- extractValue "heap_pointer" destinationOperand 1
246247
heapLimit' <- extractValue "heap_limit" destinationOperand 2
247-
modify $ \s -> s {heapPointer = heapPointer', heapLimit = heapLimit'}
248+
modify \s -> s {heapPointer = heapPointer', heapLimit = heapLimit'}
248249
pure result
249250

250251
extractHeapPointer :: Assembly.NameSuggestion -> Assembly.Operand -> Builder Assembly.Operand
@@ -286,7 +287,7 @@ switch returnType scrutinee branches defaultBranch = do
286287
initialHeapPointer <- gets (.heapPointer)
287288
initialHeapLimit <- gets (.heapLimit)
288289
let wrapBranch branch = subBuilder $ do
289-
modify $ \s ->
290+
modify \s ->
290291
s
291292
{ nextShadowStackSlot = initialNextShadowStackSlot
292293
, heapPointer = initialHeapPointer
@@ -304,13 +305,13 @@ switch returnType scrutinee branches defaultBranch = do
304305
)
305306

306307
((defaultReturn, defaultNextShadowStackSlot), defaultInstructions) <- wrapBranch defaultBranch
307-
branches' <- forM branches $ \(i, branch) -> do
308+
branches' <- forM branches \(i, branch) -> do
308309
((branchReturn, branchNextShadowStackSlot), branchInstructions) <- wrapBranch branch
309310
pure ((i, Assembly.BasicBlock branchInstructions branchReturn), branchNextShadowStackSlot)
310311
let branchNextShadowStackSlots = snd <$> branches'
311312
when (any (/= defaultNextShadowStackSlot) branchNextShadowStackSlots) $
312313
panic "ClosureConvertedToAssembly.switch: Shadow stack mismatch"
313-
modify $ \s -> s {nextShadowStackSlot = defaultNextShadowStackSlot}
314+
modify \s -> s {nextShadowStackSlot = defaultNextShadowStackSlot}
314315
case returnType of
315316
Assembly.Void -> do
316317
resultLocal <- freshLocal "heap_pointer_and_limit"
@@ -319,7 +320,7 @@ switch returnType scrutinee branches defaultBranch = do
319320
emit $ Assembly.Switch (Assembly.Return (resultType, resultLocal)) scrutinee (fst <$> branches') $ Assembly.BasicBlock defaultInstructions defaultReturn
320321
heapPointer <- extractValue "heap_pointer" resultOperand 0
321322
heapLimit <- extractValue "heap_limit" resultOperand 1
322-
modify $ \s -> s {heapPointer, heapLimit}
323+
modify \s -> s {heapPointer, heapLimit}
323324
pure Assembly.Void
324325
Assembly.Return (type_, nameSuggestion) -> do
325326
resultLocal <- freshLocal $ nameSuggestion <> "_with_heap_pointer_and_limit"
@@ -329,15 +330,15 @@ switch returnType scrutinee branches defaultBranch = do
329330
result <- extractValue nameSuggestion resultOperand 0
330331
heapPointer <- extractValue "heap_pointer" resultOperand 1
331332
heapLimit <- extractValue "heap_limit" resultOperand 2
332-
modify $ \s -> s {heapPointer, heapLimit}
333+
modify \s -> s {heapPointer, heapLimit}
333334
pure $ Assembly.Return result
334335

335336
-------------------------------------------------------------------------------
336337

337338
freshLocal :: Assembly.NameSuggestion -> Builder Assembly.Local
338339
freshLocal nameSuggestion = do
339340
fresh <- gets (.fresh)
340-
modify $ \s -> s {fresh = fresh + 1}
341+
modify \s -> s {fresh = fresh + 1}
341342
pure $ Assembly.Local fresh nameSuggestion
342343

343344
copy :: Assembly.Operand -> Operand -> Assembly.Operand -> Builder ()
@@ -366,7 +367,7 @@ callVoid global args = do
366367
let resultStructOperand = Assembly.LocalOperand resultStruct
367368
heapPointer' <- extractValue "heap_pointer" resultStructOperand 0
368369
heapLimit' <- extractValue "heap_limit" resultStructOperand 1
369-
modify $ \s ->
370+
modify \s ->
370371
s
371372
{ heapPointer = heapPointer'
372373
, heapLimit = heapLimit'
@@ -394,7 +395,7 @@ callDirect nameSuggestion global args = do
394395
result <- extractValue nameSuggestion resultStructOperand 0
395396
heapPointer' <- extractValue "heap_pointer" resultStructOperand 1
396397
heapLimit' <- extractValue "heap_limit" resultStructOperand 2
397-
modify $ \s ->
398+
modify \s ->
398399
s
399400
{ heapPointer = heapPointer'
400401
, heapLimit = heapLimit'
@@ -424,7 +425,7 @@ callInitFunction nameSuggestion global args = do
424425
result <- extractValue nameSuggestion resultStructOperand 0
425426
heapPointer' <- extractValue "heap_pointer" resultStructOperand 1
426427
heapLimit' <- extractValue "heap_limit" resultStructOperand 2
427-
modify $ \s ->
428+
modify \s ->
428429
s
429430
{ heapPointer = heapPointer'
430431
, heapLimit = heapLimit'
@@ -630,7 +631,7 @@ withFunctionDefinitionParameters m = do
630631
heapPointer <- gets (.heapPointer)
631632
heapLimit <- gets (.heapLimit)
632633
pure $
633-
mkDefinition $ \returnType parameters (Assembly.BasicBlock instructions returnOperand) ->
634+
mkDefinition \returnType parameters (Assembly.BasicBlock instructions returnOperand) ->
634635
Assembly.FunctionDefinition
635636
( case returnType of
636637
Assembly.Void -> Assembly.Return $ Assembly.Struct [Assembly.WordPointer, Assembly.WordPointer]
@@ -677,11 +678,11 @@ generateGlobal env name representation term = do
677678
pure $ Assembly.KnownConstantDefinition Assembly.Word knownConstant True
678679
Nothing ->
679680
case representation of
680-
Representation.Empty -> makeConstantDefinition Assembly.WordPointer $ \globalPointer -> do
681+
Representation.Empty -> makeConstantDefinition Assembly.WordPointer \globalPointer -> do
681682
(_, deallocateTerm) <- generateTypedTerm env term (Direct emptyTypeOperand) representation
682683
sequence_ deallocateTerm
683684
pure globalPointer
684-
Representation.Direct Representation.Doesn'tContainHeapPointers -> makeConstantDefinition Assembly.Word $ \globalPointer -> do
685+
Representation.Direct Representation.Doesn'tContainHeapPointers -> makeConstantDefinition Assembly.Word \globalPointer -> do
685686
(result, deallocateTerm) <- generateTypedTerm env term (Direct directTypeOperand) representation
686687
directResult <- forceDirect result
687688
sequence_ deallocateTerm
@@ -693,7 +694,7 @@ generateGlobal env name representation term = do
693694
indirectCase containsHeapPointers
694695
where
695696
indirectCase containsHeapPointers = do
696-
makeConstantDefinition Assembly.WordPointer $ \globalPointer -> do
697+
makeConstantDefinition Assembly.WordPointer \globalPointer -> do
697698
(type_, _representation) <- typeOf env term
698699
typeSize <- sizeOfType type_
699700
globalPointer' <- globalAllocate "globals" globalPointer typeSize
@@ -1227,7 +1228,7 @@ boxedConstructorSize env con params args = do
12271228
tele <- fetch $ Query.ClosureConvertedConstructorType con
12281229
params' <- mapM (Evaluation.evaluate env) params
12291230
args' <- mapM (Evaluation.evaluate env) args
1230-
maybeResult <- Evaluation.applyTelescope env (Telescope.fromVoid tele) params' $ \env' type_ -> do
1231+
maybeResult <- Evaluation.applyTelescope env (Telescope.fromVoid tele) params' \env' type_ -> do
12311232
type' <- Evaluation.evaluate env' type_
12321233
size <- ClosureConverted.Representation.compileBoxedConstructorFields env' type' args'
12331234
Evaluation.evaluate env' size

src/Command/BenchmarkProjectGenerator.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BlockArguments #-}
12
{-# LANGUAGE FlexibleContexts #-}
23
{-# LANGUAGE OverloadedStrings #-}
34
{-# LANGUAGE RecordWildCards #-}
@@ -21,7 +22,7 @@ data Options = Options
2122
generate :: Options -> IO ()
2223
generate Options {..} = do
2324
createDirectoryIfMissing True $ outputDirectory </> "src"
24-
forM_ [1 .. moduleCount] $ \moduleNumber -> do
25+
forM_ [1 .. moduleCount] \moduleNumber -> do
2526
let moduleName num =
2627
"Module" <> show num
2728

@@ -32,7 +33,7 @@ generate Options {..} = do
3233
replicateM (min (moduleNumber - 1) importCount) $
3334
randomRIO (1, moduleNumber - 1)
3435

35-
functions <- forM [1 .. functionCount] $ \functionNumber -> do
36+
functions <- forM [1 .. functionCount] \functionNumber -> do
3637
def <-
3738
if not (null importedModules)
3839
then do

src/Command/Check.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BlockArguments #-}
12
{-# LANGUAGE FlexibleContexts #-}
23
{-# LANGUAGE OverloadedStrings #-}
34

@@ -26,16 +27,16 @@ check argumentFiles printElaborated = do
2627
((), errs) <-
2728
Driver.runTask sourceDirectories filePaths Error.Hydrated.pretty $
2829
if printElaborated
29-
then withAsync (void Driver.checkAll) $ \checkedAll -> do
30+
then withAsync (void Driver.checkAll) \checkedAll -> do
3031
inputFiles <- fetch Query.InputFiles
31-
forM_ inputFiles $ \filePath -> do
32+
forM_ inputFiles \filePath -> do
3233
(module_, _, defs) <- fetch $ Query.ParsedFile filePath
3334
let names =
3435
HashSet.fromList $
3536
Name.Qualified module_ . fst . snd <$> defs
3637
emptyPrettyEnv <- Pretty.emptyM module_
3738
liftIO $ putDoc $ "module" <+> pretty module_ <> line <> line
38-
forM_ names $ \name -> do
39+
forM_ names \name -> do
3940
type_ <- fetch $ Query.ElaboratedType name
4041
liftIO $ putDoc $ Pretty.prettyDefinition emptyPrettyEnv name (Syntax.TypeDeclaration type_) <> line
4142
(definition, _) <- fetch $ Query.ElaboratedDefinition name
@@ -47,7 +48,7 @@ check argumentFiles printElaborated = do
4748
wait checkedAll
4849
else void Driver.checkAll
4950
endTime <- getCurrentTime
50-
forM_ errs $ \err ->
51+
forM_ errs \err ->
5152
putDoc $ err <> line
5253
let errorCount =
5354
length errs

src/Command/Compile.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BlockArguments #-}
12
{-# LANGUAGE DuplicateRecordFields #-}
23
{-# LANGUAGE FlexibleContexts #-}
34
{-# LANGUAGE OverloadedStrings #-}
@@ -32,8 +33,8 @@ withCompiledExecutable :: (FilePath -> IO ()) -> Options -> IO ()
3233
withCompiledExecutable k Options {..} = do
3334
startTime <- getCurrentTime
3435
(sourceDirectories, filePaths) <- Project.filesFromArguments argumentFiles
35-
withAssemblyDirectory maybeAssemblyDir $ \assemblyDir ->
36-
withOutputFile maybeOutputFile $ \outputFile -> do
36+
withAssemblyDirectory maybeAssemblyDir \assemblyDir ->
37+
withOutputFile maybeOutputFile \outputFile -> do
3738
((), errs) <-
3839
Driver.runTask sourceDirectories filePaths Error.Hydrated.pretty $
3940
Compiler.compile assemblyDir (isJust maybeAssemblyDir) outputFile maybeOptimisationLevel
@@ -59,7 +60,7 @@ withOutputFile :: Maybe FilePath -> (FilePath -> IO a) -> IO a
5960
withOutputFile maybeOutputFile_ k' =
6061
case maybeOutputFile_ of
6162
Nothing ->
62-
withTempFile "." "temp.exe" $ \outputFile outputFileHandle -> do
63+
withTempFile "." "temp.exe" \outputFile outputFileHandle -> do
6364
hClose outputFileHandle
6465
k' outputFile
6566
Just o -> do

src/Command/Run.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE BlockArguments #-}
2+
13
module Command.Run where
24

35
import qualified Command.Compile
@@ -6,4 +8,4 @@ import System.Process
68

79
run :: Command.Compile.Options -> IO ()
810
run =
9-
Command.Compile.withCompiledExecutable $ \exe -> callProcess exe []
11+
Command.Compile.withCompiledExecutable \exe -> callProcess exe []

0 commit comments

Comments
 (0)