-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler v2][type checker] Make arithmetic operators generic with co…
…nstraints (#9792) * [compiler v2][type checker] Make arithmetic operators generic with constraints Until now, we had represented arithmetic operators via overloads. For instance, we had `fun _+_(u8,u8):u8, fun _+_(u16,u16):u16` and so on for all integer types. The problem with this approach is that it does not work for constants, as described in #9330. Move allows to write `1+2` and this expression gets its type inferred from the context. In this PR, arithmetic ops are represented not longer as overloads but as generic functions with constraints. Basically: ``` fun _+_<A>(x: A, y: A): A where A:u8|u16|u32|..|u256; fun _-_<A>(...)... ``` This has the following effects: - Expressions over constants inherit their generic result type (that is, `1 + 2` does not fix the operator to a specific integer type. Instead the context may do this.) - Error messages get better. The messages where we just printed non-matching overloads were not very good, no we see more precise error messages. Technically, this needed some refinements of the type constraint system. Also, some error reporting has been fixed which was before only working in very specific contexts. * Addressing reviewer comments. * Addressing more reviewer comments. This revamps the generation of error messages, removing some older broken heuristics and trying to fix the problem of orientation of 'expected' vs 'found' at the core. Some context annotation 'from assignment context' not tries to clarify the error message if the typing error is for an lvalue, where the expected type is a _lower bound_ instead of an upper bound, which may leads to confusion for end users. The messages are now more systematic but perhaps a bit harder to understand, yet this is not trivial to fix and we have to iterate on this.
- Loading branch information
Showing
89 changed files
with
1,303 additions
and
2,338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
third_party/move/move-compiler-v2/tests/checking/specs/assert_skipped_for_spec.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// ---- Model Dump | ||
module 0x42::M { | ||
private fun bar(x: u64) { | ||
if Gt(x, 0) { | ||
if Gt<u64>(x, 0) { | ||
Tuple() | ||
} else { | ||
Abort(1) | ||
}; | ||
Sub(x, 1) | ||
Sub<u64>(x, 1) | ||
} | ||
} // end 0x42::M |
20 changes: 10 additions & 10 deletions
20
third_party/move/move-compiler-v2/tests/checking/typing/assign_unpack_references_invalid.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
third_party/move/move-compiler-v2/tests/checking/typing/assign_wrong_arity.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.