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

Commitf69dcf4

Browse files
forkiKevinRansom
authored andcommitted
Try to cleanup +++ (dotnet#4556)
1 parent9b1570f commitf69dcf4

File tree

1 file changed

+63
-134
lines changed

1 file changed

+63
-134
lines changed

‎src/fsharp/NameResolution.fs‎

Lines changed: 63 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,6 @@ let AddResults res1 res2 =
909909
| Exception(Error_),Exception(UndefinedName_as e2)-> Exception e2
910910
| Exception e1,Exception_-> Exception e1
911911

912-
let(+++)x y= AddResults x y
913912
letNoResultsOrUsefulErrors= Result[]
914913

915914
/// Indicates if we only need one result or all possible results from a resolution.
@@ -944,7 +943,15 @@ let AtMostOneResult m res =
944943
match reswith
945944
| Exception err-> raze err
946945
| Result[]-> raze(Error(FSComp.SR.nrInvalidModuleExprType(),m))
947-
| Result(res::_)-> success res
946+
| Result(res::_)-> success res
947+
948+
letAtMostOneResultQuery query2 res1=
949+
match res1with
950+
| Exception_-> AddResults res1(query2())
951+
| Result[]-> query2()
952+
|_-> res1
953+
954+
let inline(+++)res1 query2= AtMostOneResultQuery query2 res1
948955

949956
//-------------------------------------------------------------------------
950957
// TypeNameResolutionInfo
@@ -2274,12 +2281,9 @@ let rec ResolveExprLongIdentInModuleOrNamespace (ncenv:NameResolver) nenv (typeN
22742281
|> CollectAtMostOneResult(fun(resInfo,typ)-> ResolveObjectConstructorPrim ncenv nenv.eDisplayEnv resInfo id.idRange ad typ)
22752282
|> MapResults(fun(resInfo,item)->(resInfo,item,[]))
22762283

2277-
match tyconSearchwith
2278-
| Result(res::_)-> success res
2279-
|_->
22802284

22812285
// Something in a sub-namespace or sub-module
2282-
letmoduleSearch=
2286+
letmoduleSearch()=
22832287
match restwith
22842288
| id2::rest2->
22852289
match mty.ModulesAndNamespacesByDemangledName.TryFind(id.idText)with
@@ -2292,7 +2296,7 @@ let rec ResolveExprLongIdentInModuleOrNamespace (ncenv:NameResolver) nenv (typeN
22922296
|_->
22932297
NoResultsOrUsefulErrors
22942298

2295-
match tyconSearch+++ moduleSearch+++ unionSearchwith
2299+
match tyconSearch+++ moduleSearch+++(fun _->unionSearch)with
22962300
| Result[]->
22972301
letsuggestPossibleTypesAndNames()=
22982302
lettypes=
@@ -2402,11 +2406,7 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) first fullyQualified
24022406
lettcrefs= LookupTypeNameInEnvMaybeHaveArity fullyQualified id.idText typeNameResInfo nenv
24032407
ChooseTyconRefInExpr(ncenv, m, ad, nenv, id, typeNameResInfo, resInfo, tcrefs)
24042408

2405-
match ctorSearchwith
2406-
| Result reswhennot(isNil res)-> ctorSearch
2407-
|_->
2408-
2409-
letimplicitOpSearch=
2409+
letimplicitOpSearch()=
24102410
if IsMangledOpName id.idTextthen
24112411
success[(resInfo,Item.ImplicitOp(id, ref None),[])]
24122412
else
@@ -2485,13 +2485,13 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) first fullyQualified
24852485
else
24862486
// Otherwise modules are searched first. REVIEW: modules and types should be searched together.
24872487
// For each module referenced by 'id', search the module as if it were an F# module and/or a .NET namespace.
2488-
letmoduleSearch ad=
2488+
letmoduleSearch ad()=
24892489
ResolveLongIndentAsModuleOrNamespaceThen sink ResultCollectionSettings.AtMostOneResult ncenv.amap m fullyQualified nenv ad id rest isOpenDecl
24902490
(ResolveExprLongIdentInModuleOrNamespace ncenv nenv typeNameResInfo ad)
24912491

24922492
// REVIEW: somewhat surprisingly, this shows up on performance traces, with tcrefs non-nil.
24932493
// This seems strange since we would expect in the vast majority of cases tcrefs is empty here.
2494-
lettyconSearch ad=
2494+
lettyconSearch ad()=
24952495
lettcrefs= LookupTypeNameInEnvNoArity fullyQualified id.idText nenv
24962496
if isNil tcrefsthen NoResultsOrUsefulErrorselse
24972497
match restwith
@@ -2503,19 +2503,7 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) first fullyQualified
25032503
NoResultsOrUsefulErrors
25042504

25052505
letsearch=
2506-
letmoduleSearch= moduleSearch ad
2507-
2508-
match moduleSearchwith
2509-
| Result reswhennot(isNil res)-> moduleSearch
2510-
|_->
2511-
2512-
lettyconSearch= tyconSearch ad
2513-
2514-
match tyconSearchwith
2515-
| Result reswhennot(isNil res)-> tyconSearch
2516-
|_->
2517-
2518-
letenvSearch=
2506+
letenvSearch()=
25192507
match fullyQualifiedwith
25202508
| FullyQualified->
25212509
NoResultsOrUsefulErrors
@@ -2524,27 +2512,14 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) first fullyQualified
25242512
| Some(Item.UnqualifiedType_)
25252513
| None-> NoResultsOrUsefulErrors
25262514
| Some res-> OneSuccess(resInfo,FreshenUnqualifiedItem ncenv m res,rest)
2527-
2528-
moduleSearch+++ tyconSearch+++ envSearch
2515+
2516+
moduleSearchad()+++ tyconSearch ad+++ envSearch
25292517

25302518
letresInfo,item,rest=
25312519
match AtMostOneResult m searchwith
25322520
| Result_as res-> ForceRaise res
25332521
|_->
2534-
letinnerSearch=
2535-
letmoduleSearch= moduleSearch AccessibleFromSomeFSharpCode
2536-
2537-
match moduleSearchwith
2538-
| Result reswhennot(isNil res)-> moduleSearch
2539-
|_->
2540-
2541-
lettyconSearch= tyconSearch AccessibleFromSomeFSharpCode
2542-
2543-
match tyconSearchwith
2544-
| Result reswhennot(isNil res)-> tyconSearch
2545-
|_->
2546-
2547-
search+++ moduleSearch+++ tyconSearch
2522+
letinnerSearch= search+++(moduleSearch AccessibleFromSomeFSharpCode)+++(tyconSearch AccessibleFromSomeFSharpCode)
25482523

25492524
letsuggestEverythingInScope()=
25502525
seq{yield!
@@ -2610,7 +2585,7 @@ let rec ResolvePatternLongIdentInModuleOrNamespace (ncenv:NameResolver) nenv num
26102585
success(resInfo,Item.ActivePatternCase apref,rest)
26112586
|_->
26122587
match mty.AllValsByLogicalName.TryFind(id.idText)with
2613-
| Some vspecwhen IsValAccessible ad(mkNestedValRef modref vspec)->
2588+
| Some vspecwhen IsValAccessible ad(mkNestedValRef modref vspec)->
26142589
success(resInfo,Item.Value(mkNestedValRef modref vspec),rest)
26152590
|_->
26162591
lettcrefs=lazy(
@@ -2626,12 +2601,8 @@ let rec ResolvePatternLongIdentInModuleOrNamespace (ncenv:NameResolver) nenv num
26262601
|_->
26272602
NoResultsOrUsefulErrors
26282603

2629-
match tyconSearchwith
2630-
| Result(res::_)-> success res
2631-
|_->
2632-
26332604
// Constructor of a type?
2634-
letctorSearch=
2605+
letctorSearch()=
26352606
if isNil restthen
26362607
tcrefs.Force()
26372608
|> List.map(fun(resInfo,tcref)->(resInfo,FreshenTycon ncenv m tcref))
@@ -2640,12 +2611,8 @@ let rec ResolvePatternLongIdentInModuleOrNamespace (ncenv:NameResolver) nenv num
26402611
else
26412612
NoResultsOrUsefulErrors
26422613

2643-
match ctorSearchwith
2644-
| Result(res::_)-> success res
2645-
|_->
2646-
26472614
// Something in a sub-namespace or sub-module or nested-type
2648-
letmoduleSearch=
2615+
letmoduleSearch()=
26492616
match restwith
26502617
| id2::rest2->
26512618
match mty.ModulesAndNamespacesByDemangledName.TryFind(id.idText)with
@@ -2693,23 +2660,23 @@ let rec ResolvePatternLongIdentPrim sink (ncenv:NameResolver) fullyQualified war
26932660
else
26942661
// Single identifiers in patterns
26952662
if isNil rest&& fullyQualified<> FullyQualifiedthen
2696-
// Single identifiers in patterns - bind to constructors and active patterns
2697-
// For the special case of
2698-
// let C = x
2699-
match nenv.ePatItems.TryFind(id.idText)with
2700-
| Some reswhennot newDef-> FreshenUnqualifiedItem ncenv m res
2701-
|_->
2702-
// Single identifiers in patterns - variable bindings
2703-
ifnot newDef&&
2704-
(warnOnUpper= WarnOnUpperCase)&&
2705-
id.idText.Length>=3&&
2706-
System.Char.ToLowerInvariant id.idText.[0]<> id.idText.[0]then
2707-
warning(UpperCaseIdentifierInPattern(m))
2708-
Item.NewDef id
2709-
2663+
// Single identifiers in patterns - bind to constructors and active patterns
2664+
// For the special case of
2665+
// let C = x
2666+
match nenv.ePatItems.TryFind(id.idText)with
2667+
| Some reswhennot newDef-> FreshenUnqualifiedItem ncenv m res
2668+
|_->
2669+
// Single identifiers in patterns - variable bindings
2670+
ifnot newDef&&
2671+
(warnOnUpper= WarnOnUpperCase)&&
2672+
id.idText.Length>=3&&
2673+
System.Char.ToLowerInvariant id.idText.[0]<> id.idText.[0]then
2674+
warning(UpperCaseIdentifierInPattern(m))
2675+
Item.NewDef id
2676+
27102677
// Long identifiers in patterns
27112678
else
2712-
letmoduleSearch ad=
2679+
letmoduleSearch ad()=
27132680
ResolveLongIndentAsModuleOrNamespaceThen sink ResultCollectionSettings.AtMostOneResult ncenv.amap m fullyQualified nenv ad id restfalse
27142681
(ResolvePatternLongIdentInModuleOrNamespace ncenv nenv numTyArgsOpt ad)
27152682

@@ -2724,25 +2691,13 @@ let rec ResolvePatternLongIdentPrim sink (ncenv:NameResolver) fullyQualified war
27242691
NoResultsOrUsefulErrors
27252692

27262693
letresInfo,res,rest=
2727-
lettyconResult= tyconSearch ad
2728-
match tyconResultwith
2729-
| Result(res::_)-> res
2730-
|_->
2731-
2732-
letmoduleResult= moduleSearch ad
2733-
match moduleResultwith
2734-
| Result(res::_)-> res
2735-
|_->
2736-
2737-
match AtMostOneResult m(tyconResult+++ moduleResult)with
2694+
match AtMostOneResult m(tyconSearch ad+++(moduleSearch ad))with
27382695
| Result_as res-> ForceRaise res
27392696
|_->
27402697

2741-
lettyconResult= tyconSearch AccessibleFromSomeFSharpCode
2742-
match tyconResultwith
2743-
| Result(res::_)-> res
2744-
|_->
2745-
ForceRaise(AtMostOneResult m(tyconResult+++ moduleSearch AccessibleFromSomeFSharpCode))
2698+
tyconSearch AccessibleFromSomeFSharpCode+++(moduleSearch AccessibleFromSomeFSharpCode)
2699+
|> AtMostOneResult m
2700+
|> ForceRaise
27462701

27472702
ResolutionInfo.SendEntityPathToSink(sink,ncenv,nenv,ItemOccurence.Use,ad,resInfo,ResultTyparChecker(fun()->true))
27482703

@@ -2880,7 +2835,8 @@ let rec private ResolveTypeLongIdentInModuleOrNamespace sink nenv (ncenv:NameRes
28802835
|> HashSet
28812836

28822837
raze(UndefinedName(depth,FSComp.SR.undefinedNameType,id,suggestTypes))
2883-
tyconSearch+++ modulSearch
2838+
2839+
AddResults tyconSearch modulSearch
28842840

28852841
/// Resolve a long identifier representing a type
28862842
let recResolveTypeLongIdentPrim sink(ncenv:NameResolver)occurence first fullyQualified m nenv ad(id:Ident)(rest:Ident list)(staticResInfo:TypeNameResolutionStaticArgsInfo)genOk=
@@ -2945,7 +2901,7 @@ let rec ResolveTypeLongIdentPrim sink (ncenv:NameResolver) occurence first fully
29452901
(ResolveTypeLongIdentInModuleOrNamespace sink nenv ncenv typeNameResInfo.DropStaticArgsInfo AccessibleFromSomeFSharpCode genOk)
29462902
|?> List.concat
29472903

2948-
letsearchSoFar=tyconSearch+++ modulSearch
2904+
letsearchSoFar=AddResults tyconSearch modulSearch
29492905

29502906
match searchSoFarwith
29512907
| Result results->
@@ -2958,11 +2914,12 @@ let rec ResolveTypeLongIdentPrim sink (ncenv:NameResolver) occurence first fully
29582914
success(resInfo,tcref)
29592915
|[]->
29602916
// failing case - report nice ambiguity errors even in this case
2961-
AtMostOneResult m2((searchSoFar+++ modulSearchFailed())|?>(fun tcrefs-> CheckForTypeLegitimacyAndMultipleGenericTypeAmbiguities(tcrefs, typeNameResInfo, genOk, m)))
2962-
2917+
letr= AddResults searchSoFar(modulSearchFailed())
2918+
AtMostOneResult m2(r|?>(fun tcrefs-> CheckForTypeLegitimacyAndMultipleGenericTypeAmbiguities(tcrefs, typeNameResInfo, genOk, m)))
29632919
|_->
29642920
// failing case - report nice ambiguity errors even in this case
2965-
AtMostOneResult m2((searchSoFar+++ modulSearchFailed())|?>(fun tcrefs-> CheckForTypeLegitimacyAndMultipleGenericTypeAmbiguities(tcrefs, typeNameResInfo, genOk, m)))
2921+
letr= AddResults searchSoFar(modulSearchFailed())
2922+
AtMostOneResult m2(r|?>(fun tcrefs-> CheckForTypeLegitimacyAndMultipleGenericTypeAmbiguities(tcrefs, typeNameResInfo, genOk, m)))
29662923

29672924

29682925
/// Resolve a long identifier representing a type and report it
@@ -3000,12 +2957,8 @@ let rec ResolveFieldInModuleOrNamespace (ncenv:NameResolver) nenv ad (resInfo:Re
30002957
success[resInfo, FieldResolution(modref.RecdFieldRefInNestedTycon tycon id,showDeprecated), rest]
30012958
|_-> raze(UndefinedName(depth,FSComp.SR.undefinedNameRecordLabelOrNamespace,id,NoSuggestions))
30022959

3003-
match modulScopedFieldNameswith
3004-
| Result(res::_)-> success res
3005-
|_->
3006-
30072960
// search for type-qualified names, e.g. { Microsoft.FSharp.Core.Ref.contents = 1 }
3008-
lettyconSearch=
2961+
lettyconSearch()=
30092962
match restwith
30102963
| id2::rest2->
30112964
lettcrefs= LookupTypeNameInEntityMaybeHaveArity(ncenv.amap, id.idRange, ad, id.idText, TypeNameResolutionStaticArgsInfo.Indefinite, modref)
@@ -3018,12 +2971,8 @@ let rec ResolveFieldInModuleOrNamespace (ncenv:NameResolver) nenv ad (resInfo:Re
30182971
|_->
30192972
NoResultsOrUsefulErrors
30202973

3021-
match tyconSearchwith
3022-
| Result(res::_)-> success res
3023-
|_->
3024-
30252974
// search for names in nested modules, e.g. { Microsoft.FSharp.Core.contents = 1 }
3026-
letmodulSearch=
2975+
letmodulSearch()=
30272976
match restwith
30282977
| id2::rest2->
30292978
match modref.ModuleOrNamespaceType.ModulesAndNamespacesByDemangledName.TryFind(id.idText)with
@@ -3033,8 +2982,9 @@ let rec ResolveFieldInModuleOrNamespace (ncenv:NameResolver) nenv ad (resInfo:Re
30332982
|> OneResult
30342983
|_-> raze(UndefinedName(depth,FSComp.SR.undefinedNameRecordLabelOrNamespace,id,NoSuggestions))
30352984
|_-> raze(UndefinedName(depth,FSComp.SR.undefinedNameRecordLabelOrNamespace,id,NoSuggestions))
3036-
3037-
AtMostOneResult m(modulScopedFieldNames+++ tyconSearch+++ modulSearch)
2985+
2986+
modulScopedFieldNames+++ tyconSearch+++ modulSearch
2987+
|> AtMostOneResult m
30382988

30392989
/// Suggest other labels of the same record
30402990
letSuggestOtherLabelsOfSameRecordType g(nenv:NameResolutionEnv)typ(id:Ident)(allFields:Ident list)=
@@ -3134,7 +3084,7 @@ let ResolveFieldPrim sink (ncenv:NameResolver) nenv ad typ (mp,id:Ident) allFiel
31343084
lookup()
31353085
|_->
31363086
letlid=(mp@[id])
3137-
lettyconSearch ad=
3087+
lettyconSearch ad()=
31383088
match lidwith
31393089
| tn:: id2:: rest2->
31403090
letm= tn.idRange
@@ -3147,37 +3097,18 @@ let ResolveFieldPrim sink (ncenv:NameResolver) nenv ad typ (mp,id:Ident) allFiel
31473097
tyconSearch
31483098
|_-> NoResultsOrUsefulErrors
31493099

3150-
letmodulSearch ad=
3100+
letmodulSearch ad()=
31513101
match lidwith
31523102
|[]-> NoResultsOrUsefulErrors
31533103
| id2::rest2->
31543104
ResolveLongIndentAsModuleOrNamespaceThen sink ResultCollectionSettings.AtMostOneResult ncenv.amap m OpenQualified nenv ad id2 rest2false
31553105
(ResolveFieldInModuleOrNamespace ncenv nenv ad)
31563106

3157-
letsearch=
3158-
letmoduleSearch1= modulSearch ad
3159-
3160-
match moduleSearch1with
3161-
| Result(res::_)-> success res
3162-
|_->
3163-
3164-
lettyconSearch1= tyconSearch ad
3165-
3166-
match tyconSearch1with
3167-
| Result(res::_)-> success res
3168-
|_->
3169-
3170-
letmoduleSearch2= modulSearch AccessibleFromSomeFSharpCode
3171-
3172-
match moduleSearch2with
3173-
| Result(res::_)-> success res
3174-
|_->
3107+
letresInfo,item,rest=
3108+
modulSearch ad()+++ tyconSearch ad+++ modulSearch AccessibleFromSomeFSharpCode+++ tyconSearch AccessibleFromSomeFSharpCode
3109+
|> AtMostOneResult m
3110+
|> ForceRaise
31753111

3176-
lettyconSearch2= tyconSearch AccessibleFromSomeFSharpCode
3177-
3178-
AtMostOneResult m(moduleSearch1+++ tyconSearch1+++ moduleSearch2+++ tyconSearch2)
3179-
3180-
letresInfo,item,rest= ForceRaise search
31813112
ifnot(isNil rest)then
31823113
errorR(Error(FSComp.SR.nrInvalidFieldLabel(),(List.head rest).idRange))
31833114

@@ -3198,7 +3129,6 @@ let FreshenRecdFieldRef (ncenv:NameResolver) m (rfref:RecdFieldRef) =
31983129
Item.RecdField(RecdFieldInfo(ncenv.InstantiationGenerator m(rfref.Tycon.Typars m), rfref))
31993130

32003131

3201-
32023132
/// Resolve F#/IL "." syntax in expressions (2).
32033133
///
32043134
/// We have an expr. on the left, and we do an access, e.g.
@@ -3228,12 +3158,11 @@ let private ResolveExprDotLongIdent (ncenv:NameResolver) m ad nenv typ (id:Ident
32283158
OneSuccess(ResolutionInfo.Empty,item,rest)
32293159
|_-> NoResultsOrUsefulErrors
32303160

3231-
letsearch= dotFieldIdSearch
3232-
match AtMostOneResult m searchwith
3233-
| Result_as res-> ForceRaise res
3234-
|_->
3235-
letadhocDotSearchAll= ResolveLongIdentInTypePrim ncenv nenv LookupKind.Expr ResolutionInfo.Empty1 m AccessibleFromSomeFSharpCode id rest findFlag typeNameResInfo typ
3236-
ForceRaise(AtMostOneResult m(search+++ adhocDotSearchAll))
3161+
letadhocDotSearchAll()= ResolveLongIdentInTypePrim ncenv nenv LookupKind.Expr ResolutionInfo.Empty1 m AccessibleFromSomeFSharpCode id rest findFlag typeNameResInfo typ
3162+
3163+
dotFieldIdSearch+++ adhocDotSearchAll
3164+
|> AtMostOneResult m
3165+
|> ForceRaise
32373166
|_->
32383167
ForceRaise adhoctDotSearchAccessible
32393168

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp