Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support importing local and remote programs. #2881

Merged
merged 121 commits into from
Jan 10, 2024
Merged

Conversation

evan-schott
Copy link
Contributor

@evan-schott evan-schott commented Oct 12, 2023

tldr

Motivation

  • We want a richer dependency resolution system in Leo. Leo users should be able to import programs from chain/local file system as opposed to requiring .leo source files.

Components:

  1. Specify import configurations in program.json
  2. leo build leverages retriever module to pull programs from network/FS
  3. Generate leo.lock file to house the dependency configuration
  4. disassembler.rs to convert Aleo instructions into valid stub
  5. Type checking modification to maintain soundness
  6. Codegen modification to print nested imports properly

Retriever Design

Modifications to ~/.aleo file structure

  • .aleo/registry:

    • .aleo/registry/git : Where .aleo files from github.com are stored
    • .aleo/registry/testnet3: Where .aleo files from the network are stored
    • Note that new folders can be added for different networks like ./mainnet
  • Suppose building leo project dex and call leo build with dex/program.json set to:

{
  "program": "dex.aleo",
  "version": "0.0.0",
  "description": "",
  "license": "MIT",
  "dependencies": [
    {
	  "name": "credits.aleo",
	  "location": "network",
		"network": "testnet3"
    },
	{
		"name": "foo.aleo",
		"location": "git",
		"url": "https://github.com/alice/foo.git"
		"branch": "bar"
		"rev": "3ab873bd89de"
		},
    {
	  "name": "board.aleo",
	  "location": "local",
	  "path": "../board", 
    },
  ]
}

Specification and example flow

  1. Retrieve imports based on configurations specified in dex/program.json:
    • Must keep track of nested programs trying to build, and throw error for circular dependencies
    • Location variations:
    • "location": "network":
      • Check if credits.aleo cached already in ~/.aleo/registry/testnet3/credits.aleo
      • Retrieve from network:
        • Store copy in `~/.aleo/registry/testnet3/credits.aleo``
        • Update leo.lock
    • "location": "local":
      • Recursively build the directory (must read its program.json to see its dependencies)
      • Cache in .aleo and update leo.lock
    • "location": "git": TODO
      • Example: "url": "<https://github.com/alice/foo.git>"
      • Check if board.aleo cached already as ~/.aleo/registry/git/pranav/foo/board.aleo
      • Otherwise retrieve from network and cache
      • Allow them to specify based on commit + branch
  2. Move a copy of the retrieved import(s) into dex/build/imports/
  3. Convert all imported programs to AST before start parsing main.leo

compiler/ast/src/stub/function_stub.rs Outdated Show resolved Hide resolved
compiler/ast/src/stub/function_stub.rs Outdated Show resolved Hide resolved
compiler/parser/src/parser/file.rs Show resolved Hide resolved
compiler/parser/src/parser/file.rs Outdated Show resolved Hide resolved
compiler/parser/src/parser/type_.rs Show resolved Hide resolved
errors/src/errors/type_checker/type_checker_error.rs Outdated Show resolved Hide resolved
errors/src/errors/type_checker/type_checker_error.rs Outdated Show resolved Hide resolved
@evan-schott
Copy link
Contributor Author

I resolved the 2 file.rs changes (and comment.out as that error is a consequence of how I changed the parsing of program_ids in file.rs) as I will be reverting all of the file.rs` changes related to stubs (since we are not going to allow explicit specification of stubs) and keeping just those parser changes related to importing.

@d0cd d0cd changed the title [Draft] Support Aleo program stubs [Feature] Support importing local and remote programs. Jan 3, 2024
@evan-schott evan-schott requested a review from d0cd January 4, 2024 19:12
Copy link
Collaborator

@d0cd d0cd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Amazing work @evan-schott!

@d0cd d0cd merged commit 8cdab3b into testnet3 Jan 10, 2024
13 of 15 checks passed
@d0cd d0cd deleted the feat/stubs branch January 10, 2024 02:01
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.

3 participants