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

[Bug][move-compiler-v2] problems with errors about lambda types in test hide panics due to missing error checks #14633

Closed
brmataptos opened this issue Sep 14, 2024 · 0 comments · Fixed by brmataptos/aptos-core#1 or #14742 · May be fixed by #14732
Labels

Comments

@brmataptos
Copy link
Contributor

🐛 Bug

Comparing

  • third_party/move/move-compiler/tests/move_check/typing/lambda.exp
  • third_party/move/move-compiler-v2/tests/checking/typing/lambda.exp

We see:

  • line 40: V2 describes the error as the actual type of action (|&T|) being different from the type which would be expected from the context in which it is used (|(&T, u64)|_). The user will be confused by this, since the entire expression is pointed to. This should be changed to clarify somehow:
        error: expected `|(&T, u64)|_` but found a value of type `|&T|`
           ┌─ tests/checking/typing/lambda.move:40:13
           │
        40 │             action(XVector::borrow(v, i), i); // expected to have wrong argument count
           │             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  • line 45: similarly confusing error message from V2
  • line 61: V2 has a very confusing message, given that the previous line declares x: u64:
         error: cannot return `u64` from a function with result type `|integer|`
          ┌─ tests/checking/typing/lambda.move:61:9
          │
       61 │         x(1) // expected to be not a function
          │         ^^^^
  • line 67 and 73: describe the error in terms of the internals of the type system, rather than the programmer's view. Better would be to special-case built-in operations like + and say something like: a value of reference type &integer is not allowed as an argument to operator +.
       error: reference type `&integer` is not allowed as a type argument (type was inferred)
          ┌─ tests/checking/typing/lambda.move:67:35
          │
       67 │         foreach(&v, |e| sum = sum + e) // expected to cannot infer type
          │                                   ^
          │
          = required by instantiating type parameter `T` of function `+`
  • lines 77, 81, 84, 86. 89 have errors in V1 which are missing from the V2 case.
    • Removing earlier errors allows V2 to catch line 84, but others are missing
  • commenting out the code at line 84 causes a panic in recursive_struct_checker.rs:105.

The following is the part of the test code that doesn't yield an error and falls through to panic:

    public fun lambda_not_allowed() {
        let _x = |i| i + 1; // expected lambda not allowed
    }

    struct FieldFunNotAllowed {
        f: |u64|u64, // expected lambda not allowed
    }

    public inline fun macro_result_lambda_not_allowed(): |u64| {  // expected lambda not allowed
        abort (1)
    }
    public fun fun_result_lambda_not_allowed(): |u64| {  // expected lambda not allowed
        abort (1)
    }
@brmataptos brmataptos added the bug Something isn't working label Sep 14, 2024
@brmataptos brmataptos changed the title [Bug][move-compiler-v2] problems with errors about lambda types [Bug][move-compiler-v2] problems with errors about lambda types in test hide panics due to missing errors Sep 14, 2024
@brmataptos brmataptos changed the title [Bug][move-compiler-v2] problems with errors about lambda types in test hide panics due to missing errors [Bug][move-compiler-v2] problems with errors about lambda types in test hide panics due to missing error checks Sep 14, 2024
brmataptos added a commit that referenced this issue Sep 24, 2024
… values,

lay groundwork for implementing and testing more general lambdas.

Fixes #14633.

Catch all errors in test/checking/typing/lambda.move in Compiler V2,
after splitting and gradually commenting out code as lambda[2-5].move
to avoid shadowing by other errors.

- add checking for function-typed function results in `function_checker`
- Change `internal_error` to `error` in `bytecode_generator` and `module_generator`
  to properly show "error" rather than "bug" if lambdas are mistakenly used as values today.
- tag some code to show where changes are needed to support lambda: // TODO(LAMBDA)
- fix unused_params_checker and recursive_struct_checker to tolerate lambda types
- add experiments to control enabling of various aspects of lambda support:
  - LAMBDA_PARAMS, LAMBDA_RESULTS to allow lambdas as general function params or results
  - LAMBDA_FIELDS - support lambdas in struct fields
  - LAMBDA_VALUES - support lambdas in general-purpose values
  - may add LAMBDA_TYPE_PARAMS later
- update lambda-lifting test config to use those flags rather than disabling checks
- add a `result_type_loc` field to move-model's `FunctionData` (and model-builder's `FunEntry`)
  to more precisely locate errors in function result types.
- Fix `GlobalEnv::internal_dump_env` to use function- and struct-specific type contexts
  so that types are shown with correct type parameter names.
- Check that struct fields are not functions.
brmataptos added a commit to brmataptos/aptos-core that referenced this issue Sep 24, 2024
… points for more complete lambda implementation
brmataptos added a commit that referenced this issue Sep 28, 2024
brmataptos added a commit that referenced this issue Oct 3, 2024
brmataptos added a commit to brmataptos/aptos-core that referenced this issue Oct 3, 2024
… points for more complete lambda implementation (#1)

Catch all errors in `move-compiler-v2/tests/checking/typing/lambda.move` in Compiler V2,
after splitting and gradually commenting out code as `lambda[2-5].move`,
to avoid shadowing by other errors.  Lay groundwork for support of lambdas in various capacities.
- tag some code to show where changes are needed to support lambda: // TODO(LAMBDA)
- fix unused_params_checker and recursive_struct_checker to tolerate lambda types
- add experiments to control enabling of various aspects of lambda support
- update lambda-lifting test config to use those flags rather than disabling checks
- Fix `GlobalEnv::internal_dump_env` to use function- and struct-specific type contexts
  so that types are shown with correct type parameter names.
- Check that struct fields are not functions.
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in Move Language and Runtime Oct 3, 2024
brmataptos added a commit that referenced this issue Oct 3, 2024
brmataptos added a commit that referenced this issue Oct 10, 2024
brmataptos added a commit that referenced this issue Oct 10, 2024
…fy change points for more complete lambda implementation (#14742)

Catch all errors in move-compiler-v2/tests/checking/typing/lambda.move in Compiler V2,
after splitting and gradually commenting out code as lambda[2-5].move,
to avoid shadowing by other errors. Lay groundwork for support of lambdas in various capacities.

Fixes #14633.

- add checking for function-typed function results in function_checker, and functions in parameters and results of function types in both args and results to functions there.
- to properly show "error" rather than "bug" if lambdas are mistakenly used as values today.
- tag some code to show where changes are needed to support lambda: // TODO(LAMBDA) fix unused_params_checker and recursive_struct_checker to tolerate lambda types
- add experiments to control enabling of various aspects of lambda support:
- add a result_type_loc field to move-model's FunctionData (and model-builder's FunEntry) to more precisely locate errors in function result types.
- Fix GlobalEnv::internal_dump_env to use function- and struct-specific type contexts so that types are shown with correct type parameter names.
- Check that struct fields are not functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment