-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Final steps of using the specialize keyword in compiled programs #775
Draft
adamssonj
wants to merge
23
commits into
miking-lang:develop
Choose a base branch
from
adamssonj:pevalDynlink
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adamssonj
force-pushed
the
pevalDynlink
branch
from
November 29, 2023 19:58
00d0359
to
2980681
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for specializing in compiled programs by adding the "JIT" compilation of the residual expression, the missing step as previously mentioned in #749. The jitting is based on Lars' sketch of dynamic linking, https://github.com/larshum/miking/tree/jit/demo.
Overview
The specialize keyword is compiled as:
specialize expr
→jitCompile (peval (liftExpr expr))
where this PR contains the implementation ofjitCompile
(defined in peval/jit.mc) that is broken down into the main steps of:src/boot/lib/inter.ml
and compiling that filea. When dynamically loaded, the plugin registers itself using
src/boot/lib/inter.ml
Steps 1 and 2 are performed in
stdlib/ocaml/mcore.mc -> compileMCorePlugin
. Steps 3 and 4 are defined using intrinsicsExplanation of some specifics
Note that the residual expression (produces by peval) may contain definitions of the main program, so the plugin we dynlink in may contain references to things that are only defined in the main program. So to support this a couple of things was done:
a. A
program.ml
file that contains the usual compiled program except that the last expression of the program is let-bound to a 'main' entrypoint, and amain.ml
file that simply calls the main entrypoint.b. This split was required to ensure that the
program.ml
module is "loaded" before dynlinking happens (OCaml specific problem with Dynlink module)a. This is the reason for the "nameMap" addition to the compiler hooks
Some caveats:
mi compile a.mc && mi compile b.mc && ./a
will not work if a.mc and b.mc contain the specialize keywordprogram.ml
module has been initialized. A possible solution to this may be to segment the program module into several modules based on the location of specialize terms, and that the residuals then only depends on the modules "above" it in the program.