未验证 提交 907e4392 编写于 作者: D Don Syme 提交者: GitHub

split out CheckPatterns.* (#13168)

* split out CheckPatterns.*

* split out CheckPatterns.*
上级 3b92fd2d
...@@ -11,11 +11,11 @@ open Internal.Utilities.Library.Extras ...@@ -11,11 +11,11 @@ open Internal.Utilities.Library.Extras
open Internal.Utilities.Library.ResultOrException open Internal.Utilities.Library.ResultOrException
open FSharp.Compiler open FSharp.Compiler
open FSharp.Compiler.AbstractIL.IL open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.AbstractIL.Diagnostics
open FSharp.Compiler.AccessibilityLogic open FSharp.Compiler.AccessibilityLogic
open FSharp.Compiler.AttributeChecking open FSharp.Compiler.AttributeChecking
open FSharp.Compiler.CheckExpressions
open FSharp.Compiler.CheckComputationExpressions open FSharp.Compiler.CheckComputationExpressions
open FSharp.Compiler.CheckExpressions
open FSharp.Compiler.CheckPatterns
open FSharp.Compiler.CompilerGlobalState open FSharp.Compiler.CompilerGlobalState
open FSharp.Compiler.ConstraintSolver open FSharp.Compiler.ConstraintSolver
open FSharp.Compiler.DiagnosticsLogger open FSharp.Compiler.DiagnosticsLogger
...@@ -758,7 +758,9 @@ module IncrClassChecking = ...@@ -758,7 +758,9 @@ module IncrClassChecking =
// Type check arguments by processing them as 'simple' patterns // Type check arguments by processing them as 'simple' patterns
// NOTE: if we allow richer patterns here this is where we'd process those 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 // Create the values with the given names
let _, vspecs = MakeAndPublishSimpleVals cenv env names let _, vspecs = MakeAndPublishSimpleVals cenv env names
...@@ -3232,7 +3234,10 @@ module EstablishTypeDefinitionCores = ...@@ -3232,7 +3234,10 @@ module EstablishTypeDefinitionCores =
match implicitCtorSynPats with match implicitCtorSynPats with
| None -> () | None -> ()
| Some spats -> | 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 for arg in ctorArgNames do
let ty = names[arg].Type let ty = names[arg].Type
let m = names[arg].Ident.idRange let m = names[arg].Ident.idRange
...@@ -4113,7 +4118,10 @@ module EstablishTypeDefinitionCores = ...@@ -4113,7 +4118,10 @@ module EstablishTypeDefinitionCores =
() ()
| Some spats -> | Some spats ->
if tycon.IsFSharpStructOrEnumTycon then 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 for arg in ctorArgNames do
let ty = names[arg].Type let ty = names[arg].Type
let id = names[arg].Ident let id = names[arg].Ident
...@@ -5575,7 +5583,6 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem ...@@ -5575,7 +5583,6 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
| SynModuleDecl.NamespaceFragment(SynModuleOrNamespace(longId, isRec, kind, defs, xml, attribs, vis, m, _)) -> | SynModuleDecl.NamespaceFragment(SynModuleOrNamespace(longId, isRec, kind, defs, xml, attribs, vis, m, _)) ->
if progress then dprintn ("Typecheck implementation " + textOfLid longId)
let endm = m.EndRange let endm = m.EndRange
do for id in longId do do for id in longId do
...@@ -6002,6 +6009,8 @@ let CheckOneImplFile ...@@ -6002,6 +6009,8 @@ let CheckOneImplFile
let cenv = let cenv =
cenv.Create (g, isScript, niceNameGen, amap, thisCcu, false, Option.isSome rootSigOpt, cenv.Create (g, isScript, niceNameGen, amap, thisCcu, false, Option.isSome rootSigOpt,
conditionalDefines, tcSink, (LightweightTcValForUsingInBuildMethodCall g), isInternalTestSpanStackReferring, conditionalDefines, tcSink, (LightweightTcValForUsingInBuildMethodCall g), isInternalTestSpanStackReferring,
tcPat=TcPat,
tcSimplePats=TcSimplePats,
tcSequenceExpressionEntry=TcSequenceExpressionEntry, tcSequenceExpressionEntry=TcSequenceExpressionEntry,
tcArrayOrListSequenceExpression=TcArrayOrListComputedExpression, tcArrayOrListSequenceExpression=TcArrayOrListComputedExpression,
tcComputationExpression=TcComputationExpression) tcComputationExpression=TcComputationExpression)
...@@ -6128,6 +6137,8 @@ let CheckOneSigFile (g, niceNameGen, amap, thisCcu, checkForErrors, conditionalD ...@@ -6128,6 +6137,8 @@ let CheckOneSigFile (g, niceNameGen, amap, thisCcu, checkForErrors, conditionalD
cenv.Create cenv.Create
(g, false, niceNameGen, amap, thisCcu, true, false, conditionalDefines, tcSink, (g, false, niceNameGen, amap, thisCcu, true, false, conditionalDefines, tcSink,
(LightweightTcValForUsingInBuildMethodCall g), isInternalTestSpanStackReferring, (LightweightTcValForUsingInBuildMethodCall g), isInternalTestSpanStackReferring,
tcPat=TcPat,
tcSimplePats=TcSimplePats,
tcSequenceExpressionEntry=TcSequenceExpressionEntry, tcSequenceExpressionEntry=TcSequenceExpressionEntry,
tcArrayOrListSequenceExpression=TcArrayOrListComputedExpression, tcArrayOrListSequenceExpression=TcArrayOrListComputedExpression,
tcComputationExpression=TcComputationExpression) tcComputationExpression=TcComputationExpression)
......
...@@ -222,6 +222,89 @@ val LightweightTcValForUsingInBuildMethodCall: ...@@ -222,6 +222,89 @@ val LightweightTcValForUsingInBuildMethodCall:
/// (i.e. are without explicit declaration). /// (i.e. are without explicit declaration).
type UnscopedTyparEnv 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. /// Represents the compilation environment for typechecking a single file in an assembly.
[<NoEquality; NoComparison>] [<NoEquality; NoComparison>]
type TcFileState = type TcFileState =
...@@ -282,6 +365,27 @@ type TcFileState = ...@@ -282,6 +365,27 @@ type TcFileState =
isInternalTestSpanStackReferring: bool 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 // forward call
TcSequenceExpressionEntry: TcFileState TcSequenceExpressionEntry: TcFileState
-> TcEnv -> TcEnv
...@@ -321,6 +425,8 @@ type TcFileState = ...@@ -321,6 +425,8 @@ type TcFileState =
tcSink: TcResultsSink * tcSink: TcResultsSink *
tcVal: TcValF * tcVal: TcValF *
isInternalTestSpanStackReferring: bool * 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) * tcSequenceExpressionEntry: (TcFileState -> TcEnv -> OverallTy -> UnscopedTyparEnv -> bool * SynExpr -> range -> Expr * UnscopedTyparEnv) *
tcArrayOrListSequenceExpression: (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) -> tcComputationExpression: (TcFileState -> TcEnv -> OverallTy -> UnscopedTyparEnv -> range * Expr * TType * SynExpr -> Expr * UnscopedTyparEnv) ->
...@@ -400,11 +506,6 @@ type ImplicitlyBoundTyparsAllowed = ...@@ -400,11 +506,6 @@ type ImplicitlyBoundTyparsAllowed =
| NewTyparsOK | NewTyparsOK
| NoNewTypars | 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 /// Indicates if a member binding is an object expression binding
type IsObjExprBinding = type IsObjExprBinding =
| ObjExprBinding | ObjExprBinding
...@@ -418,12 +519,6 @@ type RecDefnBindingInfo = ...@@ -418,12 +519,6 @@ type RecDefnBindingInfo =
declKind: DeclKind * declKind: DeclKind *
synBinding: SynBinding 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 /// The result of checking a value or member signature
type ValSpecResult = type ValSpecResult =
| ValSpecResult of | ValSpecResult of
...@@ -439,13 +534,6 @@ type ValSpecResult = ...@@ -439,13 +534,6 @@ type ValSpecResult =
/// An empty environment of type variables with implicit scope /// An empty environment of type variables with implicit scope
val emptyUnscopedTyparEnv: UnscopedTyparEnv 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. /// NormalizedBindingRhs records the r.h.s. of a binding after some munging just before type checking.
type NormalizedBindingRhs = type NormalizedBindingRhs =
| NormalizedBindingRhs of | NormalizedBindingRhs of
...@@ -492,12 +580,6 @@ type RecursiveBindingInfo = ...@@ -492,12 +580,6 @@ type RecursiveBindingInfo =
member EnclosingDeclaredTypars: Typar list member EnclosingDeclaredTypars: Typar list
member Index: int 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 /// Represents the results of the first phase of preparing bindings
[<Sealed>] [<Sealed>]
type CheckedBindingInfo type CheckedBindingInfo
...@@ -963,6 +1045,9 @@ val TcNewExpr: ...@@ -963,6 +1045,9 @@ val TcNewExpr:
mWholeExprOrObjTy: range -> mWholeExprOrObjTy: range ->
Expr * UnscopedTyparEnv Expr * UnscopedTyparEnv
/// Check a 'nameof' expression
val TcNameOfExpr: cenv: TcFileState -> env: TcEnv -> tpenv: UnscopedTyparEnv -> synArg: SynExpr -> Expr
#if !NO_TYPEPROVIDERS #if !NO_TYPEPROVIDERS
/// Check the application of a provided type to static args /// Check the application of a provided type to static args
val TcProvidedTypeAppToStaticConstantArgs: val TcProvidedTypeAppToStaticConstantArgs:
...@@ -976,16 +1061,6 @@ val TcProvidedTypeAppToStaticConstantArgs: ...@@ -976,16 +1061,6 @@ val TcProvidedTypeAppToStaticConstantArgs:
bool * Tainted<ProvidedType> * (unit -> unit) bool * Tainted<ProvidedType> * (unit -> unit)
#endif #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 /// Check a set of explicitly declared constraints on type parameters
val TcTyparConstraints: val TcTyparConstraints:
cenv: TcFileState -> cenv: TcFileState ->
...@@ -1064,6 +1139,67 @@ val TranslatePartialValReprInfo: tps: Typar list -> PrelimValReprInfo -> ValRepr ...@@ -1064,6 +1139,67 @@ val TranslatePartialValReprInfo: tps: Typar list -> PrelimValReprInfo -> ValRepr
/// Constrain two types to be equal within this type checking context /// 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 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 = module GeneralizationHelpers =
/// Given an environment, compute the set of inference type variables which may not be /// Given an environment, compute the set of inference type variables which may not be
......
此差异已折叠。
// 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
...@@ -6,7 +6,6 @@ open System ...@@ -6,7 +6,6 @@ open System
open System.Threading open System.Threading
open FSharp.Compiler open FSharp.Compiler
open FSharp.Compiler.Text open FSharp.Compiler.Text
#nowarn "57" #nowarn "57"
/// Represents encoded information for the end-of-line continuation of lexing /// 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.
先完成此消息的编辑!
想要评论请 注册