Skip to content

[decompiler] Function output ordering is unstable — depends on Symbol allocation order #19151

@wrwg

Description

@wrwg

Summary

The move-decompiler's function output ordering is unstable because it depends on Symbol allocation order rather than bytecode definition order.

Sourcifier::print_module iterates module_env.get_functions() which traverses BTreeMap<FunId(Symbol), _>. Since Symbol indices are assigned in allocation order (a global usize counter), any change to the model builder that allocates symbols earlier or later (e.g. adding lemma support) shuffles the decompiler's function output order, causing baseline churn.

Suggested Fix

Use function_idx_to_id: BTreeMap<FunctionDefinitionIndex, FunId> to iterate functions in stable bytecode-definition order. Add a get_functions_in_def_order() method to ModuleEnv and use it in the sourcifier.

Key Files

  • third_party/move/move-model/src/sourcifier.rs:106 — iterates get_functions()
  • third_party/move/move-model/src/model.rs:3583get_functions() uses BTreeMap values (Symbol order)
  • third_party/move/move-model/src/model.rs:3151function_idx_to_id provides stable ordering

For tracking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions