diff --git a/src/LibHac/Common/SharedRef.cs b/src/LibHac/Common/SharedRef.cs index ae45b89a..3fff500b 100644 --- a/src/LibHac/Common/SharedRef.cs +++ b/src/LibHac/Common/SharedRef.cs @@ -1,7 +1,6 @@ using System; using System.Runtime.CompilerServices; using System.Threading; -using InlineIL; using LibHac.Diag; #pragma warning disable LH0001 @@ -13,17 +12,13 @@ public static class SharedRefExtensions // ReSharper disable once EntityNameCapturedOnly.Global public static ref SharedRef Ref(this in SharedRef value) where T : class, IDisposable { - IL.Emit.Ldarg(nameof(value)); - IL.Emit.Ret(); - throw IL.Unreachable(); + return ref Unsafe.AsRef(in value); } // ReSharper disable once EntityNameCapturedOnly.Global public static ref WeakRef Ref(this in WeakRef value) where T : class, IDisposable { - IL.Emit.Ldarg(nameof(value)); - IL.Emit.Ret(); - throw IL.Unreachable(); + return ref Unsafe.AsRef(in value); } } diff --git a/src/LibHac/Common/UniqueRef.cs b/src/LibHac/Common/UniqueRef.cs index 87505f36..46f28703 100644 --- a/src/LibHac/Common/UniqueRef.cs +++ b/src/LibHac/Common/UniqueRef.cs @@ -1,7 +1,6 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -using InlineIL; -using static InlineIL.IL.Emit; namespace LibHac.Common; @@ -10,9 +9,7 @@ public static class UniqueRefExtensions // ReSharper disable once EntityNameCapturedOnly.Global public static ref UniqueRef Ref(this in UniqueRef value) where T : class, IDisposable { - Ldarg(nameof(value)); - Ret(); - throw IL.Unreachable(); + return ref Unsafe.AsRef(in value); } } @@ -21,16 +18,8 @@ public struct UniqueRef : IDisposable where T : class, IDisposable { private T _value; - public readonly ref T Get - { - get - { - Ldarg_0(); - Ldflda(new FieldRef(typeof(UniqueRef), nameof(_value))); - Ret(); - throw IL.Unreachable(); - } - } + [UnscopedRef] + public readonly ref readonly T Get => ref _value; public readonly bool HasValue => Get is not null; diff --git a/src/LibHac/Fs/Common/Path.cs b/src/LibHac/Fs/Common/Path.cs index 6009689c..1abbdba1 100644 --- a/src/LibHac/Fs/Common/Path.cs +++ b/src/LibHac/Fs/Common/Path.cs @@ -4,7 +4,6 @@ using System.Diagnostics; using LibHac.Common; using LibHac.Diag; using LibHac.Util; -using static InlineIL.IL.Emit; using static LibHac.Fs.StringTraits; // ReSharper disable once CheckNamespace @@ -45,30 +44,40 @@ public static class PathExtensions /// of the input reference. /// The read-only reference to reinterpret. /// A reference to the given . - // ReSharper disable once EntityNameCapturedOnly.Global - public static ref Path Ref(this scoped in Path path) +#pragma warning disable LH0001 // DoNotCopyValue +#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type + public static unsafe ref Path Ref(this scoped in Path path) { - Ldarg(nameof(path)); - Ret(); - throw InlineIL.IL.Unreachable(); + fixed (Path* p = &path) + { + return ref *p; + } } - public static ref Path GetNullRef() + public static unsafe ref Path GetNullRef() { - Ldc_I4_0(); - Conv_U(); - Ret(); - throw InlineIL.IL.Unreachable(); + // Todo: Combine into one statement once ReSharper stops detecting that as an error + var p = (Path*)null; + return ref *p; } - public static bool IsNullRef(in Path path) + public static unsafe bool IsNullRef(in Path path) { - Ldarg_0(); - Ldc_I4_0(); - Conv_U(); - Ceq(); - return InlineIL.IL.Return(); + fixed (Path* p = &path) + { + return p == null; + } } + + public static unsafe bool IsNullRef(in int path) + { + fixed (int* p = &path) + { + return p == null; + } + } +#pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type +#pragma warning restore LH0001 // DoNotCopyValue } /// @@ -1214,7 +1223,7 @@ public static class PathFunctions /// : The operation was successful.
/// : was too small to contain the built path.
internal static Result SetUpFixedPathDoubleEntry(scoped ref Path path, Span pathBuffer, - scoped ReadOnlySpan entryName1, scoped ReadOnlySpan entryName2) + scoped ReadOnlySpan entryName1, scoped ReadOnlySpan entryName2) { var sb = new U8StringBuilder(pathBuffer); sb.Append((byte)'/').Append(entryName1) diff --git a/src/LibHac/Fs/Shim/SaveDataManagement.cs b/src/LibHac/Fs/Shim/SaveDataManagement.cs index 0bce6630..8ef736d4 100644 --- a/src/LibHac/Fs/Shim/SaveDataManagement.cs +++ b/src/LibHac/Fs/Shim/SaveDataManagement.cs @@ -590,7 +590,7 @@ namespace LibHac.Fs.Shim } public static Result ReadSaveDataIteratorSaveDataInfo(this FileSystemClientImpl fs, out long readCount, - Span buffer, ref SaveDataIterator iterator) + Span buffer, SaveDataIterator iterator) { Result res = iterator.ReadSaveDataInfo(out readCount, buffer); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs b/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs index a33c0d9e..b05f8089 100644 --- a/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs +++ b/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs @@ -367,7 +367,7 @@ namespace LibHac.Fs.Shim Unsafe.SkipInit(out SaveDataInfo info); res = fs.Impl.ReadSaveDataIteratorSaveDataInfo(out long count, SpanHelpers.AsSpan(ref info), - ref iterator.Get); + iterator.Get); fs.Impl.LogResultErrorMessage(res); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/FsSystem/BucketTree.cs b/src/LibHac/FsSystem/BucketTree.cs index 3ade95a4..302b51b6 100644 --- a/src/LibHac/FsSystem/BucketTree.cs +++ b/src/LibHac/FsSystem/BucketTree.cs @@ -1,5 +1,6 @@ using System; using System.Buffers.Binary; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using LibHac.Common; @@ -887,15 +888,8 @@ public partial class BucketTree : IDisposable /// This property allows using a expression with s /// while still being able to pass it by reference. /// A reference to this . - public ref Visitor Ref - { - get - { - InlineIL.IL.Emit.Ldarg_0(); - InlineIL.IL.Emit.Ret(); - throw InlineIL.IL.Unreachable(); - } - } + [UnscopedRef] + public ref Visitor Ref => ref this; internal Result Initialize(BucketTree tree, in Offsets offsets) { diff --git a/src/LibHac/LibHac.csproj b/src/LibHac/LibHac.csproj index 3edda82e..640230e3 100644 --- a/src/LibHac/LibHac.csproj +++ b/src/LibHac/LibHac.csproj @@ -25,9 +25,6 @@ $(MSBuildProjectDirectory)=C:/LibHac/ true - - $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - $(NoWarn);1591 @@ -41,8 +38,6 @@ - - @@ -52,13 +47,4 @@ - - - - - - - - - \ No newline at end of file diff --git a/src/LibHac/Os/UniqueLock.cs b/src/LibHac/Os/UniqueLock.cs index 3c8de40c..8ae04959 100644 --- a/src/LibHac/Os/UniqueLock.cs +++ b/src/LibHac/Os/UniqueLock.cs @@ -2,7 +2,6 @@ using System.Runtime.CompilerServices; using System.Threading; using LibHac.Common; -using static InlineIL.IL.Emit; namespace LibHac.Os; @@ -26,20 +25,19 @@ public static class UniqueLock return new UniqueLock(lockable); } - // ReSharper disable once EntityNameCapturedOnly.Global - public static ref UniqueLockRef Ref(this in UniqueLockRef value) where T : struct, ILockable +#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type + public static unsafe ref UniqueLockRef Ref(this in UniqueLockRef value) where T : struct, ILockable { - Ldarg(nameof(value)); - Ret(); - throw InlineIL.IL.Unreachable(); + fixed (UniqueLockRef* p = &value) + { + return ref *p; + } } +#pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type - // ReSharper disable once EntityNameCapturedOnly.Global public static ref UniqueLock Ref(this in UniqueLock value) where T : class, ILockable { - Ldarg(nameof(value)); - Ret(); - throw InlineIL.IL.Unreachable(); + return ref Unsafe.AsRef(in value); } }