Skip to content

Commit 3f8194f

Browse files
committed
Specify values to allow for ordered comparison
1 parent 9a12a51 commit 3f8194f

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

text/0000-discriminant-intrinsic.md

+13-8
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,26 @@ For any given type, `discriminant_value` will return a `u64` value. The values r
6161
specified:
6262

6363
* **Non-Enum Type**: Always 0
64-
* **Enum Type**: A value that uniquely identifies that variant within its type. I.E. for a given
65-
enum typem `E`, and two values of type `E`, `a` and `b`, the expression `discriminant_value(a) ==
66-
discriminant_value(b)` is true iff `a` and `b` are the same variant. Two values of different types
67-
may return the same discriminant value.
64+
* **C-Like Enum Type**: If no variants have fields, then the enum is considered "C-Like". The user
65+
is able to specify discriminant values in this case, and the return value would be equivalent to
66+
the result of casting the variant to a `u64`.
67+
* **ADT Enum Type**: If any variant has a field, then the enum is conidered to be an "ADT" enum. The
68+
user is not able to specify the discriminant value in this case. The precise values are
69+
unspecified, but have the following characteristics:
6870

69-
The reason for this specification is to allow flexibilty in usage of the intrinsic without
70-
compromising our ability to change the representation at will.
71+
* The value returned for the same variant of the same enum type will compare as
72+
equal. I.E. `discriminant_value(v) == discriminant_value(v)`.
73+
* Two values returned for different variants will compare as unequal relative to their respective
74+
listed positions. That means that if variant `A` is listed before variant `B`, then
75+
`discriminant_value(A) < discriminant_value(B)`.
76+
77+
Note the returned values for two differently-typed variants may compare in any way.
7178

7279
# Drawbacks
7380

7481
* Potentially exposes implementation details. However, relying the specific values returned from
7582
`discriminant_value` should be considered bad practice, as the intrinsic provides no such guarantee.
7683

77-
* Does not allow for the value to be used as part of ordering.
78-
7984
* Allows non-enum types to be provided. This may be unexpected by some users.
8085

8186
# Alternatives

0 commit comments

Comments
 (0)