Skip to content

Commit 1ab780a

Browse files
committed
Upgrade to LLVM 15, support Apple M1.
- Upgrade to GHC 9.2.x. - Apple M1 support seems to be mostly mature starting in GHC 9.2.1: https://www.haskell.org/ghc/blog/20210309-apple-m1-story.html. - Upgrade to LLVM 15. - Use the same resolver in stack*.yaml files as llvm-hs:llvm-15 for consistency. `make` now works on Apple M1, albeit with compiler warnings, some of which seem significant.
1 parent 978ef7a commit 1ab780a

File tree

11 files changed

+61
-39
lines changed

11 files changed

+61
-39
lines changed

.github/workflows/haskell-ci.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ jobs:
2121
os: [ubuntu-20.04, macos-latest]
2222
include:
2323
- os: macos-latest
24-
install_deps: brew install llvm@12 pkg-config wget gzip coreutils
25-
path_extension: $(brew --prefix llvm@12)/bin
24+
install_deps: brew install llvm@15 pkg-config wget gzip coreutils
25+
path_extension: $(brew --prefix llvm@15)/bin
2626
- os: ubuntu-20.04
27-
install_deps: sudo apt-get install llvm-12-tools llvm-12-dev pkg-config wget gzip wamerican
28-
path_extension: /usr/lib/llvm-12/bin
27+
install_deps: deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main; deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main; sudo apt-get install llvm-15-tools llvm-15-dev pkg-config wget gzip wamerican
28+
path_extension: /usr/lib/llvm-15/bin
2929

3030
steps:
3131
- name: Checkout the repository
@@ -36,7 +36,7 @@ jobs:
3636
with:
3737
path: |
3838
~/.stack
39-
~/.ghcup/ghc/8.10.7
39+
~/.ghcup/ghc/9.2.6
4040
$GITHUB_WORKSPACE/.stack-work
4141
$GITHUB_WORKSPACE/.stack-work-test
4242
$GITHUB_WORKSPACE/examples/t10k-images-idx3-ubyte
@@ -48,7 +48,7 @@ jobs:
4848
- name: Install system dependencies
4949
run: |
5050
${{ matrix.install_deps }}
51-
if [[ "$OSTYPE" == "darwin"* ]]; then ghcup install ghc 8.10.7; fi
51+
if [[ "$OSTYPE" == "darwin"* ]]; then ghcup install ghc 9.2.6; fi
5252
echo "${{ matrix.path_extension }}" >> $GITHUB_PATH
5353
5454
# This step is a workaround.

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ development. Expect monstrous bugs and razor-sharp edges!**
3636
## Dependencies
3737

3838
* Install [stack](https://www.haskellstack.org)
39-
* Install LLVM 12
40-
* Ubuntu/Debian: `apt-get install llvm-12-dev`
41-
* macOS: `brew install llvm@12`
42-
* Make sure `llvm@12` is on your `PATH` before building. Example: `export PATH="$(brew --prefix llvm@12)/bin:$PATH"`
43-
* Install clang 12 (may be installed together with llvm)
44-
* Ubuntu/Debian: `apt-get install clang-12`
39+
* Install LLVM 15
40+
* Ubuntu/Debian: `apt-get install llvm-15-dev`
41+
* macOS: `brew install llvm@15`
42+
* Make sure `llvm@15` is on your `PATH` before building. Example: `export PATH="$(brew --prefix llvm@15)/bin:$PATH"`
43+
* Install clang 15 (may be installed together with llvm)
44+
* Ubuntu/Debian: `apt-get install clang-15`
4545
* macOS: installs with llvm
4646
* Install libpng (often included by default in *nix platforms)
4747
* Ubuntu/Debian: `apt-get install libpng-dev`

dex.cabal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ library
132132
-- Serialization
133133
, aeson
134134
, store
135-
-- Floating-point pedanticness (correcting for GHC < 9.2.2)
136-
, floating-bits
137135
if flag(live)
138136
build-depends: binary
139137
, blaze-html

makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ifeq (, $(STACK))
6161
else
6262
STACK=stack
6363

64+
MACHINE := $(shell uname -m)
6465
PLATFORM := $(shell uname -s)
6566
ifeq ($(PLATFORM),Darwin)
6667
STACK=stack --stack-yaml=stack-macos.yaml
@@ -99,6 +100,15 @@ ifneq (,$(wildcard /usr/local/include/png.h))
99100
CFLAGS := $(CFLAGS) -I/usr/local/include
100101
endif
101102

103+
# Apple M1 (Darwin arm64)
104+
# - Add Homebrew include and library paths.
105+
ifeq ($(PLATFORM),Darwin)
106+
ifeq ($(MACHINE),arm64)
107+
STACK_FLAGS := $(STACK_FLAGS) --extra-include-dirs=/opt/homebrew/include
108+
STACK_FLAGS := $(STACK_FLAGS) --extra-lib-dirs=/opt/homebrew/lib
109+
endif
110+
endif
111+
102112
ifneq (,$(PREFIX))
103113
STACK_BIN_PATH := --local-bin-path $(PREFIX)
104114
endif
@@ -108,7 +118,7 @@ ifneq (,$(DEX_CI))
108118
STACK_FLAGS := $(STACK_FLAGS) --flag dex:debug
109119
endif
110120

111-
possible-clang-locations := clang++-9 clang++-10 clang++-11 clang++-12 clang++
121+
possible-clang-locations := clang++-9 clang++-10 clang++-11 clang++-12 clang++-15 clang++
112122

113123
CLANG := clang++
114124

@@ -125,7 +135,7 @@ then echo "$$clangversion" ; break ; fi ; done)
125135
ifeq (,$(CLANG))
126136
$(error "Please install clang++-12")
127137
endif
128-
clang-version-compatible := $(shell $(CLANG) -dumpversion | awk '{ print(gsub(/^((9\.)|(10\.)|(11\.)|(12\.)).*$$/, "")) }')
138+
clang-version-compatible := $(shell $(CLANG) -dumpversion | awk '{ print(gsub(/^((9\.)|(10\.)|(11\.)|(12\.)|(15\.)).*$$/, "")) }')
129139
ifneq (1,$(clang-version-compatible))
130140
$(error "Please install clang++-12")
131141
endif

src/lib/Algebra.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ blockAsPolyRec decls result = case decls of
156156
_ -> empty
157157

158158
impNameAsPoly :: ImpName i -> BlockTraverserM i o (Polynomial o)
159-
impNameAsPoly v = getSubst <&> (!v) >>= \case
159+
impNameAsPoly v = getSubst <&> (flip (!) v) >>= \case
160160
PolyRename v' -> return $ poly [(1, mono [(RightE v', 1)])]
161161

162162
atomNameAsPoly :: AtomName SimpIR i -> BlockTraverserM i o (Polynomial o)
163-
atomNameAsPoly v = getSubst <&> (!v) >>= \case
163+
atomNameAsPoly v = getSubst <&> (flip (!) v) >>= \case
164164
PolySubstVal Nothing -> empty
165165
PolySubstVal (Just cp) -> return cp
166166
PolyRename v' ->

src/lib/Name.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,8 +1323,14 @@ instance (ScopeReader m, ScopeExtender m)
13231323
instance (Monad1 m, ScopeReader m, ScopeExtender m, Fallible1 m)
13241324
=> ZipSubstReader (ZipSubstReaderT m) where
13251325

1326-
lookupZipSubstFst v = ZipSubstReaderT $ (!v) <$> fst <$> ask
1327-
lookupZipSubstSnd v = ZipSubstReaderT $ (!v) <$> snd <$> ask
1326+
lookupZipSubstFst v = ZipSubstReaderT $ (flip (!) v) <$> fst <$> ask
1327+
lookupZipSubstSnd v = ZipSubstReaderT $ (flip (!) v) <$> snd <$> ask
1328+
-- lookupZipSubstFst v = ZipSubstReaderT $ do
1329+
-- (env1, _) <- ask
1330+
-- return $ (!) env1 v
1331+
-- lookupZipSubstSnd v = ZipSubstReaderT $ do
1332+
-- (_, env2) <- ask
1333+
-- return $ (!) env2 v
13281334

13291335
extendZipSubstFst frag (ZipSubstReaderT cont) = ZipSubstReaderT $ withReaderT (onFst (<>>frag)) cont
13301336
extendZipSubstSnd frag (ZipSubstReaderT cont) = ZipSubstReaderT $ withReaderT (onSnd (<>>frag)) cont

src/lib/Optimize.hs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Optimize
1515
import Data.Functor
1616
import Data.Word
1717
import Data.Bits
18-
import Data.Bits.Floating
18+
-- import Data.Bits.Floating
1919
import Data.List
2020
import Control.Monad
2121
import Control.Monad.State.Strict
@@ -144,20 +144,26 @@ foldCast sTy l = case sTy of
144144
Float64Lit _ -> Nothing
145145
PtrLit _ _ -> Nothing
146146
Float32Type -> case l of
147-
Int32Lit i -> Just $ Float32Lit $ fixUlp i $ fromIntegral i
148-
Int64Lit i -> Just $ Float32Lit $ fixUlp i $ fromIntegral i
147+
-- Int32Lit i -> Just $ Float32Lit $ fixUlp i $ fromIntegral i
148+
Int32Lit i -> Just $ Float32Lit $ fromIntegral i
149+
-- Int64Lit i -> Just $ Float32Lit $ fixUlp i $ fromIntegral i
150+
Int64Lit i -> Just $ Float32Lit $ fromIntegral i
149151
Word8Lit i -> Just $ Float32Lit $ fromIntegral i
150-
Word32Lit i -> Just $ Float32Lit $ fixUlp i $ fromIntegral i
151-
Word64Lit i -> Just $ Float32Lit $ fixUlp i $ fromIntegral i
152+
-- Word32Lit i -> Just $ Float32Lit $ fixUlp i $ fromIntegral i
153+
Word32Lit i -> Just $ Float32Lit $ fromIntegral i
154+
-- Word64Lit i -> Just $ Float32Lit $ fixUlp i $ fromIntegral i
155+
Word64Lit i -> Just $ Float32Lit $ fromIntegral i
152156
Float32Lit _ -> Just l
153157
Float64Lit _ -> Nothing
154158
PtrLit _ _ -> Nothing
155159
Float64Type -> case l of
156160
Int32Lit i -> Just $ Float64Lit $ fromIntegral i
157-
Int64Lit i -> Just $ Float64Lit $ fixUlp i $ fromIntegral i
161+
-- Int64Lit i -> Just $ Float64Lit $ fixUlp i $ fromIntegral i
162+
Int64Lit i -> Just $ Float64Lit $ fromIntegral i
158163
Word8Lit i -> Just $ Float64Lit $ fromIntegral i
159164
Word32Lit i -> Just $ Float64Lit $ fromIntegral i
160-
Word64Lit i -> Just $ Float64Lit $ fixUlp i $ fromIntegral i
165+
-- Word64Lit i -> Just $ Float64Lit $ fixUlp i $ fromIntegral i
166+
Word64Lit i -> Just $ Float64Lit $ fromIntegral i
161167
Float32Lit f -> Just $ Float64Lit $ float2Double f
162168
Float64Lit _ -> Just l
163169
PtrLit _ _ -> Nothing
@@ -176,6 +182,8 @@ foldCast sTy l = case sTy of
176182
-- exhibit when cast back to the original integer type.
177183
fixUlp :: forall a b w. (Num a, Integral a, FiniteBits a, RealFrac b, FloatingBits b w)
178184
=> a -> b -> b
185+
fixUlp orig candidate = candidate
186+
{-
179187
fixUlp orig candidate = res where
180188
res = closest $ sortBy moreLowBits [candidate, candidatem1, candidatep1]
181189
candidatem1 = nextDown candidate
@@ -186,6 +194,7 @@ foldCast sTy l = case sTy of
186194
moreLowBits a b =
187195
compare (0 - countTrailingZeros (round @b @a a))
188196
(0 - countTrailingZeros (round @b @a b))
197+
-}
189198

190199
peepholeExpr :: SExpr o -> EnvReaderM o (Either (SAtom o) (SExpr o))
191200
peepholeExpr expr = case expr of

src/lib/Subst.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class (SinkableV v, Monad2 m) => SubstReader (v::V) (m::MonadKind2) | m -> v whe
3030
withSubst :: Subst v i' o -> m i' o a -> m i o a
3131

3232
lookupSubstM :: (Color c, SubstReader v m) => Name c i -> m i o (v c o)
33-
lookupSubstM name = (!name) <$> getSubst
33+
lookupSubstM name = (flip (!) name) <$> getSubst
3434

3535
dropSubst :: (SubstReader v m, FromName v) => m o o a -> m i o a
3636
dropSubst cont = withSubst idSubst cont

src/lib/Types/Core.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,8 @@ instance (IRRep r, HoistableE ann) => HoistableB (NonDepNest r ann)
17101710
instance (IRRep r, RenameE ann, SinkableE ann) => RenameB (NonDepNest r ann)
17111711
instance (IRRep r, AlphaEqE ann) => AlphaEqB (NonDepNest r ann)
17121712
instance (IRRep r, AlphaHashableE ann) => AlphaHashableB (NonDepNest r ann)
1713-
deriving instance (Show (ann n)) => IRRep r => Show (NonDepNest r ann n l)
1713+
-- deriving instance (Show (ann n)) => IRRep r => Show (NonDepNest r ann n l)
1714+
deriving instance (Show (ann n), IRRep r) => Show (NonDepNest r ann n l)
17141715

17151716
instance GenericB RolePiBinder where
17161717
type RepB RolePiBinder = PairB (LiftB (LiftE ParamRole)) (WithExpl CBinder)

stack-macos.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44
# license that can be found in the LICENSE file or at
55
# https://developers.google.com/open-source/licenses/bsd
66

7-
resolver: lts-18.23
7+
# Keep in sync with llvm-hs@llvm-15: https://github.com/llvm-hs/llvm-hs/blob/llvm-15/stack.yaml
8+
resolver: lts-20.16 # GHC 9.2.7
89

910
packages:
1011
- .
1112

1213
extra-deps:
1314
- github: llvm-hs/llvm-hs
14-
commit: 423220bffac4990d019fc088c46c5f25310d5a33
15+
commit: 80e0de0f96eb78288c88fda0eaba0f7cf5d38a30 # llvm-15, 2023-04-03
1516
subdirs:
1617
- llvm-hs
1718
- llvm-hs-pure
18-
- megaparsec-8.0.0
19+
- megaparsec-9.2.2
1920
- prettyprinter-1.6.2
20-
- store-0.7.8@sha256:0b604101fd5053b6d7d56a4ef4c2addf97f4e08fe8cd06b87ef86f958afef3ae,8001
21-
- store-core-0.4.4.4@sha256:a19098ca8419ea4f6f387790e942a7a5d0acf62fe1beff7662f098cfb611334c,1430
22-
- th-utilities-0.2.4.1@sha256:b37d23c8bdabd678aee5a36dd4373049d4179e9a85f34eb437e9cd3f04f435ca,1869
23-
- floating-bits-0.3.0.0@sha256:742bcfcbc21b8daffc995990ee2399ab49550e8f4dd0dff1732d18f57a064c83,2442
21+
- bytestring-0.11.4.0
2422

2523
flags:
2624
llvm-hs:

0 commit comments

Comments
 (0)