Fix bug in previous fix for #5654
authorSimon Marlow <marlowsd@gmail.com>
Sat, 17 Dec 2016 23:08:48 +0000 (18:08 -0500)
committerBen Gamari <ben@smart-cactus.org>
Sat, 17 Dec 2016 23:09:40 +0000 (18:09 -0500)
I forgot to account for BCOs, which have a different layout from
functions.  This caused crashes when using profiling with GHCi (via
-fexternal-interpreter -prof), which unfortunately is not tested at all
by validate, even when profiling is enabled.  I'm going to add some
testing that would have caught this in a separate patch.

Test Plan:
```
cd nofib/spectral/puzzle && make NoFibWithGHCi=YES
EXTRA_RUNTEST_OPTS='-fexternal-interpreter -prof'
```
New testsuite tests coming in a separate diff.

Reviewers: niteria, austin, erikd, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2868

GHC Trac Issues: #5654

rts/Apply.cmm

index 3a73ce0..b18c347 100644 (file)
@@ -57,6 +57,7 @@ stg_ap_0_fast ( P_ fun )
 again:
     W_  info;
     W_ untaggedfun;
+    W_ arity;
     untaggedfun = UNTAG(fun);
     info = %INFO_PTR(untaggedfun);
     switch [INVALID_OBJECT .. N_CLOSURE_TYPES]
@@ -68,6 +69,11 @@ again:
             fun = StgInd_indirectee(fun);
             goto again;
         }
+        case BCO:
+        {
+            arity = TO_W_(StgBCO_arity(untaggedfun));
+            goto dofun;
+        }
         case
             FUN,
             FUN_1_0,
@@ -75,9 +81,10 @@ again:
             FUN_2_0,
             FUN_1_1,
             FUN_0_2,
-            FUN_STATIC,
-            BCO:
+            FUN_STATIC:
         {
+            arity = TO_W_(StgFunInfoExtra_arity(%FUN_INFO(info)));
+        dofun:
             if (CCCS == StgHeader_ccs(untaggedfun)) {
                 return (fun);
             } else {
@@ -92,10 +99,8 @@ again:
                 // attribute this allocation to the "overhead of profiling"
                 CCS_ALLOC(BYTES_TO_WDS(SIZEOF_StgPAP), CCS_OVERHEAD);
                 P_ pap;
-                W_ arity;
                 pap = Hp - SIZEOF_StgPAP + WDS(1);
                 SET_HDR(pap, stg_PAP_info, CCCS);
-                arity = TO_W_(StgFunInfoExtra_arity(%FUN_INFO(info)));
                 StgPAP_arity(pap) = arity;
                 StgPAP_fun(pap)   = fun;
                 StgPAP_n_args(pap) = 0;