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

Commit432784c

Browse files
authored
Fix FCS problem with duplicate ByteFile (dotnet#4629)
* fix memory usage for FCS case* use explicit version flag for FCS untildotnet#3113 is fixed* fix build* use explicit version flag for FCS untildotnet#3113 is fixed* use WeakByteFile* add cache size parameter* add cache size parameter* fix build
1 parent48a2f59 commit432784c

File tree

5 files changed

+63
-52
lines changed

5 files changed

+63
-52
lines changed

‎fcs/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ImportProject="..\netfx.props" />
77
<PropertyGroup>
88
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
9-
<NoWarn>$(NoWarn);44;</NoWarn>
9+
<NoWarn>$(NoWarn);44;75;</NoWarn>
1010
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1111
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1212
<IsPackable>false</IsPackable>

‎fcs/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ which does things like:
6060
Yu can push the packages if you have permissions, either automatically using``build Release`` or manually
6161

6262
set APIKEY=...
63-
.nuget\nuget.exe pushrelease\fcs\FSharp.Compiler.Service.21.0.1.nupkg %APIKEY% -Source https://nuget.org
64-
.nuget\nuget.exe pushrelease\fcs\FSharp.Compiler.Service.MSBuild.v12.21.0.1.nupkg %APIKEY% -Source https://nuget.org
65-
.nuget\nuget.exe pushrelease\fcs\FSharp.Compiler.Service.ProjectCracker.21.0.1.nupkg %APIKEY% -Source https://nuget.org
63+
..\fsharp\.nuget\nuget.exe push%HOMEDRIVE%%HOMEPATH%\Downloads\FSharp.Compiler.Service.22.0.2.nupkg %APIKEY% -Source https://nuget.org
64+
..\fsharp\.nuget\nuget.exe push%HOMEDRIVE%%HOMEPATH%\Downloads\FSharp.Compiler.Service.MSBuild.v12.22.0.2.nupkg %APIKEY% -Source https://nuget.org
65+
..\fsharp\.nuget\nuget.exe push%HOMEDRIVE%%HOMEPATH%\Downloads\FSharp.Compiler.Service.ProjectCracker.22.0.2.nupkg %APIKEY% -Source https://nuget.org
6666

6767

6868
###Use of Paket and FAKE

‎fcs/RELEASE_NOTES.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
####22.0.2
2+
* Use correct version number in DLLs (needed untilhttps://github.com/Microsoft/visualfsharp/issues/3113 is fixed)
3+
4+
####22.0.1
5+
* Integrate visualfsharp master
6+
* Includes recent memory usage reduction work for ByteFile and ILAttributes
7+
18
####21.0.1
29
* Use new .NET SDK project files
310
* FSharp.Compiler.Service nuget now uses net45 and netstandard2.0

‎fcs/fcs.props‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<ProjectToolsVersion="4.0"DefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
44
<PropertyGroup>
55

6-
<VersionPrefix>21.0.1</VersionPrefix>
6+
<VersionPrefix>22.0.2</VersionPrefix>
7+
<OtherFlags>--version:$(VersionPrefix)</OtherFlags>
78
<!-- FSharp.Compiler.Tools is currently only used to get a working FSI.EXE to execute some scripts during the build-->
89
<!-- The LKG FSI.EXE requires MSBuild 15 to be installed, which is painful-->
910
<FsiToolPath>$(FSharpSourcesRoot)\..\packages\FSharp.Compiler.Tools.4.1.27\tools</FsiToolPath>

‎src/absil/ilread.fs‎

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ open System.Reflection
3333

3434
letchecking=false
3535
letlogging=false
36-
let_=if checkingthen dprintn"warning :Ilread.checking is on"
36+
let_=if checkingthen dprintn"warning :ILBinaryReader.checking is on"
3737
letnoStableFileHeuristic=try(System.Environment.GetEnvironmentVariable("FSharp_NoStableFileHeuristic")<>null)with_->false
3838
letalwaysMemoryMapFSC=try(System.Environment.GetEnvironmentVariable("FSharp_AlwaysMemoryMapCommandLineCompiler")<>null)with_->false
39+
letstronglyHeldReaderCacheSizeDefault=30
40+
letstronglyHeldReaderCacheSize=try(match System.Environment.GetEnvironmentVariable("FSharp_StronglyHeldBinaryReaderCacheSize")withnull-> stronglyHeldReaderCacheSizeDefault| s-> int32 s)with_-> stronglyHeldReaderCacheSizeDefault
3941

4042
letsingleOfBits(x:int32)= System.BitConverter.ToSingle(System.BitConverter.GetBytes(x),0)
4143
letdoubleOfBits(x:int64)= System.BitConverter.Int64BitsToDouble(x)
@@ -346,7 +348,7 @@ type ByteFile(fileName: string, bytes:byte[]) =
346348
/// This is the default implementation used by F# Compiler Services when accessing "stable" binaries. It is not used
347349
/// by Visual Studio, where tryGetMetadataSnapshot provides a RawMemoryFile backed by Roslyn data.
348350
[<DebuggerDisplay("{FileName}")>]
349-
typeWeakByteFile(fileName: string)=
351+
typeWeakByteFile(fileName: string,chunk:(int*int)option)=
350352

351353
do stats.weakByteFileCount<- stats.weakByteFileCount+1
352354

@@ -357,30 +359,29 @@ type WeakByteFile(fileName: string) =
357359
letweakBytes=new WeakReference<byte[]>(null)
358360

359361
member__.FileName= fileName
360-
/// Get the bytes for the file
361-
memberthis.Get()=
362-
let mutabletg=null
363-
ifnot(weakBytes.TryGetTarget(&tg))then
364-
if FileSystem.GetLastWriteTimeShim(fileName)<> fileStampthen
365-
errorR(Error(FSComp.SR.ilreadFileChanged fileName, range0))
366-
367-
tg<- FileSystem.ReadAllBytesShim fileName
368-
weakBytes.SetTarget tg
369-
tg
370362

363+
/// Get the bytes for the file
371364
interface BinaryFilewith
372-
override__.GetView()=
373-
let mutabletg=null
365+
366+
overridethis.GetView()=
374367
letstrongBytes=
368+
let mutabletg=null
375369
ifnot(weakBytes.TryGetTarget(&tg))then
376370
if FileSystem.GetLastWriteTimeShim(fileName)<> fileStampthen
377-
errorR(Error(FSComp.SR.ilreadFileChanged fileName, range0))
371+
error(Error(FSComp.SR.ilreadFileChanged fileName, range0))
372+
373+
letbytes=
374+
match chunkwith
375+
| None-> FileSystem.ReadAllBytesShim fileName
376+
| Some(start, length)-> File.ReadBinaryChunk(fileName, start, length)
377+
378+
tg<- bytes
379+
380+
weakBytes.SetTarget bytes
378381

379-
tg<- FileSystem.ReadAllBytesShim fileName
380-
weakBytes.SetTarget tg
381382
tg
382-
(ByteView(strongBytes):> BinaryView)
383383

384+
(ByteView(strongBytes):> BinaryView)
384385

385386

386387
letseekReadByte(mdv:BinaryView)addr= mdv.ReadByte addr
@@ -3927,27 +3928,31 @@ type ILModuleReader(ilModule: ILModuleDef, ilAssemblyRefs: Lazy<ILAssemblyRef li
39273928

39283929
// ++GLOBAL MUTABLE STATE (concurrency safe via locking)
39293930
typeILModuleReaderCacheLockToken()=interface LockToken
3930-
letilModuleReaderCache=new AgedLookup<ILModuleReaderCacheLockToken,(string* System.DateTime* ILScopeRef* bool* ReduceMemoryFlag* MetadataOnlyFlag), ILModuleReader>(0, areSimilar=(fun(x,y)-> x= y))
3931+
typeILModuleReaderCacheKey= ILModuleReaderCacheKeyofstring*DateTime*ILScopeRef*bool*ReduceMemoryFlag*MetadataOnlyFlag
3932+
letilModuleReaderCache=new AgedLookup<ILModuleReaderCacheLockToken, ILModuleReaderCacheKey, ILModuleReader>(stronglyHeldReaderCacheSize, areSimilar=(fun(x,y)-> x= y))
39313933
letilModuleReaderCacheLock= Lock()
39323934

39333935
letstableFileHeuristicApplies fileName=
39343936
not noStableFileHeuristic&&try FileSystem.IsStableFileHeuristic fileNamewith_->false
39353937

3936-
letcreateByteFile opts fileName=
3938+
letcreateByteFileChunk opts fileName chunk=
39373939
// If we're trying to reduce memory usage then we are willing to go back and re-read the binary, so we can use
39383940
// a weakly-held handle to an array of bytes.
39393941
if opts.reduceMemoryUsage= ReduceMemoryFlag.Yes&& stableFileHeuristicApplies fileNamethen
3940-
WeakByteFile(fileName):> BinaryFile
3942+
WeakByteFile(fileName, chunk):> BinaryFile
39413943
else
3942-
letbytes= FileSystem.ReadAllBytesShim(fileName)
3944+
letbytes=
3945+
match chunkwith
3946+
| None-> FileSystem.ReadAllBytesShim fileName
3947+
| Some(start, length)-> File.ReadBinaryChunk(fileName, start, length)
39433948
ByteFile(fileName, bytes):> BinaryFile
39443949

3945-
lettryMemoryMap opts fileName=
3950+
lettryMemoryMapWholeFile opts fileName=
39463951
letfile=
39473952
try
39483953
MemoryMapFile.Create fileName:> BinaryFile
39493954
with_->
3950-
createByteFile opts fileName
3955+
createByteFileChunk opts fileName None
39513956
letdisposer=
39523957
{new IDisposablewith
39533958
member__.Dispose()=
@@ -3963,17 +3968,16 @@ let OpenILModuleReaderFromBytes fileName bytes opts =
39633968

39643969
letOpenILModuleReader fileName opts=
39653970
// Pseudo-normalize the paths.
3966-
let((_,writeStamp,_,_,_,_)as key),keyOk=
3971+
let(ILModuleReaderCacheKey(fullPath,writeStamp,_,_,_,_)as key),keyOk=
39673972
try
3968-
(FileSystem.GetFullPathShim(fileName),
3969-
FileSystem.GetLastWriteTimeShim(fileName),
3970-
opts.ilGlobals.primaryAssemblyScopeRef,
3971-
opts.pdbPath.IsSome,
3972-
opts.reduceMemoryUsage,
3973-
opts.metadataOnly),true
3974-
with e->
3975-
System.Diagnostics.Debug.Assert(false, sprintf"Failed to compute key in OpenILModuleReader cache for '%s'. Falling back to uncached." fileName)
3976-
("", System.DateTime.UtcNow, ILScopeRef.Local,false, ReduceMemoryFlag.Yes, MetadataOnlyFlag.Yes),false
3973+
letfullPath= FileSystem.GetFullPathShim(fileName)
3974+
letwriteTime= FileSystem.GetLastWriteTimeShim(fileName)
3975+
letkey= ILModuleReaderCacheKey(fullPath, writeTime, opts.ilGlobals.primaryAssemblyScopeRef, opts.pdbPath.IsSome, opts.reduceMemoryUsage, opts.metadataOnly)
3976+
key,true
3977+
with exn->
3978+
System.Diagnostics.Debug.Assert(false, sprintf"Failed to compute key in OpenILModuleReader cache for '%s'. Falling back to uncached. Error =%s" fileName(exn.ToString()))
3979+
letfakeKey= ILModuleReaderCacheKey(fileName, System.DateTime.UtcNow, ILScopeRef.Local,false, ReduceMemoryFlag.Yes, MetadataOnlyFlag.Yes)
3980+
fakeKey,false
39773981

39783982
letcacheResult=
39793983
if keyOkthen
@@ -3999,30 +4003,29 @@ let OpenILModuleReader fileName opts =
39994003

40004004
// See if tryGetMetadata gives us a BinaryFile for the metadata section alone.
40014005
letmdfileOpt=
4002-
match opts.tryGetMetadataSnapshot(fileName, writeStamp)with
4003-
| Some(obj, start, len)-> Some(RawMemoryFile(fileName, obj, start, len):> BinaryFile)
4006+
match opts.tryGetMetadataSnapshot(fullPath, writeStamp)with
4007+
| Some(obj, start, len)-> Some(RawMemoryFile(fullPath, obj, start, len):> BinaryFile)
40044008
| None-> None
40054009

40064010
// For metadata-only, always use a temporary, short-lived PE file reader, preferably over a memory mapped file.
40074011
// Then use the metadata blob as the long-lived memory resource.
4008-
letdisposer,pefileEager=tryMemoryMap optsfileName
4012+
letdisposer,pefileEager=tryMemoryMapWholeFile optsfullPath
40094013
use _disposer= disposer
4010-
let(metadataPhysLoc,metadataSize,peinfo,pectxtEager,pevEager,_pdb)= openPEFileReader(fileName, pefileEager, None)
4014+
let(metadataPhysLoc,metadataSize,peinfo,pectxtEager,pevEager,_pdb)= openPEFileReader(fullPath, pefileEager, None)
40114015
letmdfile=
40124016
match mdfileOptwith
40134017
| Some mdfile-> mdfile
40144018
| None->
40154019
// If tryGetMetadata doesn't give anything, then just read the metadata chunk out of the binary
4016-
letbytes= File.ReadBinaryChunk(fileName, metadataPhysLoc, metadataSize)
4017-
ByteFile(fileName, bytes):> BinaryFile
4020+
createByteFileChunk opts fullPath(Some(metadataPhysLoc, metadataSize))
40184021

4019-
letilModule,ilAssemblyRefs= openPEMetadataOnly(fileName, peinfo, pectxtEager, pevEager, mdfile, reduceMemoryUsage, opts.ilGlobals)
4022+
letilModule,ilAssemblyRefs= openPEMetadataOnly(fullPath, peinfo, pectxtEager, pevEager, mdfile, reduceMemoryUsage, opts.ilGlobals)
40204023
new ILModuleReader(ilModule, ilAssemblyRefs, ignore)
40214024
else
40224025
// If we are not doing metadata-only, then just go ahead and read all the bytes and hold them either strongly or weakly
40234026
// depending on the heuristic
4024-
letpefile=createByteFile optsfileName
4025-
letilModule,ilAssemblyRefs,_pdb= openPE(fileName, pefile, None, reduceMemoryUsage, opts.ilGlobals)
4027+
letpefile=createByteFileChunk optsfullPath None
4028+
letilModule,ilAssemblyRefs,_pdb= openPE(fullPath, pefile, None, reduceMemoryUsage, opts.ilGlobals)
40264029
new ILModuleReader(ilModule, ilAssemblyRefs, ignore)
40274030

40284031
if keyOkthen
@@ -4042,14 +4045,14 @@ let OpenILModuleReader fileName opts =
40424045
// multi-proc build. So use memory mapping, but only for stable files. Other files
40434046
// fill use an in-memory ByteFile
40444047
let_disposer,pefile=
4045-
if alwaysMemoryMapFSC|| stableFileHeuristicAppliesfileNamethen
4046-
tryMemoryMap optsfileName
4048+
if alwaysMemoryMapFSC|| stableFileHeuristicAppliesfullPaththen
4049+
tryMemoryMapWholeFile optsfullPath
40474050
else
4048-
letpefile=createByteFile optsfileName
4051+
letpefile=createByteFileChunk optsfullPath None
40494052
letdisposer={new IDisposablewithmember__.Dispose()=()}
40504053
disposer, pefile
40514054

4052-
letilModule,ilAssemblyRefs,pdb= openPE(fileName, pefile, opts.pdbPath, reduceMemoryUsage, opts.ilGlobals)
4055+
letilModule,ilAssemblyRefs,pdb= openPE(fullPath, pefile, opts.pdbPath, reduceMemoryUsage, opts.ilGlobals)
40534056
letilModuleReader=new ILModuleReader(ilModule, ilAssemblyRefs,(fun()-> ClosePdbReader pdb))
40544057

40554058
// Readers with PDB reader disposal logic don't go in the cache. Note the PDB reader is only used in static linking.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp