diff --git a/src/absil/illib.fs b/src/absil/illib.fs index 8b87779a75d..bef3fc4f4c8 100644 --- a/src/absil/illib.fs +++ b/src/absil/illib.fs @@ -1133,7 +1133,7 @@ module NameMap = [] module NameMultiMap = let existsInRange f (m: NameMultiMap<'T>) = NameMap.exists (fun _ l -> List.exists f l) m - let find v (m: NameMultiMap<'T>) = match Map.tryFind v m with None -> [] | Some r -> r + let find v (m: NameMultiMap<'T>) = match m.TryGetValue v with true, r -> r | _ -> [] let add v x (m: NameMultiMap<'T>) = NameMap.add v (x :: find v m) m let range (m: NameMultiMap<'T>) = Map.foldBack (fun _ x sofar -> x @ sofar) m [] let rangeReversingEachBucket (m: NameMultiMap<'T>) = Map.foldBack (fun _ x sofar -> List.rev x @ sofar) m [] @@ -1147,7 +1147,7 @@ module NameMultiMap = [] module MultiMap = let existsInRange f (m: MultiMap<_,_>) = Map.exists (fun _ l -> List.exists f l) m - let find v (m: MultiMap<_,_>) = match Map.tryFind v m with None -> [] | Some r -> r + let find v (m: MultiMap<_,_>) = match m.TryGetValue v with true, r -> r | _ -> [] let add v x (m: MultiMap<_,_>) = Map.add v (x :: find v m) m let range (m: MultiMap<_,_>) = Map.foldBack (fun _ x sofar -> x @ sofar) m [] let empty : MultiMap<_,_> = Map.empty @@ -1167,7 +1167,7 @@ type Map<'Key,'Value when 'Key : comparison> with [] type LayeredMultiMap<'Key,'Value when 'Key : equality and 'Key : comparison>(contents : LayeredMap<'Key,'Value list>) = member x.Add (k,v) = LayeredMultiMap(contents.Add(k,v :: x.[k])) - member x.Item with get k = match contents.TryFind k with None -> [] | Some l -> l + member x.Item with get k = match contents.TryGetValue k with true, l -> l | _ -> [] member x.AddAndMarkAsCollapsible (kvs: _[]) = let x = (x,kvs) ||> Array.fold (fun x (KeyValue(k,v)) -> x.Add(k,v)) x.MarkAsCollapsible() diff --git a/src/fsharp/TypeChecker.fs b/src/fsharp/TypeChecker.fs index 4da594ed27f..61cf1098cf6 100755 --- a/src/fsharp/TypeChecker.fs +++ b/src/fsharp/TypeChecker.fs @@ -4470,9 +4470,9 @@ and TcTyparOrMeasurePar optKind cenv (env:TcEnv) newOk tpenv (Typar(id, _, _) as // CallNameResolutionSink cenv.tcSink (tp.Range.StartRange, env.NameEnv, item, item, ItemOccurence.UseInType, env.DisplayEnv, env.eAccessRights) res, tpenv let key = id.idText - match env.eNameResEnv.eTypars.TryFind key with - | Some res -> checkRes res - | None -> + match env.eNameResEnv.eTypars.TryGetValue key with + | true, res -> checkRes res + | _ -> match TryFindUnscopedTypar key tpenv with | Some res -> checkRes res | None -> @@ -5101,17 +5101,17 @@ and TcPatBindingName cenv env id ty isMemberThis vis1 topValData (inlineFlag, de let names = Map.add id.idText (PrelimValScheme1(id, declaredTypars, ty, topValData, None, isMutable, inlineFlag, baseOrThis, argAttribs, vis, compgen)) names let takenNames = Set.add id.idText takenNames (fun (TcPatPhase2Input (values, isLeftMost)) -> - let (vspec, typeScheme) = - match values.TryFind id.idText with - | Some value -> - let name = id.idText + let (vspec, typeScheme) = + let name = id.idText + match values.TryGetValue name with + | true, value -> if not (String.IsNullOrEmpty name) && Char.IsLower(name.[0]) then match env.eNameResEnv.ePatItems.TryGetValue name with | true, Item.Value vref when vref.LiteralValue.IsSome -> - warning(Error(FSComp.SR.checkLowercaseLiteralBindingInPattern(id.idText), id.idRange)) + warning(Error(FSComp.SR.checkLowercaseLiteralBindingInPattern name, id.idRange)) | _ -> () value - | None -> error(Error(FSComp.SR.tcNameNotBoundInPattern(id.idText), id.idRange)) + | _ -> error(Error(FSComp.SR.tcNameNotBoundInPattern name, id.idRange)) // isLeftMost indicates we are processing the left-most path through a disjunctive or pattern. // For those binding locations, CallNameResolutionSink is called in MakeAndPublishValue, like all other bindings @@ -5198,10 +5198,10 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p // matching error (UnionPatternsBindDifferentNames m) names1 |> Map.iter (fun _ (PrelimValScheme1(id1, _, ty1, _, _, _, _, _, _, _, _)) -> - match Map.tryFind id1.idText names2 with - | None -> () - | Some (PrelimValScheme1(_, _, ty2, _, _, _, _, _, _, _, _)) -> - UnifyTypes cenv env m ty1 ty2) + match names2.TryGetValue id1.idText with + | true, PrelimValScheme1(_, _, ty2, _, _, _, _, _, _, _, _) -> + UnifyTypes cenv env m ty1 ty2 + | _ -> ()) (fun values -> TPat_disjs ([pat1' values;pat2' values.RightPath], m)), (tpenv, names1, takenNames1) | SynPat.Ands (pats, m) -> @@ -5442,9 +5442,9 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p let ftys = fields |> List.map (fun fsp -> actualTyOfRecdField inst fsp, fsp) let fldsmap', acc = ((tpenv, names, takenNames), ftys) ||> List.mapFold (fun s (ty, fsp) -> - match Map.tryFind fsp.rfield_id.idText fldsmap with - | Some v -> TcPat warnOnUpper cenv env None vFlags s ty v - | None -> (fun _ -> TPat_wild m), s) + match fldsmap.TryGetValue fsp.rfield_id.idText with + | true, v -> TcPat warnOnUpper cenv env None vFlags s ty v + | _ -> (fun _ -> TPat_wild m), s) (fun values -> TPat_recd (tcref, tinst, List.map (fun f -> f values) fldsmap', m)), acc @@ -11598,10 +11598,10 @@ and TcIncrementalLetRecGeneralization cenv scopem // pathological situations let freeInUncheckedRecBinds = lazy ((emptyFreeTyvars, cenv.recUses.Contents) ||> Map.fold (fun acc vStamp _ -> - match Map.tryFind vStamp uncheckedRecBindsTable with - | Some fwdBind -> - accFreeInType CollectAllNoCaching fwdBind.RecBindingInfo.Val.Type acc - | None -> + match uncheckedRecBindsTable.TryGetValue vStamp with + | true, fwdBind -> + accFreeInType CollectAllNoCaching fwdBind.RecBindingInfo.Val.Type acc + | _ -> acc)) let rec loop (preGeneralizationRecBinds: PreGeneralizationRecursiveBinding list, @@ -16024,12 +16024,12 @@ module TcDeclarations = else let isInSameModuleOrNamespace = - match envForDecls.eModuleOrNamespaceTypeAccumulator.Value.TypesByMangledName.TryFind(tcref.LogicalName) with - | Some tycon -> (tyconOrder.Compare(tcref.Deref, tycon) = 0) - | None -> + match envForDecls.eModuleOrNamespaceTypeAccumulator.Value.TypesByMangledName.TryGetValue tcref.LogicalName with + | true, tycon -> tyconOrder.Compare(tcref.Deref, tycon) = 0 + | _ -> //false // There is a special case we allow when compiling FSharp.Core.dll which permits interface implementations across namespace fragments - (cenv.g.compilingFslib && tcref.LogicalName.StartsWithOrdinal("Tuple`")) + cenv.g.compilingFslib && tcref.LogicalName.StartsWithOrdinal("Tuple`") let nReqTypars = reqTypars.Length