diff options
author | Michal Strehovský <MichalStrehovsky@users.noreply.github.com> | 2017-03-23 22:28:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-23 22:28:47 +0300 |
commit | f4407ca10449c759455c3b0589fe3d689f7bb6cc (patch) | |
tree | 1df25024a56146ab5a4da61ed1347e0a806b1e14 /src/ILCompiler.TypeSystem | |
parent | 2c7f5907b1805b5cef78ddc442d6a48a1080dd31 (diff) |
Implement TypedReference in CoreRT (#3000)
This is basically three things:
1. `ByReference<T>` support
2. General support infra in the type system for Byref-like types (to be
reused for e.g. `Span<T>`).
3. TypedReference
Fixes #367.
Diffstat (limited to 'src/ILCompiler.TypeSystem')
3 files changed, 80 insertions, 0 deletions
diff --git a/src/ILCompiler.TypeSystem/tests/CoreTestAssembly/InstanceFieldLayout.cs b/src/ILCompiler.TypeSystem/tests/CoreTestAssembly/InstanceFieldLayout.cs index 827f9f478..912d7e778 100644 --- a/src/ILCompiler.TypeSystem/tests/CoreTestAssembly/InstanceFieldLayout.cs +++ b/src/ILCompiler.TypeSystem/tests/CoreTestAssembly/InstanceFieldLayout.cs @@ -146,3 +146,31 @@ namespace Sequential } } +namespace IsByRefLike +{ + public struct ByRefLikeStruct + { + ByReference<object> ByRef; + } + + public struct ComposedStruct + { + ByRefLikeStruct ByRefLike; + } + + public struct NotByRefLike + { + int X; + } + + public class Invalid + { + ByReference<int> ByRef; + } + + public class ComposedInvalid + { + ByRefLikeStruct ByRefLike; + } +} + diff --git a/src/ILCompiler.TypeSystem/tests/CoreTestAssembly/Platform.cs b/src/ILCompiler.TypeSystem/tests/CoreTestAssembly/Platform.cs index 7f2a8e258..b15af240e 100644 --- a/src/ILCompiler.TypeSystem/tests/CoreTestAssembly/Platform.cs +++ b/src/ILCompiler.TypeSystem/tests/CoreTestAssembly/Platform.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. #pragma warning disable 649 +#pragma warning disable 169 namespace System { @@ -65,6 +66,14 @@ namespace System public class Array<T> : Array, System.Collections.Generic.IList<T> { } public class Exception { } + + public struct TypedReference + { + private readonly ByReference<byte> _value; + private readonly RuntimeTypeHandle _typeHandle; + } + + public struct ByReference<T> { } } namespace System.Collections diff --git a/src/ILCompiler.TypeSystem/tests/InstanceFieldLayoutTests.cs b/src/ILCompiler.TypeSystem/tests/InstanceFieldLayoutTests.cs index 67d7f82fb..ef65ceb5d 100644 --- a/src/ILCompiler.TypeSystem/tests/InstanceFieldLayoutTests.cs +++ b/src/ILCompiler.TypeSystem/tests/InstanceFieldLayoutTests.cs @@ -299,5 +299,48 @@ namespace TypeSystemTests type = _testModule.GetType("ContainsGCPointers", "ClassHasArrayOfClassType"); Assert.True(type.ContainsGCPointers); } + + [Fact] + public void TestByRefLikeTypes() + { + { + DefType type = _context.GetWellKnownType(WellKnownType.TypedReference); + Assert.True(type.IsByRefLike); + } + + { + DefType type = _context.GetWellKnownType(WellKnownType.ByReferenceOfT); + Assert.True(type.IsByRefLike); + } + + { + DefType type = _testModule.GetType("IsByRefLike", "ByRefLikeStruct"); + Assert.True(type.IsByRefLike); + } + + { + DefType type = _testModule.GetType("IsByRefLike", "ComposedStruct"); + Assert.True(type.IsByRefLike); + } + + { + DefType type = _testModule.GetType("IsByRefLike", "NotByRefLike"); + Assert.False(type.IsByRefLike); + } + } + + [Fact] + public void TestInvalidByRefLikeTypes() + { + { + DefType type = _testModule.GetType("IsByRefLike", "Invalid"); + Assert.Throws<TypeSystemException.TypeLoadException>(() => type.ComputeInstanceLayout(InstanceLayoutKind.TypeAndFields)); + } + + { + DefType type = _testModule.GetType("IsByRefLike", "ComposedInvalid"); + Assert.Throws<TypeSystemException.TypeLoadException>(() => type.ComputeInstanceLayout(InstanceLayoutKind.TypeAndFields)); + } + } } } |