Skip to content

Commit e5a2957

Browse files
committed
fix 865 - Witness to trait constraint causes throw of TypeInitializationException in Debug build#
1 parent 0174061 commit e5a2957

File tree

19 files changed

+141
-145
lines changed

19 files changed

+141
-145
lines changed

src/absil/il.fsi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,9 +2092,7 @@ type ILPropertyRef =
20922092
member Name: string
20932093
interface System.IComparable
20942094

2095-
#if ENABLE_MONO_SUPPORT
20962095
val runningOnMono: bool
2097-
#endif
20982096

20992097
type ILReferences =
21002098
{ AssemblyReferences: ILAssemblyRef list;

src/absil/ilread.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,11 +3807,9 @@ let rec genOpenBinaryReader infile is opts =
38073807
let pdb = None
38083808
#else
38093809
let pdb =
3810-
#if ENABLE_MONO_SUPPORT
38113810
if runningOnMono then
38123811
None
38133812
else
3814-
#endif
38153813
getPdbReader opts infile
38163814
#endif
38173815

src/fsharp/CompileOps.fs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,9 +1579,9 @@ let OutputErrorOrWarningContext prefix fileLineFn os err =
15791579
let GetFSharpCoreLibraryName () = "FSharp.Core"
15801580

15811581
type internal TypeInThisAssembly = class end
1582-
let GetFSharpCoreReferenceUsedByCompiler(useMonoResolution) =
1582+
let GetFSharpCoreReferenceUsedByCompiler(useSimpleResolution) =
15831583
// On Mono, there is no good reference resolution
1584-
if useMonoResolution then
1584+
if useSimpleResolution then
15851585
GetFSharpCoreLibraryName()+".dll"
15861586
else
15871587
let fsCoreName = GetFSharpCoreLibraryName()
@@ -1698,8 +1698,8 @@ let SystemAssemblies primaryAssemblyName =
16981698
//
16991699
// REVIEW: it isn't clear if there is any negative effect
17001700
// of leaving an assembly off this list.
1701-
let BasicReferencesForScriptLoadClosure(useMonoResolution, useFsiAuxLib) =
1702-
["mscorlib"; GetFSharpCoreReferenceUsedByCompiler(useMonoResolution) ] @ // Need to resolve these explicitly so they will be found in the reference assemblies directory which is where the .xml files are.
1701+
let BasicReferencesForScriptLoadClosure(useSimpleResolution, useFsiAuxLib) =
1702+
["mscorlib"; GetFSharpCoreReferenceUsedByCompiler(useSimpleResolution) ] @ // Need to resolve these explicitly so they will be found in the reference assemblies directory which is where the .xml files are.
17031703
DefaultBasicReferencesForOutOfProjectSources @
17041704
[ if useFsiAuxLib then yield GetFsiLibraryName () ]
17051705

@@ -2011,7 +2011,7 @@ type TcConfigBuilder =
20112011
mutable resolutionAssemblyFoldersConditions : string;
20122012
mutable platform : ILPlatform option;
20132013
mutable prefer32Bit : bool;
2014-
mutable useMonoResolution : bool
2014+
mutable useSimpleResolution : bool
20152015
mutable target : CompilerTarget
20162016
mutable debuginfo : bool
20172017
mutable testFlagEmitFeeFeeAs100001 : bool;
@@ -2176,11 +2176,7 @@ type TcConfigBuilder =
21762176
resolutionAssemblyFoldersConditions = "";
21772177
platform = None;
21782178
prefer32Bit = false;
2179-
#if ENABLE_MONO_SUPPORT
2180-
useMonoResolution = runningOnMono
2181-
#else
2182-
useMonoResolution = false
2183-
#endif
2179+
useSimpleResolution = runningOnMono
21842180
target = ConsoleExe
21852181
debuginfo = false
21862182
testFlagEmitFeeFeeAs100001 = false
@@ -2531,7 +2527,7 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
25312527
match fileNameOpt with
25322528
| None ->
25332529
// if FSharp.Core was not provided explicitly - use version that was referenced by compiler
2534-
AssemblyReference(range0, GetFSharpCoreReferenceUsedByCompiler(data.useMonoResolution), None), None
2530+
AssemblyReference(range0, GetFSharpCoreReferenceUsedByCompiler(data.useSimpleResolution), None), None
25352531
| _ -> res
25362532
let primaryAssemblyCcuInitializer = getSystemRuntimeInitializer data.primaryAssembly (computeKnownDllReference >> fst)
25372533

@@ -2667,7 +2663,7 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
26672663
member x.resolutionAssemblyFoldersConditions = data. resolutionAssemblyFoldersConditions
26682664
member x.platform = data.platform
26692665
member x.prefer32Bit = data.prefer32Bit
2670-
member x.useMonoResolution = data.useMonoResolution
2666+
member x.useSimpleResolution = data.useSimpleResolution
26712667
member x.target = data.target
26722668
member x.debuginfo = data.debuginfo
26732669
member x.testFlagEmitFeeFeeAs100001 = data.testFlagEmitFeeFeeAs100001
@@ -2942,7 +2938,7 @@ type TcConfig private (data : TcConfigBuilder,validate:bool) =
29422938
// NOTE!! if mode=ReportErrors then this method must not raise exceptions. It must just report the errors and recover
29432939
static member TryResolveLibsUsingMSBuildRules (tcConfig:TcConfig,originalReferences:AssemblyReference list, errorAndWarningRange:range, mode:ResolveAssemblyReferenceMode) : AssemblyResolution list * UnresolvedAssemblyReference list =
29442940
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind (BuildPhase.Parameter)
2945-
if tcConfig.useMonoResolution then
2941+
if tcConfig.useSimpleResolution then
29462942
failwith "MSBuild resolution is not supported."
29472943
if originalReferences=[] then [],[]
29482944
else
@@ -3450,7 +3446,7 @@ type TcAssemblyResolutions(results : AssemblyResolution list, unresolved : Unres
34503446

34513447
static member Resolve (tcConfig:TcConfig,assemblyList:AssemblyReference list, knownUnresolved:UnresolvedAssemblyReference list) : TcAssemblyResolutions =
34523448
let resolved,unresolved =
3453-
if tcConfig.useMonoResolution then
3449+
if tcConfig.useSimpleResolution then
34543450
let resolutions =
34553451
assemblyList
34563452
|> List.map (fun assemblyReference ->
@@ -4449,7 +4445,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
44494445
| Some assemblyResolution ->
44504446
ResultD [assemblyResolution]
44514447
| None ->
4452-
if tcConfigP.Get().useMonoResolution then
4448+
if tcConfigP.Get().useSimpleResolution then
44534449
let action =
44544450
match mode with
44554451
| ResolveAssemblyReferenceMode.ReportErrors -> CcuLoadFailureAction.RaiseError
@@ -4857,15 +4853,15 @@ module private ScriptPreprocessClosure =
48574853
ParseOneInputLexbuf (tcConfig,lexResourceManager,defines,lexbuf,filename,isLastCompiland,errorLogger)
48584854

48594855
/// Create a TcConfig for load closure starting from a single .fsx file
4860-
let CreateScriptSourceTcConfig (filename:string, codeContext, useMonoResolution, useFsiAuxLib, basicReferences, applyCommandLineArgs) =
4856+
let CreateScriptSourceTcConfig (filename:string, codeContext, useSimpleResolution, useFsiAuxLib, basicReferences, applyCommandLineArgs) =
48614857
let projectDir = Path.GetDirectoryName(filename)
48624858
let isInteractive = (codeContext = CodeContext.Evaluation)
48634859
let isInvalidationSupported = (codeContext = CodeContext.Editing)
48644860
// always use primary assembly = mscorlib for scripts
48654861
let tcConfigB = TcConfigBuilder.CreateNew(Internal.Utilities.FSharpEnvironment.BinFolderOfDefaultFSharpCompiler.Value, true (* optimize for memory *), projectDir, isInteractive, isInvalidationSupported)
48664862
applyCommandLineArgs tcConfigB
48674863
match basicReferences with
4868-
| None -> BasicReferencesForScriptLoadClosure(useMonoResolution, useFsiAuxLib) |> List.iter(fun f->tcConfigB.AddReferencedAssemblyByPath(range0,f)) // Add script references
4864+
| None -> BasicReferencesForScriptLoadClosure(useSimpleResolution, useFsiAuxLib) |> List.iter(fun f->tcConfigB.AddReferencedAssemblyByPath(range0,f)) // Add script references
48694865
| Some rs -> for m,r in rs do tcConfigB.AddReferencedAssemblyByPath(m,r)
48704866

48714867
tcConfigB.resolutionEnvironment <-
@@ -5026,18 +5022,18 @@ module private ScriptPreprocessClosure =
50265022
result
50275023

50285024
/// Given source text, find the full load closure. Used from service.fs, when editing a script file
5029-
let GetFullClosureOfScriptSource(filename,source,codeContext,useMonoResolution,useFsiAuxLib,lexResourceManager:Lexhelp.LexResourceManager,applyCommmandLineArgs) =
5025+
let GetFullClosureOfScriptSource(filename,source,codeContext,useSimpleResolution,useFsiAuxLib,lexResourceManager:Lexhelp.LexResourceManager,applyCommmandLineArgs) =
50305026
// Resolve the basic references such as FSharp.Core.dll first, before processing any #I directives in the script
50315027
//
50325028
// This is tries to mimic the action of running the script in F# Interactive - the initial context for scripting is created
50335029
// first, then #I and other directives are processed.
50345030
let references0 =
5035-
let tcConfig = CreateScriptSourceTcConfig(filename,codeContext,useMonoResolution,useFsiAuxLib,None,applyCommmandLineArgs)
5031+
let tcConfig = CreateScriptSourceTcConfig(filename,codeContext,useSimpleResolution,useFsiAuxLib,None,applyCommmandLineArgs)
50365032
let resolutions0,_unresolvedReferences = GetAssemblyResolutionInformation(tcConfig)
50375033
let references0 = resolutions0 |> List.map (fun r->r.originalReference.Range,r.resolvedPath) |> Seq.distinct |> List.ofSeq
50385034
references0
50395035

5040-
let tcConfig = CreateScriptSourceTcConfig(filename,codeContext,useMonoResolution,useFsiAuxLib,Some references0,applyCommmandLineArgs)
5036+
let tcConfig = CreateScriptSourceTcConfig(filename,codeContext,useSimpleResolution,useFsiAuxLib,Some references0,applyCommmandLineArgs)
50415037

50425038
let protoClosure = [SourceFile(filename,range0,source)]
50435039
let finalClosure,tcConfig = FindClosureDirectives(protoClosure,tcConfig,codeContext,lexResourceManager)
@@ -5053,9 +5049,9 @@ module private ScriptPreprocessClosure =
50535049

50545050
type LoadClosure with
50555051
// Used from service.fs, when editing a script file
5056-
static member ComputeClosureOfSourceText(filename:string, source:string, codeContext, useMonoResolution:bool, useFsiAuxLib, lexResourceManager:Lexhelp.LexResourceManager, applyCommmandLineArgs) : LoadClosure =
5052+
static member ComputeClosureOfSourceText(filename:string, source:string, codeContext, useSimpleResolution:bool, useFsiAuxLib, lexResourceManager:Lexhelp.LexResourceManager, applyCommmandLineArgs) : LoadClosure =
50575053
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind (BuildPhase.Parse)
5058-
ScriptPreprocessClosure.GetFullClosureOfScriptSource(filename,source,codeContext,useMonoResolution,useFsiAuxLib, lexResourceManager, applyCommmandLineArgs)
5054+
ScriptPreprocessClosure.GetFullClosureOfScriptSource(filename,source,codeContext,useSimpleResolution,useFsiAuxLib, lexResourceManager, applyCommmandLineArgs)
50595055

50605056
/// Used from fsi.fs and fsc.fs, for #load and command line.
50615057
/// The resulting references are then added to a TcConfig.
@@ -5323,7 +5319,7 @@ let TypeCheckSingleInputAndFinishEventually(checkForErrors, tcConfig: TcConfig,
53235319
return TypeCheckMultipleInputsFinish([results],tcState)
53245320
}
53255321

5326-
let TypeCheckClosedInputSetFinish (mimpls, tcState) =
5322+
let TypeCheckClosedInputSetFinish (declaredImpls: TypedImplFile list, tcState) =
53275323
// Publish the latest contents to the CCU
53285324
tcState.tcsCcu.Deref.Contents <- tcState.tcsCcuType
53295325

@@ -5333,12 +5329,11 @@ let TypeCheckClosedInputSetFinish (mimpls, tcState) =
53335329
if not (Zset.contains qualNameOfFile rootImpls) then
53345330
errorR(Error(FSComp.SR.buildSignatureWithoutImplementation(qualNameOfFile.Text), qualNameOfFile.Range)))
53355331

5336-
let tassembly = TAssembly(mimpls)
5337-
tcState, tassembly
5332+
tcState, declaredImpls
53385333

53395334
let TypeCheckClosedInputSet (checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, inputs) =
53405335
// tcEnvAtEndOfLastFile is the environment required by fsi.exe when incrementally adding definitions
53415336
let (tcEnvAtEndOfLastFile, topAttrs, mimpls),tcState = TypeCheckMultipleInputs (checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcState, inputs)
5342-
let tcState,tassembly = TypeCheckClosedInputSetFinish (mimpls, tcState)
5343-
tcState, topAttrs, tassembly, tcEnvAtEndOfLastFile
5337+
let tcState, declaredImpls = TypeCheckClosedInputSetFinish (mimpls, tcState)
5338+
tcState, topAttrs, declaredImpls, tcEnvAtEndOfLastFile
53445339

src/fsharp/CompileOps.fsi

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ type TcConfigBuilder =
273273
mutable resolutionAssemblyFoldersConditions : string
274274
mutable platform : ILPlatform option
275275
mutable prefer32Bit : bool
276-
mutable useMonoResolution : bool
276+
mutable useSimpleResolution : bool
277277
mutable target : CompilerTarget
278278
mutable debuginfo : bool
279279
mutable testFlagEmitFeeFeeAs100001 : bool
@@ -425,7 +425,7 @@ type TcConfig =
425425
member resolutionAssemblyFoldersConditions : string
426426
member platform : ILPlatform option
427427
member prefer32Bit : bool
428-
member useMonoResolution : bool
428+
member useSimpleResolution : bool
429429
member target : CompilerTarget
430430
member debuginfo : bool
431431
member testFlagEmitFeeFeeAs100001 : bool
@@ -594,7 +594,7 @@ type TcImports =
594594
member GetCcusExcludingBase : unit -> CcuThunk list
595595
member FindDllInfo : range * string -> ImportedBinary
596596
member TryFindDllInfo : range * string * lookupOnly: bool -> option<ImportedBinary>
597-
member FindCcuFromAssemblyRef : range * ILAssemblyRef -> Tast.CcuResolutionResult
597+
member FindCcuFromAssemblyRef : range * ILAssemblyRef -> CcuResolutionResult
598598
#if EXTENSIONTYPING
599599
member ProviderGeneratedTypeRoots : ProviderGeneratedType list
600600
#endif
@@ -661,8 +661,7 @@ val ProcessMetaCommandsFromInput :
661661
val ApplyMetaCommandsFromInputToTcConfig : TcConfig -> (Ast.ParsedInput * string) -> TcConfig
662662

663663
/// Process the #nowarn in an input
664-
val ApplyNoWarnsToTcConfig : TcConfig -> (Ast.ParsedInput*string) -> TcConfig
665-
664+
val ApplyNoWarnsToTcConfig : TcConfig -> (Ast.ParsedInput * string) -> TcConfig
666665

667666
//----------------------------------------------------------------------------
668667
// Scoped pragmas
@@ -717,23 +716,21 @@ val GetInitialTcState :
717716
/// Check one input, returned as an Eventually computation
718717
val TypeCheckOneInputEventually :
719718
(unit -> bool) * TcConfig * TcImports * TcGlobals * Ast.LongIdent option * NameResolution.TcResultsSink * TcState * Ast.ParsedInput
720-
-> Eventually<(TcEnv * TopAttribs * Tast.TypedImplFile list) * TcState>
719+
-> Eventually<(TcEnv * TopAttribs * TypedImplFile list) * TcState>
721720

722721
/// Finish the checking of multiple inputs
723722
val TypeCheckMultipleInputsFinish : (TcEnv * TopAttribs * 'T list) list * TcState -> (TcEnv * TopAttribs * 'T list) * TcState
724723
725724
/// Finish the checking of a closed set of inputs
726-
val TypeCheckClosedInputSetFinish : TypedImplFile list * TcState -> TcState * TypedAssembly
725+
val TypeCheckClosedInputSetFinish : TypedImplFile list * TcState -> TcState * TypedImplFile list
727726

728727
/// Check a closed set of inputs
729-
val TypeCheckClosedInputSet :
730-
(unit -> bool) * TcConfig * TcImports * TcGlobals * Ast.LongIdent option * TcState * Ast.ParsedInput list
731-
-> TcState * TopAttribs * Tast.TypedAssembly * TcEnv
728+
val TypeCheckClosedInputSet :(unit -> bool) * TcConfig * TcImports * TcGlobals * Ast.LongIdent option * TcState * Ast.ParsedInput list -> TcState * TopAttribs * TypedImplFile list * TcEnv
732729

733730
/// Check a single input and finish the checking
734731
val TypeCheckSingleInputAndFinishEventually :
735732
(unit -> bool) * TcConfig * TcImports * TcGlobals * Ast.LongIdent option * NameResolution.TcResultsSink * TcState * Ast.ParsedInput
736-
-> Eventually<(TcEnv * TopAttribs * Tast.TypedImplFile list) * TcState>
733+
-> Eventually<(TcEnv * TopAttribs * TypedImplFile list) * TcState>
737734

738735
/// Indicates if we should report a warning
739736
val ReportWarning : globalWarnLevel: int * specificWarnOff: int list * specificWarnOn: int list -> PhasedError -> bool
@@ -775,7 +772,7 @@ type LoadClosure =
775772
RootWarnings : PhasedError list }
776773

777774
// Used from service.fs, when editing a script file
778-
static member ComputeClosureOfSourceText : filename: string * source: string * implicitDefines:CodeContext * useMonoResolution: bool * useFsiAuxLib: bool * lexResourceManager: Lexhelp.LexResourceManager * applyCompilerOptions: (TcConfigBuilder -> unit) -> LoadClosure
775+
static member ComputeClosureOfSourceText : filename: string * source: string * implicitDefines:CodeContext * useSimpleResolution: bool * useFsiAuxLib: bool * lexResourceManager: Lexhelp.LexResourceManager * applyCompilerOptions: (TcConfigBuilder -> unit) -> LoadClosure
779776

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

0 commit comments

Comments
 (0)