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

Commit1d2c78e

Browse files
authored
Merge pull requestdotnet#4486 from AviAvni/literal-value-bug
Fix Literal values bug
2 parents2d2104b +cf5afdc commit1d2c78e

File tree

11 files changed

+228
-14
lines changed

11 files changed

+228
-14
lines changed

‎src/absil/il.fs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,9 +1558,8 @@ type ILFieldDef =
15581558
memberx.WithStatic(condition)={ xwith Attributes= x.Attributes|> conditionalAdd condition FieldAttributes.Static}
15591559
memberx.WithSpecialName(condition)={ xwith Attributes= x.Attributes|> conditionalAdd condition(FieldAttributes.SpecialName||| FieldAttributes.RTSpecialName)}
15601560
memberx.WithNotSerialized(condition)={ xwith Attributes= x.Attributes|> conditionalAdd condition FieldAttributes.NotSerialized}
1561-
memberx.WithLiteral(condition)={ xwith Attributes= x.Attributes|> conditionalAdd condition FieldAttributes.Literal}
1562-
memberx.WithHasDefault(condition)={ xwith Attributes= x.Attributes|> conditionalAdd condition FieldAttributes.HasDefault}
1563-
memberx.WithHasFieldMarshal(condition)={ xwith Attributes= x.Attributes|> conditionalAdd condition FieldAttributes.HasFieldMarshal}
1561+
memberx.WithLiteralDefaultValue(literal)={ xwith LiteralValue= literal; Attributes= x.Attributes|> conditionalAdd literal.IsSome(FieldAttributes.Literal||| FieldAttributes.HasDefault)}
1562+
memberx.WithFieldMarshal(marshal)={ xwith Marshal= marshal; Attributes= x.Attributes|> conditionalAdd marshal.IsSome FieldAttributes.HasFieldMarshal}
15641563

15651564

15661565
// Index table by name. Keep a canonical list to make sure field order is not disturbed for binary manipulation.

‎src/absil/il.fsi‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,9 +1138,8 @@ type ILFieldDef =
11381138
memberWithStatic:bool->ILFieldDef
11391139
memberWithSpecialName:bool->ILFieldDef
11401140
memberWithNotSerialized:bool->ILFieldDef
1141-
memberWithLiteral:bool->ILFieldDef
1142-
memberWithHasDefault:bool->ILFieldDef
1143-
memberWithHasFieldMarshal:bool->ILFieldDef
1141+
memberWithLiteralDefaultValue:ILFieldInit option->ILFieldDef
1142+
memberWithFieldMarshal:ILNativeType option->ILFieldDef
11441143

11451144
/// Tables of fields. Logically equivalent to a list of fields but
11461145
/// the table is kept in a form optimized for looking up fields by

‎src/fsharp/IlxGen.fs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4742,7 +4742,7 @@ and GenBindingAfterSequencePoint cenv cgbuf eenv sp (TBind(vspec,rhsExpr,_)) sta
47424742
letilFieldDef= mkILStaticField(fspec.Name, fty, None, None, access)
47434743
letilFieldDef=
47444744
match vref.LiteralValuewith
4745-
| Some konst->{ilFieldDef.WithHasDefault(true)with LiteralValue=Some(GenFieldInit m konst)}
4745+
| Some konst-> ilFieldDef.WithLiteralDefaultValue(Some(GenFieldInit m konst))
47464746
| None-> ilFieldDef
47474747

47484748
letilFieldDef=
@@ -6347,19 +6347,18 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon:Tycon) =
63476347
{ Name= ilFieldName
63486348
Type= ilPropType
63496349
Attributes=enum0
6350-
Data= None
6351-
LiteralValue=literalValue
6350+
Data= None
6351+
LiteralValue=None
63526352
Offset= ilFieldOffset
6353-
Marshal=ilFieldMarshal
6353+
Marshal=None
63546354
CustomAttrs= mkILCustomAttrs(GenAttrs cenv eenv fattribs@ extraAttribs)}
63556355
letfdef=
63566356
fdef.WithAccess(access)
63576357
.WithStatic(isStatic)
63586358
.WithSpecialName(ilFieldName="value__"&& tycon.IsEnumTycon)
63596359
.WithNotSerialized(ilNotSerialized)
6360-
.WithLiteral(fspec.LiteralValue.IsSome)
6361-
.WithHasDefault(literalValue.IsSome)
6362-
.WithHasFieldMarshal(ilFieldMarshal.IsSome)
6360+
.WithLiteralDefaultValue(literalValue)
6361+
.WithFieldMarshal(ilFieldMarshal)
63636362
yield fdef
63646363

63656364
if requiresExtraFieldthen
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[<Literal>]
2+
letx=7
3+
4+
[<EntryPoint>]
5+
letmain argv=
6+
0
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
// Microsoft (R) .NET Framework IL Disassembler. Version 4.5.22220.0
3+
4+
5+
6+
// Metadata version: v4.0.30319
7+
.assembly extern mscorlib
8+
{
9+
.publickeytoken= (B7 7A 5C561934 E089 )// .z\V.4..
10+
.ver4:0:0:0
11+
}
12+
.assembly extern FSharp.Core
13+
{
14+
.publickeytoken= (B0 3F 5F 7F11 D5 0A 3A )// .?_....:
15+
.ver4:4:3:0
16+
}
17+
.assembly test
18+
{
19+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32,
20+
int32,
21+
int32)= (01000200000000000000000000000000 )
22+
23+
// --- The following custom attribute is added automatically, do not uncomment -------
24+
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 01 01 00 00 00 00 )
25+
26+
.hash algorithm 0x00008004
27+
.ver0:0:0:0
28+
}
29+
.mresource public FSharpSignatureData.test
30+
{
31+
// Offset: 0x00000000 Length: 0x00000274
32+
// WARNING: managed resource file FSharpSignatureData.test created
33+
}
34+
.mresource public FSharpOptimizationData.test
35+
{
36+
// Offset: 0x00000278 Length: 0x0000006F
37+
// WARNING: managed resource file FSharpOptimizationData.test created
38+
}
39+
.module test.exe
40+
// MVID: {5AA663EB-D9C1-2E4E-A745-0383EB63A65A}
41+
.imagebase 0x00400000
42+
.file alignment 0x00000200
43+
.stackreserve 0x00100000
44+
.subsystem 0x0003// WINDOWS_CUI
45+
.corflags 0x00000001// ILONLY
46+
// Image base: 0x02BF0000
47+
48+
49+
// =============== CLASS MEMBERS DECLARATION ===================
50+
51+
.class public abstract auto ansi sealed Test
52+
extends [mscorlib]System.Object
53+
{
54+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags)= (0100070000000000 )
55+
.field public static literal int32 x= int32(0x00000007)
56+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.LiteralAttribute::.ctor()= (01000000 )
57+
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState)= (0100000000000000 )
58+
.method public static int32 main(string[] argv) cil managed
59+
{
60+
.entrypoint
61+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.EntryPointAttribute::.ctor()= (01000000 )
62+
// Code size 2 (0x2)
63+
.maxstack8
64+
IL_0000: ldc.i4.0
65+
IL_0001: ret
66+
}// end of method Test::main
67+
68+
}// end of class Test
69+
70+
.class private abstract auto ansi sealed '<StartupCode$test>'.$Test
71+
extends [mscorlib]System.Object
72+
{
73+
}// end of class '<StartupCode$test>'.$Test
74+
75+
76+
// =============================================================
77+
78+
// *********** DISASSEMBLY COMPLETE ***********************
79+
// WARNING: Created Win32 resource file test.res
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
openSystem
2+
openSystem.Linq
3+
openSystem.Reflection
4+
5+
typethisAssembly(_dummy:System.Object)=classend
6+
7+
modulepublicMyLiteralFields=
8+
[<Literal>]
9+
letpublicliteralFieldX=7
10+
11+
printfn"MyFields.literalFieldX =%d" MyLiteralFields.literalFieldX
12+
13+
// Use dotnet reflection to verify that x is a Literal Constant
14+
// This works on full desktop / coreclr and also fsi
15+
letasm= thisAssembly(null).GetType().GetTypeInfo().Assembly
16+
lettyp= asm.GetTypes()|> Array.filter(fun t-> t.FullName.EndsWith("+MyLiteralFields"))|> Array.tryLast
17+
letresult=
18+
match typwith
19+
| Some typ->
20+
// Gets literalFieldX checks to see if it is marked "Literal"
21+
letfieldInfo= typ.GetTypeInfo().DeclaredFields|> Seq.tryFind(fun fi-> fi.Name.StartsWith("literalFieldX"))
22+
match fieldInfowith
23+
| Some fieldInfo->
24+
if fieldInfo.IsLiteral=truethen0else2
25+
| None->
26+
printfn"Failed to find fieldliteralFieldX ="
27+
3
28+
| None->
29+
printfn"Failed to find module public MyLiteralFields ="
30+
1
31+
32+
if result=0then
33+
System.IO.File.WriteAllText("test.ok","ok");
34+
printfn"Succeeded"
35+
else
36+
printfn"Failed:%d" result
37+
exit result

‎tests/fsharp/tests.fs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,13 @@ module ToolsTests =
14571457

14581458
moduleRegressionTests=
14591459

1460-
[<Test >]
1460+
[<Test>]
1461+
let``literal-value-bug-2-FSC_BASIC``()= singleTestBuildAndRun"regression/literal-value-bug-2" FSC_BASIC
1462+
1463+
[<Test>]
1464+
let``literal-value-bug-2-FSI_BASIC``()= singleTestBuildAndRun"regression/literal-value-bug-2" FSI_BASIC
1465+
1466+
[<Test>]
14611467
let``struct-tuple-bug-1-FSC_BASIC``()= singleTestBuildAndRun"regression/struct-tuple-bug-1" FSC_BASIC
14621468

14631469
[<Test >]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[<Literal>]
2+
letx=7
3+
4+
[<EntryPoint>]
5+
letmain argv=
6+
0
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
// Microsoft (R) .NET Framework IL Disassembler. Version 4.5.22220.0
3+
4+
5+
6+
// Metadata version: v4.0.30319
7+
.assembly extern mscorlib
8+
{
9+
.publickeytoken= (B7 7A 5C561934 E089 )// .z\V.4..
10+
.ver4:0:0:0
11+
}
12+
.assembly extern FSharp.Core
13+
{
14+
.publickeytoken= (B0 3F 5F 7F11 D5 0A 3A )// .?_....:
15+
.ver4:4:3:0
16+
}
17+
.assembly LiteralValue
18+
{
19+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32,
20+
int32,
21+
int32)= (01000200000000000000000000000000 )
22+
23+
// --- The following custom attribute is added automatically, do not uncomment -------
24+
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 01 01 00 00 00 00 )
25+
26+
.hash algorithm 0x00008004
27+
.ver0:0:0:0
28+
}
29+
.mresource public FSharpSignatureData.LiteralValue
30+
{
31+
// Offset: 0x00000000 Length: 0x00000274
32+
// WARNING: managed resource file FSharpSignatureData.test created
33+
}
34+
.mresource public FSharpOptimizationData.LiteralValue
35+
{
36+
// Offset: 0x00000278 Length: 0x0000006F
37+
// WARNING: managed resource file FSharpOptimizationData.test created
38+
}
39+
.module LiteralValue.exe
40+
// MVID: {5AA663EB-D9C1-2E4E-A745-0383EB63A65A}
41+
.imagebase 0x00400000
42+
.file alignment 0x00000200
43+
.stackreserve 0x00100000
44+
.subsystem 0x0003// WINDOWS_CUI
45+
.corflags 0x00000001// ILONLY
46+
// Image base: 0x02BF0000
47+
48+
49+
// =============== CLASS MEMBERS DECLARATION ===================
50+
51+
.class public abstract auto ansi sealed LiteralValue
52+
extends [mscorlib]System.Object
53+
{
54+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags)= (0100070000000000 )
55+
.field public static literal int32 x= int32(0x00000007)
56+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.LiteralAttribute::.ctor()= (01000000 )
57+
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState)= (0100000000000000 )
58+
.method public static int32 main(string[] argv) cil managed
59+
{
60+
.entrypoint
61+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.EntryPointAttribute::.ctor()= (01000000 )
62+
// Code size 2 (0x2)
63+
.maxstack8
64+
.language '{AB4F38C9-B6E6-43BA-BE3B-58080B2CCCE3}', '{994B45C4-E6E9-11D2-903F-00C04FA302A1}', '{5A869D0B-6611-11D3-BD2A-0000F80849BD}'
65+
.line6,6 :5,6 'D:\\visualfsharp\\tests\\fsharpqa\\Source\\CodeGen\\EmittedIL\\LiteralValue\\LiteralValue.fs'
66+
IL_0000: ldc.i4.0
67+
IL_0001: ret
68+
}// end of method LiteralValue::main
69+
70+
}// end of class LiteralValue
71+
72+
.class private abstract auto ansi sealed '<StartupCode$LiteralValue>'.$LiteralValue
73+
extends [mscorlib]System.Object
74+
{
75+
}// end of class '<StartupCode$test>'.$LiteralValue
76+
77+
78+
// =============================================================
79+
80+
// *********** DISASSEMBLY COMPLETE ***********************
81+
// WARNING: Created Win32 resource file test.res
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SOURCE=LiteralValue.fs SCFLAGS="-g --test:LiteralValue --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd LiteralValue.exe"# LiteralValue.fs -

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp