-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[CLI] Filter unused dependencies in the source code from being published #21168
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
|
||
let (upgrade_policy, mut compiled_package) = | ||
upgrade_result.map_err(|e| anyhow!("{e}"))?; | ||
|
||
let compiled_modules = | ||
compiled_package.get_package_bytes(with_unpublished_dependencies); | ||
let package_id = compiled_package.published_at.clone()?; | ||
let package_digest = | ||
compiled_package.get_package_digest(with_unpublished_dependencies); |
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.
This is just a refactor of the compile_package
function to return a CompiledPackage
type instead of a four-tuple.
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.
Overall, looks great; I left a few inline comments and questions. Only not approving because I think another set of more experienced eyes than mine would be useful =)
crates/sui/tests/data/tree_shaking/D_depends_on_A_v1_but_no_code_references_A/Move.toml
Outdated
Show resolved
Hide resolved
let move_pkg_b = fetch_move_packages(&client, vec![package_b_id]).await?; | ||
let linkage_table_b = move_pkg_b.first().unwrap().linkage_table(); | ||
// B depends on A, so the linkage table should contain A's object ID | ||
assert!(linkage_table_b.contains_key(&package_a_id)); |
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 think you could be a little more precise here - linkage_table_b
should equal [&package_a_id]
.
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 really, because linkage_table
has the BTreeMap<ObjectID, UpgradeInfo>
type.
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.
Maybe just asserting that the size is 1 like you do below (although BTreeMap
does implement Eq
and I assume Eq<ObjectID>
and maybe Eq<UpgradeInfo>
behave reasonably?)
.is_some_and(|x| x.upgraded_id == package_a_v1.reference.object_id)); | ||
|
||
Ok(()) | ||
} |
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.
One test that's missing I think is the case where the existing package on-chain has more dependencies in its linkage table than it actually uses.
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.
Good catch! I will add that right away.
Description
This PR filters out dependencies that might exist in the manifest but are not referenced in the source code such that they do not end up in the linkage table. However, it keeps backward compatibility with what's on chain today (a.k.a there might be dependencies in the linkage table but the code never references those deps).
In addition, it cleans up the
compile_package
function to just return theCompiledPackage
type which holds all the needed data.Test plan
Added tests: see
crates/sui/tests/data/tree_shaking/README.md
andRelease notes
Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.
For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.