Skip to content

Split early import loading semantics - #214

Open
rTreutlein wants to merge 7 commits into
mainfrom
agent/split-early-import-semantics
Open

Split early import loading semantics#214
rTreutlein wants to merge 7 commits into
mainfrom
agent/split-early-import-semantics

Conversation

@rTreutlein

Copy link
Copy Markdown
Collaborator

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:

  1. 0a0e4d0 — Resolve relative imports from the importing file
  2. 237a090 — Surface MeTTa import errors
  3. 3294517 — Make imports idempotent and cycle-safe
  4. aba3433 — Surface git import failures
  5. 3f43640 — Warn when a function arrives after being compiled as a symbol

Behavior

  • Resolve nested relative MeTTa and Python imports from the importing file.
  • Propagate missing, malformed, Python, and git import failures instead of silently swallowing them.
  • Make imports idempotent and cycle-safe per target space.
  • Warn when a function definition arrives after that name was already compiled as a symbol.

Provenance and compatibility adaptations

Original authorship and commit ordering are preserved. The commits were replayed onto main at 43705f5d9ff8958ffe7f0aa6777fb8477f2401f2.

Current main changed library discovery after the original base. The replay therefore:

  • retains current main's standard_library_path/1 candidate for ordinary library lookup and its filtered library_path/1 candidate for two-part lookup, while applying the original commit's existing-source preference; and
  • declares the now-initially-empty library_path/1 dynamic so git imports can test and register their canonical checkout before the first path exists.

No commits after 3f43640 are included. PR #203 and import-overhaul were not modified.

Validation

  • UV_CACHE_DIR=/tmp/petta-uv-cache uv run pytest tests/test_imports.py (managed environment, from python/): 2 passed
  • UV_CACHE_DIR=/tmp/petta-uv-cache uv run pytest tests (managed environment, from python/): 9 passed
  • sh test.sh (managed environment): all examples passed
  • git diff --check 43705f5d9ff8958ffe7f0aa6777fb8477f2401f2..HEAD

rTreutlein and others added 5 commits July 29, 2026 20:00
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
rTreutlein marked this pull request as ready for review July 29, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant