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

Commit9723be6

Browse files
committed
Refactor TcFieldInit function (formerly duplicated in PatternMatchCompilation)
1 parentd8ab424 commit9723be6

File tree

3 files changed

+23
-35
lines changed

3 files changed

+23
-35
lines changed

‎src/fsharp/PatternMatchCompilation.fs‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,24 @@ let rec pathEq p1 p2 =
155155
| PathEmpty(_), PathEmpty(_)->true
156156
|_->false
157157

158-
//// (Temporarily copy-pasted from TypeChecker.fs)
159-
letTcFieldInit lit=
158+
159+
//---------------------------------------------------------------------------
160+
// Counter example generation
161+
//---------------------------------------------------------------------------
162+
163+
typeRefutedSet=
164+
/// A value RefutedInvestigation(path,discrim) indicates that the value at the given path is known
165+
/// to NOT be matched by the given discriminator
166+
| RefutedInvestigationofPath*DecisionTreeTestlist
167+
/// A value RefutedWhenClause indicates that a 'when' clause failed
168+
| RefutedWhenClause
169+
170+
letnotNullText="some-non-null-value"
171+
letotherSubtypeText="some-other-subtype"
172+
173+
/// Create a TAST const value from an IL-initialized field read from .NET metadata
174+
// (Originally moved from TcFieldInit in TypeChecker.fs -- feel free to move this somewhere more appropriate)
175+
letilFieldToTastConst lit=
160176
match litwith
161177
| ILFieldInit.String s-> Const.String s
162178
| ILFieldInit.Null-> Const.Zero
@@ -173,21 +189,6 @@ let TcFieldInit lit =
173189
| ILFieldInit.Single f-> Const.Single f
174190
| ILFieldInit.Double f-> Const.Double f
175191

176-
177-
//---------------------------------------------------------------------------
178-
// Counter example generation
179-
//---------------------------------------------------------------------------
180-
181-
typeRefutedSet=
182-
/// A value RefutedInvestigation(path,discrim) indicates that the value at the given path is known
183-
/// to NOT be matched by the given discriminator
184-
| RefutedInvestigationofPath*DecisionTreeTestlist
185-
/// A value RefutedWhenClause indicates that a 'when' clause failed
186-
| RefutedWhenClause
187-
188-
letnotNullText="some-non-null-value"
189-
letotherSubtypeText="some-other-subtype"
190-
191192
exception CannotRefute
192193
letRefuteDiscrimSet g m path discrims=
193194
letmkUnknown ty= snd(mkCompGenLocal m"_" ty)
@@ -264,7 +265,7 @@ let RefuteDiscrimSet g m path discrims =
264265
|> Seq.choose(fun ilField->
265266
if ilField.IsStaticthen
266267
ilField.LiteralValue|> Option.map(fun ilValue->
267-
ilField.Name,TcFieldInit ilValue)
268+
ilField.Name,ilFieldToTastConst ilValue)
268269
else None)
269270
else
270271
tcref.AllFieldsArray|> Seq.choose(fun fsField->

‎src/fsharp/PatternMatchCompilation.fsi‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
moduleinternalMicrosoft.FSharp.Compiler.PatternMatchCompilation
44

5+
openMicrosoft.FSharp.Compiler.AbstractIL.IL
56
openMicrosoft.FSharp.Compiler
67
openMicrosoft.FSharp.Compiler.Tast
78
openMicrosoft.FSharp.Compiler.Tastops
@@ -42,6 +43,8 @@ and PatternValBinding =
4243
andTypedMatchClause=
4344
| TClauseofPattern*Exproption*DecisionTreeTarget*range
4445

46+
valilFieldToTastConst:ILFieldInit->Tast.Const
47+
4548
/// Compile a pattern into a decision tree and a set of targets.
4649
valinternalCompilePattern:
4750
TcGlobals->

‎src/fsharp/TypeChecker.fs‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -905,23 +905,7 @@ let TcConst cenv ty m env c =
905905
| SynConst.Bytes _ -> error (InternalError(FSComp.SR.tcUnexpectedConstByteArray(), m))
906906

907907
/// Convert an Abstract IL ILFieldInit value read from .NET metadata to a TAST constant
908-
let TcFieldInit (_m:range) lit =
909-
match lit with
910-
| ILFieldInit.String s -> Const.String s
911-
| ILFieldInit.Null -> Const.Zero
912-
| ILFieldInit.Bool b -> Const.Bool b
913-
| ILFieldInit.Char c -> Const.Char (char (int c))
914-
| ILFieldInit.Int8 x -> Const.SByte x
915-
| ILFieldInit.Int16 x -> Const.Int16 x
916-
| ILFieldInit.Int32 x -> Const.Int32 x
917-
| ILFieldInit.Int64 x -> Const.Int64 x
918-
| ILFieldInit.UInt8 x -> Const.Byte x
919-
| ILFieldInit.UInt16 x -> Const.UInt16 x
920-
| ILFieldInit.UInt32 x -> Const.UInt32 x
921-
| ILFieldInit.UInt64 x -> Const.UInt64 x
922-
| ILFieldInit.Single f -> Const.Single f
923-
| ILFieldInit.Double f -> Const.Double f
924-
908+
let TcFieldInit (_m:range) lit = PatternMatchCompilation.ilFieldToTastConst lit
925909

926910
//-------------------------------------------------------------------------
927911
// Arities. These serve two roles in the system:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp