Skip to content

Commit 6c18095

Browse files
authored
Merge pull request #11605 from dotnet/merges/main-to-release/dev17.0
Merge main to release/dev17.0
2 parents 78c22aa + 98e11ae commit 6c18095

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+602
-353
lines changed

src/fsharp/CheckFormatStrings.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ let parseFormatStringInternal (m: range) (fragRanges: range list) (g: TcGlobals)
366366
appendToDotnetFormatString "%"
367367
parseLoop acc (i+1, fragLine, fragCol+1) fragments
368368

369-
| ('d' | 'i' | 'o' | 'u' | 'x' | 'X') ->
369+
| ('d' | 'i' | 'u' | 'B' | 'o' | 'x' | 'X') ->
370+
if ch = 'B' then ErrorLogger.checkLanguageFeatureError g.langVersion Features.LanguageFeature.PrintfBinaryFormat m
370371
if info.precision then failwithf "%s" <| FSComp.SR.forFormatDoesntSupportPrecision(ch.ToString())
371372
collectSpecifierLocation fragLine fragCol 1
372373
let i = skipPossibleInterpolationHole (i+1)

src/fsharp/CompilerConfig.fs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ type VersionFlag =
138138
if not(FileSystem.FileExistsShim s) then
139139
errorR(Error(FSComp.SR.buildInvalidVersionFile s, rangeStartup)); "0.0.0.0"
140140
else
141-
use fs = FileSystem.OpenFileForReadShim(s).AsReadOnlyStream()
141+
use fs = FileSystem.OpenFileForReadShim(s)
142142
use is = new StreamReader(fs)
143143
is.ReadLine()
144144
| VersionNone -> "0.0.0.0"
@@ -752,7 +752,7 @@ type TcConfigBuilder =
752752
let absolutePath = ComputeMakePathAbsolute pathIncludedFrom path
753753
let ok =
754754
let existsOpt =
755-
try Some(Directory.Exists absolutePath)
755+
try Some(FileSystem.DirectoryExistsShim absolutePath)
756756
with e -> warning(Error(FSComp.SR.buildInvalidSearchDirectory path, m)); None
757757
match existsOpt with
758758
| Some exists ->
@@ -1065,7 +1065,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
10651065
let clrRoot = tcConfig.MakePathAbsolute x
10661066
yield clrRoot
10671067
let clrFacades = Path.Combine(clrRoot, "Facades")
1068-
if Directory.Exists(clrFacades) then yield clrFacades
1068+
if FileSystem.DirectoryExistsShim(clrFacades) then yield clrFacades
10691069

10701070
| None ->
10711071
// "there is no really good notion of runtime directory on .NETCore"
@@ -1084,13 +1084,13 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
10841084
//
10851085
// In the current way of doing things, F# Interactive refers to implementation assemblies.
10861086
yield runtimeRoot
1087-
if Directory.Exists runtimeRootFacades then
1087+
if FileSystem.DirectoryExistsShim runtimeRootFacades then
10881088
yield runtimeRootFacades // System.Runtime.dll is in /usr/lib/mono/4.5/Facades
1089-
if Directory.Exists runtimeRootWPF then
1089+
if FileSystem.DirectoryExistsShim runtimeRootWPF then
10901090
yield runtimeRootWPF // PresentationCore.dll is in C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF
10911091

10921092
match tcConfig.FxResolver.GetFrameworkRefsPackDirectory() with
1093-
| Some path when Directory.Exists(path) ->
1093+
| Some path when FileSystem.DirectoryExistsShim(path) ->
10941094
yield path
10951095
| _ -> ()
10961096

@@ -1102,16 +1102,16 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
11021102
// On Mono, the default references come from the implementation assemblies.
11031103
// This is because we have had trouble reliably using MSBuild APIs to compute DotNetFrameworkReferenceAssembliesRootDirectory on Mono.
11041104
yield runtimeRoot
1105-
if Directory.Exists runtimeRootFacades then
1105+
if FileSystem.DirectoryExistsShim runtimeRootFacades then
11061106
yield runtimeRootFacades // System.Runtime.dll is in /usr/lib/mono/4.5/Facades
1107-
if Directory.Exists runtimeRootWPF then
1107+
if FileSystem.DirectoryExistsShim runtimeRootWPF then
11081108
yield runtimeRootWPF // PresentationCore.dll is in C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF
11091109
// On Mono we also add a default reference to the 4.5-api and 4.5-api/Facades directories.
11101110
let runtimeRootApi = runtimeRootWithoutSlash + "-api"
11111111
let runtimeRootApiFacades = Path.Combine(runtimeRootApi, "Facades")
1112-
if Directory.Exists runtimeRootApi then
1112+
if FileSystem.DirectoryExistsShim runtimeRootApi then
11131113
yield runtimeRootApi
1114-
if Directory.Exists runtimeRootApiFacades then
1114+
if FileSystem.DirectoryExistsShim runtimeRootApiFacades then
11151115
yield runtimeRootApiFacades
11161116
else
11171117
#endif
@@ -1122,10 +1122,10 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
11221122
let frameworkRootVersion = Path.Combine(frameworkRoot, tcConfig.targetFrameworkVersion)
11231123
yield frameworkRootVersion
11241124
let facades = Path.Combine(frameworkRootVersion, "Facades")
1125-
if Directory.Exists facades then
1125+
if FileSystem.DirectoryExistsShim facades then
11261126
yield facades
11271127
match tcConfig.FxResolver.GetFrameworkRefsPackDirectory() with
1128-
| Some path when Directory.Exists(path) ->
1128+
| Some path when FileSystem.DirectoryExistsShim(path) ->
11291129
yield path
11301130
| _ -> ()
11311131
]

src/fsharp/CompilerImports.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ type RawFSharpAssemblyDataBackedByFileOnDisk (ilModule: ILModuleDef, ilAssemblyR
690690
let sigFileName = Path.ChangeExtension(filename, "sigdata")
691691
if not (FileSystem.FileExistsShim sigFileName) then
692692
error(Error(FSComp.SR.buildExpectedSigdataFile (FileSystem.GetFullPathShim sigFileName), m))
693-
[ (ilShortAssemName, fun () -> FileSystem.OpenFileForReadShim(sigFileName, shouldShadowCopy=true).AsReadOnly())]
693+
[ (ilShortAssemName, fun () -> FileSystem.OpenFileForReadShim(sigFileName, useMemoryMappedFile=true, shouldShadowCopy=true).AsByteMemory().AsReadOnly())]
694694
else
695695
sigDataReaders
696696
sigDataReaders
@@ -706,7 +706,7 @@ type RawFSharpAssemblyDataBackedByFileOnDisk (ilModule: ILModuleDef, ilAssemblyR
706706
let optDataFile = Path.ChangeExtension(filename, "optdata")
707707
if not (FileSystem.FileExistsShim optDataFile) then
708708
error(Error(FSComp.SR.buildExpectedFileAlongSideFSharpCore(optDataFile, FileSystem.GetFullPathShim optDataFile), m))
709-
[ (ilShortAssemName, (fun () -> FileSystem.OpenFileForReadShim(optDataFile, shouldShadowCopy=true).AsReadOnly()))]
709+
[ (ilShortAssemName, (fun () -> FileSystem.OpenFileForReadShim(optDataFile, useMemoryMappedFile=true, shouldShadowCopy=true).AsByteMemory().AsReadOnly()))]
710710
else
711711
optDataReaders
712712
optDataReaders

src/fsharp/CompilerOptions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ module ResponseFile =
183183
| s -> Some (ResponseFileLine.CompilerOptionSpec (s.Trim()))
184184

185185
try
186-
use stream = FileSystem.OpenFileForReadShim(path).AsReadOnlyStream()
186+
use stream = FileSystem.OpenFileForReadShim(path)
187187
use reader = new StreamReader(stream, true)
188188
let data =
189189
seq { while not reader.EndOfStream do yield reader.ReadLine () }

src/fsharp/FSComp.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ invalidFullNameForProvidedType,"invalid full name for provided type"
12301230
3087,tcCustomOperationMayNotBeOverloaded,"The custom operation '%s' refers to a method which is overloaded. The implementations of custom operations may not be overloaded."
12311231
featureOverloadsForCustomOperations,"overloads for custom operations"
12321232
featureExpandedMeasurables,"more types support units of measure"
1233+
featurePrintfBinaryFormat,"binary formatting for integers"
12331234
3090,tcIfThenElseMayNotBeUsedWithinQueries,"An if/then/else expression may not be used within queries. Consider using either an if/then expression, or use a sequence expression instead."
12341235
3091,ilxgenUnexpectedArgumentToMethodHandleOfDuringCodegen,"Invalid argument to 'methodhandleof' during codegen"
12351236
3092,etProvidedTypeReferenceMissingArgument,"A reference to a provided type was missing a value for the static parameter '%s'. You may need to recompile one or more referenced assemblies."
@@ -1558,4 +1559,4 @@ forFormatInvalidForInterpolated4,"Interpolated strings used as type IFormattable
15581559
3390,xmlDocMissingParameter,"This XML comment is incomplete: no documentation for parameter '%s'"
15591560
3391,tcLiteralAttributeCannotUseActivePattern,"A [<Literal>] declaration cannot use an active pattern for its identifier"
15601561
3392,containerDeprecated,"The 'AssemblyKeyNameAttribute' has been deprecated. Use 'AssemblyKeyFileAttribute' instead."
1561-
3393,containerSigningUnsupportedOnThisPlatform,"Key container signing is not supported on this platform."
1562+
3393,containerSigningUnsupportedOnThisPlatform,"Key container signing is not supported on this platform."

src/fsharp/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@
153153
<Compile Include="..\absil\illib.fs">
154154
<Link>Utilities\illib.fs</Link>
155155
</Compile>
156+
<Compile Include="..\utils\FileSystem.fsi">
157+
<Link>Utilities\FileSystem.fsi</Link>
158+
</Compile>
156159
<Compile Include="..\utils\FileSystem.fs">
157160
<Link>Utilities\FileSystem.fs</Link>
158161
</Compile>

src/fsharp/FSharp.Core/printf.fs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ module internal PrintfImpl =
724724
else
725725
fun (v: obj) -> noJustificationCore (f v) true (isPositive v) prefix
726726

727-
/// contains functions to handle left\right and no justification case for numbers
727+
/// contains functions to handle left/right and no justification case for numbers
728728
module Integer =
729729

730730
let eliminateNative (v: obj) =
@@ -821,21 +821,27 @@ module internal PrintfImpl =
821821
(rightJustify f prefix padChar isUnsigned)
822822

823823
let getValueConverter (spec: FormatSpecifier) : ValueConverter =
824-
let c = spec.TypeChar
825-
if c = 'd' || c = 'i' then
824+
match spec.TypeChar with
825+
| 'd' | 'i' ->
826826
withPadding spec false toString
827-
elif c = 'u' then
827+
| 'u' ->
828828
withPadding spec true (toUnsigned >> toString)
829-
elif c = 'x' then
829+
| 'x' ->
830830
withPadding spec true (toFormattedString "x")
831-
elif c = 'X' then
831+
| 'X' ->
832832
withPadding spec true (toFormattedString "X")
833-
elif c = 'o' then
833+
| 'o' ->
834834
withPadding spec true (fun (v: obj) ->
835+
// Convert.ToInt64 throws for uint64 with values above int64 range so cast directly
835836
match toUnsigned v with
836837
| :? uint64 as u -> Convert.ToString(int64 u, 8)
837838
| u -> Convert.ToString(Convert.ToInt64 u, 8))
838-
else raise (ArgumentException())
839+
| 'B' ->
840+
withPadding spec true (fun (v: obj) ->
841+
match toUnsigned v with
842+
| :? uint64 as u -> Convert.ToString(int64 u, 2)
843+
| u -> Convert.ToString(Convert.ToInt64 u, 2))
844+
| _ -> invalidArg (nameof spec) "Invalid integer format"
839845

840846
module FloatAndDecimal =
841847

@@ -982,7 +988,7 @@ module internal PrintfImpl =
982988
Basic.withPadding spec (fun (c: obj) -> (unbox<char> c).ToString())
983989
| 'M' ->
984990
FloatAndDecimal.withPadding spec (fun _ -> "G") "G" // %M ignores precision
985-
| 'd' | 'i' | 'x' | 'X' | 'u' | 'o'->
991+
| 'd' | 'i' | 'u' | 'B' | 'o' | 'x' | 'X' ->
986992
Integer.getValueConverter spec
987993
| 'e' | 'E'
988994
| 'f' | 'F'

src/fsharp/FxResolver.fs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type internal FxResolver(assumeDotNetFramework: bool, projectDir: string, useSdk
8888
| Some dotnetHostPath ->
8989
try
9090
let workingDir =
91-
if Directory.Exists(projectDir) then
91+
if FileSystem.DirectoryExistsShim(projectDir) then
9292
Some projectDir
9393
else
9494
None
@@ -131,8 +131,8 @@ type internal FxResolver(assumeDotNetFramework: bool, projectDir: string, useSdk
131131
let sdksDir =
132132
match getDotnetHostDirectory() with
133133
| Some dotnetDir ->
134-
let candidate = Path.GetFullPath(Path.Combine(dotnetDir, "sdk"))
135-
if Directory.Exists(candidate) then Some candidate else None
134+
let candidate = FileSystem.GetFullPathShim(Path.Combine(dotnetDir, "sdk"))
135+
if FileSystem.DirectoryExistsShim(candidate) then Some candidate else None
136136
| None -> None
137137

138138
match sdksDir with
@@ -177,13 +177,14 @@ type internal FxResolver(assumeDotNetFramework: bool, projectDir: string, useSdk
177177
| Some dir ->
178178
try
179179
let dotnetConfigFile = Path.Combine(dir, "dotnet.runtimeconfig.json")
180-
let dotnetConfig = FileSystem.OpenFileForReadShim(dotnetConfigFile).AsStream().ReadAllText()
180+
use stream = FileSystem.OpenFileForReadShim(dotnetConfigFile)
181+
let dotnetConfig = stream.ReadAllText()
181182
let pattern = "\"version\": \""
182183
let startPos = dotnetConfig.IndexOf(pattern, StringComparison.OrdinalIgnoreCase) + pattern.Length
183184
let endPos = dotnetConfig.IndexOf("\"", startPos)
184185
let ver = dotnetConfig.[startPos..endPos-1]
185-
let path = Path.GetFullPath(Path.Combine(dir, "..", "..", "shared", "Microsoft.NETCore.App", ver))
186-
if Directory.Exists(path) then
186+
let path = FileSystem.GetFullPathShim(Path.Combine(dir, "..", "..", "shared", "Microsoft.NETCore.App", ver))
187+
if FileSystem.DirectoryExistsShim(path) then
187188
path, warnings
188189
else
189190
getRunningImplementationAssemblyDir(), warnings
@@ -322,7 +323,8 @@ type internal FxResolver(assumeDotNetFramework: bool, projectDir: string, useSdk
322323
| asm ->
323324
let depsJsonPath = Path.ChangeExtension(asm.Location, "deps.json")
324325
if FileSystem.FileExistsShim(depsJsonPath) then
325-
FileSystem.OpenFileForReadShim(depsJsonPath).AsReadOnlyStream().ReadAllText()
326+
use stream = FileSystem.OpenFileForReadShim(depsJsonPath)
327+
stream.ReadAllText()
326328
else
327329
""
328330
with _ ->
@@ -783,7 +785,8 @@ type internal FxResolver(assumeDotNetFramework: bool, projectDir: string, useSdk
783785
match sdkDir with
784786
| Some dir ->
785787
let dotnetConfigFile = Path.Combine(dir, "dotnet.runtimeconfig.json")
786-
let dotnetConfig = FileSystem.OpenFileForReadShim(dotnetConfigFile).AsReadOnlyStream().ReadAllText()
788+
use stream = FileSystem.OpenFileForReadShim(dotnetConfigFile)
789+
let dotnetConfig = stream.ReadAllText()
787790
let pattern = "\"tfm\": \""
788791
let startPos = dotnetConfig.IndexOf(pattern, StringComparison.OrdinalIgnoreCase) + pattern.Length
789792
let endPos = dotnetConfig.IndexOf("\"", startPos)

src/fsharp/LanguageFeatures.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type LanguageFeature =
3636
| StringInterpolation
3737
| OverloadsForCustomOperations
3838
| ExpandedMeasurables
39+
| PrintfBinaryFormat
3940

4041
/// LanguageVersion management
4142
type LanguageVersion (specifiedVersionAsString) =
@@ -77,6 +78,7 @@ type LanguageVersion (specifiedVersionAsString) =
7778
LanguageFeature.OverloadsForCustomOperations, previewVersion
7879
LanguageFeature.ExpandedMeasurables, previewVersion
7980
LanguageFeature.FromEndSlicing, previewVersion
81+
LanguageFeature.PrintfBinaryFormat, previewVersion
8082
]
8183

8284
let specified =
@@ -150,6 +152,7 @@ type LanguageVersion (specifiedVersionAsString) =
150152
| LanguageFeature.StringInterpolation -> FSComp.SR.featureStringInterpolation()
151153
| LanguageFeature.OverloadsForCustomOperations -> FSComp.SR.featureOverloadsForCustomOperations()
152154
| LanguageFeature.ExpandedMeasurables -> FSComp.SR.featureExpandedMeasurables()
155+
| LanguageFeature.PrintfBinaryFormat -> FSComp.SR.featurePrintfBinaryFormat()
153156

154157
/// Get a version string associated with the given feature.
155158
member _.GetFeatureVersionString feature =

src/fsharp/LanguageFeatures.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type LanguageFeature =
2424
| StringInterpolation
2525
| OverloadsForCustomOperations
2626
| ExpandedMeasurables
27+
| PrintfBinaryFormat
2728

2829
/// LanguageVersion management
2930
type LanguageVersion =

0 commit comments

Comments
 (0)