Skip to content

feat: add closure support to the object compactor#13194

Draft
Kha wants to merge 4 commits intoleanprover:masterfrom
Kha:push-mwtznynslukl
Draft

feat: add closure support to the object compactor#13194
Kha wants to merge 4 commits intoleanprover:masterfrom
Kha:push-mwtznynslukl

Conversation

@Kha
Copy link
Copy Markdown
Member

@Kha Kha commented Mar 30, 2026

This PR adds the ability to compact and deserialize closures, which was previously rejected with "closures cannot be compacted". Closure function pointers are preserved as raw pointers at save time, with a per-library relocation table stored as a file trailer for cross-invocation ASLR fixup. The library table is built once per compactor via platform-specific APIs (dl_iterate_phdr on Linux, _dyld_* on macOS, EnumProcessModules on Windows). Files without closures are unchanged (backward compatible via a reserved flag bit).

For now it is assumed that serialization of closures is a special case affecting only smaller files, so when actual relocation is needed on mmap'd data, the region is copied to a writable buffer first.

Kha added 2 commits March 30, 2026 15:19
This PR adds new incremental module serialization functions that save/load
a single module at a time with explicit sharing via dep regions and
compactor state, alongside the existing batch saveModuleDataParts API.

Two sharing mechanisms:
- CompactedRegion dep regions for import sharing (address range check
  with rc==0 fast-reject + binary search)
- CompactorState for same-process chaining (pre-loaded obj_table)
@Kha
Copy link
Copy Markdown
Member Author

Kha commented Mar 30, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Mar 30, 2026

Benchmark results for 4e305f7 against 4786e08 are in. Significant changes detected! @Kha

  • build//instructions: -648.0M (-0.01%)

Large changes (2🟥)

  • 🟥 size/all/.cpp//lines: +229.0 (+0.80%)
  • 🟥 size/compile/.out//bytes: +194MiB (+11.15%)

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Mar 30, 2026
@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-03-25 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-03-30 20:37:51)

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 30, 2026
@github-actions github-actions bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Mar 30, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 30, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Mar 30, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

Kha added 2 commits March 31, 2026 09:26
This adds the ability to compact and deserialize closures, which was previously
rejected with `closures cannot be compacted`. Closure function pointers are
preserved as raw pointers at save time, with a per-library relocation table
in the v3 olean header extension for cross-invocation ASLR fixup. The library
table is built once per compactor via platform-specific APIs (`dl_iterate_phdr`
on Linux, `_dyld_*` on macOS, `EnumProcessModules` on Windows).

When mmap succeeds and all relocation deltas are zero (same process), the
fast path skips all fixups. When actual relocation is needed on mmap`d data,
the region is copied to a writable buffer first.
@Kha Kha force-pushed the push-mwtznynslukl branch from 4e305f7 to 16811d6 Compare March 31, 2026 15:13
@Kha Kha added the release-ci Enable all CI checks for a PR, like is done for releases label Mar 31, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN release-ci Enable all CI checks for a PR, like is done for releases toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants