Skip to content

Commit 34113a1

Browse files
authored
Merge pull request #6 from js6pak/ilhelpers
Replace MonoMod.ILHelpers with InlineIL.Fody
2 parents ab60d34 + a79fb94 commit 34113a1

37 files changed

Lines changed: 909 additions & 1658 deletions

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ ModelManifest.xml
232232

233233
# Rider configuration files
234234
.idea/
235-
*.binlog
236-
*.dump
235+
*.binlog
236+
*.dump
237237

238-
.mono/
238+
.mono/
239+
FodyWeavers.xsd

MonoMod.Backports.slnx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616
<Folder Name="/src/">
1717
<Project Path="src/MonoMod.Backports.Shims/MonoMod.Backports.Shims.csproj" />
1818
<Project Path="src/MonoMod.Backports/MonoMod.Backports.csproj" />
19-
<Project Path="src/MonoMod.ILHelpers/MonoMod.ILHelpers.ilproj" Type="C#" />
2019
</Folder>
2120
<Folder Name="/src/build/">
2221
<Project Path="src/GenApiCompatDll/GenApiCompatDll.csproj" Id="265b1234-55c4-4edd-996c-12ac77527224" />
2322
<Project Path="src/MonoMod.Backports.Tasks/MonoMod.Backports.Tasks.csproj" />
24-
<Project Path="src/Postprocess/Postprocess.csproj" />
2523
<Project Path="src/ShimGen/ShimGen.csproj" />
2624
</Folder>
2725
</Solution>

src/MonoMod.Backports/Directory.Build.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
55

66
<Import Project="$(MSBuildThisFileDirectory)FilterTfms.targets"/>
7-
<Import Project="$(MSBuildThisFileDirectory)Postprocess.targets"/>
87
<Import Project="$(MSBuildThisFileDirectory)NuGet.targets"/>
98

109
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
2+
<InlineIL SequencePoints="True" Warnings="Errors" />
3+
</Weavers>

src/MonoMod.Backports/MonoMod.Backports.csproj

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<!-- Manually reference ILHelpers -->
23-
<ProjectReference Include="$(MMSourcePath)MonoMod.ILHelpers\MonoMod.ILHelpers.ilproj">
24-
<Aliases>ilhelpers</Aliases>
25-
<CopyLocal>false</CopyLocal>
26-
<Private>false</Private>
27-
<Pack>false</Pack>
28-
</ProjectReference>
22+
<PackageReference Include="Fody" Version="6.9.2" PrivateAssets="all" />
23+
<!-- https://github.com/ltrzesniewski/InlineIL.Fody/pull/35 -->
24+
<PackageReference Include="js6pak.InlineIL.Fody" Version="1.10.0-js6pak.1" PrivateAssets="all" ExcludeAssets="runtime" Pack="false" />
2925
</ItemGroup>
3026

27+
<Target Name="RemoveImplicitOutOfBandAssemblies"
28+
BeforeTargets="BeforeCompile"
29+
AfterTargets="FindReferenceAssembliesForReferences">
30+
<ItemGroup>
31+
<ReferencePathWithRefAssemblies Remove="@(ReferencePathWithRefAssemblies)" Condition="%(Filename) == 'System.Runtime.CompilerServices.Unsafe'" />
32+
</ItemGroup>
33+
</Target>
34+
3135
</Project>
3236

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using InlineIL;
2+
using System.Runtime.CompilerServices;
3+
using static InlineIL.IL;
4+
using static InlineIL.IL.Emit;
5+
6+
namespace MonoMod
7+
{
8+
internal static class ILHelpers
9+
{
10+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
11+
public static ref T ObjectAsRef<T>(object? obj)
12+
{
13+
DeclareLocals(init: false, [
14+
new LocalVar("pin", typeof(object)).Pinned(),
15+
#if !NETCOREAPP
16+
new LocalVar("refPtr", typeof(T).MakePointerType().MakePointerType()),
17+
new LocalVar("finalRef", typeof(T).MakeByRefType()),
18+
#endif
19+
]);
20+
21+
// pin obj
22+
Ldarg(nameof(obj));
23+
Stloc("pin");
24+
25+
#if NETCOREAPP
26+
// return ref *Unsafe.BitCast<object, T*>(pin);
27+
Ldloc("pin");
28+
Conv_U();
29+
#else
30+
// see docs/RuntimeIssueNotes.md - "`fixed` on strings in old Mono" for why this is necessary
31+
// T* ptr = *(T**)(&pin);
32+
Ldloca("pin");
33+
Conv_U();
34+
Stloc("refPtr");
35+
Ldloc("refPtr");
36+
Ldind_I();
37+
// return Unsafe.AsRef<T>(ptr);
38+
// see the comments inside that function for why don't just immediately ret
39+
Stloc("finalRef");
40+
Ldloc("finalRef");
41+
#endif
42+
43+
return ref ReturnRef<T>();
44+
}
45+
}
46+
}

src/MonoMod.Backports/Postprocess.targets

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/MonoMod.Backports/SRCS.Unsafe.cs

Lines changed: 0 additions & 189 deletions
This file was deleted.

src/MonoMod.Backports/System/Buffers,is_fx,lt_core_2.1,lt_std_2.1/ArrayMemoryPool.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Runtime.CompilerServices;
5+
46
namespace System.Buffers
57
{
68
internal sealed partial class ArrayMemoryPool<T> : MemoryPool<T>

src/MonoMod.Backports/System/Buffers,is_fx,lt_core_2.1,lt_std_2.1/Number/Number.FormatAndParse.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Diagnostics;
55
using System.Buffers.Text;
6+
using System.Runtime.CompilerServices;
67

78
//
89
// This code is copied almost verbatim from the same-named file in CoreRT with mechanical changes to Span-ify it.

0 commit comments

Comments
 (0)