Repository: aptos-labs/aptos-core
File: third_party/move/move-compiler-v2/src/env_pipeline/inlining_optimization.rs (Rust)

Code before:
        return false;
    };
    let mut found = false;
    exp.visit_pre_order(&mut |e: &ExpData| {
        if let ExpData::Return(..) = e {
            found = true;
        }
        // Keep going if not yet found
        !found
    });
    found
}

/// Does `function` have an abort expression with non-constant or conflicting error code with the caller module?
fn has_abort_with_non_const_or_conflicting_error_code(
    function: &FunctionEnv,
    caller_module_env: &ModuleEnv,
) -> bool {
    let Some(exp) = function.get_def() else {
        return false;
    };
    let mut found = false;
    exp.visit_pre_order(&mut |e: &ExpData| {
        if let ExpData::Call(_, Operation::Abort, args) = e {
            assert!(args.len() == 1);
            match args[0].as_ref() {
                // if error code is a constant, check whether it is overlapping with any constants defined in the caller module
                // when caller and callee are in different modules
                ExpData::Value(_, value) => {
                    if caller_module_env.get_id() != function.module_env.get_id()
                        && caller_module_env.has_named_constant_with_value(value)
                    {
                        found = true;
                    }
                },
                _ => {
                    found = true;
                },
            }
        }
        // Keep going if not yet found
        !found
    });
    found
}

/// Does `function` have any runtime access control checks?
/// If so, by inlining, such checks would not be performed.
fn has_access_controls(function: &FunctionEnv) -> bool {
    if let Some(access_specifiers) = function.get_access_specifiers() {
        if access_specifiers.is_empty() {

Review comment (suggestion):
The reality in Move framework code is that we do

```
/// This is an error message.
const ERROR : u64 = 0;
~~ abort error::invalid_argument(ERROR) ~~
```

So I think you have to recursively visit the expression for finding a constant reference.

Here is BTW the logic how Aptos creates errormap: https://github.com/aptos-labs/aptos-core/blob/04d4126476e5c62c2e4a66713c5f695f9e8bcc49/aptos-move/framework/src/extended_checks.rs#L829



Code after:
    exp.visit_pre_order(&mut |e: &ExpData| {
        if let ExpData::Return(..) = e {
            found = true;
        }
        // Keep going if not yet found
        !found
    });
    found
}

/// Does `function` have an abort expression in its body?
fn has_abort(function: &FunctionEnv, caller: &FunctionEnv) -> bool {
    let Some(exp) = function.get_def() else {
        return false;
    };
    if function.module_env.get_id() == caller.module_env.get_id() {
        return false;
    }
    let mut found = false;
    exp.visit_pre_order(&mut |e: &ExpData| {
        if let ExpData::Call(_, Operation::Abort, _) = e {
            found = true;
        }
        // Keep going if not yet found
        !found
    });
    found
}

/// Does `function` have any runtime access control checks?
/// If so, by inlining, such checks would not be performed.
fn has_access_controls(function: &FunctionEnv) -> bool {
    if let Some(access_specifiers) = function.get_access_specifiers() {
        if access_specifiers.is_empty() {
            // empty access specifiers means no access is allowed, the strictest form
            // of access control
            return true;
        }
        // any reads or writes specification is considered an access control
        access_specifiers
            .iter()
            .any(|spec| spec.kind != AccessSpecifierKind::LegacyAcquires)
    } else {
        false
    }
}

/// Does `function` have the `#[module_lock]` attribute?
fn has_module_lock_attribute(function: &FunctionEnv) -> bool {
    let env = function.env();
    function.has_attribute(|attr| {