Skip to content

Commit

Permalink
[Bugfix][Compiler-V2] Fix public(package) causing unit test errors (#…
Browse files Browse the repository at this point in the history
…15627)

* tmp fix

* bugfix

* format

* fix bug and comment

---------

Co-authored-by: Zekun Wang <[email protected]>
  • Loading branch information
2 people authored and georgemitenkov committed Jan 6, 2025
1 parent a115258 commit 8ee1662
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
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

0 comments on commit 8ee1662

Please sign in to comment.