[Git][ghc/ghc][wip/bco-docs] 2 commits: compiler: Use field selectors when creating BCOs

Ben Gamari pushed to branch wip/bco-docs at Glasgow Haskell Compiler / GHC Commits: acd08fcd by Ben Gamari at 2025-05-15T13:05:59-04:00 compiler: Use field selectors when creating BCOs This makes it easier to grep for these fields. - - - - - 882ffdec by Ben Gamari at 2025-05-15T13:06:02-04:00 compiler: Clarify BCO size Previously the semantics and size of StgBCO was a bit unclear. Specifically, the `size` field was documented to contain the size of the bitmap whereas it was actually the size of the closure *and* bitmap. Additionally, it was not as clear as it could be that the bitmap was a full StgLargeBitmap with its own `size` field. - - - - - 4 changed files: - compiler/GHC/ByteCode/Asm.hs - compiler/GHC/ByteCode/Linker.hs - rts/PrimOps.cmm - rts/include/rts/storage/Closures.h Changes: ===================================== compiler/GHC/ByteCode/Asm.hs ===================================== @@ -266,7 +266,13 @@ assembleBCO platform let !insns_arr = mkBCOByteArray $ final_isn_array !bitmap_arr = mkBCOByteArray $ mkBitmapArray bsize bitmap - ul_bco = UnlinkedBCO nm arity insns_arr bitmap_arr (fromSmallArray final_lit_array) (fromSmallArray final_ptr_array) + ul_bco = UnlinkedBCO { unlinkedBCOName = nm + , unlinkedBCOArity = arity + , unlinkedBCOInstrs = insns_arr + , unlinkedBCOBitmap = bitmap_arr + , unlinkedBCOLits = fromSmallArray final_lit_array + , unlinkedBCOPtrs = fromSmallArray final_ptr_array + } -- 8 Aug 01: Finalisers aren't safe when attached to non-primitive -- objects, since they might get run too early. Disable this until @@ -275,6 +281,7 @@ assembleBCO platform return ul_bco +-- | Construct a word-array containing an @StgLargeBitmap@. mkBitmapArray :: Word -> [StgWord] -> UArray Int Word -- Here the return type must be an array of Words, not StgWords, -- because the underlying ByteArray# will end up as a component ===================================== compiler/GHC/ByteCode/Linker.hs ===================================== @@ -65,11 +65,13 @@ linkBCO interp pkgs_loaded le bco_ix (lits :: [Word]) <- mapM (fmap fromIntegral . lookupLiteral interp pkgs_loaded le) (elemsFlatBag lits0) ptrs <- mapM (resolvePtr interp pkgs_loaded le bco_ix) (elemsFlatBag ptrs0) let lits' = listArray (0 :: Int, fromIntegral (sizeFlatBag lits0)-1) lits - return (ResolvedBCO isLittleEndian arity - insns - bitmap - (mkBCOByteArray lits') - (addListToSS emptySS ptrs)) + return $ ResolvedBCO { resolvedBCOIsLE = isLittleEndian + , resolvedBCOArity = arity + , resolvedBCOInstrs = insns + , resolvedBCOBitmap = bitmap + , resolvedBCOLits = mkBCOByteArray lits' + , resolvedBCOPtrs = addListToSS emptySS ptrs + } lookupLiteral :: Interp -> PkgsLoaded -> LinkerEnv -> BCONPtr -> IO Word lookupLiteral interp pkgs_loaded le ptr = case ptr of ===================================== rts/PrimOps.cmm ===================================== @@ -2440,6 +2440,7 @@ stg_newBCOzh ( P_ instrs, W_ arity, P_ bitmap_arr ) { + // N.B. bitmap_arr contains a full StgLargeBitmap object. W_ bco, bytes, words; words = BYTES_TO_WDS(SIZEOF_StgBCO) + BYTE_ARR_WDS(bitmap_arr); ===================================== rts/include/rts/storage/Closures.h ===================================== @@ -427,7 +427,7 @@ typedef struct { StgArrBytes *literals; // literals used by the instructions StgMutArrPtrs *ptrs; // free variables StgHalfWord arity; // arity of this BCO - StgHalfWord size; // size of the bitmap + StgHalfWord size; // size of the closure and bitmap StgWord bitmap[]; // an StgLargeBitmap } StgBCO; View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0bf1212af899941e6e11347a8b20ad9... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0bf1212af899941e6e11347a8b20ad9... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Ben Gamari (@bgamari)