Rewrite and complete the Kaleidoscope tutorial samples (Ch3-8, ORC LLJIT) - #260
Merged
tannergooding merged 4 commits intoJul 15, 2026
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
tannergooding
force-pushed
the
tannergooding-kaleidoscope-samples-triage
branch
from
July 15, 2026 18:38
e5e561d to
066bd73
Compare
This was referenced Jul 15, 2026
This file contains hidden or 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
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.
The Kaleidoscope samples were built against the abandoned
LLVMSharp5.0.0 NuGet package (LLVM 5, 2017), not the in-repo library, so the API they called (LLVM.BuildCall, the legacyLLVMAdd*Passfunction pass manager, MCJIT) was gone or reshaped in21.x-- and the projects wereOutputType=Librarywith aMain, so they didn''t even run.Rather than patch the three dead chapters, this rewrites
samples/KaleidoscopeTutorialon the in-repoLLVMSharp.Interop, ports the tutorial through Chapter 8, moves the JIT to ORC LLJIT, and restructures so the invariant frontend lives in a sharedKaleidoscope.Commonlibrary and each chapter contains only its delta over the previous one. Builds with 0 warnings (TreatWarningsAsErrors/Nullableon) and every chapter is smoke-tested end to end.Structure
Kaleidoscope.Common-- lexer, token, full AST, baseParser+ baseCodeGenVisitor, the ORC LLJIT wrapper, the REPL loop, host functions, support helpers.Chapter3emit IR (dump only);Chapter4ORC LLJIT + new pass manager;Chapter5if/for;Chapter6user-defined operators;Chapter7mutable variables (alloca + mem2reg);Chapter8native object-file emission.Each chapter''s
Parser/CodeGenVisitorderive from the previous chapter''s and override only the new productions;Chapter{N}referencesChapter{N-1}, so the incremental steps are visible instead of copied.What it fixes
LLVM.RunPasses(module, "function(mem2reg,instcombine,reassociate,gvn,simplifycfg)", tm, opts).GetNamedFunction->BuildCall2(GlobalGetValueType(fn), fn, args). The old code also sized the arg/param arrays withMath.Max(count, 1), so a zero-arg call passed a one-element array holding a null ref -- invalid IR and an access violation inVerifyFunction; now sized exactly.foo(2,3)=25,foo(4,5)=81) instead of MCJIT re-running the first one''s code.extern sin(x)resolves from the host C runtime via the ORC process-symbol generator; no mapping needed for libc symbols.putchard/printdinjected as ORC absolute symbols backed by[UnmanagedCallersOnly]cdecl methods;printstar(5)prints*****.Verified (Release): Ch4
foo(2,3)=25/foo(4,5)=81,extern sinresolves,4+5folds; Ch5printstar(5)prints*****,if 1<2 then 10 else 20-> 10; Ch6!0=1/!1=0; Ch7test(3)=8, iterative mutablefibi(10)=55; Ch8 emits a valid COFF x64 object exportingdouble average(double, double).Out of scope: tutorial Chapter 9 (debug info / DWARF via
DIBuilder) and Chapter 10. The samples are intentionally not part of the rootLLVMSharp.slnx; aKaleidoscopeTutorial.slnxand aREADME.mddescribing the structure and chapter mapping are included.