Skip to content

Add imports with namespacing, pub/use, and C3 linearization #155

@KyrylR

Description

@KyrylR

Project

compiler

Describe the feature

Reasoning

The main reasoning is to enable an analogue of the OpenZeppelin library to exist in the SimplicityHL ecosystem.

The idea is that the code will be distributed via crates.io and will allow developers to speed up the development of applications.

Primarily, it will significantly increase code reusability. If a project is heavily focused on security, it will be able to “flatten” the code and use all the functions without external dependencies.

Semantics

  • Visibility:
    • pub fn makes a function importable from other files; fn is file-private.
    • pub use re-exports imported symbols; use only brings them into the local scope.
    • pub type exports a type alias (optional but included for consistency).
  • use forms:
    • use m::name;, use m::name as alias;, use m::{a, b as c};, use m::*;
    • pub use m::{a, b as c};, pub use m::*; (re-export)
  • Merging with C3 linearization when resolving pub use ...::* across a graph of re-exports. First wins according to the MRO; conflicts require explicit aliasing.
  • Conflicts:
    • A local use * that causes a collision → error unless explicitly aliased.
    • Re-export collisions are resolved by C3 order; later entries are ignored unless aliased.
  • Path resolution: relative to the importing file’s directory, then search -I directories in CLI order; append .simf if missing.
  • Running: Only files defining a zero-arg unit fn main are runnable. Libraries (no main) are accepted under --check; attempting to run them results in an error.

Overall, this feature can be delivered in milestones, so we can gradually add support.

Even though the StarkWare team introduced macros, in the long term it is much more beneficial to have official compiler support for imports. It can already be seen that their compiler version is outdated.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions