Skip to content

Can GHC and Cabal/Stack co-ordinate so that the GHC project provides an architecture type useful for all?

Motivation

The orignal motivation was Stack issue #6379 and Cabal issue #9534/PR #9535. In short, Stack uses Cabal's Arch type and that type does not distinguish certain distinct machine architectures. Fixing that would be a breaking change for Cabal, giving rise to a desire to go back to 'first principles'.

From that origin the question arose: Could GHC provide a 'canonical' machine architecture type, useful to (and used by) all of GHC, the Cabal project and the Stack project? As Cabal's Haddock documentation puts it:

... we really want everyone to be referring to the same or arch by the same name. Variety is not a virtue in this case ...

In connection with that question, I provde below a comparison of the existing types:

GHC constructors (a) Cabal constructors (b)
ArchX86 (s) Tier 1 I386
ArchX86_64 (s) Tier 1 X86_64
ArchPPC (s) Tier 2 PPC
ArchPPC_64 PPC_64ABI (c) (s) Tier 2 PPC64 (c)
ArchS390X (d) n/a
n/a (s) Tier 3 S390 (d) (q)
ArchARM ArmISA [ArmISAExt] ArmABI (e) (s) Tier 3 (ARMv7) Arm (e)
ArchAArch64 Tier 1 AArch64
ArchAlpha Alpha
ArchMipseb Mips (f)
ArchMipsel Note (f)
ArchRISCV64 (g)
ArchLoongArch64 (h)
ArchJavaScript JavaScript
ArchWasm32 Wasm32
ArchUnknown (i) OtherArch String (i)
n/a Sparc (j) (q)
n/a SH (k) (q)
n/a IA64 (l) (r)
n/a Hppa (m) (r)
n/a Rs6000 (n) (r)
n/a M68k (o) (r)
n/a Vax (p) (r)

(a) https://gitlab.haskell.org/ghc/ghc/-/blob/master/libraries/ghc-platform/src/GHC/Platform/ArchOS.hs as at 21 Dec 2023.

(b) https://hackage.haskell.org/package/Cabal-syntax-3.10.2.0/docs/Distribution-System.html.

(c) GHC appears to distinguish 64-bit PowerPC endianness through PPC_64ABI constructors. Cabal (wrongly) treats "powerpc64" (likely big-endian) and "powerpc64le" (little-endian) as synonyms.

(d) GHC's ArchS390X presumably relates to s390x (the 64 bit architecture of IBM mainframes). Cabal's S390 presumably relates to s390 (the predecessor 32-bit architecture).

(e) GHC distinguishes a significant number of possible ARM (Acorn RISC Machine) varieties, however it does not appear to distinguish endianness. Cabal (wrongly?) treats "arm" (likely little-endian), "armel" (little-endian) and "armeb" (big-endian) as synoynms.

(f) Cabal (wrongly) treats "mips" (likely big-endian), "mipseb" (big-endian) and "mipsel" (little-endian) as synonyms.

(g) GHC's ArchRISCV64 presumably relates to riscv64 (the 64 bit varient of RISC-V).

(h) GHC's ArchLoongArch64 presumably relates to loongarch64 (64bit Loongson architecture).

(i) GHC's ArchUnknown constructor does not preserve any information about the architecture; Cabal's OtherArch preserves the System.Info.arch or other architecture string; that information is used (e.g in error messages for Cabal users).

(j) Cabal's Sparc presumably relates to sparc (Sun's Scalable Processor ARChitecture). Cabal (wrongly) treats "sparc" (32-bit), "sun4" (32-bit) and "sparc64" (64-bit) as synonyms.

(k) Cabal's SH presumably relates to sh4 (SuperH-4).

(l) Cabal's IA64 presumably relates to ia64 (Intel Architecture 64-bit).

(m) Cabal's Hppa presumably relates to hppa (Hewlett-Packard Precision Architecture).

(n) Cabal's Rs6000 presumably relates to rs6000 (IBM RISC System/6000).

(o) Cabal's M68k presumably relates to m68k (Motorola 68000).

(p) Cabal's Vax presumably relates to vax (DEC's Virtual Address eXtension).

(q) Not entirely obsolete, but its prevelance has significantly reduced (according to ChatGPT).

(r) Largely, or entirely, obsolete (according to ChatGPT).

(s) Tiers 1 to 3 based on the classification at https://gitlab.haskell.org/ghc/ghc/-/wikis/platforms/ as at 21 Dec 2023.

Proposal

I don't make a concrete proposal here, but open the issue to allow discussion. Does GHC/Cabal/Stack need to recognise the possible endianness of ARM? Should GHC recognise (not entirely obsolete) (32-bit) Sparc or, at least, 64-bit Sparc; SuperH-4; or (32-bit) S390? Could GHC include extra information for 'unknown'/'other' architectures? Could Cabal drop machine architectures that are obsolete, or largely obsolete, and not currently covered by GHC?

Edited by Mike Pilgrem
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information