Skip to content

Commit 07cbd50

Browse files
committed
Merge remote-tracking branch 'upstream/main' into graph-tc
2 parents c1bf185 + 73714c9 commit 07cbd50

Some content is hidden

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

48 files changed

+1111
-228
lines changed

FSharpBuild.Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<OtherFlags>$(OtherFlags) --nowarn:3384</OtherFlags>
2828
<OtherFlags>$(OtherFlags) --times --nowarn:75</OtherFlags>
2929
<OtherFlags Condition="$(ParallelCheckingWithSignatureFilesOn) == 'true'">$(OtherFlags) --test:ParallelCheckingWithSignatureFilesOn</OtherFlags>
30+
<OtherFlags Condition="$(AdditionalFscCmdFlags) != ''">$(OtherFlags) $(AdditionalFscCmdFlags)</OtherFlags>
3031
</PropertyGroup>
3132

3233
<!-- nuget -->

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
<MicrosoftNETCoreILAsmVersion>5.0.0-preview.7.20364.11</MicrosoftNETCoreILAsmVersion>
199199
<MicrosoftNETTestSdkVersion>16.11.0</MicrosoftNETTestSdkVersion>
200200
<MicrosoftWin32RegistryVersion>5.0.0</MicrosoftWin32RegistryVersion>
201-
<NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
201+
<NewtonsoftJsonVersion>13.0.2</NewtonsoftJsonVersion>
202202
<NUnitVersion>3.13.2</NUnitVersion>
203203
<NUnit3TestAdapterVersion>4.1.0</NUnit3TestAdapterVersion>
204204
<NUnitLiteVersion>3.11.0</NUnitLiteVersion>

src/Compiler/AbstractIL/ilsign.fs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,6 @@ let signStream stream keyBlob =
297297
let signature = createSignature hash keyBlob KeyType.KeyPair
298298
patchSignature stream peReader signature
299299

300-
let signFile fileName keyBlob =
301-
use fs =
302-
FileSystem.OpenFileForWriteShim(fileName, FileMode.Open, FileAccess.ReadWrite)
303-
304-
signStream fs keyBlob
305-
306300
let signatureSize (pk: byte[]) =
307301
if pk.Length < 25 then
308302
raise (CryptographicException(getResourceString (FSComp.SR.ilSignInvalidPKBlob ())))
@@ -339,18 +333,9 @@ let signerOpenKeyPairFile filePath =
339333

340334
let signerGetPublicKeyForKeyPair (kp: keyPair) : pubkey = getPublicKeyForKeyPair kp
341335

342-
let signerGetPublicKeyForKeyContainer (_kcName: keyContainerName) : pubkey =
343-
raise (NotImplementedException("signerGetPublicKeyForKeyContainer is not yet implemented"))
344-
345-
let signerCloseKeyContainer (_kc: keyContainerName) : unit =
346-
raise (NotImplementedException("signerCloseKeyContainer is not yet implemented"))
347-
348336
let signerSignatureSize (pk: pubkey) : int = signatureSize pk
349337

350-
let signerSignFileWithKeyPair (fileName: string) (kp: keyPair) : unit = signFile fileName kp
351-
352-
let signerSignFileWithKeyContainer (_fileName: string) (_kcName: keyContainerName) : unit =
353-
raise (NotImplementedException("signerSignFileWithKeyContainer is not yet implemented"))
338+
let signerSignStreamWithKeyPair stream keyBlob = signStream stream keyBlob
354339

355340
let failWithContainerSigningUnsupportedOnThisPlatform () =
356341
failwith (FSComp.SR.containerSigningUnsupportedOnThisPlatform () |> snd)
@@ -371,13 +356,6 @@ type ILStrongNameSigner =
371356
static member OpenKeyPairFile s = KeyPair(signerOpenKeyPairFile s)
372357
static member OpenKeyContainer s = KeyContainer s
373358

374-
member s.Close() =
375-
match s with
376-
| PublicKeySigner _
377-
| PublicKeyOptionsSigner _
378-
| KeyPair _ -> ()
379-
| KeyContainer _ -> failWithContainerSigningUnsupportedOnThisPlatform ()
380-
381359
member s.IsFullySigned =
382360
match s with
383361
| PublicKeySigner _ -> false
@@ -412,9 +390,9 @@ type ILStrongNameSigner =
412390
| KeyPair kp -> pkSignatureSize (signerGetPublicKeyForKeyPair kp)
413391
| KeyContainer _ -> failWithContainerSigningUnsupportedOnThisPlatform ()
414392

415-
member s.SignFile file =
393+
member s.SignStream stream =
416394
match s with
417395
| PublicKeySigner _ -> ()
418396
| PublicKeyOptionsSigner _ -> ()
419-
| KeyPair kp -> signerSignFileWithKeyPair file kp
397+
| KeyPair kp -> signerSignStreamWithKeyPair stream kp
420398
| KeyContainer _ -> failWithContainerSigningUnsupportedOnThisPlatform ()

src/Compiler/AbstractIL/ilsign.fsi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
88
module internal FSharp.Compiler.AbstractIL.StrongNameSign
99

10+
open System
11+
open System.IO
12+
1013
//---------------------------------------------------------------------
1114
// Strong name signing
1215
//---------------------------------------------------------------------
@@ -17,8 +20,7 @@ type ILStrongNameSigner =
1720
static member OpenPublicKey: byte[] -> ILStrongNameSigner
1821
static member OpenKeyPairFile: string -> ILStrongNameSigner
1922
static member OpenKeyContainer: string -> ILStrongNameSigner
20-
member Close: unit -> unit
2123
member IsFullySigned: bool
2224
member PublicKey: byte[]
2325
member SignatureSize: int
24-
member SignFile: string -> unit
26+
member SignStream: Stream -> unit

src/Compiler/AbstractIL/ilwrite.fs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,9 +3711,22 @@ let writePdb (
37113711
// Used to capture the pdb file bytes in the case we're generating in-memory
37123712
let mutable pdbBytes = None
37133713

3714+
let signImage () =
3715+
// Sign the binary. No further changes to binary allowed past this point!
3716+
match signer with
3717+
| None -> ()
3718+
| Some s ->
3719+
use fs = reopenOutput()
3720+
try
3721+
s.SignStream fs
3722+
with exn ->
3723+
failwith ($"Warning: A call to SignFile failed ({exn.Message})")
3724+
reportTime showTimes "Signing Image"
3725+
37143726
// Now we've done the bulk of the binary, do the PDB file and fixup the binary.
37153727
match pdbfile with
3716-
| None -> ()
3728+
| None -> signImage ()
3729+
37173730
| Some pdbfile ->
37183731
let idd =
37193732
match pdbInfoOpt with
@@ -3763,28 +3776,14 @@ let writePdb (
37633776
os2.BaseStream.Seek (int64 (textV2P i.iddChunk.addr), SeekOrigin.Begin) |> ignore
37643777
if i.iddChunk.size < i.iddData.Length then failwith "Debug data area is not big enough. Debug info may not be usable"
37653778
writeBytes os2 i.iddData
3779+
reportTime showTimes "Finalize PDB"
3780+
signImage ()
37663781
os2.Dispose()
37673782
with exn ->
37683783
failwith ("Error while writing debug directory entry: " + exn.Message)
37693784
(try os2.Dispose(); FileSystem.FileDeleteShim outfile with _ -> ())
37703785
reraise()
37713786

3772-
reportTime showTimes "Finalize PDB"
3773-
3774-
// Sign the binary. No further changes to binary allowed past this point!
3775-
match signer with
3776-
| None -> ()
3777-
| Some s ->
3778-
try
3779-
s.SignFile outfile
3780-
s.Close()
3781-
with exn ->
3782-
failwith ("Warning: A call to SignFile failed ("+exn.Message+")")
3783-
(try s.Close() with _ -> ())
3784-
(try FileSystem.FileDeleteShim outfile with _ -> ())
3785-
()
3786-
3787-
reportTime showTimes "Signing Image"
37883787
pdbBytes
37893788

37903789
type options =
@@ -4528,7 +4527,7 @@ let writeBinaryFiles (options: options, modul, normalizeAssemblyRefs) =
45284527
reraise()
45294528

45304529
let reopenOutput () =
4531-
FileSystem.OpenFileForWriteShim(options.outfile, FileMode.Open, FileAccess.Write, FileShare.Read)
4530+
FileSystem.OpenFileForWriteShim(options.outfile, FileMode.Open, FileAccess.ReadWrite, FileShare.Read)
45324531

45334532
writePdb (options.dumpDebugInfo,
45344533
options.showTimes,
@@ -4558,7 +4557,9 @@ let writeBinaryInMemory (options: options, modul, normalizeAssemblyRefs) =
45584557
let pdbData, pdbInfoOpt, debugDirectoryChunk, debugDataChunk, debugChecksumPdbChunk, debugEmbeddedPdbChunk, debugDeterministicPdbChunk, textV2P, _mappings =
45594558
writeBinaryAux(stream, options, modul, normalizeAssemblyRefs)
45604559

4561-
let reopenOutput () = stream
4560+
let reopenOutput () =
4561+
stream.Seek(0, SeekOrigin.Begin) |> ignore
4562+
stream
45624563

45634564
let pdbBytes =
45644565
writePdb (options.dumpDebugInfo,

src/Compiler/Checking/CheckDeclarations.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5316,8 +5316,8 @@ let CheckOneImplFile
53165316
use _ =
53175317
Activity.start "CheckDeclarations.CheckOneImplFile"
53185318
[|
5319-
"fileName", fileName
5320-
"qualifiedNameOfFile", qualNameOfFile.Text
5319+
Activity.Tags.fileName, fileName
5320+
Activity.Tags.qualifiedNameOfFile, qualNameOfFile.Text
53215321
|]
53225322
let cenv =
53235323
cenv.Create (g, isScript, amap, thisCcu, false, Option.isSome rootSigOpt,
@@ -5450,8 +5450,8 @@ let CheckOneSigFile (g, amap, thisCcu, checkForErrors, conditionalDefines, tcSin
54505450
use _ =
54515451
Activity.start "CheckDeclarations.CheckOneSigFile"
54525452
[|
5453-
"fileName", sigFile.FileName
5454-
"qualifiedNameOfFile", sigFile.QualifiedName.Text
5453+
Activity.Tags.fileName, sigFile.FileName
5454+
Activity.Tags.qualifiedNameOfFile, sigFile.QualifiedName.Text
54555455
|]
54565456
let cenv =
54575457
cenv.Create

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4378,7 +4378,7 @@ and CheckIWSAM (cenv: cenv) (env: TcEnv) checkConstraints iwsam m tcref =
43784378
if iwsam = WarnOnIWSAM.Yes && isInterfaceTy g ty && checkConstraints = CheckCxs then
43794379
let tcref = tcrefOfAppTy g ty
43804380
let meths = AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults cenv.infoReader env.NameEnv None ad IgnoreOverrides m ty
4381-
if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot) then
4381+
if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot && not meth.IsExtensionMember) then
43824382
warning(Error(FSComp.SR.tcUsingInterfaceWithStaticAbstractMethodAsType(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
43834383

43844384
and TcLongIdentType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env tpenv synLongId =
@@ -7165,13 +7165,14 @@ and TcInterpolatedStringExpr cenv (overallTy: OverallTy) env m tpenv (parts: Syn
71657165
// Type check the expressions filling the holes
71667166

71677167
if List.isEmpty synFillExprs then
7168-
let str = mkString g m printfFormatString
7169-
71707168
if isString then
7169+
let sb = System.Text.StringBuilder(printfFormatString).Replace("%%", "%")
7170+
let str = mkString g m (sb.ToString())
71717171
TcPropagatingExprLeafThenConvert cenv overallTy g.string_ty env (* true *) m (fun () ->
71727172
str, tpenv
71737173
)
71747174
else
7175+
let str = mkString g m printfFormatString
71757176
mkCallNewFormat g m printerTy printerArgTy printerResidueTy printerResultTy printerTupleTy str, tpenv
71767177
else
71777178
// Type check the expressions filling the holes

src/Compiler/Checking/CheckFormatStrings.fs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,21 @@ let newInfo () =
4848
addZeros = false
4949
precision = false}
5050

51+
let escapeDotnetFormatString str =
52+
str
53+
// We need to double '{' and '}', because even if they were escaped in the
54+
// original string, extra curly braces were stripped away by the F# lexer.
55+
|> Seq.collect (fun x -> if x = '{' || x = '}' then [x;x] else [x])
56+
|> System.String.Concat
57+
5158
let parseFormatStringInternal
5259
(m: range)
5360
(fragRanges: range list)
5461
(g: TcGlobals)
5562
isInterpolated
5663
isFormattableString
5764
(context: FormatStringCheckContext option)
58-
fmt
65+
(fmt: string)
5966
printerArgTy
6067
printerResidueTy =
6168

@@ -86,6 +93,8 @@ let parseFormatStringInternal
8693
// there are no accurate intra-string ranges available for exact error message locations within the string.
8794
// The 'm' range passed as an input is however accurate and covers the whole string.
8895
//
96+
let escapeFormatStringEnabled = g.langVersion.SupportsFeature Features.LanguageFeature.EscapeDotnetFormattableStrings
97+
8998
let fmt, fragments =
9099

91100
//printfn "--------------------"
@@ -175,7 +184,7 @@ let parseFormatStringInternal
175184
| _ ->
176185
// Don't muck with the fmt when there is no source code context to go get the original
177186
// source code (i.e. when compiling or background checking)
178-
fmt, [ (0, 1, m) ]
187+
(if escapeFormatStringEnabled then escapeDotnetFormatString fmt else fmt), [ (0, 1, m) ]
179188

180189
let len = fmt.Length
181190

src/Compiler/Driver/CompilerConfig.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ type TcConfigBuilder =
525525

526526
/// show times between passes?
527527
mutable showTimes: bool
528+
mutable writeTimesToFile: string option
528529
mutable showLoadedAssemblies: bool
529530
mutable continueAfterParseFailure: bool
530531

@@ -749,6 +750,7 @@ type TcConfigBuilder =
749750
productNameForBannerText = FSharpProductName
750751
showBanner = true
751752
showTimes = false
753+
writeTimesToFile = None
752754
showLoadedAssemblies = false
753755
continueAfterParseFailure = false
754756
#if !NO_TYPEPROVIDERS
@@ -1308,6 +1310,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
13081310
member _.productNameForBannerText = data.productNameForBannerText
13091311
member _.showBanner = data.showBanner
13101312
member _.showTimes = data.showTimes
1313+
member _.writeTimesToFile = data.writeTimesToFile
13111314
member _.showLoadedAssemblies = data.showLoadedAssemblies
13121315
member _.continueAfterParseFailure = data.continueAfterParseFailure
13131316
#if !NO_TYPEPROVIDERS

src/Compiler/Driver/CompilerConfig.fsi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ type TcConfigBuilder =
436436

437437
mutable showTimes: bool
438438

439+
mutable writeTimesToFile: string option
440+
439441
mutable showLoadedAssemblies: bool
440442

441443
mutable continueAfterParseFailure: bool
@@ -758,6 +760,8 @@ type TcConfig =
758760

759761
member showTimes: bool
760762

763+
member writeTimesToFile: string option
764+
761765
member showLoadedAssemblies: bool
762766

763767
member continueAfterParseFailure: bool

0 commit comments

Comments
 (0)