Skip to content

Commit

Permalink
Fix universal canon
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky committed Nov 18, 2021
1 parent 800cf0e commit 24edc80
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected virtual ComputedInstanceFieldLayout ComputeInstanceFieldLayout(Metadat
}
// Sequential layout has to be respected for blittable types only. We use approximation and respect it for
// all types without GC references (ie C# unmanaged types). Universal canonical instances might be blittable.
else if (type.IsSequentialLayout && (type.IsCanonicalSubtype(CanonicalFormKind.Universal) || !type.ContainsGCPointers))
else if (type.IsSequentialLayout && (type.Context.SupportsUniversalCanon || !type.ContainsGCPointers))
{
return ComputeSequentialFieldLayout(type, numInstanceFields);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class CanonicalizationTests

public CanonicalizationTests()
{
_context = new TestTypeSystemContext(TargetArchitecture.Unknown);
_context = new TestTypeSystemContext(TargetArchitecture.Unknown, supportsUniversalCanon: true);
var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly");
_context.SetSystemModule(systemModule);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class RuntimeDeterminedTypesTests

public RuntimeDeterminedTypesTests()
{
_context = new TestTypeSystemContext(TargetArchitecture.Unknown);
_context = new TestTypeSystemContext(TargetArchitecture.Unknown, supportsUniversalCanon: true);
var systemModule = _context.CreateModuleForSimpleName("CoreTestAssembly");
_context.SetSystemModule(systemModule);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class TestTypeSystemContext : MetadataTypeSystemContext
MetadataRuntimeInterfacesAlgorithm _metadataRuntimeInterfacesAlgorithm = new MetadataRuntimeInterfacesAlgorithm();
ArrayOfTRuntimeInterfacesAlgorithm _arrayOfTRuntimeInterfacesAlgorithm;
VirtualMethodAlgorithm _virtualMethodAlgorithm = new MetadataVirtualMethodAlgorithm();
bool _supportsUniversalCanon;

public CanonicalizationMode CanonMode { get; set; } = CanonicalizationMode.RuntimeDetermined;

public TestTypeSystemContext(TargetArchitecture arch)
public TestTypeSystemContext(TargetArchitecture arch, bool supportsUniversalCanon = false)
: base(new TargetDetails(arch, TargetOS.Unknown, TargetAbi.Unknown))
{
_supportsUniversalCanon = supportsUniversalCanon;
}

public ModuleDesc GetModuleForSimpleName(string simpleName)
Expand Down Expand Up @@ -92,6 +94,7 @@ public override VirtualMethodAlgorithm GetVirtualMethodAlgorithmForType(TypeDesc

protected override Instantiation ConvertInstantiationToCanonForm(Instantiation instantiation, CanonicalFormKind kind, out bool changed)
{
Debug.Assert(kind != CanonicalFormKind.Universal || _supportsUniversalCanon);
if (CanonMode == CanonicalizationMode.Standard)
return StandardCanonicalizationAlgorithm.ConvertInstantiationToCanonForm(instantiation, kind, out changed);
else
Expand All @@ -100,6 +103,7 @@ protected override Instantiation ConvertInstantiationToCanonForm(Instantiation i

protected override TypeDesc ConvertToCanon(TypeDesc typeToConvert, CanonicalFormKind kind)
{
Debug.Assert(kind != CanonicalFormKind.Universal || _supportsUniversalCanon);
if (CanonMode == CanonicalizationMode.Standard)
return StandardCanonicalizationAlgorithm.ConvertToCanon(typeToConvert, kind);
else
Expand All @@ -108,6 +112,7 @@ protected override TypeDesc ConvertToCanon(TypeDesc typeToConvert, CanonicalForm

protected override TypeDesc ConvertToCanon(TypeDesc typeToConvert, ref CanonicalFormKind kind)
{
Debug.Assert(kind != CanonicalFormKind.Universal || _supportsUniversalCanon);
if (CanonMode == CanonicalizationMode.Standard)
return StandardCanonicalizationAlgorithm.ConvertToCanon(typeToConvert, kind);
else
Expand All @@ -129,7 +134,7 @@ protected override bool ComputeHasGCStaticBase(FieldDesc field)

}

public override bool SupportsUniversalCanon => true;
public override bool SupportsUniversalCanon => _supportsUniversalCanon;
public override bool SupportsCanon => true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public class UniversalGenericFieldLayoutTests
public UniversalGenericFieldLayoutTests()
{
// Architecture specific tests may use these contexts
_contextX64 = new TestTypeSystemContext(TargetArchitecture.X64);
_contextX64 = new TestTypeSystemContext(TargetArchitecture.X64, supportsUniversalCanon: true);
var systemModuleX64 = _contextX64.CreateModuleForSimpleName("CoreTestAssembly");
_contextX64.SetSystemModule(systemModuleX64);

_testModuleX64 = systemModuleX64;

_contextARM = new TestTypeSystemContext(TargetArchitecture.ARM);
_contextARM = new TestTypeSystemContext(TargetArchitecture.ARM, supportsUniversalCanon: true);
var systemModuleARM = _contextARM.CreateModuleForSimpleName("CoreTestAssembly");
_contextARM.SetSystemModule(systemModuleARM);

_testModuleARM = systemModuleARM;

_contextX86 = new TestTypeSystemContext(TargetArchitecture.X86);
_contextX86 = new TestTypeSystemContext(TargetArchitecture.X86, supportsUniversalCanon: true);
var systemModuleX86 = _contextX86.CreateModuleForSimpleName("CoreTestAssembly");
_contextX86.SetSystemModule(systemModuleX86);

Expand Down

0 comments on commit 24edc80

Please sign in to comment.