You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
0 commit comments