@@ -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
913912let NoResultsOrUsefulErrors = 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 =
944943match 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+ let AtMostOneResultQuery 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- let moduleSearch =
2286+ let moduleSearch () =
22832287match restwith
22842288| id2:: rest2->
22852289match 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[] ->
22972301let suggestPossibleTypesAndNames () =
22982302let types =
@@ -2402,11 +2406,7 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) first fullyQualified
24022406let tcrefs = LookupTypeNameInEnvMaybeHaveArity fullyQualified id.idText typeNameResInfo nenv
24032407 ChooseTyconRefInExpr( ncenv, m, ad, nenv, id, typeNameResInfo, resInfo, tcrefs)
24042408
2405- match ctorSearchwith
2406- | Result reswhen not ( isNil res) -> ctorSearch
2407- | _ ->
2408-
2409- let implicitOpSearch =
2409+ let implicitOpSearch () =
24102410if IsMangledOpName id.idTextthen
24112411 success[( resInfo, Item.ImplicitOp( id, ref None),[])]
24122412else
@@ -2485,13 +2485,13 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) first fullyQualified
24852485else
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- let moduleSearch ad =
2488+ let moduleSearch 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- let tyconSearch ad =
2494+ let tyconSearch ad () =
24952495let tcrefs = LookupTypeNameInEnvNoArity fullyQualified id.idText nenv
24962496if isNil tcrefsthen NoResultsOrUsefulErrorselse
24972497match restwith
@@ -2503,19 +2503,7 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) first fullyQualified
25032503 NoResultsOrUsefulErrors
25042504
25052505let search =
2506- let moduleSearch = moduleSearch ad
2507-
2508- match moduleSearchwith
2509- | Result reswhen not ( isNil res) -> moduleSearch
2510- | _ ->
2511-
2512- let tyconSearch = tyconSearch ad
2513-
2514- match tyconSearchwith
2515- | Result reswhen not ( isNil res) -> tyconSearch
2516- | _ ->
2517-
2518- let envSearch =
2506+ let envSearch () =
25192507match 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
25302518let resInfo , item , rest =
25312519match AtMostOneResult m searchwith
25322520| Result_ as res-> ForceRaise res
25332521| _ ->
2534- let innerSearch =
2535- let moduleSearch = moduleSearch AccessibleFromSomeFSharpCode
2536-
2537- match moduleSearchwith
2538- | Result reswhen not ( isNil res) -> moduleSearch
2539- | _ ->
2540-
2541- let tyconSearch = tyconSearch AccessibleFromSomeFSharpCode
2542-
2543- match tyconSearchwith
2544- | Result reswhen not ( isNil res) -> tyconSearch
2545- | _ ->
2546-
2547- search+++ moduleSearch+++ tyconSearch
2522+ let innerSearch = search+++ ( moduleSearch AccessibleFromSomeFSharpCode) +++ ( tyconSearch AccessibleFromSomeFSharpCode)
25482523
25492524let suggestEverythingInScope () =
25502525seq { yield !
@@ -2610,7 +2585,7 @@ let rec ResolvePatternLongIdentInModuleOrNamespace (ncenv:NameResolver) nenv num
26102585 success( resInfo, Item.ActivePatternCase apref, rest)
26112586| _ ->
26122587match 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| _ ->
26162591let tcrefs = 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- let ctorSearch =
2605+ let ctorSearch () =
26352606if 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
26402611else
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- let moduleSearch =
2615+ let moduleSearch () =
26492616match restwith
26502617| id2:: rest2->
26512618match mty.ModulesAndNamespacesByDemangledName.TryFind( id.idText) with
@@ -2693,23 +2660,23 @@ let rec ResolvePatternLongIdentPrim sink (ncenv:NameResolver) fullyQualified war
26932660else
26942661// Single identifiers in patterns
26952662if 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 reswhen not newDef-> FreshenUnqualifiedItem ncenv m res
2701- | _ ->
2702- // Single identifiers in patterns - variable bindings
2703- if not 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 reswhen not newDef-> FreshenUnqualifiedItem ncenv m res
2668+ | _ ->
2669+ // Single identifiers in patterns - variable bindings
2670+ if not 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
27112678else
2712- let moduleSearch ad =
2679+ let moduleSearch 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
27262693let resInfo , res , rest =
2727- let tyconResult = tyconSearch ad
2728- match tyconResultwith
2729- | Result( res:: _) -> res
2730- | _ ->
2731-
2732- let moduleResult = 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- let tyconResult = 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
28862842let rec ResolveTypeLongIdentPrim 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- let searchSoFar = tyconSearch +++ modulSearch
2904+ let searchSoFar = AddResults tyconSearch modulSearch
29492905
29502906match 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+ let r = 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+ let r = 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- let tyconSearch =
2961+ let tyconSearch () =
30092962match restwith
30102963| id2:: rest2->
30112964let tcrefs = 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- let modulSearch =
2975+ let modulSearch () =
30272976match restwith
30282977| id2:: rest2->
30292978match 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
30402990let SuggestOtherLabelsOfSameRecordType 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| _ ->
31363086let lid = ( mp@[ id])
3137- let tyconSearch ad =
3087+ let tyconSearch ad () =
31383088match lidwith
31393089| tn:: id2:: rest2->
31403090let m = tn.idRange
@@ -3147,37 +3097,18 @@ let ResolveFieldPrim sink (ncenv:NameResolver) nenv ad typ (mp,id:Ident) allFiel
31473097 tyconSearch
31483098| _ -> NoResultsOrUsefulErrors
31493099
3150- let modulSearch ad =
3100+ let modulSearch ad () =
31513101match 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- let search =
3158- let moduleSearch1 = modulSearch ad
3159-
3160- match moduleSearch1with
3161- | Result( res:: _) -> success res
3162- | _ ->
3163-
3164- let tyconSearch1 = tyconSearch ad
3165-
3166- match tyconSearch1with
3167- | Result( res:: _) -> success res
3168- | _ ->
3169-
3170- let moduleSearch2 = modulSearch AccessibleFromSomeFSharpCode
3171-
3172- match moduleSearch2with
3173- | Result( res:: _) -> success res
3174- | _ ->
3107+ let resInfo , item , rest =
3108+ modulSearch ad() +++ tyconSearch ad+++ modulSearch AccessibleFromSomeFSharpCode+++ tyconSearch AccessibleFromSomeFSharpCode
3109+ |> AtMostOneResult m
3110+ |> ForceRaise
31753111
3176- let tyconSearch2 = tyconSearch AccessibleFromSomeFSharpCode
3177-
3178- AtMostOneResult m( moduleSearch1+++ tyconSearch1+++ moduleSearch2+++ tyconSearch2)
3179-
3180- let resInfo , item , rest = ForceRaise search
31813112if not ( 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- let search = dotFieldIdSearch
3232- match AtMostOneResult m searchwith
3233- | Result_ as res-> ForceRaise res
3234- | _ ->
3235- let adhocDotSearchAll = ResolveLongIdentInTypePrim ncenv nenv LookupKind.Expr ResolutionInfo.Empty1 m AccessibleFromSomeFSharpCode id rest findFlag typeNameResInfo typ
3236- ForceRaise( AtMostOneResult m( search+++ adhocDotSearchAll))
3161+ let adhocDotSearchAll () = 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