From 20e25a4a2daf2e27a87030136da5d534da5dab8b Mon Sep 17 00:00:00 2001 From: Zekun Wang <41706692+fEst1ck@users.noreply.github.com> Date: Mon, 6 Jan 2025 13:01:04 -0500 Subject: [PATCH] [Bugfix][Compiler-V2] Fix `public(package)` causing unit test errors (#15627) * tmp fix * bugfix * format * fix bug and comment --------- Co-authored-by: Zekun Wang --- .../move-compiler-v2/src/env_pipeline/function_checker.rs | 4 +++- third_party/move/move-model/src/builder/model_builder.rs | 5 ++++- third_party/move/move-model/src/model.rs | 8 +++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs b/third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs index 958a13bde6425..325865f81336a 100644 --- a/third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs +++ b/third_party/move/move-compiler-v2/src/env_pipeline/function_checker.rs @@ -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(); @@ -316,6 +316,7 @@ pub fn check_access_and_use(env: &mut GlobalEnv, before_inlining: bool) { let mut private_funcs: BTreeSet = 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(); @@ -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!( diff --git a/third_party/move/move-model/src/builder/model_builder.rs b/third_party/move/move-model/src/builder/model_builder.rs index 55c3b34520c19..60bf8972b7f9d 100644 --- a/third_party/move/move-model/src/builder/model_builder.rs +++ b/third_party/move/move-model/src/builder/model_builder.rs @@ -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 { diff --git a/third_party/move/move-model/src/model.rs b/third_party/move/move-model/src/model.rs index 175923e0dade2..1280a6c3e9911 100644 --- a/third_party/move/move-model/src/model.rs +++ b/third_party/move/move-model/src/model.rs @@ -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 { - debug_assert!(self.is_primary_target()); let mut deps = BTreeSet::new(); if self.is_script_module() { return deps; @@ -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() }