Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[move-compiler-v2] clean up a few remaining issues in lambda parser/front-end code #15365

Open
wants to merge 2 commits into
base: 09-27-add_parser_code_for_lambda_types
Choose a base branch
from

Conversation

brmataptos
Copy link
Contributor

@brmataptos brmataptos commented Nov 22, 2024

Description

Various fixes:

  • Remove Constraint::NoFunction as it's too broad.
  • Make sure there are still errors for all planned unsupported cases
  • Fix LambdaLifter case for bound free variable without copy.
  • Distinguish between "not supported" and "not implemented" for lambda features.
  • Refine lambda test cases to make _ok versions that compile up to "not implemented" errors.
  • Add a test case to illustrate the function name aliasing issue ([Bug][move-compiler-v2] visible function names shadow local variables with same name in function calls #15360), but changed other tests here to avoid it.

How Has This Been Tested?

Usual tests run, showing unchanged behavior on existing code. Tests under /lambda/ without .lambda. config show proper errors generated if to many functions are used. _ok tests now show code working up until "not implemented" errors.

Key Areas to Review

Most complex stuff is in previous PR, but:

  • Am I missing some ability cases (e.g., filtering for store and copy properties in captured free variables?
  • Are closures with references getting through?
  • Do /lambda/storage/*_ok.move tests look like reasonable code to expect from users?

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Performance improvement
  • Refactoring
  • Dependency update
  • Documentation update
  • Tests

Which Components or Systems Does This Change Impact?

  • Validator Node
  • Full Node (API, Indexer, etc.)
  • Move/Aptos Virtual Machine
  • Aptos Framework
  • Aptos CLI/SDK
  • Developer Infrastructure
  • Move Compiler
  • Other (specify)

Checklist

  • I have read and followed the CONTRIBUTING doc
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I identified and added all stakeholders and component owners affected by this change as reviewers
  • I tested both happy and unhappy path of the functionality
  • I have made corresponding changes to the documentation

Copy link

trunk-io bot commented Nov 22, 2024

⏱️ 1h 20m total CI duration on this PR
Job Cumulative Duration Recent Runs
rust-move-tests 12m 🟩
rust-move-tests 12m 🟥
rust-move-tests 12m 🟥
rust-move-tests 12m 🟥
rust-move-tests 12m 🟥
rust-cargo-deny 9m 🟩🟩🟩🟩🟩
check-dynamic-deps 4m 🟩🟩🟩🟩🟩
general-lints 2m 🟩🟩🟩🟩🟩
semgrep/ci 2m 🟩🟩🟩🟩🟩
file_change_determinator 57s 🟩🟩🟩🟩🟩
permission-check 21s 🟩🟩🟩🟩🟩
permission-check 14s 🟩🟩🟩🟩🟩
check-branch-prefix 1s 🟩

settingsfeedbackdocs ⋅ learn more about trunk.io

@brmataptos brmataptos changed the title lambda-compiler-completion [move-compiler-v2] clean up a few remaining issues in lambda parser/front-end code Nov 22, 2024
@brmataptos brmataptos marked this pull request as ready for review November 22, 2024 01:45
@brmataptos brmataptos force-pushed the 11-21-lambda-compiler-completion branch from 3e3563e to dac085c Compare November 22, 2024 21:39
env.error(
&loc,
// TODO(LAMBDA)
"Lambdas expressions with `store` ability currently may only be a simple call to an existing `public` function. This lambda expression requires defining a `public` helper function, which might affect module upgradeability and is not yet supported."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message looks a little bit confusing for users (e.g what is a helper function and how it may affect upgradeability). Maybe just remove requires defining a public helper function, which might affect module upgradeability` and just saying it is not supported yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

env.error(
&loc,
&format!(
"captured variable `{}` must have a value with `copy` ability", // TODO(LAMBDA)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test case for this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added closure_args.move, see closure_args.lambda.exp.

This exercises a lot of cases.

self.emit_call(id, vec![target], BytecodeOperation::ReadRef, vec![
borrow_dest,
])
self.emit_call(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like formatting only change? When I run the formatter, it goes back to the original.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

probing_vars: Some(_),
..
})
matches!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar as above, when I run the formatter, this goes back to original.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fixed,

}

public inline fun quux(f:|u64, u64|u64, a: u64, b: u64): u64 {
f(a, b)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also add test cases where we have:

  1. Use statement importing (at the module level and at the function level) a function foo, where foo is also a function parameter to an inline function like here.
  2. Similar as above, but without explicit use statement and instead explicit qualification like other_module::foo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is rather tangential to this PR, but I've added use statements. The explicit qualification case is not interesting, as we know what it will do.

What is happening is very clear if you look at move-compiler/src/expander/translation.rs and .../aliases.rs, which tracks nesting of use of symbols from other modules. All that is tracked are those imported symbols, not any local variables. A name in function call position (and a few other places) is turned into an explicit ModuleIdent::Name pair. A name in other positions may be left unevaluated until later.

node_id,
modified: true,
});
self.free_locals.insert(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A number of changes here seem to be only whitespace changes that go away when I format. Any idea how these changes came by?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge conflicts? Also, Emacs sometimes indents differently than the Rust usual.

let Some((mut params, mut closure_args, param_index_mapping)) =
self.get_params_for_freevars()
else {
return None;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the ? operator fits well here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, though I personally find it a little too subtle.

@brmataptos brmataptos force-pushed the 09-27-add_parser_code_for_lambda_types branch from cead217 to 44baaf0 Compare November 27, 2024 10:24
@brmataptos brmataptos force-pushed the 11-21-lambda-compiler-completion branch from 42421fe to 92ae56c Compare November 27, 2024 10:24
@brmataptos brmataptos force-pushed the 11-21-lambda-compiler-completion branch from 92ae56c to 3c02ba1 Compare November 27, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants