-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Bugfix][Compiler-V2] Fix public(package)
causing unit test errors
#15627
base: main
Are you sure you want to change the base?
Conversation
⏱️ 34m total CI duration on this PR
🚨 1 job on the last run was significantly faster/slower than expected
|
@@ -490,7 +490,7 @@ impl<'env> ModelBuilder<'env> { | |||
let target_modules = self | |||
.env | |||
.get_modules() | |||
.filter(|module_env| module_env.is_primary_target() && !module_env.is_script_module()) | |||
.filter(|module_env| module_env.is_primary_target() || module_env.is_target() && !module_env.is_script_module()) |
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.
Do we also need include non targets?
@@ -490,7 +490,7 @@ impl<'env> ModelBuilder<'env> { | |||
let target_modules = self | |||
.env | |||
.get_modules() | |||
.filter(|module_env| module_env.is_primary_target() && !module_env.is_script_module()) | |||
.filter(|module_env| module_env.is_primary_target() || module_env.is_target() && !module_env.is_script_module()) |
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.
The operator precedence in this condition may not be doing what's intended. Currently !module_env.is_script_module()
only applies to the second part of the OR condition. To ensure script modules are filtered out in both cases, consider restructuring as:
!module_env.is_script_module() && (module_env.is_primary_target() || module_env.is_target())
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
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.
Done
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.
Have some comments, approving assuming those are addressed.
@@ -3015,12 +3013,12 @@ impl<'env> ModuleEnv<'env> { | |||
} | |||
|
|||
/// Returns true if functions in the current module can call a public(package) function in the given module. |
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.
In this PR: https://github.com/aptos-labs/aptos-core/pull/13680/files#diff-d91ccc31f071f5356fd31e9d48dc8372b55377e257f4f2d2a1fdebdafa78a48f, in function_checker.rs
, is_target()
was changed to is_primary_target()
.
- Among those, for the visibility check cases, can you add a similar TODO (so that once we properly add friend decls for non-primary targets for
public(package)
, we perform visibility checks on dependencies' sources as well, which is the v1 behavior). - For the non-visibility-check cases, can you double check if the change from
is_target()
tois_primary_target()
was valid, and briefly mention why, as a reply here?
!self.is_script_module() | ||
&& !other.is_script_module() | ||
&& other.is_primary_target() | ||
// TODO: fix this when we have a way to check if |
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.
// TODO: fix this when we have a way to check if | |
// TODO(#13745): fix this when we have a way to check if |
Description
Fixes #15618.
The transformation of
public(packge)
topublic(friend)
currently is only done for modules in the current package, but not the dependencies. This becomes an issue when the generated bytecode of dependencies is used, say in the case unit tests.We fix this by also doing the transformation to the dependency modules. For dependencies, we cannot perform the transformation properly, as there is no way tell if two non-primary target modules are in the same package (see #13745). So we may friend modules outside the current package. If a dependency contains
public(packge)
visibility violation, say package A contains calls function in package B that calls apublic(package)
function in package C, this will not be captured in the unit test as either a compiler error or runtime error. However, each package is compiled with it set as primary target before deployment, so a package with package visibility errors will never hit the chain.How Has This Been Tested?
All existing test cases. Manually tested the example #15618.
Type of Change
Which Components or Systems Does This Change Impact?
Checklist