@@ -0,0 +1,5067 @@
1+diff --git a/boot b/boot
2+index d57dcc8..62fb492 100755
3+--- a/boot
4++++ b/boot
5+@@ -113,12 +113,13 @@ def boot_pkgs():
6+ elif len(cabals) == 1:
7+ cabal = cabals[0]
8+
9+- if os.path.isfile(cabal):
10++ ghc_mk = os.path.join(package, 'ghc.mk')
11++
12++ if os.path.isfile(cabal) and not os.path.isfile(ghc_mk):
13+ # strip both .cabal and .in
14+ pkg = os.path.splitext(os.path.splitext(os.path.basename(cabal))[0])[0]
15+ top = os.path.join(*['..'] * len(os.path.normpath(package).split(os.path.sep)))
16+
17+- ghc_mk = os.path.join(package, 'ghc.mk')
18+ print('Creating %s' % ghc_mk)
19+ with open(ghc_mk, 'w') as f:
20+ f.write(dedent(
21+diff --git a/compiler/cmm/SMRep.hs b/compiler/cmm/SMRep.hs
22+index 7436315..b72ab70 100644
23+--- a/compiler/cmm/SMRep.hs
24++++ b/compiler/cmm/SMRep.hs
25+@@ -421,8 +421,8 @@ cardTableSizeW dflags elems =
26+ -----------------------------------------------------------------------------
27+ -- deriving the RTS closure type from an SMRep
28+
29+-#include "../includes/rts/storage/ClosureTypes.h"
30+-#include "../includes/rts/storage/FunTypes.h"
31++#include "rts/storage/ClosureTypes.h"
32++#include "rts/storage/FunTypes.h"
33+ -- Defines CONSTR, CONSTR_1_0 etc
34+
35+ -- | Derives the RTS closure type from an 'SMRep'
36+diff --git a/compiler/codeGen/CodeGen/Platform/ARM.hs b/compiler/codeGen/CodeGen/Platform/ARM.hs
37+index a2cb476..f1ea503 100644
38+--- a/compiler/codeGen/CodeGen/Platform/ARM.hs
39++++ b/compiler/codeGen/CodeGen/Platform/ARM.hs
40+@@ -6,5 +6,5 @@ import GhcPrelude
41+
42+ #define MACHREGS_NO_REGS 0
43+ #define MACHREGS_arm 1
44+-#include "../../../../includes/CodeGen.Platform.hs"
45++#include "CodeGen.Platform.hs"
46+
47+diff --git a/compiler/codeGen/CodeGen/Platform/ARM64.hs b/compiler/codeGen/CodeGen/Platform/ARM64.hs
48+index 6ace181..7a25fb8 100644
49+--- a/compiler/codeGen/CodeGen/Platform/ARM64.hs
50++++ b/compiler/codeGen/CodeGen/Platform/ARM64.hs
51+@@ -6,5 +6,5 @@ import GhcPrelude
52+
53+ #define MACHREGS_NO_REGS 0
54+ #define MACHREGS_aarch64 1
55+-#include "../../../../includes/CodeGen.Platform.hs"
56++#include "CodeGen.Platform.hs"
57+
58+diff --git a/compiler/codeGen/CodeGen/Platform/NoRegs.hs b/compiler/codeGen/CodeGen/Platform/NoRegs.hs
59+index 4c074ee..4a34c78 100644
60+--- a/compiler/codeGen/CodeGen/Platform/NoRegs.hs
61++++ b/compiler/codeGen/CodeGen/Platform/NoRegs.hs
62+@@ -5,5 +5,5 @@ module CodeGen.Platform.NoRegs where
63+ import GhcPrelude
64+
65+ #define MACHREGS_NO_REGS 1
66+-#include "../../../../includes/CodeGen.Platform.hs"
67++#include "CodeGen.Platform.hs"
68+
69+diff --git a/compiler/codeGen/CodeGen/Platform/PPC.hs b/compiler/codeGen/CodeGen/Platform/PPC.hs
70+index f7eae6b..7dd4587 100644
71+--- a/compiler/codeGen/CodeGen/Platform/PPC.hs
72++++ b/compiler/codeGen/CodeGen/Platform/PPC.hs
73+@@ -6,5 +6,5 @@ import GhcPrelude
74+
75+ #define MACHREGS_NO_REGS 0
76+ #define MACHREGS_powerpc 1
77+-#include "../../../../includes/CodeGen.Platform.hs"
78++#include "CodeGen.Platform.hs"
79+
80+diff --git a/compiler/codeGen/CodeGen/Platform/SPARC.hs b/compiler/codeGen/CodeGen/Platform/SPARC.hs
81+index 5d8dbb1..2eeb55c 100644
82+--- a/compiler/codeGen/CodeGen/Platform/SPARC.hs
83++++ b/compiler/codeGen/CodeGen/Platform/SPARC.hs
84+@@ -6,5 +6,5 @@ import GhcPrelude
85+
86+ #define MACHREGS_NO_REGS 0
87+ #define MACHREGS_sparc 1
88+-#include "../../../../includes/CodeGen.Platform.hs"
89++#include "CodeGen.Platform.hs"
90+
91+diff --git a/compiler/codeGen/CodeGen/Platform/X86.hs b/compiler/codeGen/CodeGen/Platform/X86.hs
92+index 84d52c1..fc3e384 100644
93+--- a/compiler/codeGen/CodeGen/Platform/X86.hs
94++++ b/compiler/codeGen/CodeGen/Platform/X86.hs
95+@@ -6,5 +6,5 @@ import GhcPrelude
96+
97+ #define MACHREGS_NO_REGS 0
98+ #define MACHREGS_i386 1
99+-#include "../../../../includes/CodeGen.Platform.hs"
100++#include "CodeGen.Platform.hs"
101+
102+diff --git a/compiler/codeGen/CodeGen/Platform/X86_64.hs b/compiler/codeGen/CodeGen/Platform/X86_64.hs
103+index 1b2b554..0a26a1f 100644
104+--- a/compiler/codeGen/CodeGen/Platform/X86_64.hs
105++++ b/compiler/codeGen/CodeGen/Platform/X86_64.hs
106+@@ -6,5 +6,5 @@ import GhcPrelude
107+
108+ #define MACHREGS_NO_REGS 0
109+ #define MACHREGS_x86_64 1
110+-#include "../../../../includes/CodeGen.Platform.hs"
111++#include "CodeGen.Platform.hs"
112+
113+diff --git a/compiler/codeGen/StgCmmClosure.hs b/compiler/codeGen/StgCmmClosure.hs
114+index 6f0feaa..4a4b0ed 100644
115+--- a/compiler/codeGen/StgCmmClosure.hs
116++++ b/compiler/codeGen/StgCmmClosure.hs
117+@@ -62,7 +62,7 @@ module StgCmmClosure (
118+ staticClosureNeedsLink,
119+ ) where
120+
121+-#include "../includes/MachDeps.h"
122++#include "MachDeps.h"
123+
124+ #include "HsVersions.h"
125+
126+diff --git a/compiler/codeGen/StgCmmLayout.hs b/compiler/codeGen/StgCmmLayout.hs
127+index 78a7cf3..4898eba 100644
128+--- a/compiler/codeGen/StgCmmLayout.hs
129++++ b/compiler/codeGen/StgCmmLayout.hs
130+@@ -526,7 +526,7 @@ mkVirtConstrSizes dflags field_reps
131+ -------------------------------------------------------------------------
132+
133+ -- bring in ARG_P, ARG_N, etc.
134+-#include "../includes/rts/storage/FunTypes.h"
135++#include "rts/storage/FunTypes.h"
136+
137+ mkArgDescr :: DynFlags -> [Id] -> ArgDescr
138+ mkArgDescr dflags args
139+diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in
140+index 01628dc..6be809a 100644
141+--- a/compiler/ghc.cabal.in
142++++ b/compiler/ghc.cabal.in
143+@@ -20,23 +20,29 @@ Category: Development
144+ Build-Type: Simple
145+ Cabal-Version: >=1.10
146+
147++extra-source-files:
148++ utils/md5.h
149++ Unique.h
150++ nativeGen/NCG.h
151++ parser/cutils.h
152++
153+ Flag ghci
154+ Description: Build GHCi support.
155+ Default: False
156+ Manual: True
157+
158+ Flag stage1
159+- Description: Is this stage 1?
160++ Description: Build Stage1 GHC (STAGE=1)
161+ Default: False
162+ Manual: True
163+
164+ Flag stage2
165+- Description: Is this stage 2?
166+- Default: False
167++ Description: Build Stage1 GHC (STAGE=2)
168++ Default: True
169+ Manual: True
170+
171+ Flag stage3
172+- Description: Is this stage 3?
173++ Description: Build Stage1 GHC (STAGE=3)
174+ Default: False
175+ Manual: True
176+
177+@@ -67,6 +73,9 @@ Library
178+ ghc-heap == @ProjectVersionMunged@,
179+ ghci == @ProjectVersionMunged@
180+
181++ build-tool-depends: alex:alex,
182++ happy:happy
183++
184+ if os(windows)
185+ Build-Depends: Win32 >= 2.3 && < 2.7
186+ else
187+@@ -80,6 +89,15 @@ Library
188+ -Wnoncanonical-monadfail-instances
189+ -Wnoncanonical-monoid-instances
190+
191++ if flag(stage1)
192++ ghc-options: -DSTAGE=1
193++ else
194++ if flag(stage2)
195++ ghc-options: -DSTAGE=2
196++ else
197++ if flag(stage3)
198++ ghc-options: -DSTAGE=3
199++
200+ if flag(ghci)
201+ CPP-Options: -DGHCI
202+ Include-Dirs: ../rts/dist/build @FFIIncludeDir@
203+@@ -119,17 +137,6 @@ Library
204+ -- as it's magic.
205+ GHC-Options: -this-unit-id ghc
206+
207+- if flag(stage1)
208+- Include-Dirs: stage1
209+- else
210+- if flag(stage2)
211+- Include-Dirs: stage2
212+- else
213+- if flag(stage3)
214+- Include-Dirs: stage2
215+-
216+- Install-Includes: HsVersions.h, ghc_boot_platform.h
217+-
218+ c-sources:
219+ parser/cutils.c
220+ ghci/keepCAFsForGHCi.c
221+diff --git a/compiler/ghc.mk b/compiler/ghc.mk
222+index 9bc6b3f..710ac64 100644
223+--- a/compiler/ghc.mk
224++++ b/compiler/ghc.mk
225+@@ -30,9 +30,7 @@ compiler_stage1_C_FILES_NODEPS = compiler/parser/cutils.c
226+ compiler_NO_CHECK = YES
227+
228+ ifneq "$(BINDIST)" "YES"
229+-compiler/stage1/package-data.mk : compiler/stage1/build/Config.hs
230+-compiler/stage2/package-data.mk : compiler/stage2/build/Config.hs
231+-compiler/stage3/package-data.mk : compiler/stage3/build/Config.hs
232++compiler/main/Config.hs : rts/build/config.hs-incl
233+
234+ compiler/stage1/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
235+ compiler/stage2/build/PlatformConstants.o: $(includes_GHCCONSTANTS_HASKELL_TYPE)
236+@@ -45,274 +43,6 @@
237+ compiler/stage3/build/DynFlags.o: $(includes_GHCCONSTANTS_HASKELL_WRAPPERS)
238+ endif
239+
240+-compiler/stage%/build/Config.hs : mk/config.mk mk/project.mk | $$(dir $$@)/.
241+- $(call removeFiles,$@)
242+- @echo 'Creating $@ ... '
243+- @echo '{-# LANGUAGE CPP #-}' >> $@
244+- @echo 'module Config where' >> $@
245+- @echo >> $@
246+- @echo 'import GhcPrelude' >> $@
247+- @echo >> $@
248+- @echo '#include "ghc_boot_platform.h"' >> $@
249+- @echo >> $@
250+- @echo 'data IntegerLibrary = IntegerGMP' >> $@
251+- @echo ' | IntegerSimple' >> $@
252+- @echo ' deriving Eq' >> $@
253+- @echo >> $@
254+- @echo 'cBuildPlatformString :: String' >> $@
255+- @echo 'cBuildPlatformString = BuildPlatform_NAME' >> $@
256+- @echo 'cHostPlatformString :: String' >> $@
257+- @echo 'cHostPlatformString = HostPlatform_NAME' >> $@
258+- @echo 'cTargetPlatformString :: String' >> $@
259+- @echo 'cTargetPlatformString = TargetPlatform_NAME' >> $@
260+- @echo >> $@
261+- @echo 'cProjectName :: String' >> $@
262+- @echo 'cProjectName = "$(ProjectName)"' >> $@
263+- @echo 'cProjectGitCommitId :: String' >> $@
264+- @echo 'cProjectGitCommitId = "$(ProjectGitCommitId)"' >> $@
265+- @echo 'cProjectVersion :: String' >> $@
266+- @echo 'cProjectVersion = "$(ProjectVersion)"' >> $@
267+- @echo 'cProjectVersionInt :: String' >> $@
268+- @echo 'cProjectVersionInt = "$(ProjectVersionInt)"' >> $@
269+- @echo 'cProjectPatchLevel :: String' >> $@
270+- @echo 'cProjectPatchLevel = "$(ProjectPatchLevel)"' >> $@
271+- @echo 'cProjectPatchLevel1 :: String' >> $@
272+- @echo 'cProjectPatchLevel1 = "$(ProjectPatchLevel1)"' >> $@
273+- @echo 'cProjectPatchLevel2 :: String' >> $@
274+- @echo 'cProjectPatchLevel2 = "$(ProjectPatchLevel2)"' >> $@
275+- @echo 'cBooterVersion :: String' >> $@
276+- @echo 'cBooterVersion = "$(GhcVersion)"' >> $@
277+- @echo 'cStage :: String' >> $@
278+- @echo 'cStage = show (STAGE :: Int)' >> $@
279+- @echo 'cIntegerLibraryType :: IntegerLibrary' >> $@
280+-ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
281+- @echo 'cIntegerLibraryType = IntegerGMP' >> $@
282+-else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
283+- @echo 'cIntegerLibraryType = IntegerSimple' >> $@
284+-else ifneq "$(CLEANING)" "YES"
285+-$(error Unknown integer library)
286+-endif
287+- @echo 'cSupportsSplitObjs :: String' >> $@
288+- @echo 'cSupportsSplitObjs = "$(SupportsSplitObjs)"' >> $@
289+- @echo 'cGhcWithInterpreter :: String' >> $@
290+- @echo 'cGhcWithInterpreter = "$(GhcWithInterpreter)"' >> $@
291+- @echo 'cGhcWithNativeCodeGen :: String' >> $@
292+- @echo 'cGhcWithNativeCodeGen = "$(GhcWithNativeCodeGen)"' >> $@
293+- @echo 'cGhcWithSMP :: String' >> $@
294+- @echo 'cGhcWithSMP = "$(GhcWithSMP)"' >> $@
295+- @echo 'cGhcRTSWays :: String' >> $@
296+- @echo 'cGhcRTSWays = "$(GhcRTSWays)"' >> $@
297+- @echo 'cGhcRtsWithLibdw :: Bool' >> $@
298+-ifeq "$(GhcRtsWithLibdw)" "YES"
299+- @echo 'cGhcRtsWithLibdw = True' >> $@
300+-else
301+- @echo 'cGhcRtsWithLibdw = False' >> $@
302+-endif
303+- @echo 'cGhcEnableTablesNextToCode :: String' >> $@
304+- @echo 'cGhcEnableTablesNextToCode = "$(GhcEnableTablesNextToCode)"' >> $@
305+- @echo 'cLeadingUnderscore :: String' >> $@
306+- @echo 'cLeadingUnderscore = "$(LeadingUnderscore)"' >> $@
307+- @echo 'cGHC_UNLIT_PGM :: String' >> $@
308+- @echo 'cGHC_UNLIT_PGM = "$(utils/unlit_dist_PROG)"' >> $@
309+- @echo 'cGHC_SPLIT_PGM :: String' >> $@
310+- @echo 'cGHC_SPLIT_PGM = "$(driver/split_dist_PROG)"' >> $@
311+- @echo 'cLibFFI :: Bool' >> $@
312+-ifeq "$(UseLibFFIForAdjustors)" "YES"
313+- @echo 'cLibFFI = True' >> $@
314+-else
315+- @echo 'cLibFFI = False' >> $@
316+-endif
317+-# Note that GhcThreaded just reflects the Makefile variable setting.
318+-# In particular, the stage1 compiler is never actually compiled with
319+-# -threaded, but it will nevertheless have cGhcThreaded = True.
320+-# The "+RTS --info" output will show what RTS GHC is really using.
321+- @echo 'cGhcThreaded :: Bool' >> $@
322+-ifeq "$(GhcThreaded)" "YES"
323+- @echo 'cGhcThreaded = True' >> $@
324+-else
325+- @echo 'cGhcThreaded = False' >> $@
326+-endif
327+- @echo 'cGhcDebugged :: Bool' >> $@
328+-ifeq "$(GhcDebugged)" "YES"
329+- @echo 'cGhcDebugged = True' >> $@
330+-else
331+- @echo 'cGhcDebugged = False' >> $@
332+-endif
333+- @echo done.
334+-
335+-# -----------------------------------------------------------------------------
336+-# Create platform includes
337+-
338+-# Here we generate a little header file containing CPP symbols that GHC
339+-# uses to determine which platform it is building on/for. The platforms
340+-# can differ between stage1 and stage2 if we're cross-compiling, so we
341+-# need one of these header files per stage.
342+-
343+-PLATFORM_H = ghc_boot_platform.h
344+-
345+-compiler/stage1/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
346+- $(call removeFiles,$@)
347+- @echo "Creating $@..."
348+- @echo "#ifndef __PLATFORM_H__" >> $@
349+- @echo "#define __PLATFORM_H__" >> $@
350+- @echo >> $@
351+- @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
352+- @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
353+- @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
354+- @echo >> $@
355+- @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
356+- @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
357+- @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
358+- @echo >> $@
359+- @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
360+- @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
361+- @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
362+- @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
363+- @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
364+- @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
365+- @echo "#define LLVM_TARGET \"$(LLVMTarget_CPP)\"" >> $@
366+- @echo >> $@
367+- @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
368+- @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
369+- @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
370+- @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
371+- @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
372+- @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
373+- @echo >> $@
374+- @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
375+- @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
376+- @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
377+- @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
378+- @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
379+- @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
380+- @echo >> $@
381+- @echo "#endif /* __PLATFORM_H__ */" >> $@
382+- @echo "Done."
383+-
384+-# For stage2 and above, the BUILD platform is the HOST of stage1, and
385+-# the HOST platform is the TARGET of stage1. The TARGET remains the same
386+-# (stage1 is the cross-compiler, not stage2).
387+-compiler/stage2/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
388+- $(call removeFiles,$@)
389+- @echo "Creating $@..."
390+- @echo "#ifndef __PLATFORM_H__" >> $@
391+- @echo "#define __PLATFORM_H__" >> $@
392+- @echo >> $@
393+- @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
394+- @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
395+- @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
396+- @echo >> $@
397+- @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
398+- @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
399+- @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
400+- @echo >> $@
401+- @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
402+- @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
403+- @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
404+- @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
405+- @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
406+- @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
407+- @echo "#define LLVM_TARGET \"$(LLVMTarget_CPP)\"" >> $@
408+- @echo >> $@
409+- @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
410+- @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
411+- @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
412+- @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
413+- @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
414+- @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
415+- @echo >> $@
416+- @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
417+- @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
418+- @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
419+- @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
420+- @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
421+- @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
422+- @echo >> $@
423+- @echo "#endif /* __PLATFORM_H__ */" >> $@
424+- @echo "Done."
425+-
426+-compiler/stage3/$(PLATFORM_H) : compiler/stage2/$(PLATFORM_H)
427+- "$(CP)" $< $@
428+-
429+-# ----------------------------------------------------------------------------
430+-# Generate supporting stuff for prelude/PrimOp.hs
431+-# from prelude/primops.txt
432+-
433+-PRIMOP_BITS_NAMES = primop-data-decl.hs-incl \
434+- primop-tag.hs-incl \
435+- primop-list.hs-incl \
436+- primop-has-side-effects.hs-incl \
437+- primop-out-of-line.hs-incl \
438+- primop-commutable.hs-incl \
439+- primop-code-size.hs-incl \
440+- primop-can-fail.hs-incl \
441+- primop-strictness.hs-incl \
442+- primop-fixity.hs-incl \
443+- primop-primop-info.hs-incl \
444+- primop-vector-uniques.hs-incl \
445+- primop-vector-tys.hs-incl \
446+- primop-vector-tys-exports.hs-incl \
447+- primop-vector-tycons.hs-incl
448+-
449+-PRIMOP_BITS_STAGE1 = $(addprefix compiler/stage1/build/,$(PRIMOP_BITS_NAMES))
450+-PRIMOP_BITS_STAGE2 = $(addprefix compiler/stage2/build/,$(PRIMOP_BITS_NAMES))
451+-PRIMOP_BITS_STAGE3 = $(addprefix compiler/stage3/build/,$(PRIMOP_BITS_NAMES))
452+-
453+-compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
454+-compiler_CPP_OPTS += ${GhcCppOpts}
455+-
456+-# We add these paths to the Haskell compiler's #include search path list since
457+-# we must avoid #including files by paths relative to the source file as Hadrian
458+-# moves the build artifacts out of the source tree. See #8040.
459+-compiler_HC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
460+-
461+-define preprocessCompilerFiles
462+-# $0 = stage
463+-compiler/stage$1/build/primops.txt: compiler/prelude/primops.txt.pp compiler/stage$1/$$(PLATFORM_H)
464+- $$(HS_CPP) -P $$(compiler_CPP_OPTS) -Icompiler/stage$1 -x c $$< | grep -v '^#pragma GCC' > $$@
465+-
466+-compiler/stage$1/build/primop-data-decl.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
467+- "$$(genprimopcode_INPLACE)" --data-decl < $$< > $$@
468+-compiler/stage$1/build/primop-tag.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
469+- "$$(genprimopcode_INPLACE)" --primop-tag < $$< > $$@
470+-compiler/stage$1/build/primop-list.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
471+- "$$(genprimopcode_INPLACE)" --primop-list < $$< > $$@
472+-compiler/stage$1/build/primop-has-side-effects.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
473+- "$$(genprimopcode_INPLACE)" --has-side-effects < $$< > $$@
474+-compiler/stage$1/build/primop-out-of-line.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
475+- "$$(genprimopcode_INPLACE)" --out-of-line < $$< > $$@
476+-compiler/stage$1/build/primop-commutable.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
477+- "$$(genprimopcode_INPLACE)" --commutable < $$< > $$@
478+-compiler/stage$1/build/primop-code-size.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
479+- "$$(genprimopcode_INPLACE)" --code-size < $$< > $$@
480+-compiler/stage$1/build/primop-can-fail.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
481+- "$$(genprimopcode_INPLACE)" --can-fail < $$< > $$@
482+-compiler/stage$1/build/primop-strictness.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
483+- "$$(genprimopcode_INPLACE)" --strictness < $$< > $$@
484+-compiler/stage$1/build/primop-fixity.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
485+- "$$(genprimopcode_INPLACE)" --fixity < $$< > $$@
486+-compiler/stage$1/build/primop-primop-info.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
487+- "$$(genprimopcode_INPLACE)" --primop-primop-info < $$< > $$@
488+-compiler/stage$1/build/primop-vector-uniques.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
489+- "$$(genprimopcode_INPLACE)" --primop-vector-uniques < $$< > $$@
490+-compiler/stage$1/build/primop-vector-tys.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
491+- "$$(genprimopcode_INPLACE)" --primop-vector-tys < $$< > $$@
492+-compiler/stage$1/build/primop-vector-tys-exports.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
493+- "$$(genprimopcode_INPLACE)" --primop-vector-tys-exports < $$< > $$@
494+-compiler/stage$1/build/primop-vector-tycons.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
495+- "$$(genprimopcode_INPLACE)" --primop-vector-tycons < $$< > $$@
496+-
497+-# Usages aren't used any more; but the generator
498+-# can still generate them if we want them back
499+-compiler/stage$1/build/primop-usage.hs-incl: compiler/stage$1/build/primops.txt $$$$(genprimopcode_INPLACE)
500+- "$$(genprimopcode_INPLACE)" --usage < $$< > $$@
501+-
502+-endef
503+-
504+-$(eval $(call preprocessCompilerFiles,1))
505+-$(eval $(call preprocessCompilerFiles,2))
506+-$(eval $(call preprocessCompilerFiles,3))
507+-
508+ # -----------------------------------------------------------------------------
509+ # Configuration
510+
511+@@ -367,19 +97,6 @@
512+ compiler_stage2_CONFIGURE_OPTS += --flags=-terminfo
513+ endif
514+
515+-# Careful optimisation of the parser: we don't want to throw everything
516+-# at it, because that takes too long and doesn't buy much, but we do want
517+-# to inline certain key external functions, so we instruct GHC not to
518+-# throw away inlinings as it would normally do in -O0 mode.
519+-# Since GHC version 7.8, we need -fcmm-sink to be
520+-# passed to the compiler. This is required on x86 to avoid the
521+-# register allocator running out of stack slots when compiling this
522+-# module with -fPIC -dynamic.
523+-# See #8182 for all the details
524+-compiler/stage1/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
525+-compiler/stage2/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
526+-compiler/stage3/build/Parser_HC_OPTS += -O0 -fno-ignore-interface-pragmas -fcmm-sink
527+-
528+ ifeq "$(GhcProfiled)" "YES"
529+ # If we're profiling GHC then we want SCCs. However, adding -auto-all
530+ # everywhere tends to give a hard-to-read profile, and adds lots of
531+@@ -405,9 +122,6 @@
532+
533+ compiler_stage3_CONFIGURE_OPTS := $(compiler_stage2_CONFIGURE_OPTS)
534+
535+-compiler_stage1_CONFIGURE_OPTS += --ghc-option=-DSTAGE=1
536+-compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DSTAGE=2
537+-compiler_stage3_CONFIGURE_OPTS += --ghc-option=-DSTAGE=3
538+ compiler_stage2_HADDOCK_OPTS += --optghc=-DSTAGE=2
539+
540+ compiler/stage1/package-data.mk : compiler/ghc.mk
541+@@ -485,10 +199,6 @@
542+ compiler_stage2_TAGS_HC_OPTS = -package ghc
543+ $(eval $(call tags-package,compiler,stage2))
544+
545+-$(compiler_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
546+-$(compiler_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
547+-$(compiler_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
548+-
549+ COMPILER_INCLUDES_DEPS += $(includes_H_CONFIG)
550+ COMPILER_INCLUDES_DEPS += $(includes_H_PLATFORM)
551+ COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS)
552+@@ -497,9 +207,13 @@
553+ COMPILER_INCLUDES_DEPS += $(includes_GHCCONSTANTS_HASKELL_EXPORTS)
554+ COMPILER_INCLUDES_DEPS += $(includes_DERIVEDCONSTANTS)
555+
556+-$(compiler_stage1_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE1)
557+-$(compiler_stage2_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE2)
558+-$(compiler_stage3_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE3)
559++$(compiler_stage1_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE1) libraries/ghc-prim/dist-boot/ghc_boot_platform.h
560++$(compiler_stage2_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE2) libraries/ghc-prim/dist-install/ghc_boot_platform.h
561++$(compiler_stage3_depfile_haskell) : $(COMPILER_INCLUDES_DEPS) $(PRIMOP_BITS_STAGE3) libraries/ghc-prim/dist-install/ghc_boot_platform.h
562++
563++compiler_stage1_HC_OPTS += -Ilibraries/ghc-prim/dist-boot -Irts/build
564++compiler_stage2_HC_OPTS += -Ilibraries/ghc-prim/dist-install -Irts/build
565++compiler_stage3_HC_OPTS += -Ilibraries/ghc-prim/dist-install -Irts/build
566+
567+ $(foreach way,$(compiler_stage1_WAYS),\
568+ compiler/stage1/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE1)
569+@@ -509,10 +223,6 @@
570+ compiler/stage3/build/PrimOp.$($(way)_osuf)) : $(PRIMOP_BITS_STAGE3)
571+
572+
573+-# GHC itself doesn't know about the above dependencies, so we have to
574+-# switch off the recompilation checker for that module:
575+-compiler/prelude/PrimOp_HC_OPTS += -fforce-recomp
576+-
577+ ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
578+ compiler/utils/Util_HC_OPTS += -DDYNAMIC_GHC_PROGRAMS
579+ endif
580+diff --git a/compiler/ghci/ByteCodeInstr.hs b/compiler/ghci/ByteCodeInstr.hs
581+index 07dcd22..cc44033 100644
582+--- a/compiler/ghci/ByteCodeInstr.hs
583++++ b/compiler/ghci/ByteCodeInstr.hs
584+@@ -10,6 +10,6 @@ module ByteCodeInstr (
585+ ) where
586+
587+ #include "HsVersions.h"
588+-#include "../includes/MachDeps.h"
589++#include "MachDeps.h"
590+
591+ import GhcPrelude
592+
593+diff --git a/compiler/main/Config.hs b/compiler/main/Config.hs
594+new file mode 100644
595+index 0000000..f944f7a
596+--- /dev/null
597++++ b/compiler/main/Config.hs
598+@@ -0,0 +1,7 @@
599++{-# LANGUAGE CPP #-}
600++module Config where
601++
602++import GhcPrelude
603++
604++#include "ghc_boot_platform.h"
605++#include "config.hs-incl"
606+\ No newline at end of file
607+diff -u a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
608+--- a/compiler/main/DynFlags.hs
609++++ b/compiler/main/DynFlags.hs
610+@@ -250,8 +250,9 @@
611+ import GHC.Foreign (withCString, peekCString)
612+ import qualified GHC.LanguageExtensions as LangExt
613+
614+-#if defined(GHCI)
615+-import Foreign (Ptr) -- needed for 2nd stage
616++#if defined(GHCI) || STAGE >= 2
617++-- used by SHARED_GLOBAL_VAR
618++import Foreign (Ptr)
619+ #endif
620+
621+ -- Note [Updating flag description in the User's Guide]
622+diff --git a/compiler/nativeGen/PPC/CodeGen.hs b/compiler/nativeGen/PPC/CodeGen.hs
623+index 88b9692..d73de55 100644
624+--- a/compiler/nativeGen/PPC/CodeGen.hs
625++++ b/compiler/nativeGen/PPC/CodeGen.hs
626+@@ -22,7 +22,7 @@ where
627+
628+ #include "HsVersions.h"
629+ #include "nativeGen/NCG.h"
630+-#include "../includes/MachDeps.h"
631++#include "MachDeps.h"
632+
633+ -- NCG stuff:
634+ import GhcPrelude
635+diff --git a/compiler/nativeGen/SPARC/CodeGen.hs b/compiler/nativeGen/SPARC/CodeGen.hs
636+index 98e062d..e6b3446 100644
637+--- a/compiler/nativeGen/SPARC/CodeGen.hs
638++++ b/compiler/nativeGen/SPARC/CodeGen.hs
639+@@ -19,7 +19,7 @@ where
640+
641+ #include "HsVersions.h"
642+ #include "nativeGen/NCG.h"
643+-#include "../includes/MachDeps.h"
644++#include "MachDeps.h"
645+
646+ -- NCG stuff:
647+ import GhcPrelude
648+diff --git a/compiler/nativeGen/X86/CodeGen.hs b/compiler/nativeGen/X86/CodeGen.hs
649+index 4551754..89a59dd 100644
650+--- a/compiler/nativeGen/X86/CodeGen.hs
651++++ b/compiler/nativeGen/X86/CodeGen.hs
652+@@ -27,7 +27,7 @@ where
653+
654+ #include "HsVersions.h"
655+ #include "nativeGen/NCG.h"
656+-#include "../includes/MachDeps.h"
657++#include "MachDeps.h"
658+
659+ -- NCG stuff:
660+ import GhcPrelude
661+diff --git a/compiler/parser/Parser.hs b/compiler/parser/Parser.hs
662+index 60395cc..3fba0f9 100644
663+--- a/compiler/parser/Parser.hs
664++++ b/compiler/parser/Parser.hs
665+@@ -3,6 +3,17 @@
666+ #if __GLASGOW_HASKELL__ >= 710
667+ {-# OPTIONS_GHC -XPartialTypeSignatures #-}
668+ #endif
669++-- Careful optimisation of the parser: we don't want to throw everything
670++-- at it, because that takes too long and doesn't buy much, but we do want
671++-- to inline certain key external functions, so we instruct GHC not to
672++-- throw away inlinings as it would normally do in -O0 mode.
673++-- Since GHC version 7.8, we need -fcmm-sink to be
674++-- passed to the compiler. This is required on x86 to avoid the
675++-- register allocator running out of stack slots when compiling this
676++-- module with -fPIC -dynamic.
677++-- See #8182 for all the details
678++{-# OPTIONS_GHC -O0 -fno-ignore-interface-pragmas -fcmm-sink #-}
679++
680+ {-# LANGUAGE ViewPatterns #-}
681+ {-# LANGUAGE TypeFamilies #-}
682+
683+diff --git a/compiler/parser/Parser.y.source b/compiler/parser/Parser.y.source
684+index d038562..cba0f36 100644
685+--- a/compiler/parser/Parser.y.source
686++++ b/compiler/parser/Parser.y.source
687+@@ -8,6 +8,17 @@
688+ -- ---------------------------------------------------------------------------
689+
690+ {
691++-- Careful optimisation of the parser: we don't want to throw everything
692++-- at it, because that takes too long and doesn't buy much, but we do want
693++-- to inline certain key external functions, so we instruct GHC not to
694++-- throw away inlinings as it would normally do in -O0 mode.
695++-- Since GHC version 7.8, we need -fcmm-sink to be
696++-- passed to the compiler. This is required on x86 to avoid the
697++-- register allocator running out of stack slots when compiling this
698++-- module with -fPIC -dynamic.
699++-- See #8182 for all the details
700++{-# OPTIONS_GHC -O0 -fno-ignore-interface-pragmas -fcmm-sink #-}
701++
702+ {-# LANGUAGE ViewPatterns #-}
703+ {-# LANGUAGE TypeFamilies #-}
704+
705+diff --git a/compiler/prelude/PrelRules.hs b/compiler/prelude/PrelRules.hs
706+index bc9342b..cabfe0c 100644
707+--- a/compiler/prelude/PrelRules.hs
708++++ b/compiler/prelude/PrelRules.hs
709+@@ -23,7 +23,7 @@ module PrelRules
710+ where
711+
712+ #include "HsVersions.h"
713+-#include "../includes/MachDeps.h"
714++#include "MachDeps.h"
715+
716+ import GhcPrelude
717+
718+diff --git a/compiler/prelude/PrimOp.hs b/compiler/prelude/PrimOp.hs
719+index 369f17f..e1d21df 100644
720+--- a/compiler/prelude/PrimOp.hs
721++++ b/compiler/prelude/PrimOp.hs
722+@@ -8,6 +8,11 @@
723+
724+ -- The default is a bit too low for the quite large primOpInfo definition
725+ {-# OPTIONS_GHC -fmax-pmcheck-iterations=10000000 #-}
726++-- GHC itself doesn't know about the pimop bits, so we have to
727++-- switch off the recompilation checker for that module:
728++{-# OPTIONS_GHC -fforce-recomp #-}
729++
730++
731+
732+ module PrimOp (
733+ PrimOp(..), PrimOpVecCat(..), allThePrimOps,
734+diff --git a/compiler/utils/Binary.hs b/compiler/utils/Binary.hs
735+index 447317c..562d103 100644
736+--- a/compiler/utils/Binary.hs
737++++ b/compiler/utils/Binary.hs
738+@@ -58,7 +58,7 @@ module Binary
739+ #include "HsVersions.h"
740+
741+ -- The *host* architecture version:
742+-#include "../includes/MachDeps.h"
743++#include "MachDeps.h"
744+
745+ import GhcPrelude
746+
747+diff --git a/ghc.mk b/ghc.mk
748+index eed172e..fef69d9 100644
749+--- a/ghc.mk
750++++ b/ghc.mk
751+@@ -590,26 +590,6 @@ BOOT_LIBS = $(foreach lib,$(PACKAGES_STAGE0),$(libraries/$(lib)_dist-boot_v_LIB)
752+ # Only build internal interpreter support for the stage2 ghci lib
753+ libraries/ghci_dist-install_CONFIGURE_OPTS += --flags=ghci
754+
755+-# ----------------------------------------
756+-# Special magic for the ghc-prim package
757+-
758+-# We want the ghc-prim package to include the GHC.Prim module when it
759+-# is registered, but not when it is built, because GHC.Prim is not a
760+-# real source module, it is built-in to GHC.
761+-
762+-# Strip it out again before building the package:
763+-define libraries/ghc-prim_PACKAGE_MAGIC
764+-libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
765+-endef
766+-
767+-PRIMOPS_TXT_STAGE1 = compiler/stage1/build/primops.txt
768+-
769+-libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $$(genprimopcode_INPLACE) $(PRIMOPS_TXT_STAGE1) | $$(dir $$@)/.
770+- "$(genprimopcode_INPLACE)" --make-haskell-wrappers < $(PRIMOPS_TXT_STAGE1) >$@
771+-
772+-# Required so that Haddock documents the primops.
773+-libraries/ghc-prim_dist-install_EXTRA_HADDOCK_SRCS = libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
774+-
775+ # ----------------------------------------
776+ # Special magic for the integer package
777+
778+diff --git a/ghc/ghc.mk b/ghc/ghc.mk
779+index 6e32935..b062443 100644
780+--- a/ghc/ghc.mk
781++++ b/ghc/ghc.mk
782+@@ -14,10 +14,6 @@ ghc_USES_CABAL = YES
783+ ghc_PACKAGE = ghc-bin
784+ ghc_EXECUTABLE = ghc
785+
786+-ghc_stage1_CONFIGURE_OPTS += --flags=stage1
787+-ghc_stage2_CONFIGURE_OPTS += --flags=stage2
788+-ghc_stage3_CONFIGURE_OPTS += --flags=stage3
789+-
790+ ifeq "$(GhcWithInterpreter)" "YES"
791+ ghc_stage2_CONFIGURE_OPTS += --flags=ghci
792+ ghc_stage3_CONFIGURE_OPTS += --flags=ghci
793+@@ -121,9 +117,9 @@ ghc/stage2/build/tmp/$(ghc_stage2_PROG) : $(foreach lib,$(PACKAGES_STAGE1),$(lib
794+ endif
795+
796+ # Modules here import HsVersions.h, so we need ghc_boot_platform.h
797+-$(ghc_stage1_depfile_haskell) : compiler/stage1/$(PLATFORM_H)
798+-$(ghc_stage2_depfile_haskell) : compiler/stage2/$(PLATFORM_H)
799+-$(ghc_stage3_depfile_haskell) : compiler/stage3/$(PLATFORM_H)
800++$(ghc_stage1_depfile_haskell) : libraries/ghc-prim/dist-boot/$(PLATFORM_H)
801++$(ghc_stage2_depfile_haskell) : libraries/ghc-prim/dist-install/$(PLATFORM_H)
802++$(ghc_stage3_depfile_haskell) : libraries/ghc-prim/dist-install/$(PLATFORM_H)
803+
804+ all_ghc_stage1 : $(GHC_STAGE1)
805+ all_ghc_stage2 : $(GHC_STAGE2)
806+@@ -178,6 +174,12 @@ INSTALL_LIBS += settings
807+ INSTALL_LIBS += llvm-targets
808+ INSTALL_LIBS += llvm-passes
809+
810++# A rather nasty hack needed because we still have headers in
811++# ghc-prim and rts.
812++ghc_stage1_HC_OPTS += -Irts/build -Ilibraries/ghc-prim/dist-boot
813++ghc_stage2_HC_OPTS += -Irts/build -Ilibraries/ghc-prim/dist-install
814++ghc_stage3_HC_OPTS += -Irts/build -Ilibraries/ghc-prim/dist-install
815++
816+ ifeq "$(Windows_Host)" "NO"
817+ install: install_ghc_link
818+ .PHONY: install_ghc_link
819+diff --git a/includes/ghc.mk b/includes/ghc.mk
820+index d08ecfb..9358950 100644
821+--- a/includes/ghc.mk
822++++ b/includes/ghc.mk
823+@@ -229,4 +229,6 @@ install_includes :
824+ $(INSTALL_HEADER) $(INSTALL_OPTS) includes/$d/*.h "$(DESTDIR)$(ghcheaderdir)/$d/" && \
825+ ) true
826+ $(INSTALL_HEADER) $(INSTALL_OPTS) $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION) $(includes_DERIVEDCONSTANTS) "$(DESTDIR)$(ghcheaderdir)/"
827++ $(INSTALL_HEADER) rts/build/*.h rts/build/*.hs-incl includes/CodeGen.Platform.hs "$(DESTDIR)$(ghcheaderdir)/"
828++ $(INSTALL_HEADER) $(includes_GHCCONSTANTS_HASKELL_TYPE) $(includes_GHCCONSTANTS_HASKELL_VALUE) $(includes_GHCCONSTANTS_HASKELL_WRAPPERS) $(includes_GHCCONSTANTS_HASKELL_EXPORTS) "$(DESTDIR)$(ghcheaderdir)/"
829+
830+diff --git a/libraries/ghc-prim/.gitignore b/libraries/ghc-prim/.gitignore
831+index 1186a2b..2834a36 100644
832+--- a/libraries/ghc-prim/.gitignore
833++++ b/libraries/ghc-prim/.gitignore
834+@@ -1,5 +1,3 @@
835+ /dist/
836+ /dist-install/
837+-/ghc.mk
838+ /ghc-prim.buildinfo
839+-/GNUmakefile
840+diff --git a/libraries/ghc-prim/ghc-prim.cabal b/libraries/ghc-prim/ghc-prim.cabal
841+index a95f1ec..132fe12 100644
842+--- a/libraries/ghc-prim/ghc-prim.cabal
843++++ b/libraries/ghc-prim/ghc-prim.cabal
844+@@ -12,6 +12,16 @@ build-type: Custom
845+ description:
846+ This package contains the primitive types and operations supplied by GHC.
847+
848++Flag boot
849++ Description: Is this stage 1?
850++ Default: False
851++ Manual: True
852++
853++Flag install
854++ Description: Is this stage 2?
855++ Default: True
856++ Manual: True
857++
858+ extra-source-files: changelog.md
859+
860+ source-repository head
861+@@ -81,3 +91,27 @@ Library
862+ -- We need to set the unit ID to ghc-prim (without a version number)
863+ -- as it's magic.
864+ ghc-options: -this-unit-id ghc-prim
865++
866++ if flag(boot)
867++ include-dirs: dist-boot
868++ else
869++ if flag(install)
870++ include-dirs: dist-install
871++
872++ install-includes:
873++ ghc_boot_platform.h
874++ primop-data-decl.hs-incl
875++ primop-tag.hs-incl
876++ primop-list.hs-incl
877++ primop-has-side-effects.hs-incl
878++ primop-out-of-line.hs-incl
879++ primop-commutable.hs-incl
880++ primop-code-size.hs-incl
881++ primop-can-fail.hs-incl
882++ primop-strictness.hs-incl
883++ primop-fixity.hs-incl
884++ primop-primop-info.hs-incl
885++ primop-vector-uniques.hs-incl
886++ primop-vector-tys.hs-incl
887++ primop-vector-tys-exports.hs-incl
888++ primop-vector-tycons.hs-incl
889+\ No newline at end of file
890+diff --git a/libraries/ghc-prim/ghc.mk b/libraries/ghc-prim/ghc.mk
891+new file mode 100644
892+index 0000000..5b09478
893+--- a/libraries/ghc-prim/ghc.mk
894++++ b/libraries/ghc-prim/ghc.mk
895+@@ -0,5 +1,202 @@
896+-libraries/ghc-prim_PACKAGE = ghc-prim
897+-libraries/ghc-prim_dist-install_GROUP = libraries
898+-$(if $(filter ghc-prim,$(PACKAGES_STAGE0)),$(eval $(call build-package,libraries/ghc-prim,dist-boot,0)))
899+-$(if $(filter ghc-prim,$(PACKAGES_STAGE1)),$(eval $(call build-package,libraries/ghc-prim,dist-install,1)))
900+-$(if $(filter ghc-prim,$(PACKAGES_STAGE2)),$(eval $(call build-package,libraries/ghc-prim,dist-install,2)))
901++libraries/ghc-prim_PACKAGE = ghc-prim
902++libraries/ghc-prim_dist-install_GROUP = libraries
903++
904++libraries/ghc-prim_stage1_CONFIGURE_OPTS += --flags=boot
905++libraries/ghc-prim_stage2_CONFIGURE_OPTS += --flags=install
906++libraries/ghc-prim_stage3_CONFIGURE_OPTS += --flags=install
907++
908++
909++# ----------------------------------------
910++# Special magic for the ghc-prim package
911++
912++# We want the ghc-prim package to include the GHC.Prim module when it
913++# is registered, but not when it is built, because GHC.Prim is not a
914++# real source module, it is built-in to GHC.
915++
916++# Strip it out again before building the package:
917++define libraries/ghc-prim_PACKAGE_MAGIC
918++libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
919++endef
920++
921++PRIMOPS_TXT_STAGE1 = libraries/ghc-prim/dist-boot/primops.txt
922++
923++libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $$(genprimopcode_INPLACE) $(PRIMOPS_TXT_STAGE1) | $$(dir $$@)/.
924++ "$(genprimopcode_INPLACE)" --make-haskell-wrappers < $(PRIMOPS_TXT_STAGE1) >$@
925++
926++# Required so that Haddock documents the primops.
927++libraries/ghc-prim_dist-install_EXTRA_HADDOCK_SRCS = libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
928++
929++
930++# -----------------------------------------------------------------------------
931++# Create platform includes
932++
933++# Here we generate a little header file containing CPP symbols that GHC
934++# uses to determine which platform it is building on/for. The platforms
935++# can differ between stage1 and stage2 if we're cross-compiling, so we
936++# need one of these header files per stage.
937++
938++PLATFORM_H = ghc_boot_platform.h
939++
940++libraries/ghc-prim/dist-boot/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
941++ $(call removeFiles,$@)
942++ @echo "Creating $@..."
943++ @echo "#ifndef __PLATFORM_H__" >> $@
944++ @echo "#define __PLATFORM_H__" >> $@
945++ @echo >> $@
946++ @echo "#define BuildPlatform_NAME \"$(BUILDPLATFORM)\"" >> $@
947++ @echo "#define HostPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
948++ @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
949++ @echo >> $@
950++ @echo "#define $(BuildPlatform_CPP)_BUILD 1" >> $@
951++ @echo "#define $(HostPlatform_CPP)_HOST 1" >> $@
952++ @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
953++ @echo >> $@
954++ @echo "#define $(BuildArch_CPP)_BUILD_ARCH 1" >> $@
955++ @echo "#define $(HostArch_CPP)_HOST_ARCH 1" >> $@
956++ @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
957++ @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
958++ @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
959++ @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
960++ @echo "#define LLVM_TARGET \"$(LLVMTarget_CPP)\"" >> $@
961++ @echo >> $@
962++ @echo "#define $(BuildOS_CPP)_BUILD_OS 1" >> $@
963++ @echo "#define $(HostOS_CPP)_HOST_OS 1" >> $@
964++ @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
965++ @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
966++ @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
967++ @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
968++ @echo >> $@
969++ @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 1" >> $@
970++ @echo "#define $(HostVendor_CPP)_HOST_VENDOR 1" >> $@
971++ @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
972++ @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
973++ @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
974++ @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
975++ @echo >> $@
976++ @echo "#endif /* __PLATFORM_H__ */" >> $@
977++ @echo "Done."
978++
979++# For stage2 and above, the BUILD platform is the HOST of stage1, and
980++# the HOST platform is the TARGET of stage1. The TARGET remains the same
981++# (stage1 is the cross-compiler, not stage2).
982++libraries/ghc-prim/dist-install/$(PLATFORM_H) : mk/config.mk mk/project.mk | $$(dir $$@)/.
983++ $(call removeFiles,$@)
984++ @echo "Creating $@..."
985++ @echo "#ifndef __PLATFORM_H__" >> $@
986++ @echo "#define __PLATFORM_H__" >> $@
987++ @echo >> $@
988++ @echo "#define BuildPlatform_NAME \"$(HOSTPLATFORM)\"" >> $@
989++ @echo "#define HostPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
990++ @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
991++ @echo >> $@
992++ @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
993++ @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
994++ @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
995++ @echo >> $@
996++ @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
997++ @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
998++ @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
999++ @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
1000++ @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
1001++ @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
1002++ @echo "#define LLVM_TARGET \"$(LLVMTarget_CPP)\"" >> $@
1003++ @echo >> $@
1004++ @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
1005++ @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
1006++ @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
1007++ @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
1008++ @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
1009++ @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
1010++ @echo >> $@
1011++ @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
1012++ @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
1013++ @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
1014++ @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
1015++ @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
1016++ @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
1017++ @echo >> $@
1018++ @echo "#endif /* __PLATFORM_H__ */" >> $@
1019++ @echo "Done."
1020++
1021++# ----------------------------------------------------------------------------
1022++# Generate supporting stuff for prelude/PrimOp.hs
1023++# from prelude/primops.txt
1024++
1025++PRIMOP_BITS_NAMES = primop-data-decl.hs-incl \
1026++ primop-tag.hs-incl \
1027++ primop-list.hs-incl \
1028++ primop-has-side-effects.hs-incl \
1029++ primop-out-of-line.hs-incl \
1030++ primop-commutable.hs-incl \
1031++ primop-code-size.hs-incl \
1032++ primop-can-fail.hs-incl \
1033++ primop-strictness.hs-incl \
1034++ primop-fixity.hs-incl \
1035++ primop-primop-info.hs-incl \
1036++ primop-vector-uniques.hs-incl \
1037++ primop-vector-tys.hs-incl \
1038++ primop-vector-tys-exports.hs-incl \
1039++ primop-vector-tycons.hs-incl
1040++
1041++PRIMOP_BITS_STAGE1 = $(addprefix libraries/ghc-prim/dist-boot/,$(PRIMOP_BITS_NAMES))
1042++PRIMOP_BITS_STAGE2 = $(addprefix libraries/ghc-prim/dist-install/,$(PRIMOP_BITS_NAMES))
1043++PRIMOP_BITS_STAGE3 = $(addprefix libraries/ghc-prim/dist-install/,$(PRIMOP_BITS_NAMES))
1044++
1045++compiler_CPP_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
1046++compiler_CPP_OPTS += ${GhcCppOpts}
1047++
1048++# We add these paths to the Haskell compiler's #include search path list since
1049++# we must avoid #including files by paths relative to the source file as Hadrian
1050++# moves the build artifacts out of the source tree. See #8040.
1051++compiler_HC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
1052++
1053++define preprocessCompilerFiles
1054++# $0 = stage
1055++libraries/ghc-prim/$1/primops.txt: libraries/ghc-prim/primops.txt.pp libraries/ghc-prim/$1/$$(PLATFORM_H)
1056++ $$(HS_CPP) -P $$(compiler_CPP_OPTS) -Ilibraries/ghc-prim/$1 -x c $$< | grep -v '^#pragma GCC' > $$@
1057++
1058++libraries/ghc-prim/$1/primop-data-decl.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1059++ "$$(genprimopcode_INPLACE)" --data-decl < $$< > $$@
1060++libraries/ghc-prim/$1/primop-tag.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1061++ "$$(genprimopcode_INPLACE)" --primop-tag < $$< > $$@
1062++libraries/ghc-prim/$1/primop-list.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1063++ "$$(genprimopcode_INPLACE)" --primop-list < $$< > $$@
1064++libraries/ghc-prim/$1/primop-has-side-effects.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1065++ "$$(genprimopcode_INPLACE)" --has-side-effects < $$< > $$@
1066++libraries/ghc-prim/$1/primop-out-of-line.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1067++ "$$(genprimopcode_INPLACE)" --out-of-line < $$< > $$@
1068++libraries/ghc-prim/$1/primop-commutable.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1069++ "$$(genprimopcode_INPLACE)" --commutable < $$< > $$@
1070++libraries/ghc-prim/$1/primop-code-size.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1071++ "$$(genprimopcode_INPLACE)" --code-size < $$< > $$@
1072++libraries/ghc-prim/$1/primop-can-fail.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1073++ "$$(genprimopcode_INPLACE)" --can-fail < $$< > $$@
1074++libraries/ghc-prim/$1/primop-strictness.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1075++ "$$(genprimopcode_INPLACE)" --strictness < $$< > $$@
1076++libraries/ghc-prim/$1/primop-fixity.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1077++ "$$(genprimopcode_INPLACE)" --fixity < $$< > $$@
1078++libraries/ghc-prim/$1/primop-primop-info.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1079++ "$$(genprimopcode_INPLACE)" --primop-primop-info < $$< > $$@
1080++libraries/ghc-prim/$1/primop-vector-uniques.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1081++ "$$(genprimopcode_INPLACE)" --primop-vector-uniques < $$< > $$@
1082++libraries/ghc-prim/$1/primop-vector-tys.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1083++ "$$(genprimopcode_INPLACE)" --primop-vector-tys < $$< > $$@
1084++libraries/ghc-prim/$1/primop-vector-tys-exports.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1085++ "$$(genprimopcode_INPLACE)" --primop-vector-tys-exports < $$< > $$@
1086++libraries/ghc-prim/$1/primop-vector-tycons.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1087++ "$$(genprimopcode_INPLACE)" --primop-vector-tycons < $$< > $$@
1088++
1089++# Usages aren't used any more; but the generator
1090++# can still generate them if we want them back
1091++libraries/ghc-prim/$1/primop-usage.hs-incl: libraries/ghc-prim/$1/primops.txt $$$$(genprimopcode_INPLACE)
1092++ "$$(genprimopcode_INPLACE)" --usage < $$< > $$@
1093++
1094++endef
1095++
1096++$(eval $(call preprocessCompilerFiles,dist-boot))
1097++$(eval $(call preprocessCompilerFiles,dist-install))
1098++
1099++
1100++$(if $(filter ghc-prim,$(PACKAGES_STAGE0)),$(eval $(call build-package,libraries/ghc-prim,dist-boot,0)))
1101++$(if $(filter ghc-prim,$(PACKAGES_STAGE1)),$(eval $(call build-package,libraries/ghc-prim,dist-install,1)))
1102++$(if $(filter ghc-prim,$(PACKAGES_STAGE2)),$(eval $(call build-package,libraries/ghc-prim,dist-install,2)))
1103+diff --git a/libraries/ghc-prim/primops.txt.pp b/libraries/ghc-prim/primops.txt.pp
1104+new file mode 100644
1105+index 0000000..141fe6c
1106+--- /dev/null
1107++++ b/libraries/ghc-prim/primops.txt.pp
1108+@@ -0,0 +1,3725 @@
1109++-----------------------------------------------------------------------
1110++--
1111++-- (c) 2010 The University of Glasgow
1112++--
1113++-- Primitive Operations and Types
1114++--
1115++-- For more information on PrimOps, see
1116++-- http://ghc.haskell.org/trac/ghc/wiki/Commentary/PrimOps
1117++--
1118++-----------------------------------------------------------------------
1119++
1120++-- This file is processed by the utility program genprimopcode to produce
1121++-- a number of include files within the compiler and optionally to produce
1122++-- human-readable documentation.
1123++--
1124++-- It should first be preprocessed.
1125++--
1126++-- Information on how PrimOps are implemented and the steps necessary to
1127++-- add a new one can be found in the Commentary:
1128++--
1129++-- http://ghc.haskell.org/trac/ghc/wiki/Commentary/PrimOps
1130++--
1131++-- Note in particular that Haskell block-style comments are not recognized
1132++-- here, so stick to '--' (even for Notes spanning multiple lines).
1133++
1134++-- This file is divided into named sections, each containing or more
1135++-- primop entries. Section headers have the format:
1136++--
1137++-- section "section-name" {description}
1138++--
1139++-- This information is used solely when producing documentation; it is
1140++-- otherwise ignored. The description is optional.
1141++--
1142++-- The format of each primop entry is as follows:
1143++--
1144++-- primop internal-name "name-in-program-text" type category {description} attributes
1145++
1146++-- The default attribute values which apply if you don't specify
1147++-- other ones. Attribute values can be True, False, or arbitrary
1148++-- text between curly brackets. This is a kludge to enable
1149++-- processors of this file to easily get hold of simple info
1150++-- (eg, out_of_line), whilst avoiding parsing complex expressions
1151++-- needed for strictness info.
1152++--
1153++-- type refers to the general category of the primop. Valid settings include,
1154++--
1155++-- * Compare: A comparison operation of the shape a -> a -> Int#
1156++-- * Monadic: A unary operation of shape a -> a
1157++-- * Dyadic: A binary operation of shape a -> a -> a
1158++-- * GenPrimOp: Any other sort of primop
1159++--
1160++
1161++-- The vector attribute is rather special. It takes a list of 3-tuples, each of
1162++-- which is of the form <ELEM_TYPE,SCALAR_TYPE,LENGTH>. ELEM_TYPE is the type of
1163++-- the elements in the vector; LENGTH is the length of the vector; and
1164++-- SCALAR_TYPE is the scalar type used to inject to/project from vector
1165++-- element. Note that ELEM_TYPE and SCALAR_TYPE are not the same; for example,
1166++-- to broadcast a scalar value to a vector whose elements are of type Int8, we
1167++-- use an Int#.
1168++
1169++-- When a primtype or primop has a vector attribute, it is instantiated at each
1170++-- 3-tuple in the list of 3-tuples. That is, the vector attribute allows us to
1171++-- define a family of types or primops. Vector support also adds three new
1172++-- keywords: VECTOR, SCALAR, and VECTUPLE. These keywords are expanded to types
1173++-- derived from the 3-tuple. For the 3-tuple <Int64,INT64,2>, VECTOR expands to
1174++-- Int64X2#, SCALAR expands to INT64, and VECTUPLE expands to (# INT64, INT64
1175++-- #).
1176++
1177++defaults
1178++ has_side_effects = False
1179++ out_of_line = False -- See Note Note [PrimOp can_fail and has_side_effects] in PrimOp
1180++ can_fail = False -- See Note Note [PrimOp can_fail and has_side_effects] in PrimOp
1181++ commutable = False
1182++ code_size = { primOpCodeSizeDefault }
1183++ strictness = { \ arity -> mkClosedStrictSig (replicate arity topDmd) topRes }
1184++ fixity = Nothing
1185++ llvm_only = False
1186++ vector = []
1187++ deprecated_msg = {} -- A non-empty message indicates deprecation
1188++
1189++-- Currently, documentation is produced using latex, so contents of
1190++-- description fields should be legal latex. Descriptions can contain
1191++-- matched pairs of embedded curly brackets.
1192++
1193++#include "MachDeps.h"
1194++
1195++-- We need platform defines (tests for mingw32 below).
1196++#include "ghc_boot_platform.h"
1197++
1198++section "The word size story."
1199++ {Haskell98 specifies that signed integers (type {\tt Int})
1200++ must contain at least 30 bits. GHC always implements {\tt
1201++ Int} using the primitive type {\tt Int\#}, whose size equals
1202++ the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}.
1203++ This is normally set based on the {\tt config.h} parameter
1204++ {\tt SIZEOF\_HSWORD}, i.e., 32 bits on 32-bit machines, 64
1205++ bits on 64-bit machines. However, it can also be explicitly
1206++ set to a smaller number than 64, e.g., 62 bits, to allow the
1207++ possibility of using tag bits. Currently GHC itself has only
1208++ 32-bit and 64-bit variants, but 61, 62, or 63-bit code can be
1209++ exported as an external core file for use in other back ends.
1210++ 30 and 31-bit code is no longer supported.
1211++
1212++ GHC also implements a primitive unsigned integer type {\tt
1213++ Word\#} which always has the same number of bits as {\tt
1214++ Int\#}.
1215++
1216++ In addition, GHC supports families of explicit-sized integers
1217++ and words at 8, 16, 32, and 64 bits, with the usual
1218++ arithmetic operations, comparisons, and a range of
1219++ conversions. The 8-bit and 16-bit sizes are always
1220++ represented as {\tt Int\#} and {\tt Word\#}, and the
1221++ operations implemented in terms of the primops on these
1222++ types, with suitable range restrictions on the results (using
1223++ the {\tt narrow$n$Int\#} and {\tt narrow$n$Word\#} families
1224++ of primops. The 32-bit sizes are represented using {\tt
1225++ Int\#} and {\tt Word\#} when {\tt WORD\_SIZE\_IN\_BITS}
1226++ $\geq$ 32; otherwise, these are represented using distinct
1227++ primitive types {\tt Int32\#} and {\tt Word32\#}. These (when
1228++ needed) have a complete set of corresponding operations;
1229++ however, nearly all of these are implemented as external C
1230++ functions rather than as primops. Exactly the same story
1231++ applies to the 64-bit sizes. All of these details are hidden
1232++ under the {\tt PrelInt} and {\tt PrelWord} modules, which use
1233++ {\tt \#if}-defs to invoke the appropriate types and
1234++ operators.
1235++
1236++ Word size also matters for the families of primops for
1237++ indexing/reading/writing fixed-size quantities at offsets
1238++ from an array base, address, or foreign pointer. Here, a
1239++ slightly different approach is taken. The names of these
1240++ primops are fixed, but their {\it types} vary according to
1241++ the value of {\tt WORD\_SIZE\_IN\_BITS}. For example, if word
1242++ size is at least 32 bits then an operator like
1243++ \texttt{indexInt32Array\#} has type {\tt ByteArray\# -> Int\#
1244++ -> Int\#}; otherwise it has type {\tt ByteArray\# -> Int\# ->
1245++ Int32\#}. This approach confines the necessary {\tt
1246++ \#if}-defs to this file; no conditional compilation is needed
1247++ in the files that expose these primops.
1248++
1249++ Finally, there are strongly deprecated primops for coercing
1250++ between {\tt Addr\#}, the primitive type of machine
1251++ addresses, and {\tt Int\#}. These are pretty bogus anyway,
1252++ but will work on existing 32-bit and 64-bit GHC targets; they
1253++ are completely bogus when tag bits are used in {\tt Int\#},
1254++ so are not available in this case. }
1255++
1256++-- Define synonyms for indexing ops.
1257++
1258++#define INT32 Int#
1259++#define WORD32 Word#
1260++
1261++#if WORD_SIZE_IN_BITS < 64
1262++#define INT64 Int64#
1263++#define WORD64 Word64#
1264++#else
1265++#define INT64 Int#
1266++#define WORD64 Word#
1267++#endif
1268++
1269++-- This type won't be exported directly (since there is no concrete
1270++-- syntax for this sort of export) so we'll have to manually patch
1271++-- export lists in both GHC and Haddock.
1272++primtype (->) a b
1273++ {The builtin function type, written in infix form as {\tt a -> b} and
1274++ in prefix form as {\tt (->) a b}. Values of this type are functions
1275++ taking inputs of type {\tt a} and producing outputs of type {\tt b}.
1276++
1277++ Note that {\tt a -> b} permits levity-polymorphism in both {\tt a} and
1278++ {\tt b}, so that types like {\tt Int\# -> Int\#} can still be well-kinded.
1279++ }
1280++ with fixity = infixr -1
1281++ -- This fixity is only the one picked up by Haddock. If you
1282++ -- change this, do update 'ghcPrimIface' in 'LoadIface.hs'.
1283++
1284++------------------------------------------------------------------------
1285++section "Char#"
1286++ {Operations on 31-bit characters.}
1287++------------------------------------------------------------------------
1288++
1289++primtype Char#
1290++
1291++primop CharGtOp "gtChar#" Compare Char# -> Char# -> Int#
1292++primop CharGeOp "geChar#" Compare Char# -> Char# -> Int#
1293++
1294++primop CharEqOp "eqChar#" Compare
1295++ Char# -> Char# -> Int#
1296++ with commutable = True
1297++
1298++primop CharNeOp "neChar#" Compare
1299++ Char# -> Char# -> Int#
1300++ with commutable = True
1301++
1302++primop CharLtOp "ltChar#" Compare Char# -> Char# -> Int#
1303++primop CharLeOp "leChar#" Compare Char# -> Char# -> Int#
1304++
1305++primop OrdOp "ord#" GenPrimOp Char# -> Int#
1306++ with code_size = 0
1307++
1308++------------------------------------------------------------------------
1309++section "Int#"
1310++ {Operations on native-size integers (32+ bits).}
1311++------------------------------------------------------------------------
1312++
1313++primtype Int#
1314++
1315++primop IntAddOp "+#" Dyadic
1316++ Int# -> Int# -> Int#
1317++ with commutable = True
1318++ fixity = infixl 6
1319++
1320++primop IntSubOp "-#" Dyadic Int# -> Int# -> Int#
1321++ with fixity = infixl 6
1322++
1323++primop IntMulOp "*#"
1324++ Dyadic Int# -> Int# -> Int#
1325++ {Low word of signed integer multiply.}
1326++ with commutable = True
1327++ fixity = infixl 7
1328++
1329++primop IntMulMayOfloOp "mulIntMayOflo#"
1330++ Dyadic Int# -> Int# -> Int#
1331++ {Return non-zero if there is any possibility that the upper word of a
1332++ signed integer multiply might contain useful information. Return
1333++ zero only if you are completely sure that no overflow can occur.
1334++ On a 32-bit platform, the recommended implementation is to do a
1335++ 32 x 32 -> 64 signed multiply, and subtract result[63:32] from
1336++ (result[31] >>signed 31). If this is zero, meaning that the
1337++ upper word is merely a sign extension of the lower one, no
1338++ overflow can occur.
1339++
1340++ On a 64-bit platform it is not always possible to
1341++ acquire the top 64 bits of the result. Therefore, a recommended
1342++ implementation is to take the absolute value of both operands, and
1343++ return 0 iff bits[63:31] of them are zero, since that means that their
1344++ magnitudes fit within 31 bits, so the magnitude of the product must fit
1345++ into 62 bits.
1346++
1347++ If in doubt, return non-zero, but do make an effort to create the
1348++ correct answer for small args, since otherwise the performance of
1349++ \texttt{(*) :: Integer -> Integer -> Integer} will be poor.
1350++ }
1351++ with commutable = True
1352++
1353++primop IntQuotOp "quotInt#" Dyadic
1354++ Int# -> Int# -> Int#
1355++ {Rounds towards zero. The behavior is undefined if the second argument is
1356++ zero.
1357++ }
1358++ with can_fail = True
1359++
1360++primop IntRemOp "remInt#" Dyadic
1361++ Int# -> Int# -> Int#
1362++ {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}. The
1363++ behavior is undefined if the second argument is zero.
1364++ }
1365++ with can_fail = True
1366++
1367++primop IntQuotRemOp "quotRemInt#" GenPrimOp
1368++ Int# -> Int# -> (# Int#, Int# #)
1369++ {Rounds towards zero.}
1370++ with can_fail = True
1371++
1372++primop AndIOp "andI#" Dyadic Int# -> Int# -> Int#
1373++ {Bitwise "and".}
1374++ with commutable = True
1375++
1376++primop OrIOp "orI#" Dyadic Int# -> Int# -> Int#
1377++ {Bitwise "or".}
1378++ with commutable = True
1379++
1380++primop XorIOp "xorI#" Dyadic Int# -> Int# -> Int#
1381++ {Bitwise "xor".}
1382++ with commutable = True
1383++
1384++primop NotIOp "notI#" Monadic Int# -> Int#
1385++ {Bitwise "not", also known as the binary complement.}
1386++
1387++primop IntNegOp "negateInt#" Monadic Int# -> Int#
1388++ {Unary negation.
1389++ Since the negative {\tt Int#} range extends one further than the
1390++ positive range, {\tt negateInt#} of the most negative number is an
1391++ identity operation. This way, {\tt negateInt#} is always its own inverse.}
1392++
1393++primop IntAddCOp "addIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
1394++ {Add signed integers reporting overflow.
1395++ First member of result is the sum truncated to an {\tt Int#};
1396++ second member is zero if the true sum fits in an {\tt Int#},
1397++ nonzero if overflow occurred (the sum is either too large
1398++ or too small to fit in an {\tt Int#}).}
1399++ with code_size = 2
1400++ commutable = True
1401++
1402++primop IntSubCOp "subIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
1403++ {Subtract signed integers reporting overflow.
1404++ First member of result is the difference truncated to an {\tt Int#};
1405++ second member is zero if the true difference fits in an {\tt Int#},
1406++ nonzero if overflow occurred (the difference is either too large
1407++ or too small to fit in an {\tt Int#}).}
1408++ with code_size = 2
1409++
1410++primop IntGtOp ">#" Compare Int# -> Int# -> Int#
1411++ with fixity = infix 4
1412++
1413++primop IntGeOp ">=#" Compare Int# -> Int# -> Int#
1414++ with fixity = infix 4
1415++
1416++primop IntEqOp "==#" Compare
1417++ Int# -> Int# -> Int#
1418++ with commutable = True
1419++ fixity = infix 4
1420++
1421++primop IntNeOp "/=#" Compare
1422++ Int# -> Int# -> Int#
1423++ with commutable = True
1424++ fixity = infix 4
1425++
1426++primop IntLtOp "<#" Compare Int# -> Int# -> Int#
1427++ with fixity = infix 4
1428++
1429++primop IntLeOp "<=#" Compare Int# -> Int# -> Int#
1430++ with fixity = infix 4
1431++
1432++primop ChrOp "chr#" GenPrimOp Int# -> Char#
1433++ with code_size = 0
1434++
1435++primop Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
1436++ with code_size = 0
1437++
1438++primop Int2FloatOp "int2Float#" GenPrimOp Int# -> Float#
1439++primop Int2DoubleOp "int2Double#" GenPrimOp Int# -> Double#
1440++
1441++primop Word2FloatOp "word2Float#" GenPrimOp Word# -> Float#
1442++primop Word2DoubleOp "word2Double#" GenPrimOp Word# -> Double#
1443++
1444++primop ISllOp "uncheckedIShiftL#" GenPrimOp Int# -> Int# -> Int#
1445++ {Shift left. Result undefined if shift amount is not
1446++ in the range 0 to word size - 1 inclusive.}
1447++primop ISraOp "uncheckedIShiftRA#" GenPrimOp Int# -> Int# -> Int#
1448++ {Shift right arithmetic. Result undefined if shift amount is not
1449++ in the range 0 to word size - 1 inclusive.}
1450++primop ISrlOp "uncheckedIShiftRL#" GenPrimOp Int# -> Int# -> Int#
1451++ {Shift right logical. Result undefined if shift amount is not
1452++ in the range 0 to word size - 1 inclusive.}
1453++
1454++------------------------------------------------------------------------
1455++section "Int8#"
1456++ {Operations on 8-bit integers.}
1457++------------------------------------------------------------------------
1458++
1459++primtype Int8#
1460++
1461++primop Int8Extend "extendInt8#" GenPrimOp Int8# -> Int#
1462++primop Int8Narrow "narrowInt8#" GenPrimOp Int# -> Int8#
1463++
1464++primop Int8NegOp "negateInt8#" Monadic Int8# -> Int8#
1465++
1466++primop Int8AddOp "plusInt8#" Dyadic Int8# -> Int8# -> Int8#
1467++ with
1468++ commutable = True
1469++
1470++primop Int8SubOp "subInt8#" Dyadic Int8# -> Int8# -> Int8#
1471++
1472++primop Int8MulOp "timesInt8#" Dyadic Int8# -> Int8# -> Int8#
1473++ with
1474++ commutable = True
1475++
1476++primop Int8QuotOp "quotInt8#" Dyadic Int8# -> Int8# -> Int8#
1477++ with
1478++ can_fail = True
1479++
1480++primop Int8RemOp "remInt8#" Dyadic Int8# -> Int8# -> Int8#
1481++ with
1482++ can_fail = True
1483++
1484++primop Int8QuotRemOp "quotRemInt8#" GenPrimOp Int8# -> Int8# -> (# Int8#, Int8# #)
1485++ with
1486++ can_fail = True
1487++
1488++primop Int8EqOp "eqInt8#" Compare Int8# -> Int8# -> Int#
1489++primop Int8GeOp "geInt8#" Compare Int8# -> Int8# -> Int#
1490++primop Int8GtOp "gtInt8#" Compare Int8# -> Int8# -> Int#
1491++primop Int8LeOp "leInt8#" Compare Int8# -> Int8# -> Int#
1492++primop Int8LtOp "ltInt8#" Compare Int8# -> Int8# -> Int#
1493++primop Int8NeOp "neInt8#" Compare Int8# -> Int8# -> Int#
1494++
1495++------------------------------------------------------------------------
1496++section "Word8#"
1497++ {Operations on 8-bit unsigned integers.}
1498++------------------------------------------------------------------------
1499++
1500++primtype Word8#
1501++
1502++primop Word8Extend "extendWord8#" GenPrimOp Word8# -> Word#
1503++primop Word8Narrow "narrowWord8#" GenPrimOp Word# -> Word8#
1504++
1505++primop Word8NotOp "notWord8#" Monadic Word8# -> Word8#
1506++
1507++primop Word8AddOp "plusWord8#" Dyadic Word8# -> Word8# -> Word8#
1508++ with
1509++ commutable = True
1510++
1511++primop Word8SubOp "subWord8#" Dyadic Word8# -> Word8# -> Word8#
1512++
1513++primop Word8MulOp "timesWord8#" Dyadic Word8# -> Word8# -> Word8#
1514++ with
1515++ commutable = True
1516++
1517++primop Word8QuotOp "quotWord8#" Dyadic Word8# -> Word8# -> Word8#
1518++ with
1519++ can_fail = True
1520++
1521++primop Word8RemOp "remWord8#" Dyadic Word8# -> Word8# -> Word8#
1522++ with
1523++ can_fail = True
1524++
1525++primop Word8QuotRemOp "quotRemWord8#" GenPrimOp Word8# -> Word8# -> (# Word8#, Word8# #)
1526++ with
1527++ can_fail = True
1528++
1529++primop Word8EqOp "eqWord8#" Compare Word8# -> Word8# -> Int#
1530++primop Word8GeOp "geWord8#" Compare Word8# -> Word8# -> Int#
1531++primop Word8GtOp "gtWord8#" Compare Word8# -> Word8# -> Int#
1532++primop Word8LeOp "leWord8#" Compare Word8# -> Word8# -> Int#
1533++primop Word8LtOp "ltWord8#" Compare Word8# -> Word8# -> Int#
1534++primop Word8NeOp "neWord8#" Compare Word8# -> Word8# -> Int#
1535++
1536++------------------------------------------------------------------------
1537++section "Int16#"
1538++ {Operations on 16-bit integers.}
1539++------------------------------------------------------------------------
1540++
1541++primtype Int16#
1542++
1543++primop Int16Extend "extendInt16#" GenPrimOp Int16# -> Int#
1544++primop Int16Narrow "narrowInt16#" GenPrimOp Int# -> Int16#
1545++
1546++primop Int16NegOp "negateInt16#" Monadic Int16# -> Int16#
1547++
1548++primop Int16AddOp "plusInt16#" Dyadic Int16# -> Int16# -> Int16#
1549++ with
1550++ commutable = True
1551++
1552++primop Int16SubOp "subInt16#" Dyadic Int16# -> Int16# -> Int16#
1553++
1554++primop Int16MulOp "timesInt16#" Dyadic Int16# -> Int16# -> Int16#
1555++ with
1556++ commutable = True
1557++
1558++primop Int16QuotOp "quotInt16#" Dyadic Int16# -> Int16# -> Int16#
1559++ with
1560++ can_fail = True
1561++
1562++primop Int16RemOp "remInt16#" Dyadic Int16# -> Int16# -> Int16#
1563++ with
1564++ can_fail = True
1565++
1566++primop Int16QuotRemOp "quotRemInt16#" GenPrimOp Int16# -> Int16# -> (# Int16#, Int16# #)
1567++ with
1568++ can_fail = True
1569++
1570++primop Int16EqOp "eqInt16#" Compare Int16# -> Int16# -> Int#
1571++primop Int16GeOp "geInt16#" Compare Int16# -> Int16# -> Int#
1572++primop Int16GtOp "gtInt16#" Compare Int16# -> Int16# -> Int#
1573++primop Int16LeOp "leInt16#" Compare Int16# -> Int16# -> Int#
1574++primop Int16LtOp "ltInt16#" Compare Int16# -> Int16# -> Int#
1575++primop Int16NeOp "neInt16#" Compare Int16# -> Int16# -> Int#
1576++
1577++------------------------------------------------------------------------
1578++section "Word16#"
1579++ {Operations on 16-bit unsigned integers.}
1580++------------------------------------------------------------------------
1581++
1582++primtype Word16#
1583++
1584++primop Word16Extend "extendWord16#" GenPrimOp Word16# -> Word#
1585++primop Word16Narrow "narrowWord16#" GenPrimOp Word# -> Word16#
1586++
1587++primop Word16NotOp "notWord16#" Monadic Word16# -> Word16#
1588++
1589++primop Word16AddOp "plusWord16#" Dyadic Word16# -> Word16# -> Word16#
1590++ with
1591++ commutable = True
1592++
1593++primop Word16SubOp "subWord16#" Dyadic Word16# -> Word16# -> Word16#
1594++
1595++primop Word16MulOp "timesWord16#" Dyadic Word16# -> Word16# -> Word16#
1596++ with
1597++ commutable = True
1598++
1599++primop Word16QuotOp "quotWord16#" Dyadic Word16# -> Word16# -> Word16#
1600++ with
1601++ can_fail = True
1602++
1603++primop Word16RemOp "remWord16#" Dyadic Word16# -> Word16# -> Word16#
1604++ with
1605++ can_fail = True
1606++
1607++primop Word16QuotRemOp "quotRemWord16#" GenPrimOp Word16# -> Word16# -> (# Word16#, Word16# #)
1608++ with
1609++ can_fail = True
1610++
1611++primop Word16EqOp "eqWord16#" Compare Word16# -> Word16# -> Int#
1612++primop Word16GeOp "geWord16#" Compare Word16# -> Word16# -> Int#
1613++primop Word16GtOp "gtWord16#" Compare Word16# -> Word16# -> Int#
1614++primop Word16LeOp "leWord16#" Compare Word16# -> Word16# -> Int#
1615++primop Word16LtOp "ltWord16#" Compare Word16# -> Word16# -> Int#
1616++primop Word16NeOp "neWord16#" Compare Word16# -> Word16# -> Int#
1617++
1618++------------------------------------------------------------------------
1619++section "Word#"
1620++ {Operations on native-sized unsigned words (32+ bits).}
1621++------------------------------------------------------------------------
1622++
1623++primtype Word#
1624++
1625++primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word#
1626++ with commutable = True
1627++
1628++primop WordAddCOp "addWordC#" GenPrimOp Word# -> Word# -> (# Word#, Int# #)
1629++ {Add unsigned integers reporting overflow.
1630++ The first element of the pair is the result. The second element is
1631++ the carry flag, which is nonzero on overflow. See also {\tt plusWord2#}.}
1632++ with code_size = 2
1633++ commutable = True
1634++
1635++primop WordSubCOp "subWordC#" GenPrimOp Word# -> Word# -> (# Word#, Int# #)
1636++ {Subtract unsigned integers reporting overflow.
1637++ The first element of the pair is the result. The second element is
1638++ the carry flag, which is nonzero on overflow.}
1639++ with code_size = 2
1640++
1641++primop WordAdd2Op "plusWord2#" GenPrimOp Word# -> Word# -> (# Word#, Word# #)
1642++ {Add unsigned integers, with the high part (carry) in the first
1643++ component of the returned pair and the low part in the second
1644++ component of the pair. See also {\tt addWordC#}.}
1645++ with code_size = 2
1646++ commutable = True
1647++
1648++primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word#
1649++
1650++primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word#
1651++ with commutable = True
1652++
1653++-- Returns (# high, low #)
1654++primop WordMul2Op "timesWord2#" GenPrimOp
1655++ Word# -> Word# -> (# Word#, Word# #)
1656++ with commutable = True
1657++
1658++primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word#
1659++ with can_fail = True
1660++
1661++primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word#
1662++ with can_fail = True
1663++
1664++primop WordQuotRemOp "quotRemWord#" GenPrimOp
1665++ Word# -> Word# -> (# Word#, Word# #)
1666++ with can_fail = True
1667++
1668++-- Takes high word of dividend, then low word of dividend, then divisor.
1669++-- Requires that high word is not divisible by divisor.
1670++primop WordQuotRem2Op "quotRemWord2#" GenPrimOp
1671++ Word# -> Word# -> Word# -> (# Word#, Word# #)
1672++ with can_fail = True
1673++
1674++primop AndOp "and#" Dyadic Word# -> Word# -> Word#
1675++ with commutable = True
1676++
1677++primop OrOp "or#" Dyadic Word# -> Word# -> Word#
1678++ with commutable = True
1679++
1680++primop XorOp "xor#" Dyadic Word# -> Word# -> Word#
1681++ with commutable = True
1682++
1683++primop NotOp "not#" Monadic Word# -> Word#
1684++
1685++primop SllOp "uncheckedShiftL#" GenPrimOp Word# -> Int# -> Word#
1686++ {Shift left logical. Result undefined if shift amount is not
1687++ in the range 0 to word size - 1 inclusive.}
1688++primop SrlOp "uncheckedShiftRL#" GenPrimOp Word# -> Int# -> Word#
1689++ {Shift right logical. Result undefined if shift amount is not
1690++ in the range 0 to word size - 1 inclusive.}
1691++
1692++primop Word2IntOp "word2Int#" GenPrimOp Word# -> Int#
1693++ with code_size = 0
1694++
1695++primop WordGtOp "gtWord#" Compare Word# -> Word# -> Int#
1696++primop WordGeOp "geWord#" Compare Word# -> Word# -> Int#
1697++primop WordEqOp "eqWord#" Compare Word# -> Word# -> Int#
1698++primop WordNeOp "neWord#" Compare Word# -> Word# -> Int#
1699++primop WordLtOp "ltWord#" Compare Word# -> Word# -> Int#
1700++primop WordLeOp "leWord#" Compare Word# -> Word# -> Int#
1701++
1702++primop PopCnt8Op "popCnt8#" Monadic Word# -> Word#
1703++ {Count the number of set bits in the lower 8 bits of a word.}
1704++primop PopCnt16Op "popCnt16#" Monadic Word# -> Word#
1705++ {Count the number of set bits in the lower 16 bits of a word.}
1706++primop PopCnt32Op "popCnt32#" Monadic Word# -> Word#
1707++ {Count the number of set bits in the lower 32 bits of a word.}
1708++primop PopCnt64Op "popCnt64#" GenPrimOp WORD64 -> Word#
1709++ {Count the number of set bits in a 64-bit word.}
1710++primop PopCntOp "popCnt#" Monadic Word# -> Word#
1711++ {Count the number of set bits in a word.}
1712++
1713++primop Pdep8Op "pdep8#" Dyadic Word# -> Word# -> Word#
1714++ {Deposit bits to lower 8 bits of a word at locations specified by a mask.}
1715++primop Pdep16Op "pdep16#" Dyadic Word# -> Word# -> Word#
1716++ {Deposit bits to lower 16 bits of a word at locations specified by a mask.}
1717++primop Pdep32Op "pdep32#" Dyadic Word# -> Word# -> Word#
1718++ {Deposit bits to lower 32 bits of a word at locations specified by a mask.}
1719++primop Pdep64Op "pdep64#" GenPrimOp WORD64 -> WORD64 -> WORD64
1720++ {Deposit bits to a word at locations specified by a mask.}
1721++primop PdepOp "pdep#" Dyadic Word# -> Word# -> Word#
1722++ {Deposit bits to a word at locations specified by a mask.}
1723++
1724++primop Pext8Op "pext8#" Dyadic Word# -> Word# -> Word#
1725++ {Extract bits from lower 8 bits of a word at locations specified by a mask.}
1726++primop Pext16Op "pext16#" Dyadic Word# -> Word# -> Word#
1727++ {Extract bits from lower 16 bits of a word at locations specified by a mask.}
1728++primop Pext32Op "pext32#" Dyadic Word# -> Word# -> Word#
1729++ {Extract bits from lower 32 bits of a word at locations specified by a mask.}
1730++primop Pext64Op "pext64#" GenPrimOp WORD64 -> WORD64 -> WORD64
1731++ {Extract bits from a word at locations specified by a mask.}
1732++primop PextOp "pext#" Dyadic Word# -> Word# -> Word#
1733++ {Extract bits from a word at locations specified by a mask.}
1734++
1735++primop Clz8Op "clz8#" Monadic Word# -> Word#
1736++ {Count leading zeros in the lower 8 bits of a word.}
1737++primop Clz16Op "clz16#" Monadic Word# -> Word#
1738++ {Count leading zeros in the lower 16 bits of a word.}
1739++primop Clz32Op "clz32#" Monadic Word# -> Word#
1740++ {Count leading zeros in the lower 32 bits of a word.}
1741++primop Clz64Op "clz64#" GenPrimOp WORD64 -> Word#
1742++ {Count leading zeros in a 64-bit word.}
1743++primop ClzOp "clz#" Monadic Word# -> Word#
1744++ {Count leading zeros in a word.}
1745++
1746++primop Ctz8Op "ctz8#" Monadic Word# -> Word#
1747++ {Count trailing zeros in the lower 8 bits of a word.}
1748++primop Ctz16Op "ctz16#" Monadic Word# -> Word#
1749++ {Count trailing zeros in the lower 16 bits of a word.}
1750++primop Ctz32Op "ctz32#" Monadic Word# -> Word#
1751++ {Count trailing zeros in the lower 32 bits of a word.}
1752++primop Ctz64Op "ctz64#" GenPrimOp WORD64 -> Word#
1753++ {Count trailing zeros in a 64-bit word.}
1754++primop CtzOp "ctz#" Monadic Word# -> Word#
1755++ {Count trailing zeros in a word.}
1756++
1757++primop BSwap16Op "byteSwap16#" Monadic Word# -> Word#
1758++ {Swap bytes in the lower 16 bits of a word. The higher bytes are undefined. }
1759++primop BSwap32Op "byteSwap32#" Monadic Word# -> Word#
1760++ {Swap bytes in the lower 32 bits of a word. The higher bytes are undefined. }
1761++primop BSwap64Op "byteSwap64#" Monadic WORD64 -> WORD64
1762++ {Swap bytes in a 64 bits of a word.}
1763++primop BSwapOp "byteSwap#" Monadic Word# -> Word#
1764++ {Swap bytes in a word.}
1765++
1766++------------------------------------------------------------------------
1767++section "Narrowings"
1768++ {Explicit narrowing of native-sized ints or words.}
1769++------------------------------------------------------------------------
1770++
1771++primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int#
1772++primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int#
1773++primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int#
1774++primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word#
1775++primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word#
1776++primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word#
1777++
1778++
1779++#if WORD_SIZE_IN_BITS < 64
1780++------------------------------------------------------------------------
1781++section "Int64#"
1782++ {Operations on 64-bit unsigned words. This type is only used
1783++ if plain {\tt Int\#} has less than 64 bits. In any case, the operations
1784++ are not primops; they are implemented (if needed) as ccalls instead.}
1785++------------------------------------------------------------------------
1786++
1787++primtype Int64#
1788++
1789++------------------------------------------------------------------------
1790++section "Word64#"
1791++ {Operations on 64-bit unsigned words. This type is only used
1792++ if plain {\tt Word\#} has less than 64 bits. In any case, the operations
1793++ are not primops; they are implemented (if needed) as ccalls instead.}
1794++------------------------------------------------------------------------
1795++
1796++primtype Word64#
1797++
1798++#endif
1799++
1800++------------------------------------------------------------------------
1801++section "Double#"
1802++ {Operations on double-precision (64 bit) floating-point numbers.}
1803++------------------------------------------------------------------------
1804++
1805++primtype Double#
1806++
1807++primop DoubleGtOp ">##" Compare Double# -> Double# -> Int#
1808++ with fixity = infix 4
1809++
1810++primop DoubleGeOp ">=##" Compare Double# -> Double# -> Int#
1811++ with fixity = infix 4
1812++
1813++primop DoubleEqOp "==##" Compare
1814++ Double# -> Double# -> Int#
1815++ with commutable = True
1816++ fixity = infix 4
1817++
1818++primop DoubleNeOp "/=##" Compare
1819++ Double# -> Double# -> Int#
1820++ with commutable = True
1821++ fixity = infix 4
1822++
1823++primop DoubleLtOp "<##" Compare Double# -> Double# -> Int#
1824++ with fixity = infix 4
1825++
1826++primop DoubleLeOp "<=##" Compare Double# -> Double# -> Int#
1827++ with fixity = infix 4
1828++
1829++primop DoubleAddOp "+##" Dyadic
1830++ Double# -> Double# -> Double#
1831++ with commutable = True
1832++ fixity = infixl 6
1833++
1834++primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
1835++ with fixity = infixl 6
1836++
1837++primop DoubleMulOp "*##" Dyadic
1838++ Double# -> Double# -> Double#
1839++ with commutable = True
1840++ fixity = infixl 7
1841++
1842++primop DoubleDivOp "/##" Dyadic
1843++ Double# -> Double# -> Double#
1844++ with can_fail = True
1845++ fixity = infixl 7
1846++
1847++primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
1848++
1849++primop DoubleFabsOp "fabsDouble#" Monadic Double# -> Double#
1850++
1851++primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
1852++ {Truncates a {\tt Double#} value to the nearest {\tt Int#}.
1853++ Results are undefined if the truncation if truncation yields
1854++ a value outside the range of {\tt Int#}.}
1855++
1856++primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
1857++
1858++primop DoubleExpOp "expDouble#" Monadic
1859++ Double# -> Double#
1860++ with
1861++ code_size = { primOpCodeSizeForeignCall }
1862++
1863++primop DoubleLogOp "logDouble#" Monadic
1864++ Double# -> Double#
1865++ with
1866++ code_size = { primOpCodeSizeForeignCall }
1867++ can_fail = True
1868++
1869++primop DoubleSqrtOp "sqrtDouble#" Monadic
1870++ Double# -> Double#
1871++ with
1872++ code_size = { primOpCodeSizeForeignCall }
1873++
1874++primop DoubleSinOp "sinDouble#" Monadic
1875++ Double# -> Double#
1876++ with
1877++ code_size = { primOpCodeSizeForeignCall }
1878++
1879++primop DoubleCosOp "cosDouble#" Monadic
1880++ Double# -> Double#
1881++ with
1882++ code_size = { primOpCodeSizeForeignCall }
1883++
1884++primop DoubleTanOp "tanDouble#" Monadic
1885++ Double# -> Double#
1886++ with
1887++ code_size = { primOpCodeSizeForeignCall }
1888++
1889++primop DoubleAsinOp "asinDouble#" Monadic
1890++ Double# -> Double#
1891++ with
1892++ code_size = { primOpCodeSizeForeignCall }
1893++ can_fail = True
1894++
1895++primop DoubleAcosOp "acosDouble#" Monadic
1896++ Double# -> Double#
1897++ with
1898++ code_size = { primOpCodeSizeForeignCall }
1899++ can_fail = True
1900++
1901++primop DoubleAtanOp "atanDouble#" Monadic
1902++ Double# -> Double#
1903++ with
1904++ code_size = { primOpCodeSizeForeignCall }
1905++
1906++primop DoubleSinhOp "sinhDouble#" Monadic
1907++ Double# -> Double#
1908++ with
1909++ code_size = { primOpCodeSizeForeignCall }
1910++
1911++primop DoubleCoshOp "coshDouble#" Monadic
1912++ Double# -> Double#
1913++ with
1914++ code_size = { primOpCodeSizeForeignCall }
1915++
1916++primop DoubleTanhOp "tanhDouble#" Monadic
1917++ Double# -> Double#
1918++ with
1919++ code_size = { primOpCodeSizeForeignCall }
1920++
1921++primop DoubleAsinhOp "asinhDouble#" Monadic
1922++ Double# -> Double#
1923++ with
1924++ code_size = { primOpCodeSizeForeignCall }
1925++
1926++primop DoubleAcoshOp "acoshDouble#" Monadic
1927++ Double# -> Double#
1928++ with
1929++ code_size = { primOpCodeSizeForeignCall }
1930++
1931++primop DoubleAtanhOp "atanhDouble#" Monadic
1932++ Double# -> Double#
1933++ with
1934++ code_size = { primOpCodeSizeForeignCall }
1935++
1936++primop DoublePowerOp "**##" Dyadic
1937++ Double# -> Double# -> Double#
1938++ {Exponentiation.}
1939++ with
1940++ code_size = { primOpCodeSizeForeignCall }
1941++
1942++primop DoubleDecode_2IntOp "decodeDouble_2Int#" GenPrimOp
1943++ Double# -> (# Int#, Word#, Word#, Int# #)
1944++ {Convert to integer.
1945++ First component of the result is -1 or 1, indicating the sign of the
1946++ mantissa. The next two are the high and low 32 bits of the mantissa
1947++ respectively, and the last is the exponent.}
1948++ with out_of_line = True
1949++
1950++primop DoubleDecode_Int64Op "decodeDouble_Int64#" GenPrimOp
1951++ Double# -> (# INT64, Int# #)
1952++ {Decode {\tt Double\#} into mantissa and base-2 exponent.}
1953++ with out_of_line = True
1954++
1955++------------------------------------------------------------------------
1956++section "Float#"
1957++ {Operations on single-precision (32-bit) floating-point numbers.}
1958++------------------------------------------------------------------------
1959++
1960++primtype Float#
1961++
1962++primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Int#
1963++primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Int#
1964++
1965++primop FloatEqOp "eqFloat#" Compare
1966++ Float# -> Float# -> Int#
1967++ with commutable = True
1968++
1969++primop FloatNeOp "neFloat#" Compare
1970++ Float# -> Float# -> Int#
1971++ with commutable = True
1972++
1973++primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Int#
1974++primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Int#
1975++
1976++primop FloatAddOp "plusFloat#" Dyadic
1977++ Float# -> Float# -> Float#
1978++ with commutable = True
1979++
1980++primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
1981++
1982++primop FloatMulOp "timesFloat#" Dyadic
1983++ Float# -> Float# -> Float#
1984++ with commutable = True
1985++
1986++primop FloatDivOp "divideFloat#" Dyadic
1987++ Float# -> Float# -> Float#
1988++ with can_fail = True
1989++
1990++primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
1991++
1992++primop FloatFabsOp "fabsFloat#" Monadic Float# -> Float#
1993++
1994++primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
1995++ {Truncates a {\tt Float#} value to the nearest {\tt Int#}.
1996++ Results are undefined if the truncation if truncation yields
1997++ a value outside the range of {\tt Int#}.}
1998++
1999++primop FloatExpOp "expFloat#" Monadic
2000++ Float# -> Float#
2001++ with
2002++ code_size = { primOpCodeSizeForeignCall }
2003++
2004++primop FloatLogOp "logFloat#" Monadic
2005++ Float# -> Float#
2006++ with
2007++ code_size = { primOpCodeSizeForeignCall }
2008++ can_fail = True
2009++
2010++primop FloatSqrtOp "sqrtFloat#" Monadic
2011++ Float# -> Float#
2012++ with
2013++ code_size = { primOpCodeSizeForeignCall }
2014++
2015++primop FloatSinOp "sinFloat#" Monadic
2016++ Float# -> Float#
2017++ with
2018++ code_size = { primOpCodeSizeForeignCall }
2019++
2020++primop FloatCosOp "cosFloat#" Monadic
2021++ Float# -> Float#
2022++ with
2023++ code_size = { primOpCodeSizeForeignCall }
2024++
2025++primop FloatTanOp "tanFloat#" Monadic
2026++ Float# -> Float#
2027++ with
2028++ code_size = { primOpCodeSizeForeignCall }
2029++
2030++primop FloatAsinOp "asinFloat#" Monadic
2031++ Float# -> Float#
2032++ with
2033++ code_size = { primOpCodeSizeForeignCall }
2034++ can_fail = True
2035++
2036++primop FloatAcosOp "acosFloat#" Monadic
2037++ Float# -> Float#
2038++ with
2039++ code_size = { primOpCodeSizeForeignCall }
2040++ can_fail = True
2041++
2042++primop FloatAtanOp "atanFloat#" Monadic
2043++ Float# -> Float#
2044++ with
2045++ code_size = { primOpCodeSizeForeignCall }
2046++
2047++primop FloatSinhOp "sinhFloat#" Monadic
2048++ Float# -> Float#
2049++ with
2050++ code_size = { primOpCodeSizeForeignCall }
2051++
2052++primop FloatCoshOp "coshFloat#" Monadic
2053++ Float# -> Float#
2054++ with
2055++ code_size = { primOpCodeSizeForeignCall }
2056++
2057++primop FloatTanhOp "tanhFloat#" Monadic
2058++ Float# -> Float#
2059++ with
2060++ code_size = { primOpCodeSizeForeignCall }
2061++
2062++primop FloatAsinhOp "asinhFloat#" Monadic
2063++ Float# -> Float#
2064++ with
2065++ code_size = { primOpCodeSizeForeignCall }
2066++
2067++primop FloatAcoshOp "acoshFloat#" Monadic
2068++ Float# -> Float#
2069++ with
2070++ code_size = { primOpCodeSizeForeignCall }
2071++
2072++primop FloatAtanhOp "atanhFloat#" Monadic
2073++ Float# -> Float#
2074++ with
2075++ code_size = { primOpCodeSizeForeignCall }
2076++
2077++primop FloatPowerOp "powerFloat#" Dyadic
2078++ Float# -> Float# -> Float#
2079++ with
2080++ code_size = { primOpCodeSizeForeignCall }
2081++
2082++primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
2083++
2084++primop FloatDecode_IntOp "decodeFloat_Int#" GenPrimOp
2085++ Float# -> (# Int#, Int# #)
2086++ {Convert to integers.
2087++ First {\tt Int\#} in result is the mantissa; second is the exponent.}
2088++ with out_of_line = True
2089++
2090++------------------------------------------------------------------------
2091++section "Arrays"
2092++ {Operations on {\tt Array\#}.}
2093++------------------------------------------------------------------------
2094++
2095++primtype Array# a
2096++
2097++primtype MutableArray# s a
2098++
2099++primop NewArrayOp "newArray#" GenPrimOp
2100++ Int# -> a -> State# s -> (# State# s, MutableArray# s a #)
2101++ {Create a new mutable array with the specified number of elements,
2102++ in the specified state thread,
2103++ with each element containing the specified initial value.}
2104++ with
2105++ out_of_line = True
2106++ has_side_effects = True
2107++
2108++primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
2109++ MutableArray# s a -> MutableArray# s a -> Int#
2110++
2111++primop ReadArrayOp "readArray#" GenPrimOp
2112++ MutableArray# s a -> Int# -> State# s -> (# State# s, a #)
2113++ {Read from specified index of mutable array. Result is not yet evaluated.}
2114++ with
2115++ has_side_effects = True
2116++ can_fail = True
2117++
2118++primop WriteArrayOp "writeArray#" GenPrimOp
2119++ MutableArray# s a -> Int# -> a -> State# s -> State# s
2120++ {Write to specified index of mutable array.}
2121++ with
2122++ has_side_effects = True
2123++ can_fail = True
2124++ code_size = 2 -- card update too
2125++
2126++primop SizeofArrayOp "sizeofArray#" GenPrimOp
2127++ Array# a -> Int#
2128++ {Return the number of elements in the array.}
2129++
2130++primop SizeofMutableArrayOp "sizeofMutableArray#" GenPrimOp
2131++ MutableArray# s a -> Int#
2132++ {Return the number of elements in the array.}
2133++
2134++primop IndexArrayOp "indexArray#" GenPrimOp
2135++ Array# a -> Int# -> (# a #)
2136++ {Read from the specified index of an immutable array. The result is packaged
2137++ into an unboxed unary tuple; the result itself is not yet
2138++ evaluated. Pattern matching on the tuple forces the indexing of the
2139++ array to happen but does not evaluate the element itself. Evaluating
2140++ the thunk prevents additional thunks from building up on the
2141++ heap. Avoiding these thunks, in turn, reduces references to the
2142++ argument array, allowing it to be garbage collected more promptly.}
2143++ with
2144++ can_fail = True
2145++
2146++primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
2147++ MutableArray# s a -> State# s -> (# State# s, Array# a #)
2148++ {Make a mutable array immutable, without copying.}
2149++ with
2150++ has_side_effects = True
2151++
2152++primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
2153++ Array# a -> State# s -> (# State# s, MutableArray# s a #)
2154++ {Make an immutable array mutable, without copying.}
2155++ with
2156++ out_of_line = True
2157++ has_side_effects = True
2158++
2159++primop CopyArrayOp "copyArray#" GenPrimOp
2160++ Array# a -> Int# -> MutableArray# s a -> Int# -> Int# -> State# s -> State# s
2161++ {Given a source array, an offset into the source array, a
2162++ destination array, an offset into the destination array, and a
2163++ number of elements to copy, copy the elements from the source array
2164++ to the destination array. Both arrays must fully contain the
2165++ specified ranges, but this is not checked. The two arrays must not
2166++ be the same array in different states, but this is not checked
2167++ either.}
2168++ with
2169++ out_of_line = True
2170++ has_side_effects = True
2171++ can_fail = True
2172++
2173++primop CopyMutableArrayOp "copyMutableArray#" GenPrimOp
2174++ MutableArray# s a -> Int# -> MutableArray# s a -> Int# -> Int# -> State# s -> State# s
2175++ {Given a source array, an offset into the source array, a
2176++ destination array, an offset into the destination array, and a
2177++ number of elements to copy, copy the elements from the source array
2178++ to the destination array. Both arrays must fully contain the
2179++ specified ranges, but this is not checked. In the case where
2180++ the source and destination are the same array the source and
2181++ destination regions may overlap.}
2182++ with
2183++ out_of_line = True
2184++ has_side_effects = True
2185++ can_fail = True
2186++
2187++primop CloneArrayOp "cloneArray#" GenPrimOp
2188++ Array# a -> Int# -> Int# -> Array# a
2189++ {Given a source array, an offset into the source array, and a number
2190++ of elements to copy, create a new array with the elements from the
2191++ source array. The provided array must fully contain the specified
2192++ range, but this is not checked.}
2193++ with
2194++ out_of_line = True
2195++ has_side_effects = True
2196++ can_fail = True
2197++
2198++primop CloneMutableArrayOp "cloneMutableArray#" GenPrimOp
2199++ MutableArray# s a -> Int# -> Int# -> State# s -> (# State# s, MutableArray# s a #)
2200++ {Given a source array, an offset into the source array, and a number
2201++ of elements to copy, create a new array with the elements from the
2202++ source array. The provided array must fully contain the specified
2203++ range, but this is not checked.}
2204++ with
2205++ out_of_line = True
2206++ has_side_effects = True
2207++ can_fail = True
2208++
2209++primop FreezeArrayOp "freezeArray#" GenPrimOp
2210++ MutableArray# s a -> Int# -> Int# -> State# s -> (# State# s, Array# a #)
2211++ {Given a source array, an offset into the source array, and a number
2212++ of elements to copy, create a new array with the elements from the
2213++ source array. The provided array must fully contain the specified
2214++ range, but this is not checked.}
2215++ with
2216++ out_of_line = True
2217++ has_side_effects = True
2218++ can_fail = True
2219++
2220++primop ThawArrayOp "thawArray#" GenPrimOp
2221++ Array# a -> Int# -> Int# -> State# s -> (# State# s, MutableArray# s a #)
2222++ {Given a source array, an offset into the source array, and a number
2223++ of elements to copy, create a new array with the elements from the
2224++ source array. The provided array must fully contain the specified
2225++ range, but this is not checked.}
2226++ with
2227++ out_of_line = True
2228++ has_side_effects = True
2229++ can_fail = True
2230++
2231++primop CasArrayOp "casArray#" GenPrimOp
2232++ MutableArray# s a -> Int# -> a -> a -> State# s -> (# State# s, Int#, a #)
2233++ {Unsafe, machine-level atomic compare and swap on an element within an Array.}
2234++ with
2235++ out_of_line = True
2236++ has_side_effects = True
2237++
2238++
2239++------------------------------------------------------------------------
2240++section "Small Arrays"
2241++
2242++ {Operations on {\tt SmallArray\#}. A {\tt SmallArray\#} works
2243++ just like an {\tt Array\#}, but with different space use and
2244++ performance characteristics (that are often useful with small
2245++ arrays). The {\tt SmallArray\#} and {\tt SmallMutableArray#}
2246++ lack a `card table'. The purpose of a card table is to avoid
2247++ having to scan every element of the array on each GC by
2248++ keeping track of which elements have changed since the last GC
2249++ and only scanning those that have changed. So the consequence
2250++ of there being no card table is that the representation is
2251++ somewhat smaller and the writes are somewhat faster (because
2252++ the card table does not need to be updated). The disadvantage
2253++ of course is that for a {\tt SmallMutableArray#} the whole
2254++ array has to be scanned on each GC. Thus it is best suited for
2255++ use cases where the mutable array is not long lived, e.g.
2256++ where a mutable array is initialised quickly and then frozen
2257++ to become an immutable {\tt SmallArray\#}.
2258++ }
2259++
2260++------------------------------------------------------------------------
2261++
2262++primtype SmallArray# a
2263++
2264++primtype SmallMutableArray# s a
2265++
2266++primop NewSmallArrayOp "newSmallArray#" GenPrimOp
2267++ Int# -> a -> State# s -> (# State# s, SmallMutableArray# s a #)
2268++ {Create a new mutable array with the specified number of elements,
2269++ in the specified state thread,
2270++ with each element containing the specified initial value.}
2271++ with
2272++ out_of_line = True
2273++ has_side_effects = True
2274++
2275++primop SameSmallMutableArrayOp "sameSmallMutableArray#" GenPrimOp
2276++ SmallMutableArray# s a -> SmallMutableArray# s a -> Int#
2277++
2278++primop ReadSmallArrayOp "readSmallArray#" GenPrimOp
2279++ SmallMutableArray# s a -> Int# -> State# s -> (# State# s, a #)
2280++ {Read from specified index of mutable array. Result is not yet evaluated.}
2281++ with
2282++ has_side_effects = True
2283++ can_fail = True
2284++
2285++primop WriteSmallArrayOp "writeSmallArray#" GenPrimOp
2286++ SmallMutableArray# s a -> Int# -> a -> State# s -> State# s
2287++ {Write to specified index of mutable array.}
2288++ with
2289++ has_side_effects = True
2290++ can_fail = True
2291++
2292++primop SizeofSmallArrayOp "sizeofSmallArray#" GenPrimOp
2293++ SmallArray# a -> Int#
2294++ {Return the number of elements in the array.}
2295++
2296++primop SizeofSmallMutableArrayOp "sizeofSmallMutableArray#" GenPrimOp
2297++ SmallMutableArray# s a -> Int#
2298++ {Return the number of elements in the array.}
2299++
2300++primop IndexSmallArrayOp "indexSmallArray#" GenPrimOp
2301++ SmallArray# a -> Int# -> (# a #)
2302++ {Read from specified index of immutable array. Result is packaged into
2303++ an unboxed singleton; the result itself is not yet evaluated.}
2304++ with
2305++ can_fail = True
2306++
2307++primop UnsafeFreezeSmallArrayOp "unsafeFreezeSmallArray#" GenPrimOp
2308++ SmallMutableArray# s a -> State# s -> (# State# s, SmallArray# a #)
2309++ {Make a mutable array immutable, without copying.}
2310++ with
2311++ has_side_effects = True
2312++
2313++primop UnsafeThawSmallArrayOp "unsafeThawSmallArray#" GenPrimOp
2314++ SmallArray# a -> State# s -> (# State# s, SmallMutableArray# s a #)
2315++ {Make an immutable array mutable, without copying.}
2316++ with
2317++ out_of_line = True
2318++ has_side_effects = True
2319++
2320++-- The code_size is only correct for the case when the copy family of
2321++-- primops aren't inlined. It would be nice to keep track of both.
2322++
2323++primop CopySmallArrayOp "copySmallArray#" GenPrimOp
2324++ SmallArray# a -> Int# -> SmallMutableArray# s a -> Int# -> Int# -> State# s -> State# s
2325++ {Given a source array, an offset into the source array, a
2326++ destination array, an offset into the destination array, and a
2327++ number of elements to copy, copy the elements from the source array
2328++ to the destination array. Both arrays must fully contain the
2329++ specified ranges, but this is not checked. The two arrays must not
2330++ be the same array in different states, but this is not checked
2331++ either.}
2332++ with
2333++ out_of_line = True
2334++ has_side_effects = True
2335++ can_fail = True
2336++
2337++primop CopySmallMutableArrayOp "copySmallMutableArray#" GenPrimOp
2338++ SmallMutableArray# s a -> Int# -> SmallMutableArray# s a -> Int# -> Int# -> State# s -> State# s
2339++ {Given a source array, an offset into the source array, a
2340++ destination array, an offset into the destination array, and a
2341++ number of elements to copy, copy the elements from the source array
2342++ to the destination array. The source and destination arrays can
2343++ refer to the same array. Both arrays must fully contain the
2344++ specified ranges, but this is not checked.
2345++ The regions are allowed to overlap, although this is only possible when the same
2346++ array is provided as both the source and the destination. }
2347++ with
2348++ out_of_line = True
2349++ has_side_effects = True
2350++ can_fail = True
2351++
2352++primop CloneSmallArrayOp "cloneSmallArray#" GenPrimOp
2353++ SmallArray# a -> Int# -> Int# -> SmallArray# a
2354++ {Given a source array, an offset into the source array, and a number
2355++ of elements to copy, create a new array with the elements from the
2356++ source array. The provided array must fully contain the specified
2357++ range, but this is not checked.}
2358++ with
2359++ out_of_line = True
2360++ has_side_effects = True
2361++ can_fail = True
2362++
2363++primop CloneSmallMutableArrayOp "cloneSmallMutableArray#" GenPrimOp
2364++ SmallMutableArray# s a -> Int# -> Int# -> State# s -> (# State# s, SmallMutableArray# s a #)
2365++ {Given a source array, an offset into the source array, and a number
2366++ of elements to copy, create a new array with the elements from the
2367++ source array. The provided array must fully contain the specified
2368++ range, but this is not checked.}
2369++ with
2370++ out_of_line = True
2371++ has_side_effects = True
2372++ can_fail = True
2373++
2374++primop FreezeSmallArrayOp "freezeSmallArray#" GenPrimOp
2375++ SmallMutableArray# s a -> Int# -> Int# -> State# s -> (# State# s, SmallArray# a #)
2376++ {Given a source array, an offset into the source array, and a number
2377++ of elements to copy, create a new array with the elements from the
2378++ source array. The provided array must fully contain the specified
2379++ range, but this is not checked.}
2380++ with
2381++ out_of_line = True
2382++ has_side_effects = True
2383++ can_fail = True
2384++
2385++primop ThawSmallArrayOp "thawSmallArray#" GenPrimOp
2386++ SmallArray# a -> Int# -> Int# -> State# s -> (# State# s, SmallMutableArray# s a #)
2387++ {Given a source array, an offset into the source array, and a number
2388++ of elements to copy, create a new array with the elements from the
2389++ source array. The provided array must fully contain the specified
2390++ range, but this is not checked.}
2391++ with
2392++ out_of_line = True
2393++ has_side_effects = True
2394++ can_fail = True
2395++
2396++primop CasSmallArrayOp "casSmallArray#" GenPrimOp
2397++ SmallMutableArray# s a -> Int# -> a -> a -> State# s -> (# State# s, Int#, a #)
2398++ {Unsafe, machine-level atomic compare and swap on an element within an array.}
2399++ with
2400++ out_of_line = True
2401++ has_side_effects = True
2402++
2403++------------------------------------------------------------------------
2404++section "Byte Arrays"
2405++ {Operations on {\tt ByteArray\#}. A {\tt ByteArray\#} is a just a region of
2406++ raw memory in the garbage-collected heap, which is not
2407++ scanned for pointers. It carries its own size (in bytes).
2408++ There are
2409++ three sets of operations for accessing byte array contents:
2410++ index for reading from immutable byte arrays, and read/write
2411++ for mutable byte arrays. Each set contains operations for a
2412++ range of useful primitive data types. Each operation takes
2413++ an offset measured in terms of the size of the primitive type
2414++ being read or written.}
2415++
2416++------------------------------------------------------------------------
2417++
2418++primtype ByteArray#
2419++
2420++primtype MutableByteArray# s
2421++
2422++primop NewByteArrayOp_Char "newByteArray#" GenPrimOp
2423++ Int# -> State# s -> (# State# s, MutableByteArray# s #)
2424++ {Create a new mutable byte array of specified size (in bytes), in
2425++ the specified state thread.}
2426++ with out_of_line = True
2427++ has_side_effects = True
2428++
2429++primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
2430++ Int# -> State# s -> (# State# s, MutableByteArray# s #)
2431++ {Create a mutable byte array that the GC guarantees not to move.}
2432++ with out_of_line = True
2433++ has_side_effects = True
2434++
2435++primop NewAlignedPinnedByteArrayOp_Char "newAlignedPinnedByteArray#" GenPrimOp
2436++ Int# -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
2437++ {Create a mutable byte array, aligned by the specified amount, that the GC guarantees not to move.}
2438++ with out_of_line = True
2439++ has_side_effects = True
2440++
2441++primop MutableByteArrayIsPinnedOp "isMutableByteArrayPinned#" GenPrimOp
2442++ MutableByteArray# s -> Int#
2443++ {Determine whether a {\tt MutableByteArray\#} is guaranteed not to move
2444++ during GC.}
2445++ with out_of_line = True
2446++
2447++primop ByteArrayIsPinnedOp "isByteArrayPinned#" GenPrimOp
2448++ ByteArray# -> Int#
2449++ {Determine whether a {\tt ByteArray\#} is guaranteed not to move during GC.}
2450++ with out_of_line = True
2451++
2452++primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
2453++ ByteArray# -> Addr#
2454++ {Intended for use with pinned arrays; otherwise very unsafe!}
2455++
2456++primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
2457++ MutableByteArray# s -> MutableByteArray# s -> Int#
2458++
2459++primop ShrinkMutableByteArrayOp_Char "shrinkMutableByteArray#" GenPrimOp
2460++ MutableByteArray# s -> Int# -> State# s -> State# s
2461++ {Shrink mutable byte array to new specified size (in bytes), in
2462++ the specified state thread. The new size argument must be less than or
2463++ equal to the current size as reported by {\tt sizeofMutableArray\#}.}
2464++ with out_of_line = True
2465++ has_side_effects = True
2466++
2467++primop ResizeMutableByteArrayOp_Char "resizeMutableByteArray#" GenPrimOp
2468++ MutableByteArray# s -> Int# -> State# s -> (# State# s,MutableByteArray# s #)
2469++ {Resize (unpinned) mutable byte array to new specified size (in bytes).
2470++ The returned {\tt MutableByteArray\#} is either the original
2471++ {\tt MutableByteArray\#} resized in-place or, if not possible, a newly
2472++ allocated (unpinned) {\tt MutableByteArray\#} (with the original content
2473++ copied over).
2474++
2475++ To avoid undefined behaviour, the original {\tt MutableByteArray\#} shall
2476++ not be accessed anymore after a {\tt resizeMutableByteArray\#} has been
2477++ performed. Moreover, no reference to the old one should be kept in order
2478++ to allow garbage collection of the original {\tt MutableByteArray\#} in
2479++ case a new {\tt MutableByteArray\#} had to be allocated.}
2480++ with out_of_line = True
2481++ has_side_effects = True
2482++
2483++primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
2484++ MutableByteArray# s -> State# s -> (# State# s, ByteArray# #)
2485++ {Make a mutable byte array immutable, without copying.}
2486++ with
2487++ has_side_effects = True
2488++
2489++primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
2490++ ByteArray# -> Int#
2491++ {Return the size of the array in bytes.}
2492++
2493++primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
2494++ MutableByteArray# s -> Int#
2495++ {Return the size of the array in bytes. Note that this is deprecated as it is
2496++ unsafe in the presence of concurrent resize operations on the same byte
2497++ array.}
2498++ with deprecated_msg = { Use 'getSizeofMutableByteArray#' instead }
2499++
2500++primop GetSizeofMutableByteArrayOp "getSizeofMutableByteArray#" GenPrimOp
2501++ MutableByteArray# s -> State# s -> (# State# s, Int# #)
2502++ {Return the number of elements in the array.}
2503++
2504++primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
2505++ ByteArray# -> Int# -> Char#
2506++ {Read 8-bit character; offset in bytes.}
2507++ with can_fail = True
2508++
2509++primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
2510++ ByteArray# -> Int# -> Char#
2511++ {Read 31-bit character; offset in 4-byte words.}
2512++ with can_fail = True
2513++
2514++primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
2515++ ByteArray# -> Int# -> Int#
2516++ with can_fail = True
2517++
2518++primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
2519++ ByteArray# -> Int# -> Word#
2520++ with can_fail = True
2521++
2522++primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
2523++ ByteArray# -> Int# -> Addr#
2524++ with can_fail = True
2525++
2526++primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
2527++ ByteArray# -> Int# -> Float#
2528++ with can_fail = True
2529++
2530++primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
2531++ ByteArray# -> Int# -> Double#
2532++ with can_fail = True
2533++
2534++primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
2535++ ByteArray# -> Int# -> StablePtr# a
2536++ with can_fail = True
2537++
2538++primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
2539++ ByteArray# -> Int# -> Int#
2540++ {Read 8-bit integer; offset in bytes.}
2541++ with can_fail = True
2542++
2543++primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
2544++ ByteArray# -> Int# -> Int#
2545++ {Read 16-bit integer; offset in 16-bit words.}
2546++ with can_fail = True
2547++
2548++primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
2549++ ByteArray# -> Int# -> INT32
2550++ {Read 32-bit integer; offset in 32-bit words.}
2551++ with can_fail = True
2552++
2553++primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
2554++ ByteArray# -> Int# -> INT64
2555++ {Read 64-bit integer; offset in 64-bit words.}
2556++ with can_fail = True
2557++
2558++primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
2559++ ByteArray# -> Int# -> Word#
2560++ {Read 8-bit word; offset in bytes.}
2561++ with can_fail = True
2562++
2563++primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
2564++ ByteArray# -> Int# -> Word#
2565++ {Read 16-bit word; offset in 16-bit words.}
2566++ with can_fail = True
2567++
2568++primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
2569++ ByteArray# -> Int# -> WORD32
2570++ {Read 32-bit word; offset in 32-bit words.}
2571++ with can_fail = True
2572++
2573++primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
2574++ ByteArray# -> Int# -> WORD64
2575++ {Read 64-bit word; offset in 64-bit words.}
2576++ with can_fail = True
2577++
2578++primop IndexByteArrayOp_Word8AsChar "indexWord8ArrayAsChar#" GenPrimOp
2579++ ByteArray# -> Int# -> Char#
2580++ {Read 8-bit character; offset in bytes.}
2581++ with can_fail = True
2582++
2583++primop IndexByteArrayOp_Word8AsWideChar "indexWord8ArrayAsWideChar#" GenPrimOp
2584++ ByteArray# -> Int# -> Char#
2585++ {Read 31-bit character; offset in bytes.}
2586++ with can_fail = True
2587++
2588++primop IndexByteArrayOp_Word8AsAddr "indexWord8ArrayAsAddr#" GenPrimOp
2589++ ByteArray# -> Int# -> Addr#
2590++ {Read address; offset in bytes.}
2591++ with can_fail = True
2592++
2593++primop IndexByteArrayOp_Word8AsFloat "indexWord8ArrayAsFloat#" GenPrimOp
2594++ ByteArray# -> Int# -> Float#
2595++ {Read float; offset in bytes.}
2596++ with can_fail = True
2597++
2598++primop IndexByteArrayOp_Word8AsDouble "indexWord8ArrayAsDouble#" GenPrimOp
2599++ ByteArray# -> Int# -> Double#
2600++ {Read double; offset in bytes.}
2601++ with can_fail = True
2602++
2603++primop IndexByteArrayOp_Word8AsStablePtr "indexWord8ArrayAsStablePtr#" GenPrimOp
2604++ ByteArray# -> Int# -> StablePtr# a
2605++ {Read stable pointer; offset in bytes.}
2606++ with can_fail = True
2607++
2608++primop IndexByteArrayOp_Word8AsInt16 "indexWord8ArrayAsInt16#" GenPrimOp
2609++ ByteArray# -> Int# -> Int#
2610++ {Read 16-bit int; offset in bytes.}
2611++ with can_fail = True
2612++
2613++primop IndexByteArrayOp_Word8AsInt32 "indexWord8ArrayAsInt32#" GenPrimOp
2614++ ByteArray# -> Int# -> INT32
2615++ {Read 32-bit int; offset in bytes.}
2616++ with can_fail = True
2617++
2618++primop IndexByteArrayOp_Word8AsInt64 "indexWord8ArrayAsInt64#" GenPrimOp
2619++ ByteArray# -> Int# -> INT64
2620++ {Read 64-bit int; offset in bytes.}
2621++ with can_fail = True
2622++
2623++primop IndexByteArrayOp_Word8AsInt "indexWord8ArrayAsInt#" GenPrimOp
2624++ ByteArray# -> Int# -> Int#
2625++ {Read int; offset in bytes.}
2626++ with can_fail = True
2627++
2628++primop IndexByteArrayOp_Word8AsWord16 "indexWord8ArrayAsWord16#" GenPrimOp
2629++ ByteArray# -> Int# -> Word#
2630++ {Read 16-bit word; offset in bytes.}
2631++ with can_fail = True
2632++
2633++primop IndexByteArrayOp_Word8AsWord32 "indexWord8ArrayAsWord32#" GenPrimOp
2634++ ByteArray# -> Int# -> WORD32
2635++ {Read 32-bit word; offset in bytes.}
2636++ with can_fail = True
2637++
2638++primop IndexByteArrayOp_Word8AsWord64 "indexWord8ArrayAsWord64#" GenPrimOp
2639++ ByteArray# -> Int# -> WORD64
2640++ {Read 64-bit word; offset in bytes.}
2641++ with can_fail = True
2642++
2643++primop IndexByteArrayOp_Word8AsWord "indexWord8ArrayAsWord#" GenPrimOp
2644++ ByteArray# -> Int# -> Word#
2645++ {Read word; offset in bytes.}
2646++ with can_fail = True
2647++
2648++primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
2649++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
2650++ {Read 8-bit character; offset in bytes.}
2651++ with has_side_effects = True
2652++ can_fail = True
2653++
2654++primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
2655++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
2656++ {Read 31-bit character; offset in 4-byte words.}
2657++ with has_side_effects = True
2658++ can_fail = True
2659++
2660++primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
2661++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
2662++ {Read integer; offset in words.}
2663++ with has_side_effects = True
2664++ can_fail = True
2665++
2666++primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
2667++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
2668++ {Read word; offset in words.}
2669++ with has_side_effects = True
2670++ can_fail = True
2671++
2672++primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
2673++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Addr# #)
2674++ with has_side_effects = True
2675++ can_fail = True
2676++
2677++primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
2678++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Float# #)
2679++ with has_side_effects = True
2680++ can_fail = True
2681++
2682++primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
2683++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Double# #)
2684++ with has_side_effects = True
2685++ can_fail = True
2686++
2687++primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
2688++ MutableByteArray# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
2689++ with has_side_effects = True
2690++ can_fail = True
2691++
2692++primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
2693++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
2694++ with has_side_effects = True
2695++ can_fail = True
2696++
2697++primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
2698++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
2699++ with has_side_effects = True
2700++ can_fail = True
2701++
2702++primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
2703++ MutableByteArray# s -> Int# -> State# s -> (# State# s, INT32 #)
2704++ with has_side_effects = True
2705++ can_fail = True
2706++
2707++primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
2708++ MutableByteArray# s -> Int# -> State# s -> (# State# s, INT64 #)
2709++ with has_side_effects = True
2710++ can_fail = True
2711++
2712++primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
2713++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
2714++ with has_side_effects = True
2715++ can_fail = True
2716++
2717++primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
2718++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
2719++ with has_side_effects = True
2720++ can_fail = True
2721++
2722++primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
2723++ MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD32 #)
2724++ with has_side_effects = True
2725++ can_fail = True
2726++
2727++primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
2728++ MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD64 #)
2729++ with has_side_effects = True
2730++ can_fail = True
2731++
2732++primop ReadByteArrayOp_Word8AsChar "readWord8ArrayAsChar#" GenPrimOp
2733++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
2734++ with has_side_effects = True
2735++ can_fail = True
2736++
2737++primop ReadByteArrayOp_Word8AsWideChar "readWord8ArrayAsWideChar#" GenPrimOp
2738++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
2739++ with has_side_effects = True
2740++ can_fail = True
2741++
2742++primop ReadByteArrayOp_Word8AsAddr "readWord8ArrayAsAddr#" GenPrimOp
2743++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Addr# #)
2744++ with has_side_effects = True
2745++ can_fail = True
2746++
2747++primop ReadByteArrayOp_Word8AsFloat "readWord8ArrayAsFloat#" GenPrimOp
2748++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Float# #)
2749++ with has_side_effects = True
2750++ can_fail = True
2751++
2752++primop ReadByteArrayOp_Word8AsDouble "readWord8ArrayAsDouble#" GenPrimOp
2753++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Double# #)
2754++ with has_side_effects = True
2755++ can_fail = True
2756++
2757++primop ReadByteArrayOp_Word8AsStablePtr "readWord8ArrayAsStablePtr#" GenPrimOp
2758++ MutableByteArray# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
2759++ with has_side_effects = True
2760++ can_fail = True
2761++
2762++primop ReadByteArrayOp_Word8AsInt16 "readWord8ArrayAsInt16#" GenPrimOp
2763++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
2764++ with has_side_effects = True
2765++ can_fail = True
2766++
2767++primop ReadByteArrayOp_Word8AsInt32 "readWord8ArrayAsInt32#" GenPrimOp
2768++ MutableByteArray# s -> Int# -> State# s -> (# State# s, INT32 #)
2769++ with has_side_effects = True
2770++ can_fail = True
2771++
2772++primop ReadByteArrayOp_Word8AsInt64 "readWord8ArrayAsInt64#" GenPrimOp
2773++ MutableByteArray# s -> Int# -> State# s -> (# State# s, INT64 #)
2774++ with has_side_effects = True
2775++ can_fail = True
2776++
2777++primop ReadByteArrayOp_Word8AsInt "readWord8ArrayAsInt#" GenPrimOp
2778++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
2779++ with has_side_effects = True
2780++ can_fail = True
2781++
2782++primop ReadByteArrayOp_Word8AsWord16 "readWord8ArrayAsWord16#" GenPrimOp
2783++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
2784++ with has_side_effects = True
2785++ can_fail = True
2786++
2787++primop ReadByteArrayOp_Word8AsWord32 "readWord8ArrayAsWord32#" GenPrimOp
2788++ MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD32 #)
2789++ with has_side_effects = True
2790++ can_fail = True
2791++
2792++primop ReadByteArrayOp_Word8AsWord64 "readWord8ArrayAsWord64#" GenPrimOp
2793++ MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD64 #)
2794++ with has_side_effects = True
2795++ can_fail = True
2796++
2797++primop ReadByteArrayOp_Word8AsWord "readWord8ArrayAsWord#" GenPrimOp
2798++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
2799++ with has_side_effects = True
2800++ can_fail = True
2801++
2802++primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
2803++ MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
2804++ {Write 8-bit character; offset in bytes.}
2805++ with has_side_effects = True
2806++ can_fail = True
2807++
2808++primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
2809++ MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
2810++ {Write 31-bit character; offset in 4-byte words.}
2811++ with has_side_effects = True
2812++ can_fail = True
2813++
2814++primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
2815++ MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
2816++ with has_side_effects = True
2817++ can_fail = True
2818++
2819++primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
2820++ MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
2821++ with has_side_effects = True
2822++ can_fail = True
2823++
2824++primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
2825++ MutableByteArray# s -> Int# -> Addr# -> State# s -> State# s
2826++ with has_side_effects = True
2827++ can_fail = True
2828++
2829++primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
2830++ MutableByteArray# s -> Int# -> Float# -> State# s -> State# s
2831++ with has_side_effects = True
2832++ can_fail = True
2833++
2834++primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
2835++ MutableByteArray# s -> Int# -> Double# -> State# s -> State# s
2836++ with has_side_effects = True
2837++ can_fail = True
2838++
2839++primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
2840++ MutableByteArray# s -> Int# -> StablePtr# a -> State# s -> State# s
2841++ with has_side_effects = True
2842++ can_fail = True
2843++
2844++primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
2845++ MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
2846++ with has_side_effects = True
2847++ can_fail = True
2848++
2849++primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
2850++ MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
2851++ with has_side_effects = True
2852++ can_fail = True
2853++
2854++primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
2855++ MutableByteArray# s -> Int# -> INT32 -> State# s -> State# s
2856++ with has_side_effects = True
2857++ can_fail = True
2858++
2859++primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
2860++ MutableByteArray# s -> Int# -> INT64 -> State# s -> State# s
2861++ with can_fail = True
2862++ has_side_effects = True
2863++
2864++primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
2865++ MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
2866++ with has_side_effects = True
2867++ can_fail = True
2868++
2869++primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
2870++ MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
2871++ with has_side_effects = True
2872++ can_fail = True
2873++
2874++primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
2875++ MutableByteArray# s -> Int# -> WORD32 -> State# s -> State# s
2876++ with has_side_effects = True
2877++ can_fail = True
2878++
2879++primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
2880++ MutableByteArray# s -> Int# -> WORD64 -> State# s -> State# s
2881++ with has_side_effects = True
2882++ can_fail = True
2883++
2884++primop WriteByteArrayOp_Word8AsChar "writeWord8ArrayAsChar#" GenPrimOp
2885++ MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
2886++ with has_side_effects = True
2887++ can_fail = True
2888++
2889++primop WriteByteArrayOp_Word8AsWideChar "writeWord8ArrayAsWideChar#" GenPrimOp
2890++ MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
2891++ with has_side_effects = True
2892++ can_fail = True
2893++
2894++primop WriteByteArrayOp_Word8AsAddr "writeWord8ArrayAsAddr#" GenPrimOp
2895++ MutableByteArray# s -> Int# -> Addr# -> State# s -> State# s
2896++ with has_side_effects = True
2897++ can_fail = True
2898++
2899++primop WriteByteArrayOp_Word8AsFloat "writeWord8ArrayAsFloat#" GenPrimOp
2900++ MutableByteArray# s -> Int# -> Float# -> State# s -> State# s
2901++ with has_side_effects = True
2902++ can_fail = True
2903++
2904++primop WriteByteArrayOp_Word8AsDouble "writeWord8ArrayAsDouble#" GenPrimOp
2905++ MutableByteArray# s -> Int# -> Double# -> State# s -> State# s
2906++ with has_side_effects = True
2907++ can_fail = True
2908++
2909++primop WriteByteArrayOp_Word8AsStablePtr "writeWord8ArrayAsStablePtr#" GenPrimOp
2910++ MutableByteArray# s -> Int# -> StablePtr# a -> State# s -> State# s
2911++ with has_side_effects = True
2912++ can_fail = True
2913++
2914++primop WriteByteArrayOp_Word8AsInt16 "writeWord8ArrayAsInt16#" GenPrimOp
2915++ MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
2916++ with has_side_effects = True
2917++ can_fail = True
2918++
2919++primop WriteByteArrayOp_Word8AsInt32 "writeWord8ArrayAsInt32#" GenPrimOp
2920++ MutableByteArray# s -> Int# -> INT32 -> State# s -> State# s
2921++ with has_side_effects = True
2922++ can_fail = True
2923++
2924++primop WriteByteArrayOp_Word8AsInt64 "writeWord8ArrayAsInt64#" GenPrimOp
2925++ MutableByteArray# s -> Int# -> INT64 -> State# s -> State# s
2926++ with has_side_effects = True
2927++ can_fail = True
2928++
2929++primop WriteByteArrayOp_Word8AsInt "writeWord8ArrayAsInt#" GenPrimOp
2930++ MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
2931++ with has_side_effects = True
2932++ can_fail = True
2933++
2934++primop WriteByteArrayOp_Word8AsWord16 "writeWord8ArrayAsWord16#" GenPrimOp
2935++ MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
2936++ with has_side_effects = True
2937++ can_fail = True
2938++
2939++primop WriteByteArrayOp_Word8AsWord32 "writeWord8ArrayAsWord32#" GenPrimOp
2940++ MutableByteArray# s -> Int# -> WORD32 -> State# s -> State# s
2941++ with has_side_effects = True
2942++ can_fail = True
2943++
2944++primop WriteByteArrayOp_Word8AsWord64 "writeWord8ArrayAsWord64#" GenPrimOp
2945++ MutableByteArray# s -> Int# -> WORD64 -> State# s -> State# s
2946++ with has_side_effects = True
2947++ can_fail = True
2948++
2949++primop WriteByteArrayOp_Word8AsWord "writeWord8ArrayAsWord#" GenPrimOp
2950++ MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
2951++ with has_side_effects = True
2952++ can_fail = True
2953++
2954++primop CompareByteArraysOp "compareByteArrays#" GenPrimOp
2955++ ByteArray# -> Int# -> ByteArray# -> Int# -> Int# -> Int#
2956++ {{\tt compareByteArrays# src1 src1_ofs src2 src2_ofs n} compares
2957++ {\tt n} bytes starting at offset {\tt src1_ofs} in the first
2958++ {\tt ByteArray#} {\tt src1} to the range of {\tt n} bytes
2959++ (i.e. same length) starting at offset {\tt src2_ofs} of the second
2960++ {\tt ByteArray#} {\tt src2}. Both arrays must fully contain the
2961++ specified ranges, but this is not checked. Returns an {\tt Int#}
2962++ less than, equal to, or greater than zero if the range is found,
2963++ respectively, to be byte-wise lexicographically less than, to
2964++ match, or be greater than the second range.}
2965++ with
2966++ can_fail = True
2967++
2968++primop CopyByteArrayOp "copyByteArray#" GenPrimOp
2969++ ByteArray# -> Int# -> MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
2970++ {{\tt copyByteArray# src src_ofs dst dst_ofs n} copies the range
2971++ starting at offset {\tt src_ofs} of length {\tt n} from the
2972++ {\tt ByteArray#} {\tt src} to the {\tt MutableByteArray#} {\tt dst}
2973++ starting at offset {\tt dst_ofs}. Both arrays must fully contain
2974++ the specified ranges, but this is not checked. The two arrays must
2975++ not be the same array in different states, but this is not checked
2976++ either.}
2977++ with
2978++ has_side_effects = True
2979++ code_size = { primOpCodeSizeForeignCall + 4}
2980++ can_fail = True
2981++
2982++primop CopyMutableByteArrayOp "copyMutableByteArray#" GenPrimOp
2983++ MutableByteArray# s -> Int# -> MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
2984++ {Copy a range of the first MutableByteArray\# to the specified region in the second MutableByteArray\#.
2985++ Both arrays must fully contain the specified ranges, but this is not checked. The regions are
2986++ allowed to overlap, although this is only possible when the same array is provided
2987++ as both the source and the destination.}
2988++ with
2989++ has_side_effects = True
2990++ code_size = { primOpCodeSizeForeignCall + 4 }
2991++ can_fail = True
2992++
2993++primop CopyByteArrayToAddrOp "copyByteArrayToAddr#" GenPrimOp
2994++ ByteArray# -> Int# -> Addr# -> Int# -> State# s -> State# s
2995++ {Copy a range of the ByteArray\# to the memory range starting at the Addr\#.
2996++ The ByteArray\# and the memory region at Addr\# must fully contain the
2997++ specified ranges, but this is not checked. The Addr\# must not point into the
2998++ ByteArray\# (e.g. if the ByteArray\# were pinned), but this is not checked
2999++ either.}
3000++ with
3001++ has_side_effects = True
3002++ code_size = { primOpCodeSizeForeignCall + 4}
3003++ can_fail = True
3004++
3005++primop CopyMutableByteArrayToAddrOp "copyMutableByteArrayToAddr#" GenPrimOp
3006++ MutableByteArray# s -> Int# -> Addr# -> Int# -> State# s -> State# s
3007++ {Copy a range of the MutableByteArray\# to the memory range starting at the
3008++ Addr\#. The MutableByteArray\# and the memory region at Addr\# must fully
3009++ contain the specified ranges, but this is not checked. The Addr\# must not
3010++ point into the MutableByteArray\# (e.g. if the MutableByteArray\# were
3011++ pinned), but this is not checked either.}
3012++ with
3013++ has_side_effects = True
3014++ code_size = { primOpCodeSizeForeignCall + 4}
3015++ can_fail = True
3016++
3017++primop CopyAddrToByteArrayOp "copyAddrToByteArray#" GenPrimOp
3018++ Addr# -> MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
3019++ {Copy a memory range starting at the Addr\# to the specified range in the
3020++ MutableByteArray\#. The memory region at Addr\# and the ByteArray\# must fully
3021++ contain the specified ranges, but this is not checked. The Addr\# must not
3022++ point into the MutableByteArray\# (e.g. if the MutableByteArray\# were pinned),
3023++ but this is not checked either.}
3024++ with
3025++ has_side_effects = True
3026++ code_size = { primOpCodeSizeForeignCall + 4}
3027++ can_fail = True
3028++
3029++primop SetByteArrayOp "setByteArray#" GenPrimOp
3030++ MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> State# s
3031++ {{\tt setByteArray# ba off len c} sets the byte range {\tt [off, off+len]} of
3032++ the {\tt MutableByteArray#} to the byte {\tt c}.}
3033++ with
3034++ has_side_effects = True
3035++ code_size = { primOpCodeSizeForeignCall + 4 }
3036++ can_fail = True
3037++
3038++-- Atomic operations
3039++
3040++primop AtomicReadByteArrayOp_Int "atomicReadIntArray#" GenPrimOp
3041++ MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
3042++ {Given an array and an offset in Int units, read an element. The
3043++ index is assumed to be in bounds. Implies a full memory barrier.}
3044++ with has_side_effects = True
3045++ can_fail = True
3046++
3047++primop AtomicWriteByteArrayOp_Int "atomicWriteIntArray#" GenPrimOp
3048++ MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
3049++ {Given an array and an offset in Int units, write an element. The
3050++ index is assumed to be in bounds. Implies a full memory barrier.}
3051++ with has_side_effects = True
3052++ can_fail = True
3053++
3054++primop CasByteArrayOp_Int "casIntArray#" GenPrimOp
3055++ MutableByteArray# s -> Int# -> Int# -> Int# -> State# s -> (# State# s, Int# #)
3056++ {Given an array, an offset in Int units, the expected old value, and
3057++ the new value, perform an atomic compare and swap i.e. write the new
3058++ value if the current value matches the provided old value. Returns
3059++ the value of the element before the operation. Implies a full memory
3060++ barrier.}
3061++ with has_side_effects = True
3062++ can_fail = True
3063++
3064++primop FetchAddByteArrayOp_Int "fetchAddIntArray#" GenPrimOp
3065++ MutableByteArray# s -> Int# -> Int# -> State# s -> (# State# s, Int# #)
3066++ {Given an array, and offset in Int units, and a value to add,
3067++ atomically add the value to the element. Returns the value of the
3068++ element before the operation. Implies a full memory barrier.}
3069++ with has_side_effects = True
3070++ can_fail = True
3071++
3072++primop FetchSubByteArrayOp_Int "fetchSubIntArray#" GenPrimOp
3073++ MutableByteArray# s -> Int# -> Int# -> State# s -> (# State# s, Int# #)
3074++ {Given an array, and offset in Int units, and a value to subtract,
3075++ atomically substract the value to the element. Returns the value of
3076++ the element before the operation. Implies a full memory barrier.}
3077++ with has_side_effects = True
3078++ can_fail = True
3079++
3080++primop FetchAndByteArrayOp_Int "fetchAndIntArray#" GenPrimOp
3081++ MutableByteArray# s -> Int# -> Int# -> State# s -> (# State# s, Int# #)
3082++ {Given an array, and offset in Int units, and a value to AND,
3083++ atomically AND the value to the element. Returns the value of the
3084++ element before the operation. Implies a full memory barrier.}
3085++ with has_side_effects = True
3086++ can_fail = True
3087++
3088++primop FetchNandByteArrayOp_Int "fetchNandIntArray#" GenPrimOp
3089++ MutableByteArray# s -> Int# -> Int# -> State# s -> (# State# s, Int# #)
3090++ {Given an array, and offset in Int units, and a value to NAND,
3091++ atomically NAND the value to the element. Returns the value of the
3092++ element before the operation. Implies a full memory barrier.}
3093++ with has_side_effects = True
3094++ can_fail = True
3095++
3096++primop FetchOrByteArrayOp_Int "fetchOrIntArray#" GenPrimOp
3097++ MutableByteArray# s -> Int# -> Int# -> State# s -> (# State# s, Int# #)
3098++ {Given an array, and offset in Int units, and a value to OR,
3099++ atomically OR the value to the element. Returns the value of the
3100++ element before the operation. Implies a full memory barrier.}
3101++ with has_side_effects = True
3102++ can_fail = True
3103++
3104++primop FetchXorByteArrayOp_Int "fetchXorIntArray#" GenPrimOp
3105++ MutableByteArray# s -> Int# -> Int# -> State# s -> (# State# s, Int# #)
3106++ {Given an array, and offset in Int units, and a value to XOR,
3107++ atomically XOR the value to the element. Returns the value of the
3108++ element before the operation. Implies a full memory barrier.}
3109++ with has_side_effects = True
3110++ can_fail = True
3111++
3112++
3113++------------------------------------------------------------------------
3114++section "Arrays of arrays"
3115++ {Operations on {\tt ArrayArray\#}. An {\tt ArrayArray\#} contains references to {\em unpointed}
3116++ arrays, such as {\tt ByteArray\#s}. Hence, it is not parameterised by the element types,
3117++ just like a {\tt ByteArray\#}, but it needs to be scanned during GC, just like an {\tt Array\#}.
3118++ We represent an {\tt ArrayArray\#} exactly as a {\tt Array\#}, but provide element-type-specific
3119++ indexing, reading, and writing.}
3120++------------------------------------------------------------------------
3121++
3122++primtype ArrayArray#
3123++
3124++primtype MutableArrayArray# s
3125++
3126++primop NewArrayArrayOp "newArrayArray#" GenPrimOp
3127++ Int# -> State# s -> (# State# s, MutableArrayArray# s #)
3128++ {Create a new mutable array of arrays with the specified number of elements,
3129++ in the specified state thread, with each element recursively referring to the
3130++ newly created array.}
3131++ with
3132++ out_of_line = True
3133++ has_side_effects = True
3134++
3135++primop SameMutableArrayArrayOp "sameMutableArrayArray#" GenPrimOp
3136++ MutableArrayArray# s -> MutableArrayArray# s -> Int#
3137++
3138++primop UnsafeFreezeArrayArrayOp "unsafeFreezeArrayArray#" GenPrimOp
3139++ MutableArrayArray# s -> State# s -> (# State# s, ArrayArray# #)
3140++ {Make a mutable array of arrays immutable, without copying.}
3141++ with
3142++ has_side_effects = True
3143++
3144++primop SizeofArrayArrayOp "sizeofArrayArray#" GenPrimOp
3145++ ArrayArray# -> Int#
3146++ {Return the number of elements in the array.}
3147++
3148++primop SizeofMutableArrayArrayOp "sizeofMutableArrayArray#" GenPrimOp
3149++ MutableArrayArray# s -> Int#
3150++ {Return the number of elements in the array.}
3151++
3152++primop IndexArrayArrayOp_ByteArray "indexByteArrayArray#" GenPrimOp
3153++ ArrayArray# -> Int# -> ByteArray#
3154++ with can_fail = True
3155++
3156++primop IndexArrayArrayOp_ArrayArray "indexArrayArrayArray#" GenPrimOp
3157++ ArrayArray# -> Int# -> ArrayArray#
3158++ with can_fail = True
3159++
3160++primop ReadArrayArrayOp_ByteArray "readByteArrayArray#" GenPrimOp
3161++ MutableArrayArray# s -> Int# -> State# s -> (# State# s, ByteArray# #)
3162++ with has_side_effects = True
3163++ can_fail = True
3164++
3165++primop ReadArrayArrayOp_MutableByteArray "readMutableByteArrayArray#" GenPrimOp
3166++ MutableArrayArray# s -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
3167++ with has_side_effects = True
3168++ can_fail = True
3169++
3170++primop ReadArrayArrayOp_ArrayArray "readArrayArrayArray#" GenPrimOp
3171++ MutableArrayArray# s -> Int# -> State# s -> (# State# s, ArrayArray# #)
3172++ with has_side_effects = True
3173++ can_fail = True
3174++
3175++primop ReadArrayArrayOp_MutableArrayArray "readMutableArrayArrayArray#" GenPrimOp
3176++ MutableArrayArray# s -> Int# -> State# s -> (# State# s, MutableArrayArray# s #)
3177++ with has_side_effects = True
3178++ can_fail = True
3179++
3180++primop WriteArrayArrayOp_ByteArray "writeByteArrayArray#" GenPrimOp
3181++ MutableArrayArray# s -> Int# -> ByteArray# -> State# s -> State# s
3182++ with has_side_effects = True
3183++ can_fail = True
3184++
3185++primop WriteArrayArrayOp_MutableByteArray "writeMutableByteArrayArray#" GenPrimOp
3186++ MutableArrayArray# s -> Int# -> MutableByteArray# s -> State# s -> State# s
3187++ with has_side_effects = True
3188++ can_fail = True
3189++
3190++primop WriteArrayArrayOp_ArrayArray "writeArrayArrayArray#" GenPrimOp
3191++ MutableArrayArray# s -> Int# -> ArrayArray# -> State# s -> State# s
3192++ with has_side_effects = True
3193++ can_fail = True
3194++
3195++primop WriteArrayArrayOp_MutableArrayArray "writeMutableArrayArrayArray#" GenPrimOp
3196++ MutableArrayArray# s -> Int# -> MutableArrayArray# s -> State# s -> State# s
3197++ with has_side_effects = True
3198++ can_fail = True
3199++
3200++primop CopyArrayArrayOp "copyArrayArray#" GenPrimOp
3201++ ArrayArray# -> Int# -> MutableArrayArray# s -> Int# -> Int# -> State# s -> State# s
3202++ {Copy a range of the ArrayArray\# to the specified region in the MutableArrayArray\#.
3203++ Both arrays must fully contain the specified ranges, but this is not checked.
3204++ The two arrays must not be the same array in different states, but this is not checked either.}
3205++ with
3206++ out_of_line = True
3207++ has_side_effects = True
3208++ can_fail = True
3209++
3210++primop CopyMutableArrayArrayOp "copyMutableArrayArray#" GenPrimOp
3211++ MutableArrayArray# s -> Int# -> MutableArrayArray# s -> Int# -> Int# -> State# s -> State# s
3212++ {Copy a range of the first MutableArrayArray# to the specified region in the second
3213++ MutableArrayArray#.
3214++ Both arrays must fully contain the specified ranges, but this is not checked.
3215++ The regions are allowed to overlap, although this is only possible when the same
3216++ array is provided as both the source and the destination.
3217++ }
3218++ with
3219++ out_of_line = True
3220++ has_side_effects = True
3221++ can_fail = True
3222++
3223++------------------------------------------------------------------------
3224++section "Addr#"
3225++------------------------------------------------------------------------
3226++
3227++primtype Addr#
3228++ { An arbitrary machine address assumed to point outside
3229++ the garbage-collected heap. }
3230++
3231++pseudoop "nullAddr#" Addr#
3232++ { The null address. }
3233++
3234++primop AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
3235++primop AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
3236++ {Result is meaningless if two {\tt Addr\#}s are so far apart that their
3237++ difference doesn't fit in an {\tt Int\#}.}
3238++primop AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
3239++ {Return the remainder when the {\tt Addr\#} arg, treated like an {\tt Int\#},
3240++ is divided by the {\tt Int\#} arg.}
3241++#if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
3242++primop Addr2IntOp "addr2Int#" GenPrimOp Addr# -> Int#
3243++ {Coerce directly from address to int.}
3244++ with code_size = 0
3245++ deprecated_msg = { This operation is strongly deprecated. }
3246++primop Int2AddrOp "int2Addr#" GenPrimOp Int# -> Addr#
3247++ {Coerce directly from int to address.}
3248++ with code_size = 0
3249++ deprecated_msg = { This operation is strongly deprecated. }
3250++#endif
3251++
3252++primop AddrGtOp "gtAddr#" Compare Addr# -> Addr# -> Int#
3253++primop AddrGeOp "geAddr#" Compare Addr# -> Addr# -> Int#
3254++primop AddrEqOp "eqAddr#" Compare Addr# -> Addr# -> Int#
3255++primop AddrNeOp "neAddr#" Compare Addr# -> Addr# -> Int#
3256++primop AddrLtOp "ltAddr#" Compare Addr# -> Addr# -> Int#
3257++primop AddrLeOp "leAddr#" Compare Addr# -> Addr# -> Int#
3258++
3259++primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
3260++ Addr# -> Int# -> Char#
3261++ {Reads 8-bit character; offset in bytes.}
3262++ with can_fail = True
3263++
3264++primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
3265++ Addr# -> Int# -> Char#
3266++ {Reads 31-bit character; offset in 4-byte words.}
3267++ with can_fail = True
3268++
3269++primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
3270++ Addr# -> Int# -> Int#
3271++ with can_fail = True
3272++
3273++primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
3274++ Addr# -> Int# -> Word#
3275++ with can_fail = True
3276++
3277++primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
3278++ Addr# -> Int# -> Addr#
3279++ with can_fail = True
3280++
3281++primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
3282++ Addr# -> Int# -> Float#
3283++ with can_fail = True
3284++
3285++primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
3286++ Addr# -> Int# -> Double#
3287++ with can_fail = True
3288++
3289++primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
3290++ Addr# -> Int# -> StablePtr# a
3291++ with can_fail = True
3292++
3293++primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
3294++ Addr# -> Int# -> Int#
3295++ with can_fail = True
3296++
3297++primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
3298++ Addr# -> Int# -> Int#
3299++ with can_fail = True
3300++
3301++primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
3302++ Addr# -> Int# -> INT32
3303++ with can_fail = True
3304++
3305++primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
3306++ Addr# -> Int# -> INT64
3307++ with can_fail = True
3308++
3309++primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
3310++ Addr# -> Int# -> Word#
3311++ with can_fail = True
3312++
3313++primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
3314++ Addr# -> Int# -> Word#
3315++ with can_fail = True
3316++
3317++primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
3318++ Addr# -> Int# -> WORD32
3319++ with can_fail = True
3320++
3321++primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
3322++ Addr# -> Int# -> WORD64
3323++ with can_fail = True
3324++
3325++primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
3326++ Addr# -> Int# -> State# s -> (# State# s, Char# #)
3327++ {Reads 8-bit character; offset in bytes.}
3328++ with has_side_effects = True
3329++ can_fail = True
3330++
3331++primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
3332++ Addr# -> Int# -> State# s -> (# State# s, Char# #)
3333++ {Reads 31-bit character; offset in 4-byte words.}
3334++ with has_side_effects = True
3335++ can_fail = True
3336++
3337++primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
3338++ Addr# -> Int# -> State# s -> (# State# s, Int# #)
3339++ with has_side_effects = True
3340++ can_fail = True
3341++
3342++primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
3343++ Addr# -> Int# -> State# s -> (# State# s, Word# #)
3344++ with has_side_effects = True
3345++ can_fail = True
3346++
3347++primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
3348++ Addr# -> Int# -> State# s -> (# State# s, Addr# #)
3349++ with has_side_effects = True
3350++ can_fail = True
3351++
3352++primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
3353++ Addr# -> Int# -> State# s -> (# State# s, Float# #)
3354++ with has_side_effects = True
3355++ can_fail = True
3356++
3357++primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
3358++ Addr# -> Int# -> State# s -> (# State# s, Double# #)
3359++ with has_side_effects = True
3360++ can_fail = True
3361++
3362++primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
3363++ Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
3364++ with has_side_effects = True
3365++ can_fail = True
3366++
3367++primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
3368++ Addr# -> Int# -> State# s -> (# State# s, Int# #)
3369++ with has_side_effects = True
3370++ can_fail = True
3371++
3372++primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
3373++ Addr# -> Int# -> State# s -> (# State# s, Int# #)
3374++ with has_side_effects = True
3375++ can_fail = True
3376++
3377++primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
3378++ Addr# -> Int# -> State# s -> (# State# s, INT32 #)
3379++ with has_side_effects = True
3380++ can_fail = True
3381++
3382++primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
3383++ Addr# -> Int# -> State# s -> (# State# s, INT64 #)
3384++ with has_side_effects = True
3385++ can_fail = True
3386++
3387++primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
3388++ Addr# -> Int# -> State# s -> (# State# s, Word# #)
3389++ with has_side_effects = True
3390++ can_fail = True
3391++
3392++primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
3393++ Addr# -> Int# -> State# s -> (# State# s, Word# #)
3394++ with has_side_effects = True
3395++ can_fail = True
3396++
3397++primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
3398++ Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
3399++ with has_side_effects = True
3400++ can_fail = True
3401++
3402++primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
3403++ Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
3404++ with has_side_effects = True
3405++ can_fail = True
3406++
3407++primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
3408++ Addr# -> Int# -> Char# -> State# s -> State# s
3409++ with has_side_effects = True
3410++ can_fail = True
3411++
3412++primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
3413++ Addr# -> Int# -> Char# -> State# s -> State# s
3414++ with has_side_effects = True
3415++ can_fail = True
3416++
3417++primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
3418++ Addr# -> Int# -> Int# -> State# s -> State# s
3419++ with has_side_effects = True
3420++ can_fail = True
3421++
3422++primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
3423++ Addr# -> Int# -> Word# -> State# s -> State# s
3424++ with has_side_effects = True
3425++ can_fail = True
3426++
3427++primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
3428++ Addr# -> Int# -> Addr# -> State# s -> State# s
3429++ with has_side_effects = True
3430++ can_fail = True
3431++
3432++primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
3433++ Addr# -> Int# -> Float# -> State# s -> State# s
3434++ with has_side_effects = True
3435++ can_fail = True
3436++
3437++primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
3438++ Addr# -> Int# -> Double# -> State# s -> State# s
3439++ with has_side_effects = True
3440++ can_fail = True
3441++
3442++primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
3443++ Addr# -> Int# -> StablePtr# a -> State# s -> State# s
3444++ with has_side_effects = True
3445++ can_fail = True
3446++
3447++primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
3448++ Addr# -> Int# -> Int# -> State# s -> State# s
3449++ with has_side_effects = True
3450++ can_fail = True
3451++
3452++primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
3453++ Addr# -> Int# -> Int# -> State# s -> State# s
3454++ with has_side_effects = True
3455++ can_fail = True
3456++
3457++primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
3458++ Addr# -> Int# -> INT32 -> State# s -> State# s
3459++ with has_side_effects = True
3460++ can_fail = True
3461++
3462++primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
3463++ Addr# -> Int# -> INT64 -> State# s -> State# s
3464++ with has_side_effects = True
3465++ can_fail = True
3466++
3467++primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
3468++ Addr# -> Int# -> Word# -> State# s -> State# s
3469++ with has_side_effects = True
3470++ can_fail = True
3471++
3472++primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
3473++ Addr# -> Int# -> Word# -> State# s -> State# s
3474++ with has_side_effects = True
3475++ can_fail = True
3476++
3477++primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
3478++ Addr# -> Int# -> WORD32 -> State# s -> State# s
3479++ with has_side_effects = True
3480++ can_fail = True
3481++
3482++primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
3483++ Addr# -> Int# -> WORD64 -> State# s -> State# s
3484++ with has_side_effects = True
3485++ can_fail = True
3486++
3487++------------------------------------------------------------------------
3488++section "Mutable variables"
3489++ {Operations on MutVar\#s.}
3490++------------------------------------------------------------------------
3491++
3492++primtype MutVar# s a
3493++ {A {\tt MutVar\#} behaves like a single-element mutable array.}
3494++
3495++primop NewMutVarOp "newMutVar#" GenPrimOp
3496++ a -> State# s -> (# State# s, MutVar# s a #)
3497++ {Create {\tt MutVar\#} with specified initial value in specified state thread.}
3498++ with
3499++ out_of_line = True
3500++ has_side_effects = True
3501++
3502++-- Note [Why MutVar# ops can't fail]
3503++-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3504++--
3505++-- We don't label readMutVar# or writeMutVar# as can_fail.
3506++-- This may seem a bit peculiar, because they surely *could*
3507++-- fail spectacularly if passed a pointer to unallocated memory.
3508++-- But MutVar#s are always correct by construction; we never
3509++-- test if a pointer is valid before using it with these operations.
3510++-- So we never have to worry about floating the pointer reference
3511++-- outside a validity test. At the moment, has_side_effects blocks
3512++-- up the relevant optimizations anyway, but we hope to draw finer
3513++-- distinctions soon, which should improve matters for readMutVar#
3514++-- at least.
3515++
3516++primop ReadMutVarOp "readMutVar#" GenPrimOp
3517++ MutVar# s a -> State# s -> (# State# s, a #)
3518++ {Read contents of {\tt MutVar\#}. Result is not yet evaluated.}
3519++ with
3520++ -- See Note [Why MutVar# ops can't fail]
3521++ has_side_effects = True
3522++
3523++primop WriteMutVarOp "writeMutVar#" GenPrimOp
3524++ MutVar# s a -> a -> State# s -> State# s
3525++ {Write contents of {\tt MutVar\#}.}
3526++ with
3527++ -- See Note [Why MutVar# ops can't fail]
3528++ has_side_effects = True
3529++ code_size = { primOpCodeSizeForeignCall } -- for the write barrier
3530++
3531++primop SameMutVarOp "sameMutVar#" GenPrimOp
3532++ MutVar# s a -> MutVar# s a -> Int#
3533++
3534++-- Note [Why not an unboxed tuple in atomicModifyMutVar2#?]
3535++-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3536++--
3537++-- Looking at the type of atomicModifyMutVar2#, one might wonder why
3538++-- it doesn't return an unboxed tuple. e.g.,
3539++--
3540++-- MutVar# s a -> (a -> (# a, b #)) -> State# s -> (# State# s, a, (# a, b #) #)
3541++--
3542++-- The reason is that atomicModifyMutVar2# relies on laziness for its atomicity.
3543++-- Given a MutVar# containing x, atomicModifyMutVar2# merely replaces
3544++-- its contents with a thunk of the form (fst (f x)). This can be done using an
3545++-- atomic compare-and-swap as it is merely replacing a pointer.
3546++
3547++primop AtomicModifyMutVar2Op "atomicModifyMutVar2#" GenPrimOp
3548++ MutVar# s a -> (a -> c) -> State# s -> (# State# s, a, c #)
3549++ { Modify the contents of a {\tt MutVar\#}, returning the previous
3550++ contents and the result of applying the given function to the
3551++ previous contents. Note that this isn't strictly
3552++ speaking the correct type for this function; it should really be
3553++ {\tt MutVar\# s a -> (a -> (a,b)) -> State\# s -> (\# State\# s, a, (a, b) \#)},
3554++ but we don't know about pairs here. }
3555++ with
3556++ out_of_line = True
3557++ has_side_effects = True
3558++ can_fail = True
3559++
3560++primop AtomicModifyMutVar_Op "atomicModifyMutVar_#" GenPrimOp
3561++ MutVar# s a -> (a -> a) -> State# s -> (# State# s, a, a #)
3562++ { Modify the contents of a {\tt MutVar\#}, returning the previous
3563++ contents and the result of applying the given function to the
3564++ previous contents. }
3565++ with
3566++ out_of_line = True
3567++ has_side_effects = True
3568++ can_fail = True
3569++
3570++primop CasMutVarOp "casMutVar#" GenPrimOp
3571++ MutVar# s a -> a -> a -> State# s -> (# State# s, Int#, a #)
3572++ with
3573++ out_of_line = True
3574++ has_side_effects = True
3575++
3576++------------------------------------------------------------------------
3577++section "Exceptions"
3578++------------------------------------------------------------------------
3579++
3580++-- Note [Strictness for mask/unmask/catch]
3581++-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3582++-- Consider this example, which comes from GHC.IO.Handle.Internals:
3583++-- wantReadableHandle3 f ma b st
3584++-- = case ... of
3585++-- DEFAULT -> case ma of MVar a -> ...
3586++-- 0# -> maskAsynchExceptions# (\st -> case ma of MVar a -> ...)
3587++-- The outer case just decides whether to mask exceptions, but we don't want
3588++-- thereby to hide the strictness in 'ma'! Hence the use of strictApply1Dmd.
3589++--
3590++-- For catch, catchSTM, and catchRetry, we must be extra careful; see
3591++-- Note [Exceptions and strictness] in Demand
3592++
3593++primop CatchOp "catch#" GenPrimOp
3594++ (State# RealWorld -> (# State# RealWorld, a #) )
3595++ -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
3596++ -> State# RealWorld
3597++ -> (# State# RealWorld, a #)
3598++ with
3599++ strictness = { \ _arity -> mkClosedStrictSig [ lazyApply1Dmd
3600++ , lazyApply2Dmd
3601++ , topDmd] topRes }
3602++ -- See Note [Strictness for mask/unmask/catch]
3603++ out_of_line = True
3604++ has_side_effects = True
3605++
3606++primop RaiseOp "raise#" GenPrimOp
3607++ b -> o
3608++ -- NB: the type variable "o" is "a", but with OpenKind
3609++ with
3610++ strictness = { \ _arity -> mkClosedStrictSig [topDmd] exnRes }
3611++ -- NB: result is ThrowsExn
3612++ out_of_line = True
3613++ has_side_effects = True
3614++ -- raise# certainly throws a Haskell exception and hence has_side_effects
3615++ -- It doesn't actually make much difference because the fact that it
3616++ -- returns bottom independently ensures that we are careful not to discard
3617++ -- it. But still, it's better to say the Right Thing.
3618++
3619++-- raiseIO# needs to be a primop, because exceptions in the IO monad
3620++-- must be *precise* - we don't want the strictness analyser turning
3621++-- one kind of bottom into another, as it is allowed to do in pure code.
3622++--
3623++-- But we *do* want to know that it returns bottom after
3624++-- being applied to two arguments, so that this function is strict in y
3625++-- f x y | x>0 = raiseIO blah
3626++-- | y>0 = return 1
3627++-- | otherwise = return 2
3628++--
3629++-- TODO Check that the above notes on @f@ are valid. The function successfully
3630++-- produces an IO exception when compiled without optimization. If we analyze
3631++-- it as strict in @y@, won't we change that behavior under optimization?
3632++-- I thought the rule was that it was okay to replace one valid imprecise
3633++-- exception with another, but not to replace a precise exception with
3634++-- an imprecise one (dfeuer, 2017-03-05).
3635++
3636++primop RaiseIOOp "raiseIO#" GenPrimOp
3637++ a -> State# RealWorld -> (# State# RealWorld, b #)
3638++ with
3639++ strictness = { \ _arity -> mkClosedStrictSig [topDmd, topDmd] exnRes }
3640++ out_of_line = True
3641++ has_side_effects = True
3642++
3643++primop MaskAsyncExceptionsOp "maskAsyncExceptions#" GenPrimOp
3644++ (State# RealWorld -> (# State# RealWorld, a #))
3645++ -> (State# RealWorld -> (# State# RealWorld, a #))
3646++ with
3647++ strictness = { \ _arity -> mkClosedStrictSig [strictApply1Dmd,topDmd] topRes }
3648++ -- See Note [Strictness for mask/unmask/catch]
3649++ out_of_line = True
3650++ has_side_effects = True
3651++
3652++primop MaskUninterruptibleOp "maskUninterruptible#" GenPrimOp
3653++ (State# RealWorld -> (# State# RealWorld, a #))
3654++ -> (State# RealWorld -> (# State# RealWorld, a #))
3655++ with
3656++ strictness = { \ _arity -> mkClosedStrictSig [strictApply1Dmd,topDmd] topRes }
3657++ out_of_line = True
3658++ has_side_effects = True
3659++
3660++primop UnmaskAsyncExceptionsOp "unmaskAsyncExceptions#" GenPrimOp
3661++ (State# RealWorld -> (# State# RealWorld, a #))
3662++ -> (State# RealWorld -> (# State# RealWorld, a #))
3663++ with
3664++ strictness = { \ _arity -> mkClosedStrictSig [strictApply1Dmd,topDmd] topRes }
3665++ -- See Note [Strictness for mask/unmask/catch]
3666++ out_of_line = True
3667++ has_side_effects = True
3668++
3669++primop MaskStatus "getMaskingState#" GenPrimOp
3670++ State# RealWorld -> (# State# RealWorld, Int# #)
3671++ with
3672++ out_of_line = True
3673++ has_side_effects = True
3674++
3675++------------------------------------------------------------------------
3676++section "STM-accessible Mutable Variables"
3677++------------------------------------------------------------------------
3678++
3679++primtype TVar# s a
3680++
3681++primop AtomicallyOp "atomically#" GenPrimOp
3682++ (State# RealWorld -> (# State# RealWorld, a #) )
3683++ -> State# RealWorld -> (# State# RealWorld, a #)
3684++ with
3685++ strictness = { \ _arity -> mkClosedStrictSig [strictApply1Dmd,topDmd] topRes }
3686++ -- See Note [Strictness for mask/unmask/catch]
3687++ out_of_line = True
3688++ has_side_effects = True
3689++
3690++-- NB: retry#'s strictness information specifies it to throw an exception
3691++-- This lets the compiler perform some extra simplifications, since retry#
3692++-- will technically never return.
3693++--
3694++-- This allows the simplifier to replace things like:
3695++-- case retry# s1
3696++-- (# s2, a #) -> e
3697++-- with:
3698++-- retry# s1
3699++-- where 'e' would be unreachable anyway. See Trac #8091.
3700++--
3701++-- Note that it *does not* return botRes as the "exception" that is thrown may be
3702++-- "caught" by catchRetry#. This mistake caused #14171.
3703++primop RetryOp "retry#" GenPrimOp
3704++ State# RealWorld -> (# State# RealWorld, a #)
3705++ with
3706++ strictness = { \ _arity -> mkClosedStrictSig [topDmd] exnRes }
3707++ out_of_line = True
3708++ has_side_effects = True
3709++
3710++primop CatchRetryOp "catchRetry#" GenPrimOp
3711++ (State# RealWorld -> (# State# RealWorld, a #) )
3712++ -> (State# RealWorld -> (# State# RealWorld, a #) )
3713++ -> (State# RealWorld -> (# State# RealWorld, a #) )
3714++ with
3715++ strictness = { \ _arity -> mkClosedStrictSig [ lazyApply1Dmd
3716++ , lazyApply1Dmd
3717++ , topDmd ] topRes }
3718++ -- See Note [Strictness for mask/unmask/catch]
3719++ out_of_line = True
3720++ has_side_effects = True
3721++
3722++primop CatchSTMOp "catchSTM#" GenPrimOp
3723++ (State# RealWorld -> (# State# RealWorld, a #) )
3724++ -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
3725++ -> (State# RealWorld -> (# State# RealWorld, a #) )
3726++ with
3727++ strictness = { \ _arity -> mkClosedStrictSig [ lazyApply1Dmd
3728++ , lazyApply2Dmd
3729++ , topDmd ] topRes }
3730++ -- See Note [Strictness for mask/unmask/catch]
3731++ out_of_line = True
3732++ has_side_effects = True
3733++
3734++primop NewTVarOp "newTVar#" GenPrimOp
3735++ a
3736++ -> State# s -> (# State# s, TVar# s a #)
3737++ {Create a new {\tt TVar\#} holding a specified initial value.}
3738++ with
3739++ out_of_line = True
3740++ has_side_effects = True
3741++
3742++primop ReadTVarOp "readTVar#" GenPrimOp
3743++ TVar# s a
3744++ -> State# s -> (# State# s, a #)
3745++ {Read contents of {\tt TVar\#}. Result is not yet evaluated.}
3746++ with
3747++ out_of_line = True
3748++ has_side_effects = True
3749++
3750++primop ReadTVarIOOp "readTVarIO#" GenPrimOp
3751++ TVar# s a
3752++ -> State# s -> (# State# s, a #)
3753++ {Read contents of {\tt TVar\#} outside an STM transaction}
3754++ with
3755++ out_of_line = True
3756++ has_side_effects = True
3757++
3758++primop WriteTVarOp "writeTVar#" GenPrimOp
3759++ TVar# s a
3760++ -> a
3761++ -> State# s -> State# s
3762++ {Write contents of {\tt TVar\#}.}
3763++ with
3764++ out_of_line = True
3765++ has_side_effects = True
3766++
3767++primop SameTVarOp "sameTVar#" GenPrimOp
3768++ TVar# s a -> TVar# s a -> Int#
3769++
3770++
3771++------------------------------------------------------------------------
3772++section "Synchronized Mutable Variables"
3773++ {Operations on {\tt MVar\#}s. }
3774++------------------------------------------------------------------------
3775++
3776++primtype MVar# s a
3777++ { A shared mutable variable ({\it not} the same as a {\tt MutVar\#}!).
3778++ (Note: in a non-concurrent implementation, {\tt (MVar\# a)} can be
3779++ represented by {\tt (MutVar\# (Maybe a))}.) }
3780++
3781++primop NewMVarOp "newMVar#" GenPrimOp
3782++ State# s -> (# State# s, MVar# s a #)
3783++ {Create new {\tt MVar\#}; initially empty.}
3784++ with
3785++ out_of_line = True
3786++ has_side_effects = True
3787++
3788++primop TakeMVarOp "takeMVar#" GenPrimOp
3789++ MVar# s a -> State# s -> (# State# s, a #)
3790++ {If {\tt MVar\#} is empty, block until it becomes full.
3791++ Then remove and return its contents, and set it empty.}
3792++ with
3793++ out_of_line = True
3794++ has_side_effects = True
3795++
3796++primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
3797++ MVar# s a -> State# s -> (# State# s, Int#, a #)
3798++ {If {\tt MVar\#} is empty, immediately return with integer 0 and value undefined.
3799++ Otherwise, return with integer 1 and contents of {\tt MVar\#}, and set {\tt MVar\#} empty.}
3800++ with
3801++ out_of_line = True
3802++ has_side_effects = True
3803++
3804++primop PutMVarOp "putMVar#" GenPrimOp
3805++ MVar# s a -> a -> State# s -> State# s
3806++ {If {\tt MVar\#} is full, block until it becomes empty.
3807++ Then store value arg as its new contents.}
3808++ with
3809++ out_of_line = True
3810++ has_side_effects = True
3811++
3812++primop TryPutMVarOp "tryPutMVar#" GenPrimOp
3813++ MVar# s a -> a -> State# s -> (# State# s, Int# #)
3814++ {If {\tt MVar\#} is full, immediately return with integer 0.
3815++ Otherwise, store value arg as {\tt MVar\#}'s new contents, and return with integer 1.}
3816++ with
3817++ out_of_line = True
3818++ has_side_effects = True
3819++
3820++primop ReadMVarOp "readMVar#" GenPrimOp
3821++ MVar# s a -> State# s -> (# State# s, a #)
3822++ {If {\tt MVar\#} is empty, block until it becomes full.
3823++ Then read its contents without modifying the MVar, without possibility
3824++ of intervention from other threads.}
3825++ with
3826++ out_of_line = True
3827++ has_side_effects = True
3828++
3829++primop TryReadMVarOp "tryReadMVar#" GenPrimOp
3830++ MVar# s a -> State# s -> (# State# s, Int#, a #)
3831++ {If {\tt MVar\#} is empty, immediately return with integer 0 and value undefined.
3832++ Otherwise, return with integer 1 and contents of {\tt MVar\#}.}
3833++ with
3834++ out_of_line = True
3835++ has_side_effects = True
3836++
3837++primop SameMVarOp "sameMVar#" GenPrimOp
3838++ MVar# s a -> MVar# s a -> Int#
3839++
3840++primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
3841++ MVar# s a -> State# s -> (# State# s, Int# #)
3842++ {Return 1 if {\tt MVar\#} is empty; 0 otherwise.}
3843++ with
3844++ out_of_line = True
3845++ has_side_effects = True
3846++
3847++------------------------------------------------------------------------
3848++section "Delay/wait operations"
3849++------------------------------------------------------------------------
3850++
3851++primop DelayOp "delay#" GenPrimOp
3852++ Int# -> State# s -> State# s
3853++ {Sleep specified number of microseconds.}
3854++ with
3855++ has_side_effects = True
3856++ out_of_line = True
3857++
3858++primop WaitReadOp "waitRead#" GenPrimOp
3859++ Int# -> State# s -> State# s
3860++ {Block until input is available on specified file descriptor.}
3861++ with
3862++ has_side_effects = True
3863++ out_of_line = True
3864++
3865++primop WaitWriteOp "waitWrite#" GenPrimOp
3866++ Int# -> State# s -> State# s
3867++ {Block until output is possible on specified file descriptor.}
3868++ with
3869++ has_side_effects = True
3870++ out_of_line = True
3871++
3872++#if defined(mingw32_TARGET_OS)
3873++primop AsyncReadOp "asyncRead#" GenPrimOp
3874++ Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
3875++ {Asynchronously read bytes from specified file descriptor.}
3876++ with
3877++ has_side_effects = True
3878++ out_of_line = True
3879++
3880++primop AsyncWriteOp "asyncWrite#" GenPrimOp
3881++ Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
3882++ {Asynchronously write bytes from specified file descriptor.}
3883++ with
3884++ has_side_effects = True
3885++ out_of_line = True
3886++
3887++primop AsyncDoProcOp "asyncDoProc#" GenPrimOp
3888++ Addr# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
3889++ {Asynchronously perform procedure (first arg), passing it 2nd arg.}
3890++ with
3891++ has_side_effects = True
3892++ out_of_line = True
3893++
3894++#endif
3895++
3896++------------------------------------------------------------------------
3897++section "Concurrency primitives"
3898++------------------------------------------------------------------------
3899++
3900++primtype State# s
3901++ { {\tt State\#} is the primitive, unlifted type of states. It has
3902++ one type parameter, thus {\tt State\# RealWorld}, or {\tt State\# s},
3903++ where s is a type variable. The only purpose of the type parameter
3904++ is to keep different state threads separate. It is represented by
3905++ nothing at all. }
3906++
3907++primtype RealWorld
3908++ { {\tt RealWorld} is deeply magical. It is {\it primitive}, but it is not
3909++ {\it unlifted} (hence {\tt ptrArg}). We never manipulate values of type
3910++ {\tt RealWorld}; it's only used in the type system, to parameterise {\tt State\#}. }
3911++
3912++primtype ThreadId#
3913++ {(In a non-concurrent implementation, this can be a singleton
3914++ type, whose (unique) value is returned by {\tt myThreadId\#}. The
3915++ other operations can be omitted.)}
3916++
3917++primop ForkOp "fork#" GenPrimOp
3918++ a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
3919++ with
3920++ has_side_effects = True
3921++ out_of_line = True
3922++
3923++primop ForkOnOp "forkOn#" GenPrimOp
3924++ Int# -> a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
3925++ with
3926++ has_side_effects = True
3927++ out_of_line = True
3928++
3929++primop KillThreadOp "killThread#" GenPrimOp
3930++ ThreadId# -> a -> State# RealWorld -> State# RealWorld
3931++ with
3932++ has_side_effects = True
3933++ out_of_line = True
3934++
3935++primop YieldOp "yield#" GenPrimOp
3936++ State# RealWorld -> State# RealWorld
3937++ with
3938++ has_side_effects = True
3939++ out_of_line = True
3940++
3941++primop MyThreadIdOp "myThreadId#" GenPrimOp
3942++ State# RealWorld -> (# State# RealWorld, ThreadId# #)
3943++ with
3944++ has_side_effects = True
3945++
3946++primop LabelThreadOp "labelThread#" GenPrimOp
3947++ ThreadId# -> Addr# -> State# RealWorld -> State# RealWorld
3948++ with
3949++ has_side_effects = True
3950++ out_of_line = True
3951++
3952++primop IsCurrentThreadBoundOp "isCurrentThreadBound#" GenPrimOp
3953++ State# RealWorld -> (# State# RealWorld, Int# #)
3954++ with
3955++ out_of_line = True
3956++ has_side_effects = True
3957++
3958++primop NoDuplicateOp "noDuplicate#" GenPrimOp
3959++ State# s -> State# s
3960++ with
3961++ out_of_line = True
3962++ has_side_effects = True
3963++
3964++primop ThreadStatusOp "threadStatus#" GenPrimOp
3965++ ThreadId# -> State# RealWorld -> (# State# RealWorld, Int#, Int#, Int# #)
3966++ with
3967++ out_of_line = True
3968++ has_side_effects = True
3969++
3970++------------------------------------------------------------------------
3971++section "Weak pointers"
3972++------------------------------------------------------------------------
3973++
3974++primtype Weak# b
3975++
3976++-- note that tyvar "o" denotes openAlphaTyVar
3977++
3978++primop MkWeakOp "mkWeak#" GenPrimOp
3979++ o -> b -> (State# RealWorld -> (# State# RealWorld, c #))
3980++ -> State# RealWorld -> (# State# RealWorld, Weak# b #)
3981++ { {\tt mkWeak# k v finalizer s} creates a weak reference to value {\tt k},
3982++ with an associated reference to some value {\tt v}. If {\tt k} is still
3983++ alive then {\tt v} can be retrieved using {\tt deRefWeak#}. Note that
3984++ the type of {\tt k} must be represented by a pointer (i.e. of kind {\tt
3985++ TYPE 'LiftedRep} or {\tt TYPE 'UnliftedRep}). }
3986++ with
3987++ has_side_effects = True
3988++ out_of_line = True
3989++
3990++primop MkWeakNoFinalizerOp "mkWeakNoFinalizer#" GenPrimOp
3991++ o -> b -> State# RealWorld -> (# State# RealWorld, Weak# b #)
3992++ with
3993++ has_side_effects = True
3994++ out_of_line = True
3995++
3996++primop AddCFinalizerToWeakOp "addCFinalizerToWeak#" GenPrimOp
3997++ Addr# -> Addr# -> Int# -> Addr# -> Weak# b
3998++ -> State# RealWorld -> (# State# RealWorld, Int# #)
3999++ { {\tt addCFinalizerToWeak# fptr ptr flag eptr w} attaches a C
4000++ function pointer {\tt fptr} to a weak pointer {\tt w} as a finalizer. If
4001++ {\tt flag} is zero, {\tt fptr} will be called with one argument,
4002++ {\tt ptr}. Otherwise, it will be called with two arguments,
4003++ {\tt eptr} and {\tt ptr}. {\tt addCFinalizerToWeak#} returns
4004++ 1 on success, or 0 if {\tt w} is already dead. }
4005++ with
4006++ has_side_effects = True
4007++ out_of_line = True
4008++
4009++primop DeRefWeakOp "deRefWeak#" GenPrimOp
4010++ Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
4011++ with
4012++ has_side_effects = True
4013++ out_of_line = True
4014++
4015++primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
4016++ Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
4017++ (State# RealWorld -> (# State# RealWorld, b #) ) #)
4018++ { Finalize a weak pointer. The return value is an unboxed tuple
4019++ containing the new state of the world and an "unboxed Maybe",
4020++ represented by an {\tt Int#} and a (possibly invalid) finalization
4021++ action. An {\tt Int#} of {\tt 1} indicates that the finalizer is valid. The
4022++ return value {\tt b} from the finalizer should be ignored. }
4023++ with
4024++ has_side_effects = True
4025++ out_of_line = True
4026++
4027++primop TouchOp "touch#" GenPrimOp
4028++ o -> State# RealWorld -> State# RealWorld
4029++ with
4030++ code_size = { 0 }
4031++ has_side_effects = True
4032++
4033++------------------------------------------------------------------------
4034++section "Stable pointers and names"
4035++------------------------------------------------------------------------
4036++
4037++primtype StablePtr# a
4038++
4039++primtype StableName# a
4040++
4041++primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
4042++ a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
4043++ with
4044++ has_side_effects = True
4045++ out_of_line = True
4046++
4047++primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
4048++ StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
4049++ with
4050++ has_side_effects = True
4051++ out_of_line = True
4052++
4053++primop EqStablePtrOp "eqStablePtr#" GenPrimOp
4054++ StablePtr# a -> StablePtr# a -> Int#
4055++ with
4056++ has_side_effects = True
4057++
4058++primop MakeStableNameOp "makeStableName#" GenPrimOp
4059++ a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
4060++ with
4061++ has_side_effects = True
4062++ out_of_line = True
4063++
4064++primop EqStableNameOp "eqStableName#" GenPrimOp
4065++ StableName# a -> StableName# b -> Int#
4066++
4067++primop StableNameToIntOp "stableNameToInt#" GenPrimOp
4068++ StableName# a -> Int#
4069++
4070++------------------------------------------------------------------------
4071++section "Compact normal form"
4072++------------------------------------------------------------------------
4073++
4074++primtype Compact#
4075++
4076++primop CompactNewOp "compactNew#" GenPrimOp
4077++ Word# -> State# RealWorld -> (# State# RealWorld, Compact# #)
4078++ { Create a new Compact with the given size (in bytes, not words).
4079++ The size is rounded up to a multiple of the allocator block size,
4080++ and capped to one mega block. }
4081++ with
4082++ has_side_effects = True
4083++ out_of_line = True
4084++
4085++primop CompactResizeOp "compactResize#" GenPrimOp
4086++ Compact# -> Word# -> State# RealWorld ->
4087++ State# RealWorld
4088++ { Set the new allocation size of the compact. This value (in bytes)
4089++ determines the size of each block in the compact chain. }
4090++ with
4091++ has_side_effects = True
4092++ out_of_line = True
4093++
4094++primop CompactContainsOp "compactContains#" GenPrimOp
4095++ Compact# -> a -> State# RealWorld -> (# State# RealWorld, Int# #)
4096++ { Returns 1\# if the object is contained in the compact, 0\# otherwise. }
4097++ with
4098++ out_of_line = True
4099++
4100++primop CompactContainsAnyOp "compactContainsAny#" GenPrimOp
4101++ a -> State# RealWorld -> (# State# RealWorld, Int# #)
4102++ { Returns 1\# if the object is in any compact at all, 0\# otherwise. }
4103++ with
4104++ out_of_line = True
4105++
4106++primop CompactGetFirstBlockOp "compactGetFirstBlock#" GenPrimOp
4107++ Compact# -> State# RealWorld -> (# State# RealWorld, Addr#, Word# #)
4108++ { Returns the address and the size (in bytes) of the first block of
4109++ a compact. }
4110++ with
4111++ out_of_line = True
4112++
4113++primop CompactGetNextBlockOp "compactGetNextBlock#" GenPrimOp
4114++ Compact# -> Addr# -> State# RealWorld -> (# State# RealWorld, Addr#, Word# #)
4115++ { Given a compact and the address of one its blocks, returns the
4116++ next block and its size, or #nullAddr if the argument was the
4117++ last block in the compact. }
4118++ with
4119++ out_of_line = True
4120++
4121++primop CompactAllocateBlockOp "compactAllocateBlock#" GenPrimOp
4122++ Word# -> Addr# -> State# RealWorld -> (# State# RealWorld, Addr# #)
4123++ { Attempt to allocate a compact block with the given size (in
4124++ bytes, given by the first argument). The {\texttt Addr\#} is a pointer to
4125++ previous block of the compact or {\texttt nullAddr\#} to create a new compact.
4126++
4127++ The resulting block is not known to the GC until
4128++ {\texttt compactFixupPointers\#} is called on it, and care must be taken
4129++ so that the address does not escape or memory will be leaked.
4130++ }
4131++ with
4132++ has_side_effects = True
4133++ out_of_line = True
4134++
4135++primop CompactFixupPointersOp "compactFixupPointers#" GenPrimOp
4136++ Addr# -> Addr# -> State# RealWorld -> (# State# RealWorld, Compact#, Addr# #)
4137++ { Given the pointer to the first block of a compact, and the
4138++ address of the root object in the old address space, fix up
4139++ the internal pointers inside the compact to account for
4140++ a different position in memory than when it was serialized.
4141++ This method must be called exactly once after importing
4142++ a serialized compact, and returns the new compact and
4143++ the new adjusted root address. }
4144++ with
4145++ has_side_effects = True
4146++ out_of_line = True
4147++
4148++primop CompactAdd "compactAdd#" GenPrimOp
4149++ Compact# -> a -> State# RealWorld -> (# State# RealWorld, a #)
4150++ { Recursively add a closure and its transitive closure to a
4151++ {\texttt Compact\#}, evaluating any unevaluated components at the
4152++ same time. Note: {\texttt compactAdd\#} is not thread-safe, so
4153++ only one thread may call {\texttt compactAdd\#} with a particular
4154++ {\texttt Compact#} at any given time. The primop does not
4155++ enforce any mutual exclusion; the caller is expected to
4156++ arrange this. }
4157++ with
4158++ has_side_effects = True
4159++ out_of_line = True
4160++
4161++primop CompactAddWithSharing "compactAddWithSharing#" GenPrimOp
4162++ Compact# -> a -> State# RealWorld -> (# State# RealWorld, a #)
4163++ { Like {\texttt compactAdd\#}, but retains sharing and cycles
4164++ during compaction. }
4165++ with
4166++ has_side_effects = True
4167++ out_of_line = True
4168++
4169++primop CompactSize "compactSize#" GenPrimOp
4170++ Compact# -> State# RealWorld -> (# State# RealWorld, Word# #)
4171++ { Return the size (in bytes) of the total amount of data in the Compact# }
4172++ with
4173++ has_side_effects = True
4174++ out_of_line = True
4175++
4176++------------------------------------------------------------------------
4177++section "Unsafe pointer equality"
4178++-- (#1 Bad Guy: Alastair Reid :)
4179++------------------------------------------------------------------------
4180++
4181++primop ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
4182++ a -> a -> Int#
4183++ { Returns {\texttt 1\#} if the given pointers are equal and {\texttt 0\#} otherwise. }
4184++ with
4185++ can_fail = True -- See Note [reallyUnsafePtrEquality#]
4186++
4187++
4188++-- Note [reallyUnsafePtrEquality#]
4189++-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4190++--
4191++-- reallyUnsafePtrEquality# can't actually fail, per se, but we mark it can_fail
4192++-- anyway. Until 5a9a1738023a, GHC considered primops okay for speculation only
4193++-- when their arguments were known to be forced. This was unnecessarily
4194++-- conservative, but it prevented reallyUnsafePtrEquality# from floating out of
4195++-- places where its arguments were known to be forced. Unfortunately, GHC could
4196++-- sometimes lose track of whether those arguments were forced, leading to let/app
4197++-- invariant failures (see Trac 13027 and the discussion in Trac 11444). Now that
4198++-- ok_for_speculation skips over lifted arguments, we need to explicitly prevent
4199++-- reallyUnsafePtrEquality# from floating out. Imagine if we had
4200++--
4201++-- \x y . case x of x'
4202++-- DEFAULT ->
4203++-- case y of y'
4204++-- DEFAULT ->
4205++-- let eq = reallyUnsafePtrEquality# x' y'
4206++-- in ...
4207++--
4208++-- If the let floats out, we'll get
4209++--
4210++-- \x y . let eq = reallyUnsafePtrEquality# x y
4211++-- in case x of ...
4212++--
4213++-- The trouble is that pointer equality between thunks is very different
4214++-- from pointer equality between the values those thunks reduce to, and the latter
4215++-- is typically much more precise.
4216++
4217++------------------------------------------------------------------------
4218++section "Parallelism"
4219++------------------------------------------------------------------------
4220++
4221++primop ParOp "par#" GenPrimOp
4222++ a -> Int#
4223++ with
4224++ -- Note that Par is lazy to avoid that the sparked thing
4225++ -- gets evaluated strictly, which it should *not* be
4226++ has_side_effects = True
4227++ code_size = { primOpCodeSizeForeignCall }
4228++ deprecated_msg = { Use 'spark#' instead }
4229++
4230++primop SparkOp "spark#" GenPrimOp
4231++ a -> State# s -> (# State# s, a #)
4232++ with has_side_effects = True
4233++ code_size = { primOpCodeSizeForeignCall }
4234++
4235++primop SeqOp "seq#" GenPrimOp
4236++ a -> State# s -> (# State# s, a #)
4237++ -- See Note [seq# magic] in PrelRules
4238++
4239++primop GetSparkOp "getSpark#" GenPrimOp
4240++ State# s -> (# State# s, Int#, a #)
4241++ with
4242++ has_side_effects = True
4243++ out_of_line = True
4244++
4245++primop NumSparks "numSparks#" GenPrimOp
4246++ State# s -> (# State# s, Int# #)
4247++ { Returns the number of sparks in the local spark pool. }
4248++ with
4249++ has_side_effects = True
4250++ out_of_line = True
4251++
4252++------------------------------------------------------------------------
4253++section "Tag to enum stuff"
4254++ {Convert back and forth between values of enumerated types
4255++ and small integers.}
4256++------------------------------------------------------------------------
4257++
4258++primop DataToTagOp "dataToTag#" GenPrimOp
4259++ a -> Int# -- Zero-indexed; the first constructor has tag zero
4260++ with
4261++ strictness = { \ _arity -> mkClosedStrictSig [evalDmd] topRes }
4262++ -- See Note [dataToTag# magic] in PrelRules
4263++
4264++primop TagToEnumOp "tagToEnum#" GenPrimOp
4265++ Int# -> a
4266++
4267++------------------------------------------------------------------------
4268++section "Bytecode operations"
4269++ {Support for manipulating bytecode objects used by the interpreter and
4270++ linker.
4271++
4272++ Bytecode objects are heap objects which represent top-level bindings and
4273++ contain a list of instructions and data needed by these instructions.}
4274++------------------------------------------------------------------------
4275++
4276++primtype BCO#
4277++ { Primitive bytecode type. }
4278++
4279++primop AddrToAnyOp "addrToAny#" GenPrimOp
4280++ Addr# -> (# a #)
4281++ { Convert an {\tt Addr\#} to a followable Any type. }
4282++ with
4283++ code_size = 0
4284++
4285++primop AnyToAddrOp "anyToAddr#" GenPrimOp
4286++ a -> State# RealWorld -> (# State# RealWorld, Addr# #)
4287++ { Retrieve the address of any Haskell value. This is
4288++ essentially an {\texttt unsafeCoerce\#}, but if implemented as such
4289++ the core lint pass complains and fails to compile.
4290++ As a primop, it is opaque to core/stg, and only appears
4291++ in cmm (where the copy propagation pass will get rid of it).
4292++ Note that "a" must be a value, not a thunk! It's too late
4293++ for strictness analysis to enforce this, so you're on your
4294++ own to guarantee this. Also note that {\texttt Addr\#} is not a GC
4295++ pointer - up to you to guarantee that it does not become
4296++ a dangling pointer immediately after you get it.}
4297++ with
4298++ code_size = 0
4299++
4300++primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
4301++ BCO# -> (# a #)
4302++ { Wrap a BCO in a {\tt AP_UPD} thunk which will be updated with the value of
4303++ the BCO when evaluated. }
4304++ with
4305++ out_of_line = True
4306++
4307++primop NewBCOOp "newBCO#" GenPrimOp
4308++ ByteArray# -> ByteArray# -> Array# a -> Int# -> ByteArray# -> State# s -> (# State# s, BCO# #)
4309++ { {\tt newBCO\# instrs lits ptrs arity bitmap} creates a new bytecode object. The
4310++ resulting object encodes a function of the given arity with the instructions
4311++ encoded in {\tt instrs}, and a static reference table usage bitmap given by
4312++ {\tt bitmap}. }
4313++ with
4314++ has_side_effects = True
4315++ out_of_line = True
4316++
4317++primop UnpackClosureOp "unpackClosure#" GenPrimOp
4318++ a -> (# Addr#, ByteArray#, Array# b #)
4319++ { {\tt unpackClosure\# closure} copies the closure and pointers in the
4320++ payload of the given closure into two new arrays, and returns a pointer to
4321++ the first word of the closure's info table, a non-pointer array for the raw
4322++ bytes of the closure, and a pointer array for the pointers in the payload. }
4323++ with
4324++ out_of_line = True
4325++
4326++primop GetApStackValOp "getApStackVal#" GenPrimOp
4327++ a -> Int# -> (# Int#, b #)
4328++ with
4329++ out_of_line = True
4330++
4331++------------------------------------------------------------------------
4332++section "Misc"
4333++ {These aren't nearly as wired in as Etc...}
4334++------------------------------------------------------------------------
4335++
4336++primop GetCCSOfOp "getCCSOf#" GenPrimOp
4337++ a -> State# s -> (# State# s, Addr# #)
4338++
4339++primop GetCurrentCCSOp "getCurrentCCS#" GenPrimOp
4340++ a -> State# s -> (# State# s, Addr# #)
4341++ { Returns the current {\tt CostCentreStack} (value is {\tt NULL} if
4342++ not profiling). Takes a dummy argument which can be used to
4343++ avoid the call to {\tt getCurrentCCS\#} being floated out by the
4344++ simplifier, which would result in an uninformative stack
4345++ ("CAF"). }
4346++
4347++primop ClearCCSOp "clearCCS#" GenPrimOp
4348++ (State# s -> (# State# s, a #)) -> State# s -> (# State# s, a #)
4349++ { Run the supplied IO action with an empty CCS. For example, this
4350++ is used by the interpreter to run an interpreted computation
4351++ without the call stack showing that it was invoked from GHC. }
4352++ with
4353++ out_of_line = True
4354++
4355++------------------------------------------------------------------------
4356++section "Etc"
4357++ {Miscellaneous built-ins}
4358++------------------------------------------------------------------------
4359++
4360++primtype Proxy# a
4361++ { The type constructor {\tt Proxy#} is used to bear witness to some
4362++ type variable. It's used when you want to pass around proxy values
4363++ for doing things like modelling type applications. A {\tt Proxy#}
4364++ is not only unboxed, it also has a polymorphic kind, and has no
4365++ runtime representation, being totally free. }
4366++
4367++pseudoop "proxy#"
4368++ Proxy# a
4369++ { Witness for an unboxed {\tt Proxy#} value, which has no runtime
4370++ representation. }
4371++
4372++pseudoop "seq"
4373++ a -> b -> b
4374++ { The value of {\tt seq a b} is bottom if {\tt a} is bottom, and
4375++ otherwise equal to {\tt b}. In other words, it evaluates the first
4376++ argument {\tt a} to weak head normal form (WHNF). {\tt seq} is usually
4377++ introduced to improve performance by avoiding unneeded laziness.
4378++
4379++ A note on evaluation order: the expression {\tt seq a b} does
4380++ {\it not} guarantee that {\tt a} will be evaluated before {\tt b}.
4381++ The only guarantee given by {\tt seq} is that the both {\tt a}
4382++ and {\tt b} will be evaluated before {\tt seq} returns a value.
4383++ In particular, this means that {\tt b} may be evaluated before
4384++ {\tt a}. If you need to guarantee a specific order of evaluation,
4385++ you must use the function {\tt pseq} from the "parallel" package. }
4386++ with fixity = infixr 0
4387++ -- This fixity is only the one picked up by Haddock. If you
4388++ -- change this, do update 'ghcPrimIface' in 'LoadIface.hs'.
4389++
4390++pseudoop "unsafeCoerce#"
4391++ a -> b
4392++ { The function {\tt unsafeCoerce\#} allows you to side-step the typechecker entirely. That
4393++ is, it allows you to coerce any type into any other type. If you use this function,
4394++ you had better get it right, otherwise segmentation faults await. It is generally
4395++ used when you want to write a program that you know is well-typed, but where Haskell's
4396++ type system is not expressive enough to prove that it is well typed.
4397++
4398++ The following uses of {\tt unsafeCoerce\#} are supposed to work (i.e. not lead to
4399++ spurious compile-time or run-time crashes):
4400++
4401++ * Casting any lifted type to {\tt Any}
4402++
4403++ * Casting {\tt Any} back to the real type
4404++
4405++ * Casting an unboxed type to another unboxed type of the same size.
4406++ (Casting between floating-point and integral types does not work.
4407++ See the {\tt GHC.Float} module for functions to do work.)
4408++
4409++ * Casting between two types that have the same runtime representation. One case is when
4410++ the two types differ only in "phantom" type parameters, for example
4411++ {\tt Ptr Int} to {\tt Ptr Float}, or {\tt [Int]} to {\tt [Float]} when the list is
4412++ known to be empty. Also, a {\tt newtype} of a type {\tt T} has the same representation
4413++ at runtime as {\tt T}.
4414++
4415++ Other uses of {\tt unsafeCoerce\#} are undefined. In particular, you should not use
4416++ {\tt unsafeCoerce\#} to cast a T to an algebraic data type D, unless T is also
4417++ an algebraic data type. For example, do not cast {\tt Int->Int} to {\tt Bool}, even if
4418++ you later cast that {\tt Bool} back to {\tt Int->Int} before applying it. The reasons
4419++ have to do with GHC's internal representation details (for the cognoscenti, data values
4420++ can be entered but function closures cannot). If you want a safe type to cast things
4421++ to, use {\tt Any}, which is not an algebraic data type.
4422++
4423++ }
4424++ with can_fail = True
4425++
4426++-- NB. It is tempting to think that casting a value to a type that it doesn't have is safe
4427++-- as long as you don't "do anything" with the value in its cast form, such as seq on it. This
4428++-- isn't the case: the compiler can insert seqs itself, and if these happen at the wrong type,
4429++-- Bad Things Might Happen. See bug #1616: in this case we cast a function of type (a,b) -> (a,b)
4430++-- to () -> () and back again. The strictness analyser saw that the function was strict, but
4431++-- the wrapper had type () -> (), and hence the wrapper de-constructed the (), the worker re-constructed
4432++-- a new (), with the result that the code ended up with "case () of (a,b) -> ...".
4433++
4434++primop TraceEventOp "traceEvent#" GenPrimOp
4435++ Addr# -> State# s -> State# s
4436++ { Emits an event via the RTS tracing framework. The contents
4437++ of the event is the zero-terminated byte string passed as the first
4438++ argument. The event will be emitted either to the {\tt .eventlog} file,
4439++ or to stderr, depending on the runtime RTS flags. }
4440++ with
4441++ has_side_effects = True
4442++ out_of_line = True
4443++
4444++primop TraceEventBinaryOp "traceBinaryEvent#" GenPrimOp
4445++ Addr# -> Int# -> State# s -> State# s
4446++ { Emits an event via the RTS tracing framework. The contents
4447++ of the event is the binary object passed as the first argument with
4448++ the the given length passed as the second argument. The event will be
4449++ emitted to the {\tt .eventlog} file. }
4450++ with
4451++ has_side_effects = True
4452++ out_of_line = True
4453++
4454++primop TraceMarkerOp "traceMarker#" GenPrimOp
4455++ Addr# -> State# s -> State# s
4456++ { Emits a marker event via the RTS tracing framework. The contents
4457++ of the event is the zero-terminated byte string passed as the first
4458++ argument. The event will be emitted either to the {\tt .eventlog} file,
4459++ or to stderr, depending on the runtime RTS flags. }
4460++ with
4461++ has_side_effects = True
4462++ out_of_line = True
4463++
4464++primop GetThreadAllocationCounter "getThreadAllocationCounter#" GenPrimOp
4465++ State# RealWorld -> (# State# RealWorld, INT64 #)
4466++ { Retrieves the allocation counter for the current thread. }
4467++ with
4468++ has_side_effects = True
4469++ out_of_line = True
4470++
4471++primop SetThreadAllocationCounter "setThreadAllocationCounter#" GenPrimOp
4472++ INT64 -> State# RealWorld -> State# RealWorld
4473++ { Sets the allocation counter for the current thread to the given value. }
4474++ with
4475++ has_side_effects = True
4476++ out_of_line = True
4477++
4478++------------------------------------------------------------------------
4479++section "Safe coercions"
4480++------------------------------------------------------------------------
4481++
4482++pseudoop "coerce"
4483++ Coercible a b => a -> b
4484++ { The function {\tt coerce} allows you to safely convert between values of
4485++ types that have the same representation with no run-time overhead. In the
4486++ simplest case you can use it instead of a newtype constructor, to go from
4487++ the newtype's concrete type to the abstract type. But it also works in
4488++ more complicated settings, e.g. converting a list of newtypes to a list of
4489++ concrete types.
4490++ }
4491++
4492++------------------------------------------------------------------------
4493++section "SIMD Vectors"
4494++ {Operations on SIMD vectors.}
4495++------------------------------------------------------------------------
4496++
4497++#define ALL_VECTOR_TYPES \
4498++ [<Int8,Int#,16>,<Int16,Int#,8>,<Int32,INT32,4>,<Int64,INT64,2> \
4499++ ,<Int8,Int#,32>,<Int16,Int#,16>,<Int32,INT32,8>,<Int64,INT64,4> \
4500++ ,<Int8,Int#,64>,<Int16,Int#,32>,<Int32,INT32,16>,<Int64,INT64,8> \
4501++ ,<Word8,Word#,16>,<Word16,Word#,8>,<Word32,WORD32,4>,<Word64,WORD64,2> \
4502++ ,<Word8,Word#,32>,<Word16,Word#,16>,<Word32,WORD32,8>,<Word64,WORD64,4> \
4503++ ,<Word8,Word#,64>,<Word16,Word#,32>,<Word32,WORD32,16>,<Word64,WORD64,8> \
4504++ ,<Float,Float#,4>,<Double,Double#,2> \
4505++ ,<Float,Float#,8>,<Double,Double#,4> \
4506++ ,<Float,Float#,16>,<Double,Double#,8>]
4507++
4508++#define SIGNED_VECTOR_TYPES \
4509++ [<Int8,Int#,16>,<Int16,Int#,8>,<Int32,INT32,4>,<Int64,INT64,2> \
4510++ ,<Int8,Int#,32>,<Int16,Int#,16>,<Int32,INT32,8>,<Int64,INT64,4> \
4511++ ,<Int8,Int#,64>,<Int16,Int#,32>,<Int32,INT32,16>,<Int64,INT64,8> \
4512++ ,<Float,Float#,4>,<Double,Double#,2> \
4513++ ,<Float,Float#,8>,<Double,Double#,4> \
4514++ ,<Float,Float#,16>,<Double,Double#,8>]
4515++
4516++#define FLOAT_VECTOR_TYPES \
4517++ [<Float,Float#,4>,<Double,Double#,2> \
4518++ ,<Float,Float#,8>,<Double,Double#,4> \
4519++ ,<Float,Float#,16>,<Double,Double#,8>]
4520++
4521++#define INT_VECTOR_TYPES \
4522++ [<Int8,Int#,16>,<Int16,Int#,8>,<Int32,INT32,4>,<Int64,INT64,2> \
4523++ ,<Int8,Int#,32>,<Int16,Int#,16>,<Int32,INT32,8>,<Int64,INT64,4> \
4524++ ,<Int8,Int#,64>,<Int16,Int#,32>,<Int32,INT32,16>,<Int64,INT64,8> \
4525++ ,<Word8,Word#,16>,<Word16,Word#,8>,<Word32,WORD32,4>,<Word64,WORD64,2> \
4526++ ,<Word8,Word#,32>,<Word16,Word#,16>,<Word32,WORD32,8>,<Word64,WORD64,4> \
4527++ ,<Word8,Word#,64>,<Word16,Word#,32>,<Word32,WORD32,16>,<Word64,WORD64,8>]
4528++
4529++primtype VECTOR
4530++ with llvm_only = True
4531++ vector = ALL_VECTOR_TYPES
4532++
4533++primop VecBroadcastOp "broadcast#" GenPrimOp
4534++ SCALAR -> VECTOR
4535++ { Broadcast a scalar to all elements of a vector. }
4536++ with llvm_only = True
4537++ vector = ALL_VECTOR_TYPES
4538++
4539++primop VecPackOp "pack#" GenPrimOp
4540++ VECTUPLE -> VECTOR
4541++ { Pack the elements of an unboxed tuple into a vector. }
4542++ with llvm_only = True
4543++ vector = ALL_VECTOR_TYPES
4544++
4545++primop VecUnpackOp "unpack#" GenPrimOp
4546++ VECTOR -> VECTUPLE
4547++ { Unpack the elements of a vector into an unboxed tuple. #}
4548++ with llvm_only = True
4549++ vector = ALL_VECTOR_TYPES
4550++
4551++primop VecInsertOp "insert#" GenPrimOp
4552++ VECTOR -> SCALAR -> Int# -> VECTOR
4553++ { Insert a scalar at the given position in a vector. }
4554++ with can_fail = True
4555++ llvm_only = True
4556++ vector = ALL_VECTOR_TYPES
4557++
4558++primop VecAddOp "plus#" Dyadic
4559++ VECTOR -> VECTOR -> VECTOR
4560++ { Add two vectors element-wise. }
4561++ with commutable = True
4562++ llvm_only = True
4563++ vector = ALL_VECTOR_TYPES
4564++
4565++primop VecSubOp "minus#" Dyadic
4566++ VECTOR -> VECTOR -> VECTOR
4567++ { Subtract two vectors element-wise. }
4568++ with llvm_only = True
4569++ vector = ALL_VECTOR_TYPES
4570++
4571++primop VecMulOp "times#" Dyadic
4572++ VECTOR -> VECTOR -> VECTOR
4573++ { Multiply two vectors element-wise. }
4574++ with commutable = True
4575++ llvm_only = True
4576++ vector = ALL_VECTOR_TYPES
4577++
4578++primop VecDivOp "divide#" Dyadic
4579++ VECTOR -> VECTOR -> VECTOR
4580++ { Divide two vectors element-wise. }
4581++ with can_fail = True
4582++ llvm_only = True
4583++ vector = FLOAT_VECTOR_TYPES
4584++
4585++primop VecQuotOp "quot#" Dyadic
4586++ VECTOR -> VECTOR -> VECTOR
4587++ { Rounds towards zero element-wise. }
4588++ with can_fail = True
4589++ llvm_only = True
4590++ vector = INT_VECTOR_TYPES
4591++
4592++primop VecRemOp "rem#" Dyadic
4593++ VECTOR -> VECTOR -> VECTOR
4594++ { Satisfies \texttt{(quot\# x y) times\# y plus\# (rem\# x y) == x}. }
4595++ with can_fail = True
4596++ llvm_only = True
4597++ vector = INT_VECTOR_TYPES
4598++
4599++primop VecNegOp "negate#" Monadic
4600++ VECTOR -> VECTOR
4601++ { Negate element-wise. }
4602++ with llvm_only = True
4603++ vector = SIGNED_VECTOR_TYPES
4604++
4605++primop VecIndexByteArrayOp "indexArray#" GenPrimOp
4606++ ByteArray# -> Int# -> VECTOR
4607++ { Read a vector from specified index of immutable array. }
4608++ with can_fail = True
4609++ llvm_only = True
4610++ vector = ALL_VECTOR_TYPES
4611++
4612++primop VecReadByteArrayOp "readArray#" GenPrimOp
4613++ MutableByteArray# s -> Int# -> State# s -> (# State# s, VECTOR #)
4614++ { Read a vector from specified index of mutable array. }
4615++ with has_side_effects = True
4616++ can_fail = True
4617++ llvm_only = True
4618++ vector = ALL_VECTOR_TYPES
4619++
4620++primop VecWriteByteArrayOp "writeArray#" GenPrimOp
4621++ MutableByteArray# s -> Int# -> VECTOR -> State# s -> State# s
4622++ { Write a vector to specified index of mutable array. }
4623++ with has_side_effects = True
4624++ can_fail = True
4625++ llvm_only = True
4626++ vector = ALL_VECTOR_TYPES
4627++
4628++primop VecIndexOffAddrOp "indexOffAddr#" GenPrimOp
4629++ Addr# -> Int# -> VECTOR
4630++ { Reads vector; offset in bytes. }
4631++ with can_fail = True
4632++ llvm_only = True
4633++ vector = ALL_VECTOR_TYPES
4634++
4635++primop VecReadOffAddrOp "readOffAddr#" GenPrimOp
4636++ Addr# -> Int# -> State# s -> (# State# s, VECTOR #)
4637++ { Reads vector; offset in bytes. }
4638++ with has_side_effects = True
4639++ can_fail = True
4640++ llvm_only = True
4641++ vector = ALL_VECTOR_TYPES
4642++
4643++primop VecWriteOffAddrOp "writeOffAddr#" GenPrimOp
4644++ Addr# -> Int# -> VECTOR -> State# s -> State# s
4645++ { Write vector; offset in bytes. }
4646++ with has_side_effects = True
4647++ can_fail = True
4648++ llvm_only = True
4649++ vector = ALL_VECTOR_TYPES
4650++
4651++
4652++primop VecIndexScalarByteArrayOp "indexArrayAs#" GenPrimOp
4653++ ByteArray# -> Int# -> VECTOR
4654++ { Read a vector from specified index of immutable array of scalars; offset is in scalar elements. }
4655++ with can_fail = True
4656++ llvm_only = True
4657++ vector = ALL_VECTOR_TYPES
4658++
4659++primop VecReadScalarByteArrayOp "readArrayAs#" GenPrimOp
4660++ MutableByteArray# s -> Int# -> State# s -> (# State# s, VECTOR #)
4661++ { Read a vector from specified index of mutable array of scalars; offset is in scalar elements. }
4662++ with has_side_effects = True
4663++ can_fail = True
4664++ llvm_only = True
4665++ vector = ALL_VECTOR_TYPES
4666++
4667++primop VecWriteScalarByteArrayOp "writeArrayAs#" GenPrimOp
4668++ MutableByteArray# s -> Int# -> VECTOR -> State# s -> State# s
4669++ { Write a vector to specified index of mutable array of scalars; offset is in scalar elements. }
4670++ with has_side_effects = True
4671++ can_fail = True
4672++ llvm_only = True
4673++ vector = ALL_VECTOR_TYPES
4674++
4675++primop VecIndexScalarOffAddrOp "indexOffAddrAs#" GenPrimOp
4676++ Addr# -> Int# -> VECTOR
4677++ { Reads vector; offset in scalar elements. }
4678++ with can_fail = True
4679++ llvm_only = True
4680++ vector = ALL_VECTOR_TYPES
4681++
4682++primop VecReadScalarOffAddrOp "readOffAddrAs#" GenPrimOp
4683++ Addr# -> Int# -> State# s -> (# State# s, VECTOR #)
4684++ { Reads vector; offset in scalar elements. }
4685++ with has_side_effects = True
4686++ can_fail = True
4687++ llvm_only = True
4688++ vector = ALL_VECTOR_TYPES
4689++
4690++primop VecWriteScalarOffAddrOp "writeOffAddrAs#" GenPrimOp
4691++ Addr# -> Int# -> VECTOR -> State# s -> State# s
4692++ { Write vector; offset in scalar elements. }
4693++ with has_side_effects = True
4694++ can_fail = True
4695++ llvm_only = True
4696++ vector = ALL_VECTOR_TYPES
4697++
4698++------------------------------------------------------------------------
4699++
4700++section "Prefetch"
4701++ {Prefetch operations: Note how every prefetch operation has a name
4702++ with the pattern prefetch*N#, where N is either 0,1,2, or 3.
4703++
4704++ This suffix number, N, is the "locality level" of the prefetch, following the
4705++ convention in GCC and other compilers.
4706++ Higher locality numbers correspond to the memory being loaded in more
4707++ levels of the cpu cache, and being retained after initial use. The naming
4708++ convention follows the naming convention of the prefetch intrinsic found
4709++ in the GCC and Clang C compilers.
4710++
4711++ On the LLVM backend, prefetch*N# uses the LLVM prefetch intrinsic
4712++ with locality level N. The code generated by LLVM is target architecture
4713++ dependent, but should agree with the GHC NCG on x86 systems.
4714++
4715++ On the Sparc and PPC native backends, prefetch*N is a No-Op.
4716++
4717++ On the x86 NCG, N=0 will generate prefetchNTA,
4718++ N=1 generates prefetcht2, N=2 generates prefetcht1, and
4719++ N=3 generates prefetcht0.
4720++
4721++ For streaming workloads, the prefetch*0 operations are recommended.
4722++ For workloads which do many reads or writes to a memory location in a short period of time,
4723++ prefetch*3 operations are recommended.
4724++
4725++ For further reading about prefetch and associated systems performance optimization,
4726++ the instruction set and optimization manuals by Intel and other CPU vendors are
4727++ excellent starting place.
4728++
4729++
4730++ The "Intel 64 and IA-32 Architectures Optimization Reference Manual" is
4731++ especially a helpful read, even if your software is meant for other CPU
4732++ architectures or vendor hardware. The manual can be found at
4733++ http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-optimization-manual.html .
4734++
4735++ The {\tt prefetch*} family of operations has the order of operations
4736++ determined by passing around the {\tt State#} token.
4737++
4738++ To get a "pure" version of these operations, use {\tt inlinePerformIO} which is quite safe in this context.
4739++
4740++ It is important to note that while the prefetch operations will never change the
4741++ answer to a pure computation, They CAN change the memory locations resident
4742++ in a CPU cache and that may change the performance and timing characteristics
4743++ of an application. The prefetch operations are marked has_side_effects=True
4744++ to reflect that these operations have side effects with respect to the runtime
4745++ performance characteristics of the resulting code. Additionally, if the prefetchValue
4746++ operations did not have this attribute, GHC does a float out transformation that
4747++ results in a let/app violation, at least with the current design.
4748++ }
4749++
4750++
4751++
4752++------------------------------------------------------------------------
4753++
4754++
4755++--- the Int# argument for prefetch is the byte offset on the byteArray or Addr#
4756++
4757++---
4758++primop PrefetchByteArrayOp3 "prefetchByteArray3#" GenPrimOp
4759++ ByteArray# -> Int# -> State# s -> State# s
4760++ with has_side_effects = True
4761++
4762++primop PrefetchMutableByteArrayOp3 "prefetchMutableByteArray3#" GenPrimOp
4763++ MutableByteArray# s -> Int# -> State# s -> State# s
4764++ with has_side_effects = True
4765++
4766++primop PrefetchAddrOp3 "prefetchAddr3#" GenPrimOp
4767++ Addr# -> Int# -> State# s -> State# s
4768++ with has_side_effects = True
4769++
4770++primop PrefetchValueOp3 "prefetchValue3#" GenPrimOp
4771++ a -> State# s -> State# s
4772++ with strictness = { \ _arity -> mkClosedStrictSig [botDmd, topDmd] topRes }
4773++ has_side_effects = True
4774++----
4775++
4776++primop PrefetchByteArrayOp2 "prefetchByteArray2#" GenPrimOp
4777++ ByteArray# -> Int# -> State# s -> State# s
4778++ with has_side_effects = True
4779++
4780++primop PrefetchMutableByteArrayOp2 "prefetchMutableByteArray2#" GenPrimOp
4781++ MutableByteArray# s -> Int# -> State# s -> State# s
4782++ with has_side_effects = True
4783++
4784++primop PrefetchAddrOp2 "prefetchAddr2#" GenPrimOp
4785++ Addr# -> Int# -> State# s -> State# s
4786++ with has_side_effects = True
4787++
4788++primop PrefetchValueOp2 "prefetchValue2#" GenPrimOp
4789++ a -> State# s -> State# s
4790++ with strictness = { \ _arity -> mkClosedStrictSig [botDmd, topDmd] topRes }
4791++ has_side_effects = True
4792++----
4793++
4794++primop PrefetchByteArrayOp1 "prefetchByteArray1#" GenPrimOp
4795++ ByteArray# -> Int# -> State# s -> State# s
4796++ with has_side_effects = True
4797++
4798++primop PrefetchMutableByteArrayOp1 "prefetchMutableByteArray1#" GenPrimOp
4799++ MutableByteArray# s -> Int# -> State# s -> State# s
4800++ with has_side_effects = True
4801++
4802++primop PrefetchAddrOp1 "prefetchAddr1#" GenPrimOp
4803++ Addr# -> Int# -> State# s -> State# s
4804++ with has_side_effects = True
4805++
4806++primop PrefetchValueOp1 "prefetchValue1#" GenPrimOp
4807++ a -> State# s -> State# s
4808++ with strictness = { \ _arity -> mkClosedStrictSig [botDmd, topDmd] topRes }
4809++ has_side_effects = True
4810++----
4811++
4812++primop PrefetchByteArrayOp0 "prefetchByteArray0#" GenPrimOp
4813++ ByteArray# -> Int# -> State# s -> State# s
4814++ with has_side_effects = True
4815++
4816++primop PrefetchMutableByteArrayOp0 "prefetchMutableByteArray0#" GenPrimOp
4817++ MutableByteArray# s -> Int# -> State# s -> State# s
4818++ with has_side_effects = True
4819++
4820++primop PrefetchAddrOp0 "prefetchAddr0#" GenPrimOp
4821++ Addr# -> Int# -> State# s -> State# s
4822++ with has_side_effects = True
4823++
4824++primop PrefetchValueOp0 "prefetchValue0#" GenPrimOp
4825++ a -> State# s -> State# s
4826++ with strictness = { \ _arity -> mkClosedStrictSig [botDmd, topDmd] topRes }
4827++ has_side_effects = True
4828++
4829++------------------------------------------------------------------------
4830++--- ---
4831++------------------------------------------------------------------------
4832++
4833++thats_all_folks
4834+diff --git a/rts/build/HsVersions.h b/rts/build/HsVersions.h
4835+new file mode 100644
4836+index 0000000..a4ec3e4
4837+--- /dev/null
4838++++ b/rts/build/HsVersions.h
4839+@@ -0,0 +1,65 @@
4840++#pragma once
4841++
4842++#if 0
4843++
4844++IMPORTANT! If you put extra tabs/spaces in these macro definitions,
4845++you will screw up the layout where they are used in case expressions!
4846++
4847++(This is cpp-dependent, of course)
4848++
4849++#endif
4850++
4851++/* Useful in the headers that we share with the RTS */
4852++#define COMPILING_GHC 1
4853++
4854++/* Pull in all the platform defines for this build (foo_TARGET_ARCH etc.) */
4855++#include "ghc_boot_platform.h"
4856++
4857++/* Pull in the autoconf defines (HAVE_FOO), but don't include
4858++ * ghcconfig.h, because that will include ghcplatform.h which has the
4859++ * wrong platform settings for the compiler (it has the platform
4860++ * settings for the target plat instead). */
4861++#include "ghcautoconf.h"
4862++
4863++#define GLOBAL_VAR(name,value,ty) \
4864++{-# NOINLINE name #-}; \
4865++name :: IORef (ty); \
4866++name = Util.global (value);
4867++
4868++#define GLOBAL_VAR_M(name,value,ty) \
4869++{-# NOINLINE name #-}; \
4870++name :: IORef (ty); \
4871++name = Util.globalM (value);
4872++
4873++
4874++#define SHARED_GLOBAL_VAR(name,accessor,saccessor,value,ty) \
4875++{-# NOINLINE name #-}; \
4876++name :: IORef (ty); \
4877++name = Util.sharedGlobal (value) (accessor); \
4878++foreign import ccall unsafe saccessor \
4879++ accessor :: Ptr (IORef a) -> IO (Ptr (IORef a));
4880++
4881++#define SHARED_GLOBAL_VAR_M(name,accessor,saccessor,value,ty) \
4882++{-# NOINLINE name #-}; \
4883++name :: IORef (ty); \
4884++name = Util.sharedGlobalM (value) (accessor); \
4885++foreign import ccall unsafe saccessor \
4886++ accessor :: Ptr (IORef a) -> IO (Ptr (IORef a));
4887++
4888++
4889++#define ASSERT(e) if debugIsOn && not (e) then (assertPanic __FILE__ __LINE__) else
4890++#define ASSERT2(e,msg) if debugIsOn && not (e) then (assertPprPanic __FILE__ __LINE__ (msg)) else
4891++#define WARN( e, msg ) (warnPprTrace (e) __FILE__ __LINE__ (msg)) $
4892++
4893++-- Examples: Assuming flagSet :: String -> m Bool
4894++--
4895++-- do { c <- getChar; MASSERT( isUpper c ); ... }
4896++-- do { c <- getChar; MASSERT2( isUpper c, text "Bad" ); ... }
4897++-- do { str <- getStr; ASSERTM( flagSet str ); .. }
4898++-- do { str <- getStr; ASSERTM2( flagSet str, text "Bad" ); .. }
4899++-- do { str <- getStr; WARNM2( flagSet str, text "Flag is set" ); .. }
4900++#define MASSERT(e) ASSERT(e) return ()
4901++#define MASSERT2(e,msg) ASSERT2(e,msg) return ()
4902++#define ASSERTM(e) do { bool <- e; MASSERT(bool) }
4903++#define ASSERTM2(e,msg) do { bool <- e; MASSERT2(bool,msg) }
4904++#define WARNM2(e,msg) do { bool <- e; WARN(bool, msg) return () }
4905+diff --git a/rts/ghc.mk b/rts/ghc.mk
4906+index 6154720..dcb5831 100644
4907+--- a/rts/ghc.mk
4908++++ b/rts/ghc.mk
4909+@@ -34,6 +34,95 @@ rts_dist_WAYS = $(rts_WAYS)
4910+ ALL_RTS_LIBS = $(foreach way,$(rts_WAYS),rts/dist/build/libHSrts$($(way)_libsuf))
4911+ $(eval $(call all-target,rts,$(ALL_RTS_LIBS)))
4912+
4913++
4914++rts/build/config.hs-incl : mk/config.mk mk/project.mk | $$(dir $$@)/.
4915++ $(call removeFiles,$@)
4916++ @echo 'Creating $@ ... '
4917++ @echo 'data IntegerLibrary = IntegerGMP' >> $@
4918++ @echo ' | IntegerSimple' >> $@
4919++ @echo ' deriving Eq' >> $@
4920++ @echo >> $@
4921++ @echo 'cBuildPlatformString :: String' >> $@
4922++ @echo 'cBuildPlatformString = BuildPlatform_NAME' >> $@
4923++ @echo 'cHostPlatformString :: String' >> $@
4924++ @echo 'cHostPlatformString = HostPlatform_NAME' >> $@
4925++ @echo 'cTargetPlatformString :: String' >> $@
4926++ @echo 'cTargetPlatformString = TargetPlatform_NAME' >> $@
4927++ @echo >> $@
4928++ @echo 'cProjectName :: String' >> $@
4929++ @echo 'cProjectName = "$(ProjectName)"' >> $@
4930++ @echo 'cProjectGitCommitId :: String' >> $@
4931++ @echo 'cProjectGitCommitId = "$(ProjectGitCommitId)"' >> $@
4932++ @echo 'cProjectVersion :: String' >> $@
4933++ @echo 'cProjectVersion = "$(ProjectVersion)"' >> $@
4934++ @echo 'cProjectVersionInt :: String' >> $@
4935++ @echo 'cProjectVersionInt = "$(ProjectVersionInt)"' >> $@
4936++ @echo 'cProjectPatchLevel :: String' >> $@
4937++ @echo 'cProjectPatchLevel = "$(ProjectPatchLevel)"' >> $@
4938++ @echo 'cProjectPatchLevel1 :: String' >> $@
4939++ @echo 'cProjectPatchLevel1 = "$(ProjectPatchLevel1)"' >> $@
4940++ @echo 'cProjectPatchLevel2 :: String' >> $@
4941++ @echo 'cProjectPatchLevel2 = "$(ProjectPatchLevel2)"' >> $@
4942++ @echo 'cBooterVersion :: String' >> $@
4943++ @echo 'cBooterVersion = "$(GhcVersion)"' >> $@
4944++ @echo 'cStage :: String' >> $@
4945++ @echo 'cStage = show (STAGE :: Int)' >> $@
4946++ @echo 'cIntegerLibraryType :: IntegerLibrary' >> $@
4947++ifeq "$(INTEGER_LIBRARY)" "integer-gmp"
4948++ @echo 'cIntegerLibraryType = IntegerGMP' >> $@
4949++else ifeq "$(INTEGER_LIBRARY)" "integer-simple"
4950++ @echo 'cIntegerLibraryType = IntegerSimple' >> $@
4951++else ifneq "$(CLEANING)" "YES"
4952++$(error Unknown integer library)
4953++endif
4954++ @echo 'cSupportsSplitObjs :: String' >> $@
4955++ @echo 'cSupportsSplitObjs = "$(SupportsSplitObjs)"' >> $@
4956++ @echo 'cGhcWithInterpreter :: String' >> $@
4957++ @echo 'cGhcWithInterpreter = "$(GhcWithInterpreter)"' >> $@
4958++ @echo 'cGhcWithNativeCodeGen :: String' >> $@
4959++ @echo 'cGhcWithNativeCodeGen = "$(GhcWithNativeCodeGen)"' >> $@
4960++ @echo 'cGhcWithSMP :: String' >> $@
4961++ @echo 'cGhcWithSMP = "$(GhcWithSMP)"' >> $@
4962++ @echo 'cGhcRTSWays :: String' >> $@
4963++ @echo 'cGhcRTSWays = "$(GhcRTSWays)"' >> $@
4964++ @echo 'cGhcRtsWithLibdw :: Bool' >> $@
4965++ifeq "$(GhcRtsWithLibdw)" "YES"
4966++ @echo 'cGhcRtsWithLibdw = True' >> $@
4967++else
4968++ @echo 'cGhcRtsWithLibdw = False' >> $@
4969++endif
4970++ @echo 'cGhcEnableTablesNextToCode :: String' >> $@
4971++ @echo 'cGhcEnableTablesNextToCode = "$(GhcEnableTablesNextToCode)"' >> $@
4972++ @echo 'cLeadingUnderscore :: String' >> $@
4973++ @echo 'cLeadingUnderscore = "$(LeadingUnderscore)"' >> $@
4974++ @echo 'cGHC_UNLIT_PGM :: String' >> $@
4975++ @echo 'cGHC_UNLIT_PGM = "$(utils/unlit_dist_PROG)"' >> $@
4976++ @echo 'cGHC_SPLIT_PGM :: String' >> $@
4977++ @echo 'cGHC_SPLIT_PGM = "$(driver/split_dist_PROG)"' >> $@
4978++ @echo 'cLibFFI :: Bool' >> $@
4979++ifeq "$(UseLibFFIForAdjustors)" "YES"
4980++ @echo 'cLibFFI = True' >> $@
4981++else
4982++ @echo 'cLibFFI = False' >> $@
4983++endif
4984++# Note that GhcThreaded just reflects the Makefile variable setting.
4985++# In particular, the stage1 compiler is never actually compiled with
4986++# -threaded, but it will nevertheless have cGhcThreaded = True.
4987++# The "+RTS --info" output will show what RTS GHC is really using.
4988++ @echo 'cGhcThreaded :: Bool' >> $@
4989++ifeq "$(GhcThreaded)" "YES"
4990++ @echo 'cGhcThreaded = True' >> $@
4991++else
4992++ @echo 'cGhcThreaded = False' >> $@
4993++endif
4994++ @echo 'cGhcDebugged :: Bool' >> $@
4995++ifeq "$(GhcDebugged)" "YES"
4996++ @echo 'cGhcDebugged = True' >> $@
4997++else
4998++ @echo 'cGhcDebugged = False' >> $@
4999++endif
5000++ @echo done.
5001++
5002+ # -----------------------------------------------------------------------------
5003+ # Defining the sources
5004+
5005+diff --git a/rts/rts.cabal b/rts/rts.cabal
5006+index 22f5e5d..9d0d045 100644
5007+--- a/rts/rts.cabal
5008++++ b/rts/rts.cabal
5009+@@ -7,7 +7,7 @@
5010+ flag libm
5011+ default: True
5012+ flag librt
5013+- default: True
5014++ default: False
5015+ flag libdl
5016+ default: True
5017+ flag ffi
5018+@@ -25,7 +25,7 @@
5019+ flag 64bit
5020+ default: False
5021+ flag leading-underscore
5022+- default: False
5023++ default: True
5024+ flag smp
5025+ default: True
5026+ flag find-ptr
5027+@@ -120,6 +120,11 @@
5028+ ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h
5029+ -- ^ from ../includes
5030+ DerivedConstants.h ffi.h ffitarget.h
5031++ GHCConstantsHaskellType.hs GHCConstantsHaskellWrappers.hs
5032++ CodeGen.Platform.hs
5033++ platformConstants
5034++ config.hs-incl
5035++ HsVersions.h
5036+ -- ^ generated
5037+ rts/Adjustor.h
5038+ rts/BlockSignals.h
5039+diff --git a/rts/rts.cabal.in b/rts/rts.cabal.in
5040+index d41135d..4ab75bc 100644
5041+--- a/rts/rts.cabal.in
5042++++ b/rts/rts.cabal.in
5043+@@ -102,6 +102,11 @@ library
5044+ ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h
5045+ -- ^ from ../includes
5046+ DerivedConstants.h ffi.h ffitarget.h
5047++ GHCConstantsHaskellType.hs GHCConstantsHaskellWrappers.hs
5048++ CodeGen.Platform.hs
5049++ platformConstants
5050++ config.hs-incl
5051++ HsVersions.h
5052+ -- ^ generated
5053+ rts/Adjustor.h
5054+ rts/BlockSignals.h
5055+diff --git a/utils/genapply/Main.hs b/utils/genapply/Main.hs
5056+index b30c9f8..150c8c8 100644
5057+--- a/utils/genapply/Main.hs
5058++++ b/utils/genapply/Main.hs
5059+@@ -17,7 +17,7 @@ module Main(main) where
5060+ #include "../../includes/rts/Constants.h"
5061+
5062+ -- Needed for TAG_BITS
5063+-#include "../../includes/MachDeps.h"
5064++#include "MachDeps.h"
5065+
5066+ #if MIN_VERSION_base(4,11,0)
5067+ import Prelude hiding ((<>))