Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback lookup for assemblies from loaded from memory #466

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Compiler/Infer/ModelCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ public IAlgorithm Algorithm
/// </remarks>
public CompilerChoice CompilerChoice { get; set; } = CompilerChoice.Auto;

#if ROSLYN
/// <summary>
/// Resolves reference to assembly for Roslyn.
/// </summary>
public Func<Assembly, byte[]> ReferenceResolver;
#endif

private bool useParallelForLoops = false;

/// <summary>
Expand Down Expand Up @@ -822,7 +829,8 @@ internal T CompileWithoutParams<T>(List<ITypeDeclaration> itds)
includeDebugInformation = IncludeDebugInformation,
optimizeCode = !IncludeDebugInformation, // tie these together for now
showProgress = ShowProgress,
compilerChoice = CompilerChoice
compilerChoice = CompilerChoice,
ReferenceResolver = ReferenceResolver,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs #if ROSLYN

};
CompilerResults cr = cc.WriteAndCompile(itds);
// Examine the compilation results and stop if errors
Expand Down
25 changes: 24 additions & 1 deletion src/Compiler/TransformFramework/CodeTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ public class CodeCompiler
/// </summary>
public CompilerChoice compilerChoice = CompilerChoice.Auto;

#if ROSLYN
/// <summary>
/// Resolves reference for Roslyn
/// </summary>
public Func<Assembly, byte[]> ReferenceResolver;
#endif
public List<string> WriteSource(List<ITypeDeclaration> typeDeclarations, IList<string> filenames, out ICollection<Assembly> referencedAssemblies)
{
Stopwatch watch = null;
Expand Down Expand Up @@ -449,7 +455,24 @@ private CompilerResults CompileWithRoslyn(List<string> filenames, List<string> s
{
try
{
references.Add(MetadataReference.CreateFromFile(assembly.Location));
MetadataReference metadataReference;
if (assembly.Location == "" && ReferenceResolver != null)
{
var bytes = ReferenceResolver(assembly);
if (bytes is null)
{
// do nothing - this assembly does not have a location e.g. it is in memory
continue;
}

metadataReference = MetadataReference.CreateFromImage(bytes);
}
else
{
metadataReference = MetadataReference.CreateFromFile(assembly.Location);
}

references.Add(metadataReference);
}
catch (NotSupportedException)
{
Expand Down