summaryrefslogtreecommitdiff
path: root/compiler/cmm/SMRep.hs
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2016-11-09 09:20:02 +0000
committerSimon Marlow <marlowsd@gmail.com>2016-11-14 14:43:35 +0000
commit55d535da10dd63bbaf03fb176ced7179087cd0d4 (patch)
tree57bdbf04381fe08d90c384f5b10e77c3384227d9 /compiler/cmm/SMRep.hs
parent6c0f10fac767c49b65ed71e8eb8e78ca4f9062d5 (diff)
downloadhaskell-55d535da10dd63bbaf03fb176ced7179087cd0d4.tar.gz
Remove CONSTR_STATIC
Summary: We currently have two info tables for a constructor * XXX_con_info: the info table for a heap-resident instance of the constructor, It has type CONSTR, or one of the specialised types like CONSTR_1_0 * XXX_static_info: the info table for a static instance of this constructor, which has type CONSTR_STATIC or CONSTR_STATIC_NOCAF. I'm getting rid of the latter, and using the `con_info` info table for both static and dynamic constructors. For rationale and more details see Note [static constructors] in SMRep.hs. I also removed these macros: `isSTATIC()`, `ip_STATIC()`, `closure_STATIC()`, since they relied on the CONSTR/CONSTR_STATIC distinction, and anyway HEAP_ALLOCED() does the same job. Test Plan: validate Reviewers: bgamari, simonpj, austin, gcampax, hvr, niteria, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2690 GHC Trac Issues: #12455
Diffstat (limited to 'compiler/cmm/SMRep.hs')
-rw-r--r--compiler/cmm/SMRep.hs54
1 files changed, 41 insertions, 13 deletions
diff --git a/compiler/cmm/SMRep.hs b/compiler/cmm/SMRep.hs
index ecd8905cbb..83ddf18586 100644
--- a/compiler/cmm/SMRep.hs
+++ b/compiler/cmm/SMRep.hs
@@ -177,6 +177,7 @@ data SMRep
-- | True <=> This is a static closure. Affects how we garbage-collect it.
-- Static closure have an extra static link field at the end.
+-- Constructors do not have a static variant; see Note [static constructors]
type IsStatic = Bool
-- From an SMRep you can get to the closure type defined in
@@ -287,10 +288,10 @@ isFunRep (HeapRep _ _ _ Fun{}) = True
isFunRep _ = False
isStaticNoCafCon :: SMRep -> Bool
--- This should line up exactly with CONSTR_NOCAF_STATIC above
+-- This should line up exactly with CONSTR_NOCAF below
-- See Note [Static NoCaf constructors]
-isStaticNoCafCon (HeapRep True 0 _ Constr{}) = True
-isStaticNoCafCon _ = False
+isStaticNoCafCon (HeapRep _ 0 _ Constr{}) = True
+isStaticNoCafCon _ = False
-----------------------------------------------------------------------------
@@ -428,12 +429,15 @@ rtsClosureType rep
= case rep of
RTSRep ty _ -> ty
- HeapRep False 1 0 Constr{} -> CONSTR_1_0
- HeapRep False 0 1 Constr{} -> CONSTR_0_1
- HeapRep False 2 0 Constr{} -> CONSTR_2_0
- HeapRep False 1 1 Constr{} -> CONSTR_1_1
- HeapRep False 0 2 Constr{} -> CONSTR_0_2
- HeapRep False _ _ Constr{} -> CONSTR
+ -- See Note [static constructors]
+ HeapRep _ 1 0 Constr{} -> CONSTR_1_0
+ HeapRep _ 0 1 Constr{} -> CONSTR_0_1
+ HeapRep _ 2 0 Constr{} -> CONSTR_2_0
+ HeapRep _ 1 1 Constr{} -> CONSTR_1_1
+ HeapRep _ 0 2 Constr{} -> CONSTR_0_2
+ HeapRep _ 0 _ Constr{} -> CONSTR_NOCAF
+ -- See Note [Static NoCaf constructors]
+ HeapRep _ _ _ Constr{} -> CONSTR
HeapRep False 1 0 Fun{} -> FUN_1_0
HeapRep False 0 1 Fun{} -> FUN_0_1
@@ -451,10 +455,6 @@ rtsClosureType rep
HeapRep False _ _ ThunkSelector{} -> THUNK_SELECTOR
- -- Approximation: we use the CONSTR_NOCAF_STATIC type for static
- -- constructors -- that have no pointer words only.
- HeapRep True 0 _ Constr{} -> CONSTR_NOCAF_STATIC -- See isStaticNoCafCon below
- HeapRep True _ _ Constr{} -> CONSTR_STATIC
HeapRep True _ _ Fun{} -> FUN_STATIC
HeapRep True _ _ Thunk{} -> THUNK_STATIC
@@ -472,6 +472,34 @@ aRG_GEN = ARG_GEN
aRG_GEN_BIG = ARG_GEN_BIG
{-
+Note [static constructors]
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+We used to have a CONSTR_STATIC closure type, and each constructor had
+two info tables: one with CONSTR (or CONSTR_1_0 etc.), and one with
+CONSTR_STATIC.
+
+This distinction was removed, because when copying a data structure
+into a compact region, we must copy static constructors into the
+compact region too. If we didn't do this, we would need to track the
+references from the compact region out to the static constructors,
+because they might (indirectly) refer to CAFs.
+
+Since static constructors will be copied to the heap, if we wanted to
+use different info tables for static and dynamic constructors, we
+would have to switch the info pointer when copying the constructor
+into the compact region, which means we would need an extra field of
+the static info table to point to the dynamic one.
+
+However, since the distinction between static and dynamic closure
+types is never actually needed (other than for assertions), we can
+just drop the distinction and use the same info table for both.
+
+The GC *does* need to distinguish between static and dynamic closures,
+but it does this using the HEAP_ALLOCED() macro which checks whether
+the address of the closure resides within the dynamic heap.
+HEAP_ALLOCED() doesn't read the closure's info table.
+
Note [Static NoCaf constructors]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If we know that a top-level binding 'x' is not Caffy (ie no CAFs are