@@ -3,12 +3,17 @@ module internal FSharp.Compiler.ReuseTcResults
3
3
open System.Collections .Generic
4
4
open System.IO
5
5
6
+ open FSharp.Compiler .CheckDeclarations
6
7
open FSharp.Compiler .CompilerConfig
7
8
open FSharp.Compiler .Diagnostics
8
9
open FSharp.Compiler .GraphChecking
9
10
open FSharp.Compiler .IO
11
+ open FSharp.Compiler .ParseAndCheckInputs
10
12
open FSharp.Compiler .Syntax
11
13
open FSharp.Compiler .Syntax .PrettyNaming
14
+ open FSharp.Compiler .TypedTree
15
+ open CompilerImports
16
+ open FSharp.Compiler .AbstractIL .IL
12
17
13
18
type TcData =
14
19
{
@@ -139,3 +144,60 @@ type CachingDriver(tcConfig: TcConfig) =
139
144
use _ = Activity.start Activity.Events.reuseTcResultsCacheAbsent []
140
145
writeThisTcData thisTcData
141
146
false
147
+
148
+ member _.ReuseTcResults inputs ( tcInitialState : TcState ) =
149
+
150
+ let bytes = File.ReadAllBytes( " tc" )
151
+ let memory = ByteMemory.FromArray( bytes)
152
+ let byteReaderA () = ReadOnlyByteMemory( memory)
153
+
154
+ let byteReaderB = None
155
+
156
+ let tcInfo =
157
+ GetTypecheckingData(
158
+ " " , // assembly.FileName,
159
+ ILScopeRef.Local, // assembly.ILScopeRef,
160
+ None, //assembly.RawMetadata.TryGetILModuleDef(),
161
+ byteReaderA,
162
+ byteReaderB
163
+ )
164
+
165
+ let rawData = tcInfo.RawData
166
+
167
+ let topAttrs : TopAttribs =
168
+ {
169
+ mainMethodAttrs = rawData.MainMethodAttrs
170
+ netModuleAttrs = rawData.NetModuleAttrs
171
+ assemblyAttrs = rawData.AssemblyAttrs
172
+ }
173
+
174
+ // need to understand if anything can be used here, pickling state is hard
175
+ tcInitialState,
176
+ topAttrs,
177
+ rawData.DeclaredImpls,
178
+ // this is quite definitely wrong, need to figure out what to do with the environment
179
+ tcInitialState.TcEnvFromImpls
180
+
181
+ member _.CacheTcResults ( tcState : TcState , topAttrs : TopAttribs , declaredImpls , tcEnvAtEndOfLastFile , inputs , tcGlobals , outfile ) =
182
+ let thisTcData =
183
+ {
184
+ CmdLine = getThisCompilationCmdLine tcConfig.cmdLineArgs
185
+ Graph = getThisCompilationGraph inputs
186
+ References = getThisCompilationReferences tcConfig.referencedDLLs
187
+ }
188
+
189
+ writeThisTcData thisTcData
190
+
191
+ let tcInfo =
192
+ {
193
+ MainMethodAttrs = topAttrs.mainMethodAttrs
194
+ NetModuleAttrs = topAttrs.netModuleAttrs
195
+ AssemblyAttrs = topAttrs.assemblyAttrs
196
+ DeclaredImpls = declaredImpls
197
+ }
198
+
199
+ let encodedData =
200
+ EncodeTypecheckingData( tcConfig, tcGlobals, tcState.Ccu, outfile, false , tcInfo)
201
+
202
+ let resource = encodedData[ 0 ]. GetBytes() .ToArray()
203
+ File.WriteAllBytes( " tc" , resource)
0 commit comments