@@ -214,6 +214,7 @@ let (|Nameof|_|) com ctx = function
214214 | IdentExpr ident -> Some ident.DisplayName
215215 | Get(_, ByKey( ExprKey( StringConst prop)), _, _) -> Some prop
216216 | Get(_, ByKey( FieldKey fi), _, _) -> Some fi.Name
217+ | Get(_, FieldIndex( fieldName, _), _, _) -> Some fieldName
217218 | NestedLambda( args, Call( IdentExpr ident, info, _, _), None) ->
218219 if List.sameLength args info.Args && List.zip args info.Args |> List.forall ( fun ( a1 , a2 ) ->
219220 match a2 with IdentExpr id2 -> a1.Name = id2.Name | _ -> false )
@@ -693,24 +694,47 @@ let isCompatibleWithJsComparison = function
693694// * `.GetHashCode` called directly defaults to identity hash (for reference types except string) if not implemented.
694695// * `LanguagePrimitive.PhysicalHash` creates an identity hash no matter whether GetHashCode is implemented or not.
695696
696- let getEntityHashMethod ( ent : Entity ) =
697- if ent.IsFSharpUnion || ent.IsFSharpRecord || ent.IsValueType then " Util" , " hashSafe"
697+ let getEntityHashMethod ( com : ICompiler ) ( ent : Entity ) =
698+ if ( ent.IsFSharpUnion || ent.IsFSharpRecord) then
699+ if com.Options.EraseUnions
700+ then " Util" , " structuralHash"
701+ else " Util" , " hashSafe"
702+ elif ent.IsValueType
703+ then " Util" , " hashSafe"
698704 else " Util" , " identityHash"
699705
706+ let getEntityEqualsMethod ( com : ICompiler ) ( ent : Entity ) =
707+ if ( ent.IsFSharpUnion || ent.IsFSharpRecord) then
708+ if com.Options.EraseUnions
709+ then " Util" , " equals"
710+ else " Util" , " equalsSafe"
711+ elif ent.IsValueType
712+ then " Util" , " equalsSafe"
713+ else " Util" , " equals"
714+
715+ let getEntityCompareMethod ( com : ICompiler ) ( ent : Entity ) =
716+ if ( ent.IsFSharpUnion || ent.IsFSharpRecord) then
717+ if com.Options.EraseUnions
718+ then " Util" , " compare"
719+ else " Util" , " compareSafe"
720+ elif ent.IsValueType
721+ then " Util" , " compareSafe"
722+ else " Util" , " compare"
723+
700724let identityHashMethod ( com : ICompiler ) = function
701725 | Boolean | Char | String | Number _ | Enum _ | Option _ | Tuple _ | List _
702726 | Builtin ( BclInt64 | BclUInt64 | BclDecimal | BclBigInt)
703727 | Builtin ( BclGuid | BclTimeSpan | BclDateTime | BclDateTimeOffset)
704728 | Builtin ( FSharpSet _ | FSharpMap _ | FSharpChoice _ | FSharpResult _) ->
705729 " Util" , " structuralHash"
706- | DeclaredType( ent, _) -> com.GetEntity( ent) |> getEntityHashMethod
730+ | DeclaredType( ent, _) -> com.GetEntity( ent) |> getEntityHashMethod com
707731 | _ -> " Util" , " identityHash"
708732
709733let structuralHashMethod ( com : ICompiler ) = function
710734 | MetaType -> " Reflection" , " getHashCode"
711735 | DeclaredType( ent, _) ->
712736 let ent = com.GetEntity( ent)
713- if not ent.IsInterface then getEntityHashMethod ent
737+ if not ent.IsInterface then getEntityHashMethod com ent
714738 else " Util" , " structuralHash"
715739 | _ -> " Util" , " structuralHash"
716740
@@ -739,10 +763,8 @@ let rec equals (com: ICompiler) ctx r equal (left: Expr) (right: Expr) =
739763 Helper.LibCall( com, coreModFor bt, " equals" , Boolean, [ left; right], ?loc= r) |> is equal
740764 | DeclaredType( ent, _) ->
741765 let ent = com.GetEntity( ent)
742- if ent.IsFSharpUnion || ent.IsFSharpRecord || ent.IsValueType then
743- Helper.LibCall( com, " Util" , " equalsSafe" , Boolean, [ left; right], ?loc= r) |> is equal
744- else
745- Helper.LibCall( com, " Util" , " equals" , Boolean, [ left; right], ?loc= r) |> is equal
766+ let moduleName , methodName = getEntityEqualsMethod com ent
767+ Helper.LibCall( com, moduleName, methodName, Boolean, [ left; right], ?loc= r) |> is equal
746768 | Array t ->
747769 let f = makeComparerFunction com ctx t
748770 Helper.LibCall( com, " Array" , " equalsWith" , Boolean, [ f; left; right], ?loc= r) |> is equal
@@ -767,10 +789,8 @@ and compare (com: ICompiler) ctx r (left: Expr) (right: Expr) =
767789 Helper.LibCall( com, coreModFor bt, " compare" , Number Int32, [ left; right], ?loc= r)
768790 | DeclaredType( ent, _) ->
769791 let ent = com.GetEntity( ent)
770- if ent.IsFSharpUnion || ent.IsFSharpRecord || ent.IsValueType then
771- Helper.LibCall( com, " Util" , " compareSafe" , Number Int32, [ left; right], ?loc= r)
772- else
773- Helper.LibCall( com, " Util" , " compare" , Number Int32, [ left; right], ?loc= r)
792+ let moduleName , methodName = getEntityCompareMethod com ent
793+ Helper.LibCall( com, moduleName, methodName, Number Int32, [ left; right], ?loc= r)
774794 | Array t ->
775795 let f = makeComparerFunction com ctx t
776796 Helper.LibCall( com, " Array" , " compareWith" , Number Int32, [ f; left; right], ?loc= r)
0 commit comments