Skip to content

Commit 2b158b7

Browse files
committed
Merge branch 'master' of http://github.com/fsharp/FSharp.Compiler.Service into integrate-776
2 parents 53f83b0 + 2637859 commit 2b158b7

File tree

5 files changed

+218
-130
lines changed

5 files changed

+218
-130
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ For more information about the project, see:
1717
Build Status
1818
------------
1919

20-
Head (branch ``master``), Mono 3.x, OSX + unit tests (Travis) [![Build Status](https://travis-ci.org/fsharp/FSharp.Compiler.Service.png?branch=master)](https://travis-ci.org/fsharp/FSharp.Compiler.Service/branches)
20+
Head (branch ``master``), Mono, Linux/OSX + unit tests (Travis) [![Build Status](https://travis-ci.org/fsharp/FSharp.Compiler.Service.png?branch=master)](https://travis-ci.org/fsharp/FSharp.Compiler.Service/branches)
2121

2222
Head (branch ``master``), Windows Server 2012 R2 + unit tests (AppVeyor) [![Build status](https://ci.appveyor.com/api/projects/status/3yllu2qh19brk61d?svg=true)](https://ci.appveyor.com/project/fsgit/fsharp-compiler-service)
2323

docs/content/devnotes.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ and F# interactive as services.
66

77
## Components
88

9-
There is one component, `FSharp.Compiler.Service.dll`. The first one contains minor modifications in visibility
10-
to allow refactoring editing and other tools to have access to the full F# AST and parser.
9+
There is one main component, `FSharp.Compiler.Service.dll`.
1110
The main aim is to have a stable and documented fork of the main compiler that allows various
1211
tools to share this common code.
13-
14-
The second component allows embedding F# Interactive as a service and contains a number of
12+
This component allows embedding F# Interactive as a service and contains a number of
1513
modifications to the source code of `fsi.exe` that adds `EvalExpression` and `EvalInteraction` functions.
1614

1715
This repo should be _identical_ to 'fsharp' except:
@@ -49,13 +47,3 @@ The output will be located in the `bin` directory. If you also wish to build the
4947
and NuGet package, run `build Release` (this also attempts to publish the documentation to
5048
GitHub, which only works if you have access to the GitHub repository).
5149

52-
## Clients
53-
54-
Some of the known tools that use this component are:
55-
56-
* [Fantomas](https://github.com/dungpa/fantomas) - F# code formatting tool
57-
* [Fsharp-Refactor](https://github.com/Lewix/fsharp-refactor) - Refactoring for F#
58-
* [FSharpbinding](https://github.com/fsharp/fsharpbinding) - Xamarin studio bindings
59-
* [F# Snippets web site](http://fssnip.net/) - smart F# pastebin
60-
* [F# ACE Code Editor](https://github.com/BayardRock/FSharpWebIntellisense/) - F# editing on the web
61-

src/fsharp/vs/SimpleServices.fs

Lines changed: 8 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -113,113 +113,6 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices
113113
let checker = InteractiveChecker.Create()
114114
let fileversion = 0
115115
let loadTime = DateTime.Now
116-
117-
let mkCompilationErorHandlers() =
118-
let errors = ResizeArray<_>()
119-
120-
let errorSink warn exn =
121-
let mainError,relatedErrors = SplitRelatedErrors exn
122-
let oneError trim e = errors.Add(ErrorInfo.CreateFromException (e, warn, trim, Range.range0))
123-
oneError false mainError
124-
List.iter (oneError true) relatedErrors
125-
126-
let errorLogger =
127-
{ new ErrorLogger("CompileAPI") with
128-
member x.WarnSinkImpl(exn) = errorSink true exn
129-
member x.ErrorSinkImpl(exn) = errorSink false exn
130-
member x.ErrorCount = errors |> Seq.filter (fun e -> e.Severity = FSharpErrorSeverity.Error) |> Seq.length }
131-
132-
let loggerProvider =
133-
{ new ErrorLoggerProvider() with
134-
member x.CreateErrorLoggerThatQuitsAfterMaxErrors(_tcConfigBuilder, _exiter) = errorLogger }
135-
errors, errorLogger, loggerProvider
136-
137-
let tryCompile errorLogger f =
138-
use unwindParsePhase = PushThreadBuildPhaseUntilUnwind (BuildPhase.Parse)
139-
use unwindEL_2 = PushErrorLoggerPhaseUntilUnwind (fun _ -> errorLogger)
140-
let exiter = { new Exiter with member x.Exit n = raise StopProcessing }
141-
try
142-
f exiter
143-
0
144-
with e ->
145-
stopProcessingRecovery e Range.range0
146-
1
147-
148-
/// Compile using the given flags. Source files names are resolved via the FileSystem API. The output file must be given by a -o flag.
149-
let compileFromArgs (argv: string[], tcImportsCapture, dynamicAssemblyCreator) =
150-
151-
let errors, errorLogger, loggerProvider = mkCompilationErorHandlers()
152-
let result =
153-
tryCompile errorLogger (fun exiter ->
154-
mainCompile (argv, (*bannerAlreadyPrinted*)true, (*openBinariesInMemory*)true, exiter, loggerProvider, tcImportsCapture, dynamicAssemblyCreator) )
155-
156-
errors.ToArray(), result
157-
158-
let compileFromAsts (asts, assemblyName, outFile, dependencies, noframework, pdbFile, executable, tcImportsCapture, dynamicAssemblyCreator) =
159-
160-
let errors, errorLogger, loggerProvider = mkCompilationErorHandlers()
161-
162-
let executable = defaultArg executable true
163-
let target = if executable then CompilerTarget.ConsoleExe else CompilerTarget.Dll
164-
165-
let result =
166-
tryCompile errorLogger (fun exiter ->
167-
compileOfAst ((*openBinariesInMemory=*)true, assemblyName, target, outFile, pdbFile, dependencies, noframework, exiter, loggerProvider, asts, tcImportsCapture, dynamicAssemblyCreator))
168-
169-
errors.ToArray(), result
170-
171-
let dynamicAssemblyCreator (debugInfo: bool, tcImportsRef: TcImports option ref, execute: _ option, assemblyBuilderRef: _ option ref) (_tcConfig,ilGlobals,_errorLogger,outfile,_pdbfile,ilxMainModule,_signingInfo) =
172-
173-
// Create an assembly builder
174-
let assemblyName = System.Reflection.AssemblyName(System.IO.Path.GetFileNameWithoutExtension outfile)
175-
let flags = System.Reflection.Emit.AssemblyBuilderAccess.Run
176-
#if FX_NO_APP_DOMAINS
177-
let assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, flags)
178-
let moduleBuilder = assemblyBuilder.DefineDynamicModule("IncrementalModule")
179-
#else
180-
let assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, flags)
181-
let moduleBuilder = assemblyBuilder.DefineDynamicModule("IncrementalModule", debugInfo)
182-
#endif
183-
// Omit resources in dynamic assemblies, because the module builder is constructed without a filename the module
184-
// is tagged as transient and as such DefineManifestResource will throw an invalid operation if resources are present.
185-
//
186-
// Also, the dynamic assembly creator can't currently handle types called "<Module>" from statically linked assemblies.
187-
let ilxMainModule =
188-
{ ilxMainModule with
189-
TypeDefs = ilxMainModule.TypeDefs.AsList |> List.filter (fun td -> not (isTypeNameForGlobalFunctions td.Name)) |> mkILTypeDefs
190-
Resources=mkILResources [] }
191-
192-
// The function used to resolve typees while emitting the code
193-
let assemblyResolver s =
194-
match tcImportsRef.Value.Value.TryFindExistingFullyQualifiedPathFromAssemblyRef s with
195-
| Some res -> Some (Choice1Of2 res)
196-
| None -> None
197-
198-
// Emit the code
199-
let _emEnv,execs = ILRuntimeWriter.emitModuleFragment(ilGlobals, ILRuntimeWriter.emEnv0, assemblyBuilder, moduleBuilder, ilxMainModule, debugInfo, assemblyResolver)
200-
201-
// Execute the top-level initialization, if requested
202-
if execute.IsSome then
203-
for exec in execs do
204-
match exec() with
205-
| None -> ()
206-
| Some exn -> raise exn
207-
208-
// Register the reflected definitions for the dynamically generated assembly
209-
for resource in ilxMainModule.Resources.AsList do
210-
if IsReflectedDefinitionsResource resource then
211-
Quotations.Expr.RegisterReflectedDefinitions(assemblyBuilder, moduleBuilder.Name, resource.Bytes)
212-
213-
// Save the result
214-
assemblyBuilderRef := Some assemblyBuilder
215-
216-
let setOutputStreams execute =
217-
// Set the output streams, if requested
218-
match execute with
219-
| Some (writer,error) ->
220-
System.Console.SetOut writer
221-
System.Console.SetError error
222-
| None -> ()
223116

224117

225118
/// Tokenize a single line, returning token information and a tokenization state represented by an integer
@@ -278,14 +171,14 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices
278171
checker.ParseAndCheckProject(options)
279172

280173
member x.Compile (argv: string[]) =
281-
compileFromArgs (argv, None, None)
174+
CompileHelpers.compileFromArgs (argv, None, None)
282175

283176
member x.Compile (ast:ParsedInput list, assemblyName:string, outFile:string, dependencies:string list, ?pdbFile:string, ?executable:bool, ?noframework:bool) =
284177
let noframework = defaultArg noframework false
285-
compileFromAsts (ast, assemblyName, outFile, dependencies, noframework, pdbFile, executable, None, None)
178+
CompileHelpers.compileFromAsts (ast, assemblyName, outFile, dependencies, noframework, pdbFile, executable, None, None)
286179

287180
member x.CompileToDynamicAssembly (otherFlags: string[], execute: (TextWriter * TextWriter) option) =
288-
setOutputStreams execute
181+
CompileHelpers.setOutputStreams execute
289182

290183
// References used to capture the results of compilation
291184
let tcImportsRef = ref (None: TcImports option)
@@ -294,10 +187,10 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices
294187

295188
// Function to generate and store the results of compilation
296189
let debugInfo = otherFlags |> Array.exists (fun arg -> arg = "-g" || arg = "--debug:+" || arg = "/debug:+")
297-
let dynamicAssemblyCreator = Some (dynamicAssemblyCreator (debugInfo, tcImportsRef, execute, assemblyBuilderRef))
190+
let dynamicAssemblyCreator = Some (CompileHelpers.dynamicAssemblyCreator (debugInfo, tcImportsRef, execute, assemblyBuilderRef))
298191

299192
// Perform the compilation, given the above capturing function.
300-
let errorsAndWarnings, result = compileFromArgs (otherFlags, tcImportsCapture, dynamicAssemblyCreator)
193+
let errorsAndWarnings, result = CompileHelpers.compileFromArgs (otherFlags, tcImportsCapture, dynamicAssemblyCreator)
301194

302195
// Retrieve and return the results
303196
let assemblyOpt =
@@ -308,7 +201,7 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices
308201
errorsAndWarnings, result, assemblyOpt
309202

310203
member x.CompileToDynamicAssembly (asts:ParsedInput list, assemblyName:string, dependencies:string list, execute: (TextWriter * TextWriter) option, ?debug:bool, ?noframework:bool) =
311-
setOutputStreams execute
204+
CompileHelpers.setOutputStreams execute
312205

313206
// References used to capture the results of compilation
314207
let tcImportsRef = ref (None: TcImports option)
@@ -323,11 +216,11 @@ namespace Microsoft.FSharp.Compiler.SimpleSourceCodeServices
323216
let outFile = Path.Combine(location, assemblyName + ".dll")
324217

325218
// Function to generate and store the results of compilation
326-
let dynamicAssemblyCreator = Some (dynamicAssemblyCreator (debugInfo, tcImportsRef, execute, assemblyBuilderRef))
219+
let dynamicAssemblyCreator = Some (CompileHelpers.dynamicAssemblyCreator (debugInfo, tcImportsRef, execute, assemblyBuilderRef))
327220

328221
// Perform the compilation, given the above capturing function.
329222
let errorsAndWarnings, result =
330-
compileFromAsts (asts, assemblyName, outFile, dependencies, noframework, None, Some execute.IsSome, tcImportsCapture, dynamicAssemblyCreator)
223+
CompileHelpers.compileFromAsts (asts, assemblyName, outFile, dependencies, noframework, None, Some execute.IsSome, tcImportsCapture, dynamicAssemblyCreator)
331224

332225
// Retrieve and return the results
333226
let assemblyOpt =

0 commit comments

Comments
 (0)