Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26073c3

Browse files
v2mlatkin
authored andcommitted
drop erased type arguments when computing indirect calls to avoid adding extra type functions
1 parent7b84cce commit26073c3

File tree

4 files changed

+140
-1
lines changed

4 files changed

+140
-1
lines changed

‎src/fsharp/ilxgen.fs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2774,9 +2774,12 @@ and GenArgsAndIndirectCall cenv cgbuf eenv (functy,tyargs,args,m) sequel =
27742774

27752775
/// Generate an indirect call, converting to an ILX callfunc instruction
27762776
andGenIndirectCall cenv cgbuf eenv(functy,tyargs,args,m)sequel=
2777-
2777+
27782778
// Fold in the new types into the environment as we generate the formal types.
27792779
letilxClosureApps=
2780+
// keep only non-erased type arguments when computing indirect call
2781+
lettyargs= DropErasedTyargs tyargs
2782+
27802783
lettypars,formalFuncTyp= tryDestForallTy cenv.g functy
27812784

27822785
letfeenv= eenv.tyenv.Add typars
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@if"%_echo%"==""echooff
2+
3+
setlocal
4+
REM Configure the sample, i.e. where to find the F# compiler and C# compiler.
5+
ifEXIST build.okDEL /f /q build.ok
6+
7+
call%~d0%~p0..\..\..\config.bat
8+
9+
"%FSC%"%fsc_flags% --optimize- -o:test.exe -g test.fs
10+
@if ERRORLEVEL1goto Error
11+
12+
"%PEVERIFY%" test.exe
13+
@if ERRORLEVEL1goto Error
14+
15+
:Ok
16+
echo Built fsharp%~f0 ok.
17+
echo.> build.ok
18+
endlocal
19+
exit /b0
20+
21+
:Error
22+
endlocal
23+
exit /b%ERRORLEVEL%
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
call%~d0%~p0..\..\..\config.bat
2+
3+
ifexist test.ok (del /f /q test.ok)
4+
5+
%CLIX% .\test.exe
6+
ifERRORLEVEL1goto Error
7+
8+
:Ok
9+
echo Ran fsharp%~f0 ok.
10+
endlocal
11+
exit /b0
12+
13+
:Error
14+
endlocal
15+
exit /b%ERRORLEVEL%
16+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
typeT()=
2+
memberthis.H<[<Measure>]'u>(x:int<'u>)= x
3+
4+
memberthis.F<[<Measure>]'u>(x:int<'u>)=
5+
letg x=
6+
this.H x
7+
8+
g x
9+
10+
[<Measure>]typeM
11+
12+
typeTheType={ A:int; B:int; D:int; G:seq<int>}with
13+
static memberCreate a b _ d _ _ g={ A= a; B= b; D= d; G= g}
14+
15+
letCreateBadImageFormatException()=
16+
letcreate a b c d(e:int<_>)(f:int)g= TheType.Create a b(int c) d e f g
17+
seq{yield create000000[0]}
18+
19+
moduleTestLibrary=
20+
21+
[<Measure>]
22+
typeunit=
23+
//converts an integer into a unit of measureof type int<seconds>
24+
static memberconvertLP x= LanguagePrimitives.Int32WithMeasure x
25+
static memberconvert x= x*1<unit>
26+
static memberconvertFromInt(x:int)= x*1<unit>//not generic
27+
28+
29+
//add a unit of measure to a number and convert it back again
30+
lettest1 num=
31+
letoutput= unit.convertLP(num)
32+
int output
33+
lettest2 num=
34+
letoutput= unit.convert(num)
35+
int output
36+
37+
38+
//convert the number in a sub function
39+
lettest3 num=
40+
letconvert i=
41+
unit.convertLP(i)
42+
letoutput= convert num//BadImageFormatException is thrown here
43+
int output//type of output inferred as int ?!
44+
45+
lettest4 num=
46+
letconvert(i:int)=//type of i is specified
47+
unit.convertLP(i)
48+
letoutput= convert num//BadImageFormatException is thrown here
49+
int output//type of output inferred as int ?!
50+
51+
lettest5 num=//type of num is inferred as int<u'> but no compile errors are reported
52+
letconvert i=
53+
unit.convert(i)
54+
letoutput= convert num//BadImageFormatException is thrown here
55+
int output
56+
57+
lettest6(num:int)=
58+
letconvert i=//inference looks incorrect
59+
unit.convert(i)
60+
letoutput= convert num//BadImageFormatException is thrown here
61+
int output
62+
63+
64+
//two work arounds to the problem
65+
lettest7 num=
66+
letconvert(i:int)=//with the type specified here, this doesn't crash
67+
unit.convert(i)
68+
letoutput= convert num
69+
int output
70+
71+
lettest8 num=
72+
letconvert i=
73+
unit.convertFromInt(i)//with the type specified in the converter no exception
74+
letoutput= convert num
75+
int output
76+
77+
78+
printfn"test 1:%i"(test11000)
79+
printfn"test 2:%i"(test21000)
80+
printfn"test 3:%i"(test31000)
81+
printfn"test 4:%i"(test41000)
82+
printfn"test 5:%i"(test51000)
83+
printfn"test 6:%i"(test61000)
84+
printfn"test 7:%i"(test71000)
85+
printfn"test 8:%i"(test81000)
86+
87+
88+
[<EntryPoint>]
89+
letmain argv=
90+
// test1
91+
let_= T().F(LanguagePrimitives.Int32WithMeasure<M>0)
92+
// test2
93+
for_in CreateBadImageFormatException()do()
94+
95+
System.IO.File.WriteAllText("test.ok","ok");
96+
97+
0

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp