Skip to content

Commit

Permalink
Merge pull request #15240 from dotnet/merges/main-to-release/dev17.7
Browse files Browse the repository at this point in the history
Merge main to release/dev17.7
  • Loading branch information
KevinRansom authored May 21, 2023
2 parents bc6ce04 + 363f64c commit 2341436
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 83 deletions.
23 changes: 20 additions & 3 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module FSharp.Compiler.Interactive.Shell
#nowarn "57"

#nowarn "55"
#nowarn "9"

[<assembly: System.Runtime.InteropServices.ComVisible(false)>]
[<assembly: System.CLSCompliant(true)>]
Expand Down Expand Up @@ -102,9 +103,25 @@ module internal Utilities =
member _.FsiAnyToLayout(options, o: obj, ty: Type) =
Display.fsi_any_to_layout options ((Unchecked.unbox o: 'T), ty)

let getAnyToLayoutCall ty =
let specialized = typedefof<AnyToLayoutSpecialization<_>>.MakeGenericType [| ty |]
Activator.CreateInstance(specialized) :?> IAnyToLayoutCall
let getAnyToLayoutCall (ty: Type) =
if ty.IsPointer then
let pointerToNativeInt (o: obj) : nativeint =
System.Reflection.Pointer.Unbox o
|> NativeInterop.NativePtr.ofVoidPtr<nativeptr<byte>>
|> NativeInterop.NativePtr.toNativeInt

{ new IAnyToLayoutCall with
member _.AnyToLayout(options, o: obj, ty: Type) =
let n = pointerToNativeInt o
Display.any_to_layout options (n, n.GetType())

member _.FsiAnyToLayout(options, o: obj, ty: Type) =
let n = pointerToNativeInt o
Display.any_to_layout options (n, n.GetType())
}
else
let specialized = typedefof<AnyToLayoutSpecialization<_>>.MakeGenericType [| ty |]
Activator.CreateInstance(specialized) :?> IAnyToLayoutCall

let callStaticMethod (ty: Type) name args =
ty.InvokeMember(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.ComponentTests.CompilerOptions

open System

open Xunit
open FSharp.Test.Compiler


//# Sanity check - simply check that the option is valid
module crossoptimize =

// SOURCE=crossoptimize.fs SCFLAGS="--crossoptimize"
[<InlineData("--crossoptimize")>]
[<InlineData("--crossoptimize+")>]
[<InlineData("--crossoptimize-")>]
[<Theory>]
let ``crossoptimize_flag_fs`` option =
Fs """printfn "Hello, World!!!" """
|> asExe
|> withOptions (if String.IsNullOrWhiteSpace option then [] else [option])
|> compile
|> shouldSucceed

[<InlineData("--crossoptimize")>]
[<InlineData("--crossoptimize+")>]
[<InlineData("--crossoptimize-")>]
[<Theory>]
let ``crossoptimize_flag_fsx`` option =
Fsx """printfn "Hello, World!!!" """
|> asExe
|> withOptions (if String.IsNullOrWhiteSpace option then [] else [option])
|> compile
|> shouldSucceed
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.ComponentTests.CompilerOptions

open System
open System.Reflection.PortableExecutable

open Xunit
open FSharp.Test.Compiler


module highentropyva =

let shouldHaveFlag (expected: DllCharacteristics) (result: DllCharacteristics) =
if not (result.HasFlag expected) then
raise (new Exception $"CoffHeader.Characteristics does not contain expected flag:\nFound: {result}\n Expected: {expected}")

let shouldNotHaveFlag (notexpected: DllCharacteristics) (result: DllCharacteristics) =
if result.HasFlag notexpected then
raise (new Exception $"DllCharacteristics contains the unexpected flag:\nFound: {result}\nNot expected: {notexpected}")

[<InlineData(ExecutionPlatform.X64, null)>]
[<InlineData(ExecutionPlatform.X86, null)>]
[<InlineData(ExecutionPlatform.Arm64, null)>]
[<InlineData(ExecutionPlatform.Arm, null)>]
[<InlineData(ExecutionPlatform.X64, "--highentropyva-")>]
[<InlineData(ExecutionPlatform.X86, "--highentropyva-")>]
[<InlineData(ExecutionPlatform.Arm64, "--highentropyva-")>]
[<InlineData(ExecutionPlatform.Arm, "--highentropyva-")>]
[<Theory>]
let shouldNotGenerateHighEntropyVirtualAddressSpace platform option =
Fs """printfn "Hello, World!!!" """
|> asExe
|> withPlatform platform
|> withOptions (if String.IsNullOrWhiteSpace option then [] else [option])
|> compile
|> shouldSucceed
|> withPeReader(fun rdr -> rdr.PEHeaders.PEHeader.DllCharacteristics)
|> shouldNotHaveFlag DllCharacteristics.HighEntropyVirtualAddressSpace

[<InlineData(ExecutionPlatform.X64, "--highentropyva")>]
[<InlineData(ExecutionPlatform.X64, "--highentropyva+")>]
[<InlineData(ExecutionPlatform.X86, "--highentropyva")>]
[<InlineData(ExecutionPlatform.X86, "--highentropyva+")>]
[<InlineData(ExecutionPlatform.Arm64, "--highentropyva+")>]
[<InlineData(ExecutionPlatform.Arm64, "--highentropyva")>]
[<InlineData(ExecutionPlatform.Arm, "--highentropyva")>]
[<InlineData(ExecutionPlatform.Arm, "--highentropyva+")>]
[<Theory>]
let shouldGenerateHighEntropyVirtualAddressSpace platform option =
Fs """printfn "Hello, World!!!" """
|> asExe
|> withPlatform platform
|> withOptions (if String.IsNullOrWhiteSpace option then [] else [option])
|> compile
|> shouldSucceed
|> withPeReader(fun rdr -> rdr.PEHeaders.PEHeader.DllCharacteristics)
|> shouldHaveFlag DllCharacteristics.HighEntropyVirtualAddressSpace
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@
<Compile Include="CompilerOptions\fsc\checked\checked.fs" />
<Compile Include="CompilerOptions\fsc\cliversion.fs" />
<Compile Include="CompilerOptions\fsc\codepage\codepage.fs" />
<Compile Include="CompilerOptions\fsc\crossoptimize.fs" />
<Compile Include="CompilerOptions\fsc\debug.fs" />
<Compile Include="CompilerOptions\fsc\highentropyva.fs" />
<Compile Include="CompilerOptions\fsc\langversion.fs" />
<Compile Include="CompilerOptions\fsc\misc\misc.fs" />
<Compile Include="CompilerOptions\fsc\noframework\noframework.fs" />
Expand All @@ -221,7 +223,7 @@
<Compile Include="CompilerOptions\fsc\reference.fs" />
<Compile Include="CompilerOptions\fsc\reflectionfree.fs" />
<Compile Include="CompilerOptions\fsc\refonlyrefout.fs" />
<Compile Include="CompilerOptions\fsc\sourceFiles.fs" />
<Compile Include="CompilerOptions\fsc\sourceFiles.fs" />
<Compile Include="CompilerService\RangeModule.fs" />
<Compile Include="Debugger\PortablePdbs.fs" />
<Compile Include="Diagnostics\async.fs" />
Expand Down
7 changes: 7 additions & 0 deletions tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ module ``Interactive tests`` =
|> withEvalTypeEquals typeof<int>
|> withEvalValueEquals 2

[<Fact>]
let ``Pretty print void pointer``() =
Fsx "System.IntPtr.Zero.ToPointer()"
|> runFsi
|> shouldSucceed
|> withStdOutContains "val it: voidptr = 0n"

[<Fact>]
let ``EntryPoint attribute in FSI should produce a compiler warning`` () =
Fsx "[<EntryPoint>] let myFunc _ = 0"
Expand Down
8 changes: 5 additions & 3 deletions tests/FSharp.Test.Utilities/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ open System.Reflection.PortableExecutable

open FSharp.Test.CompilerAssertHelpers
open TestFramework
open System.Reflection.Metadata

module rec Compiler =
type BaselineFile =
Expand Down Expand Up @@ -962,15 +961,18 @@ module rec Compiler =
opts.Add($"-I:\"{(outputDirectory.Value.FullName)}\"")
| _ -> ()
opts.ToArray()
let errors = CompilerAssert.RunScriptWithOptionsAndReturnResult options source
let errors, stdOut = CompilerAssert.RunScriptWithOptionsAndReturnResult options source

let executionOutputwithStdOut: RunOutput option =
ExecutionOutput { StdOut = stdOut; ExitCode = 0; StdErr = "" }
|> Some
let result =
{ OutputPath = None
Dependencies = []
Adjust = 0
Diagnostics = []
PerFileErrors= []
Output = None
Output = executionOutputwithStdOut
Compilation = cUnit }

if errors.Count > 0 then
Expand Down
4 changes: 2 additions & 2 deletions tests/FSharp.Test.Utilities/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -940,10 +940,10 @@ Updated automatically, please check diffs in your pull request, changes must be
| Choice2Of2 ex -> errorMessages.Add(ex.Message)
| _ -> ()

errorMessages
errorMessages, outStream.ToString()

static member RunScriptWithOptions options (source: string) (expectedErrorMessages: string list) =
let errorMessages = CompilerAssert.RunScriptWithOptionsAndReturnResult options source
let errorMessages, _ = CompilerAssert.RunScriptWithOptionsAndReturnResult options source
if expectedErrorMessages.Length <> errorMessages.Count then
Assert.Fail(sprintf "Expected error messages: %A \n\n Actual error messages: %A" expectedErrorMessages errorMessages)
else
Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions tests/fsharpqa/Source/CompilerOptions/fsc/crossoptimize/env.lst

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions tests/fsharpqa/Source/CompilerOptions/fsc/highentropyva/env.lst

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions tests/fsharpqa/Source/CompilerOptions/fsc/langversion/env.lst

This file was deleted.

This file was deleted.

0 comments on commit 2341436

Please sign in to comment.