Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit66b20f9

Browse files
cartermpTIHan
authored andcommitted
Avoid boxing in Range equality comparisons (dotnet#6048)
* Override '=' for Range type* Re-add overridden equals because* Replace equality with Range.equals function* Change the rest of the range equality comparisons to use range equality functions
1 parent3225121 commit66b20f9

File tree

12 files changed

+67
-50
lines changed

12 files changed

+67
-50
lines changed

‎src/fsharp/CompileOps.fs‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -646,16 +646,16 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
646646
lett1,t2,_cxs= NicePrint.minimalStringsOfTwoTypes denv t1 t2
647647

648648
match contextInfowith
649-
| ContextInfo.IfExpression rangewhenrange= m-> os.Append(FSComp.SR.ifExpression(t1, t2))|> ignore
650-
| ContextInfo.CollectionElement(isArray, range)whenrange= m->
649+
| ContextInfo.IfExpression rangewhenRange.equals range m-> os.Append(FSComp.SR.ifExpression(t1, t2))|> ignore
650+
| ContextInfo.CollectionElement(isArray, range)whenRange.equals range m->
651651
if isArraythen
652652
os.Append(FSComp.SR.arrayElementHasWrongType(t1, t2))|> ignore
653653
else
654654
os.Append(FSComp.SR.listElementHasWrongType(t1, t2))|> ignore
655-
| ContextInfo.OmittedElseBranch rangewhenrange= m-> os.Append(FSComp.SR.missingElseBranch(t2))|> ignore
656-
| ContextInfo.ElseBranchResult rangewhenrange= m-> os.Append(FSComp.SR.elseBranchHasWrongType(t1, t2))|> ignore
657-
| ContextInfo.FollowingPatternMatchClause rangewhenrange= m-> os.Append(FSComp.SR.followingPatternMatchClauseHasWrongType(t1, t2))|> ignore
658-
| ContextInfo.PatternMatchGuard rangewhenrange= m-> os.Append(FSComp.SR.patternMatchGuardIsNotBool(t2))|> ignore
655+
| ContextInfo.OmittedElseBranch rangewhenRange.equals range m-> os.Append(FSComp.SR.missingElseBranch(t2))|> ignore
656+
| ContextInfo.ElseBranchResult rangewhenRange.equals range m-> os.Append(FSComp.SR.elseBranchHasWrongType(t1, t2))|> ignore
657+
| ContextInfo.FollowingPatternMatchClause rangewhenRange.equals range m-> os.Append(FSComp.SR.followingPatternMatchClauseHasWrongType(t1, t2))|> ignore
658+
| ContextInfo.PatternMatchGuard rangewhenRange.equals range m-> os.Append(FSComp.SR.patternMatchGuardIsNotBool(t2))|> ignore
659659
|_-> os.Append(ConstraintSolverTypesNotInEqualityRelation2E().Format t1 t2)|> ignore
660660
if m.StartLine<> m2.StartLinethen
661661
os.Append(SeeAlsoE().Format(stringOfRange m))|> ignore
@@ -683,16 +683,16 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
683683
&& typeEquiv g t2 t2'->
684684
lett1,t2,tpcs= NicePrint.minimalStringsOfTwoTypes denv t1 t2
685685
match contextInfowith
686-
| ContextInfo.IfExpression rangewhenrange= m-> os.Append(FSComp.SR.ifExpression(t1, t2))|> ignore
687-
| ContextInfo.CollectionElement(isArray, range)whenrange= m->
686+
| ContextInfo.IfExpression rangewhenRange.equals range m-> os.Append(FSComp.SR.ifExpression(t1, t2))|> ignore
687+
| ContextInfo.CollectionElement(isArray, range)whenRange.equals range m->
688688
if isArraythen
689689
os.Append(FSComp.SR.arrayElementHasWrongType(t1, t2))|> ignore
690690
else
691691
os.Append(FSComp.SR.listElementHasWrongType(t1, t2))|> ignore
692-
| ContextInfo.OmittedElseBranch rangewhenrange= m-> os.Append(FSComp.SR.missingElseBranch(t2))|> ignore
693-
| ContextInfo.ElseBranchResult rangewhenrange= m-> os.Append(FSComp.SR.elseBranchHasWrongType(t1, t2))|> ignore
694-
| ContextInfo.FollowingPatternMatchClause rangewhenrange= m-> os.Append(FSComp.SR.followingPatternMatchClauseHasWrongType(t1, t2))|> ignore
695-
| ContextInfo.PatternMatchGuard rangewhenrange= m-> os.Append(FSComp.SR.patternMatchGuardIsNotBool(t2))|> ignore
692+
| ContextInfo.OmittedElseBranch rangewhenRange.equals range m-> os.Append(FSComp.SR.missingElseBranch(t2))|> ignore
693+
| ContextInfo.ElseBranchResult rangewhenRange.equals range m-> os.Append(FSComp.SR.elseBranchHasWrongType(t1, t2))|> ignore
694+
| ContextInfo.FollowingPatternMatchClause rangewhenRange.equals range m-> os.Append(FSComp.SR.followingPatternMatchClauseHasWrongType(t1, t2))|> ignore
695+
| ContextInfo.PatternMatchGuard rangewhenRange.equals range m-> os.Append(FSComp.SR.patternMatchGuardIsNotBool(t2))|> ignore
696696
| ContextInfo.TupleInRecordFields->
697697
os.Append(ErrorFromAddingTypeEquation1E().Format t2 t1 tpcs)|> ignore
698698
os.Append(System.Environment.NewLine+ FSComp.SR.commaInsteadOfSemicolonInRecord())|> ignore
@@ -1640,7 +1640,7 @@ type Diagnostic =
16401640
/// returns sequence that contains Diagnostic for the given error + Diagnostic for all related errors
16411641
letCollectDiagnostic(implicitIncludeDir,showFullPaths,flattenErrors,errorStyle,isError,err:PhasedDiagnostic)=
16421642
letoutputWhere(showFullPaths,errorStyle)m:DiagnosticLocation=
1643-
ifm=rangeStartup||m= rangeCmdArgsthen
1643+
ifRange.equals mrangeStartup||Range.equals m rangeCmdArgsthen
16441644
{ Range= m; TextRepresentation=""; IsEmpty=true; File=""}
16451645
else
16461646
letfile= m.FileName
@@ -1675,7 +1675,7 @@ let CollectDiagnostic (implicitIncludeDir, showFullPaths, flattenErrors, errorSt
16751675
| ErrorStyle.VSErrors->
16761676
// Show prefix only for real files. Otherwise, we just want a truncated error like:
16771677
// parse error FS0031 : blah blah
1678-
ifm<>range0&&m<>rangeStartup&&m<>rangeCmdArgsthen
1678+
ifnot(Range.equals mrange0)&&not(Range.equals mrangeStartup)&&not(Range.equals mrangeCmdArgs)then
16791679
letfile= file.Replace("/","\\")
16801680
letm= mkRange m.FileName(mkPos m.StartLine(m.StartColumn+1))(mkPos m.EndLine(m.EndColumn+1))
16811681
sprintf"%s(%d,%d,%d,%d):" file m.StartLine m.StartColumn m.EndLine m.EndColumn, m, file
@@ -2610,12 +2610,12 @@ type TcConfigBuilder =
26102610
membertcConfigB.AddReferencedAssemblyByPath(m,path)=
26112611
if FileSystem.IsInvalidPathShim(path)then
26122612
warning(Error(FSComp.SR.buildInvalidAssemblyName(path), m))
2613-
elifnot(tcConfigB.referencedDLLs|> List.exists(fun ar2->m=ar2.Range&& path=ar2.Text))then// NOTE: We keep same paths if range is different.
2613+
elifnot(tcConfigB.referencedDLLs|> List.exists(fun ar2->Range.equals mar2.Range&& path=ar2.Text))then// NOTE: We keep same paths if range is different.
26142614
letprojectReference= tcConfigB.projectReferences|> List.tryPick(fun pr->if pr.FileName= paththen Some prelse None)
26152615
tcConfigB.referencedDLLs<- tcConfigB.referencedDLLs++ AssemblyReference(m, path, projectReference)
26162616

26172617
membertcConfigB.RemoveReferencedAssemblyByPath(m,path)=
2618-
tcConfigB.referencedDLLs<- tcConfigB.referencedDLLs|> List.filter(fun ar-> ar.Range<> m|| ar.Text<> path)
2618+
tcConfigB.referencedDLLs<- tcConfigB.referencedDLLs|> List.filter(fun ar->not(Range.equalsar.Rangem)|| ar.Text<> path)
26192619

26202620
static memberSplitCommandLineResourceInfo(ri:string)=
26212621
letp= ri.IndexOf','
@@ -2760,7 +2760,7 @@ type TcConfig private (data : TcConfigBuilder, validate:bool) =
27602760
r, Some(filename)
27612761
else
27622762
// If the file doesn't exist, let reference resolution logic report the error later...
2763-
defaultCoreLibraryReference,if r.Range=rangeStartupthen Some(filename)else None
2763+
defaultCoreLibraryReference,ifRange.equalsr.Range rangeStartupthen Some(filename)else None
27642764
match data.referencedDLLs|> List.filter(fun assemblyReference-> assemblyReference.SimpleAssemblyNameIs libraryName)with
27652765
|[r]-> nameOfDll r
27662766
|[]->
@@ -3110,7 +3110,13 @@ type TcConfig private (data : TcConfigBuilder, validate:bool) =
31103110
// file is included in the search path. This should ideally already be one of the search paths, but
31113111
// during some global checks it won't be. We append to the end of the search list so that this is the last
31123112
// place that is checked.
3113-
if m<> range0&& m<> rangeStartup&& m<> rangeCmdArgs&& FileSystem.IsPathRootedShim m.FileNamethen
3113+
letisPoundRReference(r:range)=
3114+
not(Range.equals r range0)&&
3115+
not(Range.equals r rangeStartup)&&
3116+
not(Range.equals r rangeCmdArgs)&&
3117+
FileSystem.IsPathRootedShim r.FileName
3118+
3119+
if isPoundRReference mthen
31143120
tcConfig.GetSearchPathsForLibraryFiles()@[Path.GetDirectoryName(m.FileName)]
31153121
else
31163122
tcConfig.GetSearchPathsForLibraryFiles()
@@ -5216,7 +5222,7 @@ module private ScriptPreprocessClosure =
52165222
match GetRangeOfDiagnostic exnwith
52175223
| Some m->
52185224
// Return true if the error was *not* from a #load-ed file.
5219-
letisArgParameterWhileNotEditing=(codeContext<> CodeContext.Editing)&&(m=range0||m=rangeStartup||m= rangeCmdArgs)
5225+
letisArgParameterWhileNotEditing=(codeContext<> CodeContext.Editing)&&(Range.equals mrange0||Range.equals mrangeStartup||Range.equals m rangeCmdArgs)
52205226
letisThisFileName=(0= String.Compare(rootFilename, m.FileName, StringComparison.OrdinalIgnoreCase))
52215227
isArgParameterWhileNotEditing|| isThisFileName
52225228
| None->true

‎src/fsharp/ErrorLogger.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ let inline protectAssemblyExplorationNoReraise dflt1 dflt2 f =
125125

126126
// Attach a range if this is a range dual exception.
127127
let recAttachRange m(exn:exn)=
128-
ifm= range0then exn
128+
ifRange.equals m range0then exn
129129
else
130130
match exnwith
131131
// Strip TargetInvocationException wrappers

‎src/fsharp/NameResolution.fs‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ let AddResults res1 res2 =
898898
| Exception_,Result l-> Result l
899899
| Result x,Exception_-> Result x
900900
// If we have error messages for the same symbol, then we can merge suggestions.
901-
| Exception(UndefinedName(n1,f,id1,suggestions1)),Exception(UndefinedName(n2,_,id2,suggestions2))when n1= n2&& id1.idText= id2.idText&& id1.idRange= id2.idRange->
901+
| Exception(UndefinedName(n1,f,id1,suggestions1)),Exception(UndefinedName(n2,_,id2,suggestions2))when n1= n2&& id1.idText= id2.idText&&Range.equalsid1.idRange id2.idRange->
902902
letsuggestions= HashSet(suggestions1())
903903
suggestions.UnionWith(suggestions2())
904904
Exception(UndefinedName(n1,f,id1,fun()-> suggestions))
@@ -1354,8 +1354,10 @@ let tyconRefDefnEq g (eref1:EntityRef) (eref2: EntityRef) =
13541354
tyconRefEq g eref1 eref2||
13551355

13561356
// Signature items considered equal to implementation items
1357-
eref1.DefinitionRange<> Range.rangeStartup&& eref1.DefinitionRange<> Range.range0&& eref1.DefinitionRange<> Range.rangeCmdArgs&&
1358-
(eref1.DefinitionRange= eref2.DefinitionRange|| eref1.SigRange= eref2.SigRange)&&
1357+
not(Range.equals eref1.DefinitionRange Range.rangeStartup)&&
1358+
not(Range.equals eref1.DefinitionRange Range.range0)&&
1359+
not(Range.equals eref1.DefinitionRange Range.rangeCmdArgs)&&
1360+
(Range.equals eref1.DefinitionRange eref2.DefinitionRange|| Range.equals eref1.SigRange eref2.SigRange)&&
13591361
eref1.LogicalName= eref2.LogicalName
13601362

13611363
letvalRefDefnHash(_g:TcGlobals)(vref1:ValRef)=
@@ -1365,8 +1367,10 @@ let valRefDefnEq g (vref1:ValRef) (vref2: ValRef) =
13651367
valRefEq g vref1 vref2||
13661368

13671369
// Signature items considered equal to implementation items
1368-
vref1.DefinitionRange<> Range.rangeStartup&& vref1.DefinitionRange<> Range.range0&& vref1.DefinitionRange<> Range.rangeCmdArgs&&
1369-
(vref1.DefinitionRange= vref2.DefinitionRange|| vref1.SigRange= vref2.SigRange)&&
1370+
not(Range.equals vref1.DefinitionRange Range.rangeStartup)&&
1371+
not(Range.equals vref1.DefinitionRange Range.range0)&&
1372+
not(Range.equals vref1.DefinitionRange Range.rangeCmdArgs)&&
1373+
(Range.equals vref1.DefinitionRange vref2.DefinitionRange|| Range.equals vref1.SigRange vref2.SigRange)&&
13701374
vref1.LogicalName= vref2.LogicalName
13711375

13721376
letunionCaseRefDefnEq g(uc1:UnionCaseRef)(uc2:UnionCaseRef)=
@@ -1385,7 +1389,7 @@ let ItemsAreEffectivelyEqual g orig other =
13851389
| TType_var tp1, TType_var tp2->
13861390
not tp1.IsCompilerGenerated&&not tp1.IsFromError&&
13871391
not tp2.IsCompilerGenerated&&not tp2.IsFromError&&
1388-
tp1.Range= tp2.Range
1392+
Range.equalstp1.Range tp2.Range
13891393
| AbbrevOrAppTy tcref1, AbbrevOrAppTy tcref2->
13901394
tyconRefDefnEq g tcref1 tcref2
13911395
|_->false)
@@ -1394,7 +1398,7 @@ let ItemsAreEffectivelyEqual g orig other =
13941398
valRefDefnEq g vref1 vref2
13951399

13961400
| ActivePatternCaseUse(range1, range1i, idx1), ActivePatternCaseUse(range2, range2i, idx2)->
1397-
(idx1= idx2)&&(range1=range2||range1i= range2i)
1401+
(idx1= idx2)&&(Range.equalsrange1 range2||Range.equals range1i range2i)
13981402

13991403
| MethodUse minfo1, MethodUse minfo2->
14001404
MethInfo.MethInfosUseIdenticalDefinitions minfo1 minfo2||
@@ -1411,10 +1415,10 @@ let ItemsAreEffectivelyEqual g orig other =
14111415
|_->false
14121416

14131417
| Item.ArgName(id1,_,_), Item.ArgName(id2,_,_)->
1414-
(id1.idText= id2.idText&& id1.idRange= id2.idRange)
1418+
(id1.idText= id2.idText&&Range.equalsid1.idRange id2.idRange)
14151419

14161420
|(Item.ArgName(id,_,_), ValUse vref)|(ValUse vref, Item.ArgName(id,_,_))->
1417-
((id.idRange=vref.DefinitionRange|| id.idRange= vref.SigRange)&& id.idText= vref.DisplayName)
1421+
((Range.equalsid.idRange vref.DefinitionRange||Range.equalsid.idRange vref.SigRange)&& id.idText= vref.DisplayName)
14181422

14191423
| Item.AnonRecdField(anon1,_, i1,_), Item.AnonRecdField(anon2,_, i2,_)-> Tastops.anonInfoEquiv anon1 anon2&& i1= i2
14201424

@@ -1530,7 +1534,7 @@ type TcResultsSinkImpl(g, ?sourceText: ISourceText) =
15301534
new System.Collections.Generic.HashSet<range* Item>
15311535
({new IEqualityComparer<range* Item>with
15321536
member__.GetHashCode((m,_))= hash m
1533-
member__.Equals((m1, item1),(m2, item2))=m1= m2&& ItemsAreEffectivelyEqual g item1 item2})
1537+
member__.Equals((m1, item1),(m2, item2))=Range.equals m1 m2&& ItemsAreEffectivelyEqual g item1 item2})
15341538

15351539
letcapturedMethodGroupResolutions= ResizeArray<_>()
15361540
letcapturedOpenDeclarations= ResizeArray<OpenDeclaration>()
@@ -1576,8 +1580,8 @@ type TcResultsSinkImpl(g, ?sourceText: ISourceText) =
15761580
// for the same identifier at the same location.
15771581
if allowedRange mthen
15781582
if replacethen
1579-
capturedNameResolutions.RemoveAll(fun cnr-> cnr.Range= m)|> ignore
1580-
capturedMethodGroupResolutions.RemoveAll(fun cnr-> cnr.Range= m)|> ignore
1583+
capturedNameResolutions.RemoveAll(fun cnr->Range.equalscnr.Range m)|> ignore
1584+
capturedMethodGroupResolutions.RemoveAll(fun cnr->Range.equalscnr.Range m)|> ignore
15811585
else
15821586
letalreadyDone=
15831587
match itemwith
@@ -1841,7 +1845,7 @@ let rec ResolveLongIndentAsModuleOrNamespace sink atMostOne amap m first fullyQu
18411845
let mutablemoduleNotFoundErrorCache= None
18421846
letmoduleNotFound(modref:ModuleOrNamespaceRef)(mty:ModuleOrNamespaceType)(id:Ident)depth=
18431847
match moduleNotFoundErrorCachewith
1844-
| Some(oldId, error)whenoldId= id.idRange-> error
1848+
| Some(oldId, error)whenRange.equals oldId id.idRange-> error
18451849
|_->
18461850
letsuggestNames()=
18471851
mty.ModulesAndNamespacesByDemangledName
@@ -2593,7 +2597,7 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) first fullyQualified
25932597
}|> HashSet
25942598

25952599
match innerSearchwith
2596-
| Exception(UndefinedName(0,_,id1,suggestionsF))when id.idRange= id1.idRange->
2600+
| Exception(UndefinedName(0,_,id1,suggestionsF))whenRange.equalsid.idRange id1.idRange->
25972601
letmergeSuggestions()=
25982602
letres= suggestEverythingInScope()
25992603
res.UnionWith(suggestionsF())
@@ -3281,7 +3285,7 @@ let ResolveLongIdentAsExprAndComputeRange (sink:TcResultsSink) (ncenv:NameResolv
32813285
match lidwith
32823286
|[]|[_]->false
32833287
| head:: ids->
3284-
ids|> List.forall(fun id-> id.idRange= head.idRange)
3288+
ids|> List.forall(fun id->Range.equalsid.idRange head.idRange)
32853289

32863290
letcallSink(refinedItem,tpinst)=
32873291
ifnot isFakeIdentsthen

‎src/fsharp/PatternMatchCompilation.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ let rec CompilePattern g denv amap exprm matchm warnOnUnused actionOnFailure (o
13311331
// If the remainder of the match boiled away to nothing interesting.
13321332
// We measure this simply by seeing if the range of the resulting expression is identical to matchm.
13331333
letspTarget=
1334-
if expr.Range= matchmthen SuppressSequencePointAtTarget
1334+
ifRange.equalsexpr.Range matchmthen SuppressSequencePointAtTarget
13351335
else SequencePointAtTarget
13361336

13371337
// Make the clause that represents the remaining cases of the pattern match

‎src/fsharp/TypeChecker.fs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -671,22 +671,22 @@ let ShrinkContext env oldRange newRange =
671671
| ContextInfo.SequenceExpression _ ->
672672
env
673673
| ContextInfo.CollectionElement (b,m) ->
674-
ifm <>oldRange then env else
674+
ifnot (Range.equals moldRange) then env else
675675
{ env with eContextInfo = ContextInfo.CollectionElement(b,newRange) }
676676
| ContextInfo.FollowingPatternMatchClause m ->
677-
ifm <>oldRange then env else
677+
ifnot (Range.equals moldRange) then env else
678678
{ env with eContextInfo = ContextInfo.FollowingPatternMatchClause newRange }
679679
| ContextInfo.PatternMatchGuard m ->
680-
ifm <>oldRange then env else
680+
ifnot (Range.equals moldRange) then env else
681681
{ env with eContextInfo = ContextInfo.PatternMatchGuard newRange }
682682
| ContextInfo.IfExpression m ->
683-
ifm <>oldRange then env else
683+
ifnot (Range.equals moldRange) then env else
684684
{ env with eContextInfo = ContextInfo.IfExpression newRange }
685685
| ContextInfo.OmittedElseBranch m ->
686-
ifm <>oldRange then env else
686+
ifnot (Range.equals moldRange) then env else
687687
{ env with eContextInfo = ContextInfo.OmittedElseBranch newRange }
688688
| ContextInfo.ElseBranchResult m ->
689-
ifm <>oldRange then env else
689+
ifnot (Range.equals moldRange) then env else
690690
{ env with eContextInfo = ContextInfo.ElseBranchResult newRange }
691691

692692
/// Optimized unification routine that avoids creating new inference
@@ -11572,7 +11572,7 @@ and AnalyzeAndMakeAndPublishRecursiveValue overridesOK isGeneratedEventVal cenv
1157211572

1157311573
// Suppress hover tip for "get" and "set" at property definitions, where toolId <> bindingId
1157411574
match toolIdOpt with
11575-
| Some tid when not tid.idRange.IsSynthetic && tid.idRange<>bindingId.idRange ->
11575+
| Some tid when not tid.idRange.IsSynthetic &&not (Range.equalstid.idRange bindingId.idRange) ->
1157611576
let item = Item.Value (mkLocalValRef vspec)
1157711577
CallNameResolutionSink cenv.tcSink (tid.idRange, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.RelatedText, env.DisplayEnv, env.eAccessRights)
1157811578
| _ -> ()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp