You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
Recently, we tried to make a performance optimization on iqsharp to call the codegen asynchronously as we might have multiple block of files (one per snippet) that needs to be compiled. The code can be seen here. In essence:
foreach (var file in allSources)
{
trees.Add(Task.Run(() =>
{
var codegenContext = string.IsNullOrEmpty(executionTarget)
? CodegenContext.Create(qsCompilation.Namespaces)
: CodegenContext.Create(qsCompilation.Namespaces, new Dictionary<string, string>() { { AssemblyConstants.ExecutionTarget, executionTarget } });
var code = SimulationCode.generate(file, codegenContext);
return CSharpSyntaxTree.ParseText(code, encoding: UTF8Encoding.UTF8);
}));
}
Unfortunately, we started getting random compilation errors as internal variable names like __arg1__ got reused. The problem is that the code in SimulationCode.fs is not thread-safe. In particular there is a count static variable (line 247 that gets reset when a new Specialization is started (line 1015)[https://github.com/microsoft/qsharp-compiler/blob/main/src/QsCompiler/CSharpGeneration/SimulationCode.fs#L1015]
Expected behavior
That calling SimulationCode.generate is thread-safe.
I believe count is actually the only static variable so we should put that into the context and make sure everything is thread-safe. Most of the work is probably going to be in writing some unittests to gate this behavior.
The text was updated successfully, but these errors were encountered:
Describe the bug
Recently, we tried to make a performance optimization on iqsharp to call the codegen asynchronously as we might have multiple block of files (one per snippet) that needs to be compiled. The code can be seen here. In essence:
Unfortunately, we started getting random compilation errors as internal variable names like
__arg1__
got reused. The problem is that the code in SimulationCode.fs is not thread-safe. In particular there is acount
static variable (line 247 that gets reset when a new Specialization is started (line 1015)[https://github.com/microsoft/qsharp-compiler/blob/main/src/QsCompiler/CSharpGeneration/SimulationCode.fs#L1015]Expected behavior
That calling
SimulationCode.generate
is thread-safe.I believe
count
is actually the only static variable so we should put that into thecontext
and make sure everything is thread-safe. Most of the work is probably going to be in writing some unittests to gate this behavior.The text was updated successfully, but these errors were encountered: