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

[Bugfix][Compiler-V2] Fix public(package) causing unit test errors #15627

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn check_for_function_typed_parameters(env: &mut GlobalEnv) {
}

for caller_module in env.get_modules() {
if caller_module.is_primary_target() {
if caller_module.is_target() {
for caller_func in caller_module.get_functions() {
if !lambda_params_ok || !lambda_return_ok {
let caller_name = caller_func.get_full_name_str();
Expand Down Expand Up @@ -316,6 +316,7 @@ pub fn check_access_and_use(env: &mut GlobalEnv, before_inlining: bool) {
let mut private_funcs: BTreeSet<QualifiedFunId> = BTreeSet::new();

for caller_module in env.get_modules() {
// TODO(#13745): fix when we can tell in general if two modules are in the same package
if caller_module.is_primary_target() {
let caller_module_id = caller_module.get_id();
let caller_module_has_friends = !caller_module.has_no_friends();
Expand Down Expand Up @@ -383,6 +384,7 @@ pub fn check_access_and_use(env: &mut GlobalEnv, before_inlining: bool) {
== caller_func.module_env.self_address()
{
// if callee is also a primary target, then they are in the same package
// TODO(#13745): fix when we can tell in general if two modules are in the same package
if callee_func.module_env.is_primary_target() {
// we should've inferred the friend declaration
panic!(
Expand Down
5 changes: 4 additions & 1 deletion third_party/move/move-model/src/builder/model_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ 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()
})
.map(|module_env| module_env.get_id())
.collect_vec();
for cur_mod in target_modules {
Expand Down
8 changes: 3 additions & 5 deletions third_party/move/move-model/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2997,9 +2997,7 @@ impl<'env> ModuleEnv<'env> {

/// Returns the set of modules in the current package,
/// whose public(package) functions are called or referenced in the current module.
/// Requires: `self` is a primary target.
pub fn need_to_be_friended_by(&self) -> BTreeSet<ModuleId> {
debug_assert!(self.is_primary_target());
let mut deps = BTreeSet::new();
if self.is_script_module() {
return deps;
Expand All @@ -3024,12 +3022,12 @@ impl<'env> ModuleEnv<'env> {
}

/// Returns true if functions in the current module can call a public(package) function in the given module.
/// Requires: `self` is a primary target.
fn can_call_package_fun_in(&self, other: &Self) -> bool {
debug_assert!(self.is_primary_target());
!self.is_script_module()
&& !other.is_script_module()
&& other.is_primary_target()
// TODO(#13745): fix this when we have a way to check if
// two non-primary targets are in the same package
&& (!self.is_primary_target() || other.is_primary_target())
&& self.self_address() == other.self_address()
}

Expand Down
Loading