diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 77c570b14ea..1c7e7bcd2ac 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -6,6 +6,7 @@ module FSharp.Compiler.Interactive.Shell #nowarn "57" #nowarn "55" +#nowarn "9" [] [] @@ -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>.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> + |> 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>.MakeGenericType [| ty |] + Activator.CreateInstance(specialized) :?> IAnyToLayoutCall let callStaticMethod (ty: Type) name args = ty.InvokeMember( diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/crossoptimize.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/crossoptimize.fs new file mode 100644 index 00000000000..2304e1da339 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/crossoptimize.fs @@ -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" + [] + [] + [] + [] + let ``crossoptimize_flag_fs`` option = + Fs """printfn "Hello, World!!!" """ + |> asExe + |> withOptions (if String.IsNullOrWhiteSpace option then [] else [option]) + |> compile + |> shouldSucceed + + [] + [] + [] + [] + let ``crossoptimize_flag_fsx`` option = + Fsx """printfn "Hello, World!!!" """ + |> asExe + |> withOptions (if String.IsNullOrWhiteSpace option then [] else [option]) + |> compile + |> shouldSucceed diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/highentropyva.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/highentropyva.fs new file mode 100644 index 00000000000..bef3f6ff8b9 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/highentropyva.fs @@ -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}") + + [] + [] + [] + [] + [] + [] + [] + [] + [] + 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 + + [] + [] + [] + [] + [] + [] + [] + [] + [] + 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 diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 74d8f6c22d0..a83d57f55a5 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -210,7 +210,9 @@ + + @@ -221,7 +223,7 @@ - + diff --git a/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs b/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs index cfc86ff3618..93f9da6c30a 100644 --- a/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs +++ b/tests/FSharp.Compiler.ComponentTests/Scripting/Interactive.fs @@ -15,6 +15,13 @@ module ``Interactive tests`` = |> withEvalTypeEquals typeof |> withEvalValueEquals 2 + [] + let ``Pretty print void pointer``() = + Fsx "System.IntPtr.Zero.ToPointer()" + |> runFsi + |> shouldSucceed + |> withStdOutContains "val it: voidptr = 0n" + [] let ``EntryPoint attribute in FSI should produce a compiler warning`` () = Fsx "[] let myFunc _ = 0" diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 7045cf0c4bb..a4d59f296f7 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -24,7 +24,6 @@ open System.Reflection.PortableExecutable open FSharp.Test.CompilerAssertHelpers open TestFramework -open System.Reflection.Metadata module rec Compiler = type BaselineFile = @@ -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 diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index d018461571b..c5ec19006e5 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -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 diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/crossoptimize/crossoptimize01.fs b/tests/fsharpqa/Source/CompilerOptions/fsc/crossoptimize/crossoptimize01.fs deleted file mode 100644 index ab57f523a2e..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/crossoptimize/crossoptimize01.fs +++ /dev/null @@ -1,3 +0,0 @@ -// #NoMT #CompilerOptions -module crossoptimize01 -exit 0 diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/crossoptimize/env.lst b/tests/fsharpqa/Source/CompilerOptions/fsc/crossoptimize/env.lst deleted file mode 100644 index 68f2e152665..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/crossoptimize/env.lst +++ /dev/null @@ -1,10 +0,0 @@ -# Sanity check - simply check that the option is valid - - SOURCE=crossoptimize01.fs SCFLAGS="--crossoptimize" - SOURCE=crossoptimize01.fs SCFLAGS="--crossoptimize+" - SOURCE=crossoptimize01.fs SCFLAGS="--crossoptimize-" - - SOURCE=crossoptimize01.fs SCFLAGS="--crossoptimize" FSIMODE=EXEC COMPILE_ONLY=1 - SOURCE=crossoptimize01.fs SCFLAGS="--crossoptimize+" FSIMODE=EXEC COMPILE_ONLY=1 - SOURCE=crossoptimize01.fs SCFLAGS="--crossoptimize-" FSIMODE=EXEC COMPILE_ONLY=1 - diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/highentropyva/CheckHighEntropyASLR.bat b/tests/fsharpqa/Source/CompilerOptions/fsc/highentropyva/CheckHighEntropyASLR.bat deleted file mode 100644 index d5ec99a9a23..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/highentropyva/CheckHighEntropyASLR.bat +++ /dev/null @@ -1,10 +0,0 @@ -@echo off - -REM Use Link.exe from the nuget package - -REM %LINK_EXE% -- Path to link.exe -REM %1 -- assembly to check -REM %2 -- expected value ("yes" or "no") -%LINK_EXE% /dump /headers %1 | find "High Entropy Virtual Addresses" > NUL -IF /I "%2"=="yes" IF ERRORLEVEL 1 EXIT /B 1 -IF /I "%2"=="no" IF NOT ERRORLEVEL 1 EXIT /B 1 \ No newline at end of file diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/highentropyva/dummy.fs b/tests/fsharpqa/Source/CompilerOptions/fsc/highentropyva/dummy.fs deleted file mode 100644 index 3caed3d251c..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/highentropyva/dummy.fs +++ /dev/null @@ -1,2 +0,0 @@ -let x = 1 -x |> ignore \ No newline at end of file diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/highentropyva/env.lst b/tests/fsharpqa/Source/CompilerOptions/fsc/highentropyva/env.lst deleted file mode 100644 index 2d18646ff07..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/highentropyva/env.lst +++ /dev/null @@ -1,15 +0,0 @@ -# Default behavior - SOURCE=dummy.fs SCFLAGS="--platform:x64" COMPILE_ONLY=1 POSTCMD="CheckHighEntropyASLR.bat dummy.exe no" # CheckHighEntropyALSR - x64 - SOURCE=dummy.fs SCFLAGS="--platform:x86" COMPILE_ONLY=1 POSTCMD="CheckHighEntropyASLR.bat dummy.exe no" # CheckHighEntropyALSR - x86 - -# --highentropyva+ and --highentropyva -# SOURCE=dummy.fs SCFLAGS="--platform:x64 --highentropyva+" COMPILE_ONLY=1 POSTCMD="CheckHighEntropyASLR.bat dummy.exe yes" # CheckHighEntropyALSR - x64 highentropyva+ -# SOURCE=dummy.fs SCFLAGS="--platform:x86 --highentropyva+" COMPILE_ONLY=1 POSTCMD="CheckHighEntropyASLR.bat dummy.exe yes" # CheckHighEntropyALSR - x86 highentropyva+ -# SOURCE=dummy.fs SCFLAGS="--platform:x64 --highentropyva" COMPILE_ONLY=1 POSTCMD="CheckHighEntropyASLR.bat dummy.exe yes" # CheckHighEntropyALSR - x64 highentropyva -# SOURCE=dummy.fs SCFLAGS="--platform:x86 --highentropyva" COMPILE_ONLY=1 POSTCMD="CheckHighEntropyASLR.bat dummy.exe yes" # CheckHighEntropyALSR - x86 highentropyva -# SOURCE=dummy.fs SCFLAGS="--platform:Itanium --highentropyva" COMPILE_ONLY=1 POSTCMD="CheckHighEntropyASLR.bat dummy.exe yes" # CheckHighEntropyALSR - IA64 highentropyva - -# --highentropyva- - SOURCE=dummy.fs SCFLAGS="--platform:x64 --highentropyva-" COMPILE_ONLY=1 POSTCMD="CheckHighEntropyASLR.bat dummy.exe no" # CheckHighEntropyALSR - x64 highentropyva- - SOURCE=dummy.fs SCFLAGS="--platform:x86 --highentropyva-" COMPILE_ONLY=1 POSTCMD="CheckHighEntropyASLR.bat dummy.exe no" # CheckHighEntropyALSR - x86 highentropyva- - SOURCE=dummy.fs SCFLAGS="--platform:Itanium --highentropyva-" COMPILE_ONLY=1 POSTCMD="CheckHighEntropyASLR.bat dummy.exe no" # CheckHighEntropyALSR - IA64 highentropyva- diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/badlangversion-culture.fsx b/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/badlangversion-culture.fsx deleted file mode 100644 index d1e6d620d70..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/badlangversion-culture.fsx +++ /dev/null @@ -1,5 +0,0 @@ -// #NoMT #CompilerOptions #RequiresENU -// Unrecognized value '4,7' for --langversion use --langversion:? for complete list -// -#light -exit 0 diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/badlangversion-decimal.fsx b/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/badlangversion-decimal.fsx deleted file mode 100644 index d92c376bc39..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/badlangversion-decimal.fsx +++ /dev/null @@ -1,5 +0,0 @@ -// #NoMT #CompilerOptions #RequiresENU -// Unrecognized value '4.70000000000' for --langversion use --langversion:? for complete list -// -#light -exit 0 diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/badlangversion.fsx b/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/badlangversion.fsx deleted file mode 100644 index b41237cd0b3..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/badlangversion.fsx +++ /dev/null @@ -1,5 +0,0 @@ -// #NoMT #CompilerOptions #RequiresENU -// Unrecognized value '4.5' for --langversion use --langversion:? for complete list -// -#light -exit 0 diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/dummy.fsx b/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/dummy.fsx deleted file mode 100644 index c5ecbb36434..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/dummy.fsx +++ /dev/null @@ -1,3 +0,0 @@ -// #NoMT #CompilerOptions #RequiresENU -#light -exit 0 diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/env.lst b/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/env.lst deleted file mode 100644 index 6ecc5030f21..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/env.lst +++ /dev/null @@ -1,6 +0,0 @@ -# ReqENU means that the test is non-localized - -ReqENU SOURCE=dummy.fsx COMPILE_ONLY=1 PRECMD="\$FSC_PIPE >langversionhelp.txt --langversion:? 2>&1" POSTCMD="\$FSI_PIPE --nologo --quiet --exec ..\\..\\..\\comparer.fsx langversionhelp.txt langversionhelp.437.1033.bsl" # --langversion:? -ReqENU SOURCE=badlangversion.fsx SCFLAGS=" --langversion:4.5" # --langversion:4.5 -ReqENU SOURCE=badlangversion-culture.fsx SCFLAGS=" --langversion:4,7" # --langversion:4,7 -ReqENU SOURCE=badlangversion-decimal.fsx SCFLAGS=" --langversion:4.70000000000" # --langversion:4.70000000000 diff --git a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/langversionhelp.437.1033.bsl b/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/langversionhelp.437.1033.bsl deleted file mode 100644 index 2e3e65520ac..00000000000 --- a/tests/fsharpqa/Source/CompilerOptions/fsc/langversion/langversionhelp.437.1033.bsl +++ /dev/null @@ -1,10 +0,0 @@ -Supported language versions: -preview -default -latest -latestmajor -4.6 -4.7 -5.0 -6.0 -7.0 (Default) \ No newline at end of file