From 9ee310f757c3673888a0cf24ffbe26eb9be10d2f Mon Sep 17 00:00:00 2001 From: Will Smith Date: Mon, 20 Jan 2020 04:04:56 -0800 Subject: [PATCH 1/3] Added inref interop test --- tests/fsharp/Compiler/CompilerAssert.fs | 23 +++++++++-- tests/fsharp/Compiler/Language/ByrefTests.fs | 41 ++++++++++++++++++++ tests/fsharp/Compiler/Utilities.fs | 4 +- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/tests/fsharp/Compiler/CompilerAssert.fs b/tests/fsharp/Compiler/CompilerAssert.fs index 9f0bc09553b..0cdcf3c76b4 100644 --- a/tests/fsharp/Compiler/CompilerAssert.fs +++ b/tests/fsharp/Compiler/CompilerAssert.fs @@ -8,6 +8,7 @@ open System.Diagnostics open System.IO open System.Text open System.Diagnostics +open System.Collections.Generic open System.Reflection open FSharp.Compiler.Text open FSharp.Compiler.SourceCodeServices @@ -17,6 +18,9 @@ open System.Runtime.Loader #endif open NUnit.Framework open System.Reflection.Emit +open Microsoft.CodeAnalysis +open Microsoft.CodeAnalysis.CSharp +open FSharp.Compiler.UnitTests.Utilities [] type ILVerifier (dllFilePath: string) = @@ -52,12 +56,18 @@ type CompileOutput = | Library | Exe -type CompilationReference = private CompilationReference of Compilation * staticLink: bool with +type CompilationReference = + private + | CompilationReference of Compilation * staticLink: bool + | TestCompilationReference of TestCompilation static member CreateFSharp(cmpl: Compilation, ?staticLink) = let staticLink = defaultArg staticLink false CompilationReference(cmpl, staticLink) + static member Create(cmpl: TestCompilation) = + TestCompilationReference cmpl + and Compilation = private Compilation of string * SourceKind * CompileOutput * options: string[] * CompilationReference list with static member Create(source, sourceKind, output, ?options, ?cmplRefs) = @@ -82,7 +92,7 @@ type CompilerAssert private () = Exe - netcoreapp3.0 + netcoreapp3.1 true true @@ -257,7 +267,14 @@ let main argv = 0""" |> List.map (fun cmpl -> match cmpl with | CompilationReference (cmpl, staticLink) -> - compileCompilationAux disposals ignoreWarnings cmpl, staticLink) + compileCompilationAux disposals ignoreWarnings cmpl, staticLink + | TestCompilationReference (cmpl) -> + let tmp = Path.GetTempFileName() + disposals.Add({ new IDisposable with + member _.Dispose() = + try File.Delete tmp with | _ -> () }) + cmpl.EmitAsFile tmp + (([||], tmp), []), false) let compilationRefs = compiledRefs diff --git a/tests/fsharp/Compiler/Language/ByrefTests.fs b/tests/fsharp/Compiler/Language/ByrefTests.fs index 2797125d791..d09f9f4cf24 100644 --- a/tests/fsharp/Compiler/Language/ByrefTests.fs +++ b/tests/fsharp/Compiler/Language/ByrefTests.fs @@ -4,6 +4,7 @@ namespace FSharp.Compiler.UnitTests open NUnit.Framework open FSharp.Compiler.SourceCodeServices +open FSharp.Compiler.UnitTests.Utilities [] module ByrefTests = @@ -195,4 +196,44 @@ let test1 () = "The value has been copied to ensure the original is not mutated by this operation or because the copy is implicit when returning a struct from a member and another member is then accessed" ) |] +#endif + +#if NETCOREAPP + [] + let ``Consume CSharp interface with a method that has a readonly byref`` () = + let cs = + """ +using System; +using System.Buffers; + +namespace Example +{ + public interface IMessageReader + { + bool TryParseMessage(in byte input); + } +} + """ + let fs = + """ +module Module1 + +open Example + +type MyClass() = + + interface IMessageReader with + member this.TryParseMessage(input: inref): bool = + failwith "Not Implemented" + """ + + let csCmpl = + CompilationUtil.CreateCSharpCompilation(cs, CSharpLanguageVersion.CSharp8, TargetFramework.NetCoreApp30) + |> CompilationReference.Create + + let fsCmpl = + Compilation.Create(fs, Fsx, Library, cmplRefs = [csCmpl]) + + CompilerAssert.Compile fsCmpl + #endif \ No newline at end of file diff --git a/tests/fsharp/Compiler/Utilities.fs b/tests/fsharp/Compiler/Utilities.fs index 29de21ad3e3..b55707fdb4e 100644 --- a/tests/fsharp/Compiler/Utilities.fs +++ b/tests/fsharp/Compiler/Utilities.fs @@ -120,7 +120,7 @@ type CompilationUtil private () = [ CSharpSyntaxTree.ParseText (source, CSharpParseOptions lv) ], references.As().AddRange additionalReferences, CSharpCompilationOptions (OutputKind.DynamicallyLinkedLibrary)) - Some (TestCompilation.CSharp (c, flags)) + TestCompilation.CSharp (c, flags) static member CreateILCompilation (source: string) = let compute = @@ -139,4 +139,4 @@ type CompilationUtil private () = try File.Delete ilFilePath with | _ -> () try File.Delete tmp with | _ -> () try File.Delete dllFilePath with | _ -> () - Some (TestCompilation.IL (source, compute)) \ No newline at end of file + TestCompilation.IL (source, compute) \ No newline at end of file From e8598b761d197a4cad7aa0413d8d065201621317 Mon Sep 17 00:00:00 2001 From: Will Smith Date: Mon, 20 Jan 2020 04:38:16 -0800 Subject: [PATCH 2/3] Fixed inref interop when creating a slot sig --- src/fsharp/infos.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/infos.fs b/src/fsharp/infos.fs index 1db4e36b356..63db80bae85 100755 --- a/src/fsharp/infos.fs +++ b/src/fsharp/infos.fs @@ -1536,7 +1536,7 @@ type MethInfo = let formalRetTy = ImportReturnTypeFromMetadata amap m ilminfo.RawMetadata.Return.Type ilminfo.RawMetadata.Return.CustomAttrs ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys let formalParams = [ [ for p in ilminfo.RawMetadata.Parameters do - let paramType = ImportILTypeFromMetadata amap m ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys p.Type + let paramType = ImportILTypeFromMetadataWithAttributes amap m ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys p.Type p.CustomAttrs yield TSlotParam(p.Name, paramType, p.IsIn, p.IsOut, p.IsOptional, []) ] ] formalRetTy, formalParams #if !NO_EXTENSIONTYPING From e03f3fe24c2a94282251a0d098bb87fb1dfdad45 Mon Sep 17 00:00:00 2001 From: Will Smith Date: Mon, 20 Jan 2020 06:24:11 -0800 Subject: [PATCH 3/3] 3.1 to 3.0 --- tests/fsharp/Compiler/CompilerAssert.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fsharp/Compiler/CompilerAssert.fs b/tests/fsharp/Compiler/CompilerAssert.fs index 0cdcf3c76b4..ef0e591a0c1 100644 --- a/tests/fsharp/Compiler/CompilerAssert.fs +++ b/tests/fsharp/Compiler/CompilerAssert.fs @@ -92,7 +92,7 @@ type CompilerAssert private () = Exe - netcoreapp3.1 + netcoreapp3.0 true true