-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce unified operators, the ad-hoc specialization for primitive operators. For example adding two values, we have `+` for ints, `+.` for floats, and `++` for strings. That is because we don't allow implicit conversion or overloading for operations. It is a fundamental property of the ReScript language, but it is far from the best DX we can think of, and it became a problem when new primitives like bigint were introduced. See discussion: #6525 Unified ops mitigate the problem by adding ad-hoc translation rules on applications of the core built-in operators which have a form of binary ('a -> 'a -> 'a) or unary ('a -> 'a) Translation rules should be applied in its application, in both type-level and IR(lambda)-level. The rules: 1. If the lhs type is a primitive type, unify the rhs and the result type to the lhs type. 2. If the lhs type is not a primitive type but the rhs type is, unify lhs and the result type to the rhs type. 3. If both lhs type and rhs type is not a primitive type, unify the whole types to the int. Since these are simple ad-hoc translations for primitive applications, we cannot use the result type defined in other contexts. So falling back to int type is the simplest behavior that ensures backward compatibility. You can find related definitions on `ml/unified_ops.ml` file. The actual implementation of translation is colocated into other modules. - Type-level : `ml/typecore.ml` - IR-level : `ml/translcore.ml` You can find it with the function name `translate_unified_ops` Resolved #6477
- Loading branch information
Showing
15 changed files
with
495 additions
and
115 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
Oops, something went wrong.