Skip to content

Commit e139ffb

Browse files
authored
Introduce a source generator for invoking methods on unmanaged vtables (dotnet#68276)
1 parent 34d8715 commit e139ffb

File tree

61 files changed

+4822
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+4822
-161
lines changed

docs/design/libraries/ComInterfaceGenerator/VTableStubs.md

+413
Large diffs are not rendered by default.

eng/testing/tests.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</ItemGroup>
2828

2929
<ItemGroup Condition="'$(TestRunRequiresLiveRefPack)' == 'true'">
30-
<None Include="$(MicrosoftNetCoreAppRefPackRefDir)**/*.dll" CopyToOutputDirectory="PreserveNewest" LinkBase="live-ref-pack/" Visible="false" />
30+
<None Include="$(MicrosoftNetCoreAppRefPackRefDir)**/*.dll" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" LinkBase="live-ref-pack/" Visible="false" />
3131
</ItemGroup>
3232

3333
<!--

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSStubCodeContext.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal sealed record JSImportCodeContext : JSStubCodeContext
2525
public JSImportCodeContext(JSImportData attributeData, StubCodeContext inner)
2626
{
2727
_inner = inner;
28-
Direction = CustomTypeMarshallingDirection.In;
28+
Direction = MarshalDirection.ManagedToUnmanaged;
2929
AttributeData = attributeData;
3030
}
3131

@@ -37,7 +37,7 @@ internal sealed record JSExportCodeContext : JSStubCodeContext
3737
public JSExportCodeContext(JSExportData attributeData, StubCodeContext inner)
3838
{
3939
_inner = inner;
40-
Direction = CustomTypeMarshallingDirection.Out;
40+
Direction = MarshalDirection.UnmanagedToManaged;
4141
AttributeData = attributeData;
4242
}
4343

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/FuncJSGenerator.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
5353
.Select(a => a.Syntax)
5454
.ToArray();
5555

56-
if (context.CurrentStage == StubCodeContext.Stage.UnmarshalCapture && context.Direction == CustomTypeMarshallingDirection.In && info.IsManagedReturnPosition)
56+
if (context.CurrentStage == StubCodeContext.Stage.UnmarshalCapture && context.Direction == MarshalDirection.ManagedToUnmanaged && info.IsManagedReturnPosition)
5757
{
5858
yield return ToManagedMethod(target, source, jsty);
5959
}
6060

61-
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == CustomTypeMarshallingDirection.Out && info.IsManagedReturnPosition)
61+
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == MarshalDirection.UnmanagedToManaged && info.IsManagedReturnPosition)
6262
{
6363
yield return ToJSMethod(target, source, jsty);
6464
}
@@ -68,12 +68,12 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
6868
yield return x;
6969
}
7070

71-
if (context.CurrentStage == StubCodeContext.Stage.PinnedMarshal && context.Direction == CustomTypeMarshallingDirection.In && !info.IsManagedReturnPosition)
71+
if (context.CurrentStage == StubCodeContext.Stage.PinnedMarshal && context.Direction == MarshalDirection.ManagedToUnmanaged && !info.IsManagedReturnPosition)
7272
{
7373
yield return ToJSMethod(target, source, jsty);
7474
}
7575

76-
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.Out && !info.IsManagedReturnPosition)
76+
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == MarshalDirection.UnmanagedToManaged && !info.IsManagedReturnPosition)
7777
{
7878
yield return ToManagedMethod(target, source, jsty);
7979
}

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/PrimitiveJSGenerator.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
3232
? Argument(IdentifierName(context.GetIdentifiers(info).native))
3333
: _inner.AsArgument(info, context);
3434

35-
if (context.CurrentStage == StubCodeContext.Stage.UnmarshalCapture && context.Direction == CustomTypeMarshallingDirection.In && info.IsManagedReturnPosition)
35+
if (context.CurrentStage == StubCodeContext.Stage.UnmarshalCapture && context.Direction == MarshalDirection.ManagedToUnmanaged && info.IsManagedReturnPosition)
3636
{
3737
yield return ToManagedMethod(target, source);
3838
}
3939

40-
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == CustomTypeMarshallingDirection.Out && info.IsManagedReturnPosition)
40+
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == MarshalDirection.UnmanagedToManaged && info.IsManagedReturnPosition)
4141
{
4242
yield return ToJSMethod(target, source);
4343
}
@@ -47,12 +47,12 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
4747
yield return x;
4848
}
4949

50-
if (context.CurrentStage == StubCodeContext.Stage.PinnedMarshal && context.Direction == CustomTypeMarshallingDirection.In && !info.IsManagedReturnPosition)
50+
if (context.CurrentStage == StubCodeContext.Stage.PinnedMarshal && context.Direction == MarshalDirection.ManagedToUnmanaged && !info.IsManagedReturnPosition)
5151
{
5252
yield return ToJSMethod(target, source);
5353
}
5454

55-
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.Out && !info.IsManagedReturnPosition)
55+
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == MarshalDirection.UnmanagedToManaged && !info.IsManagedReturnPosition)
5656
{
5757
yield return ToManagedMethod(target, source);
5858
}

src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/Marshaling/TaskJSGenerator.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
4545
? Argument(IdentifierName(context.GetIdentifiers(info).native))
4646
: _inner.AsArgument(info, context);
4747

48-
if (context.CurrentStage == StubCodeContext.Stage.UnmarshalCapture && context.Direction == CustomTypeMarshallingDirection.In && info.IsManagedReturnPosition)
48+
if (context.CurrentStage == StubCodeContext.Stage.UnmarshalCapture && context.Direction == MarshalDirection.ManagedToUnmanaged && info.IsManagedReturnPosition)
4949
{
5050
yield return jsty.ResultTypeInfo is JSSimpleTypeInfo(KnownManagedType.Void)
5151
? ToManagedMethodVoid(target, source)
5252
: ToManagedMethod(target, source, jsty.ResultTypeInfo.Syntax);
5353
}
5454

55-
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == CustomTypeMarshallingDirection.Out && info.IsManagedReturnPosition)
55+
if (context.CurrentStage == StubCodeContext.Stage.Marshal && context.Direction == MarshalDirection.UnmanagedToManaged && info.IsManagedReturnPosition)
5656
{
5757
yield return jsty.ResultTypeInfo is JSSimpleTypeInfo(KnownManagedType.Void)
5858
? ToJSMethodVoid(target, source)
@@ -64,14 +64,14 @@ public override IEnumerable<StatementSyntax> Generate(TypePositionInfo info, Stu
6464
yield return x;
6565
}
6666

67-
if (context.CurrentStage == StubCodeContext.Stage.PinnedMarshal && context.Direction == CustomTypeMarshallingDirection.In && !info.IsManagedReturnPosition)
67+
if (context.CurrentStage == StubCodeContext.Stage.PinnedMarshal && context.Direction == MarshalDirection.ManagedToUnmanaged && !info.IsManagedReturnPosition)
6868
{
6969
yield return jsty.ResultTypeInfo is JSSimpleTypeInfo(KnownManagedType.Void)
7070
? ToJSMethodVoid(target, source)
7171
: ToJSMethod(target, source, jsty.ResultTypeInfo.Syntax);
7272
}
7373

74-
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == CustomTypeMarshallingDirection.Out && !info.IsManagedReturnPosition)
74+
if (context.CurrentStage == StubCodeContext.Stage.Unmarshal && context.Direction == MarshalDirection.UnmanagedToManaged && !info.IsManagedReturnPosition)
7575
{
7676
yield return jsty.ResultTypeInfo is JSSimpleTypeInfo(KnownManagedType.Void)
7777
? ToManagedMethodVoid(target, source)

0 commit comments

Comments
 (0)