-
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
[Feature] [Compiler-V2] Package Visibility #13680
Conversation
⏱️ 7h 24m total CI duration on this PR
|
e818b84
to
b719d56
Compare
@@ -471,6 +482,23 @@ impl<'env, 'translator> ModuleBuilder<'env, 'translator> { | |||
) | |||
} | |||
let fun_id = FunId::new(qsym.symbol); | |||
let visibility = match def.visibility { |
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.
Moved here to avoid borrowing issues.
@@ -0,0 +1,10 @@ | |||
|
|||
Diagnostics: | |||
error: friend modules of `0x42::A` must have the same address, but the declared friend module `0x43::B` has a different address |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
@fEst1ck, could you add some tests to the V1 compiler crate to show error messages that will be generated by V1 when compiling the code with this new feature? |
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.
Some first comments
@@ -22,6 +22,7 @@ pub const KEYWORDS: &[&str] = &[ | |||
"module", | |||
"move", | |||
"native", | |||
"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.
Please do not make this a keyword, we do not have breaking changes in Move 2.
Instead use a 'soft' keyword, that is interpreting an identifier in a special way in a given context. There are multiple examples for this already in syntax.rs, search e.g. for "schema"
or check "enum"
in the enum PR.
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
@@ -618,6 +618,7 @@ fn visibility(v: Visibility) -> IR::FunctionVisibility { | |||
Visibility::Public(_) => IR::FunctionVisibility::Public, | |||
Visibility::Friend(_) => IR::FunctionVisibility::Friend, | |||
Visibility::Internal => IR::FunctionVisibility::Internal, | |||
_ => unreachable!(), |
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.
Please panic with an error message 'unexpected visibility'. unreachable!
should only be used if its clearly never failing, e.g. if you made a check just before in the local code (if x.is_some() { let Some(y) = x else { unreachable!() }}
)
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
5847d04
to
d2d9e70
Compare
@@ -2634,6 +2633,13 @@ impl<'env> ModuleEnv<'env> { | |||
self.env.file_id_is_primary_target.contains(&file_id) | |||
} | |||
|
|||
/// Returns true if both modules are defined in the same package. | |||
pub fn in_same_package(&self, other: &'env Self) -> bool { |
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.
Submitted issue #13745 for this.
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.
As said above, I think we only need to distinguish whether a module is part of the currently compiled package or not. And this is defined by is_primary_target
(is_target
was recently renamed as such, which was an unfortunate decision because it already created a lot of confusion).
This comment was marked as outdated.
This comment was marked as outdated.
a88ac82
to
28e99fb
Compare
bf3fd5d
to
451e4be
Compare
done. |
// To avoid prover compiler <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error">error</a> on <b>spec</b> | ||
// the package need <b>to</b> be an immutable variable | ||
// the <b>package</b> need <b>to</b> be an immutable variable |
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 sure if this was a manual change or auto-generated, but "need" should be changed to "needs" to have the grammar be correct.
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 problem is that we seem to identify package as a kind of keyword. This isn't good as it is potentially breaking.
There shouldn't be any changes for generated documentation.
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.
package is should in boldface because it's now a contextual keyword.
8f5cced
to
5307aa2
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
✅ Forge suite
|
Description
Implements the
public(package)
visibility modifier for functions, making the functions visible to the modules with the same address in the current package. Underlying, the package visibilitypublic(package)
is transformed into friend visibilitypublic(friend)
. Then friend declarations are inferred when and only when necessary. Specifically, when moduleA
uses a function with package visibility in moduleB
, we declare moduleA
as a friend in moduleB
. We cannot simply declare a module containing apublic(package)
function as a friend to all other modules in the package. Because then whenever we have two or more modules withpublic(package)
functions, a friend cycle would result.As an example,
is transformed into
Note that this transformation disallows the use of both friend and package visibility in the same module. Say we have
if we transform it into
This would be wrong because now
foo
is visible in moduleC
.Type of Change
Which Components or Systems Does This Change Impact?
How Has This Been Tested?
Existing tests and new tests under
visibility-checker
,third_party/move/tools/move-package/tests/test_sources/compilation/call_package_fun_from_other_package
.