fix(api): tighten public surface before the 1.0 freeze#380
Merged
Conversation
Fix the API sharp edges that would become breaking changes once 1.0 freezes the surface: bare struct encoding now raises a helpful error (keeping the planned Lua.Encoder protocol additive), the dead is_mfa/1 compat guard is removed, :max_string_bytes accepts :infinity uniform with its siblings, eval!/3 accepts :source on the chunk clause, and the never-populated CompilerException :state field is dropped. Also documents closure/tag-tuple internals as unstable and reframes Lua.VM as internal. Plan: A50
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.
API pre-freeze fixes: struct encoding, dead guard, option consistency
Plan:
.agents/plans/A50-api-pre-freeze.mdThese are the public-API sharp edges that would become breaking changes once 1.0 freezes the surface. Each must land before the freeze so the fix isn't a breaking change later.
Changes
lib/lua/vm/value.ex). Structs are maps, soLua.encode!(lua, %MyStruct{})(andLua.set!/3) silently encoded a Lua table carrying a"__struct__"key. A new%mod{}clause (before theis_mapclause) raisesLua.RuntimeExceptionwith a message pointing atMap.from_struct/1and noting the plannedLua.Encoderprotocol (Ergonomic encode/decode for deflua (Lua.Encoder protocol + auto-marshalling) #341). Why before freeze: if struct encoding "works" accidentally today, adding the protocol in 1.1 becomes breaking instead of additive. Audit found no struct legitimately encoded inlib/ortest/today.is_mfa/1guard (lib/lua/api.ex). A Luerl-era shim that always returnedfalse, imported into everyuse Lua.APImodule. Removed the guard and the import entry; cleaned up the only other references (comments in a skipped test). Why before freeze: removing an exported guard after freeze is breaking.is_lua_func/1,is_erl_func/1, andLua.unwrap/1now carry warnings that the:lua_closure/:compiled_closure/:native_func/:treftuple internals are not stable API; use the guards. No tags were restructured.:max_string_bytesaccepts:infinity(lib/lua.ex,lib/lua/vm/state.ex,lib/lua/vm/limits.ex), uniform with:max_call_depthand:max_instructions. Enforcement is already:infinity-safe via Erlang term ordering (every number sorts below every atom); documented at the check site.eval!/3chunk clause accepts:source(lib/lua.ex). The string clause validated[decode:, source:]but the chunk clause only[decode:], soeval!(lua, chunk, source: "x")raised viaKeyword.validate!. The chunk already carries its compiled-in source name, so:sourceis accepted but ignored (documented).call_function/3's error shape — added doctests showing{:error, reason, lua}wherereasonis the raw Lua-facing pcall error value (non-string values pass through verbatim; strings carry thesource:line:prefix), distinct from the terminal-formattedcall_function!/3.Lua.CompilerException's:statefield — it was never populated (alwaysnil). Moduledoc field list updated.Lua.VMmoduledoc from "Public API" to internal (kept readable for source/IEx readers); noted:reset_instructionsis require-reentrancy machinery, not user API.Verification
Out of scope (intentional)
Lua.Encoderprotocol itself (1.1, Ergonomic encode/decode for deflua (Lua.Encoder protocol + auto-marshalling) #341).Plan: A50