Split early import loading semantics - #214
Open
rTreutlein wants to merge 7 commits into
Open
Conversation
Imports used to resolve against a single global working_dir set once at startup, so a file imported from another directory could not find its own relative dependencies. load_metta_file now maintains a stack of working directories (pushed on entry, popped via setup_call_cleanup), making both MeTTa and Python imports resolve relative to the file that declares them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
import! previously swallowed every failure via catch(_, fail), so a missing file, a syntax error in a dependency, or a failing Python module import all passed silently. Imports now resolve their target to a canonical path and throw existence_error when it is missing; errors from loading a dependency propagate wrapped with the offending filename. Since a throwing import! no longer fails into backtracking, library/2 now prefers the candidate whose source file actually exists instead of relying on backtracking across registered library paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Importing the same file twice into the same space re-asserted all of its clauses, and two files importing each other recursed until the stack blew. import! now tracks per-space load state keyed by the canonical file path: a loaded entry turns repeated imports into no-ops, a loading entry breaks cycles, and failed loads clear their entry so the source can be repaired and the import retried within the same session. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
git-import! piped clone and build output into discarded strings and never checked the exit status, so a failed clone or build step passed silently and left the import broken. Both steps now inherit the caller's stdio and throw process_error on a nonzero exit. The repository path is registered canonicalized and only once, also removing a stray debug print. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Definitions compile expression heads that are not registered functions into plain symbols, so a function imported or defined after its first use is silently never called by the already-compiled expressions. The translator now records atoms it compiles as symbol heads, and registering a function whose name was already compiled that way prints a warning telling the user to move the import or definition above the first use. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
rTreutlein
marked this pull request as ready for review
July 29, 2026 22:50
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.
Summary
This draft splits the first coherent import-loading changes from #203 into an independent review based on current
main.It replays exactly these original commits, in order:
0a0e4d0— Resolve relative imports from the importing file237a090— Surface MeTTa import errors3294517— Make imports idempotent and cycle-safeaba3433— Surface git import failures3f43640— Warn when a function arrives after being compiled as a symbolBehavior
Provenance and compatibility adaptations
Original authorship and commit ordering are preserved. The commits were replayed onto
mainat43705f5d9ff8958ffe7f0aa6777fb8477f2401f2.Current
mainchanged library discovery after the original base. The replay therefore:standard_library_path/1candidate for ordinary library lookup and its filteredlibrary_path/1candidate for two-part lookup, while applying the original commit's existing-source preference; andlibrary_path/1dynamic so git imports can test and register their canonical checkout before the first path exists.No commits after
3f43640are included. PR #203 andimport-overhaulwere not modified.Validation
UV_CACHE_DIR=/tmp/petta-uv-cache uv run pytest tests/test_imports.py(managed environment, frompython/): 2 passedUV_CACHE_DIR=/tmp/petta-uv-cache uv run pytest tests(managed environment, frompython/): 9 passedsh test.sh(managed environment): all examples passedgit diff --check 43705f5d9ff8958ffe7f0aa6777fb8477f2401f2..HEAD