Skip to content

Commit

Permalink
Merge pull request #6614 from Microsoft/merges/master-to-fsharp5
Browse files Browse the repository at this point in the history
Merge master to fsharp5
  • Loading branch information
dotnet-automerge-bot authored Apr 23, 2019
2 parents 448d48f + 22fc113 commit fa7291e
Show file tree
Hide file tree
Showing 35 changed files with 996 additions and 292 deletions.
4 changes: 2 additions & 2 deletions fcs/docsrc/content/filesystem.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let B = File1.A + File1.A"""
interface IFileSystem with
// Implement the service to open files for reading and writing
member __.FileStreamReadShim(fileName) =
match files.TryGetValue(fileName) with
match files.TryGetValue fileName with
| true, text -> new MemoryStream(Encoding.UTF8.GetBytes(text)) :> Stream
| _ -> defaultFileSystem.FileStreamReadShim(fileName)

Expand All @@ -52,7 +52,7 @@ let B = File1.A + File1.A"""
defaultFileSystem.FileStreamWriteExistingShim(fileName)

member __.ReadAllBytesShim(fileName) =
match files.TryGetValue(fileName) with
match files.TryGetValue fileName with
| true, text -> Encoding.UTF8.GetBytes(text)
| _ -> defaultFileSystem.ReadAllBytesShim(fileName)

Expand Down
4 changes: 2 additions & 2 deletions fcs/docsrc/content/ja/filesystem.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let B = File1.A + File1.A"""
interface IFileSystem with
// 読み取りおよび書き込み用にファイルをオープンする機能を実装
member __.FileStreamReadShim(fileName) =
match files.TryGetValue(fileName) with
match files.TryGetValue fileName with
| true, text -> new MemoryStream(Encoding.UTF8.GetBytes(text)) :> Stream
| _ -> defaultFileSystem.FileStreamReadShim(fileName)

Expand All @@ -55,7 +55,7 @@ let B = File1.A + File1.A"""
defaultFileSystem.FileStreamWriteExistingShim(fileName)

member __.ReadAllBytesShim(fileName) =
match files.TryGetValue(fileName) with
match files.TryGetValue fileName with
| true, text -> Encoding.UTF8.GetBytes(text)
| _ -> defaultFileSystem.ReadAllBytesShim(fileName)

Expand Down
23 changes: 10 additions & 13 deletions src/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -985,15 +985,13 @@ type MemoizationTable<'T, 'U>(compute: 'T -> 'U, keyComparer: IEqualityComparer<

member t.Apply x =
if (match canMemoize with None -> true | Some f -> f x) then
let mutable res = Unchecked.defaultof<'U>
let ok = table.TryGetValue(x, &res)
if ok then res
else
match table.TryGetValue x with
| true, res -> res
| _ ->
lock table (fun () ->
let mutable res = Unchecked.defaultof<'U>
let ok = table.TryGetValue(x, &res)
if ok then res
else
match table.TryGetValue x with
| true, res -> res
| _ ->
let res = compute x
table.[x] <- res
res)
Expand Down Expand Up @@ -1074,11 +1072,10 @@ module Tables =
let memoize f =
let t = new Dictionary<_, _>(1000, HashIdentity.Structural)
fun x ->
let mutable res = Unchecked.defaultof<_>
if t.TryGetValue(x, &res) then
res
else
res <- f x
match t.TryGetValue x with
| true, res -> res
| _ ->
let res = f x
t.[x] <- res
res

Expand Down
9 changes: 4 additions & 5 deletions src/absil/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -903,12 +903,11 @@ let mkCacheInt32 lowMem _inbase _nm _sz =
| null -> cache := new Dictionary<int32, _>(11)
| _ -> ()
!cache
let mutable res = Unchecked.defaultof<_>
let ok = cache.TryGetValue(idx, &res)
if ok then
match cache.TryGetValue idx with
| true, res ->
incr count
res
else
| _ ->
let res = f idx
cache.[idx] <- res
res
Expand Down Expand Up @@ -4048,7 +4047,7 @@ let OpenILModuleReader fileName opts =
let cacheResult2 =
// can't used a cached entry when reading PDBs, since it makes the returned object IDisposable
if keyOk && opts.pdbDirPath.IsNone then
ilModuleReaderCache2.TryGetValue(key)
ilModuleReaderCache2.TryGetValue key
else
false, Unchecked.defaultof<_>

Expand Down
18 changes: 9 additions & 9 deletions src/absil/ilwrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,9 @@ type MetadataTable<'T> =
#if DEBUG
tbl.lookups <- tbl.lookups + 1
#endif
let mutable res = Unchecked.defaultof<_>
let ok = tbl.dict.TryGetValue(x, &res)
if ok then res
else tbl.AddSharedEntry x
match tbl.dict.TryGetValue x with
| true, res -> res
| _ -> tbl.AddSharedEntry x


/// This is only used in one special place - see further below.
Expand Down Expand Up @@ -769,11 +768,12 @@ let rec GetTypeRefAsTypeRefRow cenv (tref: ILTypeRef) =
SharedRow [| ResolutionScope (rs1, rs2); nelem; nselem |]

and GetTypeRefAsTypeRefIdx cenv tref =
let mutable res = 0
if cenv.trefCache.TryGetValue(tref, &res) then res else
let res = FindOrAddSharedRow cenv TableNames.TypeRef (GetTypeRefAsTypeRefRow cenv tref)
cenv.trefCache.[tref] <- res
res
match cenv.trefCache.TryGetValue tref with
| true, res -> res
| _ ->
let res = FindOrAddSharedRow cenv TableNames.TypeRef (GetTypeRefAsTypeRefRow cenv tref)
cenv.trefCache.[tref] <- res
res

and GetTypeDescAsTypeRefIdx cenv (scoref, enc, n) =
GetTypeRefAsTypeRefIdx cenv (mkILNestedTyRef (scoref, enc, n))
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/AttributeChecking.fs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ let IsSecurityAttribute (g: TcGlobals) amap (casmap : Dictionary<Stamp, bool>) (
match attr.TyconRef.TryDeref with
| ValueSome _ ->
let tcs = tcref.Stamp
match casmap.TryGetValue(tcs) with
match casmap.TryGetValue tcs with
| true, c -> c
| _ ->
let exists = ExistsInEntireHierarchyOfType (fun t -> typeEquiv g t (mkAppTy attr.TyconRef [])) g amap m AllowMultiIntfInstantiations.Yes (mkAppTy tcref [])
Expand Down
10 changes: 6 additions & 4 deletions src/fsharp/ExtensionTyping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,18 @@ module internal ExtensionTyping =
match ctxt with
| NoEntries -> None
| Entries(d, _) ->
let mutable res = Unchecked.defaultof<_>
if d.TryGetValue(st, &res) then Some res else None
match d.TryGetValue st with
| true, res -> Some res
| _ -> None

member ctxt.TryGetTyconRef st =
match ctxt with
| NoEntries -> None
| Entries(_, d) ->
let d = d.Force()
let mutable res = Unchecked.defaultof<_>
if d.TryGetValue(st, &res) then Some res else None
match d.TryGetValue st with
| true, res -> Some res
| _ -> None

member ctxt.RemapTyconRefs (f: obj->obj) =
match ctxt with
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/InfoReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type PropertyCollector(g, amap, m, ty, optFilter, ad) =
let props = new Dictionary<PropInfo, PropInfo>(hashIdentity)

let add pinfo =
match props.TryGetValue(pinfo), pinfo with
match props.TryGetValue pinfo, pinfo with
| (true, FSProp (_, ty, Some vref1, _)), FSProp (_, _, _, Some vref2)
| (true, FSProp (_, ty, _, Some vref2)), FSProp (_, _, Some vref1, _) ->
let pinfo = FSProp (g, ty, Some vref1, Some vref2)
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ let TryImportProvidedMethodBaseAsLibraryIntrinsic (amap: Import.ImportMap, m: ra
match amap.g.knownIntrinsics.TryGetValue ((declaringEntity.LogicalName, methodName)) with
| true, vref -> Some vref
| _ ->
match amap.g.knownFSharpCoreModules.TryGetValue(declaringEntity.LogicalName) with
match amap.g.knownFSharpCoreModules.TryGetValue declaringEntity.LogicalName with
| true, modRef ->
modRef.ModuleOrNamespaceType.AllValsByLogicalName
|> Seq.tryPick (fun (KeyValue(_, v)) -> if v.CompiledName = methodName then Some (mkNestedValRef modRef v) else None)
Expand Down Expand Up @@ -1219,7 +1219,7 @@ module ProvidedMethodCalls =
// sub in the appropriate argument
// REVIEW: "thisArg" pointer should be first, if present
let vRaw = pe.PUntaint(id, m)
match varConv.TryGetValue(vRaw) with
match varConv.TryGetValue vRaw with
| true, v -> v
| _ ->
let typeProviderDesignation = ExtensionTyping.DisplayNameOfTypeProvider (pe.TypeProvider, m)
Expand Down
20 changes: 10 additions & 10 deletions src/fsharp/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -573,18 +573,18 @@ let GetInfoForLocalValue cenv env (v: Val) m =
// Abstract slots do not have values
if v.IsDispatchSlot then UnknownValInfo
else
let mutable res = Unchecked.defaultof<_>
let ok = cenv.localInternalVals.TryGetValue(v.Stamp, &res)
if ok then res else
match env.localExternalVals.TryFind v.Stamp with
| Some vval -> vval
| None ->
if v.MustInline then
errorR(Error(FSComp.SR.optValueMarkedInlineButWasNotBoundInTheOptEnv(fullDisplayTextOfValRef (mkLocalValRef v)), m))
match cenv.localInternalVals.TryGetValue v.Stamp with
| true, res -> res
| _ ->
match env.localExternalVals.TryFind v.Stamp with
| Some vval -> vval
| None ->
if v.MustInline then
errorR(Error(FSComp.SR.optValueMarkedInlineButWasNotBoundInTheOptEnv(fullDisplayTextOfValRef (mkLocalValRef v)), m))
#if CHECKED
warning(Error(FSComp.SR.optLocalValueNotFoundDuringOptimization(v.DisplayName), m))
warning(Error(FSComp.SR.optLocalValueNotFoundDuringOptimization(v.DisplayName), m))
#endif
UnknownValInfo
UnknownValInfo

let TryGetInfoForCcu env (ccu: CcuThunk) = env.globalModuleInfos.TryFind(ccu.AssemblyName)

Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ let IsValLocal env (v: Val) =
/// Get the limit of the val.
let GetLimitVal cenv env m (v: Val) =
let limit =
match cenv.limitVals.TryGetValue(v.Stamp) with
match cenv.limitVals.TryGetValue v.Stamp with
| true, limit -> limit
| _ ->
if IsValLocal env v then
Expand Down
6 changes: 3 additions & 3 deletions src/fsharp/TastPickle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ type Table<'T> =
tbl.rows.Add x
n
member tbl.FindOrAdd x =
let mutable res = Unchecked.defaultof<_>
let ok = tbl.tbl.TryGetValue(x, &res)
if ok then res else tbl.Add x
match tbl.tbl.TryGetValue x with
| true, res -> res
| _ -> tbl.Add x


static member Create n =
Expand Down
18 changes: 9 additions & 9 deletions src/fsharp/TcGlobals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -870,24 +870,24 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
TType_app (tcref, tinst)
else
let dict = getDecompileTypeDict()
let mutable builder = Unchecked.defaultof<_>
if dict.TryGetValue(tcref.Stamp, &builder) then builder tinst
else TType_app (tcref, tinst)
match dict.TryGetValue tcref.Stamp with
| true, builder -> builder tinst
| _ -> TType_app (tcref, tinst)

/// For cosmetic purposes "improve" some .NET types, e.g. Int32 --> int32.
/// Doing this normalization is a fairly performance critical piece of code as it is frequently invoked
/// in the process of converting .NET metadata to F# internal compiler data structures (see import.fs).
let improveTy (tcref: EntityRef) tinst =
if compilingFslib then
let dict = getBetterTypeDict1()
let mutable builder = Unchecked.defaultof<_>
if dict.TryGetValue(tcref.LogicalName, &builder) then builder tcref tinst
else TType_app (tcref, tinst)
match dict.TryGetValue tcref.LogicalName with
| true, builder -> builder tcref tinst
| _ -> TType_app (tcref, tinst)
else
let dict = getBetterTypeDict2()
let mutable builder = Unchecked.defaultof<_>
if dict.TryGetValue(tcref.Stamp, &builder) then builder tinst
else TType_app (tcref, tinst)
match dict.TryGetValue tcref.Stamp with
| true, builder -> builder tinst
| _ -> TType_app (tcref, tinst)


override x.ToString() = "<TcGlobals>"
Expand Down
6 changes: 3 additions & 3 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12394,16 +12394,16 @@ module TcRecdUnionAndEnumDeclarations = begin
let ValidateFieldNames (synFields: SynField list, tastFields: RecdField list) =
let seen = Dictionary()
for (sf, f) in List.zip synFields tastFields do
let mutable synField = Unchecked.defaultof<_>
if seen.TryGetValue(f.Name, &synField) then
match seen.TryGetValue f.Name with
| true, synField ->
match sf, synField with
| Field(_, _, Some id, _, _, _, _, _), Field(_, _, Some(_), _, _, _, _, _) ->
error(Error(FSComp.SR.tcFieldNameIsUsedModeThanOnce(id.idText), id.idRange))
| Field(_, _, Some id, _, _, _, _, _), Field(_, _, None, _, _, _, _, _)
| Field(_, _, None, _, _, _, _, _), Field(_, _, Some id, _, _, _, _, _) ->
error(Error(FSComp.SR.tcFieldNameConflictsWithGeneratedNameForAnonymousField(id.idText), id.idRange))
| _ -> assert false
else
| _ ->
seen.Add(f.Name, sf)

let TcUnionCaseDecl cenv env parent thisTy tpenv (UnionCase (synAttrs, id, args, xmldoc, vis, m)) =
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/fsi/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ type internal FsiInteractionProcessor
if tcConfig.shadowCopyReferences then
let resolvedPath = ar.resolvedPath.ToUpperInvariant()
let fileTime = File.GetLastWriteTimeUtc(resolvedPath)
match referencedAssemblies.TryGetValue(resolvedPath) with
match referencedAssemblies.TryGetValue resolvedPath with
| false, _ ->
referencedAssemblies.Add(resolvedPath, fileTime)
FSIstrings.SR.fsiDidAHashr(ar.resolvedPath)
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/import.fs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ let ImportILTypeRefUncached (env: ImportMap) m (tref: ILTypeRef) =

/// Import a reference to a type definition, given an AbstractIL ILTypeRef, with caching
let ImportILTypeRef (env: ImportMap) m (tref: ILTypeRef) =
match env.ILTypeRefToTyconRefCache.TryGetValue(tref) with
match env.ILTypeRefToTyconRefCache.TryGetValue tref with
| true, tcref -> tcref
| _ ->
let tcref = ImportILTypeRefUncached env m tref
Expand Down Expand Up @@ -436,7 +436,7 @@ let multisetDiscriminateAndMap nodef tipf (items: ('Key list * 'Value) list) =
| [] -> ()
| key :: rest ->
buckets.[key] <-
match buckets.TryGetValue(key) with
match buckets.TryGetValue key with
| true, b -> (rest, v) :: b
| _ -> (rest, v) :: []

Expand Down
13 changes: 7 additions & 6 deletions src/fsharp/lexhelp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ type LightSyntaxStatus(initial:bool,warn:bool) =
type LexResourceManager() =
let strings = new System.Collections.Generic.Dictionary<string, Parser.token>(1024)
member x.InternIdentifierToken(s) =
let mutable res = Unchecked.defaultof<_>
let ok = strings.TryGetValue(s, &res)
if ok then res else
let res = IDENT s
(strings.[s] <- res; res)

match strings.TryGetValue s with
| true, res -> res
| _ ->
let res = IDENT s
strings.[s] <- res
res

/// Lexer parameters
type lexargs =
{ defines: string list
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/range.fs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ type FileIndexTable() =
//
// TO move forward we should eventually introduce a new type NormalizedFileName that tracks this invariant.
member t.FileToIndex normalize filePath =
match fileToIndexTable.TryGetValue(filePath) with
match fileToIndexTable.TryGetValue filePath with
| true, idx -> idx
| _ ->

// Try again looking for a normalized entry.
let normalizedFilePath = if normalize then normalizeFilePath filePath else filePath
match fileToIndexTable.TryGetValue(normalizedFilePath) with
match fileToIndexTable.TryGetValue normalizedFilePath with
| true, idx ->
// Record the non-normalized entry if necessary
if filePath <> normalizedFilePath then
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/tast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4060,7 +4060,7 @@ and [<RequireQualifiedAccess>] AnonRecdTypeInfo =

/// Get the ILTypeRef for the generated type implied by the anonymous type
member x.ILTypeRef =
let ilTypeName = sprintf "<>f__AnonymousType%s%u`%d'" (match x.TupInfo with TupInfo.Const b -> if b then "1000" else "") (uint32 x.Stamp) x.SortedIds.Length
let ilTypeName = sprintf "<>f__AnonymousType%s%u`%d" (match x.TupInfo with TupInfo.Const b -> if b then "1000" else "") (uint32 x.Stamp) x.SortedIds.Length
mkILTyRef(x.Assembly.ILScopeRef, ilTypeName)

static member NewUnlinked() : AnonRecdTypeInfo =
Expand Down
6 changes: 3 additions & 3 deletions src/ilx/EraseUnions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,9 @@ let emitDataSwitch ilg (cg: ICodeGen<'Mark>) (avoidHelpers, cuspec, cases) =
for (i,case) in cases do dict.[i] <- case
let failLab = cg.GenerateDelayMark ()
let emitCase i _ =
let mutable res = Unchecked.defaultof<_>
let ok = dict.TryGetValue(i, &res)
if ok then res else cg.CodeLabel failLab
match dict.TryGetValue i with
| true, res -> res
| _ -> cg.CodeLabel failLab

let dests = Array.mapi emitCase cuspec.AlternativesArray
cg.EmitInstrs (mkGetTag ilg cuspec)
Expand Down
Loading

0 comments on commit fa7291e

Please sign in to comment.