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

Commit8da7286

Browse files
forkiKevinRansom
authored andcommitted
Lot's of small improvements for ConstraintSolver (dotnet#2279)
* formatting* rec not needed* Use a set for lookup* formatting* formatting* Use reduce instead of fold* Use tryAnyParTy* Check isUnitParMeasure* Use HashSet instead of Set* Cleanup* cleanup* cleanup* cleanup* tryDestTyparTy* revert cleanup as requested* More tryDestTyparTy* Cleanup* Cleanup* tryDestFunTy* Using tryDestAppTy* cleanup* Use a set* cleanup* Cleanup* Cleanup* we don't need to check for [],[] twice* tryFullDestAppTy* More tryFullDestAppTy* More tryFullDestAppTy* tryDestAppTy* Simplify the pattern a bit* cleanup* cleanup* Revert "we don't need to check for [],[] twice"This reverts commitdd628c6.* Revert "Simplify the pattern a bit"This reverts commitc54e75f.* use AppTy active pattern* Pattern matching is cool* Use AppTy* Using tryDestAppTy a lot more* tryDestAppTy* cleanup* remove comment - it doesn't refactor* Cleanup* We don't that additional int* Cleanup* Add assert for destArrayTy and destListTy -fixesdotnet#2435* cleanup* directly use TType_app* be more strict in destByrefTy and co* be more strict in destByrefTy and co* revert removed braces* small cleanup* We don't need to do all these searches if we can't find a name* Don't call the searched 3 times* Use pattern matching instead of Length on a list* cleanup
1 parent2eb9a96 commit8da7286

File tree

12 files changed

+790
-733
lines changed

12 files changed

+790
-733
lines changed

‎src/fsharp/AugmentWithHashCompare.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ let MakeBindingsForEqualsAugmentation (g: TcGlobals) (tycon:Tycon) =
10681068
let recTypeDefinitelyHasEquality g ty=
10691069
if isAppTy g ty&& HasFSharpAttribute g g.attrib_NoEqualityAttribute(tcrefOfAppTy g ty).Attribsthen
10701070
false
1071-
elif isTyparTy g ty&&(destTyparTy g ty).Constraints|> List.exists(function TyparConstraint.SupportsEquality_->true|_->false)then
1071+
elif isTyparTy g ty&&(destTyparTy g ty).Constraints|> List.exists(function TyparConstraint.SupportsEquality_->true|_->false)then
10721072
true
10731073
else
10741074
match tywith

‎src/fsharp/ConstraintSolver.fs‎

Lines changed: 357 additions & 332 deletions
Large diffs are not rendered by default.

‎src/fsharp/ConstraintSolver.fsi‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ type ConstraintSolverState =
9494

9595
type ConstraintSolverEnv
9696

97-
val BakedInTraitConstraintNames: string list
97+
val BakedInTraitConstraintNames:Set<string>
9898

9999
val MakeConstraintSolverEnv: ContextInfo-> ConstraintSolverState-> range-> DisplayEnv-> ConstraintSolverEnv
100100

101101
[<Sealed; NoEquality; NoComparison>]
102102
type Trace
103103

104104
type OptionalTrace=
105-
| NoTrace
106-
| WithTraceofTrace
105+
| NoTrace
106+
| WithTraceofTrace
107107

108108
valSimplifyMeasuresInTypeScheme:TcGlobals->bool->Typars->TType->TyparConstraint list->Typars
109109
valSolveTyparEqualsTyp:ConstraintSolverEnv->int->range->OptionalTrace->TType->TType->OperationResult<unit>

‎src/fsharp/ErrorLogger.fs‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,37 +491,53 @@ let ErrorD err = ErrorResult([],err)
491491
letWarnD err= OkResult([err],())
492492
letCompleteD= OkResult([],())
493493
letResultD x= OkResult([],x)
494-
letCheckNoErrorsAndGetWarnings res=match reswith OkResult(warns,_)-> Some warns| ErrorResult_-> None
494+
letCheckNoErrorsAndGetWarnings res=
495+
match reswith
496+
| OkResult(warns,_)-> Some warns
497+
| ErrorResult_-> None
495498

496499
/// The bind in the monad. Stop on first error. Accumulate warnings and continue.
497500
let(++)res f=
498501
match reswith
499502
| OkResult([],res)->(* tailcall*) f res
500503
| OkResult(warns,res)->
501-
beginmatch f reswith
504+
match f reswith
502505
| OkResult(warns2,res2)-> OkResult(warns@warns2, res2)
503506
| ErrorResult(warns2,err)-> ErrorResult(warns@warns2, err)
504-
end
505507
| ErrorResult(warns,err)->
506508
ErrorResult(warns,err)
507509

508510
/// Stop on first error. Accumulate warnings and continue.
509-
let recIterateD f xs=match xswith[]-> CompleteD| h:: t-> f h++(fun()-> IterateD f t)
511+
let recIterateD f xs=
512+
match xswith
513+
|[]-> CompleteD
514+
| h:: t-> f h++(fun()-> IterateD f t)
515+
510516
let recWhileD gd body=if gd()then body()++(fun()-> WhileD gd body)else CompleteD
511-
letMapD f xs=let recloop acc xs=match xswith[]-> ResultD(List.rev acc)| h:: t-> f h++(fun x-> loop(x::acc) t)in loop[] xs
517+
518+
letMapD f xs=
519+
let recloop acc xs=
520+
match xswith
521+
|[]-> ResultD(List.rev acc)
522+
| h:: t-> f h++(fun x-> loop(x::acc) t)
523+
524+
loop[] xs
512525

513526
typeTrackErrorsBuilder()=
514527
memberx.Bind(res,k)= res++ k
515-
memberx.Return(res)= ResultD(res)
516-
memberx.ReturnFrom(res)= res
528+
memberx.Returnres= ResultDres
529+
memberx.ReturnFromres= res
517530
memberx.For(seq,k)= IterateD k seq
518531
memberx.While(gd,k)= WhileD gd k
519532
memberx.Zero()= CompleteD
520533

521534
lettrackErrors= TrackErrorsBuilder()
522535

523536
/// Stop on first error. Accumulate warnings and continue.
524-
letOptionD f xs=match xswith None-> CompleteD| Some(h)-> f h
537+
letOptionD f xs=
538+
match xswith
539+
| None-> CompleteD
540+
| Some h-> f h
525541

526542
/// Stop on first error. Report index
527543
letIterateIdxD f xs=
@@ -540,13 +556,13 @@ let TryD f g =
540556
| ErrorResult(warns,err)->(OkResult(warns,()))++(fun()-> g err)
541557
| res-> res
542558

543-
let recRepeatWhileD ndeep body= body ndeep++(functiontrue-> RepeatWhileD(ndeep+1) body|false-> CompleteD)
559+
let recRepeatWhileD ndeep body= body ndeep++(fun x->if xthenRepeatWhileD(ndeep+1) bodyelse CompleteD)
544560
letAtLeastOneD f l= MapD f l++(fun res-> ResultD(List.exists id res))
545561

546562

547563
// Code below is for --flaterrors flag that is only used by the IDE
548564

549-
letstringThatIsAProxyForANewlineInFlatErrors=new System.String[|char29|]
565+
letstringThatIsAProxyForANewlineInFlatErrors=new System.String[|char29|]
550566

551567
letNewlineifyErrorString(message:string)= message.Replace(stringThatIsAProxyForANewlineInFlatErrors, Environment.NewLine)
552568

‎src/fsharp/InfoReader.fs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ let GetImmediateIntrinsicMethInfosOfType (optFilter,ad) g amap m typ =
7171
letmdefs=(match optFilterwith None-> mdefs.AsList| Some nm-> mdefs.FindByName nm)
7272
mdefs|> List.map(fun mdef-> MethInfo.CreateILMeth(amap, m, typ, mdef))
7373
| FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata->
74-
ifnot(isAppTy g typ)then[]
75-
else SelectImmediateMemberVals g optFilter(TrySelectMemberVal g optFilter typ None)(tcrefOfAppTy g typ)
74+
match tryDestAppTy g typwith
75+
| None->[]
76+
| Some tcref->
77+
SelectImmediateMemberVals g optFilter(TrySelectMemberVal g optFilter typ None) tcref
7678
letminfos= minfos|> List.filter(IsMethInfoAccessible amap m ad)
7779
minfos
7880

@@ -145,13 +147,13 @@ let GetImmediateIntrinsicPropInfosOfType (optFilter,ad) g amap m typ =
145147
letpdefs=match optFilterwith None-> pdefs.AsList| Some nm-> pdefs.LookupByName nm
146148
pdefs|> List.map(fun pd-> ILProp(g,ILPropInfo(tinfo,pd)))
147149
| FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata->
148-
149-
ifnot(isAppTy g typ)then[]
150-
else
150+
match tryDestAppTy g typwith
151+
| None->[]
152+
| Some tcref->
151153
letpropCollector=new PropertyCollector(g,amap,m,typ,optFilter,ad)
152154
SelectImmediateMemberVals g None
153155
(fun membInfo vref-> propCollector.Collect(membInfo,vref); None)
154-
(tcrefOfAppTy g typ)|> ignore
156+
tcref|> ignore
155157
propCollector.Close()
156158

157159
letpinfos= pinfos|> List.filter(IsPropInfoAccessible g amap m ad)

‎src/fsharp/NicePrint.fs‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ module private PrintTypes =
651651
andlayoutAttrib denv(Attrib(_,k,args,_props,_,_,_))=
652652
letargsL= bracketL(layoutAttribArgs denv args)
653653
match kwith
654-
|(ILAttrib(ilMethRef))->
654+
| ILAttribilMethRef->
655655
lettrimmedName=
656656
letname= ilMethRef.EnclosingTypeRef.Name
657657
match String.tryDropSuffix name"Attribute"with
@@ -660,8 +660,7 @@ module private PrintTypes =
660660
lettref= ilMethRef.EnclosingTypeRef
661661
lettref= ILTypeRef.Create(scope= tref.Scope, enclosing=tref.Enclosing, name=trimmedName)
662662
PrintIL.layoutILTypeRef denv tref++ argsL
663-
664-
|(FSAttrib(vref))->
663+
| FSAttrib vref->
665664
// REVIEW: this is not trimming "Attribute"
666665
let_,_,rty,_= GetTypeOfMemberInMemberForm denv.g vref
667666
letrty= GetFSharpViewOfReturnType denv.g rty
@@ -1034,7 +1033,7 @@ module private PrintTypes =
10341033
letlayoutMemberTypeAndConstraints denv argInfos retTy parentTyparTys=
10351034
let_,(parentTyparTys,argInfos,retTy),cxs= PrettyTypes.PrettifyTypesNM1 denv.g(parentTyparTys,argInfos,retTy)
10361035
// Filter out the parent typars, which don't get shown in the member signature
1037-
letcxs= cxs|> List.filter(fun(tp,_)->not(parentTyparTys|> List.exists(fun ty->isTyparTydenv.g ty&&typarEq tp(destTyparTy denv.g ty))))
1036+
letcxs= cxs|> List.filter(fun(tp,_)->not(parentTyparTys|> List.exists(fun ty->match tryDestTyparTydenv.g tywith Some destTypar->typarEq tpdestTypar| None->false)))
10381037
layoutPrettifiedTypesAndConstraints denv argInfos retTy cxs
10391038

10401039
// Layout: type spec - class, datatype, record, abbrev
@@ -1178,12 +1177,10 @@ module private PrintTastMemberOrVals =
11781177
lettprenaming,ptau,cxs= PrettyTypes.PrettifyTypes1 denv.g tau
11791178
letptps=
11801179
tps
1181-
|> generalizeTypars
1182-
// Badly formed code may instantiate rigid declared typars to types, e.g. see bug
1183-
// Hence we double check here that the thing is really a type variable
1184-
|> List.map(instType tprenaming)
1185-
|> List.filter(isAnyParTy denv.g)
1186-
|> List.map(destAnyParTy denv.g)
1180+
|> generalizeTypars
1181+
// Badly formed code may instantiate rigid declared typars to types, e.g. see bug
1182+
// Hence we double check here that the thing is really a type variable
1183+
|> List.choose(instType tprenaming>> tryAnyParTy denv.g)
11871184
layoutNonMemberVal denv(ptps,v,ptau,cxs)
11881185
| Some_->
11891186
layoutMember denv v
@@ -1278,9 +1275,10 @@ module InfoMemberPrinting =
12781275
else emptyL
12791276
letlayout=
12801277
layout^^
1281-
if isAppTy amap.g minfo.EnclosingTypethen
1282-
PrintTypes.layoutTyconRef denv(tcrefOfAppTy amap.g minfo.EnclosingType)
1283-
else
1278+
match tryDestAppTy amap.g minfo.EnclosingTypewith
1279+
| Some tcref->
1280+
PrintTypes.layoutTyconRef denv tcref
1281+
| None->
12841282
PrintTypes.layoutType denv minfo.EnclosingType
12851283
letlayout=
12861284
layout^^

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp