From be41885ac89f39be2cfaafa69e32a8162b2b4b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6llner?= Date: Fri, 25 Oct 2019 18:04:34 +0200 Subject: [PATCH] Issue #22, issue #23 --- Capnp.Net.Runtime.Tests/TcpRpcInterop.cs | 6 +- Capnp.Net.Runtime.Tests/TcpRpcPorted.cs | 6 +- Capnp.Net.Runtime.Tests/test.cs | 190 ++++++++---------- Capnp.Net.Runtime/Rpc/Impatient.cs | 43 ++++ .../CapnpC.CSharp.Generator.Tests.csproj | 2 + .../CodeGenerator.feature | 3 +- .../CodeGenerator.feature.cs | 12 ++ .../Embedded Resources/Issue22.capnp.bin | Bin 0 -> 2616 bytes .../Embedded Resources/test.cs | 188 ++++++++--------- .../CodeGen/CodeGenerator.cs | 10 +- CapnpC.CSharp.Generator/CodeGen/GenNames.cs | 48 ++++- .../CodeGen/GeneratorOptions.cs | 6 +- .../CodeGen/InterfaceSnippetGen.cs | 6 + MsBuildGenerationTest/Issue22.capnp | 13 ++ MsBuildGenerationTest/a.capnp | 8 + MsBuildGenerationTest/b.capnp | 8 + MsBuildGenerationTest/common.capnp | 7 + 17 files changed, 318 insertions(+), 238 deletions(-) create mode 100644 CapnpC.CSharp.Generator.Tests/Embedded Resources/Issue22.capnp.bin create mode 100644 MsBuildGenerationTest/Issue22.capnp create mode 100644 MsBuildGenerationTest/a.capnp create mode 100644 MsBuildGenerationTest/b.capnp create mode 100644 MsBuildGenerationTest/common.capnp diff --git a/Capnp.Net.Runtime.Tests/TcpRpcInterop.cs b/Capnp.Net.Runtime.Tests/TcpRpcInterop.cs index 3114d48..58c66bf 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpcInterop.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpcInterop.cs @@ -494,7 +494,7 @@ namespace Capnp.Net.Runtime.Tests using (var main = client.GetMain()) { var tcs = new TaskCompletionSource(); - var eager = tcs.Task.PseudoEager(); + var eager = tcs.Task.Eager(true); var request = main.CallFoo(eager, default); AssertOutput(stdout, "callFoo"); @@ -963,7 +963,7 @@ namespace Capnp.Net.Runtime.Tests var earlyCall = main.GetCallSequence(0, default); - using (var eager = cap.Task.PseudoEager()) + using (var eager = cap.Task.Eager(true)) { var echo = main.Echo(eager, default); @@ -1127,7 +1127,7 @@ namespace Capnp.Net.Runtime.Tests var tcs = new TaskCompletionSource(); - using (var eager = tcs.Task.PseudoEager()) + using (var eager = tcs.Task.Eager(true)) { var req = main.Hold(eager, default); Assert.IsTrue(req.Wait(MediumNonDbgTimeout)); diff --git a/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs b/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs index dec51ca..90b2b72 100644 --- a/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs +++ b/Capnp.Net.Runtime.Tests/TcpRpcPorted.cs @@ -241,7 +241,7 @@ namespace Capnp.Net.Runtime.Tests using (var main = client.GetMain()) { var tcs = new TaskCompletionSource(); - var eager = tcs.Task.PseudoEager(); + var eager = tcs.Task.Eager(true); var request = main.CallFoo(eager, default); var request2 = main.CallFooWhenResolved(eager, default); @@ -528,7 +528,7 @@ namespace Capnp.Net.Runtime.Tests var earlyCall = main.GetCallSequence(0, default); - var echo = main.Echo(cap.Task.PseudoEager(), default); + var echo = main.Echo(cap.Task.Eager(true), default); var pipeline = echo.Eager(); @@ -620,7 +620,7 @@ namespace Capnp.Net.Runtime.Tests var tcs = new TaskCompletionSource(); - var req = main.Hold(tcs.Task.PseudoEager(), default); + var req = main.Hold(tcs.Task.Eager(true), default); Assert.IsTrue(req.Wait(MediumNonDbgTimeout)); var req2 = main.CallHeld(default); diff --git a/Capnp.Net.Runtime.Tests/test.cs b/Capnp.Net.Runtime.Tests/test.cs index 925ff9d..5e02653 100644 --- a/Capnp.Net.Runtime.Tests/test.cs +++ b/Capnp.Net.Runtime.Tests/test.cs @@ -8602,13 +8602,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x8839ed86c9794287UL), Proxy(typeof(DeepNestInterfaceProxy<>)), Skeleton(typeof(DeepNestInterfaceSkeleton<>))] + [TypeId(0x8839ed86c9794287UL), Proxy(typeof(DeepNestInterface_Proxy<>)), Skeleton(typeof(DeepNestInterface_Skeleton<>))] public interface IDeepNestInterface : IDisposable where TQuux : class { Task Call(CancellationToken cancellationToken_ = default); } - public class DeepNestInterfaceProxy : Proxy, IDeepNestInterface where TQuux : class + public class DeepNestInterface_Proxy : Proxy, IDeepNestInterface where TQuux : class { public async Task Call(CancellationToken cancellationToken_ = default) { @@ -8622,9 +8622,9 @@ namespace Capnproto_test.Capnp.Test } } - public class DeepNestInterfaceSkeleton : Skeleton> where TQuux : class + public class DeepNestInterface_Skeleton : Skeleton> where TQuux : class { - public DeepNestInterfaceSkeleton() + public DeepNestInterface_Skeleton() { SetMethodTable(Call); } @@ -8734,13 +8734,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xc9e749e8dd54da5cUL), Proxy(typeof(InterfaceProxy<>)), Skeleton(typeof(InterfaceSkeleton<>))] + [TypeId(0xc9e749e8dd54da5cUL), Proxy(typeof(Interface_Proxy<>)), Skeleton(typeof(Interface_Skeleton<>))] public interface IInterface : IDisposable where TQux : class { Task<(TQux, Capnproto_test.Capnp.Test.TestGenerics)> Call(Capnproto_test.Capnp.Test.TestGenerics.Inner2 arg_, CancellationToken cancellationToken_ = default); } - public class InterfaceProxy : Proxy, IInterface where TQux : class + public class Interface_Proxy : Proxy, IInterface where TQux : class { public Task<(TQux, Capnproto_test.Capnp.Test.TestGenerics)> Call(Capnproto_test.Capnp.Test.TestGenerics.Inner2 arg_, CancellationToken cancellationToken_ = default) { @@ -8756,9 +8756,9 @@ namespace Capnproto_test.Capnp.Test } } - public class InterfaceSkeleton : Skeleton> where TQux : class + public class Interface_Skeleton : Skeleton> where TQux : class { - public InterfaceSkeleton() + public Interface_Skeleton() { SetMethodTable(Call); } @@ -9113,14 +9113,14 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x8b9717a3f8d85a9aUL), Proxy(typeof(TestImplicitMethodParamsProxy)), Skeleton(typeof(TestImplicitMethodParamsSkeleton))] + [TypeId(0x8b9717a3f8d85a9aUL), Proxy(typeof(TestImplicitMethodParams_Proxy)), Skeleton(typeof(TestImplicitMethodParams_Skeleton))] public interface ITestImplicitMethodParams : IDisposable { Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class; } - public class TestImplicitMethodParamsProxy : Proxy, ITestImplicitMethodParams + public class TestImplicitMethodParams_Proxy : Proxy, ITestImplicitMethodParams { public Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class @@ -9139,9 +9139,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestImplicitMethodParamsSkeleton : Skeleton + public class TestImplicitMethodParams_Skeleton : Skeleton { - public TestImplicitMethodParamsSkeleton() + public TestImplicitMethodParams_Skeleton() { SetMethodTable(Call); } @@ -9240,14 +9240,14 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xdf9ccdeb81a704c9UL), Proxy(typeof(TestImplicitMethodParamsInGenericProxy<>)), Skeleton(typeof(TestImplicitMethodParamsInGenericSkeleton<>))] + [TypeId(0xdf9ccdeb81a704c9UL), Proxy(typeof(TestImplicitMethodParamsInGeneric_Proxy<>)), Skeleton(typeof(TestImplicitMethodParamsInGeneric_Skeleton<>))] public interface ITestImplicitMethodParamsInGeneric : IDisposable where TV : class { Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class; } - public class TestImplicitMethodParamsInGenericProxy : Proxy, ITestImplicitMethodParamsInGeneric where TV : class + public class TestImplicitMethodParamsInGeneric_Proxy : Proxy, ITestImplicitMethodParamsInGeneric where TV : class { public Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class @@ -9266,9 +9266,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestImplicitMethodParamsInGenericSkeleton : Skeleton> where TV : class + public class TestImplicitMethodParamsInGeneric_Skeleton : Skeleton> where TV : class { - public TestImplicitMethodParamsInGenericSkeleton() + public TestImplicitMethodParamsInGeneric_Skeleton() { SetMethodTable(Call); } @@ -10797,7 +10797,7 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x88eb12a0e0af92b2UL), Proxy(typeof(TestInterfaceProxy)), Skeleton(typeof(TestInterfaceSkeleton))] + [TypeId(0x88eb12a0e0af92b2UL), Proxy(typeof(TestInterface_Proxy)), Skeleton(typeof(TestInterface_Skeleton))] public interface ITestInterface : IDisposable { Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default); @@ -10805,7 +10805,7 @@ namespace Capnproto_test.Capnp.Test Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default); } - public class TestInterfaceProxy : Proxy, ITestInterface + public class TestInterface_Proxy : Proxy, ITestInterface { public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) { @@ -10841,9 +10841,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestInterfaceSkeleton : Skeleton + public class TestInterface_Skeleton : Skeleton { - public TestInterfaceSkeleton() + public TestInterface_Skeleton() { SetMethodTable(Foo, Bar, Baz); } @@ -11212,7 +11212,7 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xe4e9bac98670b748UL), Proxy(typeof(TestExtendsProxy)), Skeleton(typeof(TestExtendsSkeleton))] + [TypeId(0xe4e9bac98670b748UL), Proxy(typeof(TestExtends_Proxy)), Skeleton(typeof(TestExtends_Skeleton))] public interface ITestExtends : Capnproto_test.Capnp.Test.ITestInterface { Task Qux(CancellationToken cancellationToken_ = default); @@ -11220,7 +11220,7 @@ namespace Capnproto_test.Capnp.Test Task Grault(CancellationToken cancellationToken_ = default); } - public class TestExtendsProxy : Proxy, ITestExtends + public class TestExtends_Proxy : Proxy, ITestExtends { public async Task Qux(CancellationToken cancellationToken_ = default) { @@ -11287,9 +11287,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestExtendsSkeleton : Skeleton + public class TestExtends_Skeleton : Skeleton { - public TestExtendsSkeleton() + public TestExtends_Skeleton() { SetMethodTable(Qux, Corge, Grault); } @@ -11505,12 +11505,12 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x98d7e0ef61488783UL), Proxy(typeof(TestExtends2Proxy)), Skeleton(typeof(TestExtends2Skeleton))] + [TypeId(0x98d7e0ef61488783UL), Proxy(typeof(TestExtends2_Proxy)), Skeleton(typeof(TestExtends2_Skeleton))] public interface ITestExtends2 : Capnproto_test.Capnp.Test.ITestExtends { } - public class TestExtends2Proxy : Proxy, ITestExtends2 + public class TestExtends2_Proxy : Proxy, ITestExtends2 { public async Task Qux(CancellationToken cancellationToken_ = default) { @@ -11577,9 +11577,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestExtends2Skeleton : Skeleton + public class TestExtends2_Skeleton : Skeleton { - public TestExtends2Skeleton() + public TestExtends2_Skeleton() { SetMethodTable(); } @@ -11587,7 +11587,7 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11013518732491786115UL; } - [TypeId(0xa5a404caa61d4cd0UL), Proxy(typeof(TestPipelineProxy)), Skeleton(typeof(TestPipelineSkeleton))] + [TypeId(0xa5a404caa61d4cd0UL), Proxy(typeof(TestPipeline_Proxy)), Skeleton(typeof(TestPipeline_Skeleton))] public interface ITestPipeline : IDisposable { Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default); @@ -11595,7 +11595,7 @@ namespace Capnproto_test.Capnp.Test Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint n, BareProxy inCap, CancellationToken cancellationToken_ = default); } - public class TestPipelineProxy : Proxy, ITestPipeline + public class TestPipeline_Proxy : Proxy, ITestPipeline { public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default) { @@ -11639,9 +11639,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestPipelineSkeleton : Skeleton + public class TestPipeline_Skeleton : Skeleton { - public TestPipelineSkeleton() + public TestPipeline_Skeleton() { SetMethodTable(GetCap, TestPointers, GetAnyCap); } @@ -12242,13 +12242,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xa0e77035bdff0051UL), Proxy(typeof(TestCallOrderProxy)), Skeleton(typeof(TestCallOrderSkeleton))] + [TypeId(0xa0e77035bdff0051UL), Proxy(typeof(TestCallOrder_Proxy)), Skeleton(typeof(TestCallOrder_Skeleton))] public interface ITestCallOrder : IDisposable { Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default); } - public class TestCallOrderProxy : Proxy, ITestCallOrder + public class TestCallOrder_Proxy : Proxy, ITestCallOrder { public async Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default) { @@ -12262,9 +12262,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestCallOrderSkeleton : Skeleton + public class TestCallOrder_Skeleton : Skeleton { - public TestCallOrderSkeleton() + public TestCallOrder_Skeleton() { SetMethodTable(GetCallSequence); } @@ -12408,13 +12408,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xddd699207eb8e23bUL), Proxy(typeof(TestTailCalleeProxy)), Skeleton(typeof(TestTailCalleeSkeleton))] + [TypeId(0xddd699207eb8e23bUL), Proxy(typeof(TestTailCallee_Proxy)), Skeleton(typeof(TestTailCallee_Skeleton))] public interface ITestTailCallee : IDisposable { Task Foo(int i, string t, CancellationToken cancellationToken_ = default); } - public class TestTailCalleeProxy : Proxy, ITestTailCallee + public class TestTailCallee_Proxy : Proxy, ITestTailCallee { public Task Foo(int i, string t, CancellationToken cancellationToken_ = default) { @@ -12432,9 +12432,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestTailCalleeSkeleton : Skeleton + public class TestTailCallee_Skeleton : Skeleton { - public TestTailCalleeSkeleton() + public TestTailCallee_Skeleton() { SetMethodTable(Foo); } @@ -12622,13 +12622,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x870bf40110ce3035UL), Proxy(typeof(TestTailCallerProxy)), Skeleton(typeof(TestTailCallerSkeleton))] + [TypeId(0x870bf40110ce3035UL), Proxy(typeof(TestTailCaller_Proxy)), Skeleton(typeof(TestTailCaller_Skeleton))] public interface ITestTailCaller : IDisposable { Task Foo(int i, Capnproto_test.Capnp.Test.ITestTailCallee callee, CancellationToken cancellationToken_ = default); } - public class TestTailCallerProxy : Proxy, ITestTailCaller + public class TestTailCaller_Proxy : Proxy, ITestTailCaller { public Task Foo(int i, Capnproto_test.Capnp.Test.ITestTailCallee callee, CancellationToken cancellationToken_ = default) { @@ -12646,9 +12646,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestTailCallerSkeleton : Skeleton + public class TestTailCaller_Skeleton : Skeleton { - public TestTailCallerSkeleton() + public TestTailCaller_Skeleton() { SetMethodTable(Foo); } @@ -12746,18 +12746,18 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xa38e5efe41e53a15UL), Proxy(typeof(TestHandleProxy)), Skeleton(typeof(TestHandleSkeleton))] + [TypeId(0xa38e5efe41e53a15UL), Proxy(typeof(TestHandle_Proxy)), Skeleton(typeof(TestHandle_Skeleton))] public interface ITestHandle : IDisposable { } - public class TestHandleProxy : Proxy, ITestHandle + public class TestHandle_Proxy : Proxy, ITestHandle { } - public class TestHandleSkeleton : Skeleton + public class TestHandle_Skeleton : Skeleton { - public TestHandleSkeleton() + public TestHandle_Skeleton() { SetMethodTable(); } @@ -12765,7 +12765,7 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11785461720995412501UL; } - [TypeId(0xddc70bf9784133cfUL), Proxy(typeof(TestMoreStuffProxy)), Skeleton(typeof(TestMoreStuffSkeleton))] + [TypeId(0xddc70bf9784133cfUL), Proxy(typeof(TestMoreStuff_Proxy)), Skeleton(typeof(TestMoreStuff_Skeleton))] public interface ITestMoreStuff : Capnproto_test.Capnp.Test.ITestCallOrder { Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); @@ -12783,7 +12783,7 @@ namespace Capnproto_test.Capnp.Test Task MethodWithNullDefault(string a, Capnproto_test.Capnp.Test.ITestInterface b, CancellationToken cancellationToken_ = default); } - public class TestMoreStuffProxy : Proxy, ITestMoreStuff + public class TestMoreStuff_Proxy : Proxy, ITestMoreStuff { public async Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) { @@ -12960,9 +12960,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestMoreStuffSkeleton : Skeleton + public class TestMoreStuff_Skeleton : Skeleton { - public TestMoreStuffSkeleton() + public TestMoreStuff_Skeleton() { SetMethodTable(CallFoo, CallFooWhenResolved, NeverReturn, Hold, CallHeld, GetHeld, Echo, ExpectCancel, MethodWithDefaults, GetHandle, GetNull, GetEnormousString, MethodWithNullDefault); } @@ -14634,7 +14634,7 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xc07d8dcd80a69c0cUL), Proxy(typeof(TestMembraneProxy)), Skeleton(typeof(TestMembraneSkeleton))] + [TypeId(0xc07d8dcd80a69c0cUL), Proxy(typeof(TestMembrane_Proxy)), Skeleton(typeof(TestMembrane_Skeleton))] public interface ITestMembrane : IDisposable { Task MakeThing(CancellationToken cancellationToken_ = default); @@ -14644,7 +14644,7 @@ namespace Capnproto_test.Capnp.Test Task WaitForever(CancellationToken cancellationToken_ = default); } - public class TestMembraneProxy : Proxy, ITestMembrane + public class TestMembrane_Proxy : Proxy, ITestMembrane { public Task MakeThing(CancellationToken cancellationToken_ = default) { @@ -14710,9 +14710,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestMembraneSkeleton : Skeleton + public class TestMembrane_Skeleton : Skeleton { - public TestMembraneSkeleton() + public TestMembrane_Skeleton() { SetMethodTable(MakeThing, CallPassThrough, CallIntercept, Loopback, WaitForever); } @@ -14781,14 +14781,14 @@ namespace Capnproto_test.Capnp.Test public static class TestMembrane { - [TypeId(0x9352e4e41f173917UL), Proxy(typeof(ThingProxy)), Skeleton(typeof(ThingSkeleton))] + [TypeId(0x9352e4e41f173917UL), Proxy(typeof(Thing_Proxy)), Skeleton(typeof(Thing_Skeleton))] public interface IThing : IDisposable { Task PassThrough(CancellationToken cancellationToken_ = default); Task Intercept(CancellationToken cancellationToken_ = default); } - public class ThingProxy : Proxy, IThing + public class Thing_Proxy : Proxy, IThing { public async Task PassThrough(CancellationToken cancellationToken_ = default) { @@ -14813,9 +14813,9 @@ namespace Capnproto_test.Capnp.Test } } - public class ThingSkeleton : Skeleton + public class Thing_Skeleton : Skeleton { - public ThingSkeleton() + public Thing_Skeleton() { SetMethodTable(PassThrough, Intercept); } @@ -15675,7 +15675,7 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x9ae342d394247cfcUL), Proxy(typeof(TestKeywordMethodsProxy)), Skeleton(typeof(TestKeywordMethodsSkeleton))] + [TypeId(0x9ae342d394247cfcUL), Proxy(typeof(TestKeywordMethods_Proxy)), Skeleton(typeof(TestKeywordMethods_Skeleton))] public interface ITestKeywordMethods : IDisposable { Task Delete(CancellationToken cancellationToken_ = default); @@ -15684,7 +15684,7 @@ namespace Capnproto_test.Capnp.Test Task Return(CancellationToken cancellationToken_ = default); } - public class TestKeywordMethodsProxy : Proxy, ITestKeywordMethods + public class TestKeywordMethods_Proxy : Proxy, ITestKeywordMethods { public async Task Delete(CancellationToken cancellationToken_ = default) { @@ -15731,9 +15731,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestKeywordMethodsSkeleton : Skeleton + public class TestKeywordMethods_Skeleton : Skeleton { - public TestKeywordMethodsSkeleton() + public TestKeywordMethods_Skeleton() { SetMethodTable(Delete, Class, Void, Return); } @@ -16131,13 +16131,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xea72cc77253798cdUL), Proxy(typeof(TestAuthenticatedBootstrapProxy<>)), Skeleton(typeof(TestAuthenticatedBootstrapSkeleton<>))] + [TypeId(0xea72cc77253798cdUL), Proxy(typeof(TestAuthenticatedBootstrap_Proxy<>)), Skeleton(typeof(TestAuthenticatedBootstrap_Skeleton<>))] public interface ITestAuthenticatedBootstrap : IDisposable where TVatId : class { Task GetCallerId(CancellationToken cancellationToken_ = default); } - public class TestAuthenticatedBootstrapProxy : Proxy, ITestAuthenticatedBootstrap where TVatId : class + public class TestAuthenticatedBootstrap_Proxy : Proxy, ITestAuthenticatedBootstrap where TVatId : class { public Task GetCallerId(CancellationToken cancellationToken_ = default) { @@ -16155,9 +16155,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestAuthenticatedBootstrapSkeleton : Skeleton> where TVatId : class + public class TestAuthenticatedBootstrap_Skeleton : Skeleton> where TVatId : class { - public TestAuthenticatedBootstrapSkeleton() + public TestAuthenticatedBootstrap_Skeleton() { SetMethodTable(GetCallerId); } @@ -17105,13 +17105,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xd112a69d31ed918bUL), Proxy(typeof(TestNameAnnotationInterfaceProxy)), Skeleton(typeof(TestNameAnnotationInterfaceSkeleton))] + [TypeId(0xd112a69d31ed918bUL), Proxy(typeof(TestNameAnnotationInterface_Proxy)), Skeleton(typeof(TestNameAnnotationInterface_Skeleton))] public interface ITestNameAnnotationInterface : IDisposable { Task BadlyNamedMethod(byte badlyNamedParam, CancellationToken cancellationToken_ = default); } - public class TestNameAnnotationInterfaceProxy : Proxy, ITestNameAnnotationInterface + public class TestNameAnnotationInterface_Proxy : Proxy, ITestNameAnnotationInterface { public async Task BadlyNamedMethod(byte badlyNamedParam, CancellationToken cancellationToken_ = default) { @@ -17125,9 +17125,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestNameAnnotationInterfaceSkeleton : Skeleton + public class TestNameAnnotationInterface_Skeleton : Skeleton { - public TestNameAnnotationInterfaceSkeleton() + public TestNameAnnotationInterface_Skeleton() { SetMethodTable(BadlyNamedMethod); } @@ -17250,54 +17250,24 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions + public static partial class PipeliningSupportExtensions_test { - static readonly MemberAccessPath Path_getCap_OutBox_Cap = new MemberAccessPath(1U, 0U); + static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestPipeline_getCap_OutBox_Cap = new MemberAccessPath(1U, 0U); public static Capnproto_test.Capnp.Test.ITestInterface OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> task) { - return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getCap_OutBox_Cap)); + return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getCap_OutBox_Cap)); } - static readonly MemberAccessPath Path_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); + static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestPipeline_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); public static BareProxy OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> task) { - return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getAnyCap_OutBox_Cap)); + return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getAnyCap_OutBox_Cap)); } - static readonly MemberAccessPath Path_foo_C = new MemberAccessPath(1U); + static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestTailCallee_foo_C = new MemberAccessPath(1U); public static Capnproto_test.Capnp.Test.ITestCallOrder C(this Task task) { - return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_foo_C)); - } - - static readonly MemberAccessPath Path_neverReturn_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestInterface Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_neverReturn_Eager)); - } - - static readonly MemberAccessPath Path_echo_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestCallOrder Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_echo_Eager)); - } - - static readonly MemberAccessPath Path_getHandle_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestHandle Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestHandle)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getHandle_Eager)); - } - - static readonly MemberAccessPath Path_getNull_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestMoreStuff Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestMoreStuff)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getNull_Eager)); - } - - static readonly MemberAccessPath Path_makeThing_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.TestMembrane.IThing Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.TestMembrane.IThing)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_makeThing_Eager)); + return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestTailCallee_foo_C)); } } -} +} \ No newline at end of file diff --git a/Capnp.Net.Runtime/Rpc/Impatient.cs b/Capnp.Net.Runtime/Rpc/Impatient.cs index 42265dd..9dd1e08 100644 --- a/Capnp.Net.Runtime/Rpc/Impatient.cs +++ b/Capnp.Net.Runtime/Rpc/Impatient.cs @@ -123,6 +123,7 @@ namespace Capnp.Rpc /// is null. /// did not /// quality as capability interface. + [Obsolete("Call Eager(task, true) instead")] public static TInterface PseudoEager(this Task task, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", @@ -133,6 +134,48 @@ namespace Capnp.Rpc return CapabilityReflection.CreateProxy(lazyCap, memberName, sourceFilePath, sourceLineNumber) as TInterface; } + static readonly MemberAccessPath Path_OneAndOnly = new MemberAccessPath(0U); + + /// + /// Returns a promise-pipelined Proxy for a remote method invocation Task. + /// + /// Capability interface type + /// Task returning an interface + /// If this flag is 'false', the MUST have been returned from a remote + /// method invocation on a generated Proxy interface. Since this is the prerequisite for promise pipelining to work, the method throws an + /// exception if the requirement is not met (i.e. the passed some Task instance was constructed "somewhere else"). Setting this flag to 'true' + /// prevents such an exception. The method falls back to a local "lazy" proxy for the given Task. It is fully usable, but does not perform + /// any promise pipelining (as specified for Cap'n Proto). + /// A proxy for the given future. + /// is null. + /// did not qualify as capability interface. + /// The task was not returned from a remote method invocation. Promise pipelining won't work. + /// Setting > to 'true' prevents this exception. + /// OR: Mismatch between generic type arguments (if capability interface is generic). + /// Mismatch between generic type arguments (if capability interface is generic). + /// Problem with instatiating the Proxy (constructor threw exception). + /// Caller does not have permission to invoke the Proxy constructor. + /// Problem with building the Proxy type, or problem with loading some dependent class. + public static TInterface Eager(this Task task, bool allowNoPipeliningFallback = false) + where TInterface : class + { + var answer = TryGetAnswer(task); + if (answer == null) + { + if (!allowNoPipeliningFallback) + { + throw new ArgumentException("The task was not returned from a remote method invocation. See documentation for details."); + } + + var lazyCap = new LazyCapability(AwaitProxy(task)); + return CapabilityReflection.CreateProxy(lazyCap) as TInterface; + } + else + { + return CapabilityReflection.CreateProxy(answer.Access(Path_OneAndOnly)) as TInterface; + } + } + internal static IRpcEndpoint AskingEndpoint { get => _askingEndpoint.Value; diff --git a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj index 2911d45..410f90a 100644 --- a/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj +++ b/CapnpC.CSharp.Generator.Tests/CapnpC.CSharp.Generator.Tests.csproj @@ -29,6 +29,7 @@ + @@ -47,6 +48,7 @@ + diff --git a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature index a32890f..3485d84 100644 --- a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature +++ b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature @@ -55,4 +55,5 @@ Scenario Outline: Valid generator output Examples: | bin | | Issue19.capnp.bin | - | Issue21.capnp.bin | \ No newline at end of file + | Issue21.capnp.bin | + | Issue22.capnp.bin | \ No newline at end of file diff --git a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs index f81372f..de6a0cc 100644 --- a/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs +++ b/CapnpC.CSharp.Generator.Tests/CodeGenerator.feature.cs @@ -279,6 +279,18 @@ this.ValidGeneratorOutput("Issue19.capnp.bin", ((string[])(null))); { #line 50 this.ValidGeneratorOutput("Issue21.capnp.bin", ((string[])(null))); +#line hidden + } + + [Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()] + [Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("Valid generator output: Issue22.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CodeGenerator")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("VariantName", "Issue22.capnp.bin")] + [Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("Parameter:bin", "Issue22.capnp.bin")] + public virtual void ValidGeneratorOutput_Issue22_Capnp_Bin() + { +#line 50 +this.ValidGeneratorOutput("Issue22.capnp.bin", ((string[])(null))); #line hidden } } diff --git a/CapnpC.CSharp.Generator.Tests/Embedded Resources/Issue22.capnp.bin b/CapnpC.CSharp.Generator.Tests/Embedded Resources/Issue22.capnp.bin new file mode 100644 index 0000000000000000000000000000000000000000..453e97c9be42cd3a14825d5a89958d456e06b158 GIT binary patch literal 2616 zcmd5;O-NKx6u!@~rXl+=B8VsvTBM~k0};3pMT!JLjgo59q!TjZIK!J6)Kx!=DB87a z(ZaTi4dVFxsplYwmM_#(~0Upo^F(PQYkLpq9Qx3)jaj`!cve*Fi6eivb% zGWhjd_}4>2-P3oz=N@f_67bb<@t@)PDSSQve*x}~_#E<4=)Z*Y#nF!ZuPc4`cVVv{ z4sT#Lj1i`f(3xRS$O*nizaPZZ}>inYi8;wIA_O`+A zOoZQsi}Q0Q5`ABn!{H|EegU7Wa98Lq(4?FRWhkm=V-b(S;T%52Jw*l$M@Td zA$8b)AV)w$u3%?bs(` z&P<6E1dDOI9KD{{FJd^e9lQa&NKZ-jl=>94FPS;GEXi{?Q>sjqnW*uc8)), Skeleton(typeof(DeepNestInterfaceSkeleton<>))] + [TypeId(0x8839ed86c9794287UL), Proxy(typeof(DeepNestInterface_Proxy<>)), Skeleton(typeof(DeepNestInterface_Skeleton<>))] public interface IDeepNestInterface : IDisposable where TQuux : class { Task Call(CancellationToken cancellationToken_ = default); } - public class DeepNestInterfaceProxy : Proxy, IDeepNestInterface where TQuux : class + public class DeepNestInterface_Proxy : Proxy, IDeepNestInterface where TQuux : class { public async Task Call(CancellationToken cancellationToken_ = default) { @@ -8486,9 +8486,9 @@ namespace Capnproto_test.Capnp.Test } } - public class DeepNestInterfaceSkeleton : Skeleton> where TQuux : class + public class DeepNestInterface_Skeleton : Skeleton> where TQuux : class { - public DeepNestInterfaceSkeleton() + public DeepNestInterface_Skeleton() { SetMethodTable(Call); } @@ -8598,13 +8598,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xc9e749e8dd54da5cUL), Proxy(typeof(InterfaceProxy<>)), Skeleton(typeof(InterfaceSkeleton<>))] + [TypeId(0xc9e749e8dd54da5cUL), Proxy(typeof(Interface_Proxy<>)), Skeleton(typeof(Interface_Skeleton<>))] public interface IInterface : IDisposable where TQux : class { Task<(TQux, Capnproto_test.Capnp.Test.TestGenerics)> Call(Capnproto_test.Capnp.Test.TestGenerics.Inner2 arg_, CancellationToken cancellationToken_ = default); } - public class InterfaceProxy : Proxy, IInterface where TQux : class + public class Interface_Proxy : Proxy, IInterface where TQux : class { public Task<(TQux, Capnproto_test.Capnp.Test.TestGenerics)> Call(Capnproto_test.Capnp.Test.TestGenerics.Inner2 arg_, CancellationToken cancellationToken_ = default) { @@ -8620,9 +8620,9 @@ namespace Capnproto_test.Capnp.Test } } - public class InterfaceSkeleton : Skeleton> where TQux : class + public class Interface_Skeleton : Skeleton> where TQux : class { - public InterfaceSkeleton() + public Interface_Skeleton() { SetMethodTable(Call); } @@ -8977,14 +8977,14 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x8b9717a3f8d85a9aUL), Proxy(typeof(TestImplicitMethodParamsProxy)), Skeleton(typeof(TestImplicitMethodParamsSkeleton))] + [TypeId(0x8b9717a3f8d85a9aUL), Proxy(typeof(TestImplicitMethodParams_Proxy)), Skeleton(typeof(TestImplicitMethodParams_Skeleton))] public interface ITestImplicitMethodParams : IDisposable { Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class; } - public class TestImplicitMethodParamsProxy : Proxy, ITestImplicitMethodParams + public class TestImplicitMethodParams_Proxy : Proxy, ITestImplicitMethodParams { public Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class @@ -9003,9 +9003,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestImplicitMethodParamsSkeleton : Skeleton + public class TestImplicitMethodParams_Skeleton : Skeleton { - public TestImplicitMethodParamsSkeleton() + public TestImplicitMethodParams_Skeleton() { SetMethodTable(Call); } @@ -9104,14 +9104,14 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xdf9ccdeb81a704c9UL), Proxy(typeof(TestImplicitMethodParamsInGenericProxy<>)), Skeleton(typeof(TestImplicitMethodParamsInGenericSkeleton<>))] + [TypeId(0xdf9ccdeb81a704c9UL), Proxy(typeof(TestImplicitMethodParamsInGeneric_Proxy<>)), Skeleton(typeof(TestImplicitMethodParamsInGeneric_Skeleton<>))] public interface ITestImplicitMethodParamsInGeneric : IDisposable where TV : class { Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class; } - public class TestImplicitMethodParamsInGenericProxy : Proxy, ITestImplicitMethodParamsInGeneric where TV : class + public class TestImplicitMethodParamsInGeneric_Proxy : Proxy, ITestImplicitMethodParamsInGeneric where TV : class { public Task> Call(TT foo, TU bar, CancellationToken cancellationToken_ = default) where TT : class where TU : class @@ -9130,9 +9130,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestImplicitMethodParamsInGenericSkeleton : Skeleton> where TV : class + public class TestImplicitMethodParamsInGeneric_Skeleton : Skeleton> where TV : class { - public TestImplicitMethodParamsInGenericSkeleton() + public TestImplicitMethodParamsInGeneric_Skeleton() { SetMethodTable(Call); } @@ -10013,7 +10013,7 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x88eb12a0e0af92b2UL), Proxy(typeof(TestInterfaceProxy)), Skeleton(typeof(TestInterfaceSkeleton))] + [TypeId(0x88eb12a0e0af92b2UL), Proxy(typeof(TestInterface_Proxy)), Skeleton(typeof(TestInterface_Skeleton))] public interface ITestInterface : IDisposable { Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default); @@ -10021,7 +10021,7 @@ namespace Capnproto_test.Capnp.Test Task Baz(Capnproto_test.Capnp.Test.TestAllTypes s, CancellationToken cancellationToken_ = default); } - public class TestInterfaceProxy : Proxy, ITestInterface + public class TestInterface_Proxy : Proxy, ITestInterface { public async Task Foo(uint i, bool j, CancellationToken cancellationToken_ = default) { @@ -10057,9 +10057,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestInterfaceSkeleton : Skeleton + public class TestInterface_Skeleton : Skeleton { - public TestInterfaceSkeleton() + public TestInterface_Skeleton() { SetMethodTable(Foo, Bar, Baz); } @@ -10428,7 +10428,7 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xe4e9bac98670b748UL), Proxy(typeof(TestExtendsProxy)), Skeleton(typeof(TestExtendsSkeleton))] + [TypeId(0xe4e9bac98670b748UL), Proxy(typeof(TestExtends_Proxy)), Skeleton(typeof(TestExtends_Skeleton))] public interface ITestExtends : Capnproto_test.Capnp.Test.ITestInterface { Task Qux(CancellationToken cancellationToken_ = default); @@ -10436,7 +10436,7 @@ namespace Capnproto_test.Capnp.Test Task Grault(CancellationToken cancellationToken_ = default); } - public class TestExtendsProxy : Proxy, ITestExtends + public class TestExtends_Proxy : Proxy, ITestExtends { public async Task Qux(CancellationToken cancellationToken_ = default) { @@ -10503,9 +10503,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestExtendsSkeleton : Skeleton + public class TestExtends_Skeleton : Skeleton { - public TestExtendsSkeleton() + public TestExtends_Skeleton() { SetMethodTable(Qux, Corge, Grault); } @@ -10721,12 +10721,12 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x98d7e0ef61488783UL), Proxy(typeof(TestExtends2Proxy)), Skeleton(typeof(TestExtends2Skeleton))] + [TypeId(0x98d7e0ef61488783UL), Proxy(typeof(TestExtends2_Proxy)), Skeleton(typeof(TestExtends2_Skeleton))] public interface ITestExtends2 : Capnproto_test.Capnp.Test.ITestExtends { } - public class TestExtends2Proxy : Proxy, ITestExtends2 + public class TestExtends2_Proxy : Proxy, ITestExtends2 { public async Task Qux(CancellationToken cancellationToken_ = default) { @@ -10793,9 +10793,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestExtends2Skeleton : Skeleton + public class TestExtends2_Skeleton : Skeleton { - public TestExtends2Skeleton() + public TestExtends2_Skeleton() { SetMethodTable(); } @@ -10803,7 +10803,7 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11013518732491786115UL; } - [TypeId(0xa5a404caa61d4cd0UL), Proxy(typeof(TestPipelineProxy)), Skeleton(typeof(TestPipelineSkeleton))] + [TypeId(0xa5a404caa61d4cd0UL), Proxy(typeof(TestPipeline_Proxy)), Skeleton(typeof(TestPipeline_Skeleton))] public interface ITestPipeline : IDisposable { Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default); @@ -10811,7 +10811,7 @@ namespace Capnproto_test.Capnp.Test Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> GetAnyCap(uint n, BareProxy inCap, CancellationToken cancellationToken_ = default); } - public class TestPipelineProxy : Proxy, ITestPipeline + public class TestPipeline_Proxy : Proxy, ITestPipeline { public Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> GetCap(uint n, Capnproto_test.Capnp.Test.ITestInterface inCap, CancellationToken cancellationToken_ = default) { @@ -10855,9 +10855,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestPipelineSkeleton : Skeleton + public class TestPipeline_Skeleton : Skeleton { - public TestPipelineSkeleton() + public TestPipeline_Skeleton() { SetMethodTable(GetCap, TestPointers, GetAnyCap); } @@ -11458,13 +11458,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xa0e77035bdff0051UL), Proxy(typeof(TestCallOrderProxy)), Skeleton(typeof(TestCallOrderSkeleton))] + [TypeId(0xa0e77035bdff0051UL), Proxy(typeof(TestCallOrder_Proxy)), Skeleton(typeof(TestCallOrder_Skeleton))] public interface ITestCallOrder : IDisposable { Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default); } - public class TestCallOrderProxy : Proxy, ITestCallOrder + public class TestCallOrder_Proxy : Proxy, ITestCallOrder { public async Task GetCallSequence(uint expected, CancellationToken cancellationToken_ = default) { @@ -11478,9 +11478,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestCallOrderSkeleton : Skeleton + public class TestCallOrder_Skeleton : Skeleton { - public TestCallOrderSkeleton() + public TestCallOrder_Skeleton() { SetMethodTable(GetCallSequence); } @@ -11624,13 +11624,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xddd699207eb8e23bUL), Proxy(typeof(TestTailCalleeProxy)), Skeleton(typeof(TestTailCalleeSkeleton))] + [TypeId(0xddd699207eb8e23bUL), Proxy(typeof(TestTailCallee_Proxy)), Skeleton(typeof(TestTailCallee_Skeleton))] public interface ITestTailCallee : IDisposable { Task Foo(int i, string t, CancellationToken cancellationToken_ = default); } - public class TestTailCalleeProxy : Proxy, ITestTailCallee + public class TestTailCallee_Proxy : Proxy, ITestTailCallee { public Task Foo(int i, string t, CancellationToken cancellationToken_ = default) { @@ -11648,9 +11648,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestTailCalleeSkeleton : Skeleton + public class TestTailCallee_Skeleton : Skeleton { - public TestTailCalleeSkeleton() + public TestTailCallee_Skeleton() { SetMethodTable(Foo); } @@ -11838,13 +11838,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x870bf40110ce3035UL), Proxy(typeof(TestTailCallerProxy)), Skeleton(typeof(TestTailCallerSkeleton))] + [TypeId(0x870bf40110ce3035UL), Proxy(typeof(TestTailCaller_Proxy)), Skeleton(typeof(TestTailCaller_Skeleton))] public interface ITestTailCaller : IDisposable { Task Foo(int i, Capnproto_test.Capnp.Test.ITestTailCallee callee, CancellationToken cancellationToken_ = default); } - public class TestTailCallerProxy : Proxy, ITestTailCaller + public class TestTailCaller_Proxy : Proxy, ITestTailCaller { public Task Foo(int i, Capnproto_test.Capnp.Test.ITestTailCallee callee, CancellationToken cancellationToken_ = default) { @@ -11862,9 +11862,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestTailCallerSkeleton : Skeleton + public class TestTailCaller_Skeleton : Skeleton { - public TestTailCallerSkeleton() + public TestTailCaller_Skeleton() { SetMethodTable(Foo); } @@ -11962,18 +11962,18 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xa38e5efe41e53a15UL), Proxy(typeof(TestHandleProxy)), Skeleton(typeof(TestHandleSkeleton))] + [TypeId(0xa38e5efe41e53a15UL), Proxy(typeof(TestHandle_Proxy)), Skeleton(typeof(TestHandle_Skeleton))] public interface ITestHandle : IDisposable { } - public class TestHandleProxy : Proxy, ITestHandle + public class TestHandle_Proxy : Proxy, ITestHandle { } - public class TestHandleSkeleton : Skeleton + public class TestHandle_Skeleton : Skeleton { - public TestHandleSkeleton() + public TestHandle_Skeleton() { SetMethodTable(); } @@ -11981,7 +11981,7 @@ namespace Capnproto_test.Capnp.Test public override ulong InterfaceId => 11785461720995412501UL; } - [TypeId(0xddc70bf9784133cfUL), Proxy(typeof(TestMoreStuffProxy)), Skeleton(typeof(TestMoreStuffSkeleton))] + [TypeId(0xddc70bf9784133cfUL), Proxy(typeof(TestMoreStuff_Proxy)), Skeleton(typeof(TestMoreStuff_Skeleton))] public interface ITestMoreStuff : Capnproto_test.Capnp.Test.ITestCallOrder { Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default); @@ -11999,7 +11999,7 @@ namespace Capnproto_test.Capnp.Test Task MethodWithNullDefault(string a, Capnproto_test.Capnp.Test.ITestInterface b, CancellationToken cancellationToken_ = default); } - public class TestMoreStuffProxy : Proxy, ITestMoreStuff + public class TestMoreStuff_Proxy : Proxy, ITestMoreStuff { public async Task CallFoo(Capnproto_test.Capnp.Test.ITestInterface cap, CancellationToken cancellationToken_ = default) { @@ -12176,9 +12176,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestMoreStuffSkeleton : Skeleton + public class TestMoreStuff_Skeleton : Skeleton { - public TestMoreStuffSkeleton() + public TestMoreStuff_Skeleton() { SetMethodTable(CallFoo, CallFooWhenResolved, NeverReturn, Hold, CallHeld, GetHeld, Echo, ExpectCancel, MethodWithDefaults, GetHandle, GetNull, GetEnormousString, MethodWithNullDefault); } @@ -13850,7 +13850,7 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xc07d8dcd80a69c0cUL), Proxy(typeof(TestMembraneProxy)), Skeleton(typeof(TestMembraneSkeleton))] + [TypeId(0xc07d8dcd80a69c0cUL), Proxy(typeof(TestMembrane_Proxy)), Skeleton(typeof(TestMembrane_Skeleton))] public interface ITestMembrane : IDisposable { Task MakeThing(CancellationToken cancellationToken_ = default); @@ -13860,7 +13860,7 @@ namespace Capnproto_test.Capnp.Test Task WaitForever(CancellationToken cancellationToken_ = default); } - public class TestMembraneProxy : Proxy, ITestMembrane + public class TestMembrane_Proxy : Proxy, ITestMembrane { public Task MakeThing(CancellationToken cancellationToken_ = default) { @@ -13926,9 +13926,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestMembraneSkeleton : Skeleton + public class TestMembrane_Skeleton : Skeleton { - public TestMembraneSkeleton() + public TestMembrane_Skeleton() { SetMethodTable(MakeThing, CallPassThrough, CallIntercept, Loopback, WaitForever); } @@ -13997,14 +13997,14 @@ namespace Capnproto_test.Capnp.Test public static class TestMembrane { - [TypeId(0x9352e4e41f173917UL), Proxy(typeof(ThingProxy)), Skeleton(typeof(ThingSkeleton))] + [TypeId(0x9352e4e41f173917UL), Proxy(typeof(Thing_Proxy)), Skeleton(typeof(Thing_Skeleton))] public interface IThing : IDisposable { Task PassThrough(CancellationToken cancellationToken_ = default); Task Intercept(CancellationToken cancellationToken_ = default); } - public class ThingProxy : Proxy, IThing + public class Thing_Proxy : Proxy, IThing { public async Task PassThrough(CancellationToken cancellationToken_ = default) { @@ -14029,9 +14029,9 @@ namespace Capnproto_test.Capnp.Test } } - public class ThingSkeleton : Skeleton + public class Thing_Skeleton : Skeleton { - public ThingSkeleton() + public Thing_Skeleton() { SetMethodTable(PassThrough, Intercept); } @@ -14891,7 +14891,7 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0x9ae342d394247cfcUL), Proxy(typeof(TestKeywordMethodsProxy)), Skeleton(typeof(TestKeywordMethodsSkeleton))] + [TypeId(0x9ae342d394247cfcUL), Proxy(typeof(TestKeywordMethods_Proxy)), Skeleton(typeof(TestKeywordMethods_Skeleton))] public interface ITestKeywordMethods : IDisposable { Task Delete(CancellationToken cancellationToken_ = default); @@ -14900,7 +14900,7 @@ namespace Capnproto_test.Capnp.Test Task Return(CancellationToken cancellationToken_ = default); } - public class TestKeywordMethodsProxy : Proxy, ITestKeywordMethods + public class TestKeywordMethods_Proxy : Proxy, ITestKeywordMethods { public async Task Delete(CancellationToken cancellationToken_ = default) { @@ -14947,9 +14947,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestKeywordMethodsSkeleton : Skeleton + public class TestKeywordMethods_Skeleton : Skeleton { - public TestKeywordMethodsSkeleton() + public TestKeywordMethods_Skeleton() { SetMethodTable(Delete, Class, Void, Return); } @@ -15347,13 +15347,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xea72cc77253798cdUL), Proxy(typeof(TestAuthenticatedBootstrapProxy<>)), Skeleton(typeof(TestAuthenticatedBootstrapSkeleton<>))] + [TypeId(0xea72cc77253798cdUL), Proxy(typeof(TestAuthenticatedBootstrap_Proxy<>)), Skeleton(typeof(TestAuthenticatedBootstrap_Skeleton<>))] public interface ITestAuthenticatedBootstrap : IDisposable where TVatId : class { Task GetCallerId(CancellationToken cancellationToken_ = default); } - public class TestAuthenticatedBootstrapProxy : Proxy, ITestAuthenticatedBootstrap where TVatId : class + public class TestAuthenticatedBootstrap_Proxy : Proxy, ITestAuthenticatedBootstrap where TVatId : class { public Task GetCallerId(CancellationToken cancellationToken_ = default) { @@ -15371,9 +15371,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestAuthenticatedBootstrapSkeleton : Skeleton> where TVatId : class + public class TestAuthenticatedBootstrap_Skeleton : Skeleton> where TVatId : class { - public TestAuthenticatedBootstrapSkeleton() + public TestAuthenticatedBootstrap_Skeleton() { SetMethodTable(GetCallerId); } @@ -16321,13 +16321,13 @@ namespace Capnproto_test.Capnp.Test } } - [TypeId(0xd112a69d31ed918bUL), Proxy(typeof(TestNameAnnotationInterfaceProxy)), Skeleton(typeof(TestNameAnnotationInterfaceSkeleton))] + [TypeId(0xd112a69d31ed918bUL), Proxy(typeof(TestNameAnnotationInterface_Proxy)), Skeleton(typeof(TestNameAnnotationInterface_Skeleton))] public interface ITestNameAnnotationInterface : IDisposable { Task BadlyNamedMethod(byte badlyNamedParam, CancellationToken cancellationToken_ = default); } - public class TestNameAnnotationInterfaceProxy : Proxy, ITestNameAnnotationInterface + public class TestNameAnnotationInterface_Proxy : Proxy, ITestNameAnnotationInterface { public async Task BadlyNamedMethod(byte badlyNamedParam, CancellationToken cancellationToken_ = default) { @@ -16341,9 +16341,9 @@ namespace Capnproto_test.Capnp.Test } } - public class TestNameAnnotationInterfaceSkeleton : Skeleton + public class TestNameAnnotationInterface_Skeleton : Skeleton { - public TestNameAnnotationInterfaceSkeleton() + public TestNameAnnotationInterface_Skeleton() { SetMethodTable(BadlyNamedMethod); } @@ -16466,54 +16466,24 @@ namespace Capnproto_test.Capnp.Test } } - public static partial class PipeliningSupportExtensions + public static partial class PipeliningSupportExtensions_test { - static readonly MemberAccessPath Path_getCap_OutBox_Cap = new MemberAccessPath(1U, 0U); + static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestPipeline_getCap_OutBox_Cap = new MemberAccessPath(1U, 0U); public static Capnproto_test.Capnp.Test.ITestInterface OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.Box)> task) { - return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getCap_OutBox_Cap)); + return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getCap_OutBox_Cap)); } - static readonly MemberAccessPath Path_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); + static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestPipeline_getAnyCap_OutBox_Cap = new MemberAccessPath(1U, 0U); public static BareProxy OutBox_Cap(this Task<(string, Capnproto_test.Capnp.Test.TestPipeline.AnyBox)> task) { - return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getAnyCap_OutBox_Cap)); + return (BareProxy)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestPipeline_getAnyCap_OutBox_Cap)); } - static readonly MemberAccessPath Path_foo_C = new MemberAccessPath(1U); + static readonly MemberAccessPath Path_capnproto_test_capnp_test_TestTailCallee_foo_C = new MemberAccessPath(1U); public static Capnproto_test.Capnp.Test.ITestCallOrder C(this Task task) { - return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_foo_C)); - } - - static readonly MemberAccessPath Path_neverReturn_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestInterface Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestInterface)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_neverReturn_Eager)); - } - - static readonly MemberAccessPath Path_echo_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestCallOrder Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_echo_Eager)); - } - - static readonly MemberAccessPath Path_getHandle_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestHandle Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestHandle)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getHandle_Eager)); - } - - static readonly MemberAccessPath Path_getNull_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.ITestMoreStuff Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.ITestMoreStuff)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_getNull_Eager)); - } - - static readonly MemberAccessPath Path_makeThing_Eager = new MemberAccessPath(0U); - public static Capnproto_test.Capnp.Test.TestMembrane.IThing Eager(this Task task) - { - return (Capnproto_test.Capnp.Test.TestMembrane.IThing)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_makeThing_Eager)); + return (Capnproto_test.Capnp.Test.ITestCallOrder)CapabilityReflection.CreateProxy(Impatient.GetAnswer(task).Access(Path_capnproto_test_capnp_test_TestTailCallee_foo_C)); } } } \ No newline at end of file diff --git a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs index 32d6f75..6ac4d0a 100644 --- a/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs +++ b/CapnpC.CSharp.Generator/CodeGen/CodeGenerator.cs @@ -142,13 +142,13 @@ } } - ClassDeclarationSyntax TransformPipeliningSupport(IHasNestedDefinitions def) + ClassDeclarationSyntax TransformForPipeliningSupport(GenFile file) { var classDecl = default(ClassDeclarationSyntax); var q = new Queue(); - foreach (var inner in def.NestedDefinitions.OfType()) + foreach (var inner in file.NestedTypes) { q.Enqueue(inner); } @@ -165,7 +165,7 @@ { if (classDecl == null) { - classDecl = ClassDeclaration(_names.PipeliningExtensionsClassName.Identifier) + classDecl = ClassDeclaration(_names.MakePipeliningSupportExtensionClassName(file).Identifier) .AddModifiers(Public, Static, Partial); } @@ -173,7 +173,7 @@ } } - foreach (var inner in cur.NestedDefinitions.OfType()) + foreach (var inner in cur.NestedTypes) { q.Enqueue(inner); } @@ -193,7 +193,7 @@ ns = ns.AddMembers(Transform(def).ToArray()); } - var psc = TransformPipeliningSupport(file); + var psc = TransformForPipeliningSupport(file); if (psc != null) { diff --git a/CapnpC.CSharp.Generator/CodeGen/GenNames.cs b/CapnpC.CSharp.Generator/CodeGen/GenNames.cs index 0690fcd..c878b04 100644 --- a/CapnpC.CSharp.Generator/CodeGen/GenNames.cs +++ b/CapnpC.CSharp.Generator/CodeGen/GenNames.cs @@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; @@ -58,12 +59,13 @@ namespace CapnpC.CSharp.Generator.CodeGen public string ResultStructFormat { get; } public string PropertyNamedLikeTypeRenameFormat { get; } public string GenericTypeParameterFormat { get; } - public Name PipeliningExtensionsClassName { get; } public string MemberAccessPathNameFormat { get; } public Name TaskParameter { get; } public Name EagerMethod { get; } public Name TypeIdField { get; } - + public string PipeliningExtensionsClassFormat { get; } + public string ProxyClassFormat { get; } + public string SkeletonClassFormat { get; } public GenNames(GeneratorOptions options) { TopNamespace = new Name(options.TopNamespaceName).IdentifierName; @@ -94,11 +96,13 @@ namespace CapnpC.CSharp.Generator.CodeGen ResultStructFormat = options.ResultStructFormat; PropertyNamedLikeTypeRenameFormat = options.PropertyNamedLikeTypeRenameFormat; GenericTypeParameterFormat = options.GenericTypeParameterFormat; - PipeliningExtensionsClassName = new Name(options.PipeliningExtensionsClassName); MemberAccessPathNameFormat = options.MemberAccessPathNameFormat; TaskParameter = new Name(options.TaskParameterName); EagerMethod = new Name(options.EagerMethodName); TypeIdField = new Name(options.TypeIdFieldName); + PipeliningExtensionsClassFormat = options.PipeliningExtensionsClassFormat; + ProxyClassFormat = options.ProxyClassFormat; + SkeletonClassFormat = options.SkeletonClassFormat; } public Name MakeTypeName(TypeDefinition def, NameUsage usage = NameUsage.Default) @@ -145,11 +149,11 @@ namespace CapnpC.CSharp.Generator.CodeGen break; case NameUsage.Proxy: - name = def.Name + "Proxy"; + name = string.Format(ProxyClassFormat, def.Name); break; case NameUsage.Skeleton: - name = def.Name + "Skeleton"; + name = string.Format(SkeletonClassFormat, def.Name); break; default: @@ -593,9 +597,43 @@ namespace CapnpC.CSharp.Generator.CodeGen return new Name(string.Join("_", path.Select(f => GetCodeIdentifier(f).ToString()))); } + public Name MakePipeliningSupportExtensionClassName(GenFile file) + { + return new Name(string.Format(PipeliningExtensionsClassFormat, Path.GetFileNameWithoutExtension(file.Name).Replace(".", "_"))); + } + public Name MakeMemberAccessPathFieldName(Method method, IReadOnlyList path) { + var nameList = new Stack(); + var cur = method.DeclaringInterface.DeclaringElement; + do + { + switch (cur) + { + case TypeDefinition def: + nameList.Push(def.Name); + cur = def.DeclaringElement; + break; + + case GenFile file: + if (file.Namespace != null) + { + foreach (string id in file.Namespace.Reverse()) + { + nameList.Push(id); + } + } + cur = null; + break; + + default: + throw new NotImplementedException("Unexpected element in definition hierarchy of method. Not a type, not a file."); + } + } while (cur != null); + return new Name(string.Format(MemberAccessPathNameFormat, + string.Join("_", nameList), + method.DeclaringInterface.Name, method.Name, MakePipeliningSupportExtensionMethodName(path))); } diff --git a/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs b/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs index c6516bb..329f553 100644 --- a/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs +++ b/CapnpC.CSharp.Generator/CodeGen/GeneratorOptions.cs @@ -30,8 +30,10 @@ public string PropertyNamedLikeTypeRenameFormat { get; set; } = "The{0}"; public string InstLocalName { get; set; } = "inst"; public string GenericTypeParameterFormat { get; set; } = "T{0}"; - public string PipeliningExtensionsClassName { get; set; } = "PipeliningSupportExtensions"; - public string MemberAccessPathNameFormat { get; set; } = "Path_{0}_{1}"; + public string PipeliningExtensionsClassFormat { get; set; } = "PipeliningSupportExtensions_{0}"; + public string ProxyClassFormat { get; set; } = "{0}_Proxy"; + public string SkeletonClassFormat { get; set; } = "{0}_Skeleton"; + public string MemberAccessPathNameFormat { get; set; } = "Path_{0}_{1}_{2}_{3}"; public string TaskParameterName { get; set; } = "task"; public string EagerMethodName { get; set; } = "Eager"; public string TypeIdFieldName { get; set; } = "typeId"; diff --git a/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs b/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs index 0f86f80..0c8b23a 100644 --- a/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs +++ b/CapnpC.CSharp.Generator/CodeGen/InterfaceSnippetGen.cs @@ -766,6 +766,12 @@ namespace CapnpC.CSharp.Generator.CodeGen { foreach (var path in ExpandPipeliningPaths(method)) { + if (path.Count == 1 && path[0].Offset == 0) + { + // The "trivial path" is already covered by the "Eager" extension method. + continue; + } + var accessPath = _names.MakeMemberAccessPathFieldName(method, path); var methodName = _names.MakePipeliningSupportExtensionMethodName(path); var capType = path[path.Count - 1].Type; diff --git a/MsBuildGenerationTest/Issue22.capnp b/MsBuildGenerationTest/Issue22.capnp new file mode 100644 index 0000000..4c74562 --- /dev/null +++ b/MsBuildGenerationTest/Issue22.capnp @@ -0,0 +1,13 @@ +@0xcda70121571f3166; + +interface Issue22 { + methodA @0 (param1 :Int64) -> (); +} + +interface Issue22Proxy { + methodB @0 (param1 :Int64) -> (a :Issue22); +} + +interface Issue22Skeleton { + methodB @0 (param1 :Int64) -> (a :Issue22); +} diff --git a/MsBuildGenerationTest/a.capnp b/MsBuildGenerationTest/a.capnp new file mode 100644 index 0000000..7b16ac8 --- /dev/null +++ b/MsBuildGenerationTest/a.capnp @@ -0,0 +1,8 @@ +@0x8e165bd19455e1ad; + +using Common = import "common.capnp".Common; +struct OuterA { + interface B { + methodB @0 () -> (a :Common.A); + } +} diff --git a/MsBuildGenerationTest/b.capnp b/MsBuildGenerationTest/b.capnp new file mode 100644 index 0000000..2ef0a90 --- /dev/null +++ b/MsBuildGenerationTest/b.capnp @@ -0,0 +1,8 @@ +@0x83152e8eed443172; + +using Common = import "common.capnp".Common; +struct OuterB { + interface B { + methodB1 @0 () -> (a :Common.A); + } +} diff --git a/MsBuildGenerationTest/common.capnp b/MsBuildGenerationTest/common.capnp new file mode 100644 index 0000000..a3ca067 --- /dev/null +++ b/MsBuildGenerationTest/common.capnp @@ -0,0 +1,7 @@ +@0xfea4761b62ddd226; + +struct Common { + interface A { + methodA @0 () -> (); + } +}