Skip to content

Commit 7514c29

Browse files
dsymeKevinRansom
authored andcommitted
Fixes #644 --- F# 4.0 ReflectedDefinitions when compiling for F# 3.1 runtime #644
A simple fix for #644. Compilation of ReflectedDefinition attributed code using F# 4.0 compiler when targeting runtime 4.3.1.0 generates an invalid attribute in a binary. commit e384c1b41855ef9c6e848b452f84fde29dbcb74c Author: Don Syme <donsyme@fastmail.fm> Date: Tue Sep 29 23:22:14 2015 +0100 Fix #644
1 parent 1692dda commit 7514c29

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

src/fsharp/fsc.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,14 +996,20 @@ module MainModuleBuilder =
996996
codegenResults.quotationResourceInfo
997997
|> List.map (fun (referencedTypeDefs, reflectedDefinitionBytes) ->
998998
let reflectedDefinitionResourceName = QuotationPickler.SerializedReflectedDefinitionsResourceNameBase+"-"+assemblyName+"-"+string(newUnique())+"-"+string(hash reflectedDefinitionBytes)
999-
let reflectedDefinitionAttr = mkCompilationMappingAttrForQuotationResource tcGlobals (reflectedDefinitionResourceName, referencedTypeDefs)
999+
let reflectedDefinitionAttrs =
1000+
match QuotationTranslator.QuotationGenerationScope.ComputeQuotationFormat tcGlobals with
1001+
| QuotationTranslator.QuotationSerializationFormat.FSharp_40_Plus ->
1002+
[ mkCompilationMappingAttrForQuotationResource tcGlobals (reflectedDefinitionResourceName, referencedTypeDefs) ]
1003+
| QuotationTranslator.QuotationSerializationFormat.FSharp_20_Plus ->
1004+
[ ]
10001005
let reflectedDefinitionResource =
10011006
{ Name=reflectedDefinitionResourceName;
10021007
Location = ILResourceLocation.Local (fun () -> reflectedDefinitionBytes);
10031008
Access= ILResourceAccess.Public;
10041009
CustomAttrs = emptyILCustomAttrs }
1005-
reflectedDefinitionAttr, reflectedDefinitionResource)
1010+
reflectedDefinitionAttrs, reflectedDefinitionResource)
10061011
|> List.unzip
1012+
|> (fun (attrs, resource) -> List.concat attrs, resource)
10071013

10081014
let manifestAttrs =
10091015
mkILCustomAttrs

tests/config.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ echo FSCOREDLLPORTABLEPATH =%FSCOREDLLPORTABLEPATH%
213213
echo FSCOREDLLNETCOREPATH=%FSCOREDLLNETCOREPATH%
214214
echo FSCOREDLLNETCORE78PATH=%FSCOREDLLNETCORE78PATH%
215215
echo FSCOREDLLNETCORE259PATH=%FSCOREDLLNETCORE259PATH%
216+
echo FSCOREDLLVPREVPATH =%FSCOREDLLVPREVPATH%
216217
echo FSDATATPPATH =%FSDATATPPATH%
217218
echo FSDIFF =%FSDIFF%
218219
echo FSI =%FSI%
@@ -266,6 +267,7 @@ set FSCOREDLLNETCOREPATH=%X86_PROGRAMFILES%\Reference Assemblies\Microsoft\FShar
266267
set FSCOREDLLNETCORE78PATH=%X86_PROGRAMFILES%\Reference Assemblies\Microsoft\FSharp\.NETCore\3.78.4.0
267268
set FSCOREDLLNETCORE259PATH=%X86_PROGRAMFILES%\Reference Assemblies\Microsoft\FSharp\.NETCore\3.259.4.0
268269
set FSDATATPPATH=%X86_PROGRAMFILES%\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.0.0\Type Providers
270+
set FSCOREDLLVPREVPATH=%X86_PROGRAMFILES%\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.3.1.0
269271

270272
REM == Check if using open build instead
271273
IF EXIST "%FSCBinPath%\FSharp.Core.dll" set FSCOREDLLPATH=%FSCBinPath%
@@ -282,4 +284,4 @@ set FSCOREDLLPORTABLEPATH=%FSCOREDLLPORTABLEPATH%\FSharp.Core.dll
282284
set FSCOREDLLNETCOREPATH=%FSCOREDLLNETCOREPATH%\FSharp.Core.dll
283285
set FSCOREDLLNETCORE78PATH=%FSCOREDLLNETCORE78PATH%\FSharp.Core.dll
284286
set FSCOREDLLNETCORE259PATH=%FSCOREDLLNETCORE259PATH%\FSharp.Core.dll
285-
set FSDATATPPATH=%FSDATATPPATH%\FSharp.Data.TypeProviders.dll
287+
set FSCOREDLLVPREVPATH=%FSCOREDLLVPREVPATH%\FSharp.Core.dll

tests/fsharp/core/quotes/build.bat

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ rem fsc.exe building
3737
"%PEVERIFY%" test--optimize.exe
3838
@if ERRORLEVEL 1 goto Error
3939

40+
rmdir /s /q test--downtarget
41+
mkdir test--downtarget
42+
43+
dir "%FSCOREDLLVPREVPATH%"
44+
dir "%X86_PROGRAMFILES%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\"
45+
REM Compile with FSharp.Core 4.3.1.0. Add the FSHARP_CORE_31 and Portable defines.
46+
"%FSC%" %fsc_flags% -o:test--downtarget\test--downtarget.exe --noframework -r "%FSCOREDLLVPREVPATH%" -r "%X86_PROGRAMFILES%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" -r System.dll -r System.Runtime.dll -r System.Xml.dll -r System.Data.dll -r System.Web.dll -r System.Core.dll -r System.Numerics.dll -r cslib.dll -g test.fsx --define:FSHARP_CORE_31 --define:Portable
47+
@if ERRORLEVEL 1 goto Error
48+
49+
copy /y "%FSCOREDLLVPREVPATH%" test--downtarget\FSharp.Core.dll
50+
@if ERRORLEVEL 1 goto Error
51+
52+
"%PEVERIFY%" test--downtarget\test--downtarget.exe
53+
@if ERRORLEVEL 1 goto Error
54+
55+
4056
:Ok
4157
echo Built fsharp %~f0 ok.
4258
echo. > build.ok

tests/fsharp/core/quotes/run.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ echo TestD
3535
@if ERRORLEVEL 1 goto Error
3636
if NOT EXIST test.ok goto SetError
3737

38+
if exist test.ok (del /f /q test.ok)
39+
%CLIX% test--downtarget\test--downtarget.exe
40+
if NOT EXIST test.ok goto SetError
41+
3842
:Ok
3943
echo Ran fsharp %~f0 ok.
4044
endlocal

tests/fsharp/core/quotes/test.fsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ module TypedTest = begin
9595
test "check UInt16" ((<@ 1us @> |> (function UInt16 1us -> true | _ -> false)))
9696
test "check UInt32" ((<@ 1u @> |> (function UInt32 1u -> true | _ -> false)))
9797
test "check UInt64" ((<@ 1UL @> |> (function UInt64 1UL -> true | _ -> false)))
98-
test "check Decimal" ((<@ 1M @> |> (function Decimal 1M -> true | _ -> false)))
9998
test "check String" ((<@ "1" @> |> (function String "1" -> true | _ -> false)))
10099

101100
test "check ~SByte" ((<@ "1" @> |> (function SByte _ -> false | _ -> true)))
@@ -106,10 +105,14 @@ module TypedTest = begin
106105
test "check ~UInt16" ((<@ "1" @> |> (function UInt16 _ -> false | _ -> true)))
107106
test "check ~UInt32" ((<@ "1" @> |> (function UInt32 _ -> false | _ -> true)))
108107
test "check ~UInt64" ((<@ "1" @> |> (function UInt64 _ -> false | _ -> true)))
109-
test "check ~Decimal" ((<@ "1" @> |> (function Decimal _ -> false | _ -> true)))
110108
test "check ~String" ((<@ 1 @> |> (function String "1" -> false | _ -> true)))
111109

110+
#if FSHARP_CORE_31
111+
#else
112+
test "check Decimal" ((<@ 1M @> |> (function Decimal 1M -> true | _ -> false)))
113+
test "check ~Decimal" ((<@ "1" @> |> (function Decimal _ -> false | _ -> true)))
112114
test "check ~Decimal neither" ((<@ 1M + 1M @> |> (function Decimal _ -> false | _ -> true)))
115+
#endif
113116

114117
test "check AndAlso" ((<@ true && true @> |> (function AndAlso(Bool(true),Bool(true)) -> true | _ -> false)))
115118
test "check OrElse" ((<@ true || true @> |> (function OrElse(Bool(true),Bool(true)) -> true | _ -> false)))
@@ -528,13 +531,16 @@ module TypedTest = begin
528531
| _ -> false
529532
end
530533

534+
#if FSHARP_CORE_31
535+
#else
531536
test "check accesses to readonly fields in ReflectedDefinitions"
532537
begin
533538
let c1 = Class1("a")
534539
match <@ c1.myReadonlyField @> with
535540
| FieldGet(Some (ValueWithName (_, v, "c1")), field) -> (v.Name = "Class1") && (field.Name = "myReadonlyField")
536541
| _ -> false
537542
end
543+
#endif
538544

539545
end
540546

@@ -1669,10 +1675,13 @@ module QuotationConstructionTests =
16691675
check "vcknwwe099" (Expr.PropertySet(<@@ (new System.Windows.Forms.Form()) @@>, setof <@@ (new System.Windows.Forms.Form()).Text <- "2" @@>, <@@ "3" @@> )) <@@ (new System.Windows.Forms.Form()).Text <- "3" @@>
16701676
#endif
16711677
check "vcknwwe099" (Expr.PropertySet(<@@ (new Foo()) @@>, setof <@@ (new Foo()).[3] <- 1 @@>, <@@ 2 @@> , [ <@@ 3 @@> ] )) <@@ (new Foo()).[3] <- 2 @@>
1678+
#if FSHARP_CORE_31
1679+
#else
16721680
check "vcknwwe0qq1" (Expr.QuoteRaw(<@ "1" @>)) <@@ <@@ "1" @@> @@>
16731681
check "vcknwwe0qq2" (Expr.QuoteRaw(<@@ "1" @@>)) <@@ <@@ "1" @@> @@>
16741682
check "vcknwwe0qq3" (Expr.QuoteTyped(<@ "1" @>)) <@@ <@ "1" @> @@>
16751683
check "vcknwwe0qq4" (Expr.QuoteTyped(<@@ "1" @@>)) <@@ <@ "1" @> @@>
1684+
#endif
16761685
check "vcknwwe0ww" (Expr.Sequential(<@@ () @@>, <@@ 1 @@>)) <@@ (); 1 @@>
16771686
check "vcknwwe0ee" (Expr.TryFinally(<@@ 1 @@>, <@@ () @@>)) <@@ try 1 finally () @@>
16781687
check "vcknwwe0rr" (match Expr.TryWith(<@@ 1 @@>, Var.Global("e1",typeof<exn>), <@@ 1 @@>, Var.Global("e2",typeof<exn>), <@@ 2 @@>) with TryWith(b,v1,ef,v2,eh) -> b = <@@ 1 @@> && eh = <@@ 2 @@> && ef = <@@ 1 @@> && v1 = Var.Global("e1",typeof<exn>) && v2 = Var.Global("e2",typeof<exn>)| _ -> false) true
@@ -2448,6 +2457,8 @@ module QuotationOfResizeArrayIteration =
24482457

24492458

24502459

2460+
#if FSHARP_CORE_31
2461+
#else
24512462
module TestAutoQuoteAtStaticMethodCalls =
24522463
open Microsoft.FSharp.Quotations
24532464

@@ -2752,6 +2763,10 @@ module ExtensionMembersWithSameName =
27522763
| _ -> failwith "unexpected shape"
27532764

27542765
runAll()
2766+
#endif
2767+
2768+
module TestAssemblyAttributes =
2769+
let attributes = System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(false)
27552770

27562771
let aa =
27572772
if not failures.IsEmpty then (printfn "Test Failed, failures = %A" failures; exit 1)

0 commit comments

Comments
 (0)