Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
907e4392
F
fsharp
项目概览
dotNET Platform
/
fsharp
10 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fsharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
907e4392
编写于
5月 19, 2022
作者:
D
Don Syme
提交者:
GitHub
5月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
split out CheckPatterns.* (#13168)
* split out CheckPatterns.* * split out CheckPatterns.*
上级
3b92fd2d
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
1606 addition
and
1842 deletion
+1606
-1842
src/Compiler/Checking/CheckDeclarations.fs
src/Compiler/Checking/CheckDeclarations.fs
+17
-6
src/Compiler/Checking/CheckExpressions.fs
src/Compiler/Checking/CheckExpressions.fs
+344
-979
src/Compiler/Checking/CheckExpressions.fsi
src/Compiler/Checking/CheckExpressions.fsi
+170
-34
src/Compiler/Checking/CheckPatterns.fs
src/Compiler/Checking/CheckPatterns.fs
+757
-0
src/Compiler/Checking/CheckPatterns.fsi
src/Compiler/Checking/CheckPatterns.fsi
+42
-0
src/Compiler/FSharp.Compiler.Service.fsproj
src/Compiler/FSharp.Compiler.Service.fsproj
+276
-822
src/Compiler/Service/ServiceLexing.fsi
src/Compiler/Service/ServiceLexing.fsi
+0
-1
未找到文件。
src/Compiler/Checking/CheckDeclarations.fs
浏览文件 @
907e4392
...
...
@@ -11,11 +11,11 @@ open Internal.Utilities.Library.Extras
open
Internal
.
Utilities
.
Library
.
ResultOrException
open
FSharp
.
Compiler
open
FSharp
.
Compiler
.
AbstractIL
.
IL
open
FSharp
.
Compiler
.
AbstractIL
.
Diagnostics
open
FSharp
.
Compiler
.
AccessibilityLogic
open
FSharp
.
Compiler
.
AttributeChecking
open
FSharp
.
Compiler
.
CheckExpressions
open
FSharp
.
Compiler
.
CheckComputationExpressions
open
FSharp
.
Compiler
.
CheckExpressions
open
FSharp
.
Compiler
.
CheckPatterns
open
FSharp
.
Compiler
.
CompilerGlobalState
open
FSharp
.
Compiler
.
ConstraintSolver
open
FSharp
.
Compiler
.
DiagnosticsLogger
...
...
@@ -758,7 +758,9 @@ module IncrClassChecking =
// Type check arguments by processing them as 'simple' patterns
// NOTE: if we allow richer patterns here this is where we'd process those patterns
let
ctorArgNames
,
(_,
names
,
_)
=
TcSimplePatsOfUnknownType
cenv
true
CheckCxs
env
tpenv
(
SynSimplePats
.
SimplePats
(
spats
,
m
))
let
ctorArgNames
,
patEnv
=
TcSimplePatsOfUnknownType
cenv
true
CheckCxs
env
tpenv
(
SynSimplePats
.
SimplePats
(
spats
,
m
))
let
(
TcPatLinearEnv
(_,
names
,
_))
=
patEnv
// Create the values with the given names
let
_,
vspecs
=
MakeAndPublishSimpleVals
cenv
env
names
...
...
@@ -3232,7 +3234,10 @@ module EstablishTypeDefinitionCores =
match
implicitCtorSynPats
with
|
None
->
()
|
Some
spats
->
let
ctorArgNames
,
(_,
names
,
_)
=
TcSimplePatsOfUnknownType
cenv
true
NoCheckCxs
env
tpenv
spats
let
ctorArgNames
,
patEnv
=
TcSimplePatsOfUnknownType
cenv
true
NoCheckCxs
env
tpenv
spats
let
(
TcPatLinearEnv
(_,
names
,
_))
=
patEnv
for
arg
in
ctorArgNames
do
let
ty
=
names
[
arg
].
Type
let
m
=
names
[
arg
].
Ident
.
idRange
...
...
@@ -4113,7 +4118,10 @@ module EstablishTypeDefinitionCores =
()
|
Some
spats
->
if
tycon
.
IsFSharpStructOrEnumTycon
then
let
ctorArgNames
,
(_,
names
,
_)
=
TcSimplePatsOfUnknownType
cenv
true
CheckCxs
envinner
tpenv
spats
let
ctorArgNames
,
patEnv
=
TcSimplePatsOfUnknownType
cenv
true
CheckCxs
envinner
tpenv
spats
let
(
TcPatLinearEnv
(_,
names
,
_))
=
patEnv
for
arg
in
ctorArgNames
do
let
ty
=
names
[
arg
].
Type
let
id
=
names
[
arg
].
Ident
...
...
@@ -5575,7 +5583,6 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
|
SynModuleDecl
.
NamespaceFragment
(
SynModuleOrNamespace
(
longId
,
isRec
,
kind
,
defs
,
xml
,
attribs
,
vis
,
m
,
_))
->
if
progress
then
dprintn
(
"Typecheck implementation "
+
textOfLid
longId
)
let
endm
=
m
.
EndRange
do
for
id
in
longId
do
...
...
@@ -6002,6 +6009,8 @@ let CheckOneImplFile
let
cenv
=
cenv
.
Create
(
g
,
isScript
,
niceNameGen
,
amap
,
thisCcu
,
false
,
Option
.
isSome
rootSigOpt
,
conditionalDefines
,
tcSink
,
(
LightweightTcValForUsingInBuildMethodCall
g
),
isInternalTestSpanStackReferring
,
tcPat
=
TcPat
,
tcSimplePats
=
TcSimplePats
,
tcSequenceExpressionEntry
=
TcSequenceExpressionEntry
,
tcArrayOrListSequenceExpression
=
TcArrayOrListComputedExpression
,
tcComputationExpression
=
TcComputationExpression
)
...
...
@@ -6128,6 +6137,8 @@ let CheckOneSigFile (g, niceNameGen, amap, thisCcu, checkForErrors, conditionalD
cenv
.
Create
(
g
,
false
,
niceNameGen
,
amap
,
thisCcu
,
true
,
false
,
conditionalDefines
,
tcSink
,
(
LightweightTcValForUsingInBuildMethodCall
g
),
isInternalTestSpanStackReferring
,
tcPat
=
TcPat
,
tcSimplePats
=
TcSimplePats
,
tcSequenceExpressionEntry
=
TcSequenceExpressionEntry
,
tcArrayOrListSequenceExpression
=
TcArrayOrListComputedExpression
,
tcComputationExpression
=
TcComputationExpression
)
...
...
src/Compiler/Checking/CheckExpressions.fs
浏览文件 @
907e4392
此差异已折叠。
点击以展开。
src/Compiler/Checking/CheckExpressions.fsi
浏览文件 @
907e4392
...
...
@@ -222,6 +222,89 @@ val LightweightTcValForUsingInBuildMethodCall:
/// (i.e. are without explicit declaration).
type
UnscopedTyparEnv
/// A type to represent information associated with values to indicate what explicit (declared) type parameters
/// are given and what additional type parameters can be inferred, if any.
///
/// The declared type parameters, e.g. let f<'a> (x:'a) = x, plus an indication
/// of whether additional polymorphism may be inferred, e.g. let f<'a, ..> (x:'a) y = x
type
ExplicitTyparInfo
=
ExplicitTyparInfo
of
rigidCopyOfDeclaredTypars
:
Typars
*
declaredTypars
:
Typars
*
infer
:
bool
val
permitInferTypars
:
ExplicitTyparInfo
val
dontInferTypars
:
ExplicitTyparInfo
type
ArgAndRetAttribs
=
ArgAndRetAttribs
of
Attribs
list
list
*
Attribs
val
noArgOrRetAttribs
:
ArgAndRetAttribs
/// Indicates whether constraints should be checked when checking syntactic types
type
CheckConstraints
=
|
CheckCxs
|
NoCheckCxs
/// Represents the ValReprInfo for a value, before the typars are fully inferred
type
PrelimValReprInfo
=
PrelimValReprInfo
of
curriedArgInfos
:
ArgReprInfo
list
list
*
returnInfo
:
ArgReprInfo
/// Holds the initial ValMemberInfo and other information before it is fully completed
type
PrelimMemberInfo
=
PrelimMemberInfo
of
memberInfo
:
ValMemberInfo
*
logicalName
:
string
*
compiledName
:
string
/// Represents the results of the first phase of preparing simple values from a pattern
type
PrelimVal1
=
|
PrelimVal1
of
id
:
Ident
*
explicitTyparInfo
:
ExplicitTyparInfo
*
prelimType
:
TType
*
prelimValReprInfo
:
PrelimValReprInfo
option
*
memberInfoOpt
:
PrelimMemberInfo
option
*
isMutable
:
bool
*
inlineFlag
:
ValInline
*
baseOrThisInfo
:
ValBaseOrThisInfo
*
argAttribs
:
ArgAndRetAttribs
*
visibility
:
SynAccess
option
*
isCompGen
:
bool
member
Type
:
TType
member
Ident
:
Ident
/// The results of applying let-style generalization after type checking.
type
PrelimVal2
=
|
PrelimVal2
of
id
:
Ident
*
prelimType
:
GeneralizedType
*
prelimValReprInfo
:
PrelimValReprInfo
option
*
memberInfoOpt
:
PrelimMemberInfo
option
*
isMutable
:
bool
*
inlineFlag
:
ValInline
*
baseOrThisInfo
:
ValBaseOrThisInfo
*
argAttribs
:
ArgAndRetAttribs
*
visibility
:
SynAccess
option
*
isCompGen
:
bool
*
hasDeclaredTypars
:
bool
/// Translation of patterns is split into three phases. The first collects names.
/// The second is run after val_specs have been created for those names and inference
/// has been resolved. The second phase is run by applying a function returned by the
/// first phase. The input to the second phase is a List.map that gives the Val and type scheme
/// for each value bound by the pattern.
type
TcPatPhase2Input
=
|
TcPatPhase2Input
of
NameMap
<
Val
*
GeneralizedType
>
*
bool
member
WithRightPath
:
unit
->
TcPatPhase2Input
/// Represents the context flowed left-to-right through pattern checking
type
TcPatLinearEnv
=
TcPatLinearEnv
of
tpenv
:
UnscopedTyparEnv
*
names
:
NameMap
<
PrelimVal1
>
*
takenNames
:
Set
<
string
>
/// Represents the flags passsed to TcPat regarding the binding location
type
TcPatValFlags
=
|
TcPatValFlags
of
inlineFlag
:
ValInline
*
explicitTyparInfo
:
ExplicitTyparInfo
*
argAndRetAttribs
:
ArgAndRetAttribs
*
isMutable
:
bool
*
visibility
:
SynAccess
option
*
isCompilerGenerated
:
bool
/// Represents the compilation environment for typechecking a single file in an assembly.
[<
NoEquality
;
NoComparison
>]
type
TcFileState
=
...
...
@@ -282,6 +365,27 @@ type TcFileState =
isInternalTestSpanStackReferring
:
bool
// forward call
TcPat
:
WarnOnUpperFlag
->
TcFileState
->
TcEnv
->
PrelimValReprInfo
option
->
TcPatValFlags
->
TcPatLinearEnv
->
TType
->
SynPat
->
(
TcPatPhase2Input
->
Pattern
)
*
TcPatLinearEnv
// forward call
TcSimplePats
:
TcFileState
->
bool
->
CheckConstraints
->
TType
->
TcEnv
->
TcPatLinearEnv
->
SynSimplePats
->
string
list
*
TcPatLinearEnv
// forward call
TcSequenceExpressionEntry
:
TcFileState
->
TcEnv
...
...
@@ -321,6 +425,8 @@ type TcFileState =
tcSink
:
TcResultsSink
*
tcVal
:
TcValF
*
isInternalTestSpanStackReferring
:
bool
*
tcPat
:
(
WarnOnUpperFlag
->
TcFileState
->
TcEnv
->
PrelimValReprInfo
option
->
TcPatValFlags
->
TcPatLinearEnv
->
TType
->
SynPat
->
(
TcPatPhase2Input
->
Pattern
)
*
TcPatLinearEnv
)
*
tcSimplePats
:
(
TcFileState
->
bool
->
CheckConstraints
->
TType
->
TcEnv
->
TcPatLinearEnv
->
SynSimplePats
->
string
list
*
TcPatLinearEnv
)
*
tcSequenceExpressionEntry
:
(
TcFileState
->
TcEnv
->
OverallTy
->
UnscopedTyparEnv
->
bool
*
SynExpr
->
range
->
Expr
*
UnscopedTyparEnv
)
*
tcArrayOrListSequenceExpression
:
(
TcFileState
->
TcEnv
->
OverallTy
->
UnscopedTyparEnv
->
bool
*
SynExpr
->
range
->
Expr
*
UnscopedTyparEnv
)
*
tcComputationExpression
:
(
TcFileState
->
TcEnv
->
OverallTy
->
UnscopedTyparEnv
->
range
*
Expr
*
TType
*
SynExpr
->
Expr
*
UnscopedTyparEnv
)
->
...
...
@@ -400,11 +506,6 @@ type ImplicitlyBoundTyparsAllowed =
|
NewTyparsOK
|
NoNewTypars
/// Indicates whether constraints should be checked when checking syntactic types
type
CheckConstraints
=
|
CheckCxs
|
NoCheckCxs
/// Indicates if a member binding is an object expression binding
type
IsObjExprBinding
=
|
ObjExprBinding
...
...
@@ -418,12 +519,6 @@ type RecDefnBindingInfo =
declKind
:
DeclKind
*
synBinding
:
SynBinding
/// Represents the ValReprInfo for a value, before the typars are fully inferred
type
PrelimValReprInfo
=
PrelimValReprInfo
of
curriedArgInfos
:
ArgReprInfo
list
list
*
returnInfo
:
ArgReprInfo
/// Holds the initial ValMemberInfo and other information before it is fully completed
type
PrelimMemberInfo
=
PrelimMemberInfo
of
memberInfo
:
ValMemberInfo
*
logicalName
:
string
*
compiledName
:
string
/// The result of checking a value or member signature
type
ValSpecResult
=
|
ValSpecResult
of
...
...
@@ -439,13 +534,6 @@ type ValSpecResult =
/// An empty environment of type variables with implicit scope
val
emptyUnscopedTyparEnv
:
UnscopedTyparEnv
/// A type to represent information associated with values to indicate what explicit (declared) type parameters
/// are given and what additional type parameters can be inferred, if any.
///
/// The declared type parameters, e.g. let f<'a> (x:'a) = x, plus an indication
/// of whether additional polymorphism may be inferred, e.g. let f<'a, ..> (x:'a) y = x
type
ExplicitTyparInfo
=
ExplicitTyparInfo
of
rigidCopyOfDeclaredTypars
:
Typars
*
declaredTypars
:
Typars
*
infer
:
bool
/// NormalizedBindingRhs records the r.h.s. of a binding after some munging just before type checking.
type
NormalizedBindingRhs
=
|
NormalizedBindingRhs
of
...
...
@@ -492,12 +580,6 @@ type RecursiveBindingInfo =
member
EnclosingDeclaredTypars
:
Typar
list
member
Index
:
int
/// Represents the results of the first phase of preparing simple values from a pattern
[<
Sealed
>]
type
PrelimVal1
=
member
Ident
:
Ident
member
Type
:
TType
/// Represents the results of the first phase of preparing bindings
[<
Sealed
>]
type
CheckedBindingInfo
...
...
@@ -963,6 +1045,9 @@ val TcNewExpr:
mWholeExprOrObjTy
:
range
->
Expr
*
UnscopedTyparEnv
/// Check a 'nameof' expression
val
TcNameOfExpr
:
cenv
:
TcFileState
->
env
:
TcEnv
->
tpenv
:
UnscopedTyparEnv
->
synArg
:
SynExpr
->
Expr
#
if
!
NO_TYPEPROVIDERS
/// Check the application of a provided type to static args
val
TcProvidedTypeAppToStaticConstantArgs
:
...
...
@@ -976,16 +1061,6 @@ val TcProvidedTypeAppToStaticConstantArgs:
bool
*
Tainted
<
ProvidedType
>
*
(
unit
->
unit
)
#
endif
/// Check a set of simple patterns, e.g. the declarations of parameters for an implicit constructor.
val
TcSimplePatsOfUnknownType
:
cenv
:
TcFileState
->
optionalArgsOK
:
bool
->
checkConstraints
:
CheckConstraints
->
env
:
TcEnv
->
tpenv
:
UnscopedTyparEnv
->
synSimplePats
:
SynSimplePats
->
string
list
*
(
UnscopedTyparEnv
*
NameMap
<
PrelimVal1
>
*
Set
<
string
>)
/// Check a set of explicitly declared constraints on type parameters
val
TcTyparConstraints
:
cenv
:
TcFileState
->
...
...
@@ -1064,6 +1139,67 @@ val TranslatePartialValReprInfo: tps: Typar list -> PrelimValReprInfo -> ValRepr
/// Constrain two types to be equal within this type checking context
val
UnifyTypes
:
cenv
:
TcFileState
->
env
:
TcEnv
->
m
:
range
->
actualTy
:
TType
->
expectedTy
:
TType
->
unit
val
TcRuntimeTypeTest
:
isCast
:
bool
->
isOperator
:
bool
->
cenv
:
TcFileState
->
denv
:
DisplayEnv
->
m
:
range
->
tgtTy
:
TType
->
srcTy
:
TType
->
unit
/// Allow the inference of structness from the known type, e.g.
/// let (x: struct (int * int)) = (3,4)
val
UnifyTupleTypeAndInferCharacteristics
:
contextInfo
:
ContextInfo
->
cenv
:
TcFileState
->
denv
:
DisplayEnv
->
m
:
range
->
knownTy
:
TType
->
isExplicitStruct
:
bool
->
'
T
list
->
TupInfo
*
TTypes
/// Helper used to check both record expressions and record patterns
val
BuildFieldMap
:
cenv
:
TcFileState
->
env
:
TcEnv
->
isPartial
:
bool
->
ty
:
TType
->
((
Ident
list
*
Ident
)
*
'
T
)
list
->
m
:
range
->
TypeInst
*
TyconRef
*
Map
<
string
,
'
T
>
*
(
string
*
'
T
)
list
/// Check a long identifier 'Case' or 'Case argsR' that has been resolved to an active pattern case
val
TcPatLongIdentActivePatternCase
:
warnOnUpper
:
WarnOnUpperFlag
->
cenv
:
TcFileState
->
env
:
TcEnv
->
vFlags
:
TcPatValFlags
->
patEnv
:
TcPatLinearEnv
->
ty
:
TType
->
lidRange
:
range
*
item
:
Item
*
apref
:
ActivePatternElemRef
*
args
:
SynPat
list
*
m
:
range
->
(
TcPatPhase2Input
->
Pattern
)
*
TcPatLinearEnv
/// The pattern syntax can also represent active pattern arguments. This routine
/// converts from the pattern syntax to the expression syntax.
///
/// Note we parse arguments to parameterized pattern labels as patterns, not expressions.
/// This means the range of syntactic expression forms that can be used here is limited.
val
ConvSynPatToSynExpr
:
synPat
:
SynPat
->
SynExpr
val
TcVal
:
checkAttributes
:
bool
->
cenv
:
TcFileState
->
env
:
TcEnv
->
tpenv
:
UnscopedTyparEnv
->
vref
:
ValRef
->
instantiationInfoOpt
:
(
ValUseFlag
*
(
UnscopedTyparEnv
->
TyparKind
list
->
TypeInst
*
UnscopedTyparEnv
))
option
->
optAfterResolution
:
AfterResolution
option
->
m
:
range
->
Typar
list
*
Expr
*
bool
*
TType
*
TType
list
*
UnscopedTyparEnv
module
GeneralizationHelpers
=
/// Given an environment, compute the set of inference type variables which may not be
...
...
src/Compiler/Checking/CheckPatterns.fs
0 → 100644
浏览文件 @
907e4392
此差异已折叠。
点击以展开。
src/Compiler/Checking/CheckPatterns.fsi
0 → 100644
浏览文件 @
907e4392
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
module
internal
FSharp
.
Compiler
.
CheckPatterns
open
FSharp
.
Compiler
.
CheckExpressions
open
FSharp
.
Compiler
.
NameResolution
open
FSharp
.
Compiler
.
TypedTree
open
FSharp
.
Compiler
.
PatternMatchCompilation
open
FSharp
.
Compiler
.
Syntax
/// Check a set of simple patterns, e.g. the declarations of parameters for an implicit constructor.
val
TcSimplePatsOfUnknownType
:
cenv
:
TcFileState
->
optionalArgsOK
:
bool
->
checkConstraints
:
CheckConstraints
->
env
:
TcEnv
->
tpenv
:
UnscopedTyparEnv
->
synSimplePats
:
SynSimplePats
->
string
list
*
TcPatLinearEnv
// Check a pattern, e.g. for a binding or a match clause
val
TcPat
:
warnOnUpper
:
WarnOnUpperFlag
->
cenv
:
TcFileState
->
env
:
TcEnv
->
valReprInfo
:
PrelimValReprInfo
option
->
vFlags
:
TcPatValFlags
->
patEnv
:
TcPatLinearEnv
->
ty
:
TType
->
synPat
:
SynPat
->
(
TcPatPhase2Input
->
Pattern
)
*
TcPatLinearEnv
// Check a list of simple patterns, e.g. for the arguments of a function or a class constructor
val
TcSimplePats
:
cenv
:
TcFileState
->
optionalArgsOK
:
bool
->
checkConstraints
:
CheckConstraints
->
ty
:
TType
->
env
:
TcEnv
->
patEnv
:
TcPatLinearEnv
->
synSimplePats
:
SynSimplePats
->
string
list
*
TcPatLinearEnv
src/Compiler/FSharp.Compiler.Service.fsproj
浏览文件 @
907e4392
此差异已折叠。
点击以展开。
src/Compiler/Service/ServiceLexing.fsi
浏览文件 @
907e4392
...
...
@@ -6,7 +6,6 @@ open System
open
System
.
Threading
open
FSharp
.
Compiler
open
FSharp
.
Compiler
.
Text
#
nowarn
"57"
/// Represents encoded information for the end-of-line continuation of lexing
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录