Skip to content

Mechanism for hand-written, but not wired-in, Ids

We got into terrible trouble trying to make unsafeCoerce# into a wired-in Id. We needed to make unsafeEqualityProof and UnsafeEquality wired in -- and the lattter is a GADT which is hugely painful to wire in.

New idea. Implement

patchMagicDefns :: [(Name, DsM (Id, CoreExpr))]
                -> [(Id,CoreExpr)]
                -> DsM [(Id,CoreExpr)]

and use it in the desugarer, here

        ; (msgs, mb_res) <- initDs hsc_env tcg_env $
                       do { ds_ev_binds <- dsEvBinds ev_binds
                          ; core_prs <- dsTopLHsBinds binds_cvr
--->  here --->           ; core_prs <- patchMagicDefns magicDefns core_prs
                          ; (spec_prs, spec_rules) <- dsImpSpecs imp_specs

So now we could have

mmagicDefns :: [(Name, DsM (Id,CoreExpr))]
magicDefns
  [ ( unsafeCoerceName, do { unsafe_eq_proof <- dsLookupGlobal unsafeEqualityProofName
        ... )
  ]

The big thing is having access to dsLookupGlobal which means you don't need to wire in the trnansitive closure.

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