Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit160223f

Browse files
authored
Fix some assertions in debug mode (#3010)
WHile fixing #2793 I improved the diagnostics for some assertions and remove some exceptions that were happening on the startup pathI also cleaned up the logic for BinFolderOfDefaultFSharpCompiler a little and take advantage of the fact that optdata/sigdata are gone to simplify some things.
1 parent42b38bf commit160223f

File tree

16 files changed

+138
-146
lines changed

16 files changed

+138
-146
lines changed

‎src/fsharp/CompileOps.fs‎

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
12821282
#if DEBUG
12831283
Printf.bprintf os"\nStack Trace\n%s\n"(exn.ToString())
12841284
if!showAssertForUnexpectedExceptionthen
1285-
System.Diagnostics.Debug.Assert(false,sprintf"Bugseen in compiler:%s"(exn.ToString()))
1285+
System.Diagnostics.Debug.Assert(false,sprintf"Unexpected exceptionseen in compiler:%s\n%s" s(exn.ToString()))
12861286
#endif
12871287
| FullAbstraction(s,_)-> os.Append(FullAbstractionE().Format s)|> ignore
12881288
| WrappedError(exn,_)-> OutputExceptionR os exn
@@ -1413,7 +1413,7 @@ let OutputPhasedErrorR (os:StringBuilder) (err:PhasedDiagnostic) =
14131413
#if DEBUG
14141414
Printf.bprintf os"\nStack Trace\n%s\n"(e.ToString())
14151415
if!showAssertForUnexpectedExceptionthen
1416-
System.Diagnostics.Debug.Assert(false,sprintf"Bug seen in compiler:%s"(e.ToString()))
1416+
System.Diagnostics.Debug.Assert(false,sprintf"Unknown exception seen in compiler:%s"(e.ToString()))
14171417
#endif
14181418
OutputExceptionR os(err.Exception)
14191419

@@ -1627,8 +1627,8 @@ let GetFSharpCoreReferenceUsedByCompiler(useSimpleResolution) =
16271627
if useSimpleResolutionthen
16281628
GetFSharpCoreLibraryName()+".dll"
16291629
else
1630-
letfsCoreName= GetFSharpCoreLibraryName()
16311630
#if FX_RESHAPED_REFLECTION
1631+
letfsCoreName= GetFSharpCoreLibraryName()
16321632
// RESHAPED_REFLECTION does not have Assembly.GetReferencedAssemblies()
16331633
// So use the FSharp.Core.dll from alongside the fsc compiler.
16341634
// This can also be used for the out of gac work on DEV15
@@ -1643,6 +1643,7 @@ let GetFSharpCoreReferenceUsedByCompiler(useSimpleResolution) =
16431643
// FSharp.Compiler.Service.dll
16441644
// assumes for the version of FSharp.Core running in the hosting environment when processing
16451645
// scripts and out-of-project files.
1646+
letfsCoreName= GetFSharpCoreLibraryName()
16461647
letfoundReference=
16471648
match System.Reflection.Assembly.GetEntryAssembly()with
16481649
|null-> None
@@ -1663,23 +1664,8 @@ let GetFSharpCoreReferenceUsedByCompiler(useSimpleResolution) =
16631664
// FSharp.Compiler.Tools nuget package fsc.exe
16641665
// Mono /usr/lib/mono/fsharp/fsc.exe
16651666
//
1666-
// assume a reference to the latest .NET Framework FSharp.Core with which those tools are built, e.g.
1667-
// "FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
1668-
// This is always known to ship as part of an installation of any delivery of the F# Compiler.
1669-
// This reference gets resolved either using the compiler tools directory itself, or using the
1670-
// AssemblyFoldersEx key on Windows, or the /usr/lib/mono/4.5/FSharp.Core.dll on Mono
1671-
// It doesn't get resolved to the GAC.
1672-
//
1673-
// In pretty much all these cases we could probably look directly in the folder where the relevant tool is located.
1674-
// Even in the case of FSharp.LanguageService.Compiler.dll this component is installed into
1675-
// ...Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\FSharp
1676-
// However that DLL can also be in the GAC
1677-
//
1678-
typeof<TypeInThisAssembly>.Assembly.GetReferencedAssemblies()
1679-
|> Array.pick(fun name->
1680-
if name.Name= fsCoreNamethen Some(name.ToString())
1681-
else None
1682-
)
1667+
// assume a reference to the latest .NET Framework FSharp.Core with which those tools are built.
1668+
typeof<list<int>>.Assembly.Location
16831669
#endif
16841670
letGetFsiLibraryName()="FSharp.Compiler.Interactive.Settings"
16851671

@@ -4961,12 +4947,11 @@ module private ScriptPreprocessClosure =
49614947
ParseOneInputLexbuf(tcConfig,lexResourceManager,defines,lexbuf,filename,isLastCompiland,errorLogger)
49624948

49634949
/// Create a TcConfig for load closure starting from a single .fsx file
4964-
letCreateScriptSourceTcConfig(referenceResolver,filename:string,codeContext,useSimpleResolution,useFsiAuxLib,basicReferences,applyCommandLineArgs,assumeDotNetFramework)=
4950+
letCreateScriptSourceTcConfig(referenceResolver,defaultFSharpBinariesDir,filename:string,codeContext,useSimpleResolution,useFsiAuxLib,basicReferences,applyCommandLineArgs,assumeDotNetFramework)=
49654951
letprojectDir= Path.GetDirectoryName(filename)
49664952
letisInteractive=(codeContext= CodeContext.Evaluation)
49674953
letisInvalidationSupported=(codeContext= CodeContext.Editing)
4968-
// always use primary assembly = mscorlib for scripts
4969-
lettcConfigB= TcConfigBuilder.CreateNew(referenceResolver, Internal.Utilities.FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value,true(* optimize for memory*), projectDir, isInteractive, isInvalidationSupported)
4954+
lettcConfigB= TcConfigBuilder.CreateNew(referenceResolver, defaultFSharpBinariesDir,true(* optimize for memory*), projectDir, isInteractive, isInvalidationSupported)
49704955
applyCommandLineArgs tcConfigB
49714956
match basicReferenceswith
49724957
| None-> BasicReferencesForScriptLoadClosure(useSimpleResolution, useFsiAuxLib, assumeDotNetFramework)|> List.iter(fun f->tcConfigB.AddReferencedAssemblyByPath(range0,f))// Add script references
@@ -5133,18 +5118,18 @@ module private ScriptPreprocessClosure =
51335118
result
51345119

51355120
/// Given source text, find the full load closure. Used from service.fs, when editing a script file
5136-
letGetFullClosureOfScriptSource(ctok,referenceResolver,filename,source,codeContext,useSimpleResolution,useFsiAuxLib,lexResourceManager:Lexhelp.LexResourceManager,applyCommmandLineArgs,assumeDotNetFramework)=
5121+
letGetFullClosureOfScriptSource(ctok,referenceResolver,defaultFSharpBinariesDir,filename,source,codeContext,useSimpleResolution,useFsiAuxLib,lexResourceManager:Lexhelp.LexResourceManager,applyCommmandLineArgs,assumeDotNetFramework)=
51375122
// Resolve the basic references such as FSharp.Core.dll first, before processing any #I directives in the script
51385123
//
51395124
// This is tries to mimic the action of running the script in F# Interactive - the initial context for scripting is created
51405125
// first, then #I and other directives are processed.
51415126
letreferences0=
5142-
lettcConfig= CreateScriptSourceTcConfig(referenceResolver, filename, codeContext, useSimpleResolution, useFsiAuxLib, None, applyCommmandLineArgs, assumeDotNetFramework)
5127+
lettcConfig= CreateScriptSourceTcConfig(referenceResolver,defaultFSharpBinariesDir,filename, codeContext, useSimpleResolution, useFsiAuxLib, None, applyCommmandLineArgs, assumeDotNetFramework)
51435128
letresolutions0,_unresolvedReferences= GetAssemblyResolutionInformation(ctok, tcConfig)
51445129
letreferences0= resolutions0|> List.map(fun r->r.originalReference.Range,r.resolvedPath)|> Seq.distinct|> List.ofSeq
51455130
references0
51465131

5147-
lettcConfig= CreateScriptSourceTcConfig(referenceResolver, filename, codeContext, useSimpleResolution, useFsiAuxLib, Some references0, applyCommmandLineArgs, assumeDotNetFramework)
5132+
lettcConfig= CreateScriptSourceTcConfig(referenceResolver,defaultFSharpBinariesDir,filename, codeContext, useSimpleResolution, useFsiAuxLib, Some references0, applyCommmandLineArgs, assumeDotNetFramework)
51485133

51495134
letclosureSources=[ClosureSource(filename,range0,source,true)]
51505135
letclosureFiles,tcConfig= FindClosureFiles(closureSources, tcConfig, codeContext, lexResourceManager)
@@ -5160,9 +5145,9 @@ module private ScriptPreprocessClosure =
51605145

51615146
typeLoadClosurewith
51625147
// Used from service.fs, when editing a script file
5163-
static memberComputeClosureOfSourceText(ctok,referenceResolver,filename:string,source:string,codeContext,useSimpleResolution:bool,useFsiAuxLib,lexResourceManager:Lexhelp.LexResourceManager,applyCommmandLineArgs,assumeDotNetFramework):LoadClosure=
5148+
static memberComputeClosureOfSourceText(ctok,referenceResolver,defaultFSharpBinariesDir,filename:string,source:string,codeContext,useSimpleResolution:bool,useFsiAuxLib,lexResourceManager:Lexhelp.LexResourceManager,applyCommmandLineArgs,assumeDotNetFramework):LoadClosure=
51645149
use unwindBuildPhase= PushThreadBuildPhaseUntilUnwind BuildPhase.Parse
5165-
ScriptPreprocessClosure.GetFullClosureOfScriptSource(ctok, referenceResolver, filename, source, codeContext, useSimpleResolution, useFsiAuxLib, lexResourceManager, applyCommmandLineArgs,assumeDotNetFramework)
5150+
ScriptPreprocessClosure.GetFullClosureOfScriptSource(ctok, referenceResolver,defaultFSharpBinariesDir,filename, source, codeContext, useSimpleResolution, useFsiAuxLib, lexResourceManager, applyCommmandLineArgs,assumeDotNetFramework)
51665151

51675152
/// Used from fsi.fs and fsc.fs, for #load and command line.
51685153
/// The resulting references are then added to a TcConfig.

‎src/fsharp/CompileOps.fsi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ type LoadClosure =
803803
LoadClosureRootFileDiagnostics:(PhasedDiagnostic* bool) list}
804804

805805
// Used from service.fs, when editing a script file
806-
static memberComputeClosureOfSourceText:CompilationThreadToken* referenceResolver: ReferenceResolver.Resolver* filename: string* source: string* implicitDefines:CodeContext* useSimpleResolution: bool* useFsiAuxLib: bool* lexResourceManager: Lexhelp.LexResourceManager* applyCompilerOptions:(TcConfigBuilder-> unit)* assumeDotNetFramework: bool-> LoadClosure
806+
static memberComputeClosureOfSourceText:CompilationThreadToken* referenceResolver: ReferenceResolver.Resolver*defaultFSharpBinariesDir: string*filename: string* source: string* implicitDefines:CodeContext* useSimpleResolution: bool* useFsiAuxLib: bool* lexResourceManager: Lexhelp.LexResourceManager* applyCompilerOptions:(TcConfigBuilder-> unit)* assumeDotNetFramework: bool-> LoadClosure
807807

808808
/// Used from fsi.fs and fsc.fs, for#load and command line. The resulting references are then added to a TcConfig.
809809
static member ComputeClosureOfSourceFiles: CompilationThreadToken* tcConfig:TcConfig*(string* range) list* implicitDefines:CodeContext* lexResourceManager: Lexhelp.LexResourceManager-> LoadClosure

‎src/fsharp/ErrorLogger.fs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,17 @@ module BuildPhaseSubcategory =
184184
[<System.Diagnostics.DebuggerDisplay("{DebugDisplay()}")>]
185185
typePhasedDiagnostic=
186186
{ Exception:exn; Phase:BuildPhase}
187+
187188
/// Construct a phased error
188189
static memberCreate(exn:exn,phase:BuildPhase):PhasedDiagnostic=
189190
#if!COMPILER_SERVICE// TODO: renable this assert in the compiler service
190191
System.Diagnostics.Debug.Assert(phase<>BuildPhase.DefaultPhase, sprintf"Compile error seen with no phase to attribute it to.%A%s%s" phase exn.Message exn.StackTrace)
191192
#endif
192193
{Exception= exn; Phase=phase}
194+
193195
memberthis.DebugDisplay()=
194196
sprintf"%s:%s"(this.Subcategory()) this.Exception.Message
197+
195198
/// This is the textual subcategory to display in error and warning messages (shows only under --vserrors):
196199
///
197200
/// file1.fs(72): subcategory warning FS0072: This is a warning message
@@ -209,6 +212,7 @@ type PhasedDiagnostic =
209212
| IlGen-> BuildPhaseSubcategory.IlGen
210213
| Output-> BuildPhaseSubcategory.Output
211214
| Interactive-> BuildPhaseSubcategory.Interactive
215+
212216
/// Return true if the textual phase given is from the compile part of the build process.
213217
/// This set needs to be equal to the set of subcategories that the language service can produce.
214218
static memberIsSubcategoryOfCompile(subcategory:string)=
@@ -236,6 +240,7 @@ type PhasedDiagnostic =
236240
// if it came from the build and not the language service.
237241
false
238242
/// Return true if this phase is one that's known to be part of the 'compile'. This is the initial phase of the entire compilation that
243+
239244
/// the language service knows about.
240245
memberpe.IsPhaseInCompile()=
241246
letisPhaseInCompile=
@@ -358,6 +363,11 @@ module ErrorLoggerExtensions =
358363
typeErrorLoggerwith
359364

360365
memberx.ErrorR exn=
366+
match exnwith
367+
| InternalError(s,_)
368+
| Failure sas exn-> System.Diagnostics.Debug.Assert(false,sprintf"Unexpected exception raised in compiler:%s\n%s" s(exn.ToString()))
369+
|_->()
370+
361371
match exnwith
362372
| StopProcessing
363373
| ReportedError_-> raise exn

‎src/fsharp/fsc.fs‎

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,12 @@ type ErrorLoggerUpToMaxErrors(tcConfigB: TcConfigBuilder, exiter: Exiter, nameFo
8686

8787
errors<- errors+1
8888

89-
match err.Exceptionwith
90-
| InternalError_
91-
| Failure_
92-
|:? KeyNotFoundException->
93-
match tcConfigB.simulateExceptionwith
94-
| Some_->()// Don't show an assert for simulateException case so that unittests can run without an assert dialog.
95-
| None-> Debug.Assert(false, sprintf"Bug seen in compiler:%s"(err.ToString()))
96-
|_->
97-
()
89+
match err.Exception, tcConfigB.simulateExceptionwith
90+
| InternalError(msg,_), None
91+
| Failure msg, None-> Debug.Assert(false, sprintf"Bug in compiler:%s\n%s" msg(err.Exception.ToString()))
92+
|:? KeyNotFoundException, None-> Debug.Assert(false, sprintf"Lookup exception in compiler:%s"(err.Exception.ToString()))
93+
|_->()
94+
9895
elif ReportWarning(tcConfigB.globalWarnLevel, tcConfigB.specificWarnOff, tcConfigB.specificWarnOn) errthen
9996
x.HandleIssue(tcConfigB, err, isError)
10097

@@ -424,20 +421,7 @@ module XmlDocWriter =
424421
fprintfn os"</doc>"
425422

426423

427-
//----------------------------------------------------------------------------
428-
// DefaultFSharpBinariesDir
429-
//----------------------------------------------------------------------------
430-
431-
letDefaultFSharpBinariesDir=
432-
#if FX_NO_APP_DOMAINS
433-
System.AppContext.BaseDirectory
434-
#else
435-
letexeName= Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.FriendlyName)
436-
Filename.directoryName exeName
437-
#endif
438-
439-
letoutpath outfile extn=
440-
String.concat"."(["out"; Filename.chopExtension(Filename.fileNameOfPath outfile); extn])
424+
letDefaultFSharpBinariesDir= FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(FSharpEnvironment.tryCurrentDomain()).Value
441425

442426
//----------------------------------------------------------------------------
443427
// GenerateInterfaceData, EncodeInterfaceData
@@ -1858,8 +1842,7 @@ let main1(Args (ctok, tcGlobals, tcImports: TcImports, frameworkTcImports, gener
18581842
// set up typecheck for given AST without parsing any command line parameters
18591843
letmain1OfAst(ctok,referenceResolver,openBinariesInMemory,assemblyName,target,outfile,pdbFile,dllReferences,noframework,exiter,errorLoggerProvider:ErrorLoggerProvider,inputs:ParsedInput list)=
18601844

1861-
letdefaultFSharpBinariesDir= Internal.Utilities.FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value
1862-
lettcConfigB= TcConfigBuilder.CreateNew(referenceResolver, defaultFSharpBinariesDir,(*optimizeForMemory*)false, Directory.GetCurrentDirectory(), isInteractive=false, isInvalidationSupported=false)
1845+
lettcConfigB= TcConfigBuilder.CreateNew(referenceResolver, DefaultFSharpBinariesDir,(*optimizeForMemory*)false, Directory.GetCurrentDirectory(), isInteractive=false, isInvalidationSupported=false)
18631846
tcConfigB.openBinariesInMemory<- openBinariesInMemory
18641847
tcConfigB.framework<-not noframework
18651848
// Preset: --optimize+ -g --tailcalls+ (see 4505)

‎src/fsharp/fsi/fsi.fs‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,23 +2467,8 @@ type FsiEvaluationSession (fsi: FsiEvaluationSessionHostConfig, argv:string[], i
24672467
//----------------------------------------------------------------------------
24682468

24692469
letcurrentDirectory= Directory.GetCurrentDirectory()
2470-
letdefaultFSharpBinariesDir=
2471-
#if FX_RESHAPED_REFLECTION
2472-
System.AppContext.BaseDirectory
2473-
#else
2474-
System.AppDomain.CurrentDomain.BaseDirectory
2475-
#endif
2476-
2477-
// When used as part of FCS we cannot assume the current process is fsi.exe
2478-
// So we try to fallback to the default compiler dir.
2479-
letdefaultFSharpBinariesDir=
2480-
letsafeExists f=(try File.Exists(f)with_->false)
2481-
letcontainsRequiredFiles=
2482-
["FSharp.Core.dll";"FSharp.Core.sigdata";"FSharp.Core.optdata"]
2483-
|> Seq.map(fun file-> Path.Combine(defaultFSharpBinariesDir, file))
2484-
|> Seq.forall safeExists
2485-
if containsRequiredFilesthen defaultFSharpBinariesDir
2486-
else Internal.Utilities.FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(None).Value
2470+
2471+
letdefaultFSharpBinariesDir= FSharpEnvironment.BinFolderOfDefaultFSharpCompiler(FSharpEnvironment.tryCurrentDomain()).Value
24872472

24882473
#if COMPILER_SERVICE&&!COMPILER_SERVICE_DLL_VISUAL_STUDIO
24892474
letreferenceResolver= SimulatedMSBuildReferenceResolver.GetBestAvailableResolver(msbuildEnabled)

‎src/fsharp/symbols/Symbols.fs‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,24 +439,28 @@ and FSharpEntity(cenv:cenv, entity:EntityRef) =
439439

440440
memberx.DeclaredInterfaces=
441441
if isUnresolved()then makeReadOnlyCollection[]else
442-
[for tyin GetImmediateInterfacesOfType SkipUnrefInterfaces.Yes cenv.g cenv.amap range0(generalizedTyconRef entity)do
443-
yield FSharpType(cenv, ty)]
442+
ErrorLogger.protectAssemblyExploration[](fun()->
443+
[for tyin GetImmediateInterfacesOfType SkipUnrefInterfaces.Yes cenv.g cenv.amap range0(generalizedTyconRef entity)do
444+
yield FSharpType(cenv, ty)])
444445
|> makeReadOnlyCollection
445446

446447
memberx.AllInterfaces=
447448
if isUnresolved()then makeReadOnlyCollection[]else
448-
[for tyin AllInterfacesOfType cenv.g cenv.amap range0 AllowMultiIntfInstantiations.Yes(generalizedTyconRef entity)do
449-
yield FSharpType(cenv, ty)]
449+
ErrorLogger.protectAssemblyExploration[](fun()->
450+
[for tyin AllInterfacesOfType cenv.g cenv.amap range0 AllowMultiIntfInstantiations.Yes(generalizedTyconRef entity)do
451+
yield FSharpType(cenv, ty)])
450452
|> makeReadOnlyCollection
451453

452454
memberx.IsAttributeType=
453455
if isUnresolved()thenfalseelse
454456
letty= generalizedTyconRef entity
457+
ErrorLogger.protectAssemblyExplorationfalse<|fun()->
455458
Infos.ExistsHeadTypeInEntireHierarchy cenv.g cenv.amap range0 ty cenv.g.tcref_System_Attribute
456459

457460
memberx.IsDisposableType=
458461
if isUnresolved()thenfalseelse
459462
letty= generalizedTyconRef entity
463+
ErrorLogger.protectAssemblyExplorationfalse<|fun()->
460464
Infos.ExistsHeadTypeInEntireHierarchy cenv.g cenv.amap range0 ty cenv.g.tcref_System_IDisposable
461465

462466
memberx.BaseType=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp