Skip to content

fix: pass Lake module setup to highlighted extractor - #222

Open
ejgallego wants to merge 5 commits into
leanprover:mainfrom
ejgallego:codex/highlighted-lake-setup
Open

fix: pass Lake module setup to highlighted extractor#222
ejgallego wants to merge 5 commits into
leanprover:mainfrom
ejgallego:codex/highlighted-lake-setup

Conversation

@ejgallego

@ejgallego ejgallego commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Fix highlighted source extraction for modules whose Lake build context includes setup data, such as dynamic libraries.

The highlighted module facet now passes Lake's module setup file to subverso-extract-mod when Lake exposes one. The extractor loads that setup before elaboration, so extraction sees the same imports, options, plugins, import artifacts, dynamic libraries, and package metadata as the module build. Older Lake versions continue using the existing extractor arguments.

This adds an FFI regression fixture that builds a dynamic library and checks Ffi:highlighted. The fixture runs on Lean 4.27 and newer; setup files exist in some earlier module-system releases, but this fixture's extern #eval fails during the module build before SubVerso extraction runs there.

Related: #221 , thanks to @kim-em for submitting the report and a preliminary fix.

@ejgallego
ejgallego force-pushed the codex/highlighted-lake-setup branch from 3e0dad3 to a1eb3e3 Compare July 3, 2026 17:38
@ejgallego ejgallego changed the title [codex] fix highlighted facet Lake module setup fix: honor Lake module setup in highlighted facet Jul 3, 2026
@ejgallego
ejgallego force-pushed the codex/highlighted-lake-setup branch 2 times, most recently from c809243 to feb86d0 Compare July 3, 2026 18:44
@ejgallego ejgallego changed the title fix: honor Lake module setup in highlighted facet fix: pass Lake module setup to highlighted extractor Jul 6, 2026
@ejgallego
ejgallego marked this pull request as ready for review July 6, 2026 11:44
@ejgallego

Copy link
Copy Markdown
Contributor Author

CI problems seem to be also present upstream, investigating. Otherwise this PR is ready for review.

@ejgallego

Copy link
Copy Markdown
Contributor Author

CI problems seem to be also present upstream, investigating. Otherwise this PR is ready for review.

Fixed by #223

@kim-em , let me know if this PR works for you, then I think we can merge.

Comment thread lakefile.lean Outdated
Comment on lines +170 to +173
-- Keep the old and modern facet implementations separate: their Lake job/trace APIs differ enough
-- that factoring the full body would force more compatibility shims. The setup-file behavior is
-- factored only at the argument level, where it does not expose old and modern Lake APIs to each
-- other.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't make much sense to me. Can you please clarify a bit?

The existing split is due to a change in Lake's bind, not a change introduced here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is indeed bad and belongs to a previous version of this PR. Fixed, thanks.

Comment thread Tests.lean Outdated
| _ => none

/--
Whether this toolchain can run the FFI regression for the highlighted facet's Lake setup-file path.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we version-gate here but feature-gate elsewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks!

@ejgallego
ejgallego force-pushed the codex/highlighted-lake-setup branch from af2adcc to 8ad177f Compare August 3, 2026 08:25
Comment thread ffi-tests/ffi.c
Comment on lines +3 to +9
#if defined(_WIN32)
#define SUBVERSO_FFI_EXPORT __declspec(dllexport)
#elif defined(__GNUC__) || defined(__clang__)
#define SUBVERSO_FFI_EXPORT __attribute__((visibility("default")))
#else
#define SUBVERSO_FFI_EXPORT
#endif

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this macro?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! This is necessary for cross-platform compat, but the LEAN_EXPORT macro does exactly this, when -DLEAN_EXPORTING is setup. Will amend.

Comment thread lakefile.lean
Comment on lines +17 to +18
-- Feature-probe Lake's setup-file support instead of version-gating it, so older Lake keeps the
-- original extractor CLI while newer Lake passes the module setup file it already computes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads like an LLM justifying a change it made during a session, rather than as a useful comment to help future readers understand the code. What about:

Suggested change
-- Feature-probe Lake's setup-file support instead of version-gating it, so older Lake keeps the
-- original extractor CLI while newer Lake passes the module setup file it already computes.
-- Checks whether the current toolchain supports setup files. If not, adding them is a no-op.

But perhaps it should be an error if not supported, so that users get more helpful messages?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will amend. I'd say we can keep the no-op, explicitly passing --setup to an unsupported extractor already produces an error through the compatibility fallback IIANM.

Comment thread Tests.lean
Comment on lines +347 to +348
-- The fixture's `lp_ffi_answer` symbol uses package-aware module names, so probe the corresponding
-- setup features rather than inferring them from the Lean version.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also reads like an LLM changing course during development. What are package-aware module names? The comment itself really doesn't help me understand the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"package-aware" names refers to the change in Lean 4.27; prior to Lean 4.27, a declaration named answer was looked up under the global native symbol l_answer. Newer Lean records the package ID from lake setup file. For package ffi, the same declaration becomes lp_ffi_answer.

I think the best fix here is to restrict this test to Lean >= 4.27 . If we'd like to test 4.25/4.26 we can add a new fixture.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking into this in more detail, there is something about how #eval resolves native symbols which I still don't understand.

Comment thread Tests.lean
-- artifacts or a previously-generated dependency source — those are managed below / kept warm.
copyRecursively project buildDir
(fun f => f != ".lake" && f != "no-mod" && f != "lake-manifest.json")
-- The prepared copy must run under the matrix/fixed toolchain, not under a fixture's checked-in

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a bit on what this means?

@ejgallego ejgallego Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was ensuring the correct toolchain was selected for the test and not rewritten by lake. After review, I think the best is to eliminate the FFI special path and have it as an standard test. Will amend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants