Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Synchronization bug in ILPreTypeDefImpl #17803

Closed
@majocha

Description

@majocha

Stack trace obtained under multithreaded test run:

[xUnit.net 00:00:01.02]     FSharp.Compiler.UnitTests.SpanTests.Script_ReadOnlySpanForInDo [FAIL]
[xUnit.net 00:00:01.02]       System.Exception : Error creating evaluation session: System.AggregateException: One or more errors occurred. (Value cannot be null.)
[xUnit.net 00:00:01.02]        ---> System.ArgumentNullException: Value cannot be null.
[xUnit.net 00:00:01.02]          at System.Threading.Monitor.Enter(Object obj)
[xUnit.net 00:00:01.02]          at FSharp.Compiler.AbstractIL.IL.ILPreTypeDefImpl.FSharp.Compiler.AbstractIL.IL.ILPreTypeDef.GetTypeDef() in E:\repos\fsharp\src\Compiler\AbstractIL\il.fs:line 2927
[xUnit.net 00:00:01.02]          at [email protected](Tuple`2 tupledArg) in E:\repos\fsharp\src\Compiler\Checking\import.fs:line 731
[xUnit.net 00:00:01.02]          at FSharp.Compiler.Import.multisetDiscriminateAndMap[Key,Value,a](FSharpFunc`2 nodef, FSharpFunc`2 tipf, FSharpList`1 items) in E:\repos\fsharp\src\Compiler\Checking\import.fs:line 689
[xUnit.net 00:00:01.02]          at FSharp.Compiler.Import.ImportILTypeDefList(FSharpFunc`2 amap, Range m, CompilationPath cpath, FSharpList`1 enc, FSharpList`1 items) in E:\repos\fsharp\src\Compiler\Checking\import.fs:line 724
[xUnit.net 00:00:01.02]          at [email protected](Unit _arg2) in E:\repos\fsharp\src\Compiler\Checking\import.fs:line 727
[xUnit.net 00:00:01.02]          at Internal.Utilities.Library.InterruptibleLazy`1.get_Value() in E:\repos\fsharp\src\Compiler\Utilities\illib.fs:line 33
[xUnit.net 00:00:01.02]          at Internal.Utilities.Library.Extras.MaybeLazy`1.Force() in E:\repos\fsharp\src\Compiler\Utilities\lib.fs:line 396
[xUnit.net 00:00:01.02]          at FSharp.Compiler.CompilerImports.TcImports.ccuHasType(CcuThunk ccu, FSharpList`1 nsname, String tname, Boolean publicOnly) in E:\repos\fsharp\src\Compiler\Driver\CompilerImports.fs:line 1296
[xUnit.net 00:00:01.02]          at FSharp.Compiler.CompilerImports.TcImports.tryFindSysTypeCcu@2596-1.Invoke(CcuThunk ccu) in E:\repos\fsharp\src\Compiler\Driver\CompilerImports.fs:line 2596
[xUnit.net 00:00:01.02]          at Microsoft.FSharp.Collections.ArrayModule.loop@1144-40[T](FSharpFunc`2 predicate, T[] array, Int32 i) in E:\repos\fsharp\src\FSharp.Core\array.fs:line 1147
[xUnit.net 00:00:01.02]          at Microsoft.FSharp.Collections.ArrayModule.TryFind[T](FSharpFunc`2 predicate, T[] array) in E:\repos\fsharp\src\FSharp.Core\array.fs:line 1152
[xUnit.net 00:00:01.02]          at FSharp.Compiler.TcGlobals.TcGlobals.tryFindSysTypeCcu(FSharpList`1 path, String nm) in E:\repos\fsharp\src\Compiler\TypedTree\TcGlobals.fs:line 216
[xUnit.net 00:00:01.02]          at FSharp.Compiler.TcGlobals.TcGlobals.tryFindSysAttrib(String nm) in E:\repos\fsharp\src\Compiler\TypedTree\TcGlobals.fs:line 320
[xUnit.net 00:00:01.02]          at FSharp.Compiler.TcGlobals.TcGlobals..ctor(Boolean compilingFSharpCore, ILGlobals ilg, CcuThunk fslibCcu, String directoryToResolveRelativePaths, Boolean mlCompatibility, Boolean isInteractive, Boolean checkNullness, Boolean useReflectionFreeCodeGen, FSharpFunc`2 tryFindSysTypeCcuHelper, Boolean emitDebugInfoInQuotations, Boolean noDebugAttributes, PathMap pathMap, LanguageVersion langVersion, Boolean realsig) in E:\repos\fsharp\src\Compiler\TypedTree\TcGlobals.fs:line 1079
[xUnit.net 00:00:01.02]          at FSharp.Compiler.CompilerImports.TcImports.BuildFrameworkTcImports@2589-10.Invoke(FSharpList`1 _arg10) in E:\repos\fsharp\src\Compiler\Driver\CompilerImports.fs:line 2602
[xUnit.net 00:00:01.02]          at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in E:\repos\fsharp\src\FSharp.Core\async.fs:line 528
[xUnit.net 00:00:01.02]          at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in E:\repos\fsharp\src\FSharp.Core\async.fs:line 112
[xUnit.net 00:00:01.02]          --- End of inner exception stack trace ---
[xUnit.net 00:00:01.02]          at Internal.Utilities.Library.PervasiveAutoOpens.Async.RunImmediate.Static[T](FSharpAsync`1 computation, FSharpOption`1 cancellationToken) in E:\repos\fsharp\src\Compiler\Utilities\illib.fs:line 151
[xUnit.net 00:00:01.02]          at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession..ctor(FsiEvaluationSessionHostConfig fsi, String[] argv, TextReader inReader, TextWriter outWriter, TextWriter errorWriter, Boolean fsiCollectible, FSharpOption`1 legacyReferenceResolver) in E:\repos\fsharp\src\Compiler\Interactive\fsi.fs:line 4673
[xUnit.net 00:00:01.02]       Stack Trace:
[xUnit.net 00:00:01.02]            at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1448.Invoke(String message)
[xUnit.net 00:00:01.02]         E:\repos\fsharp\src\Compiler\Interactive\fsi.fs(4676,0): at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession..ctor(FsiEvaluationSessionHostConfig fsi, String[] argv, TextReader inReader, TextWriter outWriter, TextWriter errorWriter, Boolean fsiCollectible, FSharpOption`1 legacyReferenceResolver)
[xUnit.net 00:00:01.02]         E:\repos\fsharp\src\Compiler\Interactive\fsi.fs(5007,0): at FSharp.Compiler.Interactive.Shell.FsiEvaluationSession.Create(FsiEvaluationSessionHostConfig fsiConfig, String[] argv, TextReader inReader, TextWriter outWriter, TextWriter errorWriter, FSharpOption`1 collectible, FSharpOption`1 legacyReferenceResolver)
[xUnit.net 00:00:01.02]         E:\repos\fsharp\tests\FSharp.Test.Utilities\CompilerAssert.fs(1004,0): at FSharp.Test.CompilerAssert.RunScriptWithOptionsAndReturnResult(String[] options, String source)
[xUnit.net 00:00:01.02]         E:\repos\fsharp\tests\FSharp.Test.Utilities\CompilerAssert.fs(1019,0): at FSharp.Test.CompilerAssert.RunScriptWithOptions(String[] options, String source, FSharpList`1 expectedErrorMessages)
[xUnit.net 00:00:01.02]         E:\repos\fsharp\tests\FSharp.Test.Utilities\CompilerAssert.fs(1029,0): at FSharp.Test.CompilerAssert.RunScript(String source, FSharpList`1 expectedErrorMessages)
[xUnit.net 00:00:01.02]         E:\repos\fsharp\tests\fsharp\Compiler\Language\SpanTests.fs(91,0): at FSharp.Compiler.UnitTests.SpanTests.Script_ReadOnlySpanForInDo()
[xUnit.net 00:00:01.02]            at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
[xUnit.net 00:00:01.02]            at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
[xUnit.net 00:00:05.32]       failing on main

The code in question:

/// This is a memory-critical class. Very many of these objects get allocated and held to represent the contents of .NET assemblies.
and [<Sealed>] ILPreTypeDefImpl(nameSpace: string list, name: string, metadataIndex: int32, storage: ILTypeDefStored) =
let mutable store: ILTypeDef = Unchecked.defaultof<_>
let mutable storage = storage
interface ILPreTypeDef with
member _.Namespace = nameSpace
member _.Name = name
member x.GetTypeDef() =
match box store with
| null ->
let syncObj = storage
Monitor.Enter(syncObj)
try
match box store with
| null ->
let value =
match storage with
| ILTypeDefStored.Given td -> td
| ILTypeDefStored.Computed f -> f ()
| ILTypeDefStored.Reader f -> f metadataIndex
store <- value
storage <- Unchecked.defaultof<_>
value
| _ -> store
finally
Monitor.Exit(syncObj)
| _ -> store

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilerCompiler-related issues which don't belong to other categoriesBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions