@@ -1606,21 +1606,33 @@ let close_program ~symbol_for_global ~big_endian ~module_ident
16061606 ~handler_params: load_fields_handler_param ~handler: load_fields_body ~body
16071607 ~is_exn_handler: false
16081608 in
1609+ let all_code =
1610+ Code_id.Map. mapi (fun code_id code_or_metadata ->
1611+ match (code_or_metadata : Code_or_metadata.t ) with
1612+ | Code_present code -> code
1613+ | Metadata_only _ -> Misc. fatal_errorf " Metadata only for code ID %a" Code_id. print code_id)
1614+ (Acc. code acc)
1615+ in
16091616 let acc, body =
1610- Code_id.Map. fold
1611- (fun code_id code (acc , body ) ->
1612- let bound_symbols =
1613- Bound_symbols. singleton (Bound_symbols.Pattern. code code_id)
1614- in
1615- let static_const = Static_const_or_code. create_code code in
1616- let defining_expr =
1617- Static_const_group. create [static_const] |> Named. create_static_consts
1618- in
1619- Let_with_acc. create acc
1620- (Bound_pattern. symbols bound_symbols)
1621- defining_expr ~body
1622- |> Expr_with_acc. create_let)
1623- (Acc. code acc) (acc, body)
1617+ let bound_symbols, static_consts =
1618+ Code_id.Map. fold
1619+ (fun code_id code (bound_symbols , static_consts ) ->
1620+ let bound_symbols =
1621+ (Bound_symbols.Pattern. code code_id) :: bound_symbols
1622+ in
1623+ let static_consts =
1624+ (Static_const_or_code. create_code code) :: static_consts
1625+ in
1626+ (bound_symbols, static_consts))
1627+ all_code ([] , [] )
1628+ in
1629+ let defining_expr =
1630+ Static_const_group. create static_consts |> Named. create_static_consts
1631+ in
1632+ Let_with_acc. create acc
1633+ (Bound_pattern. symbols (Bound_symbols. create bound_symbols))
1634+ defining_expr ~body
1635+ |> Expr_with_acc. create_let
16241636 in
16251637 (* We must make sure there is always an outer [Let_symbol] binding so that
16261638 lifted constants not in the scope of any other [Let_symbol] binding get put
@@ -1670,5 +1682,5 @@ let close_program ~symbol_for_global ~big_endian ~module_ident
16701682 ~module_symbol ~used_closure_vars: Unknown ,
16711683 Exported_code. add_code
16721684 ~keep_code: (fun _ -> false )
1673- ( Acc. code acc) Exported_code. empty,
1685+ all_code Exported_code. empty,
16741686 exported_offsets )
0 commit comments