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

fix: use unchecked constructor for ProcedureName on Library deserialization #1554

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

greenhat
Copy link
Contributor

@greenhat greenhat commented Oct 30, 2024

Describe your changes

Following the conversation with @bitwalker the checked constructor fits only when parsing MASM code. The Miden package contains the export names crafted according to the Wasm CM naming scheme, i.e. namespace:package/interface@version#function.
Discovered in 0xPolygonMiden/compiler#347 when parsing the Miden package file of the basic wallet account code.
The test for the failing case added in #1544 in the Package deserialization test suite at

#[test]
fn basic_wallet_package_deserialization() {
// Test for the https://github.com/0xPolygonMiden/compiler/issues/347
// The included Miden package file is built at
// https://github.com/0xPolygonMiden/compiler/blob/6cd29e17b34c5abef7f6328c33af06f8bf203344/tests/integration/src/rust_masm_tests/rust_sdk.rs#L48-L63
let bytes = include_bytes!("../tests/data/basic_wallet.masp");
let package = Package::read_from_bytes(bytes).unwrap();
dbg!(&package.manifest);
assert_eq!(package.name, "basic_wallet");
}
.

Checklist before requesting a review

  • Repo forked and branch created from next according to naming convention.
  • Commit messages and codestyle follow conventions.
  • Relevant issues are linked in the PR description.
  • Tests added for new functionality.
  • Documentation/comments updated according to changes.

@bobbinth
Copy link
Contributor

Would it make sense to relax procedure naming rules to accomodate WASM CM format rather than making these types of exception? Or maybe we introduce another more relaxed constructor that is not fully "unchecked" but relaxed enough to handle WASM CM naming.

…ure names

The checked constructor fits when parsing MASM code.
The Miden package contains the export names crafted according to the Wasm CM naming scheme
i.e. `namespace:package/interface@version#function`.
Discovered in 0xPolygonMiden/compiler#347
when parsing the Miden package file of the basic wallet account code.
@greenhat greenhat force-pushed the greenhat/library-deser-uncheck-exports branch from 1ca8581 to 3581727 Compare November 4, 2024 17:37
@bitwalker
Copy link
Contributor

Would it make sense to relax procedure naming rules to accomodate WASM CM format rather than making these types of exception? Or maybe we introduce another more relaxed constructor that is not fully "unchecked" but relaxed enough to handle WASM CM naming.

The naming rules are pretty much already there, though bare identifiers in MASM source code are a little more restrictive, you can use quoted identifiers to represent pretty much any possible identifier.

PR looks good, the only change I would also like to make would be to fix the naming of ProcedureName::{new, new_unchecked} and Ident::{new, new_unchecked} (and I think there are also related LibraryPath/LibraryNamespace APIs as well), to make it clear that new_unchecked is what should be used internally for virtually everything. The new variants (and their stricter validation, only exist for the parsing frontend, as MASM syntax requires bare identifiers of various kinds to be validated more strictly, but quoted identifiers do not require validation (and the parser doesn't restrict those today, just bare identifiers).

The whole new/new_unchecked naming thing ended up being misleading IMO, which was a poor choice on my part. This at least fixes the immediate issue, but to avoid future issues of the same nature, we'll want to update those function names and their docs to be clearer about their intended use.

@bobbinth
Copy link
Contributor

bobbinth commented Nov 4, 2024

PR looks good, the only change I would also like to make would be to fix the naming of ProcedureName::{new, new_unchecked} and Ident::{new, new_unchecked} (and I think there are also related LibraryPath/LibraryNamespace APIs as well), to make it clear that new_unchecked is what should be used internally for virtually everything. The new variants (and their stricter validation, only exist for the parsing frontend, as MASM syntax requires bare identifiers of various kinds to be validated more strictly, but quoted identifiers do not require validation (and the parser doesn't restrict those today, just bare identifiers).

The whole new/new_unchecked naming thing ended up being misleading IMO, which was a poor choice on my part. This at least fixes the immediate issue, but to avoid future issues of the same nature, we'll want to update those function names and their docs to be clearer about their intended use.

Great! I'll merge as is and we can refine naming in follow-up PRs.

@bobbinth bobbinth merged commit e3fa9ec into next Nov 4, 2024
9 checks passed
@bobbinth bobbinth deleted the greenhat/library-deser-uncheck-exports branch November 4, 2024 21:37
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