Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;

using ILCompiler.DependencyAnalysis;
using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;

namespace ILCompiler
{
public class ReadyToRunSingleAssemblyCompilationModuleGroup : CompilationModuleGroup
{
private HashSet<ModuleDesc> _compilationModuleSet;

public ReadyToRunSingleAssemblyCompilationModuleGroup(TypeSystemContext context, IEnumerable<ModuleDesc> compilationModuleSet)
{
_compilationModuleSet = new HashSet<ModuleDesc>(compilationModuleSet);

// The fake assembly that holds compiler generated types is part of the compilation.
_compilationModuleSet.Add(context.GeneratedAssembly);
}

public sealed override bool ContainsType(TypeDesc type)
{
if (type is EcmaType ecmaType)
{
return IsModuleInCompilationGroup(ecmaType.EcmaModule);
}
if (type is InstantiatedType instantiatedType)
{
return ContainsType(instantiatedType.GetTypeDefinition());
}
return true;
}

public sealed override bool ContainsTypeDictionary(TypeDesc type)
{
return ContainsType(type);
}

public sealed override bool ContainsMethodBody(MethodDesc method, bool unboxingStub)
{
if (method.HasInstantiation)
return true;

return ContainsType(method.OwningType);
}

public sealed override bool ContainsMethodDictionary(MethodDesc method)
{
Debug.Assert(method.GetCanonMethodTarget(CanonicalFormKind.Specific) != method);
return ContainsMethodBody(method, false);
}

public sealed override ExportForm GetExportTypeForm(TypeDesc type)
{
return ExportForm.None;
}

public sealed override ExportForm GetExportTypeFormDictionary(TypeDesc type)
{
return ExportForm.None;
}

public sealed override ExportForm GetExportMethodForm(MethodDesc method, bool unboxingStub)
{
return ExportForm.None;
}

public override ExportForm GetExportMethodDictionaryForm(MethodDesc method)
{
return ExportForm.None;
}

private bool IsModuleInCompilationGroup(EcmaModule module)
{
return _compilationModuleSet.Contains(module);
}

public sealed override bool IsSingleFileCompilation
{
get
{
return false;
}
}

public sealed override bool ShouldReferenceThroughImportTable(TypeDesc type)
{
return false;
}

public override bool CanHaveReferenceThroughImportTable
{
get
{
return false;
}
}

public override bool ShouldProduceFullVTable(TypeDesc type)
{
return ConstructedEETypeNode.CreationAllowed(type);
}

public override bool ShouldPromoteToFullType(TypeDesc type)
{
return ShouldProduceFullVTable(type);
}

public override bool PresenceOfEETypeImpliesAllMethodsOnType(TypeDesc type)
{
return (type.HasInstantiation || type.IsArray) && ShouldProduceFullVTable(type) &&
type.ConvertToCanonForm(CanonicalFormKind.Specific).IsCanonicalSubtype(CanonicalFormKind.Any);
}
}
}
1 change: 1 addition & 0 deletions src/ILCompiler.ReadyToRun/src/ILCompiler.ReadyToRun.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="Compiler\ReadyToRunCodegenCompilationBuilder.cs" />
<Compile Include="Compiler\ReadyToRunCompilerContext.cs" />
<Compile Include="Compiler\ReadyToRunMetadataFieldLayoutAlgorithm.cs" />
<Compile Include="Compiler\ReadyToRunSingleAssemblyCompilationModuleGroup.cs" />
<Compile Include="Compiler\ReadyToRunNodeMangler.cs" />
<Compile Include="JitInterface\CorInfoImpl.ReadyToRun.cs" />
<Compile Include="ObjectWriter\SectionBuilder.cs" />
Expand Down
11 changes: 9 additions & 2 deletions src/ILCompiler/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private int Run(string[] args)
}
}

if (_multiFile)
if (_multiFile || _isReadyToRunCodeGen)
{
List<EcmaModule> inputModules = new List<EcmaModule>();

Expand All @@ -378,7 +378,14 @@ private int Run(string[] args)
inputModules.Add(module);
}

compilationGroup = new MultiFileSharedCompilationModuleGroup(typeSystemContext, inputModules);
if (_isReadyToRunCodeGen)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since multi-file is independent from ready-to-run, please pull the ready-to-run piece up out of the if (_multifile) block.

{
compilationGroup = new ReadyToRunSingleAssemblyCompilationModuleGroup(typeSystemContext, inputModules);
}
else
{
compilationGroup = new MultiFileSharedCompilationModuleGroup(typeSystemContext, inputModules);
}
}
else
{
Expand Down