Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ILCompiler.DependencyAnalysis
{
public interface INativeFormatTypeReferenceProvider
{
internal Vertex EncodeReferenceToType(NativeWriter writer, TypeDesc type);
internal Vertex EncodeReferenceToType(NativeWriter writer, TypeDesc type, ModuleDesc module);
internal Vertex EncodeReferenceToMethod(NativeWriter writer, MethodDesc method);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section se
foreach ((string key, TypeDesc type) in entries)
{
Vertex keyVertex = writer.GetStringConstant(key);
Vertex valueVertex = externalReferences.EncodeReferenceToType(writer, type);
Vertex valueVertex = externalReferences.EncodeReferenceToType(writer, type, null);
Vertex entry = writer.GetTuple(keyVertex, valueVertex);
typeMapHashTable.Append((uint)TypeHashingAlgorithms.ComputeNameHashCode(key), section.Place(entry));
}

Vertex typeMapStateVertex = writer.GetUnsignedConstant(1); // Valid type map state
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup);
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup, null);
Vertex tuple = writer.GetTuple(typeMapGroupVertex, typeMapStateVertex, typeMapHashTable);
return section.Place(tuple);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section se

foreach ((TypeDesc key, TypeDesc type) in entries)
{
Vertex keyVertex = externalReferences.EncodeReferenceToType(writer, key);
Vertex valueVertex = externalReferences.EncodeReferenceToType(writer, type);
Vertex keyVertex = externalReferences.EncodeReferenceToType(writer, key, null);
Vertex valueVertex = externalReferences.EncodeReferenceToType(writer, type, null);
Vertex entry = writer.GetTuple(keyVertex, valueVertex);
typeMapHashTable.Append((uint)key.GetHashCode(), section.Place(entry));
}

Vertex typeMapStateVertex = writer.GetUnsignedConstant(1); // Valid type map state
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup);
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup, null);
Vertex tuple = writer.GetTuple(typeMapGroupVertex, typeMapStateVertex, typeMapHashTable);
return section.Place(tuple);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section se
foreach ((string key, IEETypeNode valueNode) in GetMarkedEntries(factory))
{
Vertex keyVertex = writer.GetStringConstant(key);
Vertex valueVertex = externalReferences.EncodeReferenceToType(writer, valueNode.Type);
Vertex valueVertex = externalReferences.EncodeReferenceToType(writer, valueNode.Type, null);
Vertex entry = writer.GetTuple(keyVertex, valueVertex);
typeMapHashTable.Append((uint)TypeHashingAlgorithms.ComputeNameHashCode(key), section.Place(entry));
}

Vertex typeMapStateVertex = writer.GetUnsignedConstant(1); // Valid type map state
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup);
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup, null);
Vertex tuple = writer.GetTuple(typeMapGroupVertex, typeMapStateVertex, typeMapHashTable);
return section.Place(tuple);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section section, INativeFormatTypeReferenceProvider externalReferences)
{
Vertex typeMapStateVertex = writer.GetUnsignedConstant(0); // Invalid type map state
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup);
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup, null);
Vertex throwingMethodStubVertex = externalReferences.EncodeReferenceToMethod(writer, ThrowingMethodStub);
Vertex tuple = writer.GetTuple(typeMapGroupVertex, typeMapStateVertex, throwingMethodStubVertex);
return section.Place(tuple);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section section, INativeFormatTypeReferenceProvider externalReferences)
{
Vertex typeMapStateVertex = writer.GetUnsignedConstant(0); // Invalid type map state
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup);
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup, null);
Vertex throwingMethodStubVertex = externalReferences.EncodeReferenceToMethod(writer, ThrowingMethodStub);
Vertex tuple = writer.GetTuple(typeMapGroupVertex, typeMapStateVertex, throwingMethodStubVertex);
return section.Place(tuple);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ private sealed class ExternalReferencesTableIndex(ExternalReferencesTableNode ta
{
public Vertex EncodeReferenceToMethod(NativeWriter writer, MethodDesc method)
=> writer.GetUnsignedConstant(table.GetIndex(factory.MethodEntrypoint(method)));
public Vertex EncodeReferenceToType(NativeWriter writer, TypeDesc type)
public Vertex EncodeReferenceToType(NativeWriter writer, TypeDesc type, ModuleDesc module)
=> writer.GetUnsignedConstant(table.GetIndex(factory.NecessaryTypeSymbol(type)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section se

foreach ((IEETypeNode keyNode, IEETypeNode valueNode) in GetMarkedEntries(factory))
{
Vertex keyVertex = externalReferences.EncodeReferenceToType(writer, keyNode.Type);
Vertex valueVertex = externalReferences.EncodeReferenceToType(writer, valueNode.Type);
Vertex keyVertex = externalReferences.EncodeReferenceToType(writer, keyNode.Type, null);
Vertex valueVertex = externalReferences.EncodeReferenceToType(writer, valueNode.Type, null);
Vertex entry = writer.GetTuple(keyVertex, valueVertex);
typeMapHashTable.Append((uint)keyNode.Type.GetHashCode(), section.Place(entry));
}

Vertex typeMapStateVertex = writer.GetUnsignedConstant(1); // Valid type map state
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup);
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup, null);
Vertex tuple = writer.GetTuple(typeMapGroupVertex, typeMapStateVertex, typeMapHashTable);
return section.Place(tuple);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;

using ILCompiler.DependencyAnalysis.ReadyToRun;
using ILCompiler.ReadyToRun;
using Internal.TypeSystem;
using Internal.NativeFormat;
using Internal.ReadyToRunConstants;
Expand All @@ -15,9 +16,15 @@ namespace ILCompiler.DependencyAnalysis
public sealed class ImportReferenceProvider : INativeFormatTypeReferenceProvider
{
private ReadyToRunSymbolNodeFactory _symbolNodeFactory;
private ExternalReferenceTokenManager _externalReferenceTokenManager;

public Import GetImportToType(TypeDesc type)
public Import GetImportToType(TypeDesc type, ModuleDesc moduleRequiringImport = null)
{
if (moduleRequiringImport is not null)
{
_externalReferenceTokenManager.EnsureDefTokensAreAvailable(type, moduleRequiringImport, referencesAreForAsyncMethod: false);
}

return _symbolNodeFactory.CreateReadyToRunHelper(ReadyToRunHelperId.TypeHandle, type);
}

Expand All @@ -27,9 +34,10 @@ public Import GetImportToModule(ModuleDesc module)
return _symbolNodeFactory.ModuleLookup((IEcmaModule)module);
}

public void Initialize(ReadyToRunSymbolNodeFactory symbolNodeFactory)
internal void Initialize(ReadyToRunSymbolNodeFactory symbolNodeFactory, ExternalReferenceTokenManager externalReferenceTokenManager)
{
_symbolNodeFactory = symbolNodeFactory;
_externalReferenceTokenManager = externalReferenceTokenManager;
}

internal Vertex EncodeReferenceToModule(NativeWriter writer, ModuleDesc module)
Expand All @@ -38,13 +46,14 @@ internal Vertex EncodeReferenceToModule(NativeWriter writer, ModuleDesc module)
return writer.GetTuple(writer.GetUnsignedConstant((uint)typeImport.Table.IndexFromBeginningOfArray), writer.GetUnsignedConstant((uint)typeImport.IndexFromBeginningOfArray));
}

internal Vertex EncodeReferenceToType(NativeWriter writer, TypeDesc type)
internal Vertex EncodeReferenceToType(NativeWriter writer, TypeDesc type, ModuleDesc module)
{
Import typeImport = GetImportToType(type);
Debug.Assert(module is not null);
Import typeImport = GetImportToType(type, module);
return writer.GetTuple(writer.GetUnsignedConstant((uint)typeImport.Table.IndexFromBeginningOfArray), writer.GetUnsignedConstant((uint)typeImport.IndexFromBeginningOfArray));
}

Vertex INativeFormatTypeReferenceProvider.EncodeReferenceToMethod(NativeWriter writer, MethodDesc method) => throw new NotImplementedException();
Vertex INativeFormatTypeReferenceProvider.EncodeReferenceToType(NativeWriter writer, TypeDesc type) => EncodeReferenceToType(writer, type);
Vertex INativeFormatTypeReferenceProvider.EncodeReferenceToType(NativeWriter writer, TypeDesc type, ModuleDesc module) => EncodeReferenceToType(writer, type, module);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,13 @@ internal ReadyToRunCodegenCompilation(
_customPESectionAlignment = customPESectionAlignment;
_format = format;
SymbolNodeFactory = new ReadyToRunSymbolNodeFactory(nodeFactory, verifyTypeAndFieldLayout);
_tokenManager = new ExternalReferenceTokenManager(_nodeFactory.ManifestMetadataTable._mutableModule, _nodeFactory.Resolver);
if (nodeFactory.InstrumentationDataTable != null)
nodeFactory.InstrumentationDataTable.Initialize(SymbolNodeFactory);
if (nodeFactory.CrossModuleInlningInfo != null)
nodeFactory.CrossModuleInlningInfo.Initialize(SymbolNodeFactory);
if (nodeFactory.ImportReferenceProvider != null)
nodeFactory.ImportReferenceProvider.Initialize(SymbolNodeFactory);
nodeFactory.ImportReferenceProvider.Initialize(SymbolNodeFactory, _tokenManager);
_inputFiles = inputFiles;
_compositeRootPath = compositeRootPath;
_printReproInstructions = printReproInstructions;
Expand All @@ -393,7 +394,6 @@ internal ReadyToRunCodegenCompilation(
_profileData = profileData;

_fileLayoutOptimizer = new FileLayoutOptimizer(logger, methodLayoutAlgorithm, fileLayoutAlgorithm, profileData, _nodeFactory);
_tokenManager = new ExternalReferenceTokenManager(_nodeFactory.ManifestMetadataTable._mutableModule, _nodeFactory.Resolver);
}

private readonly static string s_folderUpPrefix = ".." + Path.DirectorySeparatorChar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override int CompareToImpl(ISortableNode other, CompilerComparer comparer

public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section section, INativeFormatTypeReferenceProvider externalReferences)
{
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup);
Vertex typeMapGroupVertex = externalReferences.EncodeReferenceToType(writer, TypeMapGroup, TriggeringModule);
if (map.ThrowingMethodStub is not null)
{
// We don't write out the throwing method stub for R2R
Expand All @@ -56,7 +56,7 @@ public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section se
foreach ((string key, (TypeDesc type, _)) in map.TypeMap)
{
Vertex keyVertex = writer.GetStringConstant(key);
Vertex valueVertex = externalReferences.EncodeReferenceToType(writer, type);
Vertex valueVertex = externalReferences.EncodeReferenceToType(writer, type, TriggeringModule);
Vertex entry = writer.GetTuple(keyVertex, valueVertex);
typeMapHashTable.Append((uint)VersionResilientHashCode.NameHashCode(Encoding.UTF8.GetBytes(key)), typeMapEntriesSection.Place(entry));
}
Expand All @@ -69,7 +69,7 @@ public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section se
public override IEnumerable<CombinedDependencyListEntry> GetConditionalStaticDependencies(NodeFactory context) => [];
public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory context)
{
yield return new DependencyListEntry(importProvider.GetImportToType(TypeMapGroup), $"Type map '{TypeMapGroup}' key type");
yield return new DependencyListEntry(importProvider.GetImportToType(TypeMapGroup, TriggeringModule), $"Type map '{TypeMapGroup}' key type");

if (map.ThrowingMethodStub is not null)
{
Expand All @@ -78,7 +78,7 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto

foreach (var entry in map.TypeMap)
{
yield return new DependencyListEntry(importProvider.GetImportToType(entry.Value.type), $"External type map entry target for key '{entry.Key}'");
yield return new DependencyListEntry(importProvider.GetImportToType(entry.Value.type, TriggeringModule), $"External type map entry target for key '{entry.Key}'");
}
}
public override IEnumerable<CombinedDependencyListEntry> SearchDynamicDependencies(List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override int CompareToImpl(ISortableNode other, CompilerComparer comparer

public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section section, INativeFormatTypeReferenceProvider ProxyReferences)
{
Vertex typeMapGroupVertex = ProxyReferences.EncodeReferenceToType(writer, TypeMapGroup);
Vertex typeMapGroupVertex = ProxyReferences.EncodeReferenceToType(writer, TypeMapGroup, TriggeringModule);
if (map.ThrowingMethodStub is not null)
{
// We don't write out the throwing method stub for R2R
Expand All @@ -55,8 +55,8 @@ public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section se

foreach ((TypeDesc type, TypeDesc targetType) in map.TypeMap)
{
Vertex keyVertex = ProxyReferences.EncodeReferenceToType(writer, type);
Vertex valueVertex = ProxyReferences.EncodeReferenceToType(writer, targetType);
Vertex keyVertex = ProxyReferences.EncodeReferenceToType(writer, type, TriggeringModule);
Vertex valueVertex = ProxyReferences.EncodeReferenceToType(writer, targetType, TriggeringModule);
Vertex entry = writer.GetTuple(keyVertex, valueVertex);
typeMapHashTable.Append((uint)type.GetHashCode(), typeMapEntriesSection.Place(entry));
}
Expand All @@ -69,7 +69,7 @@ public Vertex CreateTypeMap(NodeFactory factory, NativeWriter writer, Section se
public override IEnumerable<CombinedDependencyListEntry> GetConditionalStaticDependencies(NodeFactory context) => [];
public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory context)
{
yield return new DependencyListEntry(importProvider.GetImportToType(TypeMapGroup), $"Type map '{TypeMapGroup}' key type");
yield return new DependencyListEntry(importProvider.GetImportToType(TypeMapGroup, TriggeringModule), $"Type map '{TypeMapGroup}' key type");

if (map.ThrowingMethodStub is not null)
{
Expand All @@ -78,8 +78,8 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto

foreach (var entry in map.TypeMap)
{
yield return new DependencyListEntry(importProvider.GetImportToType(entry.Key), $"Key type of Proxy type map entry");
yield return new DependencyListEntry(importProvider.GetImportToType(entry.Value), $"Proxy type map entry target for key '{entry.Key}'");
yield return new DependencyListEntry(importProvider.GetImportToType(entry.Key, TriggeringModule), $"Key type of Proxy type map entry");
yield return new DependencyListEntry(importProvider.GetImportToType(entry.Value, TriggeringModule), $"Proxy type map entry target for key '{entry.Key}'");
}
}
public override IEnumerable<CombinedDependencyListEntry> SearchDynamicDependencies(List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact
continue;

var groupType = map.Key;
dependencies.Add(new DependencyListEntry(_importReferenceProvider.GetImportToType(groupType), "Type Map Assembly Target"));
dependencies.Add(new DependencyListEntry(_importReferenceProvider.GetImportToType(groupType, _assemblyTypeMaps.AssociatedModule), "Type Map Assembly Target"));
foreach (var targetModule in map.Value.TargetModules)
{
dependencies.Add(new DependencyListEntry(_importReferenceProvider.GetImportToModule(targetModule), "Type Map Assembly Target"));
Expand Down Expand Up @@ -79,7 +79,7 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
continue;

var groupType = map.Key;
Vertex groupTypeVertex = _importReferenceProvider.EncodeReferenceToType(writer, groupType);
Vertex groupTypeVertex = _importReferenceProvider.EncodeReferenceToType(writer, groupType, _assemblyTypeMaps.AssociatedModule);
VertexSequence modules = new();
foreach (var targetModule in map.Value.TargetModules)
{
Expand Down
Loading
Loading