Cheng Shao pushed to branch wip/T26166 at Glasgow Haskell Compiler / GHC
Commits:
-
677325ce
by Cheng Shao at 2025-10-14T20:40:17+02:00
4 changed files:
Changes:
| ... | ... | @@ -664,7 +664,7 @@ dsWasmJSExport' sync m_fn_id co ext_name = do |
| 664 | 664 | -- again here.
|
| 665 | 665 | Sync -> [finally_id, flushStdHandles_id]
|
| 666 | 666 | Async -> [top_handler_id, promiseRes_id]
|
| 667 | - extern_closure_decls = vcat $ map mk_extern_closure_decl gc_root_closures
|
|
| 667 | + extern_closure_decls = vcat $ map mk_extern_closure_decl $ top_handler_id : gc_root_closures
|
|
| 668 | 668 | cstub_attr =
|
| 669 | 669 | text "__attribute__"
|
| 670 | 670 | <> parens
|
| ... | ... | @@ -109,6 +109,9 @@ __attribute__((constructor(102))) static void __ghc_wasm_jsffi_init(void) { |
| 109 | 109 | RtsConfig __conf = defaultRtsConfig;
|
| 110 | 110 | __conf.rts_opts_enabled = RtsOptsAll;
|
| 111 | 111 | __conf.rts_hs_main = false;
|
| 112 | +#if defined(__PIC__)
|
|
| 113 | + __conf.keep_cafs = 1;
|
|
| 114 | +#endif
|
|
| 112 | 115 | hs_init_ghc((int *)&argc, &argv, __conf);
|
| 113 | 116 | // See Note [threadDelay on wasm] for details.
|
| 114 | 117 | rts_JSFFI_flag = HS_BOOL_TRUE;
|
| ... | ... | @@ -113,8 +113,8 @@ |
| 113 | 113 | // JavaScript main thread.
|
| 114 | 114 | #define BUSY_YIELD_NS 15000000
|
| 115 | 115 | |
| 116 | -import CLOSURE ghczminternal_GHCziInternalziTuple_Z0T_closure;
|
|
| 117 | 116 | #if !defined(UnregisterisedCompiler)
|
| 117 | +import CLOSURE ghc_hs_iface;
|
|
| 118 | 118 | import CLOSURE stg_scheduler_loop_epoch;
|
| 119 | 119 | import CLOSURE stg_scheduler_loop_tid;
|
| 120 | 120 | #endif
|
| ... | ... | @@ -139,7 +139,7 @@ stg_scheduler_loopzh () |
| 139 | 139 | // Only meant to be run from a "main thread" (aka bound to an InCall
|
| 140 | 140 | // frame), not from a forked thread!
|
| 141 | 141 | if (StgTSO_bound(CurrentTSO) == NULL) {
|
| 142 | - return (ghczminternal_GHCziInternalziTuple_Z0T_closure);
|
|
| 142 | + return (HsIface_Z0T_closure(W_[ghc_hs_iface]));
|
|
| 143 | 143 | }
|
| 144 | 144 | |
| 145 | 145 | // Entering the scheduler loop for the first time.
|
| ... | ... | @@ -154,7 +154,7 @@ stg_scheduler_loopzh () |
| 154 | 154 | |
| 155 | 155 | // Someone else is running the loop, not my business anymore.
|
| 156 | 156 | if (I64[stg_scheduler_loop_tid] != StgTSO_id(CurrentTSO)) {
|
| 157 | - return (ghczminternal_GHCziInternalziTuple_Z0T_closure);
|
|
| 157 | + return (HsIface_Z0T_closure(W_[ghc_hs_iface]));
|
|
| 158 | 158 | }
|
| 159 | 159 | |
| 160 | 160 | work:
|
| ... | ... | @@ -180,7 +180,7 @@ work: |
| 180 | 180 | |
| 181 | 181 | cleanup:
|
| 182 | 182 | I64[stg_scheduler_loop_tid] = 0 :: I64;
|
| 183 | - return (ghczminternal_GHCziInternalziTuple_Z0T_closure);
|
|
| 183 | + return (HsIface_Z0T_closure(W_[ghc_hs_iface]));
|
|
| 184 | 184 | }
|
| 185 | 185 | |
| 186 | 186 | // After creating a new thread with only a stop frame on the stack,
|
| ... | ... | @@ -1100,22 +1100,11 @@ class DyLD { |
| 1100 | 1100 | continue;
|
| 1101 | 1101 | }
|
| 1102 | 1102 | if (/libHSghc-internal-\d+(\.\d+)*/i.test(soname)) {
|
| 1103 | + init();
|
|
| 1103 | 1104 | this.rts_init();
|
| 1104 | 1105 | delete this.rts_init;
|
| 1105 | 1106 | |
| 1106 | - // At this point the RTS symbols in linear memory are fixed
|
|
| 1107 | - // and constructors are run, especially the one in JSFFI.c
|
|
| 1108 | - // that does GHC RTS initialization for any code that links
|
|
| 1109 | - // JSFFI.o. Luckily no Haskell computation or gc has taken
|
|
| 1110 | - // place yet, so we must set keepCAFs=1 right now! Otherwise,
|
|
| 1111 | - // any BCO created by later TH splice or ghci expression may
|
|
| 1112 | - // refer to any CAF that's not reachable from GC roots (here
|
|
| 1113 | - // our only entry point is defaultServer) and the CAF could
|
|
| 1114 | - // have been GC'ed! (#26106)
|
|
| 1115 | - //
|
|
| 1116 | - // We call it here instead of in RTS C code, since we only
|
|
| 1117 | - // want keepCAFs=1 for ghci, not user code.
|
|
| 1118 | - this.exportFuncs.setKeepCAFs();
|
|
| 1107 | + continue;
|
|
| 1119 | 1108 | }
|
| 1120 | 1109 | init();
|
| 1121 | 1110 | }
|