Skip to content

Commit 515b56b

Browse files
junxzm1990claude
andcommitted
[move-model] Document and optimize struct usage fallback path
Add documentation explaining that get_using_functions() now uses pre-computed data for source-built structs, and the expensive lazy fallback should rarely execute. Initialize ghost memory structs with empty using_funs set to completely eliminate the fallback path execution. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent e7a282b commit 515b56b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

third_party/move/move-model/src/model.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,8 @@ impl GlobalEnv {
19891989
visibility: Visibility::Private,
19901990
has_package_visibility: false,
19911991
is_empty_struct: false,
1992-
using_funs: RefCell::new(None),
1992+
// Ghost memory structs are synthetic and not directly used by function bodies
1993+
using_funs: RefCell::new(Some(BTreeSet::new())),
19931994
}
19941995
}
19951996

@@ -4234,10 +4235,15 @@ impl<'env> StructEnv<'env> {
42344235
}
42354236

42364237
/// Returns the functions that use this struct.
4238+
///
4239+
/// For structs built from source code, this information is pre-computed during the build
4240+
/// phase by tracking struct usage in function bodies (see module_builder.rs def_ana_fun).
4241+
/// Falls back to expensive lazy computation for other cases.
42374242
pub fn get_using_functions(&self) -> BTreeSet<QualifiedId<FunId>> {
42384243
if let Some(using) = &*self.data.using_funs.borrow() {
42394244
return using.clone();
42404245
}
4246+
// Fallback: compute lazily for structs not built from source
42414247
let mut set = BTreeSet::new();
42424248
let my_id = self.get_qualified_id();
42434249
for module_env in self.module_env.env.get_modules() {

0 commit comments

Comments
 (0)