Skip to content

chore: move constructor invocations to Lean - #18

Merged
acmepjz merged 3 commits into
acmepjz:mainfrom
david-christiansen:ctors
Jun 22, 2026
Merged

chore: move constructor invocations to Lean#18
acmepjz merged 3 commits into
acmepjz:mainfrom
david-christiansen:ctors

Conversation

@david-christiansen

@david-christiansen david-christiansen commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Lean PR #13679 will reduce the guarantees provided by the compiler for constructor representation, allowing more freedom. This means that C code will need to invoke/destructure constructors via externed Lean declarations instead.

This PR implements the required changes. There shouldn't be any backwards compatibility issues with this.

To ensure that the changes work, this PR also adds recent releases to CI, inluding a Windows and a Mac build. Because Windows builds revealed important differences in the linker, the PR also restructures the Lakefile to build one big shared library with the C and Lean parts together, rather than separate shared libraries that are loaded at the same time. This is because Windows resolves symbols in a DLL at link time, rather than at load time. Additionally, missing initializers were added to the FFI wrapper, fixing an intermittent bug.

@david-christiansen
david-christiansen force-pushed the ctors branch 2 times, most recently from 73e2ae1 to 6986723 Compare June 17, 2026 08:30
Lean PR #13679 will reduce the guarantees provided by the compiler for
constructor representation, allowing more freedom. This means that C
code will need to invoke/destructure constructors via externed Lean
declarations instead.

This PR implements the required changes. There shouldn't be any
backwards compatibility issues with this.

To ensure that the changes work, this PR also adds recent releases to
CI, inluding a Windows build. Because Windows builds revealed
important differences in the linker, the PR also restructures the
Lakefile to build one big shared library with the C and Lean parts
together, rather than separate shared libraries that are loaded at the
same time. This is because Windows resolves symbols in a DLL at link
time, rather than at load time. Additionally, missing initializers
were added to the FFI wrapper, fixing an intermittent bug.

@acmepjz acmepjz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you!

Is this final version and is ready for deploy?

Comment thread MD4Lean/FFI.lean Outdated
Comment thread MD4Lean/FFI.lean Outdated
Comment thread MD4Lean/FFI.lean
Comment on lines +66 to +67
@[export lean_md4c_some_document] def someDocument (d : Document) : Option Document := some d
@[export lean_md4c_some_string] def someString (s : String) : Option String := some s

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Do you think it's possible to export Option.some (type polymorphic version)? Or these two has different ABIs?

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.

They should be the same. Would you prefer a polymorphic version?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Would you prefer a polymorphic version?

Yes, sure.

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 was wrong - the exported polymorphic version include a slot for the type argument, which is not pleasant C code.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I was wrong - the exported polymorphic version include a slot for the type argument, which is not pleasant C code.

OK that's new to me. I originally thought that type argument does not appear in the compiled C code.

Co-authored-by: Jz Pan <acme_pjz@hotmail.com>
@david-christiansen

Copy link
Copy Markdown
Contributor Author

Once you're happy with this code, I see no reason not to squash-merge it. Or I can squash the PR branch myself, if you'd like.

@acmepjz

acmepjz commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Once you're happy with this code, I see no reason not to squash-merge it. Or I can squash the PR branch myself, if you'd like.

I see. I can do the squash-merge by myself.

@david-christiansen

Copy link
Copy Markdown
Contributor Author

OK then, I think it's ready to go. Thanks!

@acmepjz
acmepjz merged commit 31907cc into acmepjz:main Jun 22, 2026
12 checks passed
@acmepjz

acmepjz commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Thanks!

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