Skip to content

Commit de49b59

Browse files
forkibaronfel
authored andcommitted
Calculate final only when needed (#8284)
1 parent 9d2ae9f commit de49b59

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/fsharp/AugmentWithHashCompare.fs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -883,11 +883,15 @@ let nonVirtualMethod c : ValMemberInfo =
883883
let unitArg = ValReprInfo.unitArgData
884884
let unaryArg = [ ValReprInfo.unnamedTopArg ]
885885
let tupArg = [ [ ValReprInfo.unnamedTopArg1; ValReprInfo.unnamedTopArg1 ] ]
886-
let mkValSpec g (tcref: TyconRef) tmty vis slotsig methn ty argData =
886+
let mkValSpec g (tcref: TyconRef) tmty vis slotsig methn ty argData =
887887
let m = tcref.Range
888888
let tps = tcref.Typars m
889-
let final = isUnionTy g tmty || isRecdTy g tmty || isStructTy g tmty
890-
let membInfo = match slotsig with None -> nonVirtualMethod tcref | Some slotsig -> slotImplMethod(final, tcref, slotsig)
889+
let membInfo =
890+
match slotsig with
891+
| None -> nonVirtualMethod tcref
892+
| Some slotsig ->
893+
let final = isUnionTy g tmty || isRecdTy g tmty || isStructTy g tmty
894+
slotImplMethod(final, tcref, slotsig)
891895
let inl = ValInline.Optional
892896
let args = ValReprInfo.unnamedTopArg :: argData
893897
let topValInfo = Some (ValReprInfo (ValReprInfo.InferTyparInfo tps, args, ValReprInfo.unnamedRetVal))
@@ -899,8 +903,8 @@ let MakeValsForCompareAugmentation g (tcref: TyconRef) =
899903
let tps = tcref.Typars m
900904
let vis = tcref.TypeReprAccessibility
901905

902-
mkValSpec g tcref tmty vis (Some(mkIComparableCompareToSlotSig g)) "CompareTo" (tps +-> (mkCompareObjTy g tmty)) unaryArg,
903-
mkValSpec g tcref tmty vis (Some(mkGenericIComparableCompareToSlotSig g tmty)) "CompareTo" (tps +-> (mkCompareTy g tmty)) unaryArg
906+
mkValSpec g tcref tmty vis (Some(mkIComparableCompareToSlotSig g)) "CompareTo" (tps +-> (mkCompareObjTy g tmty)) unaryArg,
907+
mkValSpec g tcref tmty vis (Some(mkGenericIComparableCompareToSlotSig g tmty)) "CompareTo" (tps +-> (mkCompareTy g tmty)) unaryArg
904908

905909
let MakeValsForCompareWithComparerAugmentation g (tcref: TyconRef) =
906910
let m = tcref.Range
@@ -915,15 +919,15 @@ let MakeValsForEqualsAugmentation g (tcref: TyconRef) =
915919
let vis = tcref.TypeReprAccessibility
916920
let tps = tcref.Typars m
917921

918-
let objEqualsVal = mkValSpec g tcref tmty vis (Some(mkEqualsSlotSig g)) "Equals" (tps +-> (mkEqualsObjTy g tmty)) unaryArg
919-
let nocEqualsVal = mkValSpec g tcref tmty vis (if tcref.Deref.IsExceptionDecl then None else Some(mkGenericIEquatableEqualsSlotSig g tmty)) "Equals" (tps +-> (mkEqualsTy g tmty)) unaryArg
922+
let objEqualsVal = mkValSpec g tcref tmty vis (Some(mkEqualsSlotSig g)) "Equals" (tps +-> (mkEqualsObjTy g tmty)) unaryArg
923+
let nocEqualsVal = mkValSpec g tcref tmty vis (if tcref.Deref.IsExceptionDecl then None else Some(mkGenericIEquatableEqualsSlotSig g tmty)) "Equals" (tps +-> (mkEqualsTy g tmty)) unaryArg
920924
objEqualsVal, nocEqualsVal
921925

922926
let MakeValsForEqualityWithComparerAugmentation g (tcref: TyconRef) =
923927
let _, tmty = mkMinimalTy g tcref
924928
let vis = tcref.TypeReprAccessibility
925929
let tps = tcref.Typars tcref.Range
926-
let objGetHashCodeVal = mkValSpec g tcref tmty vis (Some(mkGetHashCodeSlotSig g)) "GetHashCode" (tps +-> (mkHashTy g tmty)) unitArg
930+
let objGetHashCodeVal = mkValSpec g tcref tmty vis (Some(mkGetHashCodeSlotSig g)) "GetHashCode" (tps +-> (mkHashTy g tmty)) unitArg
927931
let withcGetHashCodeVal = mkValSpec g tcref tmty vis (Some(mkIStructuralEquatableGetHashCodeSlotSig g)) "GetHashCode" (tps +-> (mkHashWithComparerTy g tmty)) unaryArg
928932
let withcEqualsVal = mkValSpec g tcref tmty vis (Some(mkIStructuralEquatableEqualsSlotSig g)) "Equals" (tps +-> (mkEqualsWithComparerTy g tmty)) tupArg
929933
objGetHashCodeVal, withcGetHashCodeVal, withcEqualsVal

0 commit comments

Comments
 (0)