Self explanatory. One of the enumerations in Type_Info_Flag
is Simple_Compare
. What does this signify, and how is it different from Comparable
?
How come this flag being not present makes Odin runtime set equal_proc
in Type_Info_Struct
and Type_Info_Union
be set?
Simple_Compare
is set for types that the CPU can directly compare, if you take a peek into the compiler source these types are:
// types.cpp
enum BasicFlag {
// ...
BasicFlag_SimpleCompare = BasicFlag_Boolean | BasicFlag_Numeric | BasicFlag_Pointer | BasicFlag_Rune,
};
For all other types it requires to do the equivalent of core:mem
’s mem.compare_ptrs(&value1, &value2, size_of(value1)) == 0
when you test for equality.
Comparable
is valid for both simple types (Simple_Compare
) and for types for which all elements/members are comparable.
E.g. a struct { x, y: int}
is comparable because
- all members are
int
s which are themselves comparable
int
is comparable because they are Simple_Compare
If you wanna explore in more detail check for bool is_type_comparable(Type *t)
in the compiler source types.cpp
.
Note: unlikely that names will change, but this is from commit 3229f4668df
.