Make entry points optional - #35
Merged
Merged
Conversation
Previously a requested entry point that the source didn't define was a hard compile error. Now the backends skip undefined entry points and the client decides whether a missing one matters. - DeclTable::find_entry_point() is the single Option-returning lookup; monomorph, Cranelift, VM, stack, LLVM JIT and AOT all skip misses. - program.entry is the first entry point actually found; the VM/stack/asm run helpers early-return on an entry-less program. - Compiler gains found_entry_points()/missing_entry_points(); running still errors when nothing was found. - FFI entry-point slots are Option so indices stay aligned with the names passed to lyte_compiler_new when one is missing. New lyte_program_has_entry_point(); Swift entryPoint(named:/at:) returns nil for an undefined one. - The CLI is a client that requires them: it reports every missing entry point and exits 1 before compiling, AOT, or running. --check no longer needs an entry point. Also fixes --entry under the Cranelift JIT, which compiled and ran "main" regardless of the requested entry points. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KU75jHWHD6nzWZb5tau87e
find_entry_point only looked at find(name).first(), so a non-function decl
sharing the entry point's name (decls with equal names are ordered by source
position) shadowed the function: `var main: i32` above `main { ... }` reported
'main' as missing, and specialize() reported a bogus "Multiple overloads
found". Scan for the first Decl::Func instead, via a new
entry_point_overloads() iterator that monomorph_pass also uses for its
overload count.
The VM run guards tested functions.is_empty() as a proxy for "no entry point
was resolved", but `entry` defaults to 0, so a program with functions and an
unresolved entry would run function 0. Add has_entry() to VMProgram and
StackProgram checking that `entry` indexes a real function, and use it at all
four run sites. VM::run also re-zeroes globals and clears cancelled/trap
before the early return, per its documented contract.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KU75jHWHD6nzWZb5tau87e
collect_entries silently skipped undefined entry points, so a library caller of llvm_aot::compile_aot that misspelled an entry name got a successfully written .o + .h missing that symbol, surfacing only as an undefined-symbol error in the host's link. The CLI pre-checks with require_entry_points, but the public API shouldn't depend on that. AOT's entry point list is the object's export list, so an undefined one is now an error, reported before any file is written. found_entry_points/missing_entry_points were documented "only meaningful after check()" with nothing enforcing it: called earlier (easy for an FFI embedder, since lyte_compiler_compile is the only thing that runs check()), self.decls is empty and every entry point looks missing. Answer from the AST instead, which check() copies into self.decls wholesale, so the result is the same after check() and correct before it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KU75jHWHD6nzWZb5tau87e
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.
Previously a requested entry point that the source didn't define was a hard compile error. Now the backends skip undefined entry points, and the client decides whether a missing one is a problem.
Compiler / backends
DeclTable::find_entry_point()is the singleOption-returning lookup. The monomorph pass, Cranelift JIT, VM codegen, stack codegen, LLVM JIT, and LLVM AOT all skip entry points that aren't defined — only the ones found are compiled and show up inprogram.entry_points(or the JIT's name→ptr map).program.entryis now the first entry point that was actually found, instead of hard-requiringentry_points[0].run_vm/run_stack/jit()/LLVMcompile_and_runerror withentry point function 'x' not found, and the VM/stack/asmrunhelpers early-return on an entry-less program rather than indexing an empty function table.Client-facing API
Compiler::found_entry_points()/missing_entry_points().Option, so indices stay aligned with the names passed tolyte_compiler_newwhen one is missing (before, the list would silently shift). Newlyte_program_has_entry_point(program, index);lyte_entry_point_callreturns false for an undefined one; Swift'sProgram.entryPoint(named:/at:)returns nil.no_main.lytestill printsentry point function 'main' not found).--checkno longer needs an entry point at all.Side effects
--entry foopreviously compiled and ranmainregardless under the Cranelift JIT (Compiler::jit()hardcoded "main"); it now runs the first defined requested entry point. New golden testtests/cases/custom_entry.lytecovers this across all four backends.CLyte.xcframeworkrelease is published, sincePackage.swiftpulls the 0.34 binary artifact.Testing
cargo test --workspacepasses (354 lib + 4 golden-backend + 21 LSP tests).cargo checkis clean with--features llvm,--no-default-features, and--all-targets.🤖 Generated with Claude Code
https://claude.ai/code/session_01KU75jHWHD6nzWZb5tau87e
Fixes #34