Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into graph-tc
Browse files Browse the repository at this point in the history
  • Loading branch information
safesparrow committed Dec 19, 2022
2 parents c1bf185 + 73714c9 commit 07cbd50
Show file tree
Hide file tree
Showing 48 changed files with 1,111 additions and 228 deletions.
1 change: 1 addition & 0 deletions FSharpBuild.Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<OtherFlags>$(OtherFlags) --nowarn:3384</OtherFlags>
<OtherFlags>$(OtherFlags) --times --nowarn:75</OtherFlags>
<OtherFlags Condition="$(ParallelCheckingWithSignatureFilesOn) == 'true'">$(OtherFlags) --test:ParallelCheckingWithSignatureFilesOn</OtherFlags>
<OtherFlags Condition="$(AdditionalFscCmdFlags) != ''">$(OtherFlags) $(AdditionalFscCmdFlags)</OtherFlags>
</PropertyGroup>

<!-- nuget -->
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<MicrosoftNETCoreILAsmVersion>5.0.0-preview.7.20364.11</MicrosoftNETCoreILAsmVersion>
<MicrosoftNETTestSdkVersion>16.11.0</MicrosoftNETTestSdkVersion>
<MicrosoftWin32RegistryVersion>5.0.0</MicrosoftWin32RegistryVersion>
<NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
<NewtonsoftJsonVersion>13.0.2</NewtonsoftJsonVersion>
<NUnitVersion>3.13.2</NUnitVersion>
<NUnit3TestAdapterVersion>4.1.0</NUnit3TestAdapterVersion>
<NUnitLiteVersion>3.11.0</NUnitLiteVersion>
Expand Down
28 changes: 3 additions & 25 deletions src/Compiler/AbstractIL/ilsign.fs
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,6 @@ let signStream stream keyBlob =
let signature = createSignature hash keyBlob KeyType.KeyPair
patchSignature stream peReader signature

let signFile fileName keyBlob =
use fs =
FileSystem.OpenFileForWriteShim(fileName, FileMode.Open, FileAccess.ReadWrite)

signStream fs keyBlob

let signatureSize (pk: byte[]) =
if pk.Length < 25 then
raise (CryptographicException(getResourceString (FSComp.SR.ilSignInvalidPKBlob ())))
Expand Down Expand Up @@ -339,18 +333,9 @@ let signerOpenKeyPairFile filePath =

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

let signerGetPublicKeyForKeyContainer (_kcName: keyContainerName) : pubkey =
raise (NotImplementedException("signerGetPublicKeyForKeyContainer is not yet implemented"))

let signerCloseKeyContainer (_kc: keyContainerName) : unit =
raise (NotImplementedException("signerCloseKeyContainer is not yet implemented"))

let signerSignatureSize (pk: pubkey) : int = signatureSize pk

let signerSignFileWithKeyPair (fileName: string) (kp: keyPair) : unit = signFile fileName kp

let signerSignFileWithKeyContainer (_fileName: string) (_kcName: keyContainerName) : unit =
raise (NotImplementedException("signerSignFileWithKeyContainer is not yet implemented"))
let signerSignStreamWithKeyPair stream keyBlob = signStream stream keyBlob

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

member s.Close() =
match s with
| PublicKeySigner _
| PublicKeyOptionsSigner _
| KeyPair _ -> ()
| KeyContainer _ -> failWithContainerSigningUnsupportedOnThisPlatform ()

member s.IsFullySigned =
match s with
| PublicKeySigner _ -> false
Expand Down Expand Up @@ -412,9 +390,9 @@ type ILStrongNameSigner =
| KeyPair kp -> pkSignatureSize (signerGetPublicKeyForKeyPair kp)
| KeyContainer _ -> failWithContainerSigningUnsupportedOnThisPlatform ()

member s.SignFile file =
member s.SignStream stream =
match s with
| PublicKeySigner _ -> ()
| PublicKeyOptionsSigner _ -> ()
| KeyPair kp -> signerSignFileWithKeyPair file kp
| KeyPair kp -> signerSignStreamWithKeyPair stream kp
| KeyContainer _ -> failWithContainerSigningUnsupportedOnThisPlatform ()
6 changes: 4 additions & 2 deletions src/Compiler/AbstractIL/ilsign.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
module internal FSharp.Compiler.AbstractIL.StrongNameSign

open System
open System.IO

//---------------------------------------------------------------------
// Strong name signing
//---------------------------------------------------------------------
Expand All @@ -17,8 +20,7 @@ type ILStrongNameSigner =
static member OpenPublicKey: byte[] -> ILStrongNameSigner
static member OpenKeyPairFile: string -> ILStrongNameSigner
static member OpenKeyContainer: string -> ILStrongNameSigner
member Close: unit -> unit
member IsFullySigned: bool
member PublicKey: byte[]
member SignatureSize: int
member SignFile: string -> unit
member SignStream: Stream -> unit
39 changes: 20 additions & 19 deletions src/Compiler/AbstractIL/ilwrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3711,9 +3711,22 @@ let writePdb (
// Used to capture the pdb file bytes in the case we're generating in-memory
let mutable pdbBytes = None

let signImage () =
// Sign the binary. No further changes to binary allowed past this point!
match signer with
| None -> ()
| Some s ->
use fs = reopenOutput()
try
s.SignStream fs
with exn ->
failwith ($"Warning: A call to SignFile failed ({exn.Message})")
reportTime showTimes "Signing Image"

// Now we've done the bulk of the binary, do the PDB file and fixup the binary.
match pdbfile with
| None -> ()
| None -> signImage ()

| Some pdbfile ->
let idd =
match pdbInfoOpt with
Expand Down Expand Up @@ -3763,28 +3776,14 @@ let writePdb (
os2.BaseStream.Seek (int64 (textV2P i.iddChunk.addr), SeekOrigin.Begin) |> ignore
if i.iddChunk.size < i.iddData.Length then failwith "Debug data area is not big enough. Debug info may not be usable"
writeBytes os2 i.iddData
reportTime showTimes "Finalize PDB"
signImage ()
os2.Dispose()
with exn ->
failwith ("Error while writing debug directory entry: " + exn.Message)
(try os2.Dispose(); FileSystem.FileDeleteShim outfile with _ -> ())
reraise()

reportTime showTimes "Finalize PDB"

// Sign the binary. No further changes to binary allowed past this point!
match signer with
| None -> ()
| Some s ->
try
s.SignFile outfile
s.Close()
with exn ->
failwith ("Warning: A call to SignFile failed ("+exn.Message+")")
(try s.Close() with _ -> ())
(try FileSystem.FileDeleteShim outfile with _ -> ())
()

reportTime showTimes "Signing Image"
pdbBytes

type options =
Expand Down Expand Up @@ -4528,7 +4527,7 @@ let writeBinaryFiles (options: options, modul, normalizeAssemblyRefs) =
reraise()

let reopenOutput () =
FileSystem.OpenFileForWriteShim(options.outfile, FileMode.Open, FileAccess.Write, FileShare.Read)
FileSystem.OpenFileForWriteShim(options.outfile, FileMode.Open, FileAccess.ReadWrite, FileShare.Read)

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

let reopenOutput () = stream
let reopenOutput () =
stream.Seek(0, SeekOrigin.Begin) |> ignore
stream

let pdbBytes =
writePdb (options.dumpDebugInfo,
Expand Down
8 changes: 4 additions & 4 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5316,8 +5316,8 @@ let CheckOneImplFile
use _ =
Activity.start "CheckDeclarations.CheckOneImplFile"
[|
"fileName", fileName
"qualifiedNameOfFile", qualNameOfFile.Text
Activity.Tags.fileName, fileName
Activity.Tags.qualifiedNameOfFile, qualNameOfFile.Text
|]
let cenv =
cenv.Create (g, isScript, amap, thisCcu, false, Option.isSome rootSigOpt,
Expand Down Expand Up @@ -5450,8 +5450,8 @@ let CheckOneSigFile (g, amap, thisCcu, checkForErrors, conditionalDefines, tcSin
use _ =
Activity.start "CheckDeclarations.CheckOneSigFile"
[|
"fileName", sigFile.FileName
"qualifiedNameOfFile", sigFile.QualifiedName.Text
Activity.Tags.fileName, sigFile.FileName
Activity.Tags.qualifiedNameOfFile, sigFile.QualifiedName.Text
|]
let cenv =
cenv.Create
Expand Down
7 changes: 4 additions & 3 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4378,7 +4378,7 @@ and CheckIWSAM (cenv: cenv) (env: TcEnv) checkConstraints iwsam m tcref =
if iwsam = WarnOnIWSAM.Yes && isInterfaceTy g ty && checkConstraints = CheckCxs then
let tcref = tcrefOfAppTy g ty
let meths = AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults cenv.infoReader env.NameEnv None ad IgnoreOverrides m ty
if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot) then
if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot && not meth.IsExtensionMember) then
warning(Error(FSComp.SR.tcUsingInterfaceWithStaticAbstractMethodAsType(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))

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

if List.isEmpty synFillExprs then
let str = mkString g m printfFormatString

if isString then
let sb = System.Text.StringBuilder(printfFormatString).Replace("%%", "%")
let str = mkString g m (sb.ToString())
TcPropagatingExprLeafThenConvert cenv overallTy g.string_ty env (* true *) m (fun () ->
str, tpenv
)
else
let str = mkString g m printfFormatString
mkCallNewFormat g m printerTy printerArgTy printerResidueTy printerResultTy printerTupleTy str, tpenv
else
// Type check the expressions filling the holes
Expand Down
13 changes: 11 additions & 2 deletions src/Compiler/Checking/CheckFormatStrings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,21 @@ let newInfo () =
addZeros = false
precision = false}

let escapeDotnetFormatString str =
str
// We need to double '{' and '}', because even if they were escaped in the
// original string, extra curly braces were stripped away by the F# lexer.
|> Seq.collect (fun x -> if x = '{' || x = '}' then [x;x] else [x])
|> System.String.Concat

let parseFormatStringInternal
(m: range)
(fragRanges: range list)
(g: TcGlobals)
isInterpolated
isFormattableString
(context: FormatStringCheckContext option)
fmt
(fmt: string)
printerArgTy
printerResidueTy =

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

let fmt, fragments =

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

let len = fmt.Length

Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ type TcConfigBuilder =

/// show times between passes?
mutable showTimes: bool
mutable writeTimesToFile: string option
mutable showLoadedAssemblies: bool
mutable continueAfterParseFailure: bool

Expand Down Expand Up @@ -749,6 +750,7 @@ type TcConfigBuilder =
productNameForBannerText = FSharpProductName
showBanner = true
showTimes = false
writeTimesToFile = None
showLoadedAssemblies = false
continueAfterParseFailure = false
#if !NO_TYPEPROVIDERS
Expand Down Expand Up @@ -1308,6 +1310,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
member _.productNameForBannerText = data.productNameForBannerText
member _.showBanner = data.showBanner
member _.showTimes = data.showTimes
member _.writeTimesToFile = data.writeTimesToFile
member _.showLoadedAssemblies = data.showLoadedAssemblies
member _.continueAfterParseFailure = data.continueAfterParseFailure
#if !NO_TYPEPROVIDERS
Expand Down
4 changes: 4 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ type TcConfigBuilder =

mutable showTimes: bool

mutable writeTimesToFile: string option

mutable showLoadedAssemblies: bool

mutable continueAfterParseFailure: bool
Expand Down Expand Up @@ -758,6 +760,8 @@ type TcConfig =

member showTimes: bool

member writeTimesToFile: string option

member showLoadedAssemblies: bool

member continueAfterParseFailure: bool
Expand Down

0 comments on commit 07cbd50

Please sign in to comment.