Skip to content

Commit 3e66a60

Browse files
authored
Chore: splitting CheckIncrementalClasses from CheckDeclarations
2 parents 8882026 + 93b3c21 commit 3e66a60

File tree

6 files changed

+1055
-872
lines changed

6 files changed

+1055
-872
lines changed

src/Compiler/Checking/CheckDeclarations.fs

Lines changed: 1 addition & 870 deletions
Large diffs are not rendered by default.

src/Compiler/Checking/CheckDeclarations.fsi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,4 @@ val CheckOneSigFile:
7575
ParsedSigFileInput ->
7676
Cancellable<TcEnv * ModuleOrNamespaceType * bool>
7777

78-
exception ParameterlessStructCtor of range: range
79-
8078
exception NotUpperCaseConstructor of range: range

src/Compiler/Checking/CheckIncrementalClasses.fs

Lines changed: 892 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
module internal FSharp.Compiler.CheckIncrementalClasses
2+
3+
open Internal.Utilities.Collections
4+
open FSharp.Compiler.CheckExpressions
5+
open FSharp.Compiler.CompilerGlobalState
6+
open FSharp.Compiler.Syntax
7+
open FSharp.Compiler.TcGlobals
8+
open FSharp.Compiler.Text
9+
open FSharp.Compiler.TypedTree
10+
open FSharp.Compiler.TypedTreeOps
11+
open FSharp.Compiler.Xml
12+
13+
exception ParameterlessStructCtor of range: range
14+
15+
/// Typechecked info for implicit constructor and it's arguments
16+
type IncrClassCtorLhs =
17+
{
18+
/// The TyconRef for the type being defined
19+
TyconRef: TyconRef
20+
21+
/// The type parameters allocated for the implicit instance constructor.
22+
/// These may be equated with other (WillBeRigid) type parameters through equi-recursive inference, and so
23+
/// should always be renormalized/canonicalized when used.
24+
InstanceCtorDeclaredTypars: Typars
25+
26+
/// The value representing the static implicit constructor.
27+
/// Lazy to ensure the static ctor value is only published if needed.
28+
StaticCtorValInfo: Lazy<Val list * Val * ValScheme>
29+
30+
/// The value representing the implicit constructor.
31+
InstanceCtorVal: Val
32+
33+
/// The type of the implicit constructor, representing as a ValScheme.
34+
InstanceCtorValScheme: ValScheme
35+
36+
/// The values representing the arguments to the implicit constructor.
37+
InstanceCtorArgs: Val list
38+
39+
/// The reference cell holding the 'this' parameter within the implicit constructor so it can be referenced in the
40+
/// arguments passed to the base constructor
41+
InstanceCtorSafeThisValOpt: Val option
42+
43+
/// Data indicating if safe-initialization checks need to be inserted for this type.
44+
InstanceCtorSafeInitInfo: SafeInitData
45+
46+
/// The value representing the 'base' variable within the implicit instance constructor.
47+
InstanceCtorBaseValOpt: Val option
48+
49+
/// The value representing the 'this' variable within the implicit instance constructor.
50+
InstanceCtorThisVal: Val
51+
52+
/// The name generator used to generate the names of fields etc. within the type.
53+
NameGenerator: NiceNameGenerator
54+
}
55+
56+
/// Indicates how is a 'let' bound value in a class with implicit construction is represented in
57+
/// the TAST ultimately produced by type checking.
58+
type IncrClassValRepr =
59+
60+
// e.g representation for 'let v = 3' if it is not used in anything given a method representation
61+
| InVar of isArg: bool
62+
63+
// e.g representation for 'let v = 3'
64+
| InField of isStatic: bool * staticCountForSafeInit: int * fieldRef: RecdFieldRef
65+
66+
// e.g representation for 'let f x = 3'
67+
| InMethod of isStatic: bool * value: Val * valReprInfo: ValReprInfo
68+
69+
/// IncrClassReprInfo represents the decisions we make about the representation of 'let' and 'do' bindings in a
70+
/// type defined with implicit class construction.
71+
type IncrClassReprInfo =
72+
{
73+
/// Indicates the set of field names taken within one incremental class
74+
TakenFieldNames: Set<string>
75+
76+
RepInfoTcGlobals: TcGlobals
77+
78+
/// vals mapped to representations
79+
ValReprs: Zmap<Val, IncrClassValRepr>
80+
81+
/// vals represented as fields or members from this point on
82+
ValsWithRepresentation: Zset<Val>
83+
}
84+
85+
static member IsMethodRepr: cenv: TcFileState -> bind: Binding -> bool
86+
87+
// Publish the fields of the representation to the type
88+
member PublishIncrClassFields:
89+
cenv: TcFileState *
90+
denv: DisplayEnv *
91+
cpath: CompilationPath *
92+
ctorInfo: IncrClassCtorLhs *
93+
safeStaticInitInfo: SafeInitData ->
94+
unit
95+
96+
/// Given localRep saying how locals have been represented, e.g. as fields.
97+
/// Given an expr under a given thisVal context.
98+
member FixupIncrClassExprPhase2C:
99+
cenv: TcFileState ->
100+
thisValOpt: Val option ->
101+
safeStaticInitInfo: SafeInitData ->
102+
thisTyInst: TypeInst ->
103+
expr: Expr ->
104+
Expr
105+
106+
/// Represents a single group of bindings in a class with an implicit constructor
107+
type IncrClassBindingGroup =
108+
| IncrClassBindingGroup of bindings: Binding list * isStatic: bool * isRecursive: bool
109+
| IncrClassDo of expr: Expr * isStatic: bool * range: Range
110+
111+
type IncrClassConstructionBindingsPhase2C =
112+
| Phase2CBindings of IncrClassBindingGroup list
113+
| Phase2CCtorJustAfterSuperInit
114+
| Phase2CCtorJustAfterLastLet
115+
116+
/// Check and elaborate the "left hand side" of the implicit class construction
117+
/// syntax.
118+
val TcImplicitCtorLhs_Phase2A:
119+
cenv: TcFileState *
120+
env: TcEnv *
121+
tpenv: UnscopedTyparEnv *
122+
tcref: TyconRef *
123+
vis: SynAccess option *
124+
attrs: SynAttribute list *
125+
spats: SynSimplePat list *
126+
thisIdOpt: Ident option *
127+
baseValOpt: Val option *
128+
safeInitInfo: SafeInitData *
129+
m: range *
130+
copyOfTyconTypars: Typar list *
131+
objTy: TType *
132+
thisTy: TType *
133+
xmlDoc: PreXmlDoc ->
134+
IncrClassCtorLhs
135+
136+
/// <summary>
137+
/// Given a set of 'let' bindings (static or not, recursive or not) that make up a class,
138+
/// generate their initialization expression(s).
139+
/// </summary>
140+
/// <param name='cenv'></param>
141+
/// <param name='env'></param>
142+
/// <param name='ctorInfo'>The lhs information about the implicit constructor</param>
143+
/// <param name='inheritsExpr'>The call to the super class constructor</param>
144+
/// <param name='inheritsIsVisible'>Should we place a sequence point at the 'inheritedTys call?</param>
145+
/// <param name='decs'>The declarations</param>
146+
/// <param name='memberBinds'></param>
147+
/// <param name='generalizedTyparsForRecursiveBlock'>Record any unconstrained type parameters generalized for the outer members as "free choices" in the let bindings</param>
148+
/// <param name='safeStaticInitInfo'></param>
149+
val MakeCtorForIncrClassConstructionPhase2C:
150+
cenv: TcFileState *
151+
env: TcEnv *
152+
ctorInfo: IncrClassCtorLhs *
153+
inheritsExpr: Expr *
154+
inheritsIsVisible: bool *
155+
decs: IncrClassConstructionBindingsPhase2C list *
156+
memberBinds: Binding list *
157+
generalizedTyparsForRecursiveBlock: Typar list *
158+
safeStaticInitInfo: SafeInitData ->
159+
Expr * Expr option * Binding list * IncrClassReprInfo

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ open FSharp.Compiler
1717
open FSharp.Compiler.AttributeChecking
1818
open FSharp.Compiler.CheckExpressions
1919
open FSharp.Compiler.CheckDeclarations
20+
open FSharp.Compiler.CheckIncrementalClasses
2021
open FSharp.Compiler.CompilerConfig
2122
open FSharp.Compiler.CompilerImports
2223
open FSharp.Compiler.ConstraintSolver

src/Compiler/FSharp.Compiler.Service.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@
336336
<Compile Include="Checking\CheckPatterns.fs" />
337337
<Compile Include="Checking\CheckComputationExpressions.fsi" />
338338
<Compile Include="Checking\CheckComputationExpressions.fs" />
339+
<Compile Include="Checking\CheckIncrementalClasses.fsi" />
340+
<Compile Include="Checking\CheckIncrementalClasses.fs" />
339341
<Compile Include="Checking\CheckDeclarations.fsi" />
340342
<Compile Include="Checking\CheckDeclarations.fs" />
341343
<Compile Include="Optimize\Optimizer.fsi" />

0 commit comments

Comments
 (0)