Skip to content

Commit

Permalink
Reduce number of typeEquiv checks (#10324)
Browse files Browse the repository at this point in the history
  • Loading branch information
forki authored Nov 1, 2020
1 parent bd4f2d5 commit 5d9251d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/fsharp/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2360,7 +2360,7 @@ let TcMutRecDefns_Phase2 (cenv: cenv) envInitial bindsm scopem mutRecNSInfo (env
let interfacesFromTypeDefn envForTycon tyconMembersData =
let (MutRecDefnsPhase2DataForTycon(_, _, declKind, tcref, _, _, declaredTyconTypars, members, _, _, _)) = tyconMembersData
let overridesOK = DeclKind.CanOverrideOrImplement declKind
members |> List.collect (function
members |> List.collect (function
| SynMemberDefn.Interface(ity, defnOpt, _) ->
let _, ty = if tcref.Deref.IsExceptionDecl then [], g.exn_ty else generalizeTyconRef tcref
let m = ity.Range
Expand All @@ -2374,12 +2374,18 @@ let TcMutRecDefns_Phase2 (cenv: cenv) envInitial bindsm scopem mutRecNSInfo (env

if not (tcref.HasInterface g ity') then
error(Error(FSComp.SR.tcAllImplementedInterfacesShouldBeDeclared(), ity.Range))
if (typeEquiv g ity' g.mk_IComparable_ty && Option.isSome tcref.GeneratedCompareToValues) ||
(typeEquiv g ity' g.mk_IStructuralComparable_ty && Option.isSome tcref.GeneratedCompareToWithComparerValues) ||
(typeEquiv g ity' ((mkAppTy g.system_GenericIComparable_tcref [ty])) && Option.isSome tcref.GeneratedCompareToValues) ||
(typeEquiv g ity' ((mkAppTy g.system_GenericIEquatable_tcref [ty])) && Option.isSome tcref.GeneratedHashAndEqualsWithComparerValues) ||
(typeEquiv g ity' g.mk_IStructuralEquatable_ty && Option.isSome tcref.GeneratedHashAndEqualsWithComparerValues) then

let generatedCompareToValues = tcref.GeneratedCompareToValues.IsSome
let generatedHashAndEqualsWithComparerValues = tcref.GeneratedHashAndEqualsWithComparerValues.IsSome
let generatedCompareToWithComparerValues = tcref.GeneratedCompareToWithComparerValues.IsSome

if (generatedCompareToValues && typeEquiv g ity' g.mk_IComparable_ty) ||
(generatedCompareToWithComparerValues && typeEquiv g ity' g.mk_IStructuralComparable_ty) ||
(generatedCompareToValues && typeEquiv g ity' ((mkAppTy g.system_GenericIComparable_tcref [ty]))) ||
(generatedHashAndEqualsWithComparerValues && typeEquiv g ity' ((mkAppTy g.system_GenericIEquatable_tcref [ty]))) ||
(generatedHashAndEqualsWithComparerValues && typeEquiv g ity' g.mk_IStructuralEquatable_ty) then
errorR(Error(FSComp.SR.tcDefaultImplementationForInterfaceHasAlreadyBeenAdded(), ity.Range))

if overridesOK = WarnOnOverrides then
warning(IntfImplInIntrinsicAugmentation(ity.Range))
if overridesOK = ErrorOnOverrides then
Expand Down

0 comments on commit 5d9251d

Please sign in to comment.