Skip to content

Commit

Permalink
Misc compiler enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Nov 18, 2023
1 parent ab0a997 commit 6d89ec5
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 33 deletions.
1 change: 1 addition & 0 deletions AltCover.Async/AltCover.Async.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ContinuousIntegrationBuild>false</ContinuousIntegrationBuild>
<DeterministicSourcePaths>false</DeterministicSourcePaths>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
<OtherFlags>--keyfile:$(InfrastructureKey)</OtherFlags>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
2 changes: 1 addition & 1 deletion AltCover.Avalonia/MainWindow.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ type MainWindow() as this =
|> Event.add (fun index ->
let mutable auxModel =
{ Model = List<TreeViewItem>()
Row = null }
Row = nullObject }

let addNode =
fun
Expand Down
1 change: 1 addition & 0 deletions AltCover.Engine/Augment.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Augment =
#else
module internal Augment =
#endif
let nullObject : System.Object = null

#if !ValidateGendarmeEmulation
[<SuppressMessage("Microsoft.Globalization",
Expand Down
2 changes: 1 addition & 1 deletion AltCover.Engine/CecilEx.fs
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,4 @@ module internal CecilExtension =
|> Seq.filter (fun i -> i.OpCode = OpCodes.Tail)
|> Seq.iter (fun i ->
i.OpCode <- OpCodes.Nop
i.Operand <- null)
i.Operand <- nullObject)
2 changes: 1 addition & 1 deletion AltCover.Engine/OpenCover.fs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ module internal OpenCover =
|> Option.map _.Value

if e.Interesting && attr = Some "File" then
element.SetAttributeValue("skippedDueTo".X, null)
element.SetAttributeValue("skippedDueTo".X, nullObject)

match (e.Interesting, e.SeqPnt, s.Excluded) with
| (true, Some codeSegment, Nothing) ->
Expand Down
4 changes: 2 additions & 2 deletions AltCover.Engine/ProgramDatabase.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module internal ProgramDatabase =
.GetMethod("GetEmbeddedPortablePdbEntry")

let internal getEmbeddedPortablePdbEntry (assembly: AssemblyDefinition) =
getEmbed.Invoke(null, [| assembly.MainModule.GetDebugHeader() :> obj |])
getEmbed.Invoke(nullObject, [| assembly.MainModule.GetDebugHeader() :> obj |])
:?> ImageDebugHeaderEntry

let internal getSymbolsByFolder fileName folderName =
Expand Down Expand Up @@ -176,7 +176,7 @@ module internal ProgramDatabase =
let msfdirectory, dir =
construct "Microsoft.Cci.Pdb.MsfDirectory" [| reader; head; bits |]

let datastream =
let datastream : Object =
(field msfdirectory "streams" dir) :?> System.Collections.IEnumerable
|> Seq.cast
|> Seq.skip 1
Expand Down
2 changes: 0 additions & 2 deletions AltCover.Engine/WhatIfExtension.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
open System.Diagnostics.CodeAnalysis
open System.Runtime.CompilerServices

[<Extension>]
module PrepareExtension =
[<Extension>]
let WhatIf (prepare: Abstract.IPrepareOptions) : AltCover.ValidatedCommandLine =
Expand All @@ -12,7 +11,6 @@ module PrepareExtension =
(AltCover.PrepareOptions.Abstract prepare)
.Validate() }

[<Extension>]
module CollectExtension =
[<Extension>]
let WhatIf
Expand Down
2 changes: 0 additions & 2 deletions AltCover.Engine/WhatIfExtension.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ open System.Runtime.CompilerServices /// no doc
///<summary>
/// `Abstract.IPrepareOptions` extension methods
///</summary>
[<Extension>]
module PrepareExtension = begin
///<summary>
/// Validates the supplied options
Expand All @@ -23,7 +22,6 @@ end
///<summary>
/// `Abstract.ICollectOptions` extension methods
///</summary>
[<Extension>]
module CollectExtension = begin
///<summary>
/// Validates the supplied options
Expand Down
6 changes: 4 additions & 2 deletions AltCover.Fake.DotNet.Testing.AltCover/AltCoverCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ module AltCoverCommand =
let parameters =
Fake.DotNet.DotNet.TestOptions.Create() |> options

let nullObject : Object = null

let args =
builder.Invoke(null, [| parameters |]) :?> string list
builder.Invoke(nullObject, [| parameters |]) :?> string list

let cmdArgs =
builder2.Invoke(
null,
nullObject,
[| ("test"
|> Args.fromWindowsCommandLine
|> Seq.toList)
Expand Down
6 changes: 4 additions & 2 deletions AltCover.PowerShell/Accelerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ type AddAcceleratorCommand() =
String.Empty)
)
then
let nullObject : System.Object = null
finalmap
|> Seq.iter (fun kv ->
adder.Invoke(null, [| kv.Key :> obj; kv.Value :> obj |])
adder.Invoke(nullObject, [| kv.Key :> obj; kv.Value :> obj |])
|> ignore)

/// <summary>
Expand Down Expand Up @@ -183,8 +184,9 @@ type GetAcceleratorCommand() =
acceleratorsType.GetProperty("Get")

let result = Hashtable()
let nullObject : System.Object = null

(finder.GetValue(null, [||]) :?> Dictionary<string, Type>)
(finder.GetValue(nullObject, [||]) :?> Dictionary<string, Type>)
|> Seq.iter (fun kv -> result.Add(kv.Key, kv.Value))

self.WriteObject result
1 change: 1 addition & 0 deletions AltCover.Recorder.Tests/AltCover.Recorder.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<!-- see https://github.com/NuGet/Home/issues/8797 -->
<NoWarn>NU1702</NoWarn>
<MSBuildWarningsAsMessages>NU1702</MSBuildWarningsAsMessages>
<OtherFlags>--keyfile:$(InfrastructureKey)</OtherFlags>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
3 changes: 2 additions & 1 deletion AltCover.Recorder/AltCover.Recorder.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE</DefineConstants>
<OtherFlags>$(OtherFlags) --standalone --staticlink:ICSharpCode.SharpZipLib</OtherFlags>
<OtherFlags>--keyfile:$(InfrastructureKey) --standalone --staticlink:ICSharpCode.SharpZipLib</OtherFlags>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DefineConstants>TRACE;DEBUG;CODE_ANALYSIS</DefineConstants>
<OtherFlags>--keyfile:$(InfrastructureKey)</OtherFlags>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion AltCover.Recorder/Base.fs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ module internal Counter =
let startTimeNode =
root.GetAttributeNode("startTime")

let nullObject : System.Object = null

if
format = ReportFormat.NCover
&& Object.ReferenceEquals(startTimeNode, null) |> not
&& Object.ReferenceEquals(startTimeNode, nullObject) |> not
then
let startTimeAttr = startTimeNode.Value

Expand Down
1 change: 1 addition & 0 deletions AltCover.Recorder2.Tests/AltCover.Recorder2.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<GenerateProgramFile>false</GenerateProgramFile>
<NoWarn>NU1702</NoWarn>
<MSBuildWarningsAsMessages>NU1702</MSBuildWarningsAsMessages>
<OtherFlags>--keyfile:$(InfrastructureKey)</OtherFlags>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
4 changes: 2 additions & 2 deletions AltCover.Tests/Runner.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2542,7 +2542,7 @@ module AltCoverRunnerTests =
.GetMethod("main", BindingFlags.NonPublic ||| BindingFlags.Static)

let returnCode =
main.Invoke(null, [| [| "RuNN"; "-r"; unique |] |])
main.Invoke(nullObject, [| [| "RuNN"; "-r"; unique |] |])

Assert.That(returnCode, Is.EqualTo 255)

Expand Down Expand Up @@ -3458,7 +3458,7 @@ module AltCoverRunnerTests =

Assert.That(r, Is.EqualTo 4)
Assert.That(File.Exists(unique + ".acv"))
Assert.That(counts, Is.EquivalentTo [])
Assert.That(counts, Is.Empty)

[<Test>]
let TrackingPayloadShouldReportAsExpected () =
Expand Down
4 changes: 2 additions & 2 deletions AltCover.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ module AltCoverTests =
[ StaticFilter.AsCovered
StaticFilter.Hidden
StaticFilter.NoFilter ]
|> List.map (fun k -> Visitor.I.selectExemption k [] Exemption.None)
|> List.map (fun k -> Visitor.I.selectExemption k List.empty<obj> Exemption.None)

test
<@
Expand Down Expand Up @@ -2837,7 +2837,7 @@ module AltCoverTests =
)

let unique = Guid.NewGuid().ToString()
let op _ = raise <| IOException(unique)
let op _ : Object = raise <| IOException(unique)

let x =
Assert.Throws<InvalidOperationException>(fun () ->
Expand Down
4 changes: 2 additions & 2 deletions AltCover.Tests/Tests2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,10 @@ has been prefixed with Ldc_I4_1 (1 byte)
let n = i.ToString().Replace("-", "_")

s.Constants.Add
<| ConstantDebugInformation("I" + n, primitive, null)
<| ConstantDebugInformation("I" + n, primitive, nullObject)

s.Constants.Add
<| ConstantDebugInformation("A" + n, np, null)
<| ConstantDebugInformation("A" + n, np, nullObject)

rescope.Scopes.Add s)

Expand Down
4 changes: 2 additions & 2 deletions AltCover.Tests/Tests3.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3682,7 +3682,7 @@ module AltCoverTests3 =
.GetMethod("main", BindingFlags.NonPublic ||| BindingFlags.Static)

let returnCode =
main.Invoke(null, [| [| "TargetsPath" |] |])
main.Invoke(nullObject, [| [| "TargetsPath" |] |])

Assert.That(returnCode, Is.EqualTo 0)
test <@ stderr.ToString() |> String.IsNullOrEmpty @>
Expand Down Expand Up @@ -3728,7 +3728,7 @@ module AltCoverTests3 =
.GetMethod("main", BindingFlags.NonPublic ||| BindingFlags.Static)

let returnCode =
main.Invoke(null, [| [| "-i"; unique |] |])
main.Invoke(nullObject, [| [| "-i"; unique |] |])

Assert.That(returnCode, Is.EqualTo 255)

Expand Down
4 changes: 2 additions & 2 deletions AltCover.Tests/XTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,15 +1418,15 @@ module AltCoverXTests =
let p =
t2.GetProperty("value", BindingFlags.NonPublic ||| BindingFlags.Static)

let v = p.GetValue(null)
let v = p.GetValue(nullObject)

test <@ v.IsNotNull @>
test <@ v.GetType() = typeof<System.Threading.AsyncLocal<Stack<int>>> @>

let m =
t2.GetMethod("instance", BindingFlags.NonPublic ||| BindingFlags.Static)

let v2 = m.Invoke(null, [||])
let v2 = m.Invoke(nullObject, [||])

test <@ v2.IsNotNull @>
test <@ v2.GetType() = typeof<Stack<int>> @>
Expand Down
2 changes: 1 addition & 1 deletion AltCover.UICommon/CoverageFileTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ module CoverageFileTree =
[ (missing, "NotAllSourcePresent")
(newer, "SomeSourceModified") ]
|> Seq.filter (fun (x, y) -> x |> Seq.isEmpty |> not)
|> Seq.map (fun (x, y) -> Resource.Format(y, [||]))
|> Seq.map (fun (x, y) -> Resource.Format(y, Array.empty<Object>))

let pc = pcCover [ navigator ]

Expand Down
3 changes: 1 addition & 2 deletions AltCover.ValidateGendarmeEmulation/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ module ValidateGendarmeEmulation =
let GratuitousCoverage () =
let l = Left 23
let r = Right true
let mutable x = Object()
x <- null
let mutable x : Object = null
test <@ (23).IsNotNull @>
test <@ x.IsNotNull |> not @>

Expand Down
6 changes: 3 additions & 3 deletions AltCover.Visualizer/Visualizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module private Gui =
String.Join(
Environment.NewLine,
[ AltCover.AssemblyVersionInformation.AssemblyCopyright
Resource.Format("aboutVisualizer.Copyright", [])
Resource.Format("aboutVisualizer.Copyright", List.empty<Object>)
"https://learn.microsoft.com/en-us/visualstudio/designers/the-visual-studio-image-library?view=vs-2022" ]
)

Expand Down Expand Up @@ -282,7 +282,7 @@ module private Gui =
ResponseType.Ok,
Resource.GetResourceString "OpenFile.Cancel",
ResponseType.Cancel,
null
nullObject
)

let data =
Expand Down Expand Up @@ -906,7 +906,7 @@ module private Gui =
handler.classStructureTree.QueryTooltip
|> Event.add (fun (x: QueryTooltipArgs) ->
let tip = x.Tooltip
x.RetVal <- null
x.RetVal <- nullObject
let mutable path: TreePath = null

if handler.classStructureTree.GetPathAtPos(x.X, x.Y, &path) then
Expand Down
2 changes: 1 addition & 1 deletion Build/targets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8002,7 +8002,7 @@ module Targets =
true)
|> List.map fst

Assert.That(coberturaFiles, Is.EquivalentTo [], "coberturaFiles")
Assert.That(coberturaFiles, Is.EquivalentTo List.empty<string>, "coberturaFiles")

let cobertura2Files =
xml
Expand Down
3 changes: 2 additions & 1 deletion OutputBuildProps.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<KeyDir>$(MSBuildThisFileDirectory)Build\</KeyDir>
<InfrastructureKey>$(KeyDir)Infrastructure.snk</InfrastructureKey>
<DocumentationFile>$(OutputPath)\$(TargetFramework)\$(MSBuildProjectName).xml</DocumentationFile>
<OtherFlags>--keyfile:$(InfrastructureKey)</OtherFlags>
<OtherFlags>--keyfile:$(InfrastructureKey) --strict-indentation+</OtherFlags>
<RollForward>Major</RollForward>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand All @@ -23,6 +23,7 @@
<AssemblyOriginatorKeyFile>$(InfrastructureKey)</AssemblyOriginatorKeyFile>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<WarnOn>FS3559;FS3560</WarnOn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
1 change: 1 addition & 0 deletions Samples/Sample25/Sample25.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>net20</TargetFrameworks>
<AssemblyName>Sample25</AssemblyName>
<RootNamespace>Sample25</RootNamespace>
<OtherFlags>--keyfile:$(InfrastructureKey)</OtherFlags>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down

0 comments on commit 6d89ec5

Please sign in to comment.