@@ -18,73 +18,162 @@ DRAFT
1818# Summary
1919
2020This proposal aims to improve the import management system in Leo programs to
21- make program environment more reproducible and predictable . To achieve that
22- we suggest few changes to Leo CLI and Manifest:
21+ make program environment more reproducible, predictable and compatible . To achieve
22+ that we suggest few changes to Leo CLI and Manifest:
2323
2424- add a "dependencies" section to Leo Manifest and add a command to pull those dependencies;
2525- allow custom names for imports to manually resolve name conflicts;
26- - store imports as they are called in Leo Manifest;
26+ - add "curve" and "proving system" sections to the Manifest;
27+ - add "include" and "exclude" parameters for "proving system" and "curve";
2728
2829Later this solution can be improved by adding a lock-file which would lock
2930imported packages based on both their contents and version.
3031
3132# Motivation
3233
33- What problems does it solve? What is the background?
34+ The current design of imports does not provide any guarantees on what's stored
35+ in program imports and published with the program to Aleo Package Manager.
36+ When a dependency is "added," it is stored inside imports folder, and it is possible
37+ to manually edit and/or add packages in this folder.
3438
35- Current state:
36- - imports are published with a program to Aleo PM;
37- - we treat programs as files with no verification of imports (they can be changed locally and published in that state);
38- - name collisions cannot be resolved; a new import overwrites existing;
39+ Also, imports are stored under the package name which makes it impossible to import
40+ two different packages with the same name.
3941
40- TBD
42+ Another important detail in the scope of this proposal is that in future Leo
43+ programs will have the ability to be run with different proving systems
44+ and curves, possibly creating incompatibility between programs written
45+ for different proving systems or curves. To make a foundation for these features,
46+ imports need to be managed with include/exclude lists for allowed (compatible)
47+ proving systems and curves.
4148
4249# Design
4350
44- ## Leo Manifest
51+ ## Leo Manifest - target section
52+
53+ To lay the foundation for the future of the Leo ecosystem and start integrating
54+ information about programs compatibility we suggest adding two new fields to
55+ the new ` [target] ` section of the Leo Manifest: ` proving_system ` and ` curve ` .
56+
57+ Currently, the Leo compiler only supports ` Groth16 ` for the proving system and ` Bls12_377 `
58+ for the curve, they are meant to be default values in Leo Manifest.
59+
60+ ``` toml
61+ [project ]
62+ name = " first"
63+ version = " 0.1.0"
64+ description = " The first package"
65+ license = " MIT"
66+
67+ [target ]
68+ curve = " Bls12_377"
69+ proving_system = " Groth16"
70+ ```
71+
72+ These fields are meant to be used to determine whether imported program is
73+ compatible to the original when support for different curves and proving systems
74+ is added.
75+
76+ ## Leo Manifest - dependencies
4577
4678Dependencies section:
4779
4880``` toml
4981[dependencies ]
5082name = { author = " author" , package = " package" , version = " version" }
5183
84+ # alternative way of adding dependency record
5285[dependencies .name ]
5386author = " author"
5487package = " package"
5588version = " 1.0"
5689```
5790
58- TBD
91+ ### Parameters description
92+
93+ ` name ` field sets the name of the dependency in Leo code. That way we allow
94+ developer to resolve collisions in import names manually. So, for example,
95+ if a developer is adding ` howard/silly-sudoku ` package to his program, he
96+ might define its in-code name as ` sudoku ` and import it with that name:
97+
98+ ``` ts
99+ import sudoku ;
100+ ` ` `
101+
102+ ` package ` , ` author ` and ` version ` are package name, package author and
103+ version respectively. They are already used as arguments in ` leo add `
104+ command, so these fields are already understood by the Leo developers.
59105
60106## Leo CLI
61107
62108To support updated Manifest new command should be added to Leo CLI.
63109
64110` ` ` bash
65111# pull imports
66- leo pull
112+ leo install
113+ ` ` `
114+
115+ Alternatively it can be called ` pull ` .
116+ ` ` `
117+ leo pull
67118` ` `
68119
69120## Imports Restructurization
70121
71122One of the goals of proposed changes is to allow importing packages with the
72- same name but different authors. To resolve name conflict we suggest storing
73- imports as they are named in Leo Manifest file (Leo.toml).
123+ same name but different authors. This has to be solved not only on the
124+ language level but also on the level of storing program imports.
125+
126+ We suggest using set of all 3 possible program identifiers for import
127+ folder name: ` author -package @version ` . Later it can be extended to
128+ include hash for version, but having the inital set already solves name
129+ collisions.
130+
131+ So, updated imports would look like:
132+
133+ ` ` `
134+ leo -program
135+ ├── Leo .toml
136+ ├── README .md
137+ ├── imports
138+ │ ├── author1 -program @0.1.0
139+ │ │ └── ...
140+ │ ├── author2 -program2 @1.0.4
141+ │ └── ...
142+ ├── inputs
143+ │ └── ...
144+ └── src
145+ └── main .leo
146+ ` ` `
147+
148+ This change would also affect the way imports are being processed on the ASG
149+ level, and we'd need to add an imports map as an argument to the Leo compiler.
150+ The Leo Manifest's dependencies sections needs to be parsed and passed as
151+ a hashmap to the compiler:
152+
153+ ` ` `
154+ first -program => author1 -program @0.1.0
155+ second -program => author2 -program2 @1.0.4
156+ ` ` `
74157
158+ ## Recursive Dependencies
75159
76- <!-- The suggested change is soft. It changes only the way imports are organized
77- with minimal changes to other parts of the language.
160+ This improvement introduces recursive dependencies. To solve this case preemptively
161+ Leo CLI needs to check the dependency tree and throw an error when a recursive dependency
162+ is met. We suggest implementing simple dependency tree checking while fetching
163+ imports - if imported dependency is met on a higher level - abort the execution.
78164
79- We can consider implementing imports/username-package storage, but imports
80- will have to be resolved on a different level in compiler. -->
165+ Later this solution can be improved by building a lock file containing all the
166+ information on program dependencies, and the file itself will have enough data
167+ to track and prevent recursion.
81168
82169# Drawbacks
83170
84171This change might require the update of already published programs on Aleo PM due to
85172Leo Manifest change. However it is possible to implement it in a backward-compatible
86173way.
87174
175+ It also introduces the danger of having recursive dependencies, this problem is addressed in the Design section above.
176+
88177# Effect on Ecosystem
89178
90179Proposed improvement provides safety inside Leo programs and should not affect
0 commit comments