Skip to content

Overhaul import loading semantics - #201

Closed
rTreutlein wants to merge 5 commits into
mainfrom
import-overhaul
Closed

rTreutlein wants to merge 5 commits into
mainfrom
import-overhaul

Conversation

@rTreutlein

@rTreutlein rTreutlein commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Overhaul file imports by combining the strongest parts of the existing import PRs into one coherent loader:

  • propagate errors from imported MeTTa and Python files;
  • recursively pre-register imported function signatures so import order does not affect compilation;
  • resolve nested relative imports from the importing file;
  • canonicalize import paths;
  • make imports idempotent per target space;
  • terminate cyclic imports using explicit loading and loaded states;
  • clear failed import state so a repaired source can be retried;
  • raise an explicit existence_error(source_sink, ...) for missing files;
  • move git-import! from lib_import into the core loader;
  • prepare core Git dependencies before signature discovery, then safely no-op when their normal runnable is encountered;
  • resolve library names to the first library root containing the requested source.

The signature prescan remains separate from normal module execution, so imported atoms, clauses, and top-level runnables are still processed normally. git-import! is the one core dependency primitive prepared before that scan because it can make later imports resolvable.

This consolidates ideas explored in #157, #159, #161, #171, #189, and #195. It addresses #154, #180, #181, and #196.

Validation

bash test.sh
# passed, including a cold clone in examples/git_import.metta
# and the network-free examples/git_import_core.metta regression

cd python
uv run pytest tests
# 4 passed

@patham9 patham9 added the Import label Jul 20, 2026
@rTreutlein

Copy link
Copy Markdown
Collaborator Author

Signature prescanning is causing more trouble than it's worth so i will be removing it and creating a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants