-
Notifications
You must be signed in to change notification settings - Fork 173
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
Add miden-package
crate with Package
type to represent a compiled Miden program/library.
#1544
base: next
Are you sure you want to change the base?
Conversation
miden-package
crate with Package
type to represent a compiled Miden program/library.miden-package
crate with Package
type to represent a compiled Miden program/library.
76a4b7e
to
9ff342e
Compare
9ff342e
to
7c9b95b
Compare
1ca8581
to
3581727
Compare
41b5f5d
to
c5ff6f0
Compare
211f34c
to
84ea102
Compare
miden-package
crate with Package
type to represent a compiled Miden program/library.miden-package
crate with Package
type to represent a compiled Miden program/library.
eda4a01
to
006e03a
Compare
5ec902e
to
d6419ca
Compare
006e03a
to
92f3309
Compare
Co-authored-by: Philippe Laferrière <plafer@protonmail.com>
Co-authored-by: Philippe Laferrière <plafer@protonmail.com>
Co-authored-by: Philippe Laferrière <plafer@protonmail.com>
Co-authored-by: Philippe Laferrière <plafer@protonmail.com>
Co-authored-by: Philippe Laferrière <plafer@protonmail.com>
Co-authored-by: Philippe Laferrière <plafer@protonmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you! I left some comments inline. The main ones are about:
- Potentially adding some validation to library path deserialization.
- Using
Serializable
/Deserializable
instead ofserde
. - Not including functionality that assumes downstream crates (i.e.,
miden-base
).
@@ -0,0 +1,31 @@ | |||
[package] | |||
name = "miden-package" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should make it a bit more specific. Maybe miden-vm-package
or miden-code-package
(though, not sure if I like these better than just miden-package
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got so much used to miden-package
so I'm biased here. :) In general, if we plan to have another "packages" (account?) giving it a more specific name makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about miden-mast-package
here? I would also maybe expand the description a little bit to make it more specific.
@bobbinth @plafer Thank you for the review! I've addressed all notes, implemented easy ones, and I am converting this PR to draft to work on:
|
instead of `bitcode` and `serde`
Implement `Serializable/Deserializable` and `Arbitrary`(proptest) for `QualifiedProcedureName`. Add serialization roundtrip tests for `LibraryPath` and `ProcedureName`.
915c093
to
a93f3a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you! I left some more comments/questions inline.
Besides these, I think the main thing remaining here is potentially adding some validation to library path deserialization - right?
package/src/package.rs
Outdated
pub struct Package { | ||
/// Name of the package | ||
pub name: String, | ||
/// The MAST artifact ([Program] or [Library]) of the package | ||
pub mast: MastArtifact, | ||
/// The package manifest, containing the set of exported procedures and their signatures, | ||
/// if known. | ||
pub manifest: PackageManifest, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not for this PR, but where would we put custom metadata? Here, I'm thinking about the storage layout metadata we'd need to instantiate account components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking, either directly in Package
or in PackageManifest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create an issue for this.
constructors in deserialization.
223c95f
to
37fe048
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Looks good! I left some more comments inline - most are pretty minor.
Library::read_from(source).map(Arc::new).map(MastArtifact::Library) | ||
} else { | ||
Err(DeserializationError::InvalidValue(format!( | ||
"Invalid MAST artifact tag: {:?}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we usually don't capitalize error the first letter of error messages (i.e., "Invalid" -> "invalid").
/// A procedure exported by a package, along with its digest and | ||
/// signature(will be added after MASM type attributes are implemented). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: there should be a space after "signature". Also, we usually do newlines after about 100 chars. So, this comment should look like:
/// A procedure exported by a package, along with its digest and signature (will be added after
/// MASM type attributes are implemented).
#[cfg(test)] | ||
extern crate std; | ||
|
||
pub use vm_core::{chiplets::hasher::Digest, mast::MastForest, Program}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also re-export Library
, QualifiedProcedureName
, LibraryPath
, and maybe ProcedureName
as they are also used in the public interface (these would come from the assembly crate though).
Some((_, c)) | ||
if c.is_ascii_lowercase() || c == '_' || c == '-' || c == '$' || c == '.' => | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR, but the code in this function is a bit difficult to follow. Let's create an issue (could be a "good first issue") to make the code more readable.
@@ -505,7 +505,23 @@ impl Deserializable for LibraryPath { | |||
let path = source.read_slice(len)?; | |||
let path = | |||
str::from_utf8(path).map_err(|e| DeserializationError::InvalidValue(e.to_string()))?; | |||
Self::new(path).map_err(|e| DeserializationError::InvalidValue(e.to_string())) | |||
LibraryPath::new(path).or_else(|_| { | |||
// Try to parse at least the namespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we expand the comment a bit here to explain what the code below is intending to cover? My understanding is:
If path
is not a valid LibraryPath
, we try to take the first "leg" of the path and use it as a namespace and the rest of the string as the module name. And if there is no first "leg", then we use Anon
namespace and try to use the whole path
as the module name.
If the above is correct, it is not clear to me what exactly we are trying to enable here. It seems like maybe we want to make sure that a path with no namespaces get Anon
namespace? If so, could we simplify the code as:
LibraryPath::new(path).or_else(|_| {
let module_id = Ident::new(path).map_err(|e| {
DeserializationError::InvalidValue(format!("Invalid module id: {}", e))
})?;
Ok(LibraryPath::new_from_components(LibraryNamespace::Anon, [module_id]))
}
version = "0.11.0" | ||
description = "Miden VM package" | ||
documentation = "https://docs.rs/miden-package/0.11.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's increment the versions to v0.12.0.
@@ -0,0 +1,31 @@ | |||
[package] | |||
name = "miden-package" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about miden-mast-package
here? I would also maybe expand the description a little bit to make it more specific.
Let's also resolve the merge conflicts. |
This PR adds
miden-package
crate withPackage
type ported from the compiler's ad-hoc implementation to represent a compiled Miden program/library.Please consider reviewing this PR commit-by-commit. I crafted the commits to be focused on a single change and show the evolution of the implementation.
The reasons for the new crate are explained in 0xPolygonMiden/compiler#376
The compiler's PR that uses
miden-package
from this PR is 0xPolygonMiden/compiler#349TODO: